private static void migrateGalleryWidgetsInternal(Context context) {
    GalleryApp galleryApp = (GalleryApp) context.getApplicationContext();
    DataManager manager = galleryApp.getDataManager();
    WidgetDatabaseHelper dbHelper = new WidgetDatabaseHelper(context);

    // only need to migrate local-album entries of type TYPE_ALBUM
    List<Entry> entries = dbHelper.getEntries(WidgetDatabaseHelper.TYPE_ALBUM);
    if (entries != null) {
      HashMap<Integer, Entry> localEntries = new HashMap<Integer, Entry>(entries.size());
      for (Entry entry : entries) {
        Path path = Path.fromString(entry.albumPath);
        MediaSet mediaSet = (MediaSet) manager.getMediaObject(path);
        if (mediaSet instanceof LocalAlbum) {
          int bucketId = Integer.parseInt(path.getSuffix());
          localEntries.put(bucketId, entry);
        }
      }
      if (!localEntries.isEmpty()) migrateLocalEntries(localEntries, dbHelper);
    }
  }
 private void onGetContent(final MediaItem item) {
   DataManager dm = mActivity.getDataManager();
   Activity activity = mActivity;
   if (mData.getString(GalleryActivity.EXTRA_CROP) != null) {
     Uri uri = dm.getContentUri(item.getPath());
     Intent intent =
         new Intent(CropActivity.CROP_ACTION, uri)
             .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
             .putExtras(getData());
     if (mData.getParcelable(MediaStore.EXTRA_OUTPUT) == null) {
       intent.putExtra(CropExtras.KEY_RETURN_DATA, true);
     }
     activity.startActivity(intent);
     activity.finish();
   } else {
     Intent intent =
         new Intent(null, item.getContentUri()).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
     activity.setResult(Activity.RESULT_OK, intent);
     activity.finish();
   }
 }
  private boolean execute(DataManager manager, JobContext jc, int cmd, Path path) {
    boolean result = true;
    Log.v(TAG, "Execute cmd: " + cmd + " for " + path);
    long startTime = System.currentTimeMillis();

    switch (cmd) {
      case R.id.action_delete:
        manager.delete(path);
        break;
      case R.id.action_rotate_cw:
        manager.rotate(path, 90);
        break;
      case R.id.action_rotate_ccw:
        manager.rotate(path, -90);
        break;
      case R.id.action_toggle_full_caching:
        {
          MediaObject obj = manager.getMediaObject(path);
          int cacheFlag = obj.getCacheFlag();
          if (cacheFlag == MediaObject.CACHE_FLAG_FULL) {
            cacheFlag = MediaObject.CACHE_FLAG_SCREENNAIL;
          } else {
            cacheFlag = MediaObject.CACHE_FLAG_FULL;
          }
          obj.cache(cacheFlag);
          break;
        }
      case R.id.action_show_on_map:
        {
          MediaItem item = (MediaItem) manager.getMediaObject(path);
          double latlng[] = new double[2];
          item.getLatLong(latlng);
          if (GalleryUtils.isValidLocation(latlng[0], latlng[1])) {
            GalleryUtils.showOnMap((Context) mActivity, latlng[0], latlng[1]);
          }
          break;
        }
      case R.id.action_import:
        {
          MediaObject obj = manager.getMediaObject(path);
          result = obj.Import();
          break;
        }
      default:
        throw new AssertionError();
    }
    Log.v(
        TAG,
        "It takes " + (System.currentTimeMillis() - startTime) + " ms to execute cmd for " + path);
    return result;
  }
 private Intent getIntentBySingleSelectedPath(String action) {
   DataManager manager = mActivity.getDataManager();
   Path path = getSingleSelectedPath();
   String mimeType = getMimeType(manager.getMediaType(path));
   return new Intent(action).setDataAndType(manager.getContentUri(path), mimeType);
 }