OSDN Git Service

Use ThemedBatteryDrawable in settings
authorEvan Laird <evanlaird@google.com>
Fri, 15 Feb 2019 19:55:30 +0000 (14:55 -0500)
committerEvan Laird <evanlaird@google.com>
Tue, 26 Feb 2019 19:11:58 +0000 (14:11 -0500)
Changed out BatteryMeterDrawable to inherit from ThemedBatteryDrawable
instead of BatteryMeterDrawableBase. Also removed warning text paint
because it seemed unused and simplified the interface.

Bug: 123705805
Test: visual
Change-Id: I30496e3d8881803d9d3d8a316c10387482a8f610

src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
src/com/android/settings/fuelgauge/BatteryMeterView.java
tests/robotests/src/com/android/settings/fuelgauge/BatteryMeterViewTest.java

index 4b8efd4..f91b4f9 100644 (file)
@@ -98,8 +98,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                 new BatteryMeterView.BatteryMeterDrawable(context,
                         context.getColor(R.color.meter_background_color));
         drawable.setBatteryLevel(level);
-        drawable.setShowPercent(false);
-        drawable.setBatteryColorFilter(new PorterDuffColorFilter(
+        drawable.setColorFilter(new PorterDuffColorFilter(
                 com.android.settings.Utils.getColorAttrDefaultColor(context,
                         android.R.attr.colorControlNormal),
                 PorterDuff.Mode.SRC_IN));
index 822f0e9..aa26ff4 100644 (file)
@@ -29,7 +29,7 @@ import androidx.annotation.VisibleForTesting;
 
 import com.android.settings.R;
 import com.android.settings.Utils;
-import com.android.settingslib.graph.BatteryMeterDrawableBase;
+import com.android.settingslib.graph.ThemedBatteryDrawable;
 
 public class BatteryMeterView extends ImageView {
     @VisibleForTesting
@@ -54,29 +54,27 @@ public class BatteryMeterView extends ImageView {
         final int frameColor = context.getColor(R.color.meter_background_color);
         mAccentColorFilter = new PorterDuffColorFilter(
                 Utils.getColorAttrDefaultColor(context, android.R.attr.colorAccent),
-                PorterDuff.Mode.SRC_IN);
+                PorterDuff.Mode.SRC);
         mErrorColorFilter = new PorterDuffColorFilter(
                 context.getColor(R.color.battery_icon_color_error), PorterDuff.Mode.SRC_IN);
 
         mDrawable = new BatteryMeterDrawable(context, frameColor);
-        mDrawable.setShowPercent(false);
-        mDrawable.setBatteryColorFilter(mAccentColorFilter);
-        mDrawable.setWarningColorFilter(
-                new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));
+        mDrawable.setColorFilter(mAccentColorFilter);
         setImageDrawable(mDrawable);
+        setLayerType(LAYER_TYPE_SOFTWARE, null);
     }
 
     public void setBatteryLevel(int level) {
         mDrawable.setBatteryLevel(level);
         if (level < mDrawable.getCriticalLevel()) {
-            mDrawable.setBatteryColorFilter(mErrorColorFilter);
+            mDrawable.setColorFilter(mErrorColorFilter);
         } else {
-            mDrawable.setBatteryColorFilter(mAccentColorFilter);
+            mDrawable.setColorFilter(mAccentColorFilter);
         }
     }
 
     public void setPowerSave(boolean powerSave) {
-        mDrawable.setPowerSave(powerSave);
+        mDrawable.setPowerSaveEnabled(powerSave);
         mPowerSaveEnabled = powerSave;
     }
 
@@ -85,7 +83,7 @@ public class BatteryMeterView extends ImageView {
     }
 
     public int getBatteryLevel() {
-        return mDrawable.getBatteryLevel();
+        return mDrawable.getLevel();
     }
 
     public void setCharging(boolean charging) {
@@ -97,7 +95,7 @@ public class BatteryMeterView extends ImageView {
         return mDrawable.getCharging();
     }
 
-    public static class BatteryMeterDrawable extends BatteryMeterDrawableBase {
+    public static class BatteryMeterDrawable extends ThemedBatteryDrawable {
         private final int mIntrinsicWidth;
         private final int mIntrinsicHeight;
 
@@ -119,16 +117,5 @@ public class BatteryMeterView extends ImageView {
         public int getIntrinsicHeight() {
             return mIntrinsicHeight;
         }
-
-        public void setWarningColorFilter(@Nullable ColorFilter colorFilter) {
-            mWarningTextPaint.setColorFilter(colorFilter);
-        }
-
-        public void setBatteryColorFilter(@Nullable ColorFilter colorFilter) {
-            mFramePaint.setColorFilter(colorFilter);
-            mBatteryPaint.setColorFilter(colorFilter);
-            mBoltPaint.setColorFilter(colorFilter);
-        }
     }
-
 }
index 4bdcd55..3e99433 100644 (file)
@@ -73,14 +73,14 @@ public class BatteryMeterViewTest {
     public void testSetBatteryInfo_levelLow_setErrorColor() {
         mBatteryMeterView.setBatteryLevel(BATTERY_LOW_LEVEL);
 
-        verify(mDrawable).setBatteryColorFilter(mErrorColorFilter);
+        verify(mDrawable).setColorFilter(mErrorColorFilter);
     }
 
     @Test
     public void testSetBatteryInfo_levelNormal_setNormalColor() {
         mBatteryMeterView.setBatteryLevel(BATTERY_LEVEL);
 
-        verify(mDrawable).setBatteryColorFilter(mAccentColorFilter);
+        verify(mDrawable).setColorFilter(mAccentColorFilter);
     }
 
     @Test