|
|
|
@ -41,18 +41,37 @@ import net.micode.notes.ui.activities.NotesListActivity;
|
|
|
|
|
* 抽象了三个方法,用来获取背景资源、布局id,以及组件类型
|
|
|
|
|
*/
|
|
|
|
|
public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
|
/**
|
|
|
|
|
* 声明数据投影模板
|
|
|
|
|
*/
|
|
|
|
|
public static final String[] PROJECTION = new String[]{
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.BG_COLOR_ID,
|
|
|
|
|
NoteColumns.SNIPPET
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 元素ID
|
|
|
|
|
*/
|
|
|
|
|
public static final int COLUMN_ID = 0;
|
|
|
|
|
/**
|
|
|
|
|
* 元素背景ID
|
|
|
|
|
*/
|
|
|
|
|
public static final int COLUMN_BG_COLOR_ID = 1;
|
|
|
|
|
/**
|
|
|
|
|
* 元素片段ID
|
|
|
|
|
*/
|
|
|
|
|
public static final int COLUMN_SNIPPET = 2;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 标签名
|
|
|
|
|
*/
|
|
|
|
|
private static final String TAG = "NoteWidgetProvider";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除的钩子方法
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @param appWidgetIds 组件ID
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onDeleted(Context context, int[] appWidgetIds) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
@ -65,6 +84,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签组件信息
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @param widgetId 便签ID
|
|
|
|
|
* @return 指针
|
|
|
|
|
*/
|
|
|
|
|
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
|
|
|
|
|
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
PROJECTION,
|
|
|
|
@ -73,10 +98,23 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
|
null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 组件更新方法
|
|
|
|
|
* @param context 上下文
|
|
|
|
|
* @param appWidgetManager 组件管理器
|
|
|
|
|
* @param appWidgetIds 组件ID列表
|
|
|
|
|
*/
|
|
|
|
|
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
|
update(context, appWidgetManager, appWidgetIds, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 组件更新方法(重载)
|
|
|
|
|
* @param context
|
|
|
|
|
* @param appWidgetManager
|
|
|
|
|
* @param appWidgetIds
|
|
|
|
|
* @param privacyMode
|
|
|
|
|
*/
|
|
|
|
|
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
|
|
|
|
|
boolean privacyMode) {
|
|
|
|
|
for (int i = 0; i < appWidgetIds.length; i++) {
|
|
|
|
@ -132,9 +170,22 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取背景元素ID
|
|
|
|
|
* @param bgId 背景ID
|
|
|
|
|
* @return 背景资源ID
|
|
|
|
|
*/
|
|
|
|
|
protected abstract int getBgResourceId(int bgId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取布局ID
|
|
|
|
|
* @return 布局ID
|
|
|
|
|
*/
|
|
|
|
|
protected abstract int getLayoutId();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取组件类型
|
|
|
|
|
* @return 组件类型ID
|
|
|
|
|
*/
|
|
|
|
|
protected abstract int getWidgetType();
|
|
|
|
|
}
|
|
|
|
|