From cc28aba208af28821f18f3ddd2404b517b64140a Mon Sep 17 00:00:00 2001 From: Haijie Hong Date: Mon, 30 Dec 2024 15:07:10 +0800 Subject: [PATCH] Add content description for battery charging status icon BUG: 372622360 Test: atest AdvancedBluetoothDetailsHeaderControllerTest Flag: EXEMPT minor fix Change-Id: I23a889e1576c0625cefb91386987df8826c1935f --- res/values/strings.xml | 5 ++++ ...ancedBluetoothDetailsHeaderController.java | 5 ++++ ...dBluetoothDetailsHeaderControllerTest.java | 28 +++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 54b6fbc0da2..c707365b150 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2002,6 +2002,11 @@ %1$s app will no longer connect to your %2$s Experimental. Improves audio quality. + + Battery + + Battery, charging + Forget device diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java index 02b8813c225..d8e834dfbf8 100644 --- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java +++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java @@ -626,6 +626,11 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont imageView.setLayoutParams(layoutParams); } else { imageView.setImageDrawable(createBtBatteryIcon(mContext, level, charging)); + imageView.setContentDescription( + mContext.getString( + charging + ? R.string.device_details_battery_charging + : R.string.device_details_battery)); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(layoutParams); diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java index db8c862342f..fc1df5a0f69 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java @@ -329,11 +329,16 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { 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), - R.drawable.ic_battery_alert_24dp); + assertBatteryIcon( + mLayoutPreference.findViewById(R.id.layout_left), + R.drawable.ic_battery_alert_24dp, + false); + assertBatteryIcon( + mLayoutPreference.findViewById(R.id.layout_right), /* resId= */ -1, true); + assertBatteryIcon( + mLayoutPreference.findViewById(R.id.layout_middle), + R.drawable.ic_battery_alert_24dp, + false); } @Test @@ -546,10 +551,15 @@ public class AdvancedBluetoothDetailsHeaderControllerTest { } } - private void assertBatteryIcon(LinearLayout linearLayout, int resId) { + private void assertBatteryIcon(LinearLayout linearLayout, int resId, boolean charging) { final ImageView imageView = linearLayout.findViewById(R.id.bt_battery_icon); - assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()) - .isEqualTo(resId); + if (charging) { + assertThat(imageView.getContentDescription().toString()) + .isEqualTo(mContext.getString(R.string.device_details_battery_charging)); + } else { + assertThat(imageView.getContentDescription().toString()) + .isEqualTo(mContext.getString(R.string.device_details_battery)); + } + assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()).isEqualTo(resId); } - }