diff options
author | d34d <clark@cyngn.com> | 2016-05-20 11:22:46 -0700 |
---|---|---|
committer | Clark Scheff <clark@cyngn.com> | 2016-05-23 14:20:51 -0700 |
commit | 5953be013f1f3fe14b5f4176b743c4032e114bfc (patch) | |
tree | 2ab3f9b21cbc30ecbc8d283088006b6393c14132 | |
parent | 936f7e26cff0c4893a75ef18757efda0bd8d91df (diff) | |
download | frameworks_base-5953be013f1f3fe14b5f4176b743c4032e114bfc.zip frameworks_base-5953be013f1f3fe14b5f4176b743c4032e114bfc.tar.gz frameworks_base-5953be013f1f3fe14b5f4176b743c4032e114bfc.tar.bz2 |
SysUI: Allow styling of battery text/charge blend mode
Not all battery meter modes are created equally and sometimes you
need to draw the text or charge indicator using a different blend
mode than XOR. This patch adds a new attribute to the battery
meter style which allows the blend mode to be defined per battery
style.
Change-Id: I3d2eb38828abc7e5d93337fa815a414675df43a1
TICKET: NIGHTLIES-2981
-rw-r--r-- | packages/SystemUI/res/values/cm_attrs.xml | 37 | ||||
-rw-r--r-- | packages/SystemUI/res/values/cm_styles.xml | 5 | ||||
-rwxr-xr-x | packages/SystemUI/src/com/android/systemui/BatteryMeterView.java | 34 |
3 files changed, 67 insertions, 9 deletions
diff --git a/packages/SystemUI/res/values/cm_attrs.xml b/packages/SystemUI/res/values/cm_attrs.xml index 8c2cf91..36edac0 100644 --- a/packages/SystemUI/res/values/cm_attrs.xml +++ b/packages/SystemUI/res/values/cm_attrs.xml @@ -33,6 +33,43 @@ <declare-styleable name="BatteryMeterViewDrawable"> <attr name="android:gravity"/> + <!-- Blending mode used for drawing charging bolt and percentage text --> + <attr name="blendMode"> + <!-- [0, 0] --> + <enum name="clear" value="0" /> + <!-- [Sa, Sc] --> + <enum name="src" value="1" /> + <!-- [Da, Dc] --> + <enum name="dst" value="2" /> + <!-- [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] --> + <enum name="src_over" value="3" /> + <!-- [Sa + (1 - Sa)*Da, Rc = Dc + (1 - Da)*Sc] --> + <enum name="dst_over" value="4" /> + <!-- [Sa * Da, Sc * Da] --> + <enum name="src_in" value="5" /> + <!-- [Sa * Da, Sa * Dc] --> + <enum name="dst_in" value="6" /> + <!-- [Sa * (1 - Da), Sc * (1 - Da)] --> + <enum name="src_out" value="7" /> + <!-- [Da * (1 - Sa), Dc * (1 - Sa)] --> + <enum name="dst_out" value="8" /> + <!-- [Da, Sc * Da + (1 - Sa) * Dc] --> + <enum name="src_atop" value="9" /> + <!-- [Sa, Sa * Dc + Sc * (1 - Da)] --> + <enum name="dst_atop" value="10" /> + <!-- [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc] --> + <enum name="xor" value="11" /> + <!-- Saturate(S + D) --> + <enum name="add" value="12" /> + <!-- [Sa * Da, Sc * Dc] --> + <enum name="multiply" value="13" /> + <!-- [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] --> + <enum name="screen" value="14" /> + <!-- Draw on top without any blending operations performed --> + <enum name="overlay" value="15" /> + <!-- [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)] --> + <enum name="darken" value="16" /> + </attr> </declare-styleable> </resources> diff --git a/packages/SystemUI/res/values/cm_styles.xml b/packages/SystemUI/res/values/cm_styles.xml index 4fb216c..1e63418 100644 --- a/packages/SystemUI/res/values/cm_styles.xml +++ b/packages/SystemUI/res/values/cm_styles.xml @@ -45,10 +45,13 @@ <style name="BatteryMeterViewDrawable"> <!-- gravity used for positioning text within the battery meter --> <item name="android:gravity">center</item> + <item name="blendMode">clear</item> </style> <!-- Battery meter drawable styles --> <style name="BatteryMeterViewDrawable.Portrait"/> <style name="BatteryMeterViewDrawable.Landscape"/> - <style name="BatteryMeterViewDrawable.Circle"/> + <style name="BatteryMeterViewDrawable.Circle"> + <item name="blendMode">overlay</item> + </style> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index cfb8396..7440fc5 100755 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -473,6 +473,7 @@ public class BatteryMeterView extends View implements DemoMode, private Paint mTextAndBoltPaint; private Paint mWarningTextPaint; + private Paint mClearPaint; private LayerDrawable mBatteryDrawable; private Drawable mFrameDrawable; @@ -490,13 +491,16 @@ public class BatteryMeterView extends View implements DemoMode, mMode = mode; mDisposed = false; - // load text gravity - int[] textGravityAttr = new int[] {android.R.attr.gravity}; + // load text gravity and blend mode + int[] attrs = new int[] {android.R.attr.gravity, R.attr.blendMode}; int resId = getBatteryDrawableStyleResourceForMode(mode); + PorterDuff.Mode xferMode = PorterDuff.Mode.XOR; if (resId != 0) { TypedArray a = getContext().obtainStyledAttributes( - getBatteryDrawableStyleResourceForMode(mode), textGravityAttr); + getBatteryDrawableStyleResourceForMode(mode), attrs); mTextGravity = a.getInt(0, Gravity.CENTER); + xferMode = PorterDuff.intToMode(a.getInt(1, + PorterDuff.modeToInt(PorterDuff.Mode.XOR))); } else { mTextGravity = Gravity.CENTER; } @@ -506,13 +510,16 @@ public class BatteryMeterView extends View implements DemoMode, Typeface font = Typeface.create("sans-serif-condensed", Typeface.BOLD); mTextAndBoltPaint.setTypeface(font); mTextAndBoltPaint.setTextAlign(getPaintAlignmentFromGravity(mTextGravity)); - mTextAndBoltPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR)); + mTextAndBoltPaint.setXfermode(new PorterDuffXfermode(xferMode)); mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mWarningTextPaint.setColor(mColors[1]); font = Typeface.create("sans-serif", Typeface.BOLD); mWarningTextPaint.setTypeface(font); mWarningTextPaint.setTextAlign(getPaintAlignmentFromGravity(mTextGravity)); + + mClearPaint = new Paint(); + mClearPaint.setColor(0); } @Override @@ -635,12 +642,24 @@ public class BatteryMeterView extends View implements DemoMode, level = 100; } + mTextAndBoltPaint.setColor(getColorForLevel(level)); + + // Make sure we don't draw the charge indicator if not plugged in + Drawable d = mBatteryDrawable.findDrawableByLayerId(R.id.battery_charge_indicator); + if (d instanceof BitmapDrawable) { + // In case we are using a BitmapDrawable, which we should be unless something bad + // happened, we need to change the paint rather than the alpha in case the blendMode + // has been set to clear. Clear always clears regardless of alpha level ;) + BitmapDrawable bd = (BitmapDrawable) d; + bd.getPaint().set(tracker.plugged ? mTextAndBoltPaint : mClearPaint); + } else { + d.setAlpha(tracker.plugged ? 255 : 0); + } + // Now draw the level indicator // set the level and tint color of the fill drawable mLevelDrawable.setCurrentFraction(level / 100f); mLevelDrawable.setTint(getColorForLevel(level)); - mBatteryDrawable.findDrawableByLayerId(R.id.battery_charge_indicator) - .setAlpha(tracker.plugged ? 255 : 0); mBatteryDrawable.draw(canvas); // if chosen by options, draw percentage text in the middle @@ -774,8 +793,7 @@ public class BatteryMeterView extends View implements DemoMode, newBoltDrawable = new BitmapDrawable(getResources(), boltBitmap); newBoltDrawable.setBounds(bounds); } - newBoltDrawable.getPaint().setXfermode(new PorterDuffXfermode( - PorterDuff.Mode.XOR)); + newBoltDrawable.getPaint().set(mTextAndBoltPaint); batteryDrawable.setDrawableByLayerId(R.id.battery_charge_indicator, newBoltDrawable); } |