|
|
|
|
/*
|
|
|
|
|
* 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; // 导入AppWidgetManager类,用于管理应用小部件
|
|
|
|
|
import android.content.Context; // 导入Context类,用于提供应用环境的全局信息
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R; // 导入R类,用于访问应用的资源,如布局文件、字符串等
|
|
|
|
|
import net.micode.notes.data.Notes; // 导入Notes类,可能包含笔记的存储、类型定义等
|
|
|
|
|
import net.micode.notes.tool.ResourceParser; // 导入ResourceParser工具类,用于解析资源
|
|
|
|
|
|
|
|
|
|
// NoteWidgetProvider_2x类,继承自NoteWidgetProvider,用于显示2x大小的笔记小部件
|
|
|
|
|
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
|
|
|
|
|
|
|
|
// 当小部件需要更新时调用此方法
|
|
|
|
|
@Override
|
|
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
|
// 调用父类的update方法,传入上下文、小部件管理器和小部件ID数组
|
|
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前小部件布局的资源ID
|
|
|
|
|
@Override
|
|
|
|
|
protected int getLayoutId() {
|
|
|
|
|
// 返回R.layout.widget_2x,这是定义2x大小小部件布局的XML文件的资源ID
|
|
|
|
|
return R.layout.widget_2x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据传入的背景ID,获取对应的背景资源ID
|
|
|
|
|
@Override
|
|
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
|
|
// 使用ResourceParser.WidgetBgResources的getWidget2xBgResource方法,根据背景ID获取2x小部件的背景资源ID
|
|
|
|
|
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前小部件的类型
|
|
|
|
|
@Override
|
|
|
|
|
protected int getWidgetType() {
|
|
|
|
|
// 返回Notes.TYPE_WIDGET_2X,这是一个定义在Notes类中的常量,表示2x大小的小部件类型
|
|
|
|
|
return Notes.TYPE_WIDGET_2X;
|
|
|
|
|
}
|
|
|
|
|
}
|