public void onComplete(String location) {
   // View d is per-thread data, so when setDetailsValue is
   // executed by UI thread, it doesn't matter whether the
   // details dialog is dismissed or not.
   View view = mView.get();
   if (view == null) return;
   if (!location.equals(MenuHelper.EMPTY_STRING)) {
     MenuHelper.setDetailsValue(view, location, R.id.details_location_value);
   } else {
     MenuHelper.hideDetailsRow(view, R.id.details_location_row);
   }
 }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuItem item =
        menu.add(Menu.NONE, Menu.NONE, MenuHelper.POSITION_SLIDESHOW, R.string.slide_show);
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            setMode(MODE_SLIDESHOW);
            mLastSlideShowImage = mCurrentPosition;
            loadNextImage(mCurrentPosition, 0, true);
            return true;
          }
        });
    item.setIcon(android.R.drawable.ic_menu_slideshow);

    mImageMenuRunnable =
        MenuHelper.addImageMenuItems(
            menu,
            MenuHelper.INCLUDE_ALL,
            ViewImage.this,
            mHandler,
            mDeletePhotoRunnable,
            new MenuHelper.MenuInvoker() {
              public void run(final MenuHelper.MenuCallback cb) {
                if (mPaused) return;
                setMode(MODE_NORMAL);

                IImage image = mAllImages.getImageAt(mCurrentPosition);
                Uri uri = image.fullSizeImageUri();
                cb.run(uri, image);

                // We might have deleted all images in the callback, so
                // call setImage() only if we still have some images.
                if (mAllImages.getCount() > 0) {
                  mImageView.clear();
                  setImage(mCurrentPosition, false);
                }
              }
            });

    item =
        menu.add(
            Menu.NONE, Menu.NONE, MenuHelper.POSITION_GALLERY_SETTING, R.string.camerasettings);
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            Intent preferences = new Intent();
            preferences.setClass(ViewImage.this, GallerySettings.class);
            startActivity(preferences);
            return true;
          }
        });
    item.setAlphabeticShortcut('p');
    item.setIcon(android.R.drawable.ic_menu_preferences);

    return true;
  }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {

    super.onPrepareOptionsMenu(menu);
    if (mPaused) return false;

    setMode(MODE_NORMAL);
    IImage image = mAllImages.getImageAt(mCurrentPosition);

    if (mImageMenuRunnable != null) {
      mImageMenuRunnable.gettingReadyToOpen(menu, image);
    }

    Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
    MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));

    MenuHelper.enableShowOnMapMenuItem(menu, MenuHelper.hasLatLngData(image));

    return true;
  }
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.discard:
       MenuHelper.deletePhoto(this, mDeletePhotoRunnable);
       break;
     case R.id.play:
       startPlayVideoActivity();
       break;
     case R.id.share:
       {
         IImage image = mAllImages.getImageAt(mCurrentPosition);
         if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
           return;
         }
         startShareMediaActivity(image);
         break;
       }
     case R.id.setas:
       {
         IImage image = mAllImages.getImageAt(mCurrentPosition);
         Intent intent = Util.createSetAsIntent(image);
         try {
           startActivity(Intent.createChooser(intent, getText(R.string.setImage)));
         } catch (android.content.ActivityNotFoundException ex) {
           Toast.makeText(this, R.string.no_way_to_share_video, Toast.LENGTH_SHORT).show();
         }
         break;
       }
     case R.id.next_image:
       moveNextOrPrevious(1);
       break;
     case R.id.prev_image:
       moveNextOrPrevious(-1);
       break;
   }
 }
  @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);
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mViewImage.mPaused) return false;

    // Don't respond to arrow keys if trackball scrolling is not enabled
    if (!mEnableTrackballScroll) {
      if ((keyCode >= KeyEvent.KEYCODE_DPAD_UP) && (keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT)) {
        return super.onKeyDown(keyCode, event);
      }
    }

    int current = mViewImage.mCurrentPosition;

    int nextImagePos = -2; // default no next image
    try {
      switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
          {
            if (mViewImage.isPickIntent()) {
              IImage img = mViewImage.mAllImages.getImageAt(mViewImage.mCurrentPosition);
              mViewImage.setResult(
                  ViewImage.RESULT_OK, new Intent().setData(img.fullSizeImageUri()));
              mViewImage.finish();
            }
            break;
          }
        case KeyEvent.KEYCODE_DPAD_LEFT:
          {
            if (getScale() <= 1F && event.getEventTime() >= mNextChangePositionTime) {
              nextImagePos = current - 1;
              mNextChangePositionTime = event.getEventTime() + 500;
            } else {
              panBy(PAN_RATE, 0);
              center(true, false);
            }
            return true;
          }
        case KeyEvent.KEYCODE_DPAD_RIGHT:
          {
            if (getScale() <= 1F && event.getEventTime() >= mNextChangePositionTime) {
              nextImagePos = current + 1;
              mNextChangePositionTime = event.getEventTime() + 500;
            } else {
              panBy(-PAN_RATE, 0);
              center(true, false);
            }
            return true;
          }
        case KeyEvent.KEYCODE_DPAD_UP:
          {
            panBy(0, PAN_RATE);
            center(false, true);
            return true;
          }
        case KeyEvent.KEYCODE_DPAD_DOWN:
          {
            panBy(0, -PAN_RATE);
            center(false, true);
            return true;
          }
        case KeyEvent.KEYCODE_DEL:
          MenuHelper.deletePhoto(mViewImage, mViewImage.mDeletePhotoRunnable);
          break;
      }
    } finally {
      if (nextImagePos >= 0 && nextImagePos < mViewImage.mAllImages.getCount()) {
        synchronized (mViewImage) {
          mViewImage.setMode(ViewImage.MODE_NORMAL);
          mViewImage.setImage(nextImagePos, true);
        }
      } else if (nextImagePos != -2) {
        center(true, true);
      }
    }

    return super.onKeyDown(keyCode, event);
  }