From 4e03f5910cf641e2610f4cbe3fc24d84c430d1e8 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Fri, 29 Jul 2011 22:17:14 -0700 Subject: Removing firing of spurious scroll accesibility events. 1. Adding a TextView to a layout fires an accessibility scroll event with mScrollX = 8144. Now TextView does not fire scroll events since they are not interesting for accessibility and also the implementation fires scroll to frequently - though correctly. 2. AbsListView was firing accessibility events for the same location. Here the caveat is that this class does not know its height and calls onScrollChange every time is scroll as seen by the user may have changed but for accessibility purposes we care for the start and end indices of visible views. The fix is to avoid sending access events with duplicate data. bug:5097467 Change-Id: I7bf11efd638ea3673843f1095a03f518e57cfe9d --- core/java/android/widget/AbsListView.java | 21 +++++++++++++++++++++ core/java/android/widget/TextView.java | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index cadf2aba0cec..9737a5a9bc07 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -628,6 +628,9 @@ public abstract class AbsListView extends AdapterView implements Te private int mGlowPaddingLeft; private int mGlowPaddingRight; + private int mLastAccessibilityScrollEventFromIndex; + private int mLastAccessibilityScrollEventToIndex; + /** * Interface definition for a callback to be invoked when the list or grid * has been scrolled. @@ -1264,6 +1267,24 @@ public abstract class AbsListView extends AdapterView implements Te info.setScrollable(true); } + @Override + public void sendAccessibilityEvent(int eventType) { + // Since this class calls onScrollChanged even if the mFirstPosition and the + // child count have not changed we will avoid sending duplicate accessibility + // events. + if (eventType == AccessibilityEvent.TYPE_VIEW_SCROLLED) { + final int lastPosition = mFirstPosition + getChildCount(); + if (mLastAccessibilityScrollEventFromIndex == mFirstPosition + && mLastAccessibilityScrollEventToIndex == lastPosition) { + return; + } else { + mLastAccessibilityScrollEventFromIndex = mFirstPosition; + mLastAccessibilityScrollEventToIndex = lastPosition; + } + } + super.sendAccessibilityEvent(eventType); + } + @Override public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 6dcae6d4c936..294f6bbecc49 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8441,6 +8441,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener info.setPassword(isPassword); } + @Override + public void sendAccessibilityEvent(int eventType) { + // Do not send scroll events since first they are not interesting for + // accessibility and second such events a generated too frequently. + // For details see the implementation of bringTextIntoView(). + if (eventType == AccessibilityEvent.TYPE_VIEW_SCROLLED) { + return; + } + super.sendAccessibilityEvent(eventType); + } + void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText, int fromIndex, int removedCount, int addedCount) { AccessibilityEvent event = -- cgit v1.2.3-59-g8ed1b