Device details LCR should be show up " ! " with low battery.
screenshot: https://screenshot.googleplex.com/f72YS3THutW.png https://screenshot.googleplex.com/v6uw7XsOs9x.png Bug: 151187813 Test: make -j42 RunSettingsRoboTests Change-Id: Iabb4ac54e6f827f54cd7c5512995f185875e4a06
This commit is contained in:
@@ -47,22 +47,21 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="33dp"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:gravity="center"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/bt_battery_icon"
|
android:id="@+id/bt_battery_icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"/>
|
||||||
android:layout_gravity="center"/>
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/bt_battery_summary"
|
android:id="@+id/bt_battery_summary"
|
||||||
style="@style/TextAppearance.EntityHeaderSummary"
|
style="@style/TextAppearance.EntityHeaderSummary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"/>
|
||||||
android:layout_gravity="center_horizontal"/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@@ -408,6 +408,9 @@
|
|||||||
<!-- Battery meter icon size of advanced bluetooth device -->
|
<!-- Battery meter icon size of advanced bluetooth device -->
|
||||||
<dimen name="advanced_bluetooth_battery_meter_width">7.8dp</dimen>
|
<dimen name="advanced_bluetooth_battery_meter_width">7.8dp</dimen>
|
||||||
<dimen name="advanced_bluetooth_battery_meter_height">13dp</dimen>
|
<dimen name="advanced_bluetooth_battery_meter_height">13dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_width">15.5dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_height">27.5dp</dimen>
|
||||||
|
<dimen name="advanced_bluetooth_battery_right_margin">-4dp</dimen>
|
||||||
|
|
||||||
<!-- Developer option bluetooth settings dialog -->
|
<!-- Developer option bluetooth settings dialog -->
|
||||||
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
|
<dimen name="developer_option_dialog_margin_start">8dp</dimen>
|
||||||
|
@@ -31,6 +31,7 @@ import android.provider.DeviceConfig;
|
|||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -191,11 +192,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
context.getResources().getDimensionPixelSize(
|
context.getResources().getDimensionPixelSize(
|
||||||
R.dimen.advanced_bluetooth_battery_meter_height));
|
R.dimen.advanced_bluetooth_battery_meter_height));
|
||||||
drawable.setBatteryLevel(level);
|
drawable.setBatteryLevel(level);
|
||||||
final int attr = level > LOW_BATTERY_LEVEL || charging
|
|
||||||
? android.R.attr.colorControlNormal
|
|
||||||
: android.R.attr.colorError;
|
|
||||||
drawable.setColorFilter(new PorterDuffColorFilter(
|
drawable.setColorFilter(new PorterDuffColorFilter(
|
||||||
com.android.settings.Utils.getColorAttrDefaultColor(context, attr),
|
com.android.settings.Utils.getColorAttrDefaultColor(context,
|
||||||
|
android.R.attr.colorControlNormal),
|
||||||
PorterDuff.Mode.SRC));
|
PorterDuff.Mode.SRC));
|
||||||
drawable.setCharging(charging);
|
drawable.setCharging(charging);
|
||||||
|
|
||||||
@@ -218,12 +217,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
|
final boolean charging = BluetoothUtils.getBooleanMetaData(bluetoothDevice, chargeMetaKey);
|
||||||
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
|
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
|
||||||
linearLayout.setVisibility(View.VISIBLE);
|
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);
|
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);
|
||||||
} 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);
|
||||||
@@ -234,6 +231,28 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
textView.setVisibility(View.VISIBLE);
|
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() {
|
private void updateDisconnectLayout() {
|
||||||
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
|
mLayoutPreference.findViewById(R.id.layout_left).setVisibility(View.GONE);
|
||||||
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
|
mLayoutPreference.findViewById(R.id.layout_right).setVisibility(View.GONE);
|
||||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
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_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 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";
|
||||||
|
|
||||||
@@ -115,6 +117,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
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(BATTERY_LEVEL_MAIN).getBytes());
|
||||||
|
|
||||||
when(mCachedDevice.isConnected()).thenReturn(true);
|
when(mCachedDevice.isConnected()).thenReturn(true);
|
||||||
mController.refresh();
|
mController.refresh();
|
||||||
|
|
||||||
@@ -143,6 +146,36 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
assertThat(layout.findViewById(R.id.header_icon).getVisibility()).isEqualTo(View.VISIBLE);
|
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
|
@Test
|
||||||
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
|
public void getAvailabilityStatus_untetheredHeadsetWithConfigOn_returnAvailable() {
|
||||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SETTINGS_UI,
|
||||||
@@ -256,4 +289,10 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
com.android.settings.Utils.formatPercentage(batteryLevel));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user