Skip to content

Commit 0d607fb

Browse files
guang-googleAndroid (Google) Code Review
authored andcommitted
accessibility bug fix in NumberPicker
* moved View#isVisibleToUser to protected with @hide * added a new View#isVisibleToUser(Rect), so that a portion of the view can be tested for visibility * NumberPicker will report its concrete class name * code to append virtual children was at wrong place * boundInScreen for increment and decrement buttons are reported wrong Change-Id: Ic5d644b3e1efa15b1f0537907c8cdd4ce43a97c1
1 parent 15e8439 commit 0d607fb

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

core/java/android/view/View.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
666666
protected static final String VIEW_LOG_TAG = "View";
667667

668668
/**
669-
* When set to true, apps will draw debugging information about their layouts.
669+
* When set to true, apps will draw debugging information about their layouts.
670670
*
671671
* @hide
672672
*/
@@ -4801,17 +4801,46 @@ void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
48014801
* entirely by its predecessors, and has an alpha greater than zero.
48024802
*
48034803
* @return Whether the view is visible on the screen.
4804+
*
4805+
* @hide
48044806
*/
4805-
private boolean isVisibleToUser() {
4807+
protected boolean isVisibleToUser() {
4808+
return isVisibleToUser(null);
4809+
}
4810+
4811+
/**
4812+
* Computes whether the given portion of this view is visible to the user. Such a view is
4813+
* attached, visible, all its predecessors are visible, has an alpha greater than zero, and
4814+
* the specified portion is not clipped entirely by its predecessors.
4815+
*
4816+
* @param boundInView the portion of the view to test; coordinates should be relative; may be
4817+
* <code>null</code>, and the entire view will be tested in this case.
4818+
* When <code>true</code> is returned by the function, the actual visible
4819+
* region will be stored in this parameter; that is, if boundInView is fully
4820+
* contained within the view, no modification will be made, otherwise regions
4821+
* outside of the visible area of the view will be clipped.
4822+
*
4823+
* @return Whether the specified portion of the view is visible on the screen.
4824+
*
4825+
* @hide
4826+
*/
4827+
protected boolean isVisibleToUser(Rect boundInView) {
4828+
Rect visibleRect = mAttachInfo.mTmpInvalRect;
4829+
Point offset = mAttachInfo.mPoint;
48064830
// The first two checks are made also made by isShown() which
48074831
// however traverses the tree up to the parent to catch that.
48084832
// Therefore, we do some fail fast check to minimize the up
48094833
// tree traversal.
4810-
return (mAttachInfo != null
4811-
&& mAttachInfo.mWindowVisibility == View.VISIBLE
4812-
&& getAlpha() > 0
4813-
&& isShown()
4814-
&& getGlobalVisibleRect(mAttachInfo.mTmpInvalRect));
4834+
boolean isVisible = mAttachInfo != null
4835+
&& mAttachInfo.mWindowVisibility == View.VISIBLE
4836+
&& getAlpha() > 0
4837+
&& isShown()
4838+
&& getGlobalVisibleRect(visibleRect, offset);
4839+
if (isVisible && boundInView != null) {
4840+
visibleRect.offset(-offset.x, -offset.y);
4841+
isVisible &= boundInView.intersect(visibleRect);
4842+
}
4843+
return isVisible;
48154844
}
48164845

48174846
/**

core/java/android/widget/NumberPicker.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,20 +2239,17 @@ private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int vi
22392239
info.setPackageName(mContext.getPackageName());
22402240
info.setSource(NumberPicker.this, virtualViewId);
22412241
info.setParent(NumberPicker.this);
2242-
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
2243-
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
2244-
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
22452242
info.setText(text);
22462243
info.setClickable(true);
22472244
info.setLongClickable(true);
22482245
info.setEnabled(NumberPicker.this.isEnabled());
22492246
Rect boundsInParent = mTempRect;
22502247
boundsInParent.set(left, top, right, bottom);
2248+
info.setVisibleToUser(isVisibleToUser(boundsInParent));
22512249
info.setBoundsInParent(boundsInParent);
22522250
Rect boundsInScreen = boundsInParent;
22532251
int[] locationOnScreen = mTempArray;
22542252
getLocationOnScreen(locationOnScreen);
2255-
boundsInScreen.offsetTo(0, 0);
22562253
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
22572254
info.setBoundsInScreen(boundsInScreen);
22582255
return info;
@@ -2261,19 +2258,22 @@ private AccessibilityNodeInfo createAccessibilityNodeInfoForVirtualButton(int vi
22612258
private AccessibilityNodeInfo createAccessibilityNodeInfoForNumberPicker(int left, int top,
22622259
int right, int bottom) {
22632260
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
2264-
info.setClassName(Button.class.getName());
2261+
info.setClassName(NumberPicker.class.getName());
22652262
info.setPackageName(mContext.getPackageName());
22662263
info.setSource(NumberPicker.this);
2264+
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_DECREMENT);
2265+
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
2266+
info.addChild(NumberPicker.this, VIRTUAL_VIEW_ID_INCREMENT);
22672267
info.setParent((View) getParent());
22682268
info.setEnabled(NumberPicker.this.isEnabled());
22692269
info.setScrollable(true);
22702270
Rect boundsInParent = mTempRect;
22712271
boundsInParent.set(left, top, right, bottom);
22722272
info.setBoundsInParent(boundsInParent);
2273+
info.setVisibleToUser(isVisibleToUser());
22732274
Rect boundsInScreen = boundsInParent;
22742275
int[] locationOnScreen = mTempArray;
22752276
getLocationOnScreen(locationOnScreen);
2276-
boundsInScreen.offsetTo(0, 0);
22772277
boundsInScreen.offset(locationOnScreen[0], locationOnScreen[1]);
22782278
info.setBoundsInScreen(boundsInScreen);
22792279
return info;

0 commit comments

Comments
 (0)