diff --git a/res/layout/advanced_bt_entity_sub.xml b/res/layout/advanced_bt_entity_sub.xml
index 17ef865a62f..0c9374fdc7c 100644
--- a/res/layout/advanced_bt_entity_sub.xml
+++ b/res/layout/advanced_bt_entity_sub.xml
@@ -47,22 +47,21 @@
+ android:layout_height="wrap_content"/>
+ android:layout_marginStart="4dp"/>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 4ca9798a95d..79071ed3a05 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -408,6 +408,9 @@
7.8dp
13dp
+ 15.5dp
+ 27.5dp
+ -4dp
8dp
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index bee93fb048d..47421923230 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -31,6 +31,7 @@ import android.provider.DeviceConfig;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -191,11 +192,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
context.getResources().getDimensionPixelSize(
R.dimen.advanced_bluetooth_battery_meter_height));
drawable.setBatteryLevel(level);
- final int attr = level > LOW_BATTERY_LEVEL || charging
- ? android.R.attr.colorControlNormal
- : android.R.attr.colorError;
drawable.setColorFilter(new PorterDuffColorFilter(
- com.android.settings.Utils.getColorAttrDefaultColor(context, attr),
+ com.android.settings.Utils.getColorAttrDefaultColor(context,
+ android.R.attr.colorControlNormal),
PorterDuff.Mode.SRC));
drawable.setCharging(charging);
@@ -218,12 +217,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
linearLayout.setVisibility(View.VISIBLE);
- final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
- imageView.setImageDrawable(createBtBatteryIcon(mContext, batteryLevel, charging));
- imageView.setVisibility(View.VISIBLE);
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
textView.setText(com.android.settings.Utils.formatPercentage(batteryLevel));
textView.setVisibility(View.VISIBLE);
+ showBatteryIcon(linearLayout, batteryLevel, charging);
} else {
// Hide it if it doesn't have battery information
linearLayout.setVisibility(View.GONE);
@@ -234,6 +231,28 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
textView.setVisibility(View.VISIBLE);
}
+ private void showBatteryIcon(LinearLayout linearLayout, int level, boolean charging) {
+ boolean enableLowBattery = level <= LOW_BATTERY_LEVEL && !charging;
+ final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
+ if (enableLowBattery) {
+ imageView.setImageDrawable(mContext.getDrawable(R.drawable.ic_battery_alert_24dp));
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.advanced_bluetooth_battery_width),
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.advanced_bluetooth_battery_height));
+ layoutParams.rightMargin = mContext.getResources().getDimensionPixelSize(
+ R.dimen.advanced_bluetooth_battery_right_margin);
+ imageView.setLayoutParams(layoutParams);
+ } else {
+ imageView.setImageDrawable(createBtBatteryIcon(mContext, level, charging));
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ imageView.setLayoutParams(layoutParams);
+ }
+ imageView.setVisibility(View.VISIBLE);
+ }
+
private void updateDisconnectLayout() {
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 80ab42c58a1..5097938f2ee 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.robolectric.Shadows.shadowOf;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -58,6 +59,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
private static final int BATTERY_LEVEL_MAIN = 30;
private static final int BATTERY_LEVEL_LEFT = 25;
private static final int BATTERY_LEVEL_RIGHT = 45;
+ private static final int LOW_BATTERY_LEVEL = 5;
private static final String ICON_URI = "content://test.provider/icon.png";
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
@@ -115,6 +117,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
+
when(mCachedDevice.isConnected()).thenReturn(true);
mController.refresh();
@@ -143,6 +146,36 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
assertThat(layout.findViewById(R.id.header_icon).getVisibility()).isEqualTo(View.VISIBLE);
}
+ @Test
+ public void refresh_withLowBatteryAndUncharged_showAlertIcon() {
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY)).thenReturn(
+ String.valueOf(LOW_BATTERY_LEVEL).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY)).thenReturn(
+ String.valueOf(LOW_BATTERY_LEVEL).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY)).thenReturn(
+ String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING)).thenReturn(
+ String.valueOf(false).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING)).thenReturn(
+ String.valueOf(true).getBytes());
+ when(mBluetoothDevice.getMetadata(
+ BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING)).thenReturn(
+ String.valueOf(false).getBytes());
+ when(mCachedDevice.isConnected()).thenReturn(true);
+
+ mController.refresh();
+
+ assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_left),
+ R.drawable.ic_battery_alert_24dp);
+ assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_right), /* resId= */-1);
+ assertBatteryIcon(mLayoutPreference.findViewById(R.id.layout_middle), /* resId= */ -1);
+ }
+
@Test
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
@@ -256,4 +289,10 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
com.android.settings.Utils.formatPercentage(batteryLevel));
}
+ private void assertBatteryIcon(LinearLayout linearLayout, int resId) {
+ final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon);
+ assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId())
+ .isEqualTo(resId);
+ }
+
}