Gallery2支持默认WIGET添加于桌面
Gallery2
1. 修改,使支持默认WIGET添加于桌面
packages/apps/Gallery2/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
@Override
public void onUpdate(Context context,
AppWidgetManager appWidgetManager, int[] appWidgetIds) {
android.util.Log.d(TAG, "ALog 1219 onUpdate");
// migrate gallery widgets from pre-JB releases to JB due to bucket ID change
GalleryWidgetMigrator.migrateGalleryWidgets(context);
WidgetDatabaseHelper helper = new WidgetDatabaseHelper(context);
try {
for (int id : appWidgetIds) {
Entry entry = helper.getEntry(id);
if (entry != null) {
RemoteViews views = buildWidget(context, id, entry);
appWidgetManager.updateAppWidget(id, views);
} else {
//添加以下代码,用于在Entry为空时,创建一个默认的Entry.
entry = new Entry();
entry.type = 1;
entry.widgetId=id;
RemoteViews views = buildWidget(context, id, entry);
appWidgetManager.updateAppWidget(id, views);
Log.e(TAG, "cannot load widget: " + id);
}
}
} finally {
helper.close();
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
packages/apps/Gallery2/src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java
public static class Entry {
public int widgetId;
public int type;
public String imageUri;
public byte imageData[];
public String albumPath;
public Entry() {}
//使其外部可调用。
public Entry(int id, Cursor cursor) {
widgetId = id;
type = cursor.getInt(INDEX_WIDGET_TYPE);
if (type == TYPE_SINGLE_PHOTO) {
imageUri = cursor.getString(INDEX_IMAGE_URI);
imageData = cursor.getBlob(INDEX_PHOTO_BLOB);
} else if (type == TYPE_ALBUM) {
albumPath = cursor.getString(INDEX_ALBUM_PATH);
}
}
private Entry(Cursor cursor) {
this(cursor.getInt(INDEX_APPWIDGET_ID), cursor);
}
}
2. dsf
3. sdf
4. dsf
5. df
6. df
7. df
8. df
9. df
10.