Example #1
0
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        switch (requestCode) {
            case MenuHelper.RESULT_COMMON_MENU_CROP:
                if (resultCode == RESULT_OK) {
                    // The CropImage activity passes back the Uri of the
                    // cropped image as the Action rather than the Data.
                    mSavedUri = Uri.parse(data.getAction());

                    // if onStart() runs before, then set the returned
                    // image as currentImage.
                    if (mAllImages != null) {
                        IImage image = mAllImages.getImageForUri(mSavedUri);
                        // image could be null if SD card is removed.
                        if (image == null) {
                            finish();
                        } else {
                            mCurrentPosition = mAllImages.getImageIndex(image);
                            setImage(mCurrentPosition, false);
                        }
                    }
                }
                break;
        }
    }
Example #2
0
 private boolean init(Uri uri) {
     if (uri == null) return false;
     mAllImages = (mParam == null)
             ? buildImageListFromUri(uri)
             : ImageManager.makeImageList(getContentResolver(), mParam);
     IImage image = mAllImages.getImageForUri(uri);
     if (image == null) return false;
     mCurrentPosition = mAllImages.getImageIndex(image);
     return true;
 }
Example #3
0
 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);
 }
Example #4
0
 private void moveNextOrPrevious(int delta) {
     int nextImagePos = mCurrentPosition + delta;
     if ((0 <= nextImagePos) && (nextImagePos < mAllImages.getCount())) {
         setImage(nextImagePos, true);
         showOnScreenControls();
     }
 }
Example #5
0
    @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;
        }

        // 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();
        }
    }
Example #6
0
    @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();
        }

        //show controls only for first time
        setImage(mCurrentPosition, mShowControls);
        mShowControls = false;
    }
Example #7
0
 @Override
 public void onSaveInstanceState(Bundle b) {
     super.onSaveInstanceState(b);
     b.putParcelable(STATE_URI,
             mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri());
     b.putBoolean(STATE_SHOW_CONTROLS, mShowControls);
 }
Example #8
0
    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);
        }
    }
Example #9
0
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        if (mPaused) return false;

        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;
    }
Example #10
0
 @Override
 public boolean onMenuItemSelected(int featureId, MenuItem item) {
     boolean b = super.onMenuItemSelected(featureId, item);
     if (mImageMenuRunnable != null) {
         mImageMenuRunnable.aboutToCall(item,
                 mAllImages.getImageAt(mCurrentPosition));
     }
     return b;
 }
Example #11
0
 private void startPlayVideoActivity() {
     IImage image = mAllImages.getImageAt(mCurrentPosition);
     Intent intent = new Intent(
             Intent.ACTION_VIEW, image.fullSizeImageUri());
     try {
         startActivity(intent);
     } catch (android.content.ActivityNotFoundException ex) {
         Log.e(TAG, "Couldn't view video " + image.fullSizeImageUri(), ex);
     }
 }
Example #12
0
    private void updateActionIcons() {
        if (isPickIntent()) return;

        IImage image = mAllImages.getImageAt(mCurrentPosition);
        if (image instanceof VideoObject) {
            setButtonPanelVisibility(R.id.btn_set_as, View.GONE);
            setButtonPanelVisibility(R.id.btn_play, View.VISIBLE);
        } else {
            setButtonPanelVisibility(R.id.btn_set_as, View.VISIBLE);
            setButtonPanelVisibility(R.id.btn_play, View.GONE);
        }
    }
Example #13
0
 public void onClick(View v) {
     switch (v.getId()) {
         case R.id.btn_delete:
             MenuHelper.deleteImage(this, mDeletePhotoRunnable,
                     mAllImages.getImageAt(mCurrentPosition));
             break;
         case R.id.btn_play:
             startPlayVideoActivity();
             break;
         case R.id.btn_share: {
             IImage image = mAllImages.getImageAt(mCurrentPosition);
             if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
                 return;
             }
             startShareMediaActivity(image);
             break;
         }
         case R.id.btn_set_as: {
             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.btn_done:
             finish();
             break;
         case R.id.next_image:
             moveNextOrPrevious(1);
             break;
         case R.id.prev_image:
             moveNextOrPrevious(-1);
             break;
     }
 }
Example #14
0
    private void showOnScreenControls() {

        // If the view has not been attached to the window yet, the
        // zoomButtonControls will not able to show up. So delay it until the
        // view has attached to window.
        if (mRootView.getWindowToken() == null) {
            mHandler.postGetterCallback(new Runnable() {
                public void run() {
                    showOnScreenControls();
                }
            });
            return;
        }

        // we may need to update the next/prev button due to index changing
        updateNextPrevControls();

        if (ImageManager.isImage(mAllImages.getImageAt(mCurrentPosition))) {
            updateZoomButtonsEnabled();
            mZoomButtonsController.setVisible(true);
        } else {
            mZoomButtonsController.setVisible(false);
        }
    }
Example #15
0
 private Uri getCurrentUri() {
     if (mAllImages.getCount() == 0) return null;
     IImage image = mAllImages.getImageAt(mCurrentPosition);
     return image.fullSizeImageUri();
 }
Example #16
0
    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();
    }