|
|
/*
|
|
|
* 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.
|
|
|
*/
|
|
|
|
|
|
// NoteWidgetProvider_2x.java - 2x2便签小部件提供者
|
|
|
// 主要功能:实现2x2尺寸便签小部件的具体逻辑
|
|
|
package net.micode.notes.widget;
|
|
|
|
|
|
// ======================= 导入区域 =======================
|
|
|
// Android小部件
|
|
|
import android.appwidget.AppWidgetManager; // 小部件管理器
|
|
|
// Android基础
|
|
|
import android.content.Context; // 上下文
|
|
|
|
|
|
// 应用内部资源
|
|
|
import net.micode.notes.R; // 资源文件R类
|
|
|
// 应用数据模型
|
|
|
import net.micode.notes.data.Notes; // Notes主类
|
|
|
// 应用资源解析
|
|
|
import net.micode.notes.tool.ResourceParser; // 资源解析器
|
|
|
|
|
|
// ======================= 2x2便签小部件提供者 =======================
|
|
|
/**
|
|
|
* NoteWidgetProvider_2x - 2x2便签小部件提供者
|
|
|
* 继承自NoteWidgetProvider抽象基类
|
|
|
* 功能:实现2x2尺寸便签小部件的具体逻辑
|
|
|
* 尺寸:2x2单元格(通常为2行2列)
|
|
|
* 布局:widget_2x.xml
|
|
|
*/
|
|
|
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
|
|
|
|
// ======================= 小部件生命周期方法 =======================
|
|
|
|
|
|
/**
|
|
|
* 小部件更新回调
|
|
|
* 当小部件需要更新时调用,包括创建、定时更新、配置变更等
|
|
|
* 实现:调用父类的update()方法
|
|
|
*
|
|
|
* @param context 上下文
|
|
|
* @param appWidgetManager 小部件管理器
|
|
|
* @param appWidgetIds 需要更新的小部件ID数组
|
|
|
*/
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
// 调用父类的update()方法执行通用更新逻辑
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
|
|
|
// ======================= 抽象方法实现 =======================
|
|
|
|
|
|
/**
|
|
|
* 获取布局ID
|
|
|
* 返回2x2小部件使用的布局资源ID
|
|
|
* 布局文件:R.layout.widget_2x
|
|
|
*
|
|
|
* @return 2x2小部件布局资源ID
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.widget_2x;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取背景资源ID
|
|
|
* 将背景颜色ID映射到2x2小部件的实际Drawable资源ID
|
|
|
* 通过ResourceParser.WidgetBgResources获取对应资源
|
|
|
*
|
|
|
* @param bgId 背景颜色ID
|
|
|
* @return 2x2小部件背景Drawable资源ID
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取小部件类型
|
|
|
* 返回2x2小部件的类型常量
|
|
|
* 类型常量定义在Notes类中
|
|
|
*
|
|
|
* @return 小部件类型:Notes.TYPE_WIDGET_2X
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
return Notes.TYPE_WIDGET_2X;
|
|
|
}
|
|
|
} |