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

Commit ea515aea authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Update the public APIs for finding views by text to optionally use content description.

1. Added flags to the search method to specify whether to match text or
   content description or both.

2. Added test case for the seach by content description.

3. Updated the code in AccessibilityManager service to reflect the latest
   changes there so test automation service works - this is the fake
   service used for UI automation.

Change-Id: I14a6779a920ff0430e78947ea5aaf876c2e66076
parent b07f6e09
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -22920,7 +22920,7 @@ package android.view {
    method public android.view.View findFocus();
    method public final android.view.View findViewById(int);
    method public final android.view.View findViewWithTag(java.lang.Object);
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence);
    method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence, int);
    method protected boolean fitSystemWindows(android.graphics.Rect);
    method public boolean fitsSystemWindows();
    method public android.view.View focusSearch(int);
@@ -23249,6 +23249,8 @@ package android.view {
    field protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
    field protected static final int[] ENABLED_STATE_SET;
    field protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET;
    field public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 2; // 0x2
    field public static final int FIND_VIEWS_WITH_TEXT = 1; // 0x1
    field public static final int FOCUSABLES_ALL = 0; // 0x0
    field public static final int FOCUSABLES_TOUCH_MODE = 1; // 0x1
    field protected static final int[] FOCUSED_SELECTED_STATE_SET;
+34 −3
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.LocaleUtil;
@@ -1927,6 +1928,20 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     */
    public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF;
    /**
     * Find views that render the specified text.
     *
     * @see #findViewsWithText(ArrayList, CharSequence, int)
     */
    public static final int FIND_VIEWS_WITH_TEXT = 0x00000001;
    /**
     * Find find views that contain the specified content description.
     *
     * @see #findViewsWithText(ArrayList, CharSequence, int)
     */
    public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002;
    /**
     * Controls the over-scroll mode for this view.
     * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)},
@@ -5132,12 +5147,28 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
    /**
     * Finds the Views that contain given text. The containment is case insensitive.
     * As View's text is considered any text content that View renders.
     * The search is performed by either the text that the View renders or the content
     * description that describes the view for accessibility purposes and the view does
     * not render or both. Clients can specify how the search is to be performed via
     * passing the {@link #FIND_VIEWS_WITH_TEXT} and
     * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags.
     *
     * @param outViews The output list of matching Views.
     * @param text The text to match against.
     * @param searched The text to match against.
     * 
     * @see #FIND_VIEWS_WITH_TEXT
     * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION
     * @see #setContentDescription(CharSequence)
     */
    public void findViewsWithText(ArrayList<View> outViews, CharSequence text) {
    public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) {
        if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 && !TextUtils.isEmpty(searched)
                && !TextUtils.isEmpty(mContentDescription)) {
            String searchedLowerCase = searched.toString().toLowerCase();
            String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase();
            if (contentDescriptionLowerCase.contains(searchedLowerCase)) {
                outViews.add(this);
            }
        }
    }
    /**
+5 −3
Original line number Diff line number Diff line
@@ -802,13 +802,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
    }

    @Override
    public void findViewsWithText(ArrayList<View> outViews, CharSequence text) {
    public void findViewsWithText(ArrayList<View> outViews, CharSequence text, int flags) {
        super.findViewsWithText(outViews, text, flags);
        final int childrenCount = mChildrenCount;
        final View[] children = mChildren;
        for (int i = 0; i < childrenCount; i++) {
            View child = children[i];
            if ((child.mPrivateFlags & IS_ROOT_NAMESPACE) == 0) {
                child.findViewsWithText(outViews, text);
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE
                    && (child.mPrivateFlags & IS_ROOT_NAMESPACE) == 0) {
                child.findViewsWithText(outViews, text, flags);
            }
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -4661,7 +4661,8 @@ public final class ViewRootImpl extends Handler implements ViewParent,
                    return;
                }

                root.findViewsWithText(foundViews, text);
                root.findViewsWithText(foundViews, text, View.FIND_VIEWS_WITH_TEXT
                        | View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
                if (foundViews.isEmpty()) {
                    return;
                }
+1 −0
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ public class AccessibilityNodeInfo implements Parcelable {
     * Finds {@link AccessibilityNodeInfo}s by text. The match is case
     * insensitive containment. The search is relative to this info i.e.
     * this info is the root of the traversed tree.
     *
     * <p>
     *   <strong>Note:</strong> It is a client responsibility to recycle the
     *     received info by calling {@link AccessibilityNodeInfo#recycle()}
Loading