Fix TYPE_VIEW_SCROLLED event in AsListView and ListView

We should always send TYPE_VIEW_SCROLLED event when scroll. This applies
to ACTION_SHOW_ON_SCREEN. And we also need the scroll event when the
first visible item and last visibile item don't change.

Fix: 147907655, 147282475

Test: tested b/147282475 is fixed (this bug is not related to
ACTION_SHOW_ON_SCREEN, it is the scroll forward action).

Change-Id: I2069dc3ee692042ff87867db9837e85ac1d8dd26
This commit is contained in:
yingleiw
2020-01-29 11:15:19 -08:00
parent 68fe9164d5
commit 9407e393f9
2 changed files with 8 additions and 22 deletions

View File

@@ -756,9 +756,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
*/
private ListItemAccessibilityDelegate mAccessibilityDelegate;
private int mLastAccessibilityScrollEventFromIndex;
private int mLastAccessibilityScrollEventToIndex;
/**
* Track the item count from the last time we handled a data change.
*/
@@ -1520,25 +1517,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these.
}
/** @hide */
@Override
public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
// Since this class calls onScrollChanged even if the mFirstPosition and the
// child count have not changed we will avoid sending duplicate accessibility
// events.
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
final int firstVisiblePosition = getFirstVisiblePosition();
final int lastVisiblePosition = getLastVisiblePosition();
if (mLastAccessibilityScrollEventFromIndex == firstVisiblePosition
&& mLastAccessibilityScrollEventToIndex == lastVisiblePosition) {
return;
} else {
mLastAccessibilityScrollEventFromIndex = firstVisiblePosition;
mLastAccessibilityScrollEventToIndex = lastVisiblePosition;
}
}
super.sendAccessibilityEventUnchecked(event);
}
/**
* A TYPE_VIEW_SCROLLED event should be sent whenever a scroll happens, even if the
* mFirstPosition and the child count have not changed.
*/
@Override
public CharSequence getAccessibilityClassName() {

View File

@@ -3255,6 +3255,9 @@ public class ListView extends AbsListView {
*/
@UnsupportedAppUsage
private void scrollListItemsBy(int amount) {
int oldX = mScrollX;
int oldY = mScrollY;
offsetChildrenTopAndBottom(amount);
final int listBottom = getHeight() - mListPadding.bottom;
@@ -3327,6 +3330,7 @@ public class ListView extends AbsListView {
recycleBin.fullyDetachScrapViews();
removeUnusedFixedViews(mHeaderViewInfos);
removeUnusedFixedViews(mFooterViewInfos);
onScrollChanged(mScrollX, mScrollY, oldX, oldY);
}
private View addViewAbove(View theView, int position) {