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

Commit 776afc21 authored by Phil Weaver's avatar Phil Weaver
Browse files

Provide hint text to accessibility.

Bug: 30025621
Test: Adding CTS tests in linked CL.
Change-Id: Ib873352704a23c733a5eac36030a88fc55dc9b04
parent 0f10b2f1
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -44581,6 +44581,7 @@ package android.view.accessibility {
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public java.lang.CharSequence getHintText();
    method public int getInputType();
    method public android.view.accessibility.AccessibilityNodeInfo getLabelFor();
    method public android.view.accessibility.AccessibilityNodeInfo getLabeledBy();
@@ -44615,6 +44616,7 @@ package android.view.accessibility {
    method public boolean isPassword();
    method public boolean isScrollable();
    method public boolean isSelected();
    method public boolean isShowingHintText();
    method public boolean isVisibleToUser();
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View);
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View, int);
@@ -44648,6 +44650,7 @@ package android.view.accessibility {
    method public void setError(java.lang.CharSequence);
    method public void setFocusable(boolean);
    method public void setFocused(boolean);
    method public void setHintText(java.lang.CharSequence);
    method public void setImportantForAccessibility(boolean);
    method public void setInputType(int);
    method public void setLabelFor(android.view.View);
@@ -44666,6 +44669,7 @@ package android.view.accessibility {
    method public void setRangeInfo(android.view.accessibility.AccessibilityNodeInfo.RangeInfo);
    method public void setScrollable(boolean);
    method public void setSelected(boolean);
    method public void setShowingHintText(boolean);
    method public void setSource(android.view.View);
    method public void setSource(android.view.View, int);
    method public void setText(java.lang.CharSequence);
+4 −0
Original line number Diff line number Diff line
@@ -47747,6 +47747,7 @@ package android.view.accessibility {
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public java.lang.CharSequence getHintText();
    method public int getInputType();
    method public android.view.accessibility.AccessibilityNodeInfo getLabelFor();
    method public android.view.accessibility.AccessibilityNodeInfo getLabeledBy();
@@ -47781,6 +47782,7 @@ package android.view.accessibility {
    method public boolean isPassword();
    method public boolean isScrollable();
    method public boolean isSelected();
    method public boolean isShowingHintText();
    method public boolean isVisibleToUser();
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View);
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View, int);
@@ -47814,6 +47816,7 @@ package android.view.accessibility {
    method public void setError(java.lang.CharSequence);
    method public void setFocusable(boolean);
    method public void setFocused(boolean);
    method public void setHintText(java.lang.CharSequence);
    method public void setImportantForAccessibility(boolean);
    method public void setInputType(int);
    method public void setLabelFor(android.view.View);
@@ -47832,6 +47835,7 @@ package android.view.accessibility {
    method public void setRangeInfo(android.view.accessibility.AccessibilityNodeInfo.RangeInfo);
    method public void setScrollable(boolean);
    method public void setSelected(boolean);
    method public void setShowingHintText(boolean);
    method public void setSource(android.view.View);
    method public void setSource(android.view.View, int);
    method public void setText(java.lang.CharSequence);
+4 −0
Original line number Diff line number Diff line
@@ -44836,6 +44836,7 @@ package android.view.accessibility {
    method public int getDrawingOrder();
    method public java.lang.CharSequence getError();
    method public android.os.Bundle getExtras();
    method public java.lang.CharSequence getHintText();
    method public int getInputType();
    method public android.view.accessibility.AccessibilityNodeInfo getLabelFor();
    method public android.view.accessibility.AccessibilityNodeInfo getLabeledBy();
@@ -44870,6 +44871,7 @@ package android.view.accessibility {
    method public boolean isPassword();
    method public boolean isScrollable();
    method public boolean isSelected();
    method public boolean isShowingHintText();
    method public boolean isVisibleToUser();
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View);
    method public static android.view.accessibility.AccessibilityNodeInfo obtain(android.view.View, int);
@@ -44903,6 +44905,7 @@ package android.view.accessibility {
    method public void setError(java.lang.CharSequence);
    method public void setFocusable(boolean);
    method public void setFocused(boolean);
    method public void setHintText(java.lang.CharSequence);
    method public void setImportantForAccessibility(boolean);
    method public void setInputType(int);
    method public void setLabelFor(android.view.View);
@@ -44922,6 +44925,7 @@ package android.view.accessibility {
    method public void setRangeInfo(android.view.accessibility.AccessibilityNodeInfo.RangeInfo);
    method public void setScrollable(boolean);
    method public void setSelected(boolean);
    method public void setShowingHintText(boolean);
    method public void setSource(android.view.View);
    method public void setSource(android.view.View, int);
    method public void setText(java.lang.CharSequence);
+60 −0
Original line number Diff line number Diff line
@@ -543,6 +543,8 @@ public class AccessibilityNodeInfo implements Parcelable {

    private static final int BOOLEAN_PROPERTY_IMPORTANCE = 0x0040000;

    private static final int BOOLEAN_PROPERTY_IS_SHOWING_HINT = 0x0100000;

    /**
     * Bits that provide the id of a virtual descendant of a view.
     */
@@ -629,6 +631,7 @@ public class AccessibilityNodeInfo implements Parcelable {
    private CharSequence mPackageName;
    private CharSequence mClassName;
    private CharSequence mText;
    private CharSequence mHintText;
    private CharSequence mError;
    private CharSequence mContentDescription;
    private String mViewIdResourceName;
@@ -2159,6 +2162,33 @@ public class AccessibilityNodeInfo implements Parcelable {
        setBooleanProperty(BOOLEAN_PROPERTY_IMPORTANCE, important);
    }

    /**
     * Returns whether the node's text represents a hint for the user to enter text. It should only
     * be {@code true} if the node has editable text.
     *
     * @return {@code true} if the text in the node represents a hint to the user, {@code false}
     * otherwise.
     */
    public boolean isShowingHintText() {
        return getBooleanProperty(BOOLEAN_PROPERTY_IS_SHOWING_HINT);
    }

    /**
     * Sets whether the node's text represents a hint for the user to enter text. It should only
     * be {@code true} if the node has editable text.
     * <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 showingHintText {@code true} if the text in the node represents a hint to the user,
     * {@code false} otherwise.
     */
    public void setShowingHintText(boolean showingHintText) {
        setBooleanProperty(BOOLEAN_PROPERTY_IS_SHOWING_HINT, showingHintText);
    }

    /**
     * Gets the package this node comes from.
     *
@@ -2237,6 +2267,32 @@ public class AccessibilityNodeInfo implements Parcelable {
        mText = (text == null) ? null : text.subSequence(0, text.length());
    }

    /**
     * Gets the hint text of this node. Only applies to nodes where text can be entered.
     *
     * @return The hint text.
     */
    public CharSequence getHintText() {
        return mHintText;
    }

    /**
     * Sets the hint text of this node. Only applies to nodes where text can be entered.
     * <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 hintText The hint text for this mode.
     *
     * @throws IllegalStateException If called from an AccessibilityService.
     */
    public void setHintText(CharSequence hintText) {
        enforceNotSealed();
        mHintText = (hintText == null) ? null : hintText.subSequence(0, hintText.length());
    }

    /**
     * Sets the error text of this node.
     * <p>
@@ -2810,6 +2866,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        parcel.writeCharSequence(mPackageName);
        parcel.writeCharSequence(mClassName);
        parcel.writeCharSequence(mText);
        parcel.writeCharSequence(mHintText);
        parcel.writeCharSequence(mError);
        parcel.writeCharSequence(mContentDescription);
        parcel.writeString(mViewIdResourceName);
@@ -2884,6 +2941,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        mPackageName = other.mPackageName;
        mClassName = other.mClassName;
        mText = other.mText;
        mHintText = other.mHintText;
        mError = other.mError;
        mContentDescription = other.mContentDescription;
        mViewIdResourceName = other.mViewIdResourceName;
@@ -2987,6 +3045,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        mPackageName = parcel.readCharSequence();
        mClassName = parcel.readCharSequence();
        mText = parcel.readCharSequence();
        mHintText = parcel.readCharSequence();
        mError = parcel.readCharSequence();
        mContentDescription = parcel.readCharSequence();
        mViewIdResourceName = parcel.readString();
@@ -3058,6 +3117,7 @@ public class AccessibilityNodeInfo implements Parcelable {
        mPackageName = null;
        mClassName = null;
        mText = null;
        mHintText = null;
        mError = null;
        mContentDescription = null;
        mViewIdResourceName = null;
+2 −0
Original line number Diff line number Diff line
@@ -9509,6 +9509,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        final boolean isPassword = hasPasswordTransformationMethod();
        info.setPassword(isPassword);
        info.setText(getTextForAccessibility());
        info.setHintText(mHint);
        info.setShowingHintText(isShowingHint());

        if (mBufferType == BufferType.EDITABLE) {
            info.setEditable(true);