Beispiel #1
0
public class MediaSetUtils {
  public static final Comparator<MediaSet> NAME_COMPARATOR = new NameComparator();

  public static final int CAMERA_BUCKET_ID =
      GalleryUtils.getBucketId(
          Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera");
  public static final int DOWNLOAD_BUCKET_ID =
      GalleryUtils.getBucketId(
          Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.DOWNLOAD);
  public static final int EDITED_ONLINE_PHOTOS_BUCKET_ID =
      GalleryUtils.getBucketId(
          Environment.getExternalStorageDirectory().toString()
              + "/"
              + BucketNames.EDITED_ONLINE_PHOTOS);
  public static final int IMPORTED_BUCKET_ID =
      GalleryUtils.getBucketId(
          Environment.getExternalStorageDirectory().toString() + "/" + BucketNames.IMPORTED);
  public static final int SNAPSHOT_BUCKET_ID =
      GalleryUtils.getBucketId(
          Environment.getExternalStorageDirectory().toString() + "/Pictures/Screenshots");

  private static final Path[] CAMERA_PATHS = {
    Path.fromString("/local/all/" + CAMERA_BUCKET_ID),
    Path.fromString("/local/image/" + CAMERA_BUCKET_ID),
    Path.fromString("/local/video/" + CAMERA_BUCKET_ID)
  };

  public static boolean isCameraSource(Path path) {
    return CAMERA_PATHS[0] == path || CAMERA_PATHS[1] == path || CAMERA_PATHS[2] == path;
  }

  // Sort MediaSets by name
  public static class NameComparator implements Comparator<MediaSet> {
    @Override
    public int compare(MediaSet set1, MediaSet set2) {
      int result = set1.getName().compareToIgnoreCase(set2.getName());
      if (result != 0) return result;
      return set1.getPath().toString().compareTo(set2.getPath().toString());
    }
  }
}
 public void saveImage() {
   if (mImageShow.hasModifications()) {
     // Get the name of the album, to which the image will be saved
     File saveDir = SaveCopyTask.getFinalSaveDirectory(this, mImageLoader.getUri());
     int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
     String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
     showSavingProgress(albumName);
     mImageShow.saveImage(this, null);
   } else {
     finish();
   }
 }
 private static void updatePath(
     File root, HashMap<Integer, Entry> entries, WidgetDatabaseHelper dbHelper) {
   File[] files = root.listFiles();
   if (files != null) {
     for (File file : files) {
       if (file.isDirectory() && !entries.isEmpty()) {
         String path = file.getAbsolutePath();
         String oldPath = OLD_EXT_PATH + path.substring(RELATIVE_PATH_START);
         int oldBucketId = GalleryUtils.getBucketId(oldPath);
         Entry entry = entries.remove(oldBucketId);
         if (entry != null) {
           int newBucketId = GalleryUtils.getBucketId(path);
           String newAlbumPath =
               Path.fromString(entry.albumPath).getParent().getChild(newBucketId).toString();
           Log.d(TAG, "migrate from " + entry.albumPath + " to " + newAlbumPath);
           entry.albumPath = newAlbumPath;
           dbHelper.updateEntry(entry);
         }
         updatePath(file, entries, dbHelper); // recursion
       }
     }
   }
 }