|
|
/*
|
|
|
* 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;
|
|
|
|
|
|
/**
|
|
|
* 4x4尺寸便签小部件提供者
|
|
|
* 继承自NoteWidgetProvider抽象基类,实现4x4大尺寸小部件的具体行为
|
|
|
* 负责管理桌面4x4网格尺寸的便签小部件显示和交互,提供更大的显示区域
|
|
|
*/
|
|
|
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
|
|
|
|
|
|
/**
|
|
|
* 小部件更新回调方法
|
|
|
* 当小部件需要更新显示内容时调用,复用父类的通用更新逻辑
|
|
|
* 4x4小部件使用与2x2相同的更新机制,但显示布局和背景资源不同
|
|
|
*
|
|
|
* @param context 上下文对象,用于访问应用资源和服务
|
|
|
* @param appWidgetManager 小部件管理器实例,用于执行小部件更新操作
|
|
|
* @param appWidgetIds 需要更新的小部件ID数组,支持批量更新多个小部件实例
|
|
|
*/
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
// 直接调用父类的通用更新逻辑,避免代码重复
|
|
|
// 父类已实现数据查询、界面绑定、点击事件等完整的小部件更新流程
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取4x4小部件专用布局资源ID
|
|
|
* 实现抽象方法,返回针对4x4网格尺寸优化的布局文件
|
|
|
* 4x4布局相比2x2具有更大的显示区域,可以展示更多内容
|
|
|
*
|
|
|
* @return 4x4小部件的布局资源ID,定义在R.layout.widget_4x中
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
// 返回4x4尺寸专用的布局文件
|
|
|
// 该布局针对4x4网格进行了优化,可能包含更大的文本区域或额外的显示元素
|
|
|
return R.layout.widget_4x;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据背景颜色ID获取4x4小部件的背景资源ID
|
|
|
* 实现抽象方法,提供4x4尺寸专用的背景图片映射
|
|
|
* 4x4背景图片在尺寸和比例上与2x2不同,适配更大的显示区域
|
|
|
*
|
|
|
* @param bgId 背景颜色ID(Notes.COLOR_YELLOW, Notes.COLOR_BLUE等颜色常量)
|
|
|
* @return 对应颜色的4x4小部件背景图片资源ID
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
// 通过资源解析器获取4x4尺寸专用的背景图片资源
|
|
|
// ResourceParser.WidgetBgResources.getWidget4xBgResource()专门处理4x4尺寸的背景映射
|
|
|
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取小部件类型标识符
|
|
|
* 实现抽象方法,返回4x4小部件的唯一类型常量
|
|
|
* 该标识符用于在数据库和Intent中区分不同尺寸的小部件
|
|
|
*
|
|
|
* @return 4x4小部件的类型标识符,值为Notes.TYPE_WIDGET_4X
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
// 返回4x4小部件的类型常量
|
|
|
// 这个值会存储在数据库中,用于关联便签数据和小部件实例
|
|
|
return Notes.TYPE_WIDGET_4X;
|
|
|
}
|
|
|
} |