From fcf54601d45bfcef2fbeb911c46ff394e84d7011 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Wed, 12 Dec 2012 17:47:12 -0800 Subject: 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 --- src/com/android/gallery3d/util/BucketNames.java | 2 ++ src/com/android/gallery3d/util/GalleryUtils.java | 21 +++++++++++++++++++++ src/com/android/gallery3d/util/MediaSetUtils.java | 5 +++-- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/com/android/gallery3d/util') diff --git a/src/com/android/gallery3d/util/BucketNames.java b/src/com/android/gallery3d/util/BucketNames.java index df7684a04..990dc8224 100644 --- a/src/com/android/gallery3d/util/BucketNames.java +++ b/src/com/android/gallery3d/util/BucketNames.java @@ -21,7 +21,9 @@ package com.android.gallery3d.util; */ public class BucketNames { + public static final String CAMERA = "DCIM/Camera"; public static final String IMPORTED = "Imported"; public static final String DOWNLOAD = "download"; public static final String EDITED_ONLINE_PHOTOS = "EditedOnlinePhotos"; + public static final String SCREENSHOTS = "Pictures/Screenshots"; } diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 1e5d8d5fe..9245e2c5f 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -46,6 +46,7 @@ import com.android.gallery3d.ui.TiledScreenNail; import com.android.gallery3d.util.ThreadPool.CancelListener; import com.android.gallery3d.util.ThreadPool.JobContext; +import java.io.File; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -309,6 +310,26 @@ public class GalleryUtils { return path.toLowerCase().hashCode(); } + // Return the local path that matches the given bucketId. If no match is + // found, return null + public static String searchDirForPath(File dir, int bucketId) { + File[] files = dir.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + String path = file.getAbsolutePath(); + if (GalleryUtils.getBucketId(path) == bucketId) { + return path; + } else { + path = searchDirForPath(file, bucketId); + if (path != null) return path; + } + } + } + } + return null; + } + // Returns a (localized) string for the given duration (in seconds). public static String formatDuration(final Context context, int duration) { int h = duration / 3600; diff --git a/src/com/android/gallery3d/util/MediaSetUtils.java b/src/com/android/gallery3d/util/MediaSetUtils.java index 83b6b320b..043800561 100644 --- a/src/com/android/gallery3d/util/MediaSetUtils.java +++ b/src/com/android/gallery3d/util/MediaSetUtils.java @@ -29,7 +29,8 @@ public class MediaSetUtils { public static final Comparator NAME_COMPARATOR = new NameComparator(); public static final int CAMERA_BUCKET_ID = GalleryUtils.getBucketId( - Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera"); + Environment.getExternalStorageDirectory().toString() + "/" + + BucketNames.CAMERA); public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId( Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.DOWNLOAD); @@ -41,7 +42,7 @@ public class MediaSetUtils { + BucketNames.IMPORTED); public static final int SNAPSHOT_BUCKET_ID = GalleryUtils.getBucketId( Environment.getExternalStorageDirectory().toString() + - "/Pictures/Screenshots"); + "/" + BucketNames.SCREENSHOTS); private static final Path[] CAMERA_PATHS = { Path.fromString("/local/all/" + CAMERA_BUCKET_ID), -- cgit v1.2.3