Avoid duplicate accessibility announcement upon switching to -1st page

Since -1st window already has accessible description, no need to
announce "Page X of Y" for it.

Bug: 74210311
Test: Manual
Change-Id: I5cbfd763778b5f7049be732a750df4501b5419e0
This commit is contained in:
Vadim Tryshev
2018-04-04 14:45:21 -07:00
parent ac6a6b6bf7
commit 2c430b34cb
2 changed files with 30 additions and 6 deletions

View File

@@ -424,6 +424,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return computeScrollHelper(true);
}
protected void announcePageForAccessibility() {
if (isAccessibilityEnabled(getContext())) {
// Notify the user when the page changes
announceForAccessibility(getCurrentPageDescription());
}
}
protected boolean computeScrollHelper(boolean shouldInvalidate) {
if (mScroller.computeScrollOffset()) {
// Don't bother scrolling if the page does not need to be moved
@@ -452,9 +459,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
pageEndTransition();
}
if (isAccessibilityEnabled(getContext())) {
// Notify the user when the page changes
announceForAccessibility(getCurrentPageDescription());
if (canAnnouncePageDescription()) {
announcePageForAccessibility();
}
}
return false;
@@ -1535,6 +1541,10 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return getCurrentPageDescription();
}
protected boolean canAnnouncePageDescription() {
return true;
}
protected String getCurrentPageDescription() {
return getContext().getString(R.string.default_scroll_format,
getNextPage() + 1, getChildCount());