summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout-sw600dp/camera_control.xml10
-rw-r--r--src/com/android/camera/ui/IndicatorControlWheel.java137
-rw-r--r--src/com/android/camera/ui/IndicatorControlWheelContainer.java33
-rw-r--r--src/com/android/camera/ui/ZoomControl.java1
-rw-r--r--src/com/android/camera/ui/ZoomControlBar.java1
-rw-r--r--src/com/android/camera/ui/ZoomControlWheel.java66
6 files changed, 118 insertions, 130 deletions
diff --git a/res/layout-sw600dp/camera_control.xml b/res/layout-sw600dp/camera_control.xml
index 194547a..4637567 100644
--- a/res/layout-sw600dp/camera_control.xml
+++ b/res/layout-sw600dp/camera_control.xml
@@ -43,12 +43,12 @@
<com.android.camera.ui.IndicatorControlWheel android:id="@+id/indicator_control_wheel"
android:layout_width="match_parent"
android:layout_height="match_parent">
+ <com.android.camera.ui.ZoomControlWheel
+ android:id="@+id/zoom_control"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone" />
</com.android.camera.ui.IndicatorControlWheel>
- <com.android.camera.ui.ZoomControlWheel
- android:id="@+id/zoom_control"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone" />
</com.android.camera.ui.IndicatorControlWheelContainer>
<include layout="@layout/mode_picker" />
</com.android.camera.ui.ControlPanelLayout>
diff --git a/src/com/android/camera/ui/IndicatorControlWheel.java b/src/com/android/camera/ui/IndicatorControlWheel.java
index 92f658a..90d8ba8 100644
--- a/src/com/android/camera/ui/IndicatorControlWheel.java
+++ b/src/com/android/camera/ui/IndicatorControlWheel.java
@@ -47,17 +47,19 @@ public class IndicatorControlWheel extends IndicatorControl implements
private static final double HIGHLIGHT_RADIANS = Math.toRadians(HIGHLIGHT_DEGREES);
// The following angles are based in the zero degree on the right. Here we
- // have the fix 45 degrees for each sector in the first-level as we have to
- // align the zoom button exactly at degree 180. For second-level indicators,
- // the indicators located evenly between start and end angle. In addition,
- // these indicators for the second-level hidden in the same wheel with
- // larger angle values are visible after rotation.
- private static final int FIRST_LEVEL_END_DEGREES = 270;
+ // have the CameraPicker, ZoomControl and the Settings icons in the
+ // first-level. For consistency, we treat the zoom control as one of the
+ // indicator buttons but it needs additional efforts for rotation animation.
+ // For second-level indicators, the indicators are located evenly between start
+ // and end angle. In addition, these indicators for the second-level hidden
+ // in the same wheel with larger angle values are visible after rotation.
+ private static final int FIRST_LEVEL_START_DEGREES = 74;
+ private static final int FIRST_LEVEL_END_DEGREES = 286;
private static final int FIRST_LEVEL_SECTOR_DEGREES = 45;
private static final int SECOND_LEVEL_START_DEGREES = 60;
private static final int SECOND_LEVEL_END_DEGREES = 300;
+ private static final int MAX_ZOOM_CONTROL_DEGREES = 264;
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
@@ -111,7 +113,8 @@ public class IndicatorControlWheel extends IndicatorControl implements
private double mSectorRadians[] = new double[2];
private double mTouchSectorRadians[] = new double[2];
- private ImageView mZoomIcon;
+ private ZoomControlWheel mZoomControl;
+ private boolean mInitialized;
public IndicatorControlWheel(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -148,7 +151,6 @@ public class IndicatorControlWheel extends IndicatorControl implements
@Override
public void onClick(View view) {
- if (view == mZoomIcon) return;
changeIndicatorsLevel();
}
@@ -160,9 +162,10 @@ public class IndicatorControlWheel extends IndicatorControl implements
setPreferenceGroup(group);
- // Add Zoom Icon.
+ // Add the ZoomControl if supported.
if (isZoomSupported) {
- mZoomIcon = (ImageView) addImageButton(context, R.drawable.ic_zoom_holo_light, false);
+ mZoomControl = (ZoomControlWheel) findViewById(R.id.zoom_control);
+ mZoomControl.setVisibility(View.VISIBLE);
}
// Add CameraPicker.
@@ -180,6 +183,7 @@ public class IndicatorControlWheel extends IndicatorControl implements
mChildRadians = new double[getChildCount()];
presetFirstLevelChildRadians();
presetSecondLevelChildRadians();
+ mInitialized = true;
}
private ImageView addImageButton(Context context, int resourceId, boolean rotatable) {
@@ -200,18 +204,25 @@ public class IndicatorControlWheel extends IndicatorControl implements
if (mInAnimation) return -1;
int count = getChildCountByLevel(mCurrentLevel);
if (count == 0) return -1;
- int startIndex = (mCurrentLevel == 0) ? 0 : mSecondLevelStartIndex;
+ int startIndex = 0;
int sectors = count - 1;
// Check which indicator is touched.
if ((delta >= (mStartVisibleRadians[mCurrentLevel] - HIGHLIGHT_RADIANS / 2)) &&
(delta <= (mEndVisibleRadians[mCurrentLevel] + HIGHLIGHT_RADIANS / 2))) {
- int index = (int) ((delta - mStartVisibleRadians[mCurrentLevel])
- / mSectorRadians[mCurrentLevel]);
-
- // greater than the center of ending indicator
- if (index > sectors) return (startIndex + sectors);
- // less than the center of starting indicator
- if (index < 0) return startIndex;
+ int index = 0;
+ if (mCurrentLevel == 0) {
+ // Skip the first component if it is zoom control, as we will
+ // deal with it specifically.
+ if (mZoomControl != null) startIndex++;
+ } else {
+ startIndex = mSecondLevelStartIndex;
+ index = (int) ((delta - mStartVisibleRadians[mCurrentLevel])
+ / mSectorRadians[mCurrentLevel]);
+ // greater than the center of ending indicator
+ if (index > sectors) return (startIndex + sectors);
+ // less than the center of starting indicator
+ if (index < 0) return startIndex;
+ }
if (delta <= (mChildRadians[startIndex + index]
+ mTouchSectorRadians[mCurrentLevel] / 2)) {
@@ -221,6 +232,10 @@ public class IndicatorControlWheel extends IndicatorControl implements
- mTouchSectorRadians[mCurrentLevel] / 2)) {
return (startIndex + index + 1);
}
+
+ // It must be for zoom control if the touch event is in the visible
+ // range and not for other indicator buttons.
+ if ((mCurrentLevel == 0) && (mZoomControl != null)) return 0;
}
return -1;
}
@@ -246,6 +261,10 @@ public class IndicatorControlWheel extends IndicatorControl implements
double delta = Math.atan2(dy, dx);
if (delta < 0) delta += Math.PI * 2;
int index = getTouchIndicatorIndex(delta);
+ // Check if the touch event is for zoom control.
+ if ((mZoomControl != null) && (index == 0)) {
+ mZoomControl.dispatchTouchEvent(event);
+ }
// Move over from one indicator to another.
if ((index != mPressedIndex) || (action == MotionEvent.ACTION_DOWN)) {
if (mPressedIndex != -1) {
@@ -255,21 +274,19 @@ public class IndicatorControlWheel extends IndicatorControl implements
if (getSelectedIndicatorIndex() != index) dismissSettingPopup();
}
if ((index != -1) && (action == MotionEvent.ACTION_MOVE)) {
- injectMotionEvent(index, event, MotionEvent.ACTION_DOWN);
+ if (mCurrentLevel != 0) {
+ injectMotionEvent(index, event, MotionEvent.ACTION_DOWN);
+ }
}
}
if ((index != -1) && (action != MotionEvent.ACTION_MOVE)) {
- View view = getChildAt(index);
- // Switch to zoom control only if a touch down event is received.
- if ((view == mZoomIcon) && (action == MotionEvent.ACTION_DOWN)
- && mZoomIcon.isEnabled()) {
- mPressedIndex = -1;
- mOnIndicatorEventListener.onIndicatorEvent(
- OnIndicatorEventListener.EVENT_ENTER_ZOOM_CONTROL);
- return true;
- } else {
- getChildAt(index).dispatchTouchEvent(event);
- }
+ getChildAt(index).dispatchTouchEvent(event);
+ }
+ // Do not highlight the CameraPicker or Settings icon if we
+ // touch from the zoom control to one of them.
+ if ((mCurrentLevel == 0) && (index != 0)
+ && (action == MotionEvent.ACTION_MOVE)) {
+ return true;
}
// Once the button is up, reset the press index.
mPressedIndex = (action == MotionEvent.ACTION_UP) ? -1 : index;
@@ -298,11 +315,17 @@ public class IndicatorControlWheel extends IndicatorControl implements
double increment = Math.toRadians(expectedAngle)
- mChildRadians[mSecondLevelStartIndex];
for (int i = 0 ; i < getChildCount(); ++i) mChildRadians[i] += increment;
- }
+ // We also need to rotate the zoom control wheel as well.
+ if (mZoomControl != null) {
+ mZoomControl.rotate(mChildRadians[0]
+ - Math.toRadians(MAX_ZOOM_CONTROL_DEGREES));
+ }
+ }
@Override
protected void onLayout(
boolean changed, int left, int top, int right, int bottom) {
+ if (!mInitialized) return;
if (mInAnimation) {
rotateWheel();
mHandler.post(mRunnable);
@@ -334,39 +357,31 @@ public class IndicatorControlWheel extends IndicatorControl implements
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);
+ if (view == mZoomControl) {
+ // ZoomControlWheel matches the size of its parent view.
+ view.layout(0, 0, right - left, bottom - top);
+ } else {
+ view.layout(x - width / 2, y - height / 2, x + width / 2,
+ y + height / 2);
+ }
}
}
private void presetFirstLevelChildRadians() {
- int count = getChildCountByLevel(0);
- int sectors = (count <= 1) ? 0 : (count - 1);
- double sectorDegrees = FIRST_LEVEL_SECTOR_DEGREES;
- mSectorRadians[0] = Math.toRadians(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);
+ // Set the visible range in the first-level indicator wheel.
+ mStartVisibleRadians[0] = Math.toRadians(FIRST_LEVEL_START_DEGREES);
+ mTouchSectorRadians[0] = HIGHLIGHT_RADIANS;
+ mEndVisibleRadians[0] = Math.toRadians(FIRST_LEVEL_END_DEGREES);
+ // Set the angle of each component in the first-level indicator wheel.
int startIndex = 0;
- for (int i = 0; i < count; i++) {
- mChildRadians[startIndex + i] = Math.toRadians(degrees);
- degrees += sectorDegrees;
+ if (mZoomControl != null) {
+ mChildRadians[startIndex++] = Math.toRadians(MAX_ZOOM_CONTROL_DEGREES);
}
-
- // The radians for the touch sector of an indicator.
- mTouchSectorRadians[0] = HIGHLIGHT_RADIANS;
- mEndVisibleRadians[0] = Math.toRadians(FIRST_LEVEL_END_DEGREES);
+ if (mCameraPicker != null) {
+ mChildRadians[startIndex++] = Math.toRadians(FIRST_LEVEL_START_DEGREES);
+ }
+ mChildRadians[startIndex++] = Math.toRadians(FIRST_LEVEL_END_DEGREES);
}
private void presetSecondLevelChildRadians() {
@@ -425,7 +440,8 @@ public class IndicatorControlWheel extends IndicatorControl implements
int selectedIndex = getSelectedIndicatorIndex();
// Draw the highlight arc if an indicator is selected or being pressed.
- if (selectedIndex >= 0) {
+ // And skip the zoom control which index is zero.
+ if (selectedIndex >= 1) {
int degree = (int) Math.toDegrees(mChildRadians[selectedIndex]);
float innerR = (float) mShutterButtonRadius;
float outerR = (float) (mShutterButtonRadius + mStrokeWidth +
@@ -491,6 +507,7 @@ public class IndicatorControlWheel extends IndicatorControl implements
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
+ if (!mInitialized) return;
if (mCurrentMode == MODE_VIDEO) {
mSecondLevelIcon.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
mCloseIcon.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
@@ -504,7 +521,7 @@ public class IndicatorControlWheel extends IndicatorControl implements
}
public void enableZoom(boolean enabled) {
- if (mZoomIcon != null) mZoomIcon.setEnabled(enabled);
+ if (mZoomControl != null) mZoomControl.setEnabled(enabled);
}
public void onTouchOutBound() {
diff --git a/src/com/android/camera/ui/IndicatorControlWheelContainer.java b/src/com/android/camera/ui/IndicatorControlWheelContainer.java
index a10136b..ab52695 100644
--- a/src/com/android/camera/ui/IndicatorControlWheelContainer.java
+++ b/src/com/android/camera/ui/IndicatorControlWheelContainer.java
@@ -28,8 +28,8 @@ import android.view.View;
/**
* On the tablet UI, we have IndicatorControlWheelContainer which contains a
- * ShutterButton, a IndicatorControlWheel (which combines first-level and
- * second-level indicators) and a ZoomControlWheel.
+ * ShutterButton, an IndicatorControlWheel(which combines first-level and
+ * second-level indicators and a ZoomControlWheel).
*/
public class IndicatorControlWheelContainer extends IndicatorControlContainer {
public static final int STROKE_WIDTH = 87;
@@ -41,7 +41,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
private View mShutterButton;
private double mShutterButtonRadius;
private IndicatorControlWheel mIndicatorControlWheel;
- private ZoomControlWheel mZoomControlWheel;
private int mCenterX, mCenterY;
public IndicatorControlWheelContainer(Context context, AttributeSet attrs) {
@@ -53,9 +52,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
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);
}
@@ -64,22 +60,9 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
boolean isZoomSupported, String[] keys, String[] otherSettingKeys) {
mIndicatorControlWheel.initialize(context, group, 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
@@ -96,8 +79,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
if (radius <= mShutterButtonRadius) {
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);
@@ -112,11 +93,7 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
return true;
}
- if (mIndicatorControlWheel.getVisibility() == View.VISIBLE) {
- return mIndicatorControlWheel.dispatchTouchEvent(event);
- } else {
- return mZoomControlWheel.dispatchTouchEvent(event);
- }
+ return mIndicatorControlWheel.dispatchTouchEvent(event);
}
@Override
@@ -134,7 +111,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
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
@@ -143,7 +119,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
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()
@@ -193,7 +168,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
@Override
public void setOrientation(int orientation) {
mIndicatorControlWheel.setOrientation(orientation);
- mZoomControlWheel.setOrientation(orientation);
}
public void startTimeLapseAnimation(int timeLapseInterval, long startTime) {
@@ -208,7 +182,6 @@ public class IndicatorControlWheelContainer extends IndicatorControlContainer {
@Override
public void setEnabled(boolean enabled) {
mIndicatorControlWheel.setEnabled(enabled);
- mZoomControlWheel.setEnabled(enabled);
}
@Override
diff --git a/src/com/android/camera/ui/ZoomControl.java b/src/com/android/camera/ui/ZoomControl.java
index f2971cd..594662f 100644
--- a/src/com/android/camera/ui/ZoomControl.java
+++ b/src/com/android/camera/ui/ZoomControl.java
@@ -41,7 +41,6 @@ public abstract class ZoomControl extends RelativeLayout implements Rotatable {
protected ImageView mZoomIn;
protected ImageView mZoomOut;
protected ImageView mZoomSlider;
- protected int mSliderPosition = 0;
protected int mOrientation;
private Handler mHandler;
diff --git a/src/com/android/camera/ui/ZoomControlBar.java b/src/com/android/camera/ui/ZoomControlBar.java
index 4e572cf..3d5d2e9 100644
--- a/src/com/android/camera/ui/ZoomControlBar.java
+++ b/src/com/android/camera/ui/ZoomControlBar.java
@@ -35,6 +35,7 @@ public class ZoomControlBar extends ZoomControl {
private View mBar;
private boolean mStartChanging;
+ private int mSliderPosition = 0;
private int mSliderLength;
private int mWidth;
private int mIconWidth;
diff --git a/src/com/android/camera/ui/ZoomControlWheel.java b/src/com/android/camera/ui/ZoomControlWheel.java
index 6a75097..9114fe8 100644
--- a/src/com/android/camera/ui/ZoomControlWheel.java
+++ b/src/com/android/camera/ui/ZoomControlWheel.java
@@ -29,23 +29,27 @@ import android.view.MotionEvent;
import android.view.View;
/**
- * A view that contains camera zoom control and its layout.
+ * A view that contains camera zoom control and its layout. In addition to the
+ * zoom control, the method {@link #rotate} is added for rotation animation
+ * which is called in switching between first-level and second-level indicators.
*/
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 ZOOM_IN_ICON_DEGREES = 96;
+ private static final int ZOOM_OUT_ICON_DEGREES = 264;
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 int DEFAULT_SLIDER_POSITION = MAX_SLIDER_ANGLE;
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 static final double SLIDER_RANGE =
+ Math.toRadians(MAX_SLIDER_ANGLE - MIN_SLIDER_ANGLE);
+ private double mSliderRadians = DEFAULT_SLIDER_POSITION;
private final int HIGHLIGHT_COLOR;
private final int TRAIL_COLOR;
@@ -59,6 +63,8 @@ public class ZoomControlWheel extends ZoomControl {
private Paint mBackgroundPaint;
private RectF mBackgroundRect;
+ private double mRotateAngle;
+
public ZoomControlWheel(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
@@ -75,35 +81,21 @@ 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
public boolean dispatchTouchEvent(MotionEvent event) {
- if (!onFilterTouchEventForSecurity(event)) return false;
+ if (!onFilterTouchEventForSecurity(event) || !isEnabled()) 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;
- }
+ double angle = Math.atan2(dy, dx);
+ if (angle < 0) angle += (2 * Math.PI);
+ mSliderRadians = getSliderDrawAngle(angle);
+
// 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.
@@ -114,7 +106,8 @@ public class ZoomControlWheel extends ZoomControl {
closeZoomControl();
break;
case MotionEvent.ACTION_MOVE:
- performZoom();
+ performZoom((Math.toRadians(MAX_SLIDER_ANGLE)
+ - mSliderRadians) / SLIDER_RANGE);
requestLayout();
}
return true;
@@ -127,6 +120,9 @@ public class ZoomControlWheel extends ZoomControl {
}
private void layoutIcon(View view, double radian) {
+ // Rotate the wheel with the angle when the wheel is rotating or
+ // the indicator control is in the second-level.
+ radian += mRotateAngle;
int x = mCenterX + (int)(mWheelRadius * Math.cos(radian));
int y = mCenterY - (int)(mWheelRadius * Math.sin(radian));
int width = view.getMeasuredWidth();
@@ -135,8 +131,7 @@ public class ZoomControlWheel extends ZoomControl {
y + height / 2);
}
- private double getSliderDrawAngle() {
- double sliderAngle = mSliderRadians;
+ private double getSliderDrawAngle(double sliderAngle) {
if (sliderAngle > Math.toRadians(MAX_SLIDER_ANGLE)) {
return Math.toRadians(MAX_SLIDER_ANGLE);
} else if (sliderAngle < Math.toRadians(MIN_SLIDER_ANGLE)) {
@@ -153,7 +148,7 @@ public class ZoomControlWheel extends ZoomControl {
mCenterY = (bottom - top) / 2;
layoutIcon(mZoomIn, Math.toRadians(ZOOM_IN_ICON_DEGREES));
layoutIcon(mZoomOut, Math.toRadians(ZOOM_OUT_ICON_DEGREES));
- layoutIcon(mZoomSlider, getSliderDrawAngle());
+ layoutIcon(mZoomSlider, getSliderDrawAngle(mSliderRadians));
}
private double getZoomIndexAngle() {
@@ -174,14 +169,17 @@ public class ZoomControlWheel extends ZoomControl {
@Override
protected void onDraw(Canvas canvas) {
- // Draw zoom index highlight.
- 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),
+ int startAngle = -MAX_SLIDER_ANGLE - (int) Math.toDegrees(mRotateAngle);
+ int radians = (MAX_SLIDER_ANGLE - MIN_SLIDER_ANGLE);
+ if ((startAngle + radians) > 0) radians = -startAngle;
+ drawArc(canvas, startAngle, radians,
mWheelRadius, TRAIL_COLOR, TRAIL_WIDTH);
super.onDraw(canvas);
}
+
+ public void rotate(double angle) {
+ mRotateAngle = angle;
+ requestLayout();
+ }
}