Notifications: Clear animation start visible type when not animating
Fixes an issue where the animation start visible type could
be stale if the animation was cancelled.
Bug: 30876804
Test: runtest systemui
Change-Id: I8e6ac6ba0bcd785f980b22529d83ba86da744f00
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
index 077303a..b45cde8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java
@@ -31,6 +31,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.NotificationColorUtil;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.HybridNotificationView;
@@ -693,6 +694,9 @@
forceUpdateVisibility(VISIBLE_TYPE_HEADSUP, mHeadsUpChild, mHeadsUpWrapper);
forceUpdateVisibility(VISIBLE_TYPE_SINGLELINE, mSingleLineView, mSingleLineView);
forceUpdateVisibility(VISIBLE_TYPE_AMBIENT, mAmbientChild, mAmbientWrapper);
+ // forceUpdateVisibilities cancels outstanding animations without updating the
+ // mAnimationStartVisibleType. Do so here instead.
+ mAnimationStartVisibleType = UNDEFINED;
}
private void forceUpdateVisibility(int type, View view, TransformableView wrapper) {
@@ -748,6 +752,9 @@
mSingleLineView, mSingleLineView);
updateViewVisibility(visibleType, VISIBLE_TYPE_AMBIENT,
mAmbientChild, mAmbientWrapper);
+ // updateViewVisibilities cancels outstanding animations without updating the
+ // mAnimationStartVisibleType. Do so here instead.
+ mAnimationStartVisibleType = UNDEFINED;
}
private void updateViewVisibility(int visibleType, int type, View view,
@@ -1236,6 +1243,11 @@
}
}
+ @VisibleForTesting
+ boolean isAnimatingVisibleType() {
+ return mAnimationStartVisibleType != UNDEFINED;
+ }
+
public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
mHeadsUpAnimatingAway = headsUpAnimatingAway;
selectLayout(false /* animate */, true /* force */);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java
new file mode 100644
index 0000000..3bb9f5f
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.statusbar;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.annotation.UiThreadTest;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.view.View;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class NotificationContentViewTest {
+
+ NotificationContentView mView;
+ Context mContext;
+
+ @Before
+ public void setup() {
+ ExpandableNotificationRow rowMock = mock(ExpandableNotificationRow.class);
+ when(rowMock.getIntrinsicHeight()).thenReturn(10);
+
+ mContext = InstrumentationRegistry.getTargetContext();
+ mView = new NotificationContentView(mContext, null);
+ mView.setContainingNotification(rowMock);
+ mView.setHeights(10, 20, 30, 40);
+
+ mView.setContractedChild(createViewWithHeight(10));
+ mView.setExpandedChild(createViewWithHeight(20));
+ mView.setHeadsUpChild(createViewWithHeight(30));
+ mView.setAmbientChild(createViewWithHeight(40));
+
+ mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
+ mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight());
+ }
+
+ private View createViewWithHeight(int height) {
+ View view = new View(mContext, null);
+ view.setMinimumHeight(height);
+ return view;
+ }
+
+ @Test
+ @UiThreadTest
+ public void animationStartType_getsClearedAfterUpdatingVisibilitiesWithoutAnimation() {
+ mView.setHeadsUp(true);
+ mView.setDark(true, false, 0);
+ mView.setDark(false, true, 0);
+ mView.setHeadsUpAnimatingAway(true);
+ Assert.assertFalse(mView.isAnimatingVisibleType());
+ }
+}