Fix switch access for overview grid

- Removed overscroll checking in switch access, as overscroll isn't supported via snapToPage
- Don't show forward/backward action if no further scroll is possible
- When scrolling right in overveiw grid, snap to the next non-fully visible task
- When scrolling left in overview grid, snap to a position that next non-fully visible task is on the left of the screen

Fix: 204162346
Test: Use switch action in Workspace/Recents with and w/o RTL
Change-Id: I0d4f201edf2da543703e88420e6f3255fb2ba16f
This commit is contained in:
Alex Chau
2021-11-26 16:22:49 +00:00
parent 71b7d1537d
commit 9ead9ca226
2 changed files with 91 additions and 12 deletions
@@ -1039,6 +1039,17 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
}
}
public boolean isTaskViewFullyVisible(TaskView tv) {
if (showAsGrid()) {
int screenStart = mOrientationHandler.getPrimaryScroll(this);
int screenEnd = screenStart + mOrientationHandler.getMeasuredSize(this);
return isTaskViewFullyWithinBounds(tv, screenStart, screenEnd);
} else {
// For now, just check if it's the active task
return indexOfChild(tv) == getNextPage();
}
}
@Nullable
private TaskView getLastGridTaskView() {
return getLastGridTaskView(getTopRowIdArray(), getBottomRowIdArray());
@@ -1085,6 +1096,15 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
&& taskEnd <= end);
}
private boolean isTaskViewFullyWithinBounds(TaskView tv, int start, int end) {
int taskStart = mOrientationHandler.getChildStart(tv) + (int) tv.getOffsetAdjustment(
showAsFullscreen(), showAsGrid());
int taskSize = (int) (mOrientationHandler.getMeasuredSize(tv) * tv.getSizeAdjustment(
showAsFullscreen()));
int taskEnd = taskStart + taskSize;
return taskStart >= start && taskEnd <= end;
}
/**
* Returns true if the task is in expected scroll position.
*
@@ -4939,6 +4959,62 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
return mPipCornerRadius;
}
@Override
public boolean scrollLeft() {
if (!showAsGrid()) {
return super.scrollLeft();
}
int targetPage = getNextPage();
if (targetPage >= 0) {
// Find the next page that is not fully visible.
TaskView taskView = getTaskViewAt(targetPage);
while ((taskView == null || isTaskViewFullyVisible(taskView)) && targetPage - 1 >= 0) {
taskView = getTaskViewAt(--targetPage);
}
// Target a scroll where targetPage is on left of screen but still fully visible.
int lastTaskEnd = (mIsRtl
? mLastComputedGridSize.left
: mLastComputedGridSize.right)
+ (mIsRtl ? mPageSpacing : -mPageSpacing);
int normalTaskEnd = mIsRtl
? mLastComputedGridTaskSize.left
: mLastComputedGridTaskSize.right;
int targetScroll = getScrollForPage(targetPage) + normalTaskEnd - lastTaskEnd;
// Find a page that is close to targetScroll while not over it.
while (targetPage - 1 >= 0
&& (mIsRtl
? getScrollForPage(targetPage - 1) < targetScroll
: getScrollForPage(targetPage - 1) > targetScroll)) {
targetPage--;
}
snapToPage(targetPage);
return true;
}
return mAllowOverScroll;
}
@Override
public boolean scrollRight() {
if (!showAsGrid()) {
return super.scrollRight();
}
int targetPage = getNextPage();
if (targetPage < getChildCount()) {
// Find the next page that is not fully visible.
TaskView taskView = getTaskViewAt(targetPage);
while ((taskView != null && isTaskViewFullyVisible(taskView))
&& targetPage + 1 < getChildCount()) {
taskView = getTaskViewAt(++targetPage);
}
snapToPage(targetPage);
return true;
}
return mAllowOverScroll;
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);