diff options
author | Evan Laird <evanlaird@google.com> | 2019-02-08 16:48:53 -0500 |
---|---|---|
committer | Evan Laird <evanlaird@google.com> | 2019-02-26 13:42:03 -0500 |
commit | 2259da403c52a00b113e662df829f117a868a452 (patch) | |
tree | 81395c008194bc45abd9e6016a485c1af3b49115 /packages/SystemUI/src/com/android/systemui/BatteryMeterView.java | |
parent | 854a76c8709072c34c341a832a2e38389b3b43ae (diff) |
Create a battery icon that loads paths
Create a new battery drawable that will load enough resources from
frameworks/base/core/res/res/ to allow for theming overlays. The current
things are overlayable:
- Perimeter path: the outer shape of the battery (including the
terminal)
- Fill mask: path defining the shape of the fill
- Bolt path: charging bolt path. draws with appropriate protection for
visibilty
- Powersave path: path of the plus sign that draws when in powersave
mode. also draws with protection
Test: visual; sysui demo mode
Bug: 123705805
Change-Id: I2bb15fd10e3fec63cb115a8f216794933b717404
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/BatteryMeterView.java')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/BatteryMeterView.java | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index 200679432200..592b6039d69d 100644 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -46,7 +46,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.android.settingslib.Utils; -import com.android.settingslib.graph.BatteryMeterDrawableBase; +import com.android.settingslib.graph.ThemedBatteryDrawable; import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; import com.android.systemui.settings.CurrentUserTracker; @@ -76,7 +76,7 @@ public class BatteryMeterView extends LinearLayout implements public static final int MODE_OFF = 2; public static final int MODE_ESTIMATE = 3; - private final BatteryMeterDrawableBase mDrawable; + private final ThemedBatteryDrawable mDrawable; private final String mSlotBattery; private final ImageView mBatteryIconView; private final CurrentUserTracker mUserTracker; @@ -94,9 +94,11 @@ public class BatteryMeterView extends LinearLayout implements private boolean mIsSubscribedForTunerUpdates; private boolean mCharging; + private int mDarkModeSingleToneColor; private int mDarkModeBackgroundColor; private int mDarkModeFillColor; + private int mLightModeSingleToneColor; private int mLightModeBackgroundColor; private int mLightModeFillColor; private int mUser; @@ -106,6 +108,7 @@ public class BatteryMeterView extends LinearLayout implements */ private boolean mUseWallpaperTextColors; + private int mNonAdaptedSingleToneColor; private int mNonAdaptedForegroundColor; private int mNonAdaptedBackgroundColor; @@ -127,7 +130,7 @@ public class BatteryMeterView extends LinearLayout implements defStyle, 0); final int frameColor = atts.getColor(R.styleable.BatteryMeterView_frameColor, context.getColor(R.color.meter_background_color)); - mDrawable = new BatteryMeterDrawableBase(context, frameColor); + mDrawable = new ThemedBatteryDrawable(context, frameColor); atts.recycle(); mSettingObserver = new SettingObserver(new Handler(context.getMainLooper())); @@ -169,6 +172,10 @@ public class BatteryMeterView extends LinearLayout implements setClipChildren(false); setClipToPadding(false); Dependency.get(ConfigurationController.class).observe(viewAttachLifecycle(this), this); + + // Needed for PorderDuff.Mode.CLEAR operations to work properly, but redraws don't happen + // enough to justify a hardware layer. + setLayerType(LAYER_TYPE_SOFTWARE, null); } public void setForceShowPercent(boolean show) { @@ -243,9 +250,11 @@ public class BatteryMeterView extends LinearLayout implements if (mUseWallpaperTextColors) { updateColors( Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor), - Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColorSecondary)); + Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColorSecondary), + Utils.getColorAttrDefaultColor(mContext, R.attr.wallpaperTextColor)); } else { - updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor); + updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor, + mNonAdaptedSingleToneColor); } } @@ -258,10 +267,14 @@ public class BatteryMeterView extends LinearLayout implements Utils.getThemeAttr(context, R.attr.darkIconTheme)); Context dualToneLightTheme = new ContextThemeWrapper(context, Utils.getThemeAttr(context, R.attr.lightIconTheme)); + mDarkModeSingleToneColor = Utils.getColorAttrDefaultColor(dualToneDarkTheme, + R.attr.singleToneColor); mDarkModeBackgroundColor = Utils.getColorAttrDefaultColor(dualToneDarkTheme, R.attr.backgroundColor); mDarkModeFillColor = Utils.getColorAttrDefaultColor(dualToneDarkTheme, R.attr.fillColor); + mLightModeSingleToneColor = Utils.getColorAttrDefaultColor(dualToneLightTheme, + R.attr.singleToneColor); mLightModeBackgroundColor = Utils.getColorAttrDefaultColor(dualToneLightTheme, R.attr.backgroundColor); mLightModeFillColor = Utils.getColorAttrDefaultColor(dualToneLightTheme, R.attr.fillColor); @@ -303,8 +316,8 @@ public class BatteryMeterView extends LinearLayout implements @Override public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { - mDrawable.setBatteryLevel(level); mDrawable.setCharging(pluggedIn); + mDrawable.setBatteryLevel(level); mCharging = pluggedIn; mLevel = level; updatePercentText(); @@ -315,7 +328,7 @@ public class BatteryMeterView extends LinearLayout implements @Override public void onPowerSaveChanged(boolean isPowerSave) { - mDrawable.setPowerSave(isPowerSave); + mDrawable.setPowerSaveEnabled(isPowerSave); } private TextView loadPercentView() { @@ -406,21 +419,24 @@ public class BatteryMeterView extends LinearLayout implements @Override public void onDarkChanged(Rect area, float darkIntensity, int tint) { float intensity = DarkIconDispatcher.isInArea(area, this) ? darkIntensity : 0; + mNonAdaptedSingleToneColor = getColorForDarkIntensity( + intensity, mLightModeSingleToneColor, mDarkModeSingleToneColor); mNonAdaptedForegroundColor = getColorForDarkIntensity( intensity, mLightModeFillColor, mDarkModeFillColor); mNonAdaptedBackgroundColor = getColorForDarkIntensity( intensity, mLightModeBackgroundColor,mDarkModeBackgroundColor); if (!mUseWallpaperTextColors) { - updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor); + updateColors(mNonAdaptedForegroundColor, mNonAdaptedBackgroundColor, + mNonAdaptedSingleToneColor); } } - private void updateColors(int foregroundColor, int backgroundColor) { - mDrawable.setColors(foregroundColor, backgroundColor); - mTextColor = foregroundColor; + private void updateColors(int foregroundColor, int backgroundColor, int singleToneColor) { + mDrawable.setColors(foregroundColor, backgroundColor, singleToneColor); + mTextColor = singleToneColor; if (mBatteryPercentView != null) { - mBatteryPercentView.setTextColor(foregroundColor); + mBatteryPercentView.setTextColor(singleToneColor); } } @@ -429,7 +445,7 @@ public class BatteryMeterView extends LinearLayout implements } public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { - String powerSave = mDrawable == null ? null : mDrawable.getPowerSave() + ""; + String powerSave = mDrawable == null ? null : mDrawable.getPowerSaveEnabled() + ""; CharSequence percent = mBatteryPercentView == null ? null : mBatteryPercentView.getText(); pw.println(" BatteryMeterView:"); pw.println(" mDrawable.getPowerSave: " + powerSave); |