Merge "Fix contrast exception"
This commit is contained in:
@@ -26,12 +26,15 @@ import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.NotificationHeaderView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.graphics.ColorUtils;
|
||||
import com.android.internal.util.ContrastColorUtil;
|
||||
import com.android.systemui.statusbar.CrossFadeHelper;
|
||||
import com.android.systemui.statusbar.TransformableView;
|
||||
import com.android.systemui.statusbar.notification.TransformState;
|
||||
@@ -108,6 +111,11 @@ public abstract class NotificationViewWrapper implements TransformableView {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apps targeting Q should fix their dark mode bugs.
|
||||
if (mRow.getEntry().targetSdk >= Build.VERSION_CODES.Q) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int background = getBackgroundColor(view);
|
||||
if (background == Color.TRANSPARENT) {
|
||||
background = defaultBackgroundColor;
|
||||
@@ -138,17 +146,19 @@ public abstract class NotificationViewWrapper implements TransformableView {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean childrenNeedInversion(@ColorInt int parentBackground, ViewGroup viewGroup) {
|
||||
@VisibleForTesting
|
||||
boolean childrenNeedInversion(@ColorInt int parentBackground, ViewGroup viewGroup) {
|
||||
if (viewGroup == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int backgroundColor = getBackgroundColor(viewGroup);
|
||||
if (Color.alpha(backgroundColor) != 255) {
|
||||
backgroundColor = ContrastColorUtil.compositeColors(backgroundColor, parentBackground);
|
||||
backgroundColor = ColorUtils.setAlphaComponent(backgroundColor, 255);
|
||||
}
|
||||
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
||||
View child = viewGroup.getChildAt(i);
|
||||
int backgroundColor = getBackgroundColor(viewGroup);
|
||||
if (backgroundColor == Color.TRANSPARENT) {
|
||||
backgroundColor = parentBackground;
|
||||
}
|
||||
if (child instanceof TextView) {
|
||||
int foreground = ((TextView) child).getCurrentTextColor();
|
||||
if (ColorUtils.calculateContrast(foreground, backgroundColor) < 3) {
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.statusbar.notification;
|
||||
package com.android.systemui.statusbar.notification.row.wrapper;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.filters.SmallTest;
|
||||
@@ -22,13 +24,15 @@ import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.NotificationTestHelper;
|
||||
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
|
||||
import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper;
|
||||
import com.android.systemui.util.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -37,12 +41,26 @@ import org.junit.runner.RunWith;
|
||||
@RunWithLooper
|
||||
public class NotificationViewWrapperTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void constructor_doesntUseViewContext() throws Exception {
|
||||
private View mView;
|
||||
private ExpandableNotificationRow mRow;
|
||||
private TestableNotificationViewWrapper mNotificationViewWrapper;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Assert.sMainLooper = TestableLooper.get(this).getLooper();
|
||||
new TestableNotificationViewWrapper(mContext,
|
||||
new View(mContext),
|
||||
new NotificationTestHelper(getContext()).createRow());
|
||||
mView = mock(View.class);
|
||||
mRow = new NotificationTestHelper(getContext()).createRow();
|
||||
mNotificationViewWrapper = new TestableNotificationViewWrapper(mContext, mView, mRow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void childrenNeedInversion_doesntCrash_whenOpacity() {
|
||||
LinearLayout viewGroup = new LinearLayout(mContext);
|
||||
TextView textView = new TextView(mContext);
|
||||
textView.setTextColor(0xcc000000);
|
||||
viewGroup.addView(textView);
|
||||
|
||||
mNotificationViewWrapper.childrenNeedInversion(0xcc000000, viewGroup);
|
||||
}
|
||||
|
||||
static class TestableNotificationViewWrapper extends NotificationViewWrapper {
|
||||
Reference in New Issue
Block a user