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_2x.java

54 lines
2.3 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;
// 导入所需的Android和Java类
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
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
// 当小部件需要更新时,系统会调用此方法
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的update方法传入相同的参数以执行更新逻辑
super.update(context, appWidgetManager, appWidgetIds);
}
// 重写父类的getLayoutId方法用于返回此小部件布局的资源ID
@Override
protected int getLayoutId() {
// 返回R.layout.widget_2x这是预定义在res/layout目录下的XML布局文件
return R.layout.widget_2x;
}
// 重写父类的getBgResourceId方法用于根据传入的背景ID获取对应的资源ID
@Override
protected int getBgResourceId(int bgId) {
// 调用ResourceParser.WidgetBgResources.getWidget2xBgResource方法传入bgId
// 并返回对应的2x小部件背景资源ID
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
// 重写父类的getWidgetType方法用于返回此小部件的类型
@Override
protected int getWidgetType() {
// 返回Notes.TYPE_WIDGET_2X这是一个在Notes类中定义的常量表示2x小部件的类型
return Notes.TYPE_WIDGET_2X;
}
}