Merge "Add low battery level for case" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
83cc03d0b1
@@ -63,6 +63,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback {
|
LifecycleObserver, OnStart, OnStop, OnDestroy, CachedBluetoothDevice.Callback {
|
||||||
private static final String TAG = "AdvancedBtHeaderCtrl";
|
private static final String TAG = "AdvancedBtHeaderCtrl";
|
||||||
private static final int LOW_BATTERY_LEVEL = 15;
|
private static final int LOW_BATTERY_LEVEL = 15;
|
||||||
|
private static final int CASE_LOW_BATTERY_LEVEL = 19;
|
||||||
private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -226,7 +227,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
|
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
|
||||||
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
|
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
|
||||||
textView.setVisibility(View.VISIBLE);
|
textView.setVisibility(View.VISIBLE);
|
||||||
showBatteryIcon(linearLayout, batteryLevel, charging);
|
showBatteryIcon(linearLayout, batteryLevel, charging, batteryMetaKey);
|
||||||
} else {
|
} else {
|
||||||
// Hide it if it doesn't have battery information
|
// Hide it if it doesn't have battery information
|
||||||
linearLayout.setVisibility(View.GONE);
|
linearLayout.setVisibility(View.GONE);
|
||||||
@@ -237,8 +238,12 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
textView.setVisibility(View.VISIBLE);
|
textView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBatteryIcon(LinearLayout linearLayout, int level, boolean charging) {
|
private void showBatteryIcon(LinearLayout linearLayout, int level, boolean charging,
|
||||||
boolean enableLowBattery = level <= LOW_BATTERY_LEVEL && !charging;
|
int batteryMetaKey) {
|
||||||
|
final int lowBatteryLevel =
|
||||||
|
batteryMetaKey == BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY
|
||||||
|
? CASE_LOW_BATTERY_LEVEL : LOW_BATTERY_LEVEL;
|
||||||
|
final boolean enableLowBattery = level <= lowBatteryLevel && !charging;
|
||||||
final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
|
final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
|
||||||
if (enableLowBattery) {
|
if (enableLowBattery) {
|
||||||
imageView.setImageDrawable(mContext.getDrawable(R.drawable.ic_battery_alert_24dp));
|
imageView.setImageDrawable(mContext.getDrawable(R.drawable.ic_battery_alert_24dp));
|
||||||
|
@@ -59,7 +59,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
private static final int BATTERY_LEVEL_MAIN = 30;
|
private static final int BATTERY_LEVEL_MAIN = 30;
|
||||||
private static final int BATTERY_LEVEL_LEFT = 25;
|
private static final int BATTERY_LEVEL_LEFT = 25;
|
||||||
private static final int BATTERY_LEVEL_RIGHT = 45;
|
private static final int BATTERY_LEVEL_RIGHT = 45;
|
||||||
private static final int LOW_BATTERY_LEVEL = 5;
|
private static final int LOW_BATTERY_LEVEL = 15;
|
||||||
|
private static final int CASE_LOW_BATTERY_LEVEL = 19;
|
||||||
private static final String ICON_URI = "content://test.provider/icon.png";
|
private static final String ICON_URI = "content://test.provider/icon.png";
|
||||||
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
String.valueOf(LOW_BATTERY_LEVEL).getBytes());
|
String.valueOf(LOW_BATTERY_LEVEL).getBytes());
|
||||||
when(mBluetoothDevice.getMetadata(
|
when(mBluetoothDevice.getMetadata(
|
||||||
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
|
||||||
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
|
String.valueOf(CASE_LOW_BATTERY_LEVEL).getBytes());
|
||||||
when(mBluetoothDevice.getMetadata(
|
when(mBluetoothDevice.getMetadata(
|
||||||
BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING)).thenReturn(
|
BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING)).thenReturn(
|
||||||
String.valueOf(false).getBytes());
|
String.valueOf(false).getBytes());
|
||||||
@@ -173,7 +174,8 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_left),
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
R.drawable.ic_battery_alert_24dp);
|
R.drawable.ic_battery_alert_24dp);
|
||||||
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_right), /* resId= */-1);
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_right), /* resId= */-1);
|
||||||
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), /* resId= */ -1);
|
assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle),
|
||||||
|
R.drawable.ic_battery_alert_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user