From 4393d200b69d7a5c5176924c3a5ad9906d149a35 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Mon, 26 Oct 2020 12:25:36 -0400 Subject: [PATCH] Use ColorMatrixColorFilter in batterymeterview the old PorterDuff color filter didn't allow us to pass through the drawable's alpha. Test: manual Bug: 162901879 Change-Id: I1ad7d9a0177c7a25d1c6a5a8437c27f60390f45e --- .../settings/fuelgauge/BatteryMeterView.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/fuelgauge/BatteryMeterView.java b/src/com/android/settings/fuelgauge/BatteryMeterView.java index d54f5a4e2e0..4a0dc1d6040 100644 --- a/src/com/android/settings/fuelgauge/BatteryMeterView.java +++ b/src/com/android/settings/fuelgauge/BatteryMeterView.java @@ -19,8 +19,6 @@ package com.android.settings.fuelgauge; import android.annotation.Nullable; import android.content.Context; import android.graphics.ColorFilter; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; import android.util.AttributeSet; import android.widget.ImageView; @@ -52,14 +50,12 @@ public class BatteryMeterView extends ImageView { super(context, attrs, defStyleAttr); final int frameColor = context.getColor(R.color.meter_background_color); - mAccentColorFilter = new PorterDuffColorFilter( - Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent), - PorterDuff.Mode.SRC); - mErrorColorFilter = new PorterDuffColorFilter( - context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN); - mForegroundColorFilter =new PorterDuffColorFilter( - Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground), - PorterDuff.Mode.SRC); + mAccentColorFilter = Utils.getAlphaInvariantColorFilterForColor( + Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent)); + mErrorColorFilter = Utils.getAlphaInvariantColorFilterForColor( + context.getColor(R.color.battery_icon_color_error)); + mForegroundColorFilter = Utils.getAlphaInvariantColorFilterForColor( + Utils.getColorAttrDefaultColor(context, android.R.attr.colorForeground)); mDrawable = new BatteryMeterDrawable(context, frameColor); mDrawable.setColorFilter(mAccentColorFilter); setImageDrawable(mDrawable);