You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xiaomi-Notes/NoteWidgetProvider_4x.java

65 lines
3.1 KiB

2 months ago
/*
* 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;
// 导入Android框架中用于管理小部件的类
import android.appwidget.AppWidgetManager;
// 导入Android框架中提供应用环境信息的类
import android.content.Context;
// 导入项目内的资源类和其他相关类
import net.micode.notes.R; // 包含项目资源引用的类
import net.micode.notes.data.Notes; // 可能包含与笔记数据相关的常量或方法
import net.micode.notes.tool.ResourceParser; // 用于解析资源的工具类
// 声明NoteWidgetProvider_4x类它继承自NoteWidgetProvider
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
// 当小部件需要更新时,系统会调用此方法
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的update方法传入相同的参数执行更新逻辑
super.update(context, appWidgetManager, appWidgetIds);
}
// 重写父类的getLayoutId方法用于返回此小部件的布局资源ID
// 这里不需要@Override注解因为该方法在父类中不是抽象的且可见性允许重写
// 但加上@Override可以提高代码的可读性和维护性确保方法签名的正确性。
// 实际上,由于子类直接调用了父类的非抽象方法,这里的重写是可选的,
// 但如果父类中的getLayoutId方法被重写以提供不同的行为则这里的重写是必要的。
// 在这个例子中我们假设父类有一个受保护的getLayoutId方法这里是为了特定尺寸重写它。
protected int getLayoutId() {
// 返回R.layout.widget_4x这是预定义在res/layout目录下的XML布局文件
return R.layout.widget_4x;
}
// 重写父类的getBgResourceId方法用于根据传入的背景ID获取对应的资源ID
@Override
protected int getBgResourceId(int bgId) {
// 调用ResourceParser.WidgetBgResources.getWidget4xBgResource方法传入bgId
// 并返回对应的4x小部件背景资源ID
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
// 重写父类的getWidgetType方法用于返回此小部件的类型
@Override
protected int getWidgetType() {
// 返回Notes.TYPE_WIDGET_4X这是一个在Notes类中定义的常量表示4x小部件的类型
return Notes.TYPE_WIDGET_4X;
}
}