From 1fc7629dda695c51289034bb7ad895d20ea80f63 Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Tue, 8 Jan 2019 16:20:52 -0800 Subject: [PATCH] Add layout for advanced BT detail header If device supports metadata, then we display advanced UI in Bluetooth details header. This CL adds layout for this header. In advanced layout, it will show: 1. Device name 2. Left, right and case icon 3. Left, right and case battery level Once API is ready, following CL will get metadata from it and set it to UI. Bug: 122460277 Test: RunSettingsRoboTests Change-Id: Ide044cf9705f350b431b2cb3a9ad82cc4425a17e --- res/layout/advanced_bt_entity_header.xml | 68 ++++++++++++++ res/layout/advanced_bt_entity_sub.xml | 63 +++++++++++++ res/values/strings.xml | 7 ++ res/xml/bluetooth_device_details_fragment.xml | 11 ++- ...ancedBluetoothDetailsHeaderController.java | 88 +++++++++++++++++++ .../BluetoothDetailsButtonsController.java | 2 +- .../bluetooth/BluetoothDetailsController.java | 2 +- .../BluetoothDetailsHeaderController.java | 5 +- .../BluetoothDetailsMacAddressController.java | 2 +- .../BluetoothDetailsProfilesController.java | 2 +- .../BluetoothDeviceDetailsFragment.java | 1 + ...dBluetoothDetailsHeaderControllerTest.java | 59 +++++++++++++ .../BluetoothDetailsHeaderControllerTest.java | 1 - 13 files changed, 303 insertions(+), 8 deletions(-) create mode 100644 res/layout/advanced_bt_entity_header.xml create mode 100644 res/layout/advanced_bt_entity_sub.xml create mode 100644 src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java create mode 100644 tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java diff --git a/res/layout/advanced_bt_entity_header.xml b/res/layout/advanced_bt_entity_header.xml new file mode 100644 index 00000000000..4aadad1fc34 --- /dev/null +++ b/res/layout/advanced_bt_entity_header.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/advanced_bt_entity_sub.xml b/res/layout/advanced_bt_entity_sub.xml new file mode 100644 index 00000000000..07ea8146fad --- /dev/null +++ b/res/layout/advanced_bt_entity_sub.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 35c89234eee..3eb7ccccdd7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10496,6 +10496,13 @@ No Bluetooth devices + + Left + + Right + + Case + Settings Panel diff --git a/res/xml/bluetooth_device_details_fragment.xml b/res/xml/bluetooth_device_details_fragment.xml index cf9fbf936c7..f485c6a8709 100644 --- a/res/xml/bluetooth_device_details_fragment.xml +++ b/res/xml/bluetooth_device_details_fragment.xml @@ -23,7 +23,16 @@ android:key="bluetooth_device_header" android:layout="@layout/settings_entity_header" android:selectable="false" - settings:allowDividerBelow="true"/> + settings:allowDividerBelow="true" + settings:searchable="false"/> + + pair = BluetoothUtils .getBtClassDrawableWithDescription(mContext, mCachedDevice, - mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, 1)); + mContext.getResources().getFraction(R.fraction.bt_battery_scale_fraction, 1, + 1)); String summaryText = mCachedDevice.getConnectionSummary(); // If both the hearing aids are connected, two device status should be shown. // If Second Summary is unavailable, to set it to null. @@ -84,4 +85,4 @@ public class BluetoothDetailsHeaderController extends BluetoothDetailsController public String getPreferenceKey() { return KEY_DEVICE_HEADER; } -} +} \ No newline at end of file diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java index 987dbe4f050..835961dee5e 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsMacAddressController.java @@ -62,4 +62,4 @@ public class BluetoothDetailsMacAddressController extends BluetoothDetailsContro } return mFooterPreference.getKey(); } -} +} \ No newline at end of file diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index 88cebcb331f..5c609e69c44 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -264,4 +264,4 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll public String getPreferenceKey() { return KEY_PROFILES_GROUP; } -} +} \ No newline at end of file diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java index 6ff4309a4fa..1ddad7be26b 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java @@ -108,6 +108,7 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment mManager = getLocalBluetoothManager(context); mCachedDevice = getCachedDevice(mDeviceAddress); super.onAttach(context); + use(AdvancedBluetoothDetailsHeaderController.class).init(mCachedDevice); final BluetoothFeatureProvider featureProvider = FeatureFactory.getFactory( context).getBluetoothFeatureProvider(context); diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java new file mode 100644 index 00000000000..aa91e37adb4 --- /dev/null +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.bluetooth; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.graphics.drawable.Drawable; + +import com.android.settings.fuelgauge.BatteryMeterView; +import com.android.settings.testutils.shadow.ShadowEntityHeaderController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +@Config(shadows = ShadowEntityHeaderController.class) +public class AdvancedBluetoothDetailsHeaderControllerTest{ + private static final int BATTERY_LEVEL = 30; + + private Context mContext; + private AdvancedBluetoothDetailsHeaderController mController; + + @Before + public void setUp() { + mContext = RuntimeEnvironment.application; + + mController = new AdvancedBluetoothDetailsHeaderController(mContext, "pref_Key"); + } + + @Test + public void createBatteryIcon_hasCorrectInfo() { + final Drawable drawable = mController.createBtBatteryIcon(mContext, BATTERY_LEVEL); + assertThat(drawable).isInstanceOf(BatteryMeterView.BatteryMeterDrawable.class); + + final BatteryMeterView.BatteryMeterDrawable iconDrawable = + (BatteryMeterView.BatteryMeterDrawable) drawable; + assertThat(iconDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL); + } + +} diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java index 1e780753156..930d9cbe087 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsHeaderControllerTest.java @@ -50,7 +50,6 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) - @Config(shadows = ShadowEntityHeaderController.class) public class BluetoothDetailsHeaderControllerTest extends BluetoothDetailsControllerTestBase {