Merge "Invert custom views in dark mode"

This commit is contained in:
Lucas Dupin
2019-01-25 04:00:05 +00:00
committed by Android (Google) Code Review
4 changed files with 61 additions and 5 deletions

View File

@@ -68,6 +68,7 @@
<item type="id" name="panel_alpha_animator_tag"/>
<item type="id" name="panel_alpha_animator_start_tag"/>
<item type="id" name="panel_alpha_animator_end_tag"/>
<item type="id" name="cross_fade_layer_type_changed_tag"/>
<!-- Whether the icon is from a notification for which targetSdk < L -->
<item type="id" name="icon_is_pre_L"/>

View File

@@ -19,6 +19,7 @@ package com.android.systemui.statusbar;
import android.view.View;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
/**
@@ -92,9 +93,15 @@ public class CrossFadeHelper {
private static void updateLayerType(View view, float alpha) {
if (view.hasOverlappingRendering() && alpha > 0.0f && alpha < 1.0f) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} else if (view.getLayerType() == View.LAYER_TYPE_HARDWARE) {
view.setLayerType(View.LAYER_TYPE_NONE, null);
if (view.getLayerType() != View.LAYER_TYPE_HARDWARE) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
view.setTag(R.id.cross_fade_layer_type_changed_tag, true);
}
} else if (view.getLayerType() == View.LAYER_TYPE_HARDWARE
&& view.getTag(R.id.cross_fade_layer_type_changed_tag) != null) {
if (view.getTag(R.id.cross_fade_layer_type_changed_tag) != null) {
view.setLayerType(View.LAYER_TYPE_NONE, null);
}
}
}
@@ -114,7 +121,7 @@ public class CrossFadeHelper {
.setStartDelay(delay)
.setInterpolator(Interpolators.ALPHA_IN)
.withEndAction(null);
if (view.hasOverlappingRendering()) {
if (view.hasOverlappingRendering() && view.getLayerType() != View.LAYER_TYPE_HARDWARE) {
view.animate().withLayer();
}
}

View File

@@ -17,8 +17,15 @@
package com.android.systemui.statusbar.notification.row.wrapper;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Build;
import android.view.View;
import com.android.internal.graphics.ColorUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
@@ -41,6 +48,47 @@ public class NotificationCustomViewWrapper extends NotificationViewWrapper {
mView.setAlpha(visible ? 1.0f : 0.0f);
}
@Override
public void onReinflated() {
super.onReinflated();
Configuration configuration = mView.getResources().getConfiguration();
boolean nightMode = (configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK)
== Configuration.UI_MODE_NIGHT_YES;
float[] hsl = new float[] {0f, 0f, 0f};
ColorUtils.colorToHSL(mBackgroundColor, hsl);
boolean backgroundIsDark = Color.alpha(mBackgroundColor) == 0
|| hsl[1] == 0 && hsl[2] < 0.5;
boolean backgroundHasColor = hsl[1] > 0;
// Let's invert the notification colors when we're in night mode and
// the notification background isn't colorized.
if (!backgroundIsDark && !backgroundHasColor && nightMode
&& mRow.getEntry().targetSdk < Build.VERSION_CODES.Q) {
Paint paint = new Paint();
ColorMatrix matrix = new ColorMatrix();
ColorMatrix tmp = new ColorMatrix();
// Inversion should happen on Y'UV space to conseve the colors and
// only affect the luminosity.
matrix.setRGB2YUV();
tmp.set(new float[]{
-1f, 0f, 0f, 0f, 255f,
0f, 1f, 0f, 0f, 0f,
0f, 0f, 1f, 0f, 0f,
0f, 0f, 0f, 1f, 0f
});
matrix.postConcat(tmp);
tmp.setYUV2RGB();
matrix.postConcat(tmp);
paint.setColorFilter(new ColorMatrixColorFilter(matrix));
mView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
hsl[2] = 1f - hsl[2];
mBackgroundColor = ColorUtils.HSLToColor(hsl);
}
}
@Override
protected boolean shouldClearBackgroundOnReapply() {
return false;

View File

@@ -37,7 +37,7 @@ public abstract class NotificationViewWrapper implements TransformableView {
protected final View mView;
protected final ExpandableNotificationRow mRow;
private int mBackgroundColor = 0;
protected int mBackgroundColor = 0;
public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) {
if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {