From c3813a2e674818005aada3fad336fffd97dd4aaf Mon Sep 17 00:00:00 2001 From: YourUsername Date: Sun, 15 Dec 2024 21:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NoteWidgetProvider_4x.java | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 NoteWidgetProvider_4x.java diff --git a/NoteWidgetProvider_4x.java b/NoteWidgetProvider_4x.java new file mode 100644 index 0000000..a8e2100 --- /dev/null +++ b/NoteWidgetProvider_4x.java @@ -0,0 +1,65 @@ +/* + * 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; + } +} \ No newline at end of file