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.
2Q1/widget/NoteWidgetProvider_2x.java

53 lines
3.2 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.

/*
* 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_2x类继承自NoteWidgetProvider抽象类是针对特定尺寸可能是 2x 尺寸,具体需结合应用场景理解)桌面小部件的具体实现类,用于实现该尺寸小部件的特定功能,比如布局、背景资源以及类型等相关设置。
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
// 重写父类的onUpdate方法该方法在桌面小部件需要更新时被调用例如小部件添加到桌面、系统触发小部件更新等情况
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的update方法来执行小部件的更新操作将当前上下文、AppWidgetManager实例以及小部件ID数组传递给父类方法由父类中定义的通用更新逻辑来处理更新相关事宜例如设置小部件的显示内容、点击事件等具体逻辑在父类的update方法中
super.update(context, appWidgetManager, appWidgetIds);
}
// 重写父类的抽象方法getLayoutId用于返回该尺寸小部件对应的布局资源ID这里返回的是R.layout.widget_2x表示使用名为widget_2x的布局文件来展示该小部件的外观样式
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
// 重写父类的抽象方法getBgResourceId用于根据传入的背景颜色ID获取对应的背景资源ID通过调用ResourceParser.WidgetBgResources工具类的相关方法getWidget2xBgResource来获取适合该尺寸小部件的背景资源ID实现了根据不同背景颜色ID来设置小部件背景图片等显示资源的功能
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
// 重写父类的抽象方法getWidgetType用于返回该小部件的类型这里返回的是Notes.TYPE_WIDGET_2X表示该小部件属于特定的2x类型具体类型含义可能由应用中对不同尺寸或功能小部件的分类定义决定以便在小部件相关的操作和逻辑中能准确区分不同类型的小部件
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}
}