Merge "Update advanced bt header"

This commit is contained in:
Lei Yu
2019-02-22 21:50:04 +00:00
committed by Android (Google) Code Review
2 changed files with 91 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -74,16 +75,18 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
@Test
public void createBatteryIcon_hasCorrectInfo() {
final Drawable drawable = mController.createBtBatteryIcon(mContext, BATTERY_LEVEL_MAIN);
final Drawable drawable = mController.createBtBatteryIcon(mContext, BATTERY_LEVEL_MAIN,
true /* charging */);
assertThat(drawable).isInstanceOf(BatteryMeterView.BatteryMeterDrawable.class);
final BatteryMeterView.BatteryMeterDrawable iconDrawable =
(BatteryMeterView.BatteryMeterDrawable) drawable;
assertThat(iconDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL_MAIN);
assertThat(iconDrawable.getCharging()).isTrue();
}
@Test
public void refresh_updateCorrectInfo() {
public void refresh_connected_updateCorrectInfo() {
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY)).thenReturn(
String.valueOf(BATTERY_LEVEL_LEFT));
@@ -93,6 +96,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
when(mBluetoothDevice.getMetadata(
BluetoothDevice.METADATA_UNTHETHERED_CASE_BATTERY)).thenReturn(
String.valueOf(BATTERY_LEVEL_MAIN));
when(mCachedDevice.isConnected()).thenReturn(true);
mController.refresh();
assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT);
@@ -100,6 +104,26 @@ public class AdvancedBluetoothDetailsHeaderControllerTest{
assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
}
@Test
public void refresh_disconnected_updateCorrectInfo() {
when(mCachedDevice.isConnected()).thenReturn(false);
mController.refresh();
final LinearLayout layout = mLayoutPreference.findViewById(R.id.layout_middle);
assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility()).isEqualTo(
View.GONE);
assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility()).isEqualTo(
View.GONE);
assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(layout.findViewById(R.id.header_title).getVisibility()).isEqualTo(View.GONE);
assertThat(layout.findViewById(R.id.bt_battery_summary).getVisibility()).isEqualTo(
View.GONE);
assertThat(layout.findViewById(R.id.bt_battery_icon).getVisibility()).isEqualTo(View.GONE);
assertThat(layout.findViewById(R.id.header_icon).getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
public void getAvailabilityStatus_unthetheredHeadset_returnAvailable() {
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET))