Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca492009 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Fix a11y label for LE Audio Battery

Before fix, "Left" & "Right" are in the same LinearLayout, not grouped
with battery info.

After fix, "Left" & "100% battery" are grouped together.

Bug: 229042138
Test: manual test when Talkback enabled
Change-Id: Ieb35ef992f62040f14ed878515d63f6edb2559f6
parent b3db0000
Loading
Loading
Loading
Loading
+50 −34
Original line number Diff line number Diff line
@@ -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"
                style="@style/TextAppearance.EntityHeaderTitle"
                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: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"/>
            android:orientation="horizontal"
            android:visibility="gone"
            android:focusable="true">
            <TextView
                android:id="@+id/bt_battery_right_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_right_name"
                android:text="@string/bluetooth_left_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"
                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: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"
                android:visibility="gone"/>
                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
                android:id="@+id/bt_battery_left_summary"
                style="@style/TextAppearance.EntityHeaderSummary"
                style="@style/TextAppearance.EntityHeaderTitle"
                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: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"/>
            <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>
+1 −0
Original line number Diff line number Diff line
@@ -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>
+24 −37
Original line number Diff line number Diff line
@@ -198,38 +198,25 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
        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 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
                    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);
        }
    }