diff options
author | Chung-yih Wang <cywang@google.com> | 2011-09-06 19:50:47 +0800 |
---|---|---|
committer | Chung-yih Wang <cywang@google.com> | 2011-09-20 21:22:55 +0800 |
commit | b7d0a0704e437a1892fbf2a6e5138cf36df9fde8 (patch) | |
tree | 6e09e8f668403167a10217feb3cf2c613c91e186 /src/com | |
parent | 5e73dd3bc86baa3cc32cb94ec8f20a818d8156c0 (diff) | |
download | LegacyCamera-b7d0a0704e437a1892fbf2a6e5138cf36df9fde8.zip LegacyCamera-b7d0a0704e437a1892fbf2a6e5138cf36df9fde8.tar.gz LegacyCamera-b7d0a0704e437a1892fbf2a6e5138cf36df9fde8.tar.bz2 |
New zoom control for phone.
bug:5318964
+update assets
Change-Id: I39c6575803d22ab5db5c75a2d47257d12a397255
Diffstat (limited to 'src/com')
12 files changed, 152 insertions, 126 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 5c645a4..1274a72 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -460,7 +460,8 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void initializeZoom() { if (!mParameters.isZoomSupported()) return; mZoomMax = mParameters.getMaxZoom(); - mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); + // Currently we use immediate zoom for fast zooming to get better UX and + // there is no plan to take advantage of the smooth zoom. mZoomControl.setZoomMax(mZoomMax); mZoomControl.setZoomIndex(mParameters.getZoom()); mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); @@ -938,6 +939,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, if (mIndicatorControlContainer == null) return; loadCameraPreferences(); final String[] SETTING_KEYS = { + CameraSettings.KEY_FLASH_MODE, CameraSettings.KEY_WHITE_BALANCE, CameraSettings.KEY_SCENE_MODE}; final String[] OTHER_SETTING_KEYS = { @@ -948,7 +950,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, CameraPicker.setImageResourceId(R.drawable.ic_switch_photo_facing_holo_light); mIndicatorControlContainer.initialize(this, mPreferenceGroup, - CameraSettings.KEY_FLASH_MODE, mParameters.isZoomSupported(), + mParameters.isZoomSupported(), SETTING_KEYS, OTHER_SETTING_KEYS); mIndicatorControlContainer.setListener(this); } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index e9c3133..f100d28 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -469,6 +469,7 @@ public class VideoCamera extends ActivityBase loadCameraPreferences(); final String[] SETTING_KEYS = { + CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, CameraSettings.KEY_VIDEO_EFFECT, CameraSettings.KEY_WHITE_BALANCE, CameraSettings.KEY_VIDEO_QUALITY}; @@ -477,7 +478,6 @@ public class VideoCamera extends ActivityBase CameraPicker.setImageResourceId(R.drawable.ic_switch_video_facing_holo_light); mIndicatorControlContainer.initialize(this, mPreferenceGroup, - CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, mParameters.isZoomSupported(), SETTING_KEYS, OTHER_SETTING_KEYS); mIndicatorControlContainer.setListener(this); mPopupGestureDetector = new GestureDetector(this, @@ -2108,7 +2108,8 @@ public class VideoCamera extends ActivityBase if (!mParameters.isZoomSupported()) return; mZoomMax = mParameters.getMaxZoom(); - mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); + // Currently we use immediate zoom for fast zooming to get better UX and + // there is no plan to take advantage of the smooth zoom. mZoomControl.setZoomMax(mZoomMax); mZoomControl.setZoomIndex(mParameters.getZoom()); mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); diff --git a/src/com/android/camera/ui/IndicatorControl.java b/src/com/android/camera/ui/IndicatorControl.java index 78d51c1..4bc5d29 100644 --- a/src/com/android/camera/ui/IndicatorControl.java +++ b/src/com/android/camera/ui/IndicatorControl.java @@ -70,6 +70,8 @@ public abstract class IndicatorControl extends RelativeLayout implements View view = getChildAt(i); if (view instanceof RotateImageView) { ((RotateImageView) view).setDegree(degree); + } else if (view instanceof ZoomControl) { + ((ZoomControl) view).setDegree(degree); } } } diff --git a/src/com/android/camera/ui/IndicatorControlBar.java b/src/com/android/camera/ui/IndicatorControlBar.java index c1e6607..4297528 100644 --- a/src/com/android/camera/ui/IndicatorControlBar.java +++ b/src/com/android/camera/ui/IndicatorControlBar.java @@ -30,7 +30,7 @@ import android.widget.ImageView; * A view that contains the top-level indicator control. */ public class IndicatorControlBar extends IndicatorControl implements - View.OnClickListener, View.OnTouchListener { + View.OnClickListener { private static final String TAG = "IndicatorControlBar"; // Space between indicator icons. @@ -38,6 +38,7 @@ public class IndicatorControlBar extends IndicatorControl implements private ImageView mZoomIcon; private ImageView mSecondLevelIcon; + private ZoomControlBar mZoomControl; public IndicatorControlBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -45,27 +46,23 @@ public class IndicatorControlBar extends IndicatorControl implements @Override protected void onFinishInflate() { - mZoomIcon = (ImageView) findViewById(R.id.zoom_control_icon); mSecondLevelIcon = (ImageView) findViewById(R.id.second_level_indicator_bar_icon); mSecondLevelIcon.setOnClickListener(this); } public void initialize(Context context, PreferenceGroup group, - String flashSetting, boolean zoomSupported) { - // From UI spec, we have camera_flash setting on the first level. + boolean zoomSupported) { setPreferenceGroup(group); - addControls(new String[] {flashSetting}, null); // Add CameraPicker control. initializeCameraPicker(); - // add Zoom Icon. + // Add the ZoomControl if supported. if (zoomSupported) { - mZoomIcon.setOnTouchListener(this); - mZoomIcon.setVisibility(View.VISIBLE); + mZoomControl = (ZoomControlBar) findViewById(R.id.zoom_control); + mZoomControl.setVisibility(View.VISIBLE); } - requestLayout(); } @@ -76,15 +73,6 @@ public class IndicatorControlBar extends IndicatorControl implements return true; } - public boolean onTouch(View v, MotionEvent event) { - dismissSettingPopup(); - if (event.getAction() == MotionEvent.ACTION_DOWN) { - mOnIndicatorEventListener.onIndicatorEvent( - OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL); - } - return true; - } - public void onClick(View view) { dismissSettingPopup(); // Only for the click on mSecondLevelIcon. @@ -96,21 +84,25 @@ public class IndicatorControlBar extends IndicatorControl implements protected void onLayout( boolean changed, int left, int top, int right, int bottom) { // Layout the static components. + int padding = getPaddingTop(); super.onLayout(changed, left, top, right, bottom); int count = getChildCount(); if (count == 0) return; int width = right - left; - int offset = 0; - - for (int i = 0 ; i < count ; i++) { - View view = getChildAt(i); - if (view instanceof IndicatorButton) { - view.layout(0, offset, width, offset + width); - offset += (width + ICON_SPACING); - } + + // First indicator will be CameraPicker if exists. + if (mCameraPicker != null) { + mCameraPicker.layout(0, padding, width, padding + width); } - if (mCameraPicker != null) mCameraPicker.layout(0, offset, width, offset + width); + + // Layout the zoom control if required. + int offset = padding + width; // the padding and the icon height + if (mZoomControl != null) { + mZoomControl.layout(0, offset, width, bottom - top - offset); + } + + mSecondLevelIcon.layout(0, bottom - top - offset, width, bottom - top); } @Override @@ -126,6 +118,6 @@ public class IndicatorControlBar extends IndicatorControl implements } public void enableZoom(boolean enabled) { - if (mZoomIcon != null) mZoomIcon.setEnabled(enabled); + if (mZoomControl != null) mZoomControl.setEnabled(enabled); } } diff --git a/src/com/android/camera/ui/IndicatorControlBarContainer.java b/src/com/android/camera/ui/IndicatorControlBarContainer.java index 60eb6b2..9c01e01 100644 --- a/src/com/android/camera/ui/IndicatorControlBarContainer.java +++ b/src/com/android/camera/ui/IndicatorControlBarContainer.java @@ -39,8 +39,6 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer private Animation mFadeIn, mFadeOut; private Animation mSecondLevelFadeIn, mSecondLevelFadeOut; private IndicatorControlBar mIndicatorControlBar; - private ZoomControlBar mZoomControlBar; - private ZoomIndexBar mZoomIndexBar; private SecondLevelIndicatorControlBar mSecondLevelIndicatorControlBar; public IndicatorControlBarContainer(Context context, AttributeSet attrs) { @@ -59,10 +57,6 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer @Override protected void onFinishInflate() { - mZoomControlBar = (ZoomControlBar) findViewById(R.id.zoom_control); - mZoomControlBar.setOnIndicatorEventListener(this); - mZoomIndexBar = (ZoomIndexBar) findViewById(R.id.zoom_index_bar); - mZoomControlBar.setOnZoomIndexChangeListener(mZoomIndexBar); mIndicatorControlBar = (IndicatorControlBar) findViewById(R.id.indicator_bar); mIndicatorControlBar.setOnIndicatorEventListener(this); @@ -73,13 +67,10 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer @Override public void initialize(Context context, PreferenceGroup group, - String flashSetting, boolean isZoomSupported, - String[] secondLevelKeys, String[] secondLevelOtherSettingKeys) { + boolean isZoomSupported, String[] secondLevelKeys, + String[] secondLevelOtherSettingKeys) { - // We need to show/hide the zoom slider icon accordingly. - // From UI spec, we have camera_flash setting on the first level. - mIndicatorControlBar.initialize(context, group, flashSetting, - isZoomSupported); + mIndicatorControlBar.initialize(context, group, isZoomSupported); mSecondLevelIndicatorControlBar.initialize(context, group, secondLevelKeys, secondLevelOtherSettingKeys); @@ -88,8 +79,6 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer public void setDegree(int degree) { mIndicatorControlBar.setDegree(degree); mSecondLevelIndicatorControlBar.setDegree(degree); - mZoomControlBar.setDegree(degree); - mZoomIndexBar.setDegree(degree); } @Override @@ -98,8 +87,6 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer return mIndicatorControlBar.dispatchTouchEvent(event); } else if (mSecondLevelIndicatorControlBar.getVisibility() == View.VISIBLE) { return mSecondLevelIndicatorControlBar.dispatchTouchEvent(event); - } else if (mZoomControlBar.getVisibility() == View.VISIBLE) { - return mZoomControlBar.dispatchTouchEvent(event); } return true; } @@ -133,19 +120,6 @@ public class IndicatorControlBarContainer extends IndicatorControlContainer mIndicatorControlBar.setVisibility(View.VISIBLE); mSecondLevelIndicatorControlBar.startAnimation(mSecondLevelFadeOut); break; - - case OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL: - mIndicatorControlBar.setVisibility(View.GONE); - mZoomControlBar.setVisibility(View.VISIBLE); - mZoomIndexBar.setVisibility(View.VISIBLE); - mZoomControlBar.startZoomControl(); - break; - - case OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL: - mZoomControlBar.setVisibility(View.GONE); - mZoomIndexBar.setVisibility(View.GONE); - mIndicatorControlBar.setVisibility(View.VISIBLE); - break; } } diff --git a/src/com/android/camera/ui/IndicatorControlContainer.java b/src/com/android/camera/ui/IndicatorControlContainer.java index 552c551..3f66acb 100644 --- a/src/com/android/camera/ui/IndicatorControlContainer.java +++ b/src/com/android/camera/ui/IndicatorControlContainer.java @@ -23,8 +23,7 @@ import android.util.AttributeSet; public abstract class IndicatorControlContainer extends IndicatorControl { public abstract void initialize(Context context, PreferenceGroup group, - String flashSetting, boolean isZoomSupported, - String[] keys, String[] otherSettingKeys); + boolean isZoomSupported, String[] keys, String[] otherSettingKeys); public IndicatorControlContainer(Context context, AttributeSet attrs) { super(context, attrs); diff --git a/src/com/android/camera/ui/IndicatorControlWheel.java b/src/com/android/camera/ui/IndicatorControlWheel.java index f3f869a..af36e11 100644 --- a/src/com/android/camera/ui/IndicatorControlWheel.java +++ b/src/com/android/camera/ui/IndicatorControlWheel.java @@ -146,17 +146,13 @@ public class IndicatorControlWheel extends IndicatorControl implements } public void initialize(Context context, PreferenceGroup group, - String flashSetting, boolean isZoomSupported, String[] keys, - String[] otherSettingKeys) { + boolean isZoomSupported, String[] keys, String[] otherSettingKeys) { mShutterButtonRadius = IndicatorControlWheelContainer.SHUTTER_BUTTON_RADIUS; mStrokeWidth = Util.dpToPixel(IndicatorControlWheelContainer.STROKE_WIDTH); mWheelRadius = mShutterButtonRadius + mStrokeWidth * 0.5; setPreferenceGroup(group); - // Add first-level controls. - addControls(new String[] {flashSetting}, null); - // Add Zoom Icon. if (isZoomSupported) { mZoomIcon = (ImageView) addImageButton(context, R.drawable.ic_zoom_holo_light, false); diff --git a/src/com/android/camera/ui/IndicatorControlWheelContainer.java b/src/com/android/camera/ui/IndicatorControlWheelContainer.java index 4e2a03e..664aa9b 100644 --- a/src/com/android/camera/ui/IndicatorControlWheelContainer.java +++ b/src/com/android/camera/ui/IndicatorControlWheelContainer.java @@ -62,10 +62,9 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer } public void initialize(Context context, PreferenceGroup group, - String flashSetting, boolean isZoomSupported, - String[] keys, String[] otherSettingKeys) { - mIndicatorControlWheel.initialize(context, group, flashSetting, - isZoomSupported, keys, otherSettingKeys); + boolean isZoomSupported, String[] keys, String[] otherSettingKeys) { + mIndicatorControlWheel.initialize(context, group, isZoomSupported, + keys, otherSettingKeys); mIndicatorControlWheel.setOnIndicatorEventListener(this); } diff --git a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java index 386179d..bfa9f94 100644 --- a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java +++ b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java @@ -33,7 +33,7 @@ import android.widget.ImageView; public class SecondLevelIndicatorControlBar extends IndicatorControl implements View.OnClickListener { private static final String TAG = "SecondLevelIndicatorControlBar"; - private static int ICON_SPACING = Util.dpToPixel(32); + private static int ICON_SPACING = Util.dpToPixel(24); private ImageView mCloseIcon; private View mDivider; // the divider line int mDegree = 0; diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java index be2bdb9..662ee92 100644 --- a/src/com/android/camera/ui/ZoomControl.java +++ b/src/com/android/camera/ui/ZoomControl.java @@ -20,6 +20,7 @@ import com.android.camera.R; import android.content.Context; import android.os.Handler; +import android.os.SystemClock; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; @@ -30,16 +31,20 @@ import android.widget.RelativeLayout; * if the camera supports zooming. */ public abstract class ZoomControl extends RelativeLayout { - private static final String TAG = "ZoomControl"; + // The states of zoom button. + public static final int ZOOM_IN = 0; + public static final int ZOOM_OUT = 1; + public static final int ZOOM_STOP = 2; - public static final int ZOOMING_INTERVAL = 300; // milliseconds + private static final String TAG = "ZoomControl"; + private static final int ZOOMING_INTERVAL = 1000; // milliseconds protected ImageView mZoomIn; protected ImageView mZoomOut; protected ImageView mZoomSlider; protected int mSliderPosition = 0; protected int mDegree; - protected Handler mHandler; + private Handler mHandler; public interface OnZoomChangedListener { void onZoomValueChanged(int index); // only for immediate zoom @@ -58,23 +63,13 @@ public abstract class ZoomControl extends RelativeLayout { private OnZoomChangedListener mListener; private OnZoomIndexChangedListener mIndexListener; - // 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; - protected OnIndicatorEventListener mOnIndicatorEventListener; + private int mState; + private int mStep; protected final Runnable mRunnable = new Runnable() { public void run() { - if (mSliderPosition < 0) { - zoomIn(); - } else if (mSliderPosition > 0) { - zoomOut(); - } else { - stopZooming(); - } - mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); + performZoom(mState, false); } }; @@ -88,7 +83,6 @@ public abstract class ZoomControl extends RelativeLayout { public void startZoomControl() { mZoomSlider.setPressed(true); - mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); setZoomIndex(mZoomIndex); // Update the zoom index bar. } @@ -100,12 +94,13 @@ public abstract class ZoomControl extends RelativeLayout { } public void closeZoomControl() { - mHandler.removeCallbacks(mRunnable); - mSliderPosition = 0; mZoomSlider.setPressed(false); stopZooming(); - mOnIndicatorEventListener.onIndicatorEvent( - OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL); + if (!mSmoothZoomSupported) mHandler.removeCallbacks(mRunnable); + if (mOnIndicatorEventListener != null) { + mOnIndicatorEventListener.onIndicatorEvent( + OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL); + } } public void setZoomMax(int zoomMax) { @@ -143,30 +138,71 @@ public abstract class ZoomControl extends RelativeLayout { mSmoothZoomSupported = smoothZoomSupported; } - public boolean zoomIn() { - return (mZoomIndex == mZoomMax) ? false : changeZoomIndex(mZoomIndex + 1); + private boolean zoomIn() { + return (mZoomIndex == mZoomMax) ? false : changeZoomIndex(mZoomIndex + mStep); + } + + private boolean zoomOut() { + return (mZoomIndex == 0) ? false : changeZoomIndex(mZoomIndex - mStep); } - public boolean zoomOut() { - return (mZoomIndex == 0) ? false : changeZoomIndex(mZoomIndex - 1); + protected void setZoomStep(int step) { + mStep = step; } - public void stopZooming() { + private void stopZooming() { if (mSmoothZoomSupported) { if (mListener != null) mListener.onZoomStateChanged(ZOOM_STOP); } } + // Called from ZoomControlWheel to change the zoom level. + // TODO: merge the zoom control for both platforms. + protected void performZoom(int state) { + performZoom(state, true); + } + + private void performZoom(int state, boolean fromUser) { + if ((mState == state) && fromUser) return; + if (fromUser) mHandler.removeCallbacks(mRunnable); + mState = state; + switch (state) { + case ZOOM_IN: + zoomIn(); + break; + case ZOOM_OUT: + zoomOut(); + break; + case ZOOM_STOP: + stopZooming(); + break; + } + if (!mSmoothZoomSupported) { + // Repeat the zoom action on tablet as the user is still holding + // the zoom slider. + mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL / mZoomMax); + } + } + + // Called from ZoomControlBar to change the zoom level. + protected void performZoom(double zoomPercentage) { + int index = (int) (mZoomMax * zoomPercentage); + if (mZoomIndex == index) return; + changeZoomIndex(index); + } + private boolean changeZoomIndex(int index) { - int zoomType = (index < mZoomIndex) ? ZOOM_OUT : ZOOM_IN; if (mListener != null) { if (mSmoothZoomSupported) { + int zoomType = (index < mZoomIndex) ? ZOOM_OUT : ZOOM_IN; if (((zoomType == ZOOM_IN) && (mZoomIndex != mZoomMax)) || ((zoomType == ZOOM_OUT) && (mZoomIndex != 0))) { mListener.onZoomStateChanged(zoomType); } } else { - mListener.onZoomStateChanged(index); + if (index > mZoomMax) index = mZoomMax; + if (index < 0) index = 0; + mListener.onZoomValueChanged(index); setZoomIndex(index); } } diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java index d906dea..6bbb8f1 100644 --- a/src/com/android/camera/ui/ZoomControlBar.java +++ b/src/com/android/camera/ui/ZoomControlBar.java @@ -20,6 +20,7 @@ import com.android.camera.R; import com.android.camera.Util; import android.content.Context; +import android.os.Handler; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -29,9 +30,9 @@ import android.view.View; */ public class ZoomControlBar extends ZoomControl { private static final String TAG = "ZoomControlBar"; - private static final int STOP_ZOOM_BUFFER = Util.dpToPixel(30); - + private static int THRESHOLD_FIRST_MOVE = Util.dpToPixel(10); // pixels private View mBar; + private boolean mStartChanging; public ZoomControlBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -49,29 +50,42 @@ public class ZoomControlBar extends ZoomControl { if (!isEnabled()) return false; double y = (double) event.getY(); - int offset = getHeight() / 2; + // Calculate the absolute offset of the slider in the zoom control bar. // For left-hand users, as the device is rotated for 180 degree for // landscape mode, the zoom-in bottom should be on the top, so the // position should be reversed. - int delta; + int offset = 5 * getWidth() / 4; // the padding and the icon height + int height = getHeight(); + int range = height - 2 * offset; // the range of the zoom slider + int pos; // the relative position in the zoom slider bar if (mDegree == 180) { - delta = offset - (int) y; + pos = (int) y - offset; } else { - delta = (int) y - offset; + pos = height - (int) y - offset; } - // We need some space to stop zooming. - mSliderPosition = (Math.abs(delta) < STOP_ZOOM_BUFFER) ? 0 : delta; - - // TODO: add fast zoom change here + if (pos < 0) pos = 0; + if (pos > range) pos = range; switch (action) { case MotionEvent.ACTION_OUTSIDE: - case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: closeZoomControl(); break; - default: + + case MotionEvent.ACTION_DOWN: + mStartChanging = false; + case MotionEvent.ACTION_MOVE: + // Make sure the movement is large enough before we start + // changing the zoom. + if (!mStartChanging && (Math.abs(mSliderPosition - pos) + > THRESHOLD_FIRST_MOVE)) { + mStartChanging = true; + } + if (mStartChanging) { + performZoom(1.0d * pos / range); + mSliderPosition = pos; + } requestLayout(); } return true; @@ -87,30 +101,29 @@ public class ZoomControlBar extends ZoomControl { @Override protected void onLayout( boolean changed, int left, int top, int right, int bottom) { + if (mZoomMax == 0) return; + int width = right - left; int height = bottom - top; - int h = height / 2; + int range = height - 10 * width / 4; int pos; + // TODO: remove offset once we have correct ic_zoom_big.9.png. + int offset = 3 * width / 4; + // For left-hand users, as the device is rotated for 180 degree, // the zoom-in button should be on the top. if (mDegree == 180) { - pos = h - mSliderPosition - width / 2; mZoomOut.layout(0, 0, width, width); mZoomIn.layout(0, height - width, width, height); + pos = offset + mZoomIndex * range / mZoomMax; + mZoomSlider.layout(0, pos, width, pos + width); } else { - pos = h + mSliderPosition - width / 2; mZoomIn.layout(0, 0, width, width); mZoomOut.layout(0, height - width, width, height); + pos = offset + (mZoomMax - mZoomIndex) * range / mZoomMax; + mZoomSlider.layout(0, pos, width, pos + width); } - mBar.layout(0, width, width, height - width); - - // TODO: fix the pos once we have correct zoom_big asset. - if (pos < 3 * width / 4) { - pos = 3 * width / 4; - } else if (pos > (height - (7 * width / 4))) { - pos = height - (7 * width / 4); - } - mZoomSlider.layout(0, pos, width, pos + width); + mBar.layout(0, width, width, bottom - top - width); } } diff --git a/src/com/android/camera/ui/ZoomControlWheel.java b/src/com/android/camera/ui/ZoomControlWheel.java index bb70ddf..6a75097 100644 --- a/src/com/android/camera/ui/ZoomControlWheel.java +++ b/src/com/android/camera/ui/ZoomControlWheel.java @@ -75,6 +75,17 @@ public class ZoomControlWheel extends ZoomControl { mShutterButtonRadius = IndicatorControlWheelContainer.SHUTTER_BUTTON_RADIUS; mStrokeWidth = Util.dpToPixel(IndicatorControlWheelContainer.STROKE_WIDTH); mWheelRadius = mShutterButtonRadius + mStrokeWidth * 0.5; + super.setZoomStep(1); // one zoom level at a time + } + + private void performZoom() { + if (mSliderRadians > (Math.PI + BUFFER_RADIANS)) { + super.performZoom(ZOOM_OUT); + } else if (mSliderRadians < (Math.PI - BUFFER_RADIANS)) { + super.performZoom(ZOOM_IN); + } else { + super.performZoom(ZOOM_STOP); + } } @Override @@ -102,7 +113,8 @@ public class ZoomControlWheel extends ZoomControl { case MotionEvent.ACTION_CANCEL: closeZoomControl(); break; - default: + case MotionEvent.ACTION_MOVE: + performZoom(); requestLayout(); } return true; |