|
|
/*
|
|
|
* 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;
|
|
|
|
|
|
// 导入必要的Android和项目相关的类
|
|
|
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_4x类,继承自NoteWidgetProvider,用于显示4x大小的笔记小部件
|
|
|
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
|
|
|
|
|
|
// 当小部件需要更新时,系统会调用此方法
|
|
|
// 参数包括上下文(Context)、小部件管理器(AppWidgetManager)和小部件ID数组(int[])
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
// 调用父类的update方法,将更新请求传递给父类处理
|
|
|
// 父类可能会根据小部件ID数组更新一个或多个小部件
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
|
|
|
// 获取当前小部件布局的资源ID
|
|
|
// 这个方法被父类中的某些方法调用,用于加载小部件的UI布局
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
// 返回R.layout.widget_4x,这是定义4x大小小部件布局的XML文件的资源ID
|
|
|
return R.layout.widget_4x;
|
|
|
}
|
|
|
|
|
|
// 根据传入的背景ID,获取对应的背景资源ID
|
|
|
// 这个方法可能被父类中的某些方法调用,用于设置小部件的背景
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
// 使用ResourceParser.WidgetBgResources的getWidget4xBgResource方法
|
|
|
// 根据背景ID获取4x小部件的背景资源ID
|
|
|
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
|
|
|
}
|
|
|
|
|
|
// 获取当前小部件的类型
|
|
|
// 这个方法可能被父类中的某些方法调用,用于区分不同类型的小部件
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
// 返回Notes.TYPE_WIDGET_4X,这是一个定义在Notes类中的常量
|
|
|
// 表示4x大小的小部件类型
|
|
|
return Notes.TYPE_WIDGET_4X;
|
|
|
}
|
|
|
} |