packages/apps/Gallery2
修订版 | 023a8c06b5e3fafab92cc07f2f93641253e32bb3 (tree) |
---|---|
时间 | 2011-08-24 21:58:27 |
作者 | Owen Lin <owenlin@goog...> |
Commiter | Android (Google) Code Review |
Merge "Fix shortcup broken issue."
@@ -66,6 +66,17 @@ | ||
66 | 66 | <data android:mimeType="application/x-mpegurl" /> |
67 | 67 | </intent-filter> |
68 | 68 | </activity> |
69 | + | |
70 | + <!-- we add the activity-alias for shortcut backward compatibility --> | |
71 | + <activity-alias android:name="com.cooliris.media.Gallery" | |
72 | + android:targetActivity="com.android.gallery3d.app.Gallery" | |
73 | + android:configChanges="keyboardHidden|orientation|screenSize" | |
74 | + android:label="string/app_name"> | |
75 | + <intent-filter> | |
76 | + <action android:name="android.intent.action.MAIN" /> | |
77 | + </intent-filter> | |
78 | + </activity-alias> | |
79 | + | |
69 | 80 | <activity android:name="com.android.gallery3d.app.Gallery" android:label="@string/app_name" |
70 | 81 | android:configChanges="keyboardHidden|orientation|screenSize"> |
71 | 82 | <intent-filter> |
@@ -200,18 +211,18 @@ | ||
200 | 211 | android:syncable="false" |
201 | 212 | android:grantUriPermissions="true" |
202 | 213 | android:authorities="com.android.gallery3d.provider" /> |
203 | - <activity android:name="com.android.gallery3d.widget.WidgetClickHandler" /> | |
214 | + <activity android:name="com.android.gallery3d.gadget.WidgetClickHandler" /> | |
204 | 215 | <activity android:name="com.android.gallery3d.app.DialogPicker" |
205 | 216 | android:configChanges="keyboardHidden|orientation|screenSize" |
206 | 217 | android:theme="@style/DialogPickerTheme"/> |
207 | 218 | <activity android:name="com.android.gallery3d.app.AlbumPicker" |
208 | 219 | android:configChanges="keyboardHidden|orientation|screenSize" |
209 | 220 | android:theme="@style/DialogPickerTheme"/> |
210 | - <activity android:name="com.android.gallery3d.widget.WidgetTypeChooser" | |
221 | + <activity android:name="com.android.gallery3d.gadget.WidgetTypeChooser" | |
211 | 222 | android:configChanges="keyboardHidden|orientation|screenSize" |
212 | 223 | android:theme="@style/DialogPickerTheme"/> |
213 | 224 | |
214 | - <receiver android:name="com.android.gallery3d.widget.WidgetProvider" | |
225 | + <receiver android:name="com.android.gallery3d.gadget.PhotoAppWidgetProvider" | |
215 | 226 | android:label="@string/appwidget_title"> |
216 | 227 | <intent-filter> |
217 | 228 | <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> |
@@ -226,9 +237,9 @@ | ||
226 | 237 | <data android:scheme="package"/> |
227 | 238 | </intent-filter> |
228 | 239 | </receiver> |
229 | - <service android:name="com.android.gallery3d.widget.WidgetService" | |
240 | + <service android:name="com.android.gallery3d.gadget.WidgetService" | |
230 | 241 | android:permission="android.permission.BIND_REMOTEVIEWS"/> |
231 | - <activity android:name="com.android.gallery3d.widget.WidgetConfigure" | |
242 | + <activity android:name="com.android.gallery3d.gadget.WidgetConfigure" | |
232 | 243 | android:configChanges="keyboardHidden|orientation|screenSize" |
233 | 244 | android:theme="@style/android:Theme.Translucent.NoTitleBar"> |
234 | 245 | <intent-filter> |
@@ -5,4 +5,4 @@ | ||
5 | 5 | android:updatePeriodMillis="86400000" |
6 | 6 | android:previewImage="@drawable/preview" |
7 | 7 | android:initialLayout="@layout/appwidget_main" |
8 | - android:configure="com.android.gallery3d.widget.WidgetConfigure"/> | |
8 | + android:configure="com.android.gallery3d.gadget.WidgetConfigure"/> |
@@ -19,10 +19,10 @@ package com.android.gallery3d.app; | ||
19 | 19 | import com.android.gallery3d.data.DataManager; |
20 | 20 | import com.android.gallery3d.data.DownloadCache; |
21 | 21 | import com.android.gallery3d.data.ImageCacheService; |
22 | +import com.android.gallery3d.gadget.WidgetUtils; | |
22 | 23 | import com.android.gallery3d.picasasource.PicasaSource; |
23 | 24 | import com.android.gallery3d.util.GalleryUtils; |
24 | 25 | import com.android.gallery3d.util.ThreadPool; |
25 | -import com.android.gallery3d.widget.WidgetUtils; | |
26 | 26 | |
27 | 27 | import android.app.Application; |
28 | 28 | import android.content.Context; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.app.GalleryApp; |
20 | 20 | import com.android.gallery3d.common.Utils; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.common.Utils; |
20 | 20 | import com.android.gallery3d.data.ContentListener; |
@@ -14,21 +14,23 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | -import com.android.gallery3d.widget.WidgetDatabaseHelper.Entry; | |
20 | +import com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry; | |
21 | 21 | |
22 | 22 | import android.app.PendingIntent; |
23 | 23 | import android.appwidget.AppWidgetManager; |
24 | 24 | import android.appwidget.AppWidgetProvider; |
25 | 25 | import android.content.Context; |
26 | 26 | import android.content.Intent; |
27 | +import android.graphics.Bitmap; | |
28 | +import android.graphics.BitmapFactory; | |
27 | 29 | import android.net.Uri; |
28 | 30 | import android.util.Log; |
29 | 31 | import android.widget.RemoteViews; |
30 | 32 | |
31 | -public class WidgetProvider extends AppWidgetProvider { | |
33 | +public class PhotoAppWidgetProvider extends AppWidgetProvider { | |
32 | 34 | |
33 | 35 | private static final String TAG = "WidgetProvider"; |
34 | 36 |
@@ -88,12 +90,26 @@ public class WidgetProvider extends AppWidgetProvider { | ||
88 | 90 | static RemoteViews buildFrameWidget(Context context, int appWidgetId, Entry entry) { |
89 | 91 | RemoteViews views = new RemoteViews( |
90 | 92 | context.getPackageName(), R.layout.photo_frame); |
91 | - views.setImageViewBitmap(R.id.photo, entry.image); | |
92 | - Intent clickIntent = new Intent(context, | |
93 | - WidgetClickHandler.class).setData(entry.imageUri); | |
94 | - PendingIntent pendingClickIntent = PendingIntent.getActivity(context, 0, | |
95 | - clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); | |
96 | - views.setOnClickPendingIntent(R.id.photo, pendingClickIntent); | |
93 | + try { | |
94 | + byte[] data = entry.imageData; | |
95 | + Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); | |
96 | + views.setImageViewBitmap(R.id.photo, bitmap); | |
97 | + } catch (Throwable t) { | |
98 | + Log.w(TAG, "cannot load widget image: " + appWidgetId, t); | |
99 | + } | |
100 | + | |
101 | + if (entry.imageUri != null) { | |
102 | + try { | |
103 | + Uri uri = Uri.parse(entry.imageUri); | |
104 | + Intent clickIntent = new Intent(context, WidgetClickHandler.class) | |
105 | + .setData(uri); | |
106 | + PendingIntent pendingClickIntent = PendingIntent.getActivity(context, 0, | |
107 | + clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); | |
108 | + views.setOnClickPendingIntent(R.id.photo, pendingClickIntent); | |
109 | + } catch (Throwable t) { | |
110 | + Log.w(TAG, "cannot load widget uri: " + appWidgetId, t); | |
111 | + } | |
112 | + } | |
97 | 113 | return views; |
98 | 114 | } |
99 | 115 |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | 20 | import com.android.gallery3d.app.Gallery; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | 20 | import com.android.gallery3d.app.AlbumPicker; |
@@ -72,7 +72,7 @@ public class WidgetConfigure extends Activity { | ||
72 | 72 | |
73 | 73 | private void updateWidgetAndFinish(WidgetDatabaseHelper.Entry entry) { |
74 | 74 | AppWidgetManager manager = AppWidgetManager.getInstance(this); |
75 | - RemoteViews views = WidgetProvider.buildWidget(this, mAppWidgetId, entry); | |
75 | + RemoteViews views = PhotoAppWidgetProvider.buildWidget(this, mAppWidgetId, entry); | |
76 | 76 | manager.updateAppWidget(mAppWidgetId, views); |
77 | 77 | setResult(RESULT_OK, new Intent().putExtra( |
78 | 78 | AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.common.Utils; |
20 | 20 |
@@ -25,11 +25,11 @@ import android.database.sqlite.SQLiteDatabase; | ||
25 | 25 | import android.database.sqlite.SQLiteException; |
26 | 26 | import android.database.sqlite.SQLiteOpenHelper; |
27 | 27 | import android.graphics.Bitmap; |
28 | -import android.graphics.BitmapFactory; | |
29 | 28 | import android.net.Uri; |
30 | 29 | import android.util.Log; |
31 | 30 | |
32 | 31 | import java.io.ByteArrayOutputStream; |
32 | +import java.util.ArrayList; | |
33 | 33 | |
34 | 34 | public class WidgetDatabaseHelper extends SQLiteOpenHelper { |
35 | 35 | private static final String TAG = "PhotoDatabaseHelper"; |
@@ -60,17 +60,18 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper { | ||
60 | 60 | public static class Entry { |
61 | 61 | public int widgetId; |
62 | 62 | public int type; |
63 | - public Uri imageUri; | |
64 | - public Bitmap image; | |
63 | + public String imageUri; | |
64 | + public byte imageData[]; | |
65 | 65 | public String albumPath; |
66 | 66 | |
67 | + private Entry() {} | |
68 | + | |
67 | 69 | private Entry(int id, Cursor cursor) { |
68 | 70 | widgetId = id; |
69 | 71 | type = cursor.getInt(INDEX_WIDGET_TYPE); |
70 | - | |
71 | 72 | if (type == TYPE_SINGLE_PHOTO) { |
72 | - imageUri = Uri.parse(cursor.getString(INDEX_IMAGE_URI)); | |
73 | - image = loadBitmap(cursor, INDEX_PHOTO_BLOB); | |
73 | + imageUri = cursor.getString(INDEX_IMAGE_URI); | |
74 | + imageData = cursor.getBlob(INDEX_PHOTO_BLOB); | |
74 | 75 | } else if (type == TYPE_ALBUM) { |
75 | 76 | albumPath = cursor.getString(INDEX_ALBUM_PATH); |
76 | 77 | } |
@@ -91,16 +92,79 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper { | ||
91 | 92 | + FIELD_PHOTO_BLOB + " BLOB)"); |
92 | 93 | } |
93 | 94 | |
95 | + private void saveData(SQLiteDatabase db, int oldVersion, ArrayList<Entry> data) { | |
96 | + if (oldVersion <= 2) { | |
97 | + Cursor cursor = db.query("photos", | |
98 | + new String[] {FIELD_APPWIDGET_ID, FIELD_PHOTO_BLOB}, | |
99 | + null, null, null, null, null); | |
100 | + if (cursor == null) return; | |
101 | + try { | |
102 | + while (cursor.moveToNext()) { | |
103 | + Entry entry = new Entry(); | |
104 | + entry.type = TYPE_SINGLE_PHOTO; | |
105 | + entry.widgetId = cursor.getInt(0); | |
106 | + entry.imageData = cursor.getBlob(1); | |
107 | + data.add(entry); | |
108 | + } | |
109 | + } finally { | |
110 | + cursor.close(); | |
111 | + } | |
112 | + } else if (oldVersion == 3) { | |
113 | + Utils.debug("saveData of version: %s", oldVersion); | |
114 | + Cursor cursor = db.query("photos", | |
115 | + new String[] {FIELD_APPWIDGET_ID, FIELD_PHOTO_BLOB, FIELD_IMAGE_URI}, | |
116 | + null, null, null, null, null); | |
117 | + if (cursor == null) return; | |
118 | + try { | |
119 | + while (cursor.moveToNext()) { | |
120 | + Entry entry = new Entry(); | |
121 | + entry.type = TYPE_SINGLE_PHOTO; | |
122 | + entry.widgetId = cursor.getInt(0); | |
123 | + entry.imageData = cursor.getBlob(1); | |
124 | + entry.imageUri = cursor.getString(2); | |
125 | + | |
126 | + Utils.debug("store widget[%s] - %s", entry.widgetId, entry.imageUri); | |
127 | + data.add(entry); | |
128 | + } | |
129 | + } finally { | |
130 | + cursor.close(); | |
131 | + } | |
132 | + } | |
133 | + } | |
134 | + | |
135 | + private void restoreData(SQLiteDatabase db, ArrayList<Entry> data) { | |
136 | + db.beginTransaction(); | |
137 | + try { | |
138 | + for (Entry entry : data) { | |
139 | + ContentValues values = new ContentValues(); | |
140 | + values.put(FIELD_APPWIDGET_ID, entry.widgetId); | |
141 | + values.put(FIELD_WIDGET_TYPE, entry.type); | |
142 | + values.put(FIELD_IMAGE_URI, entry.imageUri); | |
143 | + values.put(FIELD_PHOTO_BLOB, entry.imageData); | |
144 | + values.put(FIELD_ALBUM_PATH, entry.albumPath); | |
145 | + db.insert(TABLE_WIDGETS, null, values); | |
146 | + } | |
147 | + db.setTransactionSuccessful(); | |
148 | + } finally { | |
149 | + db.endTransaction(); | |
150 | + } | |
151 | + } | |
152 | + | |
94 | 153 | @Override |
95 | 154 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
96 | 155 | int version = oldVersion; |
97 | 156 | |
98 | 157 | if (version != DATABASE_VERSION) { |
158 | + ArrayList<Entry> data = new ArrayList<Entry>(); | |
159 | + saveData(db, oldVersion, data); | |
160 | + | |
99 | 161 | Log.w(TAG, "destroying all old data."); |
100 | 162 | // Table "photos" is renamed to "widget" in version 4 |
101 | 163 | db.execSQL("DROP TABLE IF EXISTS photos"); |
102 | 164 | db.execSQL("DROP TABLE IF EXISTS " + TABLE_WIDGETS); |
103 | 165 | onCreate(db); |
166 | + | |
167 | + restoreData(db, data); | |
104 | 168 | } |
105 | 169 | } |
106 | 170 |
@@ -146,12 +210,6 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper { | ||
146 | 210 | } |
147 | 211 | } |
148 | 212 | |
149 | - private static Bitmap loadBitmap(Cursor cursor, int columnIndex) { | |
150 | - byte[] data = cursor.getBlob(columnIndex); | |
151 | - if (data == null) return null; | |
152 | - return BitmapFactory.decodeByteArray(data, 0, data.length); | |
153 | - } | |
154 | - | |
155 | 213 | public Entry getEntry(int appWidgetId) { |
156 | 214 | Cursor cursor = null; |
157 | 215 | try { |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | 20 | import com.android.gallery3d.app.GalleryApp; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.data.ContentListener; |
20 | 20 |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | 20 |
@@ -14,7 +14,7 @@ | ||
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -package com.android.gallery3d.widget; | |
17 | +package com.android.gallery3d.gadget; | |
18 | 18 | |
19 | 19 | import com.android.gallery3d.R; |
20 | 20 | import com.android.gallery3d.data.MediaItem; |