Merge "Fix a11y label for LE Audio Battery" into tm-dev
diff --git a/res/layout/le_audio_bt_entity_header.xml b/res/layout/le_audio_bt_entity_header.xml
index 6e2a1e8..a05d707 100644
--- a/res/layout/le_audio_bt_entity_header.xml
+++ b/res/layout/le_audio_bt_entity_header.xml
@@ -61,75 +61,91 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
- android:orientation="horizontal">
+ android:orientation="vertical">
<LinearLayout
- android:layout_width="wrap_content"
+ android:id="@+id/bt_battery_case"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/le_bluetooth_battery_start_margin"
- android:orientation="vertical">
+ android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:orientation="horizontal"
+ android:visibility="gone"
+ android:focusable="true">
<TextView
- android:id="@+id/bt_battery_case_title"
style="@style/TextAppearance.EntityHeaderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:layout_weight="1"
android:gravity="start|center_vertical"
android:ellipsize="end"
android:textDirection="locale"
android:text="@string/bluetooth_middle_name"
- android:textSize="@dimen/advanced_bluetooth_header_title_text_size"
- android:visibility="gone"/>
+ android:textSize="@dimen/advanced_bluetooth_header_title_text_size"/>
<TextView
- android:id="@+id/bt_battery_left_title"
+ android:id="@+id/bt_battery_case_summary"
+ style="@style/TextAppearance.EntityHeaderSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/le_bluetooth_summary_start_margin"
+ android:minWidth="@dimen/le_bluetooth_summary_min_width"
+ android:padding="@dimen/le_bluetooth_summary_padding"
+ android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
+ </LinearLayout>
+ <LinearLayout
+ android:id="@+id/bt_battery_left"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/le_bluetooth_battery_start_margin"
+ android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:orientation="horizontal"
+ android:visibility="gone"
+ android:focusable="true">
+ <TextView
style="@style/TextAppearance.EntityHeaderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:layout_weight="1"
android:gravity="start|center_vertical"
android:ellipsize="end"
android:textDirection="locale"
android:text="@string/bluetooth_left_name"
android:textSize="@dimen/advanced_bluetooth_header_title_text_size"/>
<TextView
- android:id="@+id/bt_battery_right_title"
+ android:id="@+id/bt_battery_left_summary"
+ style="@style/TextAppearance.EntityHeaderSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/le_bluetooth_summary_start_margin"
+ android:minWidth="@dimen/le_bluetooth_summary_min_width"
+ android:padding="@dimen/le_bluetooth_summary_padding"
+ android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
+ </LinearLayout>
+ <LinearLayout
+ android:id="@+id/bt_battery_right"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/le_bluetooth_battery_start_margin"
+ android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:orientation="horizontal"
+ android:visibility="gone"
+ android:focusable="true">
+ <TextView
style="@style/TextAppearance.EntityHeaderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:layout_weight="1"
android:gravity="start|center_vertical"
android:ellipsize="end"
android:textDirection="locale"
android:text="@string/bluetooth_right_name"
android:textSize="@dimen/advanced_bluetooth_header_title_text_size"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="@dimen/le_bluetooth_summary_start_margin"
- android:orientation="vertical">
- <TextView
- android:id="@+id/bt_battery_case_summary"
- style="@style/TextAppearance.EntityHeaderSummary"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
- android:padding="@dimen/le_bluetooth_summary_padding"
- android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"
- android:visibility="gone"/>
- <TextView
- android:id="@+id/bt_battery_left_summary"
- style="@style/TextAppearance.EntityHeaderSummary"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
- android:padding="@dimen/le_bluetooth_summary_padding"
- android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
<TextView
android:id="@+id/bt_battery_right_summary"
style="@style/TextAppearance.EntityHeaderSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
+ android:layout_marginStart="@dimen/le_bluetooth_summary_start_margin"
+ android:minWidth="@dimen/le_bluetooth_summary_min_width"
android:padding="@dimen/le_bluetooth_summary_padding"
android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f11cee5..1582d21 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -415,6 +415,7 @@
<dimen name="le_bluetooth_summary_drawable_padding">6dp</dimen>
<dimen name="le_bluetooth_summary_start_margin">20dp</dimen>
<dimen name="le_bluetooth_summary_padding">1.5dp</dimen>
+ <dimen name="le_bluetooth_summary_min_width">64dp</dimen>
<!-- Header layout of bluetooth find broadcast page -->
<dimen name="bluetooth_find_broadcast_button_one_size">220dp</dimen>
diff --git a/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
index 7b74f77..188770b 100644
--- a/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/LeAudioBluetoothDetailsHeaderController.java
@@ -198,38 +198,25 @@
return drawable;
}
- private int getBatteryTitleResource(int deviceId) {
- if (deviceId == LEFT_DEVICE_ID) {
- return R.id.bt_battery_left_title;
- }
- if (deviceId == RIGHT_DEVICE_ID) {
- return R.id.bt_battery_right_title;
- }
- Log.d(TAG, "No resource id. The deviceId is " + deviceId);
- return INVALID_RESOURCE_ID;
- }
-
- private int getBatterySummaryResource(int deviceId) {
- if (deviceId == LEFT_DEVICE_ID) {
+ private int getBatterySummaryResource(int containerId) {
+ if (containerId == R.id.bt_battery_case) {
+ return R.id.bt_battery_case_summary;
+ } else if (containerId == R.id.bt_battery_left) {
return R.id.bt_battery_left_summary;
- }
- if (deviceId == RIGHT_DEVICE_ID) {
+ } else if (containerId == R.id.bt_battery_right) {
return R.id.bt_battery_right_summary;
}
- Log.d(TAG, "No resource id. The deviceId is " + deviceId);
+ Log.d(TAG, "No summary resource id. The containerId is " + containerId);
return INVALID_RESOURCE_ID;
}
private void hideAllOfBatteryLayouts() {
// hide the case
- updateBatteryLayout(R.id.bt_battery_case_title, R.id.bt_battery_case_summary,
- BluetoothUtils.META_INT_ERROR);
+ updateBatteryLayout(R.id.bt_battery_case, BluetoothUtils.META_INT_ERROR);
// hide the left
- updateBatteryLayout(R.id.bt_battery_left_title, R.id.bt_battery_left_summary,
- BluetoothUtils.META_INT_ERROR);
+ updateBatteryLayout(R.id.bt_battery_left, BluetoothUtils.META_INT_ERROR);
// hide the right
- updateBatteryLayout(R.id.bt_battery_right_title, R.id.bt_battery_right_summary,
- BluetoothUtils.META_INT_ERROR);
+ updateBatteryLayout(R.id.bt_battery_right, BluetoothUtils.META_INT_ERROR);
}
private List<CachedBluetoothDevice> getAllOfLeAudioDevices() {
@@ -285,36 +272,36 @@
summary.setText(mCachedDevice.getConnectionSummary());
}
} else if (isLeft) {
- updateBatteryLayout(getBatteryTitleResource(LEFT_DEVICE_ID),
- getBatterySummaryResource(LEFT_DEVICE_ID), cachedDevice.getBatteryLevel());
+ updateBatteryLayout(R.id.bt_battery_left, cachedDevice.getBatteryLevel());
} else if (isRight) {
- updateBatteryLayout(getBatteryTitleResource(RIGHT_DEVICE_ID),
- getBatterySummaryResource(RIGHT_DEVICE_ID), cachedDevice.getBatteryLevel());
+ updateBatteryLayout(R.id.bt_battery_right, cachedDevice.getBatteryLevel());
} else {
Log.d(TAG, "The device id is other Audio Location. Do nothing.");
}
}
}
- private void updateBatteryLayout(int titleResId, int summaryResId, int batteryLevel) {
- final TextView batteryTitleView = mLayoutPreference.findViewById(titleResId);
- final TextView batterySummaryView = mLayoutPreference.findViewById(summaryResId);
- if (batteryTitleView == null || batterySummaryView == null) {
- Log.e(TAG, "updateBatteryLayout: No TextView");
+ private void updateBatteryLayout(int resId, int batteryLevel) {
+ final View batteryView = mLayoutPreference.findViewById(resId);
+ if (batteryView == null) {
+ Log.e(TAG, "updateBatteryLayout: No View");
return;
}
if (batteryLevel != BluetoothUtils.META_INT_ERROR) {
- batteryTitleView.setVisibility(View.VISIBLE);
- batterySummaryView.setVisibility(View.VISIBLE);
- batterySummaryView.setText(
- com.android.settings.Utils.formatPercentage(batteryLevel));
+ batteryView.setVisibility(View.VISIBLE);
+ final TextView batterySummaryView =
+ batteryView.requireViewById(getBatterySummaryResource(resId));
+ final String batteryLevelPercentageString =
+ com.android.settings.Utils.formatPercentage(batteryLevel);
+ batterySummaryView.setText(batteryLevelPercentageString);
+ batterySummaryView.setContentDescription(mContext.getString(
+ R.string.bluetooth_battery_level, batteryLevelPercentageString));
batterySummaryView.setCompoundDrawablesRelativeWithIntrinsicBounds(
createBtBatteryIcon(mContext, batteryLevel), /* top */ null,
/* end */ null, /* bottom */ null);
} else {
Log.d(TAG, "updateBatteryLayout: Hide it if it doesn't have battery information.");
- batteryTitleView.setVisibility(View.GONE);
- batterySummaryView.setVisibility(View.GONE);
+ batteryView.setVisibility(View.GONE);
}
}