|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
* You may obtain a copy of the License at
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
package net.micode.notes.widget;
|
|
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
import android.content.Context;
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
import net.micode.notes.data.Notes;
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
|
|
// NoteWidgetProvider_2x类继承自NoteWidgetProvider,用于特定样式(可能与2倍尺寸相关)的桌面小部件相关功能实现
|
|
|
// 比如处理小部件的更新、获取对应布局资源、背景资源以及定义小部件类型等操作
|
|
|
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
|
// 重写onUpdate方法,该方法会在桌面小部件需要更新时被调用,例如配置改变、定时更新等情况
|
|
|
// 此处调用了父类的update方法,通常父类的update方法包含了通用的小部件更新逻辑
|
|
|
// 子类可以在此基础上根据自身特点再做额外的定制化处理(当前代码暂时仅调用父类方法)
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
// 重写getLayoutId方法,其目的是返回此桌面小部件对应的布局资源的ID
|
|
|
// 这里返回R.layout.widget_2x,表示对应的布局文件是项目中名为widget_2x.xml的布局资源
|
|
|
// 该布局文件定义了小部件具体的界面展示样式,如组件构成及排列等
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.widget_2x;
|
|
|
}
|
|
|
// 重写getBgResourceId方法,用于根据传入的背景资源相关的ID(bgId参数)来获取对应的小部件背景资源的实际ID
|
|
|
// 通过调用ResourceParser类中WidgetBgResources内部类(假设)的getWidget2xBgResource静态方法来获取相应的背景资源ID
|
|
|
// 意味着具体的背景资源获取逻辑被封装在该工具类及其内部类方法中,会依据不同的bgId查找对应的背景资源
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
|
}
|
|
|
// 重写getWidgetType方法,用来返回小部件的类型标识
|
|
|
// 当前返回的是Notes.TYPE_WIDGET_2X,表明这个小部件属于一种特定的类型(可能代表2倍尺寸之类与其他小部件区分的类型定义)
|
|
|
// 方便在整个应用中根据小部件类型做不同处理,例如不同类型小部件的显示和交互逻辑会有所差异
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
return Notes.TYPE_WIDGET_2X;
|
|
|
}
|
|
|
}
|