diff options
-rw-r--r-- | src/com/android/camera/Camera.java | 33 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomPicker.java | 45 |
2 files changed, 65 insertions, 13 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 0a8cc99..12f1b3b 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -442,10 +442,30 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, if (mZoomPicker != null) { mZoomPicker.setZoomRatios(getZoomRatios()); mZoomPicker.setZoomIndex(mParameters.getZoom()); + mZoomPicker.setSmoothZoomSupported(mSmoothZoomSupported); mZoomPicker.setOnZoomChangeListener( new ZoomPicker.OnZoomChangedListener() { - public void onZoomChanged(int index) { - onZoomValueChanged(index); + // only for immediate zoom + public void onZoomValueChanged(int index) { + Camera.this.onZoomValueChanged(index); + } + + // only for smooth zoom + public void onZoomStateChanged(int state) { + if (mPausing) return; + + Log.v(TAG, "zoom picker state=" + state); + if (state == mZoomPicker.ZOOM_IN) { + Camera.this.onZoomValueChanged(mZoomMax); + } else if (state == mZoomPicker.ZOOM_OUT){ + Camera.this.onZoomValueChanged(0); + } else { + mTargetZoomValue = -1; + if (mZoomState == ZOOM_START) { + mZoomState = ZOOM_STOPPING; + mCameraDevice.stopSmoothZoom(); + } + } } }); } @@ -772,13 +792,16 @@ public class Camera extends NoSearchActivity implements View.OnClickListener, int value, boolean stopped, android.hardware.Camera camera) { Log.v(TAG, "Zoom changed: value=" + value + ". stopped="+ stopped); mZoomValue = value; + + // Update the UI when we get zoom value. + if (mZoomPicker != null) mZoomPicker.setZoomIndex(value); + // Keep mParameters up to date. We do not getParameter again in // takePicture. If we do not do this, wrong zoom value will be set. mParameters.setZoom(value); - // We only care if the zoom is stopped. mZooming is set to true when - // we start smooth zoom. + if (stopped && mZoomState != ZOOM_STOPPED) { - if (value != mTargetZoomValue) { + if (mTargetZoomValue != -1 && value != mTargetZoomValue) { mCameraDevice.startSmoothZoom(mTargetZoomValue); mZoomState = ZOOM_START; } else { diff --git a/src/com/android/camera/ui/ZoomPicker.java b/src/com/android/camera/ui/ZoomPicker.java index 98e18d7..6d31fe8 100644 --- a/src/com/android/camera/ui/ZoomPicker.java +++ b/src/com/android/camera/ui/ZoomPicker.java @@ -40,6 +40,7 @@ public class ZoomPicker extends LinearLayout { private TextView mZoomTextView; private int mZoomMax, mZoomIndex; private float[] mZoomRatios; + private boolean mSmoothZoomSupported; private OnZoomChangedListener mListener; private boolean mIncrement, mDecrement; private final StringBuilder mBuilder = new StringBuilder(); @@ -49,17 +50,30 @@ public class ZoomPicker extends LinearLayout { private Button mIncrementButton; private Button mDecrementButton; + // The state of zoom button. + public static final int ZOOM_IN = 0; + public static final int ZOOM_OUT = 1; + public static final int ZOOM_STOP = 2; + private Handler mHandler; private final Runnable mRunnable = new Runnable() { public void run() { if (mIncrement) { mIncrementButton.setBackgroundResource(R.drawable.button_zoom_in_longpressed_holo); - if (changeZoomIndex(mZoomIndex + 1)) { + if (mSmoothZoomSupported) { + if (mZoomIndex != mZoomMax && mListener != null) { + mListener.onZoomStateChanged(ZOOM_IN); + } + } else if (changeZoomIndex(mZoomIndex + 1)) { mHandler.postDelayed(this, 65); } } else if (mDecrement) { mDecrementButton.setBackgroundResource(R.drawable.button_zoom_out_longpressed_holo); - if (changeZoomIndex(mZoomIndex - 1)) { + if (mSmoothZoomSupported) { + if (mZoomIndex != 0 && mListener != null) { + mListener.onZoomStateChanged(ZOOM_OUT); + } + } else if (changeZoomIndex(mZoomIndex - 1)) { mHandler.postDelayed(this, 65); } } @@ -78,16 +92,21 @@ public class ZoomPicker extends LinearLayout { OnTouchListener incrementTouchListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { + int action = event.getAction(); + if (action == MotionEvent.ACTION_DOWN) { if (!mIncrement && changeZoomIndex(mZoomIndex + 1)) { mIncrement = true; // Give bigger delay so users can tap to change only one // zoom step. mHandler.postDelayed(mRunnable, 300); } - } else if (event.getAction() == MotionEvent.ACTION_UP) { + } else if (action == MotionEvent.ACTION_UP + || action == MotionEvent.ACTION_CANCEL) { mIncrementButton.setBackgroundResource(R.drawable.btn_zoom_in); mIncrement = false; + if (mSmoothZoomSupported) { + if (mListener != null) mListener.onZoomStateChanged(ZOOM_STOP); + } } return false; } @@ -95,16 +114,21 @@ public class ZoomPicker extends LinearLayout { OnTouchListener decrementTouchListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { + int action = event.getAction(); + if (action == MotionEvent.ACTION_DOWN) { if (!mDecrement && changeZoomIndex(mZoomIndex - 1)) { mDecrement = true; // Give bigger delay so users can tap to change only one // zoom step. mHandler.postDelayed(mRunnable, 300); } - } else if (event.getAction() == MotionEvent.ACTION_UP) { + } else if (action == MotionEvent.ACTION_UP + || action == MotionEvent.ACTION_CANCEL) { mDecrementButton.setBackgroundResource(R.drawable.btn_zoom_out); mDecrement = false; + if (mSmoothZoomSupported) { + if (mListener != null) mListener.onZoomStateChanged(ZOOM_STOP); + } } return false; } @@ -121,7 +145,8 @@ public class ZoomPicker extends LinearLayout { } public interface OnZoomChangedListener { - void onZoomChanged(int index); + void onZoomValueChanged(int index); // only for immediate zoom + void onZoomStateChanged(int state); // only for smooth zoom } public void setZoomRatios(float[] zoomRatios) { @@ -138,11 +163,15 @@ public class ZoomPicker extends LinearLayout { updateView(); } + public void setSmoothZoomSupported(boolean smoothZoomSupported) { + mSmoothZoomSupported = smoothZoomSupported; + } + private boolean changeZoomIndex(int index) { if (index > mZoomMax || index < 0) return false; mZoomIndex = index; if (mListener != null) { - mListener.onZoomChanged(mZoomIndex); + mListener.onZoomValueChanged(mZoomIndex); } updateView(); return true; |