void setMode(int mode) {
    if (mMode == mode) {
      return;
    }
    View slideshowPanel = findViewById(R.id.slideShowContainer);
    View normalPanel = findViewById(R.id.abs);

    Window win = getWindow();
    mMode = mode;
    if (mode == MODE_SLIDESHOW) {
      slideshowPanel.setVisibility(View.VISIBLE);
      normalPanel.setVisibility(View.GONE);

      win.addFlags(
          WindowManager.LayoutParams.FLAG_FULLSCREEN
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

      mImageView.clear();
      mActionIconPanel.setVisibility(View.GONE);

      slideshowPanel.getRootView().requestLayout();

      // The preferences we want to read:
      //   mUseShuffleOrder
      //   mSlideShowLoop
      //   mAnimationIndex
      //   mSlideShowInterval

      mUseShuffleOrder = mPrefs.getBoolean(PREF_SHUFFLE_SLIDESHOW, false);
      mSlideShowLoop = mPrefs.getBoolean(PREF_SLIDESHOW_REPEAT, false);
      mAnimationIndex = getPreferencesInteger(mPrefs, "pref_gallery_slideshow_transition_key", 0);
      mSlideShowInterval =
          getPreferencesInteger(mPrefs, "pref_gallery_slideshow_interval_key", 3) * 1000;
    } else {
      slideshowPanel.setVisibility(View.GONE);
      normalPanel.setVisibility(View.VISIBLE);

      win.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      if (mFullScreenInNormalMode) {
        win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      } else {
        win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      }

      if (mGetter != null) {
        mGetter.cancelCurrent();
      }

      if (mShowActionIcons) {
        Animation animation = new AlphaAnimation(0F, 1F);
        animation.setDuration(500);
        mActionIconPanel.setAnimation(animation);
        mActionIconPanel.setVisibility(View.VISIBLE);
      }

      ImageViewTouchBase dst = mImageView;
      for (ImageViewTouchBase ivt : mSlideShowImageViews) {
        ivt.clear();
      }

      mShuffleOrder = null;

      // mGetter null is a proxy for being paused
      if (mGetter != null) {
        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();
    }
  }
  @Override
  public void onCreate(Bundle instanceState) {
    super.onCreate(instanceState);

    Intent intent = getIntent();
    mFullScreenInNormalMode = intent.getBooleanExtra(MediaStore.EXTRA_FULL_SCREEN, true);
    mShowActionIcons = intent.getBooleanExtra(MediaStore.EXTRA_SHOW_ACTION_ICONS, true);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.viewimage);

    mImageView = (ImageViewTouch) findViewById(R.id.image);
    mImageView.setEnableTrackballScroll(true);
    mCache = new BitmapCache(3);
    mImageView.setRecycler(mCache);

    makeGetter();

    mAnimationIndex = -1;

    mSlideShowInAnimation =
        new Animation[] {
          makeInAnimation(R.anim.transition_in),
          makeInAnimation(R.anim.slide_in),
          makeInAnimation(R.anim.slide_in_vertical),
        };

    mSlideShowOutAnimation =
        new Animation[] {
          makeOutAnimation(R.anim.transition_out),
          makeOutAnimation(R.anim.slide_out),
          makeOutAnimation(R.anim.slide_out_vertical),
        };

    mSlideShowImageViews[0] = (ImageViewTouchBase) findViewById(R.id.image1_slideShow);
    mSlideShowImageViews[1] = (ImageViewTouchBase) findViewById(R.id.image2_slideShow);
    for (ImageViewTouchBase v : mSlideShowImageViews) {
      v.setVisibility(View.INVISIBLE);
      v.setRecycler(mCache);
    }

    mActionIconPanel = findViewById(R.id.action_icon_panel);

    mParam = getIntent().getParcelableExtra(KEY_IMAGE_LIST);

    boolean slideshow;
    if (instanceState != null) {
      mSavedUri = instanceState.getParcelable(STATE_URI);
      slideshow = instanceState.getBoolean(STATE_SLIDESHOW, false);
      mShowControls = instanceState.getBoolean(STATE_SHOW_CONTROLS, true);
    } else {
      mSavedUri = getIntent().getData();
      slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
    }

    // We only show action icons for URIs that we know we can share and
    // delete. Although we get read permission (for the images) from
    // applications like MMS, we cannot pass the permission to other
    // activities due to the current framework design.
    if (!MenuHelper.isWhiteListUri(mSavedUri)) {
      mShowActionIcons = false;
    }

    if (mShowActionIcons) {
      int[] pickIds = {R.id.attach, R.id.cancel};
      int[] normalIds = {R.id.setas, R.id.play, R.id.share, R.id.discard};
      int[] connectIds = isPickIntent() ? pickIds : normalIds;
      for (int id : connectIds) {
        View view = mActionIconPanel.findViewById(id);
        view.setVisibility(View.VISIBLE);
        view.setOnClickListener(this);
      }
    }

    // Don't show the "delete" icon for SingleImageList.
    if (ImageManager.isSingleImageMode(mSavedUri.toString())) {
      mActionIconPanel.findViewById(R.id.discard).setVisibility(View.GONE);
    }

    if (slideshow) {
      setMode(MODE_SLIDESHOW);
    } else {
      if (mFullScreenInNormalMode) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      }
      if (mShowActionIcons) {
        mActionIconPanel.setVisibility(View.VISIBLE);
      }
    }

    setupOnScreenControls(findViewById(R.id.rootLayout), mImageView);
  }
 protected void postTranslateCenter(float dx, float dy) {
   super.postTranslate(dx, dy);
   center(true, true);
 }