diff options
author | Jorim Jaggi <jjaggi@google.com> | 2015-07-16 15:30:10 -0700 |
---|---|---|
committer | Jorim Jaggi <jjaggi@google.com> | 2015-07-22 15:23:52 -0700 |
commit | 613f55fbbb23249d7c65e3f1fe8c943c4459b41a (patch) | |
tree | 8de9921b69de0255ef57d5ee323c1decf9a54d65 /packages | |
parent | db71828cb7bff983bd758e986b65731cb0a5b2f6 (diff) | |
download | frameworks_base-613f55fbbb23249d7c65e3f1fe8c943c4459b41a.zip frameworks_base-613f55fbbb23249d7c65e3f1fe8c943c4459b41a.tar.gz frameworks_base-613f55fbbb23249d7c65e3f1fe8c943c4459b41a.tar.bz2 |
Move PIN/Pattern appear animation to RenderThread (1/2)
Bug: 22205322
Change-Id: I253f20a397ab89cb78254338a0254619232d7300
Diffstat (limited to 'packages')
4 files changed, 97 insertions, 59 deletions
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java index d265e0d..4abb795 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java @@ -16,8 +16,12 @@ package com.android.keyguard; +import android.animation.Animator; +import android.animation.ObjectAnimator; import android.content.Context; import android.util.AttributeSet; +import android.view.RenderNode; +import android.view.RenderNodeAnimator; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; @@ -114,10 +118,8 @@ public class KeyguardPINView extends KeyguardPinBasedInputView { enableClipping(false); setAlpha(1f); setTranslationY(mAppearAnimationUtils.getStartTranslation()); - animate() - .setDuration(500) - .setInterpolator(mAppearAnimationUtils.getInterpolator()) - .translationY(0); + AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */, + 0, mAppearAnimationUtils.getInterpolator()); mAppearAnimationUtils.startAnimation2d(mViews, new Runnable() { @Override @@ -131,10 +133,8 @@ public class KeyguardPINView extends KeyguardPinBasedInputView { public boolean startDisappearAnimation(final Runnable finishRunnable) { enableClipping(false); setTranslationY(0); - animate() - .setDuration(280) - .setInterpolator(mDisappearAnimationUtils.getInterpolator()) - .translationY(mDisappearYTranslation); + AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */, + mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator()); mDisappearAnimationUtils.startAnimation2d(mViews, new Runnable() { @Override diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java index 3568429..b000e26 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java @@ -17,6 +17,7 @@ package com.android.keyguard; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Rect; @@ -27,6 +28,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; +import android.view.RenderNodeAnimator; import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; @@ -334,10 +336,8 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit enableClipping(false); setAlpha(1f); setTranslationY(mAppearAnimationUtils.getStartTranslation()); - animate() - .setDuration(500) - .setInterpolator(mAppearAnimationUtils.getInterpolator()) - .translationY(0); + AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */, + 0, mAppearAnimationUtils.getInterpolator()); mAppearAnimationUtils.startAnimation2d( mLockPatternView.getCellStates(), new Runnable() { @@ -362,10 +362,9 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit mLockPatternView.clearPattern(); enableClipping(false); setTranslationY(0); - animate() - .setDuration(300) - .setInterpolator(mDisappearAnimationUtils.getInterpolator()) - .translationY(-mDisappearAnimationUtils.getStartTranslation()); + AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 300 /* duration */, + -mDisappearAnimationUtils.getStartTranslation(), + mDisappearAnimationUtils.getInterpolator()); mDisappearAnimationUtils.startAnimation2d(mLockPatternView.getCellStates(), new Runnable() { @Override @@ -398,43 +397,16 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit long duration, float translationY, final boolean appearing, Interpolator interpolator, final Runnable finishListener) { - if (appearing) { - animatedCell.scale = 0.0f; - animatedCell.alpha = 1.0f; - } - animatedCell.translateY = appearing ? translationY : 0; - ValueAnimator animator = ValueAnimator.ofFloat(animatedCell.translateY, - appearing ? 0 : translationY); - animator.setInterpolator(interpolator); - animator.setDuration(duration); - animator.setStartDelay(delay); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - float animatedFraction = animation.getAnimatedFraction(); - if (appearing) { - animatedCell.scale = animatedFraction; - } else { - animatedCell.alpha = 1 - animatedFraction; - } - animatedCell.translateY = (float) animation.getAnimatedValue(); - mLockPatternView.invalidate(); - } - }); + mLockPatternView.startCellStateAnimation(animatedCell, + 1f, appearing ? 1f : 0f, /* alpha */ + appearing ? translationY : 0f, appearing ? 0f : translationY, /* translation */ + appearing ? 0f : 1f, 1f /* scale */, + delay, duration, interpolator, finishListener); if (finishListener != null) { - animator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - finishListener.run(); - } - }); - // Also animate the Emergency call mAppearAnimationUtils.createAnimation(mEcaView, delay, duration, translationY, appearing, interpolator, null); } - animator.start(); - mLockPatternView.invalidate(); } @Override diff --git a/packages/SettingsLib/src/com/android/settingslib/animation/AppearAnimationUtils.java b/packages/SettingsLib/src/com/android/settingslib/animation/AppearAnimationUtils.java index 441474d..df76125 100644 --- a/packages/SettingsLib/src/com/android/settingslib/animation/AppearAnimationUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/animation/AppearAnimationUtils.java @@ -16,11 +16,18 @@ package com.android.settingslib.animation; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.content.Context; +import android.view.RenderNodeAnimator; import android.view.View; +import android.view.ViewPropertyAnimator; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; +import com.android.internal.widget.LockPatternView; import com.android.settingslib.R; /** @@ -174,24 +181,63 @@ public class AppearAnimationUtils implements AppearAnimationCreator<View> { } @Override - public void createAnimation(View view, long delay, long duration, float translationY, - boolean appearing, Interpolator interpolator, Runnable endRunnable) { + public void createAnimation(final View view, long delay, long duration, float translationY, + boolean appearing, Interpolator interpolator, final Runnable endRunnable) { if (view != null) { view.setAlpha(appearing ? 0f : 1.0f); view.setTranslationY(appearing ? translationY : 0); - view.animate() - .alpha(appearing ? 1f : 0f) - .translationY(appearing ? 0 : translationY) - .setInterpolator(interpolator) - .setDuration(duration) - .setStartDelay(delay); + Animator alphaAnim; + float targetAlpha = appearing ? 1f : 0f; + if (view.isHardwareAccelerated()) { + RenderNodeAnimator alphaAnimRt = new RenderNodeAnimator(RenderNodeAnimator.ALPHA, + targetAlpha); + alphaAnimRt.setTarget(view); + alphaAnim = alphaAnimRt; + } else { + alphaAnim = ObjectAnimator.ofFloat(view, View.ALPHA, view.getAlpha(), targetAlpha); + } + alphaAnim.setInterpolator(interpolator); + alphaAnim.setDuration(duration); + alphaAnim.setStartDelay(delay); if (view.hasOverlappingRendering()) { - view.animate().withLayer(); + view.setLayerType(View.LAYER_TYPE_HARDWARE, null); + alphaAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + view.setLayerType(View.LAYER_TYPE_NONE, null); + } + }); } if (endRunnable != null) { - view.animate().withEndAction(endRunnable); + alphaAnim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + endRunnable.run(); + } + }); } + alphaAnim.start(); + startTranslationYAnimation(view, delay, duration, appearing ? 0 : translationY, + interpolator); + } + } + + public static void startTranslationYAnimation(View view, long delay, long duration, + float endTranslationY, Interpolator interpolator) { + Animator translationAnim; + if (view.isHardwareAccelerated()) { + RenderNodeAnimator translationAnimRt = new RenderNodeAnimator( + RenderNodeAnimator.TRANSLATION_Y, endTranslationY); + translationAnimRt.setTarget(view); + translationAnim = translationAnimRt; + } else { + translationAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, + view.getTranslationY(), endTranslationY); } + translationAnim.setInterpolator(interpolator); + translationAnim.setDuration(duration); + translationAnim.setStartDelay(delay); + translationAnim.start(); } public class AppearAnimationProperties { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index 10191ed..bbd57db 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -26,11 +26,13 @@ import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.util.AttributeSet; import android.util.MathUtils; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; +import android.view.ViewRootImpl; import android.view.ViewTreeObserver; import android.view.WindowInsets; import android.view.accessibility.AccessibilityEvent; @@ -42,6 +44,7 @@ import android.widget.TextView; import com.android.internal.logging.MetricsLogger; import com.android.keyguard.KeyguardStatusView; +import com.android.systemui.DejankUtils; import com.android.systemui.EventLogConstants; import com.android.systemui.EventLogTags; import com.android.systemui.R; @@ -79,6 +82,8 @@ public class NotificationPanelView extends PanelView implements private static final String COUNTER_PANEL_OPEN_QS = "panel_open_qs"; private static final String COUNTER_PANEL_OPEN_PEEK = "panel_open_peek"; + private static final Rect mDummyDirtyRect = new Rect(0, 0, 1, 1); + public static final long DOZE_ANIMATION_DURATION = 700; private KeyguardAffordanceHelper mAfforanceHelper; @@ -1776,7 +1781,22 @@ public class NotificationPanelView extends PanelView implements mIsExpanding = false; mScrollYOverride = -1; if (isFullyCollapsed()) { - setListening(false); + DejankUtils.postAfterTraversal(new Runnable() { + @Override + public void run() { + setListening(false); + } + }); + + // Workaround b/22639032: Make sure we invalidate something because else RenderThread + // thinks we are actually drawing a frame put in reality we don't, so RT doesn't go + // ahead with rendering and we jank. + postOnAnimation(new Runnable() { + @Override + public void run() { + getParent().invalidateChild(NotificationPanelView.this, mDummyDirtyRect); + } + }); } else { setListening(true); } |