|
|
@ -14,8 +14,10 @@
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 包声明,定义了这个类属于哪个包
|
|
|
|
package net.micode.notes.widget;
|
|
|
|
package net.micode.notes.widget;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入所需的类和接口
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
|
|
|
@ -23,25 +25,33 @@ import net.micode.notes.R;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义NoteWidgetProvider_2x类,继承自NoteWidgetProvider
|
|
|
|
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
|
|
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
|
|
|
|
|
|
|
|
// 当小部件需要更新时调用的方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
|
|
|
|
// 调用父类的update方法来更新小部件
|
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
|
super.update(context, appWidgetManager, appWidgetIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取小部件布局资源ID的方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected int getLayoutId() {
|
|
|
|
protected int getLayoutId() {
|
|
|
|
|
|
|
|
// 返回2x小部件的布局资源ID
|
|
|
|
return R.layout.widget_2x;
|
|
|
|
return R.layout.widget_2x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取背景资源ID的方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
|
protected int getBgResourceId(int bgId) {
|
|
|
|
|
|
|
|
// 使用ResourceParser来获取2x小部件的背景资源ID
|
|
|
|
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
|
|
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取小部件类型的方法
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected int getWidgetType() {
|
|
|
|
protected int getWidgetType() {
|
|
|
|
|
|
|
|
// 返回小部件的类型,这里是2x小部件
|
|
|
|
return Notes.TYPE_WIDGET_2X;
|
|
|
|
return Notes.TYPE_WIDGET_2X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|