diff options
author | 2017-10-19 11:05:09 -0700 | |
---|---|---|
committer | 2017-10-19 11:43:54 -0700 | |
commit | 4b7f43bcae20e5fe0f452098c70359e6d54885c5 (patch) | |
tree | 7daf9745ed8633976546a54244ef3a997fdeda25 | |
parent | db768d45e0f9d3fb9928257324249a9cdad7b539 (diff) |
Reuse the BluetoothBatteryDrawable in QS detail
BluetoothBatteryDrawable creates the drawable lazily using
the latest(and most correct) context. So it could get the
correct color from the theme.
Also add iconScale field in BluetoothBatteryDrawable so the size
of the battery icon could be scaled.
Bug: 67377756
Test: Manual - connected to bluetooth headphone and open the qs
page and detail page. Retest it after changing it to dark theme.
Change-Id: Ic6c871985a89a503221755eed4bc2605ab53f630
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/QSDetailItems.java | 5 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java | 17 |
2 files changed, 14 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSDetailItems.java b/packages/SystemUI/src/com/android/systemui/qs/QSDetailItems.java index b4cc4b1586a2..8869e8dd3821 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSDetailItems.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSDetailItems.java @@ -34,6 +34,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.android.systemui.FontSizeUtils; import com.android.systemui.R; +import com.android.systemui.plugins.qs.QSTile; /** * Quick settings common detail view with line items. @@ -185,7 +186,7 @@ public class QSDetailItems extends FrameLayout { view.setVisibility(mItemsVisible ? VISIBLE : INVISIBLE); final ImageView iv = (ImageView) view.findViewById(android.R.id.icon); if (item.iconDrawable != null) { - iv.setImageDrawable(item.iconDrawable); + iv.setImageDrawable(item.iconDrawable.getDrawable(iv.getContext())); } else { iv.setImageResource(item.icon); } @@ -258,7 +259,7 @@ public class QSDetailItems extends FrameLayout { public static class Item { public int icon; - public Drawable iconDrawable; + public QSTile.Icon iconDrawable; public Drawable overlay; public CharSequence line1; public CharSequence line2; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java index 81b8622c548f..bc3ccb41cce0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/BluetoothTile.java @@ -134,7 +134,9 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { if (lastDevice != null) { int batteryLevel = lastDevice.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { - state.icon = new BluetoothBatteryDrawable(batteryLevel); + state.icon = new BluetoothBatteryDrawable(batteryLevel, + mContext.getResources().getFraction( + R.fraction.bt_battery_scale_fraction, 1, 1)); } } state.contentDescription = mContext.getString( @@ -212,17 +214,21 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { private class BluetoothBatteryDrawable extends Icon { private int mLevel; + private float mIconScale; BluetoothBatteryDrawable(int level) { + this(level, 1 /* iconScale */); + } + + BluetoothBatteryDrawable(int level, float iconScale) { mLevel = level; + mIconScale = iconScale; } @Override public Drawable getDrawable(Context context) { return createLayerDrawable(context, - R.drawable.ic_qs_bluetooth_connected, mLevel, - context.getResources().getFraction( - R.fraction.bt_battery_scale_fraction, 1, 1)); + R.drawable.ic_qs_bluetooth_connected, mLevel, mIconScale); } } @@ -304,8 +310,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> { item.icon = R.drawable.ic_qs_bluetooth_connected; int batteryLevel = device.getBatteryLevel(); if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) { - item.iconDrawable = createLayerDrawable(mContext, item.icon, - batteryLevel); + item.iconDrawable = new BluetoothBatteryDrawable(batteryLevel); item.line2 = mContext.getString( R.string.quick_settings_connected_battery_level, Utils.formatPercentage(batteryLevel)); |