diff options
author | Doris Liu <tianliu@google.com> | 2012-12-12 17:47:12 -0800 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2012-12-14 17:09:12 -0800 |
commit | 3b0ed25fd416934fabb7003c1d2981b3a311186d (patch) | |
tree | 7fb302da1892e685c84d533e279a7e9509e799fd /src/com/android/gallery3d/data/LocalAlbum.java | |
parent | b8378fae9f19191d2706e3579158aaf3c2ffe75e (diff) | |
download | android_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/data/LocalAlbum.java')
-rw-r--r-- | src/com/android/gallery3d/data/LocalAlbum.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/data/LocalAlbum.java b/src/com/android/gallery3d/data/LocalAlbum.java index 6c5feb5c8..7b7015af6 100644 --- a/src/com/android/gallery3d/data/LocalAlbum.java +++ b/src/com/android/gallery3d/data/LocalAlbum.java @@ -20,6 +20,7 @@ import android.content.ContentResolver; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; +import android.os.Environment; import android.provider.MediaStore; import android.provider.MediaStore.Images; import android.provider.MediaStore.Images.ImageColumns; @@ -29,9 +30,11 @@ import android.provider.MediaStore.Video.VideoColumns; import com.android.gallery3d.R; import com.android.gallery3d.app.GalleryApp; import com.android.gallery3d.common.Utils; +import com.android.gallery3d.util.BucketNames; import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.MediaSetUtils; +import java.io.File; import java.util.ArrayList; // LocalAlbumSet lists all media items in one bucket on local storage. @@ -290,4 +293,33 @@ public class LocalAlbum extends MediaSet { return name; } } + + // Relative path is the absolute path minus external storage path + public static String getRelativePath(int bucketId) { + String relativePath = "/"; + if (bucketId == MediaSetUtils.CAMERA_BUCKET_ID) { + relativePath += BucketNames.CAMERA; + } else if (bucketId == MediaSetUtils.DOWNLOAD_BUCKET_ID) { + relativePath += BucketNames.DOWNLOAD; + } else if (bucketId == MediaSetUtils.IMPORTED_BUCKET_ID) { + relativePath += BucketNames.IMPORTED; + } else if (bucketId == MediaSetUtils.SNAPSHOT_BUCKET_ID) { + relativePath += BucketNames.SCREENSHOTS; + } else if (bucketId == MediaSetUtils.EDITED_ONLINE_PHOTOS_BUCKET_ID) { + relativePath += BucketNames.EDITED_ONLINE_PHOTOS; + } else { + // If the first few cases didn't hit the matching path, do a + // thorough search in the local directories. + File extStorage = Environment.getExternalStorageDirectory(); + String path = GalleryUtils.searchDirForPath(extStorage, bucketId); + if (path == null) { + Log.w(TAG, "Relative path for bucket id: " + bucketId + " is not found."); + relativePath = null; + } else { + relativePath = path.substring(extStorage.getAbsolutePath().length()); + } + } + return relativePath; + } + } |