|  |  | /*
 | 
						
						
						
							|  |  |  * 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;
 | 
						
						
						
							|  |  |     }
 | 
						
						
						
							|  |  | }
 |