|
|
/*
|
|
|
* 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;
|
|
|
|
|
|
// NoteWidgetProvider_4x类继承自NoteWidgetProvider抽象类,是专门针对某种特定的4x尺寸(可能是桌面小部件尺寸规格,具体取决于应用定义)桌面小部件功能实现的类,通过重写抽象类中的相关方法来定制该尺寸小部件的具体行为和外观展示等内容。
|
|
|
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
|
|
|
// 重写父类的onUpdate方法,该方法会在桌面小部件需要更新时被调用,例如小部件首次添加到桌面、系统定时触发小部件更新或者应用内有相关更新操作触发等情况。
|
|
|
@Override
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
// 调用父类的update方法来执行具体的更新操作,将当前上下文、AppWidgetManager实例以及小部件ID数组作为参数传递过去,由父类中通用的更新逻辑来处理诸如设置小部件显示内容、配置点击事件等更新相关的操作(父类update方法中已定义了这些通用逻辑)。
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
}
|
|
|
|
|
|
// 重写父类的抽象方法getLayoutId,用于返回该4x尺寸小部件对应的布局资源ID,这里返回R.layout.widget_4x,表示该小部件将会使用名为widget_4x的布局文件来构建其界面显示样式,该布局文件中定义了小部件各个元素的布局结构、样式等信息。
|
|
|
protected int getLayoutId() {
|
|
|
return R.layout.widget_4x;
|
|
|
}
|
|
|
|
|
|
// 重写父类的抽象方法getBgResourceId,用于根据传入的背景颜色ID获取对应的背景资源ID,通过调用ResourceParser.WidgetBgResources工具类中的getWidget4xBgResource方法来获取适合该4x尺寸小部件的背景资源ID,以此实现根据不同的背景颜色需求来准确设置小部件的背景图片等显示相关资源,使得小部件的外观能根据不同情况进行相应变化。
|
|
|
@Override
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
|
|
|
}
|
|
|
|
|
|
// 重写父类的抽象方法getWidgetType,用于返回该小部件的类型标识,这里返回Notes.TYPE_WIDGET_4X,表示该小部件属于特定的4x类型(在应用中可能依据不同尺寸、功能等对小部件进行了分类定义,通过这个类型标识来区分),方便在整个桌面小部件相关的逻辑处理中(如更新、交互等操作)准确识别该小部件的类型并进行针对性的处理。
|
|
|
@Override
|
|
|
protected int getWidgetType() {
|
|
|
return Notes.TYPE_WIDGET_4X;
|
|
|
}
|
|
|
} |