am 6b965126: Merge change 26034 into eclair
Merge commit '6b96512601bf37d840a99c8d82dcfbcc0427b33c' into eclair-plus-aosp * commit '6b96512601bf37d840a99c8d82dcfbcc0427b33c': Clean up spin animation in rotary selector, and be even more generous for triggering.
This commit is contained in:
@@ -25,6 +25,7 @@ import android.util.AttributeSet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.SoundEffectConstants;
|
||||||
import android.view.animation.AccelerateInterpolator;
|
import android.view.animation.AccelerateInterpolator;
|
||||||
import static android.view.animation.AnimationUtils.currentAnimationTimeMillis;
|
import static android.view.animation.AnimationUtils.currentAnimationTimeMillis;
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -65,8 +66,9 @@ public class RotarySelector extends View {
|
|||||||
// state of the animation used to bring the handle back to its start position when
|
// state of the animation used to bring the handle back to its start position when
|
||||||
// the user lets go before triggering an action
|
// the user lets go before triggering an action
|
||||||
private boolean mAnimating = false;
|
private boolean mAnimating = false;
|
||||||
private long mAnimationEndTime;
|
private long mAnimationStartTime; // set to the end point of the animatino
|
||||||
private int mAnimatingDelta;
|
private long mAnimationDuration;
|
||||||
|
private int mAnimatingDeltaXStart; // the animation will interpolate from this delta down to zero
|
||||||
private AccelerateInterpolator mInterpolator;
|
private AccelerateInterpolator mInterpolator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,14 +104,15 @@ public class RotarySelector extends View {
|
|||||||
/**
|
/**
|
||||||
* How far from the edge of the screen the user must drag to trigger the event.
|
* How far from the edge of the screen the user must drag to trigger the event.
|
||||||
*/
|
*/
|
||||||
private static final int EDGE_TRIGGER_DIP = 65;
|
private static final int EDGE_TRIGGER_DIP = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dimensions of arc in background drawable.
|
* Dimensions of arc in background drawable.
|
||||||
*/
|
*/
|
||||||
static final int OUTER_ROTARY_RADIUS_DIP = 390;
|
static final int OUTER_ROTARY_RADIUS_DIP = 390;
|
||||||
static final int ROTARY_STROKE_WIDTH_DIP = 83;
|
static final int ROTARY_STROKE_WIDTH_DIP = 83;
|
||||||
private static final int ANIMATION_DURATION_MILLIS = 300;
|
static final int SNAP_BACK_ANIMATION_DURATION_MILLIS = 300;
|
||||||
|
static final int SPIN_ANIMATION_DURATION_MILLIS = 800;
|
||||||
|
|
||||||
private static final boolean DRAW_CENTER_DIMPLE = false;
|
private static final boolean DRAW_CENTER_DIMPLE = false;
|
||||||
private int mEdgeTriggerThresh;
|
private int mEdgeTriggerThresh;
|
||||||
@@ -249,14 +252,19 @@ public class RotarySelector extends View {
|
|||||||
|
|
||||||
// update animating state before we draw anything
|
// update animating state before we draw anything
|
||||||
if (mAnimating) {
|
if (mAnimating) {
|
||||||
long millisLeft = mAnimationEndTime - currentAnimationTimeMillis();
|
final long millisSoFar = currentAnimationTimeMillis() - mAnimationStartTime;
|
||||||
|
final long millisLeft = mAnimationDuration - millisSoFar;
|
||||||
if (DBG) log("millisleft for animating: " + millisLeft);
|
if (DBG) log("millisleft for animating: " + millisLeft);
|
||||||
if (millisLeft <= 0) {
|
if (millisLeft <= 0) {
|
||||||
reset();
|
reset();
|
||||||
} else {
|
} else {
|
||||||
|
// we always use the snap back duration as the denominator for interpolation
|
||||||
|
// to get a consistent velocity (bascially this makes us happy for the snap back
|
||||||
|
// and the spin around one).
|
||||||
|
final long denom = SNAP_BACK_ANIMATION_DURATION_MILLIS; // mAnimationDuration
|
||||||
float interpolation = mInterpolator.getInterpolation(
|
float interpolation = mInterpolator.getInterpolation(
|
||||||
(float) millisLeft / ANIMATION_DURATION_MILLIS);
|
(float) millisLeft / denom);
|
||||||
mTouchDragOffset = (int) (mAnimatingDelta * interpolation);
|
mTouchDragOffset = (int) (mAnimatingDeltaXStart * interpolation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,8 +431,9 @@ public class RotarySelector extends View {
|
|||||||
dispatchTriggerEvent(OnDialTriggerListener.LEFT_HANDLE);
|
dispatchTriggerEvent(OnDialTriggerListener.LEFT_HANDLE);
|
||||||
// set up "spin around animation"
|
// set up "spin around animation"
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
mAnimationEndTime = currentAnimationTimeMillis() + ANIMATION_DURATION_MILLIS;
|
mAnimationStartTime = currentAnimationTimeMillis();
|
||||||
mAnimatingDelta = -mBackgroundWidth;
|
mAnimationDuration = SPIN_ANIMATION_DURATION_MILLIS;
|
||||||
|
mAnimatingDeltaXStart = -mBackgroundWidth*3;
|
||||||
mTouchDragOffset = 0;
|
mTouchDragOffset = 0;
|
||||||
mGrabbedState = NOTHING_GRABBED;
|
mGrabbedState = NOTHING_GRABBED;
|
||||||
invalidate();
|
invalidate();
|
||||||
@@ -438,8 +447,9 @@ public class RotarySelector extends View {
|
|||||||
dispatchTriggerEvent(OnDialTriggerListener.RIGHT_HANDLE);
|
dispatchTriggerEvent(OnDialTriggerListener.RIGHT_HANDLE);
|
||||||
// set up "spin around animation"
|
// set up "spin around animation"
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
mAnimationEndTime = currentAnimationTimeMillis() + ANIMATION_DURATION_MILLIS;
|
mAnimationStartTime = currentAnimationTimeMillis();
|
||||||
mAnimatingDelta = mBackgroundWidth;
|
mAnimationDuration = SPIN_ANIMATION_DURATION_MILLIS;
|
||||||
|
mAnimatingDeltaXStart = mBackgroundWidth*3;
|
||||||
mTouchDragOffset = 0;
|
mTouchDragOffset = 0;
|
||||||
mGrabbedState = NOTHING_GRABBED;
|
mGrabbedState = NOTHING_GRABBED;
|
||||||
invalidate();
|
invalidate();
|
||||||
@@ -453,14 +463,16 @@ public class RotarySelector extends View {
|
|||||||
&& Math.abs(eventX - mLeftHandleX) > 5) {
|
&& Math.abs(eventX - mLeftHandleX) > 5) {
|
||||||
// set up "snap back" animation
|
// set up "snap back" animation
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
mAnimationEndTime = currentAnimationTimeMillis() + ANIMATION_DURATION_MILLIS;
|
mAnimationStartTime = currentAnimationTimeMillis();
|
||||||
mAnimatingDelta = eventX - mLeftHandleX;
|
mAnimationDuration = SNAP_BACK_ANIMATION_DURATION_MILLIS;
|
||||||
|
mAnimatingDeltaXStart = eventX - mLeftHandleX;
|
||||||
} else if (mGrabbedState == RIGHT_HANDLE_GRABBED
|
} else if (mGrabbedState == RIGHT_HANDLE_GRABBED
|
||||||
&& Math.abs(eventX - mRightHandleX) > 5) {
|
&& Math.abs(eventX - mRightHandleX) > 5) {
|
||||||
// set up "snap back" animation
|
// set up "snap back" animation
|
||||||
mAnimating = true;
|
mAnimating = true;
|
||||||
mAnimationEndTime = currentAnimationTimeMillis() + ANIMATION_DURATION_MILLIS;
|
mAnimationStartTime = currentAnimationTimeMillis();
|
||||||
mAnimatingDelta = eventX - mRightHandleX;
|
mAnimationDuration = SNAP_BACK_ANIMATION_DURATION_MILLIS;
|
||||||
|
mAnimatingDeltaXStart = eventX - mRightHandleX;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTouchDragOffset = 0;
|
mTouchDragOffset = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user