From fbab8ae9d562ee7ebe22ec6bcf3aa03d4db106fb Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Wed, 9 May 2012 02:06:29 -0400 Subject: [PATCH] Fix situations where the shade wouldn't close. It appears sometimes the Choreographer will call you with an old frame (i.e. an animation time in the past). Bug: 6457615 Change-Id: I7135e2f4f524c14fe4f58f9a367f764b66d68edc --- .../statusbar/phone/PhoneStatusBar.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 96f08b11ac383..1d281c50311a6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -212,6 +212,7 @@ public class PhoneStatusBar extends BaseStatusBar { Choreographer mChoreographer; boolean mAnimating; + boolean mClosing; // only valid when mAnimating; indicates the initial acceleration float mAnimY; float mAnimVel; float mAnimAccel; @@ -1276,14 +1277,26 @@ public class PhoneStatusBar extends BaseStatusBar { } } + void resetLastAnimTime() { + mAnimLastTimeNanos = System.nanoTime(); + if (SPEW) { + Throwable t = new Throwable(); + t.fillInStackTrace(); + Slog.d(TAG, "resetting last anim time=" + mAnimLastTimeNanos, t); + } + } + void doAnimation(long frameTimeNanos) { if (mAnimating) { - if (SPEW) Slog.d(TAG, "doAnimation"); + if (SPEW) Slog.d(TAG, "doAnimation dt=" + (frameTimeNanos - mAnimLastTimeNanos)); if (SPEW) Slog.d(TAG, "doAnimation before mAnimY=" + mAnimY); incrementAnim(frameTimeNanos); - if (SPEW) Slog.d(TAG, "doAnimation after mAnimY=" + mAnimY); + if (SPEW) { + Slog.d(TAG, "doAnimation after mAnimY=" + mAnimY); + Slog.d(TAG, "doAnimation expandedViewMax=" + getExpandedViewMaxHeight()); + } - if (mAnimY >= getExpandedViewMaxHeight()-1) { + if (mAnimY >= getExpandedViewMaxHeight()-1 && !mClosing) { if (SPEW) Slog.d(TAG, "Animation completed to expanded state."); mAnimating = false; updateExpandedViewPos(EXPANDED_FULL_OPEN); @@ -1291,14 +1304,14 @@ public class PhoneStatusBar extends BaseStatusBar { return; } - if (mAnimY == 0 && mAnimAccel == 0 && mAnimVel == 0) { + if (mAnimY == 0 && mAnimAccel == 0 && mClosing) { if (SPEW) Slog.d(TAG, "Animation completed to collapsed state."); mAnimating = false; performCollapse(); return; } - if (mAnimY < getStatusBarHeight()) { + if (mAnimY < getStatusBarHeight() && mClosing) { // Draw one more frame with the bar positioned at the top of the screen // before ending the animation so that the user sees the bar in // its final position. The call to performCollapse() causes a window @@ -1336,6 +1349,9 @@ public class PhoneStatusBar extends BaseStatusBar { } void doRevealAnimation(long frameTimeNanos) { + if (SPEW) { + Slog.d(TAG, "doRevealAnimation: dt=" + (frameTimeNanos - mAnimLastTimeNanos)); + } final int h = getCloseViewHeight() + getStatusBarHeight(); if (mAnimatingReveal && mAnimating && mAnimY < h) { incrementAnim(frameTimeNanos); @@ -1365,7 +1381,7 @@ public class PhoneStatusBar extends BaseStatusBar { updateExpandedViewPos((int)mAnimY); mAnimating = true; mAnimatingReveal = true; - mAnimLastTimeNanos = System.nanoTime(); + resetLastAnimTime(); mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null); mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, @@ -1439,8 +1455,9 @@ public class PhoneStatusBar extends BaseStatusBar { //Slog.d(TAG, "mAnimY=" + mAnimY + " mAnimVel=" + mAnimVel // + " mAnimAccel=" + mAnimAccel); - mAnimLastTimeNanos = System.nanoTime(); + resetLastAnimTime(); mAnimating = true; + mClosing = mAnimAccel < 0; mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null);