Merge "Fix launcher navigation issue when using a controller" into sc-dev am: 45e72a1ed3 am: 4d9953d5e8

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14425542

Change-Id: Ie0ed78e783db477c09b0146ed6c4cf09c85b4706
This commit is contained in:
András Klöczl
2021-05-11 10:45:13 +00:00
committed by Automerger Merge Worker
+21 -6
View File
@@ -833,18 +833,25 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
return;
}
// Add the current page's views as focusable and the next possible page's too. If the
// last focus change action was left then the left neighbour's views will be added, and
// if it was right then the right neighbour's views will be added.
// Unfortunately mCurrentPage can be outdated if there were multiple control actions in a
// short period of time, but mNextPage is up to date because it is always updated by
// method snapToPage.
int nextPage = getNextPage();
// XXX-RTL: This will be fixed in a future CL
if (mCurrentPage >= 0 && mCurrentPage < getPageCount()) {
getPageAt(mCurrentPage).addFocusables(views, direction, focusableMode);
if (nextPage >= 0 && nextPage < getPageCount()) {
getPageAt(nextPage).addFocusables(views, direction, focusableMode);
}
if (direction == View.FOCUS_LEFT) {
if (mCurrentPage > 0) {
int nextPage = validateNewPage(mCurrentPage - 1);
if (nextPage > 0) {
nextPage = validateNewPage(nextPage - 1);
getPageAt(nextPage).addFocusables(views, direction, focusableMode);
}
} else if (direction == View.FOCUS_RIGHT) {
if (mCurrentPage < getPageCount() - 1) {
int nextPage = validateNewPage(mCurrentPage + 1);
if (nextPage < getPageCount() - 1) {
nextPage = validateNewPage(nextPage + 1);
getPageAt(nextPage).addFocusables(views, direction, focusableMode);
}
}
@@ -1414,6 +1421,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
@Override
public void requestChildFocus(View child, View focused) {
super.requestChildFocus(child, focused);
// In case the device is controlled by a controller, mCurrentPage isn't updated properly
// which results in incorrect navigation
int nextPage = getNextPage();
if (nextPage != mCurrentPage) {
setCurrentPage(nextPage);
}
int page = indexToPage(indexOfChild(child));
if (page >= 0 && page != getCurrentPage() && !isInTouchMode()) {
snapToPage(page);