am 05da3280: Merge "Fix warp animation in keyguard" into klp-dev

* commit '05da328078b71f4aa9a42552f9c2b6713010686e':
  Fix warp animation in keyguard
This commit is contained in:
Jim Miller
2013-10-13 17:09:23 -07:00
committed by Android Git Automerger

View File

@ -44,6 +44,7 @@ import android.view.View;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
import android.view.ViewPropertyAnimator;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo;
@ -134,6 +135,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
protected final static int TOUCH_STATE_PREV_PAGE = 2; protected final static int TOUCH_STATE_PREV_PAGE = 2;
protected final static int TOUCH_STATE_NEXT_PAGE = 3; protected final static int TOUCH_STATE_NEXT_PAGE = 3;
protected final static int TOUCH_STATE_REORDERING = 4; protected final static int TOUCH_STATE_REORDERING = 4;
protected final static int TOUCH_STATE_READY = 5; // when finger is down
protected final static float ALPHA_QUANTIZE_LEVEL = 0.0001f; protected final static float ALPHA_QUANTIZE_LEVEL = 0.0001f;
protected final static float TOUCH_SLOP_SCALE = 1.0f; protected final static float TOUCH_SLOP_SCALE = 1.0f;
@ -260,11 +262,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
// Page warping // Page warping
private int mPageSwapIndex = -1; // the page we swapped out if needed private int mPageSwapIndex = -1; // the page we swapped out if needed
private int mPageWarpIndex = -1; // the page we intend to warp private int mPageWarpIndex = -1; // the page we intend to warp
private boolean mWarpPageExposed;
private ViewPropertyAnimator mWarpAnimation;
private boolean mIsCameraEvent; private boolean mIsCameraEvent;
private float mWarpPeekAmount; private float mWarpPeekAmount;
private boolean mAnimatingWarp; // true while warped page is being animated
private boolean mFingerDown;
public interface PageSwitchListener { public interface PageSwitchListener {
void onPageSwitching(View newPage, int newPageIndex); void onPageSwitching(View newPage, int newPageIndex);
@ -1128,7 +1130,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
} }
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
if (mIsCameraEvent && !mAnimatingWarp) { if (mIsCameraEvent) {
animateWarpPageOnScreen("interceptTouch(): DOWN"); animateWarpPageOnScreen("interceptTouch(): DOWN");
} }
// Remember where the motion event started // Remember where the motion event started
@ -1196,6 +1198,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
private void setTouchState(int touchState) { private void setTouchState(int touchState) {
if (mTouchState != touchState) { if (mTouchState != touchState) {
if (DEBUG_WARP) Log.v(TAG, "mTouchState changing to " + touchState);
onTouchStateChanged(touchState); onTouchStateChanged(touchState);
mTouchState = touchState; mTouchState = touchState;
} }
@ -1223,8 +1226,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
mTotalMotionX = 0; mTotalMotionX = 0;
mActivePointerId = ev.getPointerId(0); mActivePointerId = ev.getPointerId(0);
mFingerDown = true;
// Determine if the down event is within the threshold to be an edge swipe // Determine if the down event is within the threshold to be an edge swipe
int leftEdgeBoundary = getViewportOffsetX() + mEdgeSwipeRegionSize; int leftEdgeBoundary = getViewportOffsetX() + mEdgeSwipeRegionSize;
int rightEdgeBoundary = getMeasuredWidth() - getViewportOffsetX() - mEdgeSwipeRegionSize; int rightEdgeBoundary = getMeasuredWidth() - getViewportOffsetX() - mEdgeSwipeRegionSize;
@ -1399,9 +1400,11 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
if (mTouchState == TOUCH_STATE_SCROLLING) { if (mTouchState == TOUCH_STATE_SCROLLING) {
pageBeginMoving(); pageBeginMoving();
} else {
setTouchState(TOUCH_STATE_READY);
} }
if (mIsCameraEvent && !mAnimatingWarp) { if (mIsCameraEvent) {
animateWarpPageOnScreen("onTouch(): DOWN"); animateWarpPageOnScreen("onTouch(): DOWN");
} }
break; break;
@ -1635,6 +1638,10 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
onDropToDelete(); onDropToDelete();
} }
} else { } else {
if (DEBUG_WARP) Log.v(TAG, "calling onUnhandledTap()");
if (mWarpPageExposed && !isAnimatingWarpPage()) {
animateWarpPageOffScreen("unhandled tap", true);
}
onUnhandledTap(ev); onUnhandledTap(ev);
} }
@ -1670,7 +1677,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
setTouchState(TOUCH_STATE_REST); setTouchState(TOUCH_STATE_REST);
mActivePointerId = INVALID_POINTER; mActivePointerId = INVALID_POINTER;
mDownEventOnEdge = false; mDownEventOnEdge = false;
mFingerDown = false;
} }
protected void onUnhandledTap(MotionEvent ev) {} protected void onUnhandledTap(MotionEvent ev) {}
@ -2675,16 +2681,24 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
mIsCameraEvent = false; mIsCameraEvent = false;
} }
AnimatorListenerAdapter mFinishWarpAnimationListener = new AnimatorListenerAdapter() { AnimatorListenerAdapter mOnScreenAnimationListener = new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
mAnimatingWarp = false; mWarpAnimation = null;
if (!mFingerDown) { if (mTouchState != TOUCH_STATE_SCROLLING && mTouchState != TOUCH_STATE_READY) {
animateWarpPageOffScreen("animation end", true); animateWarpPageOffScreen("onScreen end", true);
} }
} }
}; };
AnimatorListenerAdapter mOffScreenAnimationListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mWarpAnimation = null;
mWarpPageExposed = true;
}
};
private void cancelWarpAnimation(String msg) { private void cancelWarpAnimation(String msg) {
if (DEBUG_WARP) Log.v(TAG, "cancelWarpAnimation(" + msg + ")"); if (DEBUG_WARP) Log.v(TAG, "cancelWarpAnimation(" + msg + ")");
// We're done with the animation, let the scroller take over the positioning // We're done with the animation, let the scroller take over the positioning
@ -2694,18 +2708,23 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
scrollBy((int) Math.round(v.getTranslationX() - mWarpPeekAmount), 0); scrollBy((int) Math.round(v.getTranslationX() - mWarpPeekAmount), 0);
} }
private boolean isAnimatingWarpPage() {
return mWarpAnimation != null;
}
private void animateWarpPageOnScreen(String reason) { private void animateWarpPageOnScreen(String reason) {
if (DEBUG_WARP) Log.v(TAG, "animateWarpPageOnScreen(" + reason + ")"); if (DEBUG_WARP) Log.v(TAG, "animateWarpPageOnScreen(" + reason + ")");
if (isWarping()) { if (isWarping()) {
mWarpPageExposed = true;
onPageBeginWarp(); onPageBeginWarp();
KeyguardWidgetFrame v = (KeyguardWidgetFrame) getPageAt(mPageWarpIndex); KeyguardWidgetFrame v = (KeyguardWidgetFrame) getPageAt(mPageWarpIndex);
if (DEBUG_WARP) Log.v(TAG, "moving page on screen: Tx=" + v.getTranslationX()); if (DEBUG_WARP) Log.v(TAG, "moving page on screen: Tx=" + v.getTranslationX());
DecelerateInterpolator interp = new DecelerateInterpolator(1.5f); DecelerateInterpolator interp = new DecelerateInterpolator(1.5f);
v.animate().translationX(mWarpPeekAmount) mWarpAnimation = v.animate();
mWarpAnimation.translationX(mWarpPeekAmount)
.setInterpolator(interp) .setInterpolator(interp)
.setDuration(WARP_PEEK_ANIMATION_DURATION) .setDuration(WARP_PEEK_ANIMATION_DURATION)
.setListener(mFinishWarpAnimationListener); .setListener(mOnScreenAnimationListener);
mAnimatingWarp = true;
} }
} }
@ -2719,7 +2738,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
v.animate().translationX(0.0f) v.animate().translationX(0.0f)
.setInterpolator(interp) .setInterpolator(interp)
.setDuration(animate ? WARP_PEEK_ANIMATION_DURATION : 0) .setDuration(animate ? WARP_PEEK_ANIMATION_DURATION : 0)
.setListener(null); .setListener(mOffScreenAnimationListener);
} else { } else {
if (DEBUG_WARP) Log.e(TAG, "animateWarpPageOffScreen(): not warping", new Exception()); if (DEBUG_WARP) Log.e(TAG, "animateWarpPageOffScreen(): not warping", new Exception());
} }