|
45 | 45 | import android.os.Parcelable; |
46 | 46 | import android.os.RemoteException; |
47 | 47 | import android.os.SystemClock; |
| 48 | +import android.text.TextUtils; |
48 | 49 | import android.util.AttributeSet; |
49 | 50 | import android.util.FloatProperty; |
50 | 51 | import android.util.LocaleUtil; |
@@ -1927,6 +1928,20 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal |
1927 | 1928 | */ |
1928 | 1929 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
1929 | 1930 |
|
| 1931 | + /** |
| 1932 | + * Find views that render the specified text. |
| 1933 | + * |
| 1934 | + * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 1935 | + */ |
| 1936 | + public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 1937 | + |
| 1938 | + /** |
| 1939 | + * Find find views that contain the specified content description. |
| 1940 | + * |
| 1941 | + * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 1942 | + */ |
| 1943 | + public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 1944 | + |
1930 | 1945 | /** |
1931 | 1946 | * Controls the over-scroll mode for this view. |
1932 | 1947 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
@@ -5132,12 +5147,28 @@ public void addFocusables(ArrayList<View> views, int direction, int focusableMod |
5132 | 5147 |
|
5133 | 5148 | /** |
5134 | 5149 | * Finds the Views that contain given text. The containment is case insensitive. |
5135 | | - * As View's text is considered any text content that View renders. |
| 5150 | + * The search is performed by either the text that the View renders or the content |
| 5151 | + * description that describes the view for accessibility purposes and the view does |
| 5152 | + * not render or both. Clients can specify how the search is to be performed via |
| 5153 | + * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5154 | + * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
5136 | 5155 | * |
5137 | 5156 | * @param outViews The output list of matching Views. |
5138 | | - * @param text The text to match against. |
| 5157 | + * @param searched The text to match against. |
| 5158 | + * |
| 5159 | + * @see #FIND_VIEWS_WITH_TEXT |
| 5160 | + * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5161 | + * @see #setContentDescription(CharSequence) |
5139 | 5162 | */ |
5140 | | - public void findViewsWithText(ArrayList<View> outViews, CharSequence text) { |
| 5163 | + public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
| 5164 | + if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 && !TextUtils.isEmpty(searched) |
| 5165 | + && !TextUtils.isEmpty(mContentDescription)) { |
| 5166 | + String searchedLowerCase = searched.toString().toLowerCase(); |
| 5167 | + String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5168 | + if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5169 | + outViews.add(this); |
| 5170 | + } |
| 5171 | + } |
5141 | 5172 | } |
5142 | 5173 |
|
5143 | 5174 | /** |
|
0 commit comments