/* * 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_4x类继承自NoteWidgetProvider类,专门用于实现4x4网格大小的Note小部件功能。 public class NoteWidgetProvider_4x extends NoteWidgetProvider { // 当AppWidgetManager需要更新小部件时,会调用此方法。 // 这是AppWidgetProvider生命周期中的一个重要方法,用于响应小部件的更新请求。 @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // 调用父类(NoteWidgetProvider)的update方法,传入必要的参数,以更新小部件的UI。 // 这里使用super关键字来访问父类的update方法,确保父类的逻辑被正确执行。 super.update(context, appWidgetManager, appWidgetIds); } // getLayoutId方法被用来获取小部件的布局资源ID。 // 每个小部件都有自己的布局文件,这里返回的是4x4网格小部件的布局资源ID。 // 注意:该方法没有@Override注解,这是一个遗漏,因为方法体与父类中的方法签名相同, // 应该加上@Override注解以明确表示这是一个重写的方法。 protected int getLayoutId() { // 返回R.layout.widget_4x,这是4x4网格小部件对应的布局资源ID。 return R.layout.widget_4x; } // getBgResourceId方法根据传入的背景ID(bgId),返回对应的背景资源ID。 // 这个方法使用ResourceParser工具类中的WidgetBgResources来获取正确的背景资源ID。 @Override protected int getBgResourceId(int bgId) { // 调用ResourceParser.WidgetBgResources的getWidget4xBgResource方法,传入bgId。 // 这个方法负责根据bgId返回4x4网格小部件的背景资源ID。 return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId); } // getWidgetType方法返回当前小部件的类型。 // 小部件类型用于区分不同的小部件,例如,不同的网格大小可能会有不同的类型。 @Override protected int getWidgetType() { // 返回Notes.TYPE_WIDGET_4X,这是一个常量,表示当前小部件是4x4网格大小的笔记小部件。 return Notes.TYPE_WIDGET_4X; } }