summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/gadget
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2012-12-12 17:47:12 -0800
committerDoris Liu <tianliu@google.com>2012-12-14 17:09:12 -0800
commit3b0ed25fd416934fabb7003c1d2981b3a311186d (patch)
tree7fb302da1892e685c84d533e279a7e9509e799fd /src/com/android/gallery3d/gadget
parentb8378fae9f19191d2706e3579158aaf3c2ffe75e (diff)
downloadandroid_packages_apps_Snap-3b0ed25fd416934fabb7003c1d2981b3a311186d.tar.gz
android_packages_apps_Snap-3b0ed25fd416934fabb7003c1d2981b3a311186d.tar.bz2
android_packages_apps_Snap-3b0ed25fd416934fabb7003c1d2981b3a311186d.zip
Add relativePath field into photo widget db
Bug: 7481248 The bug is caused by the change of external storage going from JB to JBMR1. In light of this change, a new field has been added to the photo widget app database to store the relative path for the local album. With the relative paths stored, the widget app should be more resilient to future storage path changes. Change-Id: Ia2497b882ae67178fa0632f23e07673b82d3a942
Diffstat (limited to 'src/com/android/gallery3d/gadget')
-rw-r--r--src/com/android/gallery3d/gadget/WidgetConfigure.java23
-rw-r--r--src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java35
2 files changed, 47 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/gadget/WidgetConfigure.java b/src/com/android/gallery3d/gadget/WidgetConfigure.java
index 3a1b52bdc..4818d261b 100644
--- a/src/com/android/gallery3d/gadget/WidgetConfigure.java
+++ b/src/com/android/gallery3d/gadget/WidgetConfigure.java
@@ -23,12 +23,18 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
+import android.util.Log;
import android.widget.RemoteViews;
import com.android.gallery3d.R;
import com.android.gallery3d.app.AlbumPicker;
import com.android.gallery3d.app.DialogPicker;
+import com.android.gallery3d.app.GalleryApp;
import com.android.gallery3d.common.ApiHelper;
+import com.android.gallery3d.data.DataManager;
+import com.android.gallery3d.data.LocalAlbum;
+import com.android.gallery3d.data.MediaSet;
+import com.android.gallery3d.data.Path;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.CropExtras;
@@ -158,8 +164,21 @@ public class WidgetConfigure extends Activity {
String albumPath = data.getStringExtra(AlbumPicker.KEY_ALBUM_PATH);
WidgetDatabaseHelper helper = new WidgetDatabaseHelper(this);
try {
+ String relativePath = null;
+ GalleryApp galleryApp = (GalleryApp) getApplicationContext();
+ DataManager manager = galleryApp.getDataManager();
+ Path path = Path.fromString(albumPath);
+ MediaSet mediaSet = (MediaSet) manager.getMediaObject(path);
+ if (mediaSet instanceof LocalAlbum) {
+ int bucketId = Integer.parseInt(path.getSuffix());
+ // If the chosen album is a local album, find relative path
+ // Otherwise, leave the relative path field empty
+ relativePath = LocalAlbum.getRelativePath(bucketId);
+ Log.i(TAG, "Setting widget, album path: " + albumPath
+ + ", relative path: " + relativePath);
+ }
helper.setWidget(mAppWidgetId,
- WidgetDatabaseHelper.TYPE_ALBUM, albumPath);
+ WidgetDatabaseHelper.TYPE_ALBUM, albumPath, relativePath);
updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
} finally {
helper.close();
@@ -174,7 +193,7 @@ public class WidgetConfigure extends Activity {
} else if (widgetType == R.id.widget_type_shuffle) {
WidgetDatabaseHelper helper = new WidgetDatabaseHelper(this);
try {
- helper.setWidget(mAppWidgetId, WidgetDatabaseHelper.TYPE_SHUFFLE, null);
+ helper.setWidget(mAppWidgetId, WidgetDatabaseHelper.TYPE_SHUFFLE, null, null);
updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
} finally {
helper.close();
diff --git a/src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java b/src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java
index c411c365f..c0145843b 100644
--- a/src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java
+++ b/src/com/android/gallery3d/gadget/WidgetDatabaseHelper.java
@@ -36,7 +36,9 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "PhotoDatabaseHelper";
private static final String DATABASE_NAME = "launcher.db";
- private static final int DATABASE_VERSION = 4;
+ // Increment the database version to 5. In version 5, we
+ // add a column in widgets table to record relative paths.
+ private static final int DATABASE_VERSION = 5;
private static final String TABLE_WIDGETS = "widgets";
@@ -45,6 +47,7 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
private static final String FIELD_PHOTO_BLOB = "photoBlob";
private static final String FIELD_WIDGET_TYPE = "widgetType";
private static final String FIELD_ALBUM_PATH = "albumPath";
+ private static final String FIELD_RELATIVE_PATH = "relativePath";
public static final int TYPE_SINGLE_PHOTO = 0;
public static final int TYPE_SHUFFLE = 1;
@@ -52,12 +55,13 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
private static final String[] PROJECTION = {
FIELD_WIDGET_TYPE, FIELD_IMAGE_URI, FIELD_PHOTO_BLOB, FIELD_ALBUM_PATH,
- FIELD_APPWIDGET_ID};
+ FIELD_APPWIDGET_ID, FIELD_RELATIVE_PATH};
private static final int INDEX_WIDGET_TYPE = 0;
private static final int INDEX_IMAGE_URI = 1;
private static final int INDEX_PHOTO_BLOB = 2;
private static final int INDEX_ALBUM_PATH = 3;
private static final int INDEX_APPWIDGET_ID = 4;
+ private static final int INDEX_RELATIVE_PATH = 5;
private static final String WHERE_APPWIDGET_ID = FIELD_APPWIDGET_ID + " = ?";
private static final String WHERE_WIDGET_TYPE = FIELD_WIDGET_TYPE + " = ?";
@@ -67,6 +71,7 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
public String imageUri;
public byte imageData[];
public String albumPath;
+ public String relativePath;
private Entry() {}
@@ -78,6 +83,7 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
imageData = cursor.getBlob(INDEX_PHOTO_BLOB);
} else if (type == TYPE_ALBUM) {
albumPath = cursor.getString(INDEX_ALBUM_PATH);
+ relativePath = cursor.getString(INDEX_RELATIVE_PATH);
}
}
@@ -97,7 +103,8 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
+ FIELD_WIDGET_TYPE + " INTEGER DEFAULT 0, "
+ FIELD_IMAGE_URI + " TEXT, "
+ FIELD_ALBUM_PATH + " TEXT, "
- + FIELD_PHOTO_BLOB + " BLOB)");
+ + FIELD_PHOTO_BLOB + " BLOB, "
+ + FIELD_RELATIVE_PATH + " TEXT)");
}
private void saveData(SQLiteDatabase db, int oldVersion, ArrayList<Entry> data) {
@@ -157,20 +164,27 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- int version = oldVersion;
-
- if (version != DATABASE_VERSION) {
+ if (oldVersion < 4) {
+ // Table "photos" is renamed to "widget" in version 4
ArrayList<Entry> data = new ArrayList<Entry>();
saveData(db, oldVersion, data);
Log.w(TAG, "destroying all old data.");
- // Table "photos" is renamed to "widget" in version 4
db.execSQL("DROP TABLE IF EXISTS photos");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_WIDGETS);
onCreate(db);
restoreData(db, data);
}
+ // Add a column for relative path
+ if (oldVersion < DATABASE_VERSION) {
+ try {
+ db.execSQL("ALTER TABLE widgets ADD COLUMN relativePath TEXT");
+ } catch (Throwable t) {
+ Log.e(TAG, "Failed to add the column for relative path.");
+ return;
+ }
+ }
}
/**
@@ -201,12 +215,13 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
}
}
- public boolean setWidget(int id, int type, String albumPath) {
+ public boolean setWidget(int id, int type, String albumPath, String relativePath) {
try {
ContentValues values = new ContentValues();
values.put(FIELD_APPWIDGET_ID, id);
values.put(FIELD_WIDGET_TYPE, type);
values.put(FIELD_ALBUM_PATH, Utils.ensureNotNull(albumPath));
+ values.put(FIELD_RELATIVE_PATH, relativePath);
getWritableDatabase().replaceOrThrow(TABLE_WIDGETS, null, values);
return true;
} catch (Throwable e) {
@@ -223,7 +238,8 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
WHERE_APPWIDGET_ID, new String[] {String.valueOf(appWidgetId)},
null, null, null);
if (cursor == null || !cursor.moveToNext()) {
- Log.e(TAG, "query fail: empty cursor: " + cursor);
+ Log.e(TAG, "query fail: empty cursor: " + cursor + " appWidgetId: "
+ + appWidgetId);
return null;
}
return new Entry(appWidgetId, cursor);
@@ -271,6 +287,7 @@ public class WidgetDatabaseHelper extends SQLiteOpenHelper {
values.put(FIELD_ALBUM_PATH, entry.albumPath);
values.put(FIELD_IMAGE_URI, entry.imageUri);
values.put(FIELD_PHOTO_BLOB, entry.imageData);
+ values.put(FIELD_RELATIVE_PATH, entry.relativePath);
getWritableDatabase().insert(TABLE_WIDGETS, null, values);
} catch (Throwable e) {
Log.e(TAG, "set widget fail", e);