OSDN Git Service

Only animate when the slice is actually animating
authorLucas Dupin <dupin@google.com>
Wed, 23 May 2018 01:08:35 +0000 (18:08 -0700)
committerLucas Dupin <dupin@google.com>
Wed, 23 May 2018 02:13:51 +0000 (19:13 -0700)
It's not correct to always animate if there is a layout transition.
The transition might not be triggered when the view is invisible
for example. It's necessary to check if we have pending/running
animations.

Change-Id: I75dbc9f8a152a162a3c77c9b316f653e665b8842
Fixes: 79773596
Test: manual
Test: atest packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java

packages/SystemUI/src/com/android/keyguard/KeyguardSliceView.java
packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java
packages/SystemUI/tests/src/com/android/keyguard/KeyguardSliceViewTest.java

index f066e34..c0b10e2 100644 (file)
@@ -83,10 +83,9 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
     private LiveData<Slice> mLiveData;
     private int mIconSize;
     /**
-     * Listener called whenever the view contents change.
-     * Boolean will be true when the change happens animated.
+     * Runnable called whenever the view contents change.
      */
-    private Consumer<Boolean> mContentChangeListener;
+    private Runnable mContentChangeListener;
     private boolean mHasHeader;
     private Slice mSlice;
     private boolean mPulsing;
@@ -149,7 +148,9 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
         if (mPulsing || mSlice == null) {
             mTitle.setVisibility(GONE);
             mRow.setVisibility(GONE);
-            mContentChangeListener.accept(getLayoutTransition() != null);
+            if (mContentChangeListener != null) {
+                mContentChangeListener.run();
+            }
             return;
         }
 
@@ -221,7 +222,7 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
         }
 
         if (mContentChangeListener != null) {
-            mContentChangeListener.accept(getLayoutTransition() != null);
+            mContentChangeListener.run();
         }
     }
 
@@ -308,11 +309,10 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
     }
 
     /**
-     * Listener that gets invoked every time the title or the row visibility changes.
-     * Parameter will be {@code true} whenever the change happens animated.
+     * Runnable that gets invoked every time the title or the row visibility changes.
      * @param contentChangeListener The listener.
      */
-    public void setContentChangeListener(Consumer<Boolean> contentChangeListener) {
+    public void setContentChangeListener(Runnable contentChangeListener) {
         mContentChangeListener = contentChangeListener;
     }
 
index 758a1b4..976b454 100644 (file)
@@ -76,7 +76,6 @@ public class KeyguardStatusView extends GridLayout implements
     private float mDarkAmount = 0;
     private int mTextColor;
     private float mWidgetPadding;
-    private boolean mAnimateLayout;
     private int mLastLayoutHeight;
 
     private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
@@ -185,7 +184,7 @@ public class KeyguardStatusView extends GridLayout implements
         mClockView.addOnLayoutChangeListener(this);
         mClockSeparator.addOnLayoutChangeListener(this);
         mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged);
-        onSliceContentChanged(false /* animated */);
+        onSliceContentChanged();
 
         boolean shouldMarquee = KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
         setEnableMarquee(shouldMarquee);
@@ -199,8 +198,7 @@ public class KeyguardStatusView extends GridLayout implements
         mClockView.setElegantTextHeight(false);
     }
 
-    private void onSliceContentChanged(boolean animated) {
-        mAnimateLayout = animated;
+    private void onSliceContentChanged() {
         boolean smallClock = mKeyguardSlice.hasHeader() || mPulsing;
         float clockScale = smallClock ? mSmallClockScale : 1;
 
@@ -228,10 +226,12 @@ public class KeyguardStatusView extends GridLayout implements
         long duration = KeyguardSliceView.DEFAULT_ANIM_DURATION;
         long delay = smallClock ? 0 : duration / 4;
 
+        boolean shouldAnimate = mKeyguardSlice.getLayoutTransition() != null
+                && mKeyguardSlice.getLayoutTransition().isRunning();
         if (view == mClockView) {
             float clockScale = smallClock ? mSmallClockScale : 1;
             Paint.Style style = smallClock ? Paint.Style.FILL_AND_STROKE : Paint.Style.FILL;
-            if (mAnimateLayout) {
+            if (shouldAnimate) {
                 mClockView.setY(oldTop + heightOffset);
                 mClockView.animate().cancel();
                 mClockView.animate()
@@ -257,7 +257,7 @@ public class KeyguardStatusView extends GridLayout implements
         } else if (view == mClockSeparator) {
             boolean hasSeparator = hasHeader && !mPulsing;
             float alpha = hasSeparator ? 1 : 0;
-            if (mAnimateLayout) {
+            if (shouldAnimate) {
                 boolean isAwake = mDarkAmount != 0;
                 mClockSeparator.setY(oldTop + heightOffset);
                 mClockSeparator.animate().cancel();
index 17a4fbc..189b1ee 100644 (file)
@@ -57,9 +57,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase {
     public void showSlice_notifiesListener() {
         ListBuilder builder = new ListBuilder(getContext(), mSliceUri);
         AtomicBoolean notified = new AtomicBoolean();
-        mKeyguardSliceView.setContentChangeListener((hasHeader)-> {
-            notified.set(true);
-        });
+        mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
         mKeyguardSliceView.onChanged(builder.build());
         Assert.assertTrue("Listener should be notified about slice changes.",
                 notified.get());
@@ -68,9 +66,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase {
     @Test
     public void showSlice_emptySliceNotifiesListener() {
         AtomicBoolean notified = new AtomicBoolean();
-        mKeyguardSliceView.setContentChangeListener((hasHeader)-> {
-            notified.set(true);
-        });
+        mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
         mKeyguardSliceView.onChanged(null);
         Assert.assertTrue("Listener should be notified about slice changes.",
                 notified.get());
@@ -92,9 +88,7 @@ public class KeyguardSliceViewTest extends SysuiTestCase {
     @Test
     public void refresh_replacesSliceContentAndNotifiesListener() {
         AtomicBoolean notified = new AtomicBoolean();
-        mKeyguardSliceView.setContentChangeListener((hasHeader)-> {
-            notified.set(true);
-        });
+        mKeyguardSliceView.setContentChangeListener(()-> notified.set(true));
         mKeyguardSliceView.refresh();
         Assert.assertTrue("Listener should be notified about slice changes.",
                 notified.get());