|
|
@ -60,6 +60,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
private static final String TAG = "NoteWidgetProvider";
|
|
|
|
private static final String TAG = "NoteWidgetProvider";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
//删除便签程序小部件
|
|
|
|
public void onDeleted(Context context, int[] appWidgetIds) {
|
|
|
|
public void onDeleted(Context context, int[] appWidgetIds) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
@ -71,6 +72,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取小部件信息
|
|
|
|
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
|
|
|
|
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
|
|
|
|
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
|
|
|
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
|
|
|
PROJECTION,
|
|
|
|
PROJECTION,
|
|
|
@ -79,21 +81,27 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
null);
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新应用程序小部件
|
|
|
|
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
update(context, appWidgetManager, appWidgetIds, false);
|
|
|
|
update(context, appWidgetManager, appWidgetIds, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新
|
|
|
|
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
|
|
|
|
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
|
|
|
|
boolean privacyMode) {
|
|
|
|
boolean privacyMode) {
|
|
|
|
|
|
|
|
//遍历所有小部件 ID
|
|
|
|
for (int i = 0; i < appWidgetIds.length; i++) {
|
|
|
|
for (int i = 0; i < appWidgetIds.length; i++) {
|
|
|
|
|
|
|
|
//若有效 获取默认背景 ID 和一个空字符串作为 snippet
|
|
|
|
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
|
|
|
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
|
|
|
int bgId = ResourceParser.getDefaultBgId(context);
|
|
|
|
int bgId = ResourceParser.getDefaultBgId(context);
|
|
|
|
String snippet = "";
|
|
|
|
String snippet = "";
|
|
|
|
|
|
|
|
//创建一个指向 NoteEditActivity 的意图
|
|
|
|
Intent intent = new Intent(context, NoteEditActivity.class);
|
|
|
|
Intent intent = new Intent(context, NoteEditActivity.class);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询以获取有关该小部件的信息
|
|
|
|
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
|
|
|
|
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
|
|
|
|
if (c != null && c.moveToFirst()) {
|
|
|
|
if (c != null && c.moveToFirst()) {
|
|
|
|
if (c.getCount() > 1) {
|
|
|
|
if (c.getCount() > 1) {
|
|
|
@ -105,7 +113,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
bgId = c.getInt(COLUMN_BG_COLOR_ID);
|
|
|
|
bgId = c.getInt(COLUMN_BG_COLOR_ID);
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
} else {
|
|
|
|
} else {//它将 snippet 设置为默认文本,并将意图设置为插入或编辑操作
|
|
|
|
snippet = context.getResources().getString(R.string.widget_havenot_content);
|
|
|
|
snippet = context.getResources().getString(R.string.widget_havenot_content);
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,6 +127,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId);
|
|
|
|
intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId);
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Generate the pending intent to start host for the widget
|
|
|
|
* Generate the pending intent to start host for the widget
|
|
|
|
|
|
|
|
* 生成为小组件启动主机的挂起意图
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
PendingIntent pendingIntent = null;
|
|
|
|
PendingIntent pendingIntent = null;
|
|
|
|
if (privacyMode) {
|
|
|
|
if (privacyMode) {
|
|
|
@ -138,9 +147,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取 Bg 资源标识
|
|
|
|
protected abstract int getBgResourceId(int bgId);
|
|
|
|
protected abstract int getBgResourceId(int bgId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取布局标识
|
|
|
|
protected abstract int getLayoutId();
|
|
|
|
protected abstract int getLayoutId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取小部件类型
|
|
|
|
protected abstract int getWidgetType();
|
|
|
|
protected abstract int getWidgetType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|