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

Commit 1f45b58f authored by yingleiw's avatar yingleiw
Browse files

Use event text for partial accessibility state change in quicksettings

For the accessibility state description change event, if only part of
the state description is changed, we can put the changed part into event
text so that accessibility service knows the changed part.

Test: tested with the wifi tile and blooth tile. When state changes in
the on state, only the changed part is announced in talkbacki when the
focus is on the tile. The "on" state is not announced repeatedly when the
tile remains in the on state. All other behaviors are the same.

Change-Id: I05ebe806e7887ba3d0496b3819fac2a7184813cc
parent ddf7bf12
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -605,7 +605,10 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
    /**
     * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
     * state description of the node as returned by
     * {@link AccessibilityNodeInfo#getStateDescription} changed.
     * {@link AccessibilityNodeInfo#getStateDescription} changed. If part of the state description
     * changes, the changed part can be put into event text. For example, if state description
     * changed from "on, wifi signal full" to "on, wifi three bars", "wifi three bars" can be put
     * into the event text.
     */
    public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 0x00000040;

+17 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
 */
package com.android.systemui.qs.tileimpl;

import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_STATE_DESCRIPTION;

import static com.android.systemui.qs.tileimpl.QSIconViewImpl.QS_ANIM_LENGTH;

import android.animation.ValueAnimator;
@@ -73,6 +75,10 @@ public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView {
    private int mCircleColor;
    private int mBgSize;

    private static final int INVALID = -1;
    private CharSequence mStateDescriptionDeltas = null;
    private CharSequence mLastStateDescription;
    private int mLastState = INVALID;

    public QSTileBaseView(Context context, QSIconView icon) {
        this(context, icon, false);
@@ -250,8 +256,14 @@ public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView {
        if (!TextUtils.isEmpty(state.stateDescription)) {
            stateDescription.append(", ");
            stateDescription.append(state.stateDescription);
            if (mLastState != INVALID && state.state == mLastState
                    && !state.stateDescription.equals(mLastStateDescription)) {
                mStateDescriptionDeltas = state.stateDescription;
            }
        }
        setStateDescription(stateDescription.toString());
        mLastState = state.state;
        mLastStateDescription = state.stateDescription;

        mAccessibilityClass =
                state.state == Tile.STATE_UNAVAILABLE ? null : state.expandedAccessibilityClassName;
@@ -314,6 +326,11 @@ public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView {
        if (!TextUtils.isEmpty(mAccessibilityClass)) {
            event.setClassName(mAccessibilityClass);
        }
        if (event.getContentChangeTypes() == CONTENT_CHANGE_TYPE_STATE_DESCRIPTION
                && mStateDescriptionDeltas != null) {
            event.getText().add(mStateDescriptionDeltas);
            mStateDescriptionDeltas = null;
        }
    }

    @Override
+2 −5
Original line number Diff line number Diff line
@@ -134,7 +134,8 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
        state.label = mContext.getString(R.string.quick_settings_bluetooth_label);
        state.secondaryLabel = TextUtils.emptyIfNull(
                getSecondaryLabel(enabled, connecting, connected, state.isTransient));
        state.contentDescription = state.label;
        state.contentDescription = mContext.getString(
                R.string.accessibility_quick_settings_bluetooth);
        state.stateDescription = "";
        if (enabled) {
            if (connected) {
@@ -152,15 +153,11 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
            } else {
                state.icon =
                        ResourceIcon.get(com.android.internal.R.drawable.ic_qs_bluetooth);
                state.contentDescription = mContext.getString(
                        R.string.accessibility_quick_settings_bluetooth);
                state.stateDescription = mContext.getString(R.string.accessibility_not_connected);
            }
            state.state = Tile.STATE_ACTIVE;
        } else {
            state.icon = ResourceIcon.get(com.android.internal.R.drawable.ic_qs_bluetooth);
            state.contentDescription = mContext.getString(
                    R.string.accessibility_quick_settings_bluetooth);
            state.state = Tile.STATE_INACTIVE;
        }