|
|
/*
|
|
|
* 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_4x.java - 4x4便签小部件提供者
|
|
|
// 主要功能:实现4x4尺寸便签小部件的具体逻辑
|
|
|
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; // 资源解析器
|
|
|
|
|
|
// ======================= 4x4便签小部件提供者 =======================
|
|
|
/**
|
|
|
* NoteWidgetProvider_4x - 4x4便签小部件提供者
|
|
|
* 继承自NoteWidgetProvider抽象基类
|
|
|
* 功能:实现4x4尺寸便签小部件的具体逻辑
|
|
|
* 尺寸:4x4单元格(通常为4行4列)
|
|
|
* 布局:widget_4x.xml
|
|
|
* 特点:更大显示面积,可显示更多便签内容
|
|
|
*/
|
|
|
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
|
|
|
|
|
|
// ======================= 小部件生命周期方法 =======================
|
|
|
|
|
|
/**
|
|
|
* 小部件更新回调
|
|
|
* 当小部件需要更新时调用,包括创建、定时更新、配置变更等
|
|
|
* 实现:调用父类的update()方法
|
|
|
* 与2x版本逻辑完全相同,复用父类通用更新逻辑
|
|
|
*
|
|
|
* @param context 上下文
|
|
|
* @param appWidgetManager 小部件管理器
|
|
|
* @param appWidgetIds 需要更新的小部件ID数组
|
|
|
*/
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
// 调用父类的update()方法执行通用更新逻辑
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
|
|
|
// ======================= 抽象方法实现 =======================
|
|
|
|
|
|
/**
|
|
|
* 获取布局ID
|
|
|
* 返回4x4小部件使用的布局资源ID
|
|
|
* 布局文件:R.layout.widget_4x
|
|
|
* 布局特点:更大的显示区域,适合显示更多文本内容
|
|
|
*
|
|
|
* @return 4x4小部件布局资源ID
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.widget_4x;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取背景资源ID
|
|
|
* 将背景颜色ID映射到4x4小部件的实际Drawable资源ID
|
|
|
* 通过ResourceParser.WidgetBgResources获取对应资源
|
|
|
* 注意:使用4x专用的背景资源,适配4x4尺寸
|
|
|
*
|
|
|
* @param bgId 背景颜色ID
|
|
|
* @return 4x4小部件背景Drawable资源ID
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取小部件类型
|
|
|
* 返回4x4小部件的类型常量
|
|
|
* 类型常量定义在Notes类中
|
|
|
* 用于数据库记录和业务逻辑区分
|
|
|
*
|
|
|
* @return 小部件类型:Notes.TYPE_WIDGET_4X
|
|
|
*/
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
return Notes.TYPE_WIDGET_4X;
|
|
|
}
|
|
|
} |