コード例 #1
0
  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;
  }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int typeBits = GalleryUtils.determineTypeBits(this, getIntent());
    setTitle(GalleryUtils.getSelectionModePrompt(typeBits));
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    Bundle data = extras == null ? new Bundle() : new Bundle(extras);

    data.putBoolean(Gallery.KEY_GET_CONTENT, true);
    data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(typeBits));
    getStateManager().startState(AlbumSetPage.class, data);
  }
コード例 #3
0
  @Override
  protected boolean onCreateActionBar(Menu menu) {
    Activity activity = mActivity;
    final boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
    MenuInflater inflater = getSupportMenuInflater();

    if (mGetContent) {
      inflater.inflate(R.menu.pickup, menu);
      int typeBits = mData.getInt(GalleryActivity.KEY_TYPE_BITS, DataManager.INCLUDE_IMAGE);
      mActionBar.setTitle(GalleryUtils.getSelectionModePrompt(typeBits));
    } else if (mGetAlbum) {
      inflater.inflate(R.menu.pickup, menu);
      mActionBar.setTitle(R.string.select_album);
    } else {
      inflater.inflate(R.menu.albumset, menu);
      boolean wasShowingClusterMenu = mShowClusterMenu;
      mShowClusterMenu = !inAlbum;
      if (mShowClusterMenu != wasShowingClusterMenu) {
        if (mShowClusterMenu) {
          mActionBar.enableClusterMenu(mSelectedAction, this);
        } else {
          mActionBar.disableClusterMenu(true);
        }
      }
      boolean selectAlbums =
          !inAlbum && mActionBar.getClusterTypeAction() == FilterUtils.CLUSTER_BY_ALBUM;
      MenuItem selectItem = menu.findItem(R.id.action_select);
      selectItem.setTitle(
          activity.getString(selectAlbums ? R.string.select_album : R.string.select_group));

      MenuItem cameraItem = menu.findItem(R.id.action_camera);
      cameraItem.setVisible(GalleryUtils.isCameraAvailable(activity));

      FilterUtils.setupMenuItems(mActionBar, mMediaSet.getPath(), false);

      Intent helpIntent = HelpUtils.getHelpIntent(activity);

      MenuItem helpItem = menu.findItem(R.id.action_general_help);
      helpItem.setVisible(helpIntent != null);
      if (helpIntent != null) helpItem.setIntent(helpIntent);

      MenuItem moreItem = menu.findItem(R.id.action_more_image);
      moreItem.setVisible(mActivity.getResources().getBoolean(R.bool.config_show_more_images));

      mActionBar.setTitle(mTitle);
      mActionBar.setSubtitle(mSubtitle);
    }
    return true;
  }
コード例 #4
0
 // 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;
 }
コード例 #5
0
  @Override
  protected void onCreate(Bundle data, Bundle restoreState) {
    super.onCreate(data, restoreState);
    mUserDistance = GalleryUtils.meterToPixel(USER_DISTANCE_METER);
    initializeViews();
    initializeData(data);
    mGetContent = data.getBoolean(GalleryActivity.KEY_GET_CONTENT, false);
    mShowClusterMenu = data.getBoolean(KEY_SHOW_CLUSTER_MENU, false);
    mDetailsSource = new MyDetailsSource();
    Context context = mActivity.getAndroidContext();

    if (data.getBoolean(KEY_AUTO_SELECT_ALL)) {
      mSelectionManager.selectAll();
    }

    mLaunchedFromPhotoPage = mActivity.getStateManager().hasStateClass(FilmstripPage.class);
    mInCameraApp = data.getBoolean(PhotoPage.KEY_APP_BRIDGE, false);

    mHandler =
        new SynchronizedHandler(mActivity.getGLRoot()) {
          @Override
          public void handleMessage(Message message) {
            switch (message.what) {
              case MSG_PICK_PHOTO:
                {
                  pickPhoto(message.arg1);
                  break;
                }
              default:
                throw new AssertionError(message.what);
            }
          }
        };
  }
コード例 #6
0
  @Override
  public ArrayList<MediaItem> getMediaItem(int start, int count) {
    DataManager dataManager = mApplication.getDataManager();
    Uri uri = mBaseUri.buildUpon().appendQueryParameter("limit", start + "," + count).build();
    ArrayList<MediaItem> list = new ArrayList<MediaItem>();
    GalleryUtils.assertNotInRenderThread();
    Cursor cursor =
        mResolver.query(
            uri, mProjection, mWhereClause, new String[] {String.valueOf(mBucketId)}, mOrderClause);
    if (cursor == null) {
      Log.w(TAG, "query fail: " + uri);
      return list;
    }

    try {
      while (cursor.moveToNext()) {
        int id = cursor.getInt(0); // _id must be in the first column
        Path childPath = mItemPath.getChild(id);
        MediaItem item = loadOrUpdateItem(childPath, cursor, dataManager, mApplication, mIsImage);
        list.add(item);
      }
    } finally {
      cursor.close();
    }
    return list;
  }
コード例 #7
0
 @Override
 protected void render(GLCanvas canvas) {
   canvas.save(GLCanvas.SAVE_FLAG_MATRIX);
   GalleryUtils.setViewPointMatrix(mMatrix, getWidth() / 2 + mX, getHeight() / 2 + mY, mZ);
   canvas.multiplyMatrix(mMatrix, 0);
   super.render(canvas);
   canvas.restore();
 }
コード例 #8
0
 @Override
 protected boolean onItemSelected(MenuItem item) {
   Activity activity = mActivity;
   switch (item.getItemId()) {
     case R.id.action_more_image:
       Uri moreUri = Uri.parse(mActivity.getString(R.string.website_for_more_image));
       Intent moreIntent = new Intent(Intent.ACTION_VIEW, moreUri);
       mActivity.startActivity(moreIntent);
       return true;
     case R.id.action_cancel:
       activity.setResult(Activity.RESULT_CANCELED);
       activity.finish();
       return true;
     case R.id.action_select:
       mSelectionManager.setAutoLeaveSelectionMode(false);
       mSelectionManager.enterSelectionMode();
       return true;
     case R.id.action_details:
       if (mAlbumSetDataAdapter.size() != 0) {
         if (mShowDetails) {
           hideDetails();
         } else {
           showDetails();
         }
       } else {
         Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT)
             .show();
       }
       return true;
     case R.id.action_camera:
       {
         GalleryUtils.startCameraActivity(activity);
         return true;
       }
     case R.id.action_manage_offline:
       {
         Bundle data = new Bundle();
         String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
         data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
         mActivity.getStateManager().startState(ManageCachePage.class, data);
         return true;
       }
     case R.id.action_sync_picasa_albums:
       {
         PicasaSource.requestSync(activity);
         return true;
       }
     case R.id.action_settings:
       {
         activity.startActivity(new Intent(activity, GallerySettings.class));
         return true;
       }
     default:
       return false;
   }
 }
コード例 #9
0
ファイル: AlbumSetPage.java プロジェクト: schukje/Project-M
  @Override
  protected boolean onItemSelected(MenuItem item) {
    Activity activity = mActivity;
    switch (item.getItemId()) {
      case R.id.action_cancel:
        activity.setResult(Activity.RESULT_CANCELED);
        activity.finish();
        return true;
      case R.id.action_select:
        mSelectionManager.setAutoLeaveSelectionMode(false);
        mSelectionManager.enterSelectionMode();
        return true;
      case R.id.action_details:
        if (mAlbumSetDataAdapter.size() != 0) {
          if (mShowDetails) {
            hideDetails();
          } else {
            showDetails();
          }
        } else {
          Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT)
              .show();
        }
        return true;
      case R.id.action_camera:
        {
          GalleryUtils.startCameraActivity(activity);
          return true;
        }
      case R.id.action_manage_offline:
        {
          Bundle data = new Bundle();
          String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
          data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
          mActivity.getStateManager().startState(ManageCachePage.class, data);
          return true;
        }
      case R.id.action_sync_picasa_albums:
        {
          PicasaSource.requestSync(activity);
          return true;
        }
        /*   Comment out to enable Settings in menu. This should be done when
             GallerySettings.java has content, as it is currently empty.
             Also comment out the settings item at albumset.xml menu.

                    case R.id.action_settings: {
                        activity.startActivity(new Intent(activity, GallerySettings.class));
                        return true;
                    }
        */
      default:
        return false;
    }
  }
コード例 #10
0
 private void onUpPressed() {
   if (mInCameraApp) {
     GalleryUtils.startGalleryActivity(mActivity);
   } else if (mActivity.getStateManager().getStateCount() > 1) {
     super.onBackPressed();
   } else if (mParentMediaSetString != null) {
     Bundle data = new Bundle(getData());
     data.putString(AlbumSetPage.KEY_MEDIA_PATH, mParentMediaSetString);
     mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
   }
 }
コード例 #11
0
ファイル: MediaSetUtils.java プロジェクト: gityouzi/Camera
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();
   }
 }
コード例 #13
0
 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
       }
     }
   }
 }
コード例 #14
0
ファイル: LocalMediaItem.java プロジェクト: Snotbob/chanu
  @Override
  public MediaDetails getDetails() {
    MediaDetails details = super.getDetails();
    details.addDetail(MediaDetails.INDEX_PATH, filePath);
    details.addDetail(MediaDetails.INDEX_TITLE, caption);
    DateFormat formater = DateFormat.getDateTimeInstance();
    details.addDetail(MediaDetails.INDEX_DATETIME, formater.format(new Date(dateTakenInMs)));

    if (GalleryUtils.isValidLocation(latitude, longitude)) {
      details.addDetail(MediaDetails.INDEX_LOCATION, new double[] {latitude, longitude});
    }
    if (fileSize > 0) details.addDetail(MediaDetails.INDEX_SIZE, fileSize);
    return details;
  }
コード例 #15
0
  @Override
  protected boolean onCreateActionBar(Menu menu) {
    GalleryActionBar actionBar = mActivity.getGalleryActionBar();
    MenuInflater inflator = getSupportMenuInflater();
    if (mGetContent) {
      inflator.inflate(R.menu.pickup, menu);
      int typeBits = mData.getInt(GalleryActivity.KEY_TYPE_BITS, DataManager.INCLUDE_IMAGE);
      actionBar.setTitle(GalleryUtils.getSelectionModePrompt(typeBits));
    } else {
      inflator.inflate(R.menu.album, menu);
      actionBar.setTitle(mMediaSet.getName());

      FilterUtils.setupMenuItems(actionBar, mMediaSetPath, true);

      menu.findItem(R.id.action_group_by).setVisible(mShowClusterMenu);
      menu.findItem(R.id.action_camera)
          .setVisible(
              MediaSetUtils.isCameraSource(mMediaSetPath)
                  && GalleryUtils.isCameraAvailable(mActivity));
    }
    actionBar.setSubtitle(null);
    return true;
  }
コード例 #16
0
 @Override
 protected boolean onItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       {
         onUpPressed();
         return true;
       }
     case R.id.action_cancel:
       mActivity.getStateManager().finishState(this);
       return true;
     case R.id.action_select:
       mSelectionManager.setAutoLeaveSelectionMode(false);
       mSelectionManager.enterSelectionMode();
       return true;
     case R.id.action_group_by:
       {
         mActivity.getGalleryActionBar().showClusterDialog(this);
         return true;
       }
     case R.id.action_slideshow:
       {
         mInCameraAndWantQuitOnPause = false;
         Bundle data = new Bundle();
         data.putString(SlideshowPage.KEY_SET_PATH, mMediaSetPath.toString());
         data.putBoolean(SlideshowPage.KEY_REPEAT, true);
         mActivity
             .getStateManager()
             .startStateForResult(SlideshowPage.class, REQUEST_SLIDESHOW, data);
         return true;
       }
     case R.id.action_details:
       {
         if (mShowDetails) {
           hideDetails();
         } else {
           showDetails();
         }
         return true;
       }
     case R.id.action_camera:
       {
         GalleryUtils.startCameraActivity(mActivity);
         return true;
       }
     default:
       return false;
   }
 }
コード例 #17
0
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

          int slotViewTop = mActivity.getGalleryActionBar().getHeight() + mConfig.paddingTop;
          int slotViewBottom = bottom - top - mConfig.paddingBottom;
          int slotViewRight = right - left - mConfig.paddingRight;

          if (mShowDetails) {
            mDetailsHelper.layout(left, slotViewTop, right, bottom);
          } else {
            mAlbumView.setHighlightItemPath(null);
          }

          // Set the mSlotView as a reference point to the open animation
          mOpenCenter.setReferencePosition(mConfig.paddingLeft, slotViewTop);
          mSlotView.layout(mConfig.paddingLeft, slotViewTop, slotViewRight, slotViewBottom);
          GalleryUtils.setViewPointMatrix(
              mMatrix, (right - left) / 2, (bottom - top) / 2, -mUserDistance);
        }
コード例 #18
0
  private boolean setupCameraButton() {
    if (!GalleryUtils.isCameraAvailable(mActivity)) return false;
    RelativeLayout galleryRoot =
        (RelativeLayout) ((Activity) mActivity).findViewById(R.id.gallery_root);
    if (galleryRoot == null) return false;

    mCameraButton = new Button(mActivity);
    mCameraButton.setText(R.string.camera_label);
    mCameraButton.setCompoundDrawablesWithIntrinsicBounds(
        0, R.drawable.frame_overlay_gallery_camera, 0, 0);
    mCameraButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            GalleryUtils.startCameraActivity(mActivity);
          }
        });
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    galleryRoot.addView(mCameraButton, lp);
    return true;
  }
コード例 #19
0
 @Override
 public void delete() {
   GalleryUtils.assertNotInRenderThread();
   mResolver.delete(mBaseUri, mWhereClause, new String[] {String.valueOf(mBucketId)});
 }