Reuse the BluetoothBatteryDrawable in QS detail
am: 4b7f43bcae
Change-Id: Ie5fd81010fae4660bb0fdd5d6d061fa535d86150
This commit is contained in:
@@ -34,6 +34,7 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import com.android.systemui.FontSizeUtils;
|
import com.android.systemui.FontSizeUtils;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
|
import com.android.systemui.plugins.qs.QSTile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick settings common detail view with line items.
|
* Quick settings common detail view with line items.
|
||||||
@@ -185,7 +186,7 @@ public class QSDetailItems extends FrameLayout {
|
|||||||
view.setVisibility(mItemsVisible ? VISIBLE : INVISIBLE);
|
view.setVisibility(mItemsVisible ? VISIBLE : INVISIBLE);
|
||||||
final ImageView iv = (ImageView) view.findViewById(android.R.id.icon);
|
final ImageView iv = (ImageView) view.findViewById(android.R.id.icon);
|
||||||
if (item.iconDrawable != null) {
|
if (item.iconDrawable != null) {
|
||||||
iv.setImageDrawable(item.iconDrawable);
|
iv.setImageDrawable(item.iconDrawable.getDrawable(iv.getContext()));
|
||||||
} else {
|
} else {
|
||||||
iv.setImageResource(item.icon);
|
iv.setImageResource(item.icon);
|
||||||
}
|
}
|
||||||
@@ -258,7 +259,7 @@ public class QSDetailItems extends FrameLayout {
|
|||||||
|
|
||||||
public static class Item {
|
public static class Item {
|
||||||
public int icon;
|
public int icon;
|
||||||
public Drawable iconDrawable;
|
public QSTile.Icon iconDrawable;
|
||||||
public Drawable overlay;
|
public Drawable overlay;
|
||||||
public CharSequence line1;
|
public CharSequence line1;
|
||||||
public CharSequence line2;
|
public CharSequence line2;
|
||||||
|
|||||||
@@ -134,7 +134,9 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
|
|||||||
if (lastDevice != null) {
|
if (lastDevice != null) {
|
||||||
int batteryLevel = lastDevice.getBatteryLevel();
|
int batteryLevel = lastDevice.getBatteryLevel();
|
||||||
if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
|
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(
|
state.contentDescription = mContext.getString(
|
||||||
@@ -212,17 +214,21 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
|
|||||||
|
|
||||||
private class BluetoothBatteryDrawable extends Icon {
|
private class BluetoothBatteryDrawable extends Icon {
|
||||||
private int mLevel;
|
private int mLevel;
|
||||||
|
private float mIconScale;
|
||||||
|
|
||||||
BluetoothBatteryDrawable(int level) {
|
BluetoothBatteryDrawable(int level) {
|
||||||
|
this(level, 1 /* iconScale */);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluetoothBatteryDrawable(int level, float iconScale) {
|
||||||
mLevel = level;
|
mLevel = level;
|
||||||
|
mIconScale = iconScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(Context context) {
|
public Drawable getDrawable(Context context) {
|
||||||
return createLayerDrawable(context,
|
return createLayerDrawable(context,
|
||||||
R.drawable.ic_qs_bluetooth_connected, mLevel,
|
R.drawable.ic_qs_bluetooth_connected, mLevel, mIconScale);
|
||||||
context.getResources().getFraction(
|
|
||||||
R.fraction.bt_battery_scale_fraction, 1, 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,8 +310,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
|
|||||||
item.icon = R.drawable.ic_qs_bluetooth_connected;
|
item.icon = R.drawable.ic_qs_bluetooth_connected;
|
||||||
int batteryLevel = device.getBatteryLevel();
|
int batteryLevel = device.getBatteryLevel();
|
||||||
if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
|
if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
|
||||||
item.iconDrawable = createLayerDrawable(mContext, item.icon,
|
item.iconDrawable = new BluetoothBatteryDrawable(batteryLevel);
|
||||||
batteryLevel);
|
|
||||||
item.line2 = mContext.getString(
|
item.line2 = mContext.getString(
|
||||||
R.string.quick_settings_connected_battery_level,
|
R.string.quick_settings_connected_battery_level,
|
||||||
Utils.formatPercentage(batteryLevel));
|
Utils.formatPercentage(batteryLevel));
|
||||||
|
|||||||
Reference in New Issue
Block a user