From f868efedd5d3a2a0d5b385104a580cbd7f54a63a Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Wed, 1 Feb 2017 11:43:18 -0800 Subject: [PATCH] Fixed the background for low-priority legacy notifications The background color could be calculated wrong in case we Had a legacy notification with a dark background. Test: install legacy custom notification with background, observe Change-Id: Ie2a8ba4012f30719c05115f51bfddbdc8e33e551 Fixes: 34856700 --- .../ActivatableNotificationView.java | 14 -------------- .../statusbar/ExpandableNotificationRow.java | 2 -- .../NotificationCustomViewWrapper.java | 11 +++++++++++ .../NotificationContentViewTest.java | 19 ++++++++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java index b9ed72522bdba..4b1baa2edb396 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java @@ -38,7 +38,6 @@ import com.android.systemui.R; import com.android.systemui.classifier.FalsingManager; import com.android.systemui.statusbar.notification.FakeShadowView; import com.android.systemui.statusbar.notification.NotificationUtils; -import com.android.systemui.statusbar.policy.AccessibilityController; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.stack.StackStateAnimator; @@ -140,8 +139,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView private ValueAnimator mBackgroundColorAnimator; private float mAppearAnimationFraction = -1.0f; private float mAppearAnimationTranslation; - private boolean mShowingLegacyBackground; - private final int mLegacyColor; private final int mNormalColor; private final int mLowPriorityColor; private boolean mIsBelowSpeedBump; @@ -192,7 +189,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView mSlowOutLinearInInterpolator = new PathInterpolator(0.8f, 0.0f, 1.0f, 1.0f); setClipChildren(false); setClipToPadding(false); - mLegacyColor = context.getColor(R.color.notification_legacy_background_color); mNormalColor = context.getColor(R.color.notification_material_background_color); mLowPriorityColor = context.getColor( R.color.notification_material_background_low_priority_color); @@ -489,11 +485,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView updateOutlineAlpha(); } - public void setShowingLegacyBackground(boolean showing) { - mShowingLegacyBackground = showing; - updateBackgroundTint(); - } - @Override public void setBelowSpeedBump(boolean below) { super.setBelowSpeedBump(below); @@ -950,8 +941,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView } if (withTint && mBgTint != NO_COLOR) { return mBgTint; - } else if (mShowingLegacyBackground) { - return mLegacyColor; } else if (mIsBelowSpeedBump) { return mLowPriorityColor; } else { @@ -962,8 +951,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView protected int getRippleColor() { if (mBgTint != 0) { return mTintedRippleColor; - } else if (mShowingLegacyBackground) { - return mTintedRippleColor; } else if (mIsBelowSpeedBump) { return mLowPriorityRippleColor; } else { @@ -1009,7 +996,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView public void reset() { setTintColor(0); resetBackgroundAlpha(); - setShowingLegacyBackground(false); setBelowSpeedBump(false); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index f19d6d7f65ac0..85e2bd6161686 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -1796,9 +1796,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { return mShowingPublic ? mPublicLayout : mPrivateLayout; } - @Override public void setShowingLegacyBackground(boolean showing) { - super.setShowingLegacyBackground(showing); for (NotificationContentView l : mLayouts) { l.setShowingLegacyBackground(showing); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java index 3b18886372e20..03c732557244d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationCustomViewWrapper.java @@ -41,10 +41,12 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper { private final ViewInvertHelper mInvertHelper; private final Paint mGreyPaint = new Paint(); private boolean mShowingLegacyBackground; + private int mLegacyColor; protected NotificationCustomViewWrapper(View view, ExpandableNotificationRow row) { super(view, row); mInvertHelper = new ViewInvertHelper(view, NotificationPanelView.DOZE_ANIMATION_DURATION); + mLegacyColor = row.getContext().getColor(R.color.notification_legacy_background_color); } @Override @@ -102,6 +104,15 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper { mView.setAlpha(visible ? 1.0f : 0.0f); } + @Override + public int getCustomBackgroundColor() { + int customBackgroundColor = super.getCustomBackgroundColor(); + if (customBackgroundColor == 0 && mShowingLegacyBackground) { + return mLegacyColor; + } + return customBackgroundColor; + } + @Override public void setShowingLegacyBackground(boolean showing) { super.setShowingLegacyBackground(showing); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java index 3bb9f5fe85468..77f96b8a7b19d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationContentViewTest.java @@ -16,9 +16,6 @@ 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; @@ -31,6 +28,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + @SmallTest @RunWith(AndroidJUnit4.class) public class NotificationContentViewTest { @@ -39,13 +41,16 @@ public class NotificationContentViewTest { Context mContext; @Before + @UiThreadTest public void setup() { - ExpandableNotificationRow rowMock = mock(ExpandableNotificationRow.class); - when(rowMock.getIntrinsicHeight()).thenReturn(10); - mContext = InstrumentationRegistry.getTargetContext(); mView = new NotificationContentView(mContext, null); - mView.setContainingNotification(rowMock); + ExpandableNotificationRow row = new ExpandableNotificationRow(mContext, null); + ExpandableNotificationRow mockRow = spy(row); + doNothing().when(mockRow).updateBackgroundAlpha(anyFloat()); + doReturn(10).when(mockRow).getIntrinsicHeight(); + + mView.setContainingNotification(mockRow); mView.setHeights(10, 20, 30, 40); mView.setContractedChild(createViewWithHeight(10));