diff options
author | Chung-yih Wang <cywang@google.com> | 2011-08-24 23:48:29 +0800 |
---|---|---|
committer | Chung-yih Wang <cywang@google.com> | 2011-08-29 17:21:24 +0800 |
commit | ab2ffa88872149978823c3184d0af162d3cdca13 (patch) | |
tree | a44ada0a2acc03353fe87a0cd4ed29040e4eddcf /src/com/android/camera | |
parent | 5f47cc1a9ce83a5656751df5705674a1711687d1 (diff) | |
download | LegacyCamera-ab2ffa88872149978823c3184d0af162d3cdca13.zip LegacyCamera-ab2ffa88872149978823c3184d0af162d3cdca13.tar.gz LegacyCamera-ab2ffa88872149978823c3184d0af162d3cdca13.tar.bz2 |
Add ZoomControlWheel.
bug:5083780
Change-Id: I1a18c247d638edd3f8e5e0588170b6820f280f96
Diffstat (limited to 'src/com/android/camera')
-rw-r--r-- | src/com/android/camera/Camera.java | 116 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 125 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControl.java | 12 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlBar.java | 26 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlBarContainer.java | 28 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlContainer.java | 33 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlWheel.java | 44 | ||||
-rw-r--r-- | src/com/android/camera/ui/IndicatorControlWheelContainer.java | 50 | ||||
-rw-r--r-- | src/com/android/camera/ui/OnIndicatorEventListener.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/SecondLevelIndicatorControlBar.java | 4 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControl.java | 68 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControlBar.java | 50 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomControlWheel.java | 180 | ||||
-rw-r--r-- | src/com/android/camera/ui/ZoomPicker.java | 100 |
14 files changed, 511 insertions, 329 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index a71954c..accc369 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -19,7 +19,7 @@ package com.android.camera; import com.android.camera.ui.CameraPicker; import com.android.camera.ui.FaceView; import com.android.camera.ui.FocusRectangle; -import com.android.camera.ui.IndicatorControl; +import com.android.camera.ui.IndicatorControlContainer; import com.android.camera.ui.RotateImageView; import com.android.camera.ui.RotateLayout; import com.android.camera.ui.SharePopup; @@ -249,7 +249,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private Toast mNoShareToast; private final Handler mHandler = new MainHandler(); - private IndicatorControl mIndicatorControl; + private IndicatorControlContainer mIndicatorControlContainer; private PreferenceGroup mPreferenceGroup; // multiple cameras support @@ -335,8 +335,8 @@ public class Camera extends ActivityBase implements FocusManager.Listener, Editor editor = mPreferences.edit(); editor.putString(CameraSettings.KEY_EXPOSURE, "0"); editor.apply(); - if (mIndicatorControl != null) { - mIndicatorControl.reloadPreferences(); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.reloadPreferences(); } } } @@ -460,48 +460,45 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void initializeZoomControl() { mZoomControl = (ZoomControl) findViewById(R.id.zoom_control); - if (!mParameters.isZoomSupported()) { - mZoomControl.setZoomSupported(false); - } + if (!mParameters.isZoomSupported()) return; mZoomControl.initialize(this); } - private void initializeZoom() { - if (!mParameters.isZoomSupported()) return; - mZoomMax = mParameters.getMaxZoom(); - mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); - if (mZoomControl != null) { - mZoomControl.setZoomMax(mZoomMax); - mZoomControl.setZoomIndex(mParameters.getZoom()); - mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); - mZoomControl.setOnZoomChangeListener( - new ZoomControl.OnZoomChangedListener() { - // only for immediate zoom - @Override - public void onZoomValueChanged(int index) { - Camera.this.onZoomValueChanged(index); - } + private class ZoomChangeListener implements ZoomControl.OnZoomChangedListener { + // only for immediate zoom + @Override + public void onZoomValueChanged(int index) { + Camera.this.onZoomValueChanged(index); + } - // only for smooth zoom - @Override - public void onZoomStateChanged(int state) { - if (mPausing) return; + // only for smooth zoom + @Override + public void onZoomStateChanged(int state) { + if (mPausing) return; - Log.v(TAG, "zoom picker state=" + state); - if (state == ZoomControl.ZOOM_IN) { - Camera.this.onZoomValueChanged(mZoomMax); - } else if (state == ZoomControl.ZOOM_OUT){ - Camera.this.onZoomValueChanged(0); - } else { - mTargetZoomValue = -1; - if (mZoomState == ZOOM_START) { - mZoomState = ZOOM_STOPPING; - mCameraDevice.stopSmoothZoom(); - } - } + Log.v(TAG, "zoom picker state=" + state); + if (state == ZoomControl.ZOOM_IN) { + Camera.this.onZoomValueChanged(mZoomMax); + } else if (state == ZoomControl.ZOOM_OUT) { + Camera.this.onZoomValueChanged(0); + } else { + mTargetZoomValue = -1; + if (mZoomState == ZOOM_START) { + mZoomState = ZOOM_STOPPING; + mCameraDevice.stopSmoothZoom(); } - }); + } } + } + + private void initializeZoom() { + if (!mParameters.isZoomSupported()) return; + mZoomMax = mParameters.getMaxZoom(); + mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); + mZoomControl.setZoomMax(mZoomMax); + mZoomControl.setZoomIndex(mParameters.getZoom()); + mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); + mZoomControl.setOnZoomChangeListener(new ZoomChangeListener()); mCameraDevice.setZoomChangeListener(mZoomListener); } @@ -556,7 +553,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, @Override public boolean onDown(MotionEvent e) { // Check if the popup window is visible. - View popup = mIndicatorControl.getActiveSettingPopup(); + View popup = mIndicatorControlContainer.getActiveSettingPopup(); if (popup == null) return false; @@ -564,9 +561,9 @@ public class Camera extends ActivityBase implements FocusManager.Listener, // event by themselves. Dismiss the popup window if users touch on // other areas. if (!Util.pointInView(e.getX(), e.getY(), popup) - && !Util.pointInView(e.getX(), e.getY(), mIndicatorControl) + && !Util.pointInView(e.getX(), e.getY(), mIndicatorControlContainer) && !Util.pointInView(e.getX(), e.getY(), mPreviewFrame)) { - mIndicatorControl.dismissSettingPopup(); + mIndicatorControlContainer.dismissSettingPopup(); // Let event fall through. } return false; @@ -824,7 +821,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, mZoomValue = value; // Update the UI when we get zoom value. - if (mZoomControl != null) mZoomControl.setZoomIndex(value); + mZoomControl.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. @@ -1065,8 +1062,8 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void overrideCameraSettings(final String flashMode, final String whiteBalance, final String focusMode) { - if (mIndicatorControl != null) { - mIndicatorControl.overrideSettings( + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.overrideSettings( CameraSettings.KEY_FLASH_MODE, flashMode, CameraSettings.KEY_WHITE_BALANCE, whiteBalance, CameraSettings.KEY_FOCUS_MODE, focusMode); @@ -1092,8 +1089,9 @@ public class Camera extends ActivityBase implements FocusManager.Listener, private void initializeIndicatorControl() { // setting the indicator buttons. - mIndicatorControl = (IndicatorControl) findViewById(R.id.indicator_control); - if (mIndicatorControl == null) return; + mIndicatorControlContainer = + (IndicatorControlContainer) findViewById(R.id.indicator_control); + if (mIndicatorControlContainer == null) return; loadCameraPreferences(); final String[] SETTING_KEYS = { CameraSettings.KEY_WHITE_BALANCE, @@ -1105,20 +1103,24 @@ public class Camera extends ActivityBase implements FocusManager.Listener, CameraSettings.KEY_PICTURE_SIZE}; CameraPicker.setImageResourceId(R.drawable.ic_switch_photo_facing_holo_light); - mIndicatorControl.initialize(this, mPreferenceGroup, - CameraSettings.KEY_FLASH_MODE, SETTING_KEYS, OTHER_SETTING_KEYS); - mIndicatorControl.setListener(this); + mIndicatorControlContainer.initialize(this, mPreferenceGroup, + CameraSettings.KEY_FLASH_MODE, mParameters.isZoomSupported(), + SETTING_KEYS, OTHER_SETTING_KEYS); + mIndicatorControlContainer.setListener(this); } private boolean collapseCameraControls() { - if (mIndicatorControl != null && mIndicatorControl.dismissSettingPopup()) { + if ((mIndicatorControlContainer != null) + && mIndicatorControlContainer.dismissSettingPopup()) { return true; } return false; } private void enableCameraControls(boolean enable) { - if (mIndicatorControl != null) mIndicatorControl.setEnabled(enable); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.setEnabled(enable); + } if (mModePicker != null) mModePicker.setEnabled(enable); if (mZoomControl != null) mZoomControl.setEnabled(enable); } @@ -1161,7 +1163,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); - if (mIndicatorControl != null) mIndicatorControl.setDegree(degree); + if (mIndicatorControlContainer != null) mIndicatorControlContainer.setDegree(degree); if (mZoomControl != null) mZoomControl.setDegree(degree); } @@ -2153,13 +2155,13 @@ public class Camera extends ActivityBase implements FocusManager.Listener, if (mParameters.isZoomSupported()) { mZoomValue = 0; setCameraParametersWhenIdle(UPDATE_PARAM_ZOOM); - if (mZoomControl != null) mZoomControl.setZoomIndex(0); + mZoomControl.setZoomIndex(0); } - if (mIndicatorControl != null) { - mIndicatorControl.dismissSettingPopup(); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.dismissSettingPopup(); CameraSettings.restorePreferences(Camera.this, mPreferences, mParameters); - mIndicatorControl.reloadPreferences(); + mIndicatorControlContainer.reloadPreferences(); onSharedPreferenceChanged(); } } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 744357a..b6027be 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -17,12 +17,11 @@ package com.android.camera; import com.android.camera.ui.CameraPicker; -import com.android.camera.ui.IndicatorControl; +import com.android.camera.ui.IndicatorControlContainer; import com.android.camera.ui.IndicatorControlWheelContainer; import com.android.camera.ui.RotateImageView; import com.android.camera.ui.SharePopup; import com.android.camera.ui.ZoomControl; -import com.android.camera.ui.ZoomPicker; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; @@ -139,7 +138,7 @@ public class VideoCamera extends ActivityBase private PreviewFrameLayout mPreviewFrameLayout; private SurfaceHolder mSurfaceHolder = null; - private IndicatorControl mIndicatorControl; + private IndicatorControlContainer mIndicatorControlContainer; private View mReviewControl; private Toast mNoShareToast; @@ -453,20 +452,24 @@ public class VideoCamera extends ActivityBase } private boolean collapseCameraControls() { - if (mIndicatorControl != null && mIndicatorControl.dismissSettingPopup()) { + if ((mIndicatorControlContainer != null) + && mIndicatorControlContainer.dismissSettingPopup()) { return true; } return false; } private void enableCameraControls(boolean enable) { - if (mIndicatorControl != null) mIndicatorControl.setEnabled(enable); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.setEnabled(enable); + } if (mModePicker != null) mModePicker.setEnabled(enable); } private void initializeIndicatorControl() { - mIndicatorControl = (IndicatorControl) findViewById(R.id.indicator_control); - if (mIndicatorControl == null) return; + mIndicatorControlContainer = + (IndicatorControlContainer) findViewById(R.id.indicator_control); + if (mIndicatorControlContainer == null) return; loadCameraPreferences(); final String[] SETTING_KEYS = { @@ -476,10 +479,10 @@ public class VideoCamera extends ActivityBase CameraSettings.KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL}; CameraPicker.setImageResourceId(R.drawable.ic_switch_video_facing_holo_light); - mIndicatorControl.initialize(this, mPreferenceGroup, + mIndicatorControlContainer.initialize(this, mPreferenceGroup, CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, - SETTING_KEYS, OTHER_SETTING_KEYS); - mIndicatorControl.setListener(this); + mParameters.isZoomSupported(), SETTING_KEYS, OTHER_SETTING_KEYS); + mIndicatorControlContainer.setListener(this); mPopupGestureDetector = new GestureDetector(this, new PopupGestureListener()); } @@ -517,7 +520,7 @@ public class VideoCamera extends ActivityBase if (mThumbnailView != null) mThumbnailView.setDegree(degree); if (mModePicker != null) mModePicker.setDegree(degree); if (mSharePopup != null) mSharePopup.setOrientation(degree); - if (mIndicatorControl != null) mIndicatorControl.setDegree(degree); + if (mIndicatorControlContainer != null) mIndicatorControlContainer.setDegree(degree); } private void startPlayVideoActivity() { @@ -876,7 +879,9 @@ public class VideoCamera extends ActivityBase super.onPause(); mPausing = true; - if (mIndicatorControl != null) mIndicatorControl.dismissSettingPopup(); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.dismissSettingPopup(); + } finishRecorderAndCloseCamera(); @@ -1375,9 +1380,10 @@ public class VideoCamera extends ActivityBase if (mReviewControl != null) mReviewControl.setVisibility(View.GONE); if (mCaptureTimeLapse) { if (Util.isTabletUI()) { - ((IndicatorControlWheelContainer) mIndicatorControl).startTimeLapseAnimation( - mTimeBetweenTimeLapseFrameCaptureMs, - mRecordingStartTime); + ((IndicatorControlWheelContainer) mIndicatorControlContainer) + .startTimeLapseAnimation( + mTimeBetweenTimeLapseFrameCaptureMs, + mRecordingStartTime); } } } else { @@ -1386,7 +1392,8 @@ public class VideoCamera extends ActivityBase if (mReviewControl != null) mReviewControl.setVisibility(View.VISIBLE); if (mCaptureTimeLapse) { if (Util.isTabletUI()) { - ((IndicatorControlWheelContainer) mIndicatorControl).stopTimeLapseAnimation(); + ((IndicatorControlWheelContainer) mIndicatorControlContainer) + .stopTimeLapseAnimation(); } } } @@ -1735,14 +1742,14 @@ public class VideoCamera extends ActivityBase if (mParameters.isZoomSupported()) { mZoomValue = 0; setCameraParameters(); - if (mZoomControl != null) mZoomControl.setZoomIndex(0); + mZoomControl.setZoomIndex(0); } - if (mIndicatorControl != null) { - mIndicatorControl.dismissSettingPopup(); + if (mIndicatorControlContainer != null) { + mIndicatorControlContainer.dismissSettingPopup(); CameraSettings.restorePreferences(VideoCamera.this, mPreferences, mParameters); - mIndicatorControl.reloadPreferences(); + mIndicatorControlContainer.reloadPreferences(); onSharedPreferenceChanged(); } } @@ -1821,65 +1828,59 @@ public class VideoCamera extends ActivityBase @Override public boolean onDown(MotionEvent e) { // Check if the popup window is visible. - View popup = mIndicatorControl.getActiveSettingPopup(); + View popup = mIndicatorControlContainer.getActiveSettingPopup(); if (popup == null) return false; // Let popup window or indicator wheel handle the event by // themselves. Dismiss the popup window if users touch on other // areas. if (!Util.pointInView(e.getX(), e.getY(), popup) - && !Util.pointInView(e.getX(), e.getY(), mIndicatorControl)) { - mIndicatorControl.dismissSettingPopup(); + && !Util.pointInView(e.getX(), e.getY(), mIndicatorControlContainer)) { + mIndicatorControlContainer.dismissSettingPopup(); // Let event fall through. } return false; } } + private class ZoomChangeListener implements ZoomControl.OnZoomChangedListener { + // only for immediate zoom + @Override + public void onZoomValueChanged(int index) { + VideoCamera.this.onZoomValueChanged(index); + } + + // only for smooth zoom + @Override + public void onZoomStateChanged(int state) { + if (mPausing) return; + + Log.v(TAG, "zoom picker state=" + state); + if (state == ZoomControl.ZOOM_IN) { + VideoCamera.this.onZoomValueChanged(mZoomMax); + } else if (state == ZoomControl.ZOOM_OUT){ + VideoCamera.this.onZoomValueChanged(0); + } else { + mTargetZoomValue = -1; + if (mZoomState == ZOOM_START) { + mZoomState = ZOOM_STOPPING; + mCameraDevice.stopSmoothZoom(); + } + } + } + } + private void initializeZoomControl() { mZoomControl = (ZoomControl) findViewById(R.id.zoom_control); - if (!mParameters.isZoomSupported()) { - mZoomControl.setZoomSupported(false); - return; - } + if (!mParameters.isZoomSupported()) return; mZoomControl.initialize(this); mZoomMax = mParameters.getMaxZoom(); mSmoothZoomSupported = mParameters.isSmoothZoomSupported(); - if (mZoomControl != null) { - if (Util.isTabletUI()) ((ZoomPicker) mZoomControl).initialize(this); - mZoomControl.setZoomMax(mZoomMax); - mZoomControl.setZoomIndex(mParameters.getZoom()); - mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); - mZoomControl.setOnZoomChangeListener( - new ZoomPicker.OnZoomChangedListener() { - // only for immediate zoom - @Override - public void onZoomValueChanged(int index) { - VideoCamera.this.onZoomValueChanged(index); - } - - // only for smooth zoom - @Override - public void onZoomStateChanged(int state) { - if (mPausing) return; - - Log.v(TAG, "zoom picker state=" + state); - if (state == ZoomPicker.ZOOM_IN) { - VideoCamera.this.onZoomValueChanged(mZoomMax); - } else if (state == ZoomPicker.ZOOM_OUT){ - VideoCamera.this.onZoomValueChanged(0); - } else { - mTargetZoomValue = -1; - if (mZoomState == ZOOM_START) { - mZoomState = ZOOM_STOPPING; - mCameraDevice.stopSmoothZoom(); - } - } - } - }); - } - + mZoomControl.setZoomMax(mZoomMax); + mZoomControl.setZoomIndex(mParameters.getZoom()); + mZoomControl.setSmoothZoomSupported(mSmoothZoomSupported); + mZoomControl.setOnZoomChangeListener(new ZoomChangeListener() ); mCameraDevice.setZoomChangeListener(mZoomListener); } @@ -1891,7 +1892,7 @@ public class VideoCamera extends ActivityBase mZoomValue = value; // Update the UI when we get zoom value. - if (mZoomControl != null) mZoomControl.setZoomIndex(value); + mZoomControl.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. diff --git a/src/com/android/camera/ui/IndicatorControl.java b/src/com/android/camera/ui/IndicatorControl.java index d97646a..b31c751 100644 --- a/src/com/android/camera/ui/IndicatorControl.java +++ b/src/com/android/camera/ui/IndicatorControl.java @@ -74,18 +74,8 @@ public abstract class IndicatorControl extends RelativeLayout implements mOnIndicatorEventListener = listener; } - // For the initialization of first-level indicator control. - public void initialize(Context context, PreferenceGroup group, - String flashSetting, String[] keys, String[] otherSettingKeys) { - initialize(context, group, keys, otherSettingKeys); - } - - public void initialize(Context context, PreferenceGroup group, - String[] keys, String[] otherSettingKeys) { - // Initialize all variables and icons. + public void setPreferenceGroup(PreferenceGroup group) { mPreferenceGroup = group; - addControls(keys, otherSettingKeys); - requestLayout(); } protected void addControls(String[] keys, String[] otherSettingKeys) { diff --git a/src/com/android/camera/ui/IndicatorControlBar.java b/src/com/android/camera/ui/IndicatorControlBar.java index 6c2d15f..748e23c 100644 --- a/src/com/android/camera/ui/IndicatorControlBar.java +++ b/src/com/android/camera/ui/IndicatorControlBar.java @@ -21,6 +21,7 @@ import com.android.camera.R; import android.content.Context; import android.util.AttributeSet; +import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; @@ -28,7 +29,7 @@ import android.widget.ImageView; * A view that contains the top-level indicator control. */ public class IndicatorControlBar extends IndicatorControl implements - View.OnClickListener { + View.OnClickListener, View.OnTouchListener { private static final String TAG = "IndicatorControlBar"; private ImageView mZoomIcon; @@ -41,7 +42,8 @@ public class IndicatorControlBar extends IndicatorControl implements public void initialize(Context context, PreferenceGroup group, String flashSetting, boolean zoomSupported) { // From UI spec, we have camera_flash setting on the first level. - super.initialize(context, group, new String[] {flashSetting}, null); + setPreferenceGroup(group); + addControls(new String[] {flashSetting}, null); // Add CameraPicker control. initializeCameraPicker(); @@ -49,7 +51,7 @@ public class IndicatorControlBar extends IndicatorControl implements // add Zoom Icon. if (zoomSupported) { mZoomIcon = (ImageView) findViewById(R.id.zoom_control_icon); - mZoomIcon.setOnClickListener(this); + mZoomIcon.setOnTouchListener(this); mZoomIcon.setVisibility(View.VISIBLE); } @@ -58,15 +60,21 @@ public class IndicatorControlBar extends IndicatorControl implements requestLayout(); } - public void onClick(View view) { + public boolean onTouch(View v, MotionEvent event) { dismissSettingPopup(); - if (view == mZoomIcon) { - mOnIndicatorEventListener.onIndicatorEvent( - OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL_BAR); - } else if (view == mSecondLevelIcon) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { mOnIndicatorEventListener.onIndicatorEvent( - OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR); + OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL); + return true; } + return false; + } + + public void onClick(View view) { + dismissSettingPopup(); + // Only for the click on mSecondLevelIcon. + mOnIndicatorEventListener.onIndicatorEvent( + OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR); } @Override diff --git a/src/com/android/camera/ui/IndicatorControlBarContainer.java b/src/com/android/camera/ui/IndicatorControlBarContainer.java index 3695d56..0ca378d 100644 --- a/src/com/android/camera/ui/IndicatorControlBarContainer.java +++ b/src/com/android/camera/ui/IndicatorControlBarContainer.java @@ -22,6 +22,7 @@ import com.android.camera.R; import android.content.Context; import android.util.AttributeSet; +import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; @@ -30,8 +31,8 @@ import android.view.animation.AnimationUtils; * The IndicatorControlBarContainer is a IndicatorControl containing * IndicatorControlBar, SecondIndicatorControlBar and ZoomControlBar for Phone UI. */ -public class IndicatorControlBarContainer extends IndicatorControl implements - OnIndicatorEventListener { +public class IndicatorControlBarContainer extends IndicatorControlContainer + implements OnIndicatorEventListener { private static final String TAG = "IndicatorControlBarContainer"; private Animation mFadeIn, mFadeOut; @@ -45,8 +46,8 @@ public class IndicatorControlBarContainer extends IndicatorControl implements @Override public void initialize(Context context, PreferenceGroup group, - String flashSetting, String[] secondLevelKeys, - String[] secondLevelOtherSettingKeys) { + String flashSetting, boolean isZoomSupported, + String[] secondLevelKeys, String[] secondLevelOtherSettingKeys) { mZoomControlBar = (ZoomControlBar) findViewById(R.id.zoom_control); mZoomControlBar.setOnIndicatorEventListener(this); @@ -56,7 +57,7 @@ public class IndicatorControlBarContainer extends IndicatorControl implements mIndicatorControlBar = (IndicatorControlBar) findViewById(R.id.indicator_bar); mIndicatorControlBar.initialize(context, group, flashSetting, - mZoomControlBar.isZoomSupported()); + isZoomSupported); mIndicatorControlBar.setOnIndicatorEventListener(this); mSecondLevelIndicatorControlBar = (SecondLevelIndicatorControlBar) @@ -77,6 +78,18 @@ public class IndicatorControlBarContainer extends IndicatorControl implements mZoomControlBar.setDegree(degree); } + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + if (mIndicatorControlBar.getVisibility() == View.VISIBLE) { + 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 false; + } + public void onIndicatorEvent(int event) { switch (event) { case OnIndicatorEventListener.EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR: @@ -91,12 +104,13 @@ public class IndicatorControlBarContainer extends IndicatorControl implements mIndicatorControlBar.setVisibility(View.VISIBLE); break; - case OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL_BAR: + case OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL: mIndicatorControlBar.setVisibility(View.GONE); mZoomControlBar.setVisibility(View.VISIBLE); + mZoomControlBar.startZoomControl(); break; - case OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL_BAR: + case OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL: mZoomControlBar.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 new file mode 100644 index 0000000..2e6711f --- /dev/null +++ b/src/com/android/camera/ui/IndicatorControlContainer.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.ui; + +import com.android.camera.PreferenceGroup; + +import android.content.Context; +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); + + 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 e432f6d..8d37b19 100644 --- a/src/com/android/camera/ui/IndicatorControlWheel.java +++ b/src/com/android/camera/ui/IndicatorControlWheel.java @@ -56,6 +56,7 @@ public class IndicatorControlWheel extends IndicatorControl implements private static final int SECOND_LEVEL_START_DEGREES = 60; private static final int SECOND_LEVEL_END_DEGREES = 300; private static final int CLOSE_ICON_DEFAULT_DEGREES = 315; + private static final int ZOOM_ICON_DEFAULT_DEGREES = 180; private static final int ANIMATION_TIME = 300; // milliseconds @@ -109,9 +110,7 @@ public class IndicatorControlWheel extends IndicatorControl implements private double mSectorRadians[] = new double[2]; private double mTouchSectorRadians[] = new double[2]; - // TODO: we won't need these buttons later once we switch to new zoom control. - private View mZoomIn; - private View mZoomOut; + private View mZoomIcon; public IndicatorControlWheel(Context context, AttributeSet attrs) { super(context, attrs); @@ -140,6 +139,7 @@ public class IndicatorControlWheel extends IndicatorControl implements @Override public void onClick(View view) { + if (view == mZoomIcon) return; mPressedIndex = -1; dismissSettingPopup(); mInAnimation = true; @@ -148,15 +148,23 @@ public class IndicatorControlWheel extends IndicatorControl implements } public void initialize(Context context, PreferenceGroup group, - String flashSetting, String[] keys, String[] otherSettingKeys) { + String flashSetting, 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. - super.initialize(context, group, new String[] {flashSetting}, null); + addControls(new String[] {flashSetting}, null); + + // Add Zoom Icon. + if (isZoomSupported) { + mZoomIcon = (ImageView) addImageButton(context, R.drawable.ic_zoom_holo_light, false); + } - // Add CameraPicker control. + // Add CameraPicker. initializeCameraPicker(); // Add second-level Indicator Icon. @@ -245,7 +253,16 @@ public class IndicatorControlWheel extends IndicatorControl implements } } if ((index != -1) && (action != MotionEvent.ACTION_MOVE)) { - getChildAt(index).dispatchTouchEvent(event); + View view = getChildAt(index); + // Switch to zoom control only if a touch down event is received. + if ((view == mZoomIcon) && (action == MotionEvent.ACTION_DOWN)) { + mPressedIndex = -1; + mOnIndicatorEventListener.onIndicatorEvent( + OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL); + return true; + } else { + getChildAt(index).dispatchTouchEvent(event); + } } // Once the button is up, reset the press index. mPressedIndex = (action == MotionEvent.ACTION_UP) ? -1 : index; @@ -319,7 +336,18 @@ public class IndicatorControlWheel extends IndicatorControl implements int sectors = (count <= 1) ? 0 : (count - 1); double sectorDegrees = FIRST_LEVEL_SECTOR_DEGREES; mSectorRadians[0] = Math.toRadians(sectorDegrees); - double degrees = (FIRST_LEVEL_END_DEGREES - sectors * sectorDegrees); + int zoomIndex = indexOfChild(mZoomIcon); + double degrees; + + // Make sure the zoom button is located at 180 degrees. If there are + // more buttons than we could show in the visible angle from 90 degrees + // to 270 degrees, the modification of FIRST_LEVEL_SECTOR_DEGREES is + // required then. + if (zoomIndex >= 0) { + degrees = ZOOM_ICON_DEFAULT_DEGREES - (zoomIndex * sectorDegrees); + } else { + degrees = FIRST_LEVEL_END_DEGREES - (sectors * sectorDegrees); + } mStartVisibleRadians[0] = Math.toRadians(degrees); int startIndex = 0; diff --git a/src/com/android/camera/ui/IndicatorControlWheelContainer.java b/src/com/android/camera/ui/IndicatorControlWheelContainer.java index 27f5455..b7b338f 100644 --- a/src/com/android/camera/ui/IndicatorControlWheelContainer.java +++ b/src/com/android/camera/ui/IndicatorControlWheelContainer.java @@ -31,7 +31,8 @@ import android.view.View; * ShutterButton, a IndicatorControlWheel (which combines first-level and * second-level indicators) and a ZoomControlWheel. */ -public class IndicatorControlWheelContainer extends IndicatorControl { +public class IndicatorControlWheelContainer extends IndicatorControlContainer + implements OnIndicatorEventListener { public static final int STROKE_WIDTH = 87; public static final int SHUTTER_BUTTON_RADIUS = 74; public static final int FULL_WHEEL_RADIUS = 93; @@ -41,6 +42,7 @@ public class IndicatorControlWheelContainer extends IndicatorControl { private View mShutterButton; private double mShutterButtonRadius; private IndicatorControlWheel mIndicatorControlWheel; + private ZoomControlWheel mZoomControlWheel; private int mCenterX, mCenterY; public IndicatorControlWheelContainer(Context context, AttributeSet attrs) { @@ -51,16 +53,35 @@ public class IndicatorControlWheelContainer extends IndicatorControl { protected void onFinishInflate() { mShutterButton = findViewById(R.id.shutter_button); mShutterButtonRadius = Util.dpToPixel(SHUTTER_BUTTON_RADIUS); + + mZoomControlWheel = (ZoomControlWheel) findViewById(R.id.zoom_control); + mZoomControlWheel.setOnIndicatorEventListener(this); + mIndicatorControlWheel = (IndicatorControlWheel) findViewById( R.id.indicator_control_wheel); } - @Override public void initialize(Context context, PreferenceGroup group, - String flashSetting, String[] keys, String[] otherSettingKeys) { - mIndicatorControlWheel.initialize(context, group, - flashSetting, keys, otherSettingKeys); - // TODO: add ZoomControlWheel here. + String flashSetting, boolean isZoomSupported, + String[] keys, String[] otherSettingKeys) { + mIndicatorControlWheel.initialize(context, group, flashSetting, + isZoomSupported, keys, otherSettingKeys); + mIndicatorControlWheel.setOnIndicatorEventListener(this); + } + + public void onIndicatorEvent(int event) { + switch (event) { + case OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL: + mIndicatorControlWheel.setVisibility(View.GONE); + mZoomControlWheel.setVisibility(View.VISIBLE); + mZoomControlWheel.startZoomControl(); + break; + + case OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL: + mZoomControlWheel.setVisibility(View.GONE); + mIndicatorControlWheel.setVisibility(View.VISIBLE); + break; + } } @Override @@ -75,7 +96,11 @@ public class IndicatorControlWheelContainer extends IndicatorControl { // Check if the event should be dispatched to the shutter button. if (radius <= mShutterButtonRadius) { - mIndicatorControlWheel.onTouchOutBound(); + if (mIndicatorControlWheel.getVisibility() == View.VISIBLE) { + mIndicatorControlWheel.onTouchOutBound(); + } else { + return mZoomControlWheel.dispatchTouchEvent(event); + } if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { return mShutterButton.dispatchTouchEvent(event); } @@ -89,8 +114,11 @@ public class IndicatorControlWheelContainer extends IndicatorControl { return true; } - // TODO: dispatch event to ZoomControlWheel instead if it is visible. - return mIndicatorControlWheel.dispatchTouchEvent(event); + if (mIndicatorControlWheel.getVisibility() == View.VISIBLE) { + return mIndicatorControlWheel.dispatchTouchEvent(event); + } else { + return mZoomControlWheel.dispatchTouchEvent(event); + } } @Override @@ -108,6 +136,7 @@ public class IndicatorControlWheelContainer extends IndicatorControl { mCenterY + shutterButtonHeight - shutterButtonHeight / 2); // Layout the control wheel. mIndicatorControlWheel.layout(0, 0, right - left, bottom - top); + mZoomControlWheel.layout(0, 0, right - left, bottom - top); } @Override @@ -116,6 +145,7 @@ public class IndicatorControlWheelContainer extends IndicatorControl { int freeSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); mShutterButton.measure(freeSpec, freeSpec); mIndicatorControlWheel.measure(freeSpec, freeSpec); + mZoomControlWheel.measure(freeSpec, freeSpec); // Measure myself. Add some buffer for highlight arc. int desiredWidth = mShutterButton.getMeasuredWidth() @@ -165,6 +195,7 @@ public class IndicatorControlWheelContainer extends IndicatorControl { @Override public void setDegree(int degree) { mIndicatorControlWheel.setDegree(degree); + mZoomControlWheel.setDegree(degree); } public void startTimeLapseAnimation(int timeLapseInterval, long startTime) { @@ -179,6 +210,7 @@ public class IndicatorControlWheelContainer extends IndicatorControl { @Override public void setEnabled(boolean enabled) { mIndicatorControlWheel.setEnabled(enabled); + mZoomControlWheel.setEnabled(enabled); } @Override diff --git a/src/com/android/camera/ui/OnIndicatorEventListener.java b/src/com/android/camera/ui/OnIndicatorEventListener.java index f4e1deb..566f5c7 100644 --- a/src/com/android/camera/ui/OnIndicatorEventListener.java +++ b/src/com/android/camera/ui/OnIndicatorEventListener.java @@ -19,7 +19,7 @@ package com.android.camera.ui; public interface OnIndicatorEventListener { public static int EVENT_ENTER_SECOND_LEVEL_INDICATOR_BAR = 0; public static int EVENT_LEAVE_SECOND_LEVEL_INDICATOR_BAR = 1; - public static int EVENT_ENTER_ZOOM_CONTROL_BAR = 2; - public static int EVENT_LEAVE_ZOOM_CONTROL_BAR = 3; + public static int EVENT_ENTER_ZOOM_CONTROL = 2; + public static int EVENT_LEAVE_ZOOM_CONTROL = 3; void onIndicatorEvent(int event); } diff --git a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java index 8fb3599..5ce586e 100644 --- a/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java +++ b/src/com/android/camera/ui/SecondLevelIndicatorControlBar.java @@ -40,7 +40,6 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements super(context, attrs); } - @Override public void initialize(Context context, PreferenceGroup group, String[] keys, String[] otherSettingKeys) { if (mCloseIcon == null) { @@ -49,7 +48,8 @@ public class SecondLevelIndicatorControlBar extends IndicatorControl implements mCloseIcon.setOnClickListener(this); addView(mCloseIcon); } - super.initialize(context, group, keys, otherSettingKeys); + setPreferenceGroup(group); + addControls(keys, otherSettingKeys); if (mDegree != 0) setDegree(mDegree); } diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java index 142e4b8..6bb22a9 100644 --- a/src/com/android/camera/ui/ZoomControl.java +++ b/src/com/android/camera/ui/ZoomControl.java @@ -19,8 +19,10 @@ package com.android.camera.ui; import com.android.camera.R; import android.content.Context; +import android.os.Handler; import android.util.AttributeSet; import android.view.View; +import android.widget.ImageView; import android.widget.RelativeLayout; /** @@ -30,15 +32,23 @@ import android.widget.RelativeLayout; public abstract class ZoomControl extends RelativeLayout { private static final String TAG = "ZoomControl"; + public static final int ZOOMING_INTERVAL = 300; // milliseconds + + protected ImageView mZoomIn; + protected ImageView mZoomOut; + protected ImageView mZoomSlider; + protected int mSliderPosition = 0; + protected int mDegree; + protected Handler mHandler; + public interface OnZoomChangedListener { void onZoomValueChanged(int index); // only for immediate zoom void onZoomStateChanged(int state); // only for smooth zoom } - private int mZoomMax, mZoomIndex; + protected int mZoomMax, mZoomIndex; private boolean mSmoothZoomSupported; private OnZoomChangedListener mListener; - private boolean mZoomSupported = true; // The state of zoom button. public static final int ZOOM_IN = 0; @@ -47,22 +57,53 @@ public abstract class ZoomControl extends RelativeLayout { protected OnIndicatorEventListener mOnIndicatorEventListener; + 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); + } + }; + public ZoomControl(Context context, AttributeSet attrs) { super(context, attrs); } - public abstract void initialize(Context context); + public void initialize(Context context) { + mZoomIn = addImageView(context, R.drawable.ic_zoom_in_holo_light); + mZoomSlider = addImageView(context, R.drawable.btn_zoom_slider); + mZoomOut = addImageView(context, R.drawable.ic_zoom_out_holo_light); + mHandler = new Handler(); + } - public void setZoomMax(int zoomMax) { - mZoomMax = zoomMax; + public void startZoomControl() { + mZoomSlider.setPressed(true); + mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); } - public void setZoomSupported(boolean supported) { - mZoomSupported = supported; + protected ImageView addImageView(Context context, int iconResourceId) { + ImageView image = new RotateImageView(context); + image.setImageResource(iconResourceId); + addView(image); + return image; } - public boolean isZoomSupported() { - return mZoomSupported; + public void closeZoomControl() { + mHandler.removeCallbacks(mRunnable); + mSliderPosition = 0; + mZoomSlider.setPressed(false); + stopZooming(); + mOnIndicatorEventListener.onIndicatorEvent( + OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL); + } + + public void setZoomMax(int zoomMax) { + mZoomMax = zoomMax; } public void setOnZoomChangeListener(OnZoomChangedListener listener) { @@ -78,6 +119,7 @@ public abstract class ZoomControl extends RelativeLayout { throw new IllegalArgumentException("Invalid zoom value:" + index); } mZoomIndex = index; + invalidate(); } public void setSmoothZoomSupported(boolean smoothZoomSupported) { @@ -108,13 +150,15 @@ public abstract class ZoomControl extends RelativeLayout { } } else { mListener.onZoomStateChanged(index); + mZoomIndex = index; + invalidate(); } - mZoomIndex = index; } return true; } public void setDegree(int degree) { + mDegree = degree; int count = getChildCount(); for (int i = 0 ; i < count ; ++i) { View view = getChildAt(i); @@ -123,8 +167,4 @@ public abstract class ZoomControl extends RelativeLayout { } } } - - protected int getZoomIndex() { - return mZoomIndex; - } } diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java index 07ad143..fdfeb50 100644 --- a/src/com/android/camera/ui/ZoomControlBar.java +++ b/src/com/android/camera/ui/ZoomControlBar.java @@ -19,38 +19,16 @@ package com.android.camera.ui; import com.android.camera.R; import android.content.Context; -import android.os.Handler; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.widget.ImageView; /** * A view that contains camera zoom control and its layout. */ public class ZoomControlBar extends ZoomControl { private static final String TAG = "ZoomControlBar"; - - private static final int ZOOMING_INTERVAL = 300; // milliseconds - - private ImageView mZoomIn; - private ImageView mZoomOut; - private ImageView mZoomSlider; private View mBar; - private int mSliderPosition = 0; - private Handler mHandler; - private int mDegree; - - private final Runnable mRunnable = new Runnable() { - public void run() { - if (mSliderPosition < 0) { - zoomIn(); - } else if (mSliderPosition > 0) { - zoomOut(); - } - if (mSliderPosition != 0) mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); - } - }; public ZoomControlBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -58,28 +36,10 @@ public class ZoomControlBar extends ZoomControl { @Override public void initialize(Context context) { - mZoomIn = addImageView(context, R.drawable.ic_zoom_in_holo_light); + super.initialize(context); mBar = new View(context); mBar.setBackgroundResource(R.drawable.ic_zoom_big); addView(mBar); - mZoomSlider = addImageView(context, R.drawable.btn_zoom_slider); - mZoomOut = addImageView(context, R.drawable.ic_zoom_out_holo_light); - mHandler = new Handler(); - } - - ImageView addImageView(Context context, int iconResourceId) { - ImageView image = new RotateImageView(context); - image.setImageResource(iconResourceId); - addView(image); - return image; - } - - private void closeControl() { - mHandler.removeCallbacks(mRunnable); - mSliderPosition = 0; - stopZooming(); - mOnIndicatorEventListener.onIndicatorEvent( - OnIndicatorEventListener.EVENT_LEAVE_ZOOM_CONTROL_BAR); } @Override @@ -104,15 +64,10 @@ public class ZoomControlBar extends ZoomControl { // TODO: add fast zoom change here switch (action) { - case MotionEvent.ACTION_DOWN: - mHandler.postDelayed(mRunnable, ZOOMING_INTERVAL); - mZoomSlider.setPressed(true); - break; case MotionEvent.ACTION_OUTSIDE: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - mZoomSlider.setPressed(false); - closeControl(); + closeZoomControl(); break; default: requestLayout(); @@ -124,7 +79,6 @@ public class ZoomControlBar extends ZoomControl { public void setDegree(int degree) { // layout for the left-hand camera control if ((degree == 180) || (mDegree == 180)) requestLayout(); - mDegree = degree; super.setDegree(degree); } diff --git a/src/com/android/camera/ui/ZoomControlWheel.java b/src/com/android/camera/ui/ZoomControlWheel.java new file mode 100644 index 0000000..40c1124 --- /dev/null +++ b/src/com/android/camera/ui/ZoomControlWheel.java @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.ui; + +import com.android.camera.R; +import com.android.camera.Util; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; + +/** + * A view that contains camera zoom control and its layout. + */ +public class ZoomControlWheel extends ZoomControl { + private static final String TAG = "ZoomControlWheel"; + private static final int HIGHLIGHT_WIDTH = 4; + private static final int HIGHLIGHT_DEGREES = 30; + private static final int TRAIL_WIDTH = 2; + private static final int ZOOM_IN_ICON_DEGREES = 60; + private static final int ZOOM_OUT_ICON_DEGREES = 300; + private static final int DEFAULT_SLIDER_POSITION = 180; + private static final int MAX_SLIDER_ANGLE = + ZOOM_OUT_ICON_DEGREES - (HIGHLIGHT_DEGREES / 2); + private static final int MIN_SLIDER_ANGLE = + ZOOM_IN_ICON_DEGREES + (HIGHLIGHT_DEGREES / 2); + private static final float EDGE_STROKE_WIDTH = 6f; + private static final double BUFFER_RADIANS = Math.toRadians(HIGHLIGHT_DEGREES / 2); + private double mSliderRadians = Math.toRadians(DEFAULT_SLIDER_POSITION); + + private final int HIGHLIGHT_COLOR; + private final int TRAIL_COLOR; + + // The center of the shutter button. + private int mCenterX, mCenterY; + // The width of the wheel stroke. + private int mStrokeWidth; + private double mShutterButtonRadius; + private double mWheelRadius; + private Paint mBackgroundPaint; + private RectF mBackgroundRect; + + public ZoomControlWheel(Context context, AttributeSet attrs) { + super(context, attrs); + setWillNotDraw(false); + + mBackgroundPaint = new Paint(); + mBackgroundPaint.setStyle(Paint.Style.STROKE); + mBackgroundPaint.setAntiAlias(true); + + mBackgroundRect = new RectF(); + Resources resources = context.getResources(); + HIGHLIGHT_COLOR = resources.getColor(R.color.review_control_pressed_color); + TRAIL_COLOR = resources.getColor(R.color.icon_disabled_color); + } + + @Override + public void initialize(Context context) { + super.initialize(context); + mShutterButtonRadius = IndicatorControlWheelContainer.SHUTTER_BUTTON_RADIUS; + mStrokeWidth = Util.dpToPixel(IndicatorControlWheelContainer.STROKE_WIDTH); + mWheelRadius = mShutterButtonRadius + mStrokeWidth * 0.5; + requestLayout(); + } + + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + if (!onFilterTouchEventForSecurity(event)) return false; + int action = event.getAction(); + + double dx = event.getX() - mCenterX; + double dy = mCenterY - event.getY(); + double radius = Math.sqrt(dx * dx + dy * dy); + // Ignore the event if too far from the shutter button. + mSliderRadians = Math.atan2(dy, dx); + if (mSliderRadians < 0) mSliderRadians += Math.PI * 2; + if (mSliderRadians > (Math.PI + BUFFER_RADIANS)) { + mSliderPosition = 1; + } else { + mSliderPosition = (mSliderRadians < (Math.PI - BUFFER_RADIANS)) ? -1 : 0; + } + // We assume the slider button is pressed all the time when the + // zoom control is active. So we take care of the following events + // only. + switch (action) { + case MotionEvent.ACTION_OUTSIDE: + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + closeZoomControl(); + break; + default: + requestLayout(); + } + return true; + } + + @Override + public void startZoomControl() { + super.startZoomControl(); + mSliderRadians = Math.toRadians(DEFAULT_SLIDER_POSITION); + } + + private void layoutIcon(View view, double radian) { + int x = mCenterX + (int)(mWheelRadius * Math.cos(radian)); + int y = mCenterY - (int)(mWheelRadius * Math.sin(radian)); + int width = view.getMeasuredWidth(); + int height = view.getMeasuredHeight(); + view.layout(x - width / 2, y - height / 2, x + width / 2, + y + height / 2); + } + + private double getSliderDrawAngle() { + double sliderAngle = mSliderRadians; + if (sliderAngle > Math.toRadians(MAX_SLIDER_ANGLE)) { + return Math.toRadians(MAX_SLIDER_ANGLE); + } else if (sliderAngle < Math.toRadians(MIN_SLIDER_ANGLE)) { + return Math.toRadians(MIN_SLIDER_ANGLE); + } + return sliderAngle; + } + + @Override + protected void onLayout( + boolean changed, int left, int top, int right, int bottom) { + mCenterX = right - left - Util.dpToPixel( + IndicatorControlWheelContainer.FULL_WHEEL_RADIUS); + mCenterY = (bottom - top) / 2; + layoutIcon(mZoomIn, Math.toRadians(ZOOM_IN_ICON_DEGREES)); + layoutIcon(mZoomOut, Math.toRadians(ZOOM_OUT_ICON_DEGREES)); + layoutIcon(mZoomSlider, getSliderDrawAngle()); + } + + private double getZoomIndexAngle() { + return Math.toRadians(MAX_SLIDER_ANGLE - + (MAX_SLIDER_ANGLE - MIN_SLIDER_ANGLE) * mZoomIndex / mZoomMax); + } + + private void drawArc(Canvas canvas, int startAngle, int sweepAngle, + double radius, int color, int width) { + mBackgroundRect.set((float) (mCenterX - radius), (float) (mCenterY - radius), + (float) (mCenterX + radius), (float) (mCenterY + radius)); + mBackgroundPaint.setStrokeWidth(width); + mBackgroundPaint.setStrokeCap(Paint.Cap.ROUND); + mBackgroundPaint.setColor(color); + canvas.drawArc(mBackgroundRect, startAngle, sweepAngle, false, mBackgroundPaint); + } + + @Override + protected void onDraw(Canvas canvas) { + // Draw slider highlight. + float delta = mStrokeWidth * 0.5f; + float radius = (float) (mWheelRadius + mStrokeWidth * 0.5 + EDGE_STROKE_WIDTH); + int degree = (int) Math.toDegrees(getZoomIndexAngle()); + drawArc(canvas, (-degree - HIGHLIGHT_DEGREES / 2), HIGHLIGHT_DEGREES, + radius, HIGHLIGHT_COLOR, HIGHLIGHT_WIDTH); + // Draw the slider trail. + drawArc(canvas, -MAX_SLIDER_ANGLE, (MAX_SLIDER_ANGLE - MIN_SLIDER_ANGLE), + mWheelRadius, TRAIL_COLOR, TRAIL_WIDTH); + super.onDraw(canvas); + } +} diff --git a/src/com/android/camera/ui/ZoomPicker.java b/src/com/android/camera/ui/ZoomPicker.java deleted file mode 100644 index d25b6f8..0000000 --- a/src/com/android/camera/ui/ZoomPicker.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.camera.ui; - -import com.android.camera.R; - -import android.content.Context; -import android.os.Handler; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.view.View.OnTouchListener; - -/** - * A class to increase or decrease zoom - */ -public class ZoomPicker extends ZoomControl { - private final String TAG = "ZoomPicker"; - - private View mIncrementButton; - private View mDecrementButton; - private int mState = ZOOM_STOP; - - private Handler mHandler; - - public ZoomPicker(Context context, AttributeSet attrs) { - super(context, attrs); - } - - private final Runnable mRunnable = new Runnable() { - public void run() { - if (zooming()) mHandler.postDelayed(this, 65); - } - }; - - private boolean zooming() { - switch (mState) { - case ZOOM_IN: - return zoomIn(); - case ZOOM_OUT: - return zoomOut(); - default: - return false; - } - } - - @Override - public void initialize(Context context) { - final View increment = getRootView().findViewById(R.id.zoom_increment); - final View decrement = getRootView().findViewById(R.id.zoom_decrement); - - mHandler = new Handler(); - - OnTouchListener touchListener = new OnTouchListener() { - public boolean onTouch(View v, MotionEvent event) { - int action = event.getAction(); - if (action == MotionEvent.ACTION_DOWN) { - mState = (v == increment) ? ZOOM_IN : ZOOM_OUT; - if (zooming()) mHandler.postDelayed(mRunnable, 300); - } else if (action == MotionEvent.ACTION_UP - || action == MotionEvent.ACTION_CANCEL) { - int eventState = (v == increment) ? ZOOM_IN : ZOOM_OUT; - // Ignore the event if the current state does not match. - if (eventState == mState) { - stopZooming(); - mState = ZOOM_STOP; - } - } - return false; - } - }; - - mIncrementButton = increment; - mIncrementButton.setOnTouchListener(touchListener); - mIncrementButton.setVisibility(View.VISIBLE); - mDecrementButton = decrement; - mDecrementButton.setOnTouchListener(touchListener); - mDecrementButton.setVisibility(View.VISIBLE); - } - - public void setEnabled(boolean enabled) { - mIncrementButton.setEnabled(enabled); - mDecrementButton.setEnabled(enabled); - } - -} |