summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src/com/android/settingslib/Utils.java
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2020-11-05 18:29:12 -0800
committerScott Lobdell <slobdell@google.com>2020-11-13 11:48:49 -0800
commit3933f277a025be704e68ea593536e492831a7e05 (patch)
tree084aa5e0858c449a63dd18cc57fb21ab054d363a /packages/SettingsLib/src/com/android/settingslib/Utils.java
parent248a6ce2e2ee65f367b01c43edeecef5a6d57581 (diff)
parent9c74513b2d828d5169e9942b58b2f93bb3e04aff (diff)
Merge SP1A.201105.002
Change-Id: Iec83a0c1f6f286a1e51abfc4356633ca9d8aea5f
Diffstat (limited to 'packages/SettingsLib/src/com/android/settingslib/Utils.java')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/Utils.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/Utils.java b/packages/SettingsLib/src/com/android/settingslib/Utils.java
index 2232af32dd12..176bce12505f 100644
--- a/packages/SettingsLib/src/com/android/settingslib/Utils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/Utils.java
@@ -15,6 +15,9 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
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;
@@ -332,6 +335,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.
*/