From e15452bb49d2531eee3086acb4763dd125f8053a Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Thu, 21 Aug 2014 09:44:39 -0400 Subject: [PATCH] Doze: Improve icon treatment when dozing. Instead of inverting them, simply desaturate. Also, apply a constant background to small icons and give them some transparency. Bug:17137319 Change-Id: Id772b4fcd9ffa461bec26b87a74302012fb27867 --- packages/SystemUI/res/values/colors.xml | 1 + packages/SystemUI/res/values/config.xml | 3 ++ packages/SystemUI/res/values/ids.xml | 1 + .../statusbar/ExpandableNotificationRow.java | 9 ++++ .../statusbar/NotificationContentView.java | 53 +++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 40870bf3a3486..dea14e9fcafc0 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -105,4 +105,5 @@ #ffffff #77000000 + #ff434343 diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 42d97343be038..52dc000198ec0 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -189,6 +189,9 @@ 30000 + + 222 + 200 diff --git a/packages/SystemUI/res/values/ids.xml b/packages/SystemUI/res/values/ids.xml index 6418930d2c73e..4e93cd8dfc529 100644 --- a/packages/SystemUI/res/values/ids.xml +++ b/packages/SystemUI/res/values/ids.xml @@ -34,5 +34,6 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 9ac20a6c9d254..7d6432564d10e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -120,6 +120,15 @@ public class ExpandableNotificationRow extends ActivatableNotificationView { return false; } + @Override + public void setDark(boolean dark, boolean fade) { + super.setDark(dark, fade); + final NotificationContentView showing = getShowingLayout(); + if (showing != null) { + showing.setDark(dark, fade); + } + } + public void setHeightRange(int rowMinHeight, int rowMaxHeight) { mRowMinHeight = rowMinHeight; mRowMaxHeight = rowMaxHeight; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index a030f616515fd..548e7d2240934 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -17,15 +17,20 @@ package com.android.systemui.statusbar; import android.content.Context; +import android.graphics.ColorFilter; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; import android.view.animation.Interpolator; import android.view.animation.LinearInterpolator; import android.widget.FrameLayout; +import android.widget.ImageView; import com.android.systemui.R; @@ -37,6 +42,8 @@ import com.android.systemui.R; public class NotificationContentView extends FrameLayout { private static final long ANIMATION_DURATION_LENGTH = 170; + private static final Paint INVERT_PAINT = createInvertPaint(); + private static final ColorFilter NO_COLOR_FILTER = new ColorFilter(); private final Rect mClipBounds = new Rect(); @@ -50,6 +57,7 @@ public class NotificationContentView extends FrameLayout { private final Interpolator mLinearInterpolator = new LinearInterpolator(); private boolean mContractedVisible = true; + private boolean mDark; private final Paint mFadePaint = new Paint(); @@ -192,4 +200,49 @@ public class NotificationContentView extends FrameLayout { public boolean isContentExpandable() { return mExpandedChild != null; } + + public void setDark(boolean dark, boolean fade) { + if (mDark == dark) return; + mDark = dark; + setImageViewDark(dark, fade, com.android.internal.R.id.right_icon); + setImageViewDark(dark, fade, com.android.internal.R.id.icon); + } + + private void setImageViewDark(boolean dark, boolean fade, int imageViewId) { + // TODO: implement fade + final ImageView v = (ImageView) mContractedChild.findViewById(imageViewId); + final Drawable d = v.getBackground(); + if (dark) { + v.setLayerType(LAYER_TYPE_HARDWARE, INVERT_PAINT); + if (d != null) { + v.setTag(R.id.doze_saved_filter_tag, d.getColorFilter() != null ? d.getColorFilter() + : NO_COLOR_FILTER); + d.setColorFilter(getResources().getColor(R.color.doze_small_icon_background_color), + PorterDuff.Mode.SRC_ATOP); + v.setImageAlpha(getResources().getInteger(R.integer.doze_small_icon_alpha)); + } + } else { + v.setLayerType(LAYER_TYPE_NONE, null); + if (d != null) { + final ColorFilter filter = (ColorFilter) v.getTag(R.id.doze_saved_filter_tag); + if (filter != null) { + d.setColorFilter(filter == NO_COLOR_FILTER ? null : filter); + v.setTag(R.id.doze_saved_filter_tag, null); + } + v.setImageAlpha(0xff); + } + } + } + + private static Paint createInvertPaint() { + final Paint p = new Paint(); + final float[] invert = { + -1f, 0f, 0f, 1f, 1f, + 0f, -1f, 0f, 1f, 1f, + 0f, 0f, -1f, 1f, 1f, + 0f, 0f, 0f, 1f, 0f + }; + p.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(invert))); + return p; + } }