summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src
diff options
context:
space:
mode:
authorEvan Laird <evanlaird@google.com>2020-10-26 11:35:09 -0400
committerJay Aliomer <aaliomer@google.com>2020-10-28 22:26:43 +0000
commitcae46e71686d481469cb0c79afb6064ac9ba2466 (patch)
treecc072b6a240a7ee066a99b873b3bf2ed4b3915da /packages/SettingsLib/src
parent06c050caf28a4b4c2407a9d87addbfb38a0d8812 (diff)
Default dual tone alpha set to 0.3
In the event where a user of ThemedBatteryDrawable does not set the foreground / background colors explicitly, but rather uses a color filter, just set a default alpha for the background paint. Test: manual; set theme to any dualtone icon pack and visit settings battery page Bug: 162901879 Change-Id: If9becd40fbebeba15f3714e012623d3da61a7efe
Diffstat (limited to 'packages/SettingsLib/src')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/Utils.java33
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt3
2 files changed, 35 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java
index b2808061586b..9e59ce3ea166 100644
--- a/packages/SettingsLib/src/com/android/settingslib/Utils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java
@@ -14,6 +14,9 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
@@ -303,6 +306,36 @@ public class Utils {
}
/**
+ * Create a color matrix suitable for a ColorMatrixColorFilter that modifies only the color but
+ * preserves the alpha for a given drawable
+ * @param color
+ * @return a color matrix that uses the source alpha and given color
+ */
+ public static ColorMatrix getAlphaInvariantColorMatrixForColor(@ColorInt int color) {
+ int r = Color.red(color);
+ int g = Color.green(color);
+ int b = Color.blue(color);
+
+ ColorMatrix cm = new ColorMatrix(new float[] {
+ 0, 0, 0, 0, r,
+ 0, 0, 0, 0, g,
+ 0, 0, 0, 0, b,
+ 0, 0, 0, 1, 0 });
+
+ return cm;
+ }
+
+ /**
+ * Create a ColorMatrixColorFilter to tint a drawable but retain its alpha characteristics
+ *
+ * @return a ColorMatrixColorFilter which changes the color of the output but is invariant on
+ * the source alpha
+ */
+ public static ColorFilter getAlphaInvariantColorFilterForColor(@ColorInt int color) {
+ return new ColorMatrixColorFilter(getAlphaInvariantColorMatrixForColor(color));
+ }
+
+ /**
* Determine whether a package is a "system package", in which case certain things (like
* disabling notifications or disabling the package altogether) should be disallowed.
*/
diff --git a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt
index a5b5312707d0..5fa04f93e993 100644
--- a/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/graph/ThemedBatteryDrawable.kt
@@ -108,6 +108,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
private val fillColorStrokePaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
p.color = frameColor
+ p.alpha = 255
p.isDither = true
p.strokeWidth = 5f
p.style = Paint.Style.STROKE
@@ -145,7 +146,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
// Only used if dualTone is set to true
private val dualToneBackgroundFill = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
p.color = frameColor
- p.alpha = 255
+ p.alpha = 85 // ~0.3 alpha by default
p.isDither = true
p.strokeWidth = 0f
p.style = Paint.Style.FILL_AND_STROKE