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 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);
  }