From e8118e17b2f088f2ebecfbe050c4ffa80f686abf Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Wed, 30 May 2012 14:19:02 -0700 Subject: [PATCH] Sped up ActionBar and StatusBar animations Animations to show/hide the ActionBar and StatusBar were very slow, given the size of the objects and the distances covered by the sliding animations. Also, the ActionBar animation was sometimes hiccuppy as it faded in/out. This change eliminates the ActionBar fade (which is unnecessary) and speeds up the animations (smaller durations and steeper interpolation curves). Also, it eliminates the startDelay on the ActionBar show animation. Issue #6564089 Options menu should slide in much quicker (nakasi/JB) Change-Id: I2c8298301f7bf26bbbc94444e715420a2c029ba0 --- .../android/internal/app/ActionBarImpl.java | 45 ++++++++++--------- core/res/res/anim/dock_bottom_enter.xml | 4 +- core/res/res/anim/dock_bottom_exit.xml | 4 +- core/res/res/anim/dock_left_enter.xml | 4 +- core/res/res/anim/dock_left_exit.xml | 4 +- core/res/res/anim/dock_right_enter.xml | 4 +- core/res/res/anim/dock_right_exit.xml | 4 +- core/res/res/anim/dock_top_enter.xml | 4 +- core/res/res/anim/dock_top_exit.xml | 4 +- 9 files changed, 40 insertions(+), 37 deletions(-) diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java index 234cb71cedbb9..46478ca707d34 100644 --- a/core/java/com/android/internal/app/ActionBarImpl.java +++ b/core/java/com/android/internal/app/ActionBarImpl.java @@ -673,26 +673,29 @@ public class ActionBarImpl extends ActionBar { if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled || fromSystem)) { - mTopVisibilityView.setAlpha(0); - mTopVisibilityView.setTranslationY(-mTopVisibilityView.getHeight()); + mTopVisibilityView.setTranslationY(0); // because we're about to ask its window loc + float startingY = -mTopVisibilityView.getHeight(); + if (fromSystem) { + int topLeft[] = {0, 0}; + mTopVisibilityView.getLocationInWindow(topLeft); + startingY -= topLeft[1]; + } + mTopVisibilityView.setTranslationY(startingY); AnimatorSet anim = new AnimatorSet(); - AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mTopVisibilityView, "alpha", 1)); - b.with(ObjectAnimator.ofFloat(mTopVisibilityView, "translationY", 0)); + AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mTopVisibilityView, + "translationY", 0)); if (mContentView != null) { b.with(ObjectAnimator.ofFloat(mContentView, "translationY", - -mTopVisibilityView.getHeight(), 0)); + startingY, 0)); } if (mSplitView != null && mContextDisplayMode == CONTEXT_DISPLAY_SPLIT) { - mSplitView.setAlpha(0); mSplitView.setTranslationY(mSplitView.getHeight()); mSplitView.setVisibility(View.VISIBLE); - b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 1)); b.with(ObjectAnimator.ofFloat(mSplitView, "translationY", 0)); } anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, - com.android.internal.R.interpolator.decelerate_quad)); - anim.setDuration(mContext.getResources().getInteger( - com.android.internal.R.integer.config_mediumAnimTime)); + com.android.internal.R.interpolator.decelerate_cubic)); + anim.setDuration(250); // If this is being shown from the system, add a small delay. // This is because we will also be animating in the status bar, // and these two elements can't be done in lock-step. So we give @@ -700,9 +703,6 @@ public class ActionBarImpl extends ActionBar { // the action bar animates. (This corresponds to the corresponding // case when hiding, where the status bar has a small delay before // starting.) - if (fromSystem) { - anim.setStartDelay(100); - } anim.addListener(mShowListener); mCurrentShowAnim = anim; anim.start(); @@ -734,23 +734,26 @@ public class ActionBarImpl extends ActionBar { mTopVisibilityView.setAlpha(1); mContainerView.setTransitioning(true); AnimatorSet anim = new AnimatorSet(); - AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mTopVisibilityView, "alpha", 0)); - b.with(ObjectAnimator.ofFloat(mTopVisibilityView, "translationY", - -mTopVisibilityView.getHeight())); + float endingY = -mTopVisibilityView.getHeight(); + if (fromSystem) { + int topLeft[] = {0, 0}; + mTopVisibilityView.getLocationInWindow(topLeft); + endingY -= topLeft[1]; + } + AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mTopVisibilityView, + "translationY", endingY)); if (mContentView != null) { b.with(ObjectAnimator.ofFloat(mContentView, "translationY", - 0, -mTopVisibilityView.getHeight())); + 0, endingY)); } if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) { mSplitView.setAlpha(1); - b.with(ObjectAnimator.ofFloat(mSplitView, "alpha", 0)); b.with(ObjectAnimator.ofFloat(mSplitView, "translationY", mSplitView.getHeight())); } anim.setInterpolator(AnimationUtils.loadInterpolator(mContext, - com.android.internal.R.interpolator.accelerate_quad)); - anim.setDuration(mContext.getResources().getInteger( - com.android.internal.R.integer.config_mediumAnimTime)); + com.android.internal.R.interpolator.accelerate_cubic)); + anim.setDuration(250); anim.addListener(mHideListener); mCurrentShowAnim = anim; anim.start(); diff --git a/core/res/res/anim/dock_bottom_enter.xml b/core/res/res/anim/dock_bottom_enter.xml index 74a021b90f24f..4f2f753169d0c 100644 --- a/core/res/res/anim/dock_bottom_enter.xml +++ b/core/res/res/anim/dock_bottom_enter.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/decelerate_cubic"> + android:duration="250"/> diff --git a/core/res/res/anim/dock_bottom_exit.xml b/core/res/res/anim/dock_bottom_exit.xml index 213b3d91a5f95..afbe24b82aa06 100644 --- a/core/res/res/anim/dock_bottom_exit.xml +++ b/core/res/res/anim/dock_bottom_exit.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/accelerate_cubic"> + android:startOffset="100" android:duration="250"/> diff --git a/core/res/res/anim/dock_left_enter.xml b/core/res/res/anim/dock_left_enter.xml index 4fce35ab3678a..7f5dfd50afc75 100644 --- a/core/res/res/anim/dock_left_enter.xml +++ b/core/res/res/anim/dock_left_enter.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/decelerate_cubic"> + android:duration="250"/> diff --git a/core/res/res/anim/dock_left_exit.xml b/core/res/res/anim/dock_left_exit.xml index bce203dc3c452..11cbc0b364058 100644 --- a/core/res/res/anim/dock_left_exit.xml +++ b/core/res/res/anim/dock_left_exit.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/accelerate_cubic"> + android:startOffset="100" android:duration="250"/> diff --git a/core/res/res/anim/dock_right_enter.xml b/core/res/res/anim/dock_right_enter.xml index 26b8ad6ee6b02..a92c7d234e58e 100644 --- a/core/res/res/anim/dock_right_enter.xml +++ b/core/res/res/anim/dock_right_enter.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/decelerate_cubic"> + android:duration="250"/> diff --git a/core/res/res/anim/dock_right_exit.xml b/core/res/res/anim/dock_right_exit.xml index 6beda5927b3f0..80e4dc3181920 100644 --- a/core/res/res/anim/dock_right_exit.xml +++ b/core/res/res/anim/dock_right_exit.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/accelerate_cubic"> + android:startOffset="100" android:duration="250"/> diff --git a/core/res/res/anim/dock_top_enter.xml b/core/res/res/anim/dock_top_enter.xml index 594b47950f078..1f74e4827aaa3 100644 --- a/core/res/res/anim/dock_top_enter.xml +++ b/core/res/res/anim/dock_top_enter.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/decelerate_cubic"> + android:duration="250"/> diff --git a/core/res/res/anim/dock_top_exit.xml b/core/res/res/anim/dock_top_exit.xml index b9691f6446a7d..4d2fea94f3226 100644 --- a/core/res/res/anim/dock_top_exit.xml +++ b/core/res/res/anim/dock_top_exit.xml @@ -18,7 +18,7 @@ + android:interpolator="@android:interpolator/accelerate_cubic"> + android:startOffset="100" android:duration="250"/>