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.
5._Open-source-software-rea.../NoteWidgetProvider_2x.java

77 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* 版权声明MiCode开源社区www.micode.net
*
* 本代码遵循Apache 2.0开源协议
* 如需获取完整的授权条款请访问http://www.apache.org/licenses/LICENSE-2.0.html
*
* 代码开始
*/
// 定义包名,组织代码模块化管理
package net.micode.notes.widget;
// 导入Android小部件相关类和应用的资源类
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R; // 导入资源文件R类用于访问布局和其他资源
import net.micode.notes.data.Notes; // 导入笔记相关的数据类
import net.micode.notes.tool.ResourceParser; // 导入资源解析工具类
/**
* 2x版本的小部件提供者类。
* 该类继承自 NoteWidgetProvider专门处理 2x2 尺寸的笔记小部件。
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
/**
* 当系统需要更新小部件时,会调用此方法。
* 此方法通过调用父类的 `update` 方法来处理小部件更新的逻辑。
*
* @param context 上下文环境,用于获取应用程序资源和操作。
* @param appWidgetManager 管理当前应用中所有小部件的 AppWidgetManager 实例。
* @param appWidgetIds 当前需要更新的小部件 ID 数组。
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的 update 方法,完成小部件的更新逻辑
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 获取小部件布局的资源 ID。
* 此方法返回当前小部件所使用的布局文件的资源 ID。
* 该布局文件定义了小部件在屏幕上的外观。
*
* @return 布局资源的 ID对应 `res/layout/widget_2x.xml` 文件。
*/
@Override
protected int getLayoutId() {
return R.layout.widget_2x; // 返回 2x 小部件的布局资源 ID
}
/**
* 根据背景 ID 获取对应的背景资源 ID。
* 小部件有不同的背景样式(如不同颜色或主题),通过背景 ID 选择对应的资源。
*
* @param bgId 背景资源的索引 ID表示选择哪一种背景样式。
* @return 背景资源的 ID用于设置小部件的背景。
*/
@Override
protected int getBgResourceId(int bgId) {
// 使用 ResourceParser 工具类,根据背景 ID 获取 2x 小部件的背景资源 ID
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
/**
* 获取当前小部件的类型。
* 该方法返回一个常量,用于标识当前小部件的类型。
* 不同尺寸的小部件有不同的类型常量,例如 2x 和 4x 小部件。
*
* @return 小部件类型的常量值,表示当前为 2x 尺寸的小部件。
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X; // 返回表示 2x 小部件类型的常量
}
}