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 onStop() {
    super.onStop();
    mPaused = true;

    // mGetter could be null if we call finish() and leave early in
    // onStart().
    if (mGetter != null) {
      mGetter.cancelCurrent();
      mGetter.stop();
      mGetter = null;
    }
    setMode(MODE_NORMAL);

    // removing all callback in the message queue
    mHandler.removeAllGetterCallbacks();

    if (mAllImages != null) {
      mSavedUri = getCurrentUri();
      mAllImages.close();
      mAllImages = null;
    }

    hideOnScreenControls();
    mImageView.clear();
    mCache.clear();

    for (ImageViewTouchBase iv : mSlideShowImageViews) {
      iv.clear();
    }
  }
  void setImage(int pos, boolean showControls) {
    mCurrentPosition = pos;

    Bitmap b = mCache.getBitmap(pos);
    if (b != null) {
      IImage image = mAllImages.getImageAt(pos);
      mImageView.setImageRotateBitmapResetBase(
          new RotateBitmap(b, image.getDegreesRotated()), true);
      updateZoomButtonsEnabled();
    }

    ImageGetterCallback cb =
        new ImageGetterCallback() {
          public void completed() {}

          public boolean wantsThumbnail(int pos, int offset) {
            return !mCache.hasBitmap(pos + offset);
          }

          public boolean wantsFullImage(int pos, int offset) {
            return offset == 0;
          }

          public int fullImageSizeToUse(int pos, int offset) {
            // this number should be bigger so that we can zoom.  we may
            // need to get fancier and read in the fuller size image as the
            // user starts to zoom.
            // Originally the value is set to 480 in order to avoid OOM.
            // Now we set it to 2048 because of using
            // native memory allocation for Bitmaps.
            final int imageViewSize = 2048;
            return imageViewSize;
          }

          public int[] loadOrder() {
            return sOrderAdjacents;
          }

          public void imageLoaded(int pos, int offset, RotateBitmap bitmap, boolean isThumb) {
            // shouldn't get here after onPause()

            // We may get a result from a previous request. Ignore it.
            if (pos != mCurrentPosition) {
              bitmap.recycle();
              return;
            }

            if (isThumb) {
              mCache.put(pos + offset, bitmap.getBitmap());
            }
            if (offset == 0) {
              // isThumb: We always load thumb bitmap first, so we will
              // reset the supp matrix for then thumb bitmap, and keep
              // the supp matrix when the full bitmap is loaded.
              mImageView.setImageRotateBitmapResetBase(bitmap, isThumb);
              updateZoomButtonsEnabled();
            }
          }
        };

    // Could be null if we're stopping a slide show in the course of pausing
    if (mGetter != null) {
      mGetter.setPosition(pos, cb, mAllImages, mHandler);
    }
    updateActionIcons();
    if (showControls) showOnScreenControls();
    scheduleDismissOnScreenControls();
  }