public void onLongTap(int slotIndex) {
   if (mGetContent || mGetAlbum) return;
   MediaSet set = mAlbumSetDataAdapter.getMediaSet(slotIndex);
   if (set == null) return;
   mSelectionManager.setAutoLeaveSelectionMode(true);
   mSelectionManager.toggle(set.getPath());
   mSlotView.invalidate();
 }
 @Override
 public void onSyncDone(final MediaSet mediaSet, final int resultCode) {
   if (resultCode == MediaSet.SYNC_RESULT_ERROR) {
     Log.d(
         TAG, "onSyncDone: " + Utils.maskDebugInfo(mediaSet.getName()) + " result=" + resultCode);
   }
   ((Activity) mActivity)
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               GLRoot root = mActivity.getGLRoot();
               root.lockRenderThread();
               try {
                 if (resultCode == MediaSet.SYNC_RESULT_SUCCESS) {
                   mInitialSynced = true;
                 }
                 clearLoadingBit(BIT_LOADING_SYNC);
                 if (resultCode == MediaSet.SYNC_RESULT_ERROR && mIsActive) {
                   Log.w(TAG, "failed to load album set");
                 }
               } finally {
                 root.unlockRenderThread();
               }
             }
           });
 }
  public void onSingleTapUp(int slotIndex) {
    if (!mIsActive) return;

    if (mSelectionManager.inSelectionMode()) {
      MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
      if (targetSet == null) return; // Content is dirty, we shall reload soon
      mSelectionManager.toggle(targetSet.getPath());
      mSlotView.invalidate();
    } else {
      // Show pressed-up animation for the single-tap.
      mAlbumSetView.setPressedIndex(slotIndex);
      mAlbumSetView.setPressedUp();
      mHandler.sendMessageDelayed(
          mHandler.obtainMessage(MSG_PICK_ALBUM, slotIndex, 0), FadeTexture.DURATION);
    }
  }
Ejemplo n.º 4
0
  @Override
  public void onResume() {
    super.onResume();
    mIsActive = true;
    setContentPane(mRootPane);

    // Set the reload bit here to prevent it exit this page in clearLoadingBit().
    setLoadingBit(BIT_LOADING_RELOAD);
    mAlbumSetDataAdapter.resume();

    mAlbumSetView.resume();
    mEyePosition.resume();
    mActionModeHandler.resume();
    if (mShowClusterMenu) {
      mActionBar.enableClusterMenu(mSelectedAction, this);
    }
    if (!mInitialSynced) {
      setLoadingBit(BIT_LOADING_SYNC);
      mSyncTask = mMediaSet.requestSync(AlbumSetPage.this);
    }
    // jiangxd add for dockbar
    if (mActivity instanceof Gallery) {
      ((Gallery) mActivity).setDockBarVisible(false);
    }
    // end
  }
  @Override
  public void doCluster(int clusterType) {
    String basePath = mMediaSet.getPath().toString();
    String newPath = FilterUtils.newClusterPath(basePath, clusterType);
    Bundle data = new Bundle(getData());
    data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);
    if (mShowClusterMenu) {
      Context context = mActivity.getAndroidContext();
      data.putString(AlbumSetPage.KEY_SET_TITLE, mMediaSet.getName());
      data.putString(
          AlbumSetPage.KEY_SET_SUBTITLE,
          GalleryActionBar.getClusterByTypeString(context, clusterType));
    }

    // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
    mActivity.getStateManager().startStateForResult(AlbumSetPage.class, REQUEST_DO_ANIMATION, data);
  }
 @Override
 public void doCluster(int clusterType) {
   String basePath = mMediaSet.getPath().toString();
   String newPath = FilterUtils.switchClusterPath(basePath, clusterType);
   Bundle data = new Bundle(getData());
   data.putString(AlbumSetPage.KEY_MEDIA_PATH, newPath);
   data.putInt(KEY_SELECTED_CLUSTER_TYPE, clusterType);
   mActivity.getStateManager().switchState(this, AlbumSetPage.class, data);
 }
Ejemplo n.º 7
0
  public void resume() {
    mIsActive = true;
    mSource.addContentListener(mSourceListener);
    updateImageCache();
    updateImageRequests();

    mReloadTask = new ReloadTask();
    mReloadTask.start();

    mPhotoView.notifyModelInvalidated();
  }
Ejemplo n.º 8
0
  private void pickAlbum(int slotIndex) {
    if (!mIsActive) return;

    MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
    if (targetSet == null) return; // Content is dirty, we shall reload soon
    if (targetSet.getTotalMediaItemCount() == 0) {
      showEmptyAlbumToast(Toast.LENGTH_SHORT);
      return;
    }
    hideEmptyAlbumToast();

    String mediaPath = targetSet.getPath().toString();

    Bundle data = new Bundle(getData());
    int[] center = new int[2];
    getSlotCenter(slotIndex, center);
    data.putIntArray(AlbumPage.KEY_SET_CENTER, center);
    if (mGetAlbum && targetSet.isLeafAlbum()) {
      Activity activity = mActivity;
      Intent result =
          new Intent().putExtra(AlbumPicker.KEY_ALBUM_PATH, targetSet.getPath().toString());
      activity.setResult(Activity.RESULT_OK, result);
      activity.finish();
    } else if (targetSet.getSubMediaSetCount() > 0) {
      data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
      mActivity
          .getStateManager()
          .startStateForResult(AlbumSetPage.class, REQUEST_DO_ANIMATION, data);
    } else {
      if (!mGetContent && (targetSet.getSupportedOperations() & MediaObject.SUPPORT_IMPORT) != 0) {
        data.putBoolean(AlbumPage.KEY_AUTO_SELECT_ALL, true);
      } else if (!mGetContent && albumShouldOpenInFilmstrip(targetSet)) {
        data.putParcelable(
            PhotoPage.KEY_OPEN_ANIMATION_RECT, mSlotView.getSlotRect(slotIndex, mRootPane));
        data.putInt(PhotoPage.KEY_INDEX_HINT, 0);
        data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mediaPath);
        data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, true);
        data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, targetSet.isCameraRoll());
        mActivity
            .getStateManager()
            .startStateForResult(PhotoPage.class, AlbumPage.REQUEST_PHOTO, data);
        return;
      }
      data.putString(AlbumPage.KEY_MEDIA_PATH, mediaPath);

      // We only show cluster menu in the first AlbumPage in stack
      boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
      data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum);
      mActivity.getStateManager().startStateForResult(AlbumPage.class, REQUEST_DO_ANIMATION, data);
    }
  }
  @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;
  }
Ejemplo n.º 10
0
  public void pause() {
    mIsActive = false;

    mReloadTask.terminate();
    mReloadTask = null;

    mSource.removeContentListener(mSourceListener);

    for (ImageEntry entry : mImageCache.values()) {
      if (entry.fullImageTask != null) entry.fullImageTask.cancel();
      if (entry.screenNailTask != null) entry.screenNailTask.cancel();
    }
    mImageCache.clear();
    mTileProvider.clear();
  }
 @Override
 public void onSyncDone(final MediaSet mediaSet, final int resultCode) {
   Log.d(TAG, "onSyncDone: " + Utils.maskDebugInfo(mediaSet.getName()) + " result=" + resultCode);
   ((Activity) mActivity)
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               GLRoot root = mActivity.getGLRoot();
               root.lockRenderThread();
               mSyncResult = resultCode;
               try {
                 if (resultCode == MediaSet.SYNC_RESULT_SUCCESS) {
                   mInitialSynced = true;
                 }
                 clearLoadingBit(BIT_LOADING_SYNC);
                 showSyncErrorIfNecessary(mLoadingFailed);
               } finally {
                 root.unlockRenderThread();
               }
             }
           });
 }
  @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;
  }
  @Override
  protected void onResume() {
    super.onResume();
    mIsActive = true;

    mResumeEffect = mActivity.getTransitionStore().get(KEY_RESUME_ANIMATION);
    if (mResumeEffect != null) {
      mAlbumView.setSlotFilter(mResumeEffect);
      mResumeEffect.setPositionProvider(mPositionProvider);
      mResumeEffect.start();
    }

    setContentPane(mRootPane);

    boolean enableHomeButton =
        (mActivity.getStateManager().getStateCount() > 1) | mParentMediaSetString != null;
    GalleryActionBar actionBar = mActivity.getGalleryActionBar();
    actionBar.setDisplayOptions(enableHomeButton, false);
    if (!mGetContent) {
      actionBar.enableAlbumModeMenu(GalleryActionBar.ALBUM_GRID_MODE_SELECTED, this);
    }

    // Set the reload bit here to prevent it exit this page in clearLoadingBit().
    setLoadingBit(BIT_LOADING_RELOAD);
    mLoadingFailed = false;
    mAlbumDataAdapter.resume();

    mAlbumView.resume();
    mAlbumView.setPressedIndex(-1);
    mActionModeHandler.resume();
    if (!mInitialSynced) {
      setLoadingBit(BIT_LOADING_SYNC);
      mSyncTask = mMediaSet.requestSync(this);
    }
    mInCameraAndWantQuitOnPause = mInCameraApp;
  }
  private void pickPhoto(int slotIndex, boolean startInFilmstrip) {
    if (!mIsActive) return;

    if (!startInFilmstrip) {
      // Launch photos in lights out mode
      mActivity.getGLRoot().setLightsOutMode(true);
    }

    MediaItem item = mAlbumDataAdapter.get(slotIndex);
    if (item == null) return; // Item not ready yet, ignore the click
    if (mGetContent) {
      onGetContent(item);
    } else if (mLaunchedFromPhotoPage) {
      TransitionStore transitions = mActivity.getTransitionStore();
      transitions.put(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_PICKED);
      transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex);
      onBackPressed();
    } else {
      // Get into the PhotoPage.
      // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
      Bundle data = new Bundle();
      data.putInt(PhotoPage.KEY_INDEX_HINT, slotIndex);
      data.putParcelable(
          PhotoPage.KEY_OPEN_ANIMATION_RECT, mSlotView.getSlotRect(slotIndex, mRootPane));
      data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mMediaSetPath.toString());
      data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, item.getPath().toString());
      data.putInt(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_STARTED);
      data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, startInFilmstrip);
      data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, mMediaSet.isCameraRoll());
      if (startInFilmstrip) {
        mActivity.getStateManager().switchState(this, FilmstripPage.class, data);
      } else {
        mActivity.getStateManager().startStateForResult(SinglePhotoPage.class, REQUEST_PHOTO, data);
      }
    }
  }
 private static boolean albumShouldOpenInFilmstrip(MediaSet album) {
   int itemCount = album.getMediaItemCount();
   ArrayList<MediaItem> list = (itemCount == 1) ? album.getMediaItem(0, 1) : null;
   // open in film strip only if there's one item in the album and the item exists
   return (list != null && !list.isEmpty());
 }
Ejemplo n.º 16
0
 @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());
 }