From 1f463a62595ee86c7f4472d8ad69dda959b396ff Mon Sep 17 00:00:00 2001 From: Chih-Chung Chang Date: Thu, 30 Jul 2009 17:59:09 +0800 Subject: Make dpad left/right move to prev/next image. --- src/com/android/camera/CropImage.java | 5 +-- src/com/android/camera/ImageViewTouchBase.java | 8 ++-- src/com/android/camera/ReviewImage.java | 46 ++++++----------------- src/com/android/camera/ViewImage.java | 52 ++++++-------------------- 4 files changed, 28 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/com/android/camera/CropImage.java b/src/com/android/camera/CropImage.java index 32a0dff..6b45cc5 100644 --- a/src/com/android/camera/CropImage.java +++ b/src/com/android/camera/CropImage.java @@ -175,9 +175,6 @@ public class CropImage extends MonitoredActivity { } mImageView.setImageBitmapResetBase(mBitmap, true); - if (mImageView.getScale() == 1F) { - mImageView.center(true, true); - } Util.startBackgroundJob(this, null, getResources().getString(R.string.runningFaceDetection), @@ -557,7 +554,7 @@ class CropImageView extends ImageViewTouchBase { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - if (mBitmapDisplayed != null) { + if (mBitmapDisplayed.getBitmap() != null) { for (HighlightView hv : mHighlightViews) { hv.mMatrix.set(getImageMatrix()); hv.invalidate(); diff --git a/src/com/android/camera/ImageViewTouchBase.java b/src/com/android/camera/ImageViewTouchBase.java index 1812466..5841854 100644 --- a/src/com/android/camera/ImageViewTouchBase.java +++ b/src/com/android/camera/ImageViewTouchBase.java @@ -256,10 +256,10 @@ abstract class ImageViewTouchBase extends ImageView { int rotation = bitmap.getRotation(); matrix.reset(); - // Up-scaling is not allowed because the result may look bad if it's - // a thumbnail icon. - float widthScale = Math.min(viewWidth / w, 1.0f); - float heightScale = Math.min(viewHeight / h, 1.0f); + // We limit up-scaling to 2x otherwise the result may look bad if it's + // a small icon. + float widthScale = Math.min(viewWidth / w, 2.0f); + float heightScale = Math.min(viewHeight / h, 2.0f); float scale = Math.min(widthScale, heightScale); matrix.postConcat(bitmap.getRotateMatrix()); diff --git a/src/com/android/camera/ReviewImage.java b/src/com/android/camera/ReviewImage.java index 61f6915..b5cef72 100644 --- a/src/com/android/camera/ReviewImage.java +++ b/src/com/android/camera/ReviewImage.java @@ -112,10 +112,6 @@ public class ReviewImage extends Activity implements View.OnClickListener { private final Animation mShowPrevImageViewAnimation = new AlphaAnimation(0F, 1F); - static final int PADDING = 20; - static final int HYSTERESIS = PADDING * 2; - static final int BASE_SCROLL_DURATION = 1000; // ms - public static final String KEY_IMAGE_LIST = "image_list"; IImageList mAllImages; @@ -432,8 +428,6 @@ public class ReviewImage extends Activity implements View.OnClickListener { ImageGetterCallback cb = new ImageGetterCallback() { public void completed() { - mImageView.setFocusableInTouchMode(true); - mImageView.requestFocus(); } public boolean wantsThumbnail(int pos, int offset) { @@ -578,9 +572,8 @@ public class ReviewImage extends Activity implements View.OnClickListener { mNextImageView.setOnClickListener(this); mPrevImageView.setOnClickListener(this); - mNextImageView.setFocusable(true); - mPrevImageView.setFocusable(true); - + mImageView.setFocusable(true); + mImageView.setFocusableInTouchMode(true); } private void setButtonPanelVisibility(int id, int visibility) { @@ -1020,6 +1013,9 @@ class ImageViewTouch2 extends ImageViewTouchBase { static final float PAN_RATE = 20; + // This is the time we allow the dpad to change the image position again. + static long nextChangePositionTime; + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Don't respond to arrow keys if trackball scrolling is not enabled @@ -1046,10 +1042,10 @@ class ImageViewTouch2 extends ImageViewTouchBase { break; } case KeyEvent.KEYCODE_DPAD_LEFT: { - int maxOffset = (current == 0) ? 0 : ReviewImage.HYSTERESIS; - if (getScale() <= 1F - || isShiftedToNextImage(true, maxOffset)) { + if (getScale() <= 1F && event.getEventTime() + >= nextChangePositionTime) { nextImagePos = current - 1; + nextChangePositionTime = event.getEventTime() + 500; } else { panBy(PAN_RATE, 0); center(true, false); @@ -1057,13 +1053,10 @@ class ImageViewTouch2 extends ImageViewTouchBase { return true; } case KeyEvent.KEYCODE_DPAD_RIGHT: { - int maxOffset = - (current == mViewImage.mAllImages.getCount() - 1) - ? 0 - : ReviewImage.HYSTERESIS; - if (getScale() <= 1F - || isShiftedToNextImage(false, maxOffset)) { + if (getScale() <= 1F && event.getEventTime() + >= nextChangePositionTime) { nextImagePos = current + 1; + nextChangePositionTime = event.getEventTime() + 500; } else { panBy(-PAN_RATE, 0); center(true, false); @@ -1099,21 +1092,4 @@ class ImageViewTouch2 extends ImageViewTouchBase { return super.onKeyDown(keyCode, event); } - - protected boolean isShiftedToNextImage(boolean left, int maxOffset) { - boolean retval; - RotateBitmap bitmap = mBitmapDisplayed; - Matrix m = getImageViewMatrix(); - if (left) { - float [] t1 = new float[] { 0, 0 }; - m.mapPoints(t1); - retval = t1[0] > maxOffset; - } else { - int width = bitmap != null ? bitmap.getWidth() : getWidth(); - float [] t1 = new float[] { width, 0 }; - m.mapPoints(t1); - retval = t1[0] + maxOffset < getWidth(); - } - return retval; - } } diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java index bab65a4..1a0d933 100644 --- a/src/com/android/camera/ViewImage.java +++ b/src/com/android/camera/ViewImage.java @@ -111,10 +111,6 @@ public class ViewImage extends Activity implements View.OnClickListener { private final Animation mShowPrevImageViewAnimation = new AlphaAnimation(0F, 1F); - static final int PADDING = 20; - static final int HYSTERESIS = PADDING * 2; - static final int BASE_SCROLL_DURATION = 1000; // ms - public static final String KEY_IMAGE_LIST = "image_list"; IImageList mAllImages; @@ -458,10 +454,6 @@ public class ViewImage extends Activity implements View.OnClickListener { ImageGetterCallback cb = new ImageGetterCallback() { public void completed() { - if (!mShowActionIcons) { - mImageView.setFocusableInTouchMode(true); - mImageView.requestFocus(); - } } public boolean wantsThumbnail(int pos, int offset) { @@ -535,7 +527,7 @@ public class ViewImage extends Activity implements View.OnClickListener { setContentView(R.layout.viewimage); mImageView = (ImageViewTouch) findViewById(R.id.image); - mImageView.setEnableTrackballScroll(!mShowActionIcons); + mImageView.setEnableTrackballScroll(true); mCache = new BitmapCache(3); mImageView.setRecycler(mCache); @@ -619,11 +611,8 @@ public class ViewImage extends Activity implements View.OnClickListener { mNextImageView.setOnClickListener(this); mPrevImageView.setOnClickListener(this); - if (mShowActionIcons) { - mNextImageView.setFocusable(true); - mPrevImageView.setFocusable(true); - } - + mImageView.setFocusable(true); + mImageView.setFocusableInTouchMode(true); } private void updateActionIcons() { @@ -1077,6 +1066,9 @@ class ImageViewTouch extends ImageViewTouchBase { static final float PAN_RATE = 20; + // This is the time we allow the dpad to change the image position again. + static long nextChangePositionTime; + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Don't respond to arrow keys if trackball scrolling is not enabled @@ -1103,10 +1095,10 @@ class ImageViewTouch extends ImageViewTouchBase { break; } case KeyEvent.KEYCODE_DPAD_LEFT: { - int maxOffset = (current == 0) ? 0 : ViewImage.HYSTERESIS; - if (getScale() <= 1F - || isShiftedToNextImage(true, maxOffset)) { + if (getScale() <= 1F && event.getEventTime() + >= nextChangePositionTime) { nextImagePos = current - 1; + nextChangePositionTime = event.getEventTime() + 500; } else { panBy(PAN_RATE, 0); center(true, false); @@ -1114,13 +1106,10 @@ class ImageViewTouch extends ImageViewTouchBase { return true; } case KeyEvent.KEYCODE_DPAD_RIGHT: { - int maxOffset = - (current == mViewImage.mAllImages.getCount() - 1) - ? 0 - : ViewImage.HYSTERESIS; - if (getScale() <= 1F - || isShiftedToNextImage(false, maxOffset)) { + if (getScale() <= 1F && event.getEventTime() + >= nextChangePositionTime) { nextImagePos = current + 1; + nextChangePositionTime = event.getEventTime() + 500; } else { panBy(-PAN_RATE, 0); center(true, false); @@ -1156,23 +1145,6 @@ class ImageViewTouch extends ImageViewTouchBase { return super.onKeyDown(keyCode, event); } - - protected boolean isShiftedToNextImage(boolean left, int maxOffset) { - boolean retval; - RotateBitmap bitmap = mBitmapDisplayed; - Matrix m = getImageViewMatrix(); - if (left) { - float [] t1 = new float[] { 0, 0 }; - m.mapPoints(t1); - retval = t1[0] > maxOffset; - } else { - int width = bitmap != null ? bitmap.getWidth() : getWidth(); - float [] t1 = new float[] { width, 0 }; - m.mapPoints(t1); - retval = t1[0] + maxOffset < getWidth(); - } - return retval; - } } // This is a cache for Bitmap displayed in ViewImage (normal mode, thumb only). -- cgit v1.1