RotarySelector widget: add callback for "grabbed" state changes.

This is the frameworks/base part of the fix for Bug 2158434: add a new
callback to the OnDialTriggerListener interface, so the RotarySelector can
tell the app about state changes between NOTHING_GRABBED and
LEFT_HANDLE_GRABBED and RIGHT_HANDLE_GRABBED.

BUG=2158434
DRNO=timsullivan

TESTED=regular incoming calls, call waiting calls, answering a call,
       rejecting a call.  Also verified I didn't affect the
       lock screen at all.
This commit is contained in:
David Brown
2009-10-01 19:25:54 -07:00
parent 3d7bb3a5e4
commit 88e037577f

View File

@ -93,9 +93,9 @@ public class RotarySelector extends View {
* If the user is currently dragging something. * If the user is currently dragging something.
*/ */
private int mGrabbedState = NOTHING_GRABBED; private int mGrabbedState = NOTHING_GRABBED;
private static final int NOTHING_GRABBED = 0; public static final int NOTHING_GRABBED = 0;
private static final int LEFT_HANDLE_GRABBED = 1; public static final int LEFT_HANDLE_GRABBED = 1;
private static final int RIGHT_HANDLE_GRABBED = 2; public static final int RIGHT_HANDLE_GRABBED = 2;
/** /**
* Whether the user has triggered something (e.g dragging the left handle all the way over to * Whether the user has triggered something (e.g dragging the left handle all the way over to
@ -522,12 +522,12 @@ public class RotarySelector extends View {
} }
if (eventX < mLeftHandleX + hitWindow) { if (eventX < mLeftHandleX + hitWindow) {
mRotaryOffsetX = eventX - mLeftHandleX; mRotaryOffsetX = eventX - mLeftHandleX;
mGrabbedState = LEFT_HANDLE_GRABBED; setGrabbedState(LEFT_HANDLE_GRABBED);
invalidate(); invalidate();
vibrate(VIBRATE_SHORT); vibrate(VIBRATE_SHORT);
} else if (eventX > mRightHandleX - hitWindow) { } else if (eventX > mRightHandleX - hitWindow) {
mRotaryOffsetX = eventX - mRightHandleX; mRotaryOffsetX = eventX - mRightHandleX;
mGrabbedState = RIGHT_HANDLE_GRABBED; setGrabbedState(RIGHT_HANDLE_GRABBED);
invalidate(); invalidate();
vibrate(VIBRATE_SHORT); vibrate(VIBRATE_SHORT);
} }
@ -591,7 +591,7 @@ public class RotarySelector extends View {
startAnimation(eventX - mRightHandleX, 0, SNAP_BACK_ANIMATION_DURATION_MILLIS); startAnimation(eventX - mRightHandleX, 0, SNAP_BACK_ANIMATION_DURATION_MILLIS);
} }
mRotaryOffsetX = 0; mRotaryOffsetX = 0;
mGrabbedState = NOTHING_GRABBED; setGrabbedState(NOTHING_GRABBED);
invalidate(); invalidate();
if (mVelocityTracker != null) { if (mVelocityTracker != null) {
mVelocityTracker.recycle(); // wishin' we had generational GC mVelocityTracker.recycle(); // wishin' we had generational GC
@ -617,7 +617,7 @@ public class RotarySelector extends View {
mAnimationDuration = duration; mAnimationDuration = duration;
mAnimatingDeltaXStart = startX; mAnimatingDeltaXStart = startX;
mAnimatingDeltaXEnd = endX; mAnimatingDeltaXEnd = endX;
mGrabbedState = NOTHING_GRABBED; setGrabbedState(NOTHING_GRABBED);
mDimplesOfFling = 0; mDimplesOfFling = 0;
invalidate(); invalidate();
} }
@ -628,7 +628,7 @@ public class RotarySelector extends View {
mAnimationDuration = 1000 * (endX - startX) / pixelsPerSecond; mAnimationDuration = 1000 * (endX - startX) / pixelsPerSecond;
mAnimatingDeltaXStart = startX; mAnimatingDeltaXStart = startX;
mAnimatingDeltaXEnd = endX; mAnimatingDeltaXEnd = endX;
mGrabbedState = NOTHING_GRABBED; setGrabbedState(NOTHING_GRABBED);
invalidate(); invalidate();
} }
@ -667,7 +667,7 @@ public class RotarySelector extends View {
mAnimating = false; mAnimating = false;
mRotaryOffsetX = 0; mRotaryOffsetX = 0;
mDimplesOfFling = 0; mDimplesOfFling = 0;
mGrabbedState = NOTHING_GRABBED; setGrabbedState(NOTHING_GRABBED);
mTriggered = false; mTriggered = false;
} }
@ -715,6 +715,19 @@ public class RotarySelector extends View {
} }
} }
/**
* Sets the current grabbed state, and dispatches a grabbed state change
* event to our listener.
*/
private void setGrabbedState(int newState) {
if (newState != mGrabbedState) {
mGrabbedState = newState;
if (mOnDialTriggerListener != null) {
mOnDialTriggerListener.onGrabbedStateChange(this, mGrabbedState);
}
}
}
/** /**
* Interface definition for a callback to be invoked when the dial * Interface definition for a callback to be invoked when the dial
* is "triggered" by rotating it one way or the other. * is "triggered" by rotating it one way or the other.
@ -740,6 +753,16 @@ public class RotarySelector extends View {
* either {@link #LEFT_HANDLE}, {@link #RIGHT_HANDLE}. * either {@link #LEFT_HANDLE}, {@link #RIGHT_HANDLE}.
*/ */
void onDialTrigger(View v, int whichHandle); void onDialTrigger(View v, int whichHandle);
/**
* Called when the "grabbed state" changes (i.e. when
* the user either grabs or releases one of the handles.)
*
* @param v the view that was triggered
* @param grabbedState the new state: either {@link #NOTHING_GRABBED},
* {@link #LEFT_HANDLE_GRABBED}, or {@link #RIGHT_HANDLE_GRABBED}.
*/
void onGrabbedStateChange(View v, int grabbedState);
} }