public void run() {
   mAllImages.removeImageAt(mCurrentPosition);
   if (mAllImages.getCount() == 0) {
     finish();
     return;
   } else {
     if (mCurrentPosition == mAllImages.getCount()) {
       mCurrentPosition -= 1;
     }
   }
   mImageView.clear();
   mCache.clear(); // Because the position number is changed.
   setImage(mCurrentPosition, true);
 }
  @Override
  public void onStart() {
    super.onStart();
    mPaused = false;

    if (!init(mSavedUri)) {
      Log.w(TAG, "init failed: " + mSavedUri);
      finish();
      return;
    }

    // normally this will never be zero but if one "backs" into this
    // activity after removing the sdcard it could be zero.  in that
    // case just "finish" since there's nothing useful that can happen.
    int count = mAllImages.getCount();
    if (count == 0) {
      finish();
      return;
    } else if (count <= mCurrentPosition) {
      mCurrentPosition = count - 1;
    }

    if (mGetter == null) {
      makeGetter();
    }

    if (mMode == MODE_SLIDESHOW) {
      loadNextImage(mCurrentPosition, 0, true);
    } else { // MODE_NORMAL
      setImage(mCurrentPosition, mShowControls);
      mShowControls = false;
    }
  }
  private void updateNextPrevControls() {
    boolean showPrev = mCurrentPosition > 0;
    boolean showNext = mCurrentPosition < mAllImages.getCount() - 1;

    boolean prevIsVisible = mPrevImageView.getVisibility() == View.VISIBLE;
    boolean nextIsVisible = mNextImageView.getVisibility() == View.VISIBLE;

    if (showPrev && !prevIsVisible) {
      Animation a = mShowPrevImageViewAnimation;
      a.setDuration(500);
      mPrevImageView.startAnimation(a);
      mPrevImageView.setVisibility(View.VISIBLE);
    } else if (!showPrev && prevIsVisible) {
      Animation a = mHidePrevImageViewAnimation;
      a.setDuration(500);
      mPrevImageView.startAnimation(a);
      mPrevImageView.setVisibility(View.GONE);
    }

    if (showNext && !nextIsVisible) {
      Animation a = mShowNextImageViewAnimation;
      a.setDuration(500);
      mNextImageView.startAnimation(a);
      mNextImageView.setVisibility(View.VISIBLE);
    } else if (!showNext && nextIsVisible) {
      Animation a = mHideNextImageViewAnimation;
      a.setDuration(500);
      mNextImageView.startAnimation(a);
      mNextImageView.setVisibility(View.GONE);
    }
  }
 private void moveNextOrPrevious(int delta) {
   int nextImagePos = mCurrentPosition + delta;
   if ((0 <= nextImagePos) && (nextImagePos < mAllImages.getCount())) {
     setImage(nextImagePos, true);
     showOnScreenControls();
   }
 }
  private void generateShuffleOrder() {
    if (mShuffleOrder == null || mShuffleOrder.length != mAllImages.getCount()) {
      mShuffleOrder = new int[mAllImages.getCount()];
      for (int i = 0, n = mShuffleOrder.length; i < n; i++) {
        mShuffleOrder[i] = i;
      }
    }

    for (int i = mShuffleOrder.length - 1; i >= 0; i--) {
      int r = mRandom.nextInt(i + 1);
      if (r != i) {
        int tmp = mShuffleOrder[r];
        mShuffleOrder[r] = mShuffleOrder[i];
        mShuffleOrder[i] = tmp;
      }
    }
  }
 private Uri getCurrentUri() {
   if (mAllImages.getCount() == 0) return null;
   IImage image = mAllImages.getImageAt(mCurrentPosition);
   if (image == null) return null;
   return image.fullSizeImageUri();
 }