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

Commit d4a9b490 authored by Yinglei Wang's avatar Yinglei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add accessibility state API in platform"

parents 4dae6fbf 6189b8c2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -50449,6 +50449,7 @@ package android.view {
    method public final int getScrollY();
    method @android.view.ViewDebug.ExportedProperty(category="drawing") @ColorInt public int getSolidColor();
    method @LayoutRes public int getSourceLayoutResId();
    method @android.view.ViewDebug.ExportedProperty(category="accessibility") @Nullable public final CharSequence getStateDescription();
    method public android.animation.StateListAnimator getStateListAnimator();
    method protected int getSuggestedMinimumHeight();
    method protected int getSuggestedMinimumWidth();
@@ -50793,6 +50794,7 @@ package android.view {
    method public void setScrollbarFadingEnabled(boolean);
    method public void setSelected(boolean);
    method public void setSoundEffectsEnabled(boolean);
    method public void setStateDescription(@Nullable CharSequence);
    method public void setStateListAnimator(android.animation.StateListAnimator);
    method public void setSystemGestureExclusionRects(@NonNull java.util.List<android.graphics.Rect>);
    method public void setSystemUiVisibility(int);
@@ -52147,6 +52149,7 @@ package android.view.accessibility {
    field public static final int CONTENT_CHANGE_TYPE_PANE_APPEARED = 16; // 0x10
    field public static final int CONTENT_CHANGE_TYPE_PANE_DISAPPEARED = 32; // 0x20
    field public static final int CONTENT_CHANGE_TYPE_PANE_TITLE = 8; // 0x8
    field public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 64; // 0x40
    field public static final int CONTENT_CHANGE_TYPE_SUBTREE = 1; // 0x1
    field public static final int CONTENT_CHANGE_TYPE_TEXT = 2; // 0x2
    field public static final int CONTENT_CHANGE_TYPE_UNDEFINED = 0; // 0x0
@@ -52264,6 +52267,7 @@ package android.view.accessibility {
    method @Nullable public CharSequence getPaneTitle();
    method public android.view.accessibility.AccessibilityNodeInfo getParent();
    method public android.view.accessibility.AccessibilityNodeInfo.RangeInfo getRangeInfo();
    method @Nullable public CharSequence getStateDescription();
    method public CharSequence getText();
    method public int getTextSelectionEnd();
    method public int getTextSelectionStart();
@@ -52355,6 +52359,7 @@ package android.view.accessibility {
    method public void setShowingHintText(boolean);
    method public void setSource(android.view.View);
    method public void setSource(android.view.View, int);
    method public void setStateDescription(@Nullable CharSequence);
    method public void setText(CharSequence);
    method public void setTextEntryKey(boolean);
    method public void setTextSelection(int, int);
+52 −0
Original line number Diff line number Diff line
@@ -4355,6 +4355,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private Insets mLayoutInsets;
    /**
     * Briefly describes the state of the view and is primarily used for accessibility support.
     */
    private CharSequence mStateDescription;
    /**
     * Briefly describes the view and is primarily used for accessibility support.
     */
@@ -9925,6 +9930,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        info.setImportantForAccessibility(isImportantForAccessibility());
        info.setPackageName(mContext.getPackageName());
        info.setClassName(getAccessibilityClassName());
        info.setStateDescription(getStateDescription());
        info.setContentDescription(getContentDescription());
        info.setEnabled(isEnabled());
@@ -10296,6 +10302,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                : AccessibilityWindowInfo.UNDEFINED_WINDOW_ID;
    }
    /**
     * Returns the {@link View}'s state description.
     * <p>
     * <strong>Note:</strong> Do not override this method, as it will have no
     * effect on the state description presented to accessibility services.
     * You must call {@link #setStateDescription(CharSequence)} to modify the
     * state description.
     *
     * @return the state description
     * @see #setStateDescription(CharSequence)
     */
    @ViewDebug.ExportedProperty(category = "accessibility")
    public final @Nullable CharSequence getStateDescription() {
        return mStateDescription;
    }
    /**
     * Returns the {@link View}'s content description.
     * <p>
@@ -10314,6 +10336,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return mContentDescription;
    }
    /**
     * Sets the {@link View}'s state description.
     * <p>
     * A state description briefly describes the states of the view and is primarily used
     * for accessibility support to determine how the states of a view should be presented to
     * the user. It is a supplement to the boolean states (for example, checked/unchecked) and
     * it is used for customized state description (for example, "wifi, connected, three bars").
     * State description changes frequently while content description should change less often.
     *
     * @param stateDescription The state description.
     * @see #getStateDescription()
     */
    @RemotableViewMethod
    public void setStateDescription(@Nullable CharSequence stateDescription) {
        if (mStateDescription == null) {
            if (stateDescription == null) {
                return;
            }
        } else if (mStateDescription.equals(stateDescription)) {
            return;
        }
        mStateDescription = stateDescription;
        if (!TextUtils.isEmpty(stateDescription)
                && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
        }
        notifyViewAccessibilityStateChangedIfNeeded(
                AccessibilityEvent.CONTENT_CHANGE_TYPE_STATE_DESCRIPTION);
    }
    /**
     * Sets the {@link View}'s content description.
     * <p>
+1 −0
Original line number Diff line number Diff line
@@ -408,6 +408,7 @@ public interface ViewParent {
     *            or more of:
     *            <ul>
     *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
     *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_STATE_DESCRIPTION}
     *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_SUBTREE}
     *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_TEXT}
     *            <li>{@link AccessibilityEvent#CONTENT_CHANGE_TYPE_UNDEFINED}
+11 −0
Original line number Diff line number Diff line
@@ -601,6 +601,13 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
     */
    public static final int CONTENT_CHANGE_TYPE_PANE_DISAPPEARED = 0x00000020;

    /**
     * Change type for {@link #TYPE_WINDOW_CONTENT_CHANGED} event:
     * state description of the node as returned by
     * {@link AccessibilityNodeInfo#getStateDescription} changed.
     */
    public static final int CONTENT_CHANGE_TYPE_STATE_DESCRIPTION = 0x00000040;

    /**
     * Change type for {@link #TYPE_WINDOWS_CHANGED} event:
     * The window was added.
@@ -696,6 +703,7 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
                    CONTENT_CHANGE_TYPE_SUBTREE,
                    CONTENT_CHANGE_TYPE_TEXT,
                    CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION,
                    CONTENT_CHANGE_TYPE_STATE_DESCRIPTION,
                    CONTENT_CHANGE_TYPE_PANE_TITLE,
                    CONTENT_CHANGE_TYPE_PANE_APPEARED,
                    CONTENT_CHANGE_TYPE_PANE_DISAPPEARED
@@ -885,6 +893,7 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
     * @return The bit mask of change types. One or more of:
     *         <ul>
     *         <li>{@link #CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION}
     *         <li>{@link #CONTENT_CHANGE_TYPE_STATE_DESCRIPTION}
     *         <li>{@link #CONTENT_CHANGE_TYPE_SUBTREE}
     *         <li>{@link #CONTENT_CHANGE_TYPE_TEXT}
     *         <li>{@link #CONTENT_CHANGE_TYPE_PANE_TITLE}
@@ -906,6 +915,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
        switch (type) {
            case CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION:
                return "CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION";
            case CONTENT_CHANGE_TYPE_STATE_DESCRIPTION:
                return "CONTENT_CHANGE_TYPE_STATE_DESCRIPTION";
            case CONTENT_CHANGE_TYPE_SUBTREE: return "CONTENT_CHANGE_TYPE_SUBTREE";
            case CONTENT_CHANGE_TYPE_TEXT: return "CONTENT_CHANGE_TYPE_TEXT";
            case CONTENT_CHANGE_TYPE_PANE_TITLE: return "CONTENT_CHANGE_TYPE_PANE_TITLE";
+37 −0
Original line number Diff line number Diff line
@@ -744,6 +744,7 @@ public class AccessibilityNodeInfo implements Parcelable {
    private CharSequence mHintText;
    private CharSequence mError;
    private CharSequence mPaneTitle;
    private CharSequence mStateDescription;
    private CharSequence mContentDescription;
    private CharSequence mTooltipText;
    private String mViewIdResourceName;
@@ -2722,6 +2723,15 @@ public class AccessibilityNodeInfo implements Parcelable {
        return mError;
    }

    /**
     * Get the state description of this node.
     *
     * @return the state description
     */
    public @Nullable CharSequence getStateDescription() {
        return mStateDescription;
    }

    /**
     * Gets the content description of this node.
     *
@@ -2731,6 +2741,25 @@ public class AccessibilityNodeInfo implements Parcelable {
        return mContentDescription;
    }


    /**
     * Sets the state description of this node.
     * <p>
     *   <strong>Note:</strong> Cannot be called from an
     *   {@link android.accessibilityservice.AccessibilityService}.
     *   This class is made immutable before being delivered to an AccessibilityService.
     * </p>
     *
     * @param stateDescription the state description of this node.
     *
     * @throws IllegalStateException If called from an AccessibilityService.
     */
    public void setStateDescription(@Nullable CharSequence stateDescription) {
        enforceNotSealed();
        mStateDescription = (stateDescription == null) ? null
                : stateDescription.subSequence(0, stateDescription.length());
    }

    /**
     * Sets the content description of this node.
     * <p>
@@ -3373,6 +3402,10 @@ public class AccessibilityNodeInfo implements Parcelable {
        fieldIndex++;
        if (!Objects.equals(mError, DEFAULT.mError)) nonDefaultFields |= bitAt(fieldIndex);
        fieldIndex++;
        if (!Objects.equals(mStateDescription, DEFAULT.mStateDescription)) {
            nonDefaultFields |= bitAt(fieldIndex);
        }
        fieldIndex++;
        if (!Objects.equals(mContentDescription, DEFAULT.mContentDescription)) {
            nonDefaultFields |= bitAt(fieldIndex);
        }
@@ -3505,6 +3538,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mText);
        if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mHintText);
        if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mError);
        if (isBitSet(nonDefaultFields, fieldIndex++)) parcel.writeCharSequence(mStateDescription);
        if (isBitSet(nonDefaultFields, fieldIndex++)) {
            parcel.writeCharSequence(mContentDescription);
        }
@@ -3582,6 +3616,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        mOriginalText = other.mOriginalText;
        mHintText = other.mHintText;
        mError = other.mError;
        mStateDescription = other.mStateDescription;
        mContentDescription = other.mContentDescription;
        mPaneTitle = other.mPaneTitle;
        mTooltipText = other.mTooltipText;
@@ -3706,6 +3741,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        if (isBitSet(nonDefaultFields, fieldIndex++)) mText = parcel.readCharSequence();
        if (isBitSet(nonDefaultFields, fieldIndex++)) mHintText = parcel.readCharSequence();
        if (isBitSet(nonDefaultFields, fieldIndex++)) mError = parcel.readCharSequence();
        if (isBitSet(nonDefaultFields, fieldIndex++)) mStateDescription = parcel.readCharSequence();
        if (isBitSet(nonDefaultFields, fieldIndex++)) {
            mContentDescription = parcel.readCharSequence();
        }
@@ -4004,6 +4040,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        builder.append("; text: ").append(mText);
        builder.append("; error: ").append(mError);
        builder.append("; maxTextLength: ").append(mMaxTextLength);
        builder.append("; stateDescription: ").append(mStateDescription);
        builder.append("; contentDescription: ").append(mContentDescription);
        builder.append("; tooltipText: ").append(mTooltipText);
        builder.append("; viewIdResName: ").append(mViewIdResourceName);
Loading