Refactoring RecentsView to handle non-TaskViews

Change-Id: I0bc28ef670a1dad9a3912ca5360c9bab18afd4b2
This commit is contained in:
Sreyas
2019-08-13 16:43:21 -07:00
parent d61f73d935
commit 78010c1958
9 changed files with 136 additions and 70 deletions
@@ -19,7 +19,6 @@ import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Launcher; import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.AllAppsTransitionController; import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.LayoutUtils;
@@ -69,8 +68,16 @@ public class BackgroundAppState extends OverviewState {
if (taskCount == 0) { if (taskCount == 0) {
return super.getOverviewScaleAndTranslation(launcher); return super.getOverviewScaleAndTranslation(launcher);
} }
TaskView dummyTask = recentsView.getTaskViewAt(Utilities.boundToRange( TaskView dummyTask;
recentsView.getCurrentPage(), 0, taskCount - 1)); if (recentsView.getCurrentPage() >= 0) {
if (recentsView.getCurrentPage() <= taskCount - 1) {
dummyTask = recentsView.getCurrentPageTaskView();
} else {
dummyTask = recentsView.getTaskViewAt(taskCount - 1);
}
} else {
dummyTask = recentsView.getTaskViewAt(0);
}
return recentsView.getTempClipAnimationHelper().updateForFullscreenOverview(dummyTask) return recentsView.getTempClipAnimationHelper().updateForFullscreenOverview(dummyTask)
.getScaleAndTranslation(); .getScaleAndTranslation();
} }
@@ -47,9 +47,9 @@ public final class PortraitOverviewStateTouchHelper {
* @return true if we should intercept the motion event * @return true if we should intercept the motion event
*/ */
boolean canInterceptTouch(MotionEvent ev) { boolean canInterceptTouch(MotionEvent ev) {
if (mRecentsView.getChildCount() > 0) { if (mRecentsView.getTaskViewCount() > 0) {
// Allow swiping up in the gap between the hotseat and overview. // Allow swiping up in the gap between the hotseat and overview.
return ev.getY() >= mRecentsView.getChildAt(0).getBottom(); return ev.getY() >= mRecentsView.getTaskViewAt(0).getBottom();
} else { } else {
// If there are no tasks, we only intercept if we're below the hotseat height. // If there are no tasks, we only intercept if we're below the hotseat height.
return isTouchOverHotseat(mLauncher, ev); return isTouchOverHotseat(mLauncher, ev);
@@ -63,7 +63,7 @@ public final class PortraitOverviewStateTouchHelper {
* @return true if going back should take the user to the currently running task * @return true if going back should take the user to the currently running task
*/ */
boolean shouldSwipeDownReturnToApp() { boolean shouldSwipeDownReturnToApp() {
TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getNextPage()); TaskView taskView = mRecentsView.getNextPageTaskView();
return taskView != null && mRecentsView.shouldSwipeDownLaunchApp(); return taskView != null && mRecentsView.shouldSwipeDownLaunchApp();
} }
@@ -76,7 +76,7 @@ public final class PortraitOverviewStateTouchHelper {
*/ */
PendingAnimation createSwipeDownToTaskAppAnimation(long duration) { PendingAnimation createSwipeDownToTaskAppAnimation(long duration) {
mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen()); mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen());
TaskView taskView = mRecentsView.getTaskViewAt(mRecentsView.getCurrentPage()); TaskView taskView = mRecentsView.getCurrentPageTaskView();
if (taskView == null) { if (taskView == null) {
throw new IllegalStateException("There is no task view to animate to."); throw new IllegalStateException("There is no task view to animate to.");
} }
@@ -50,7 +50,6 @@ import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode.Mode; import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.views.RecentsView; import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView; import com.android.quickstep.views.TaskView;
import com.android.systemui.shared.system.QuickStepContract;
/** /**
* Handles quick switching to a recent task from the home screen. * Handles quick switching to a recent task from the home screen.
@@ -227,10 +227,10 @@ public abstract class BaseSwipeUpHandler<T extends BaseDraggingActivity, Q exten
// Launch the task user scrolled to (mRecentsView.getNextPage()). // Launch the task user scrolled to (mRecentsView.getNextPage()).
if (ENABLE_QUICKSTEP_LIVE_TILE.get()) { if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
// We finish recents animation inside launchTask() when live tile is enabled. // We finish recents animation inside launchTask() when live tile is enabled.
mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false /* animate */, mRecentsView.getNextPageTaskView().launchTask(false /* animate */,
true /* freezeTaskList */); true /* freezeTaskList */);
} else { } else {
int taskId = mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).getTask().key.id; int taskId = mRecentsView.getNextPageTaskView().getTask().key.id;
mFinishingRecentsAnimationForNewTaskId = taskId; mFinishingRecentsAnimationForNewTaskId = taskId;
mRecentsAnimationWrapper.finish(true /* toRecents */, () -> { mRecentsAnimationWrapper.finish(true /* toRecents */, () -> {
if (!mCanceled) { if (!mCanceled) {
@@ -268,7 +268,7 @@ public final class LauncherActivityControllerHelper implements ActivityControlHe
INDEX_RECENTS_FADE_ANIM, attached ? 1 : 0); INDEX_RECENTS_FADE_ANIM, attached ? 1 : 0);
int runningTaskIndex = recentsView.getRunningTaskIndex(); int runningTaskIndex = recentsView.getRunningTaskIndex();
if (runningTaskIndex == 0) { if (runningTaskIndex == recentsView.getTaskViewStartIndex()) {
// If we are on the first task (we haven't quick switched), translate recents in // If we are on the first task (we haven't quick switched), translate recents in
// from the side. Calculate the start translation based on current scale/scroll. // from the side. Calculate the start translation based on current scale/scroll.
float currScale = recentsView.getScaleX(); float currScale = recentsView.getScaleX();
@@ -351,8 +351,7 @@ public final class LauncherActivityControllerHelper implements ActivityControlHe
private void playScaleDownAnim(AnimatorSet anim, Launcher launcher, LauncherState fromState, private void playScaleDownAnim(AnimatorSet anim, Launcher launcher, LauncherState fromState,
LauncherState endState) { LauncherState endState) {
RecentsView recentsView = launcher.getOverviewPanel(); RecentsView recentsView = launcher.getOverviewPanel();
TaskView v = recentsView.getTaskViewAt(recentsView.getCurrentPage()); if (recentsView.getCurrentPageTaskView() == null) {
if (v == null) {
return; return;
} }
@@ -380,7 +379,7 @@ public final class LauncherActivityControllerHelper implements ActivityControlHe
// recents as a whole needs to translate further to keep up with the app window. // recents as a whole needs to translate further to keep up with the app window.
TaskView runningTaskView = recentsView.getRunningTaskView(); TaskView runningTaskView = recentsView.getRunningTaskView();
if (runningTaskView == null) { if (runningTaskView == null) {
runningTaskView = recentsView.getTaskViewAt(recentsView.getCurrentPage()); runningTaskView = recentsView.getCurrentPageTaskView();
} }
TimeInterpolator oldInterpolator = translateY.getInterpolator(); TimeInterpolator oldInterpolator = translateY.getInterpolator();
Rect fallbackInsets = launcher.getDeviceProfile().getInsets(); Rect fallbackInsets = launcher.getDeviceProfile().getInsets();
@@ -109,7 +109,7 @@ public class OverviewCommandHelper {
TaskView taskView = rv.getNextTaskView(); TaskView taskView = rv.getNextTaskView();
if (taskView == null) { if (taskView == null) {
if (rv.getTaskViewCount() > 0) { if (rv.getTaskViewCount() > 0) {
taskView = (TaskView) rv.getPageAt(0); taskView = rv.getTaskViewAt(0);
taskView.requestFocus(); taskView.requestFocus();
} else { } else {
rv.requestFocus(); rv.requestFocus();
@@ -479,8 +479,8 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
recentsAttachedToAppWindow = mIsShelfPeeking || mIsLikelyToStartNewTask; recentsAttachedToAppWindow = mIsShelfPeeking || mIsLikelyToStartNewTask;
if (animate) { if (animate) {
// Only animate if an adjacent task view is visible on screen. // Only animate if an adjacent task view is visible on screen.
TaskView adjacentTask1 = mRecentsView.getTaskViewAt(runningTaskIndex + 1); TaskView adjacentTask1 = mRecentsView.getNextTaskView();
TaskView adjacentTask2 = mRecentsView.getTaskViewAt(runningTaskIndex - 1); TaskView adjacentTask2 = mRecentsView.getPreviousTaskView();
float prevTranslationX = mRecentsView.getTranslationX(); float prevTranslationX = mRecentsView.getTranslationX();
mRecentsView.setTranslationX(0); mRecentsView.setTranslationX(0);
animate = (adjacentTask1 != null && adjacentTask1.getGlobalVisibleRect(TEMP_RECT)) animate = (adjacentTask1 != null && adjacentTask1.getGlobalVisibleRect(TEMP_RECT))
@@ -590,8 +590,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
*/ */
private void updateSysUiFlags(float windowProgress) { private void updateSysUiFlags(float windowProgress) {
if (mRecentsView != null) { if (mRecentsView != null) {
TaskView centermostTask = mRecentsView.getTaskViewAt(mRecentsView TaskView centermostTask = mRecentsView.getTaskViewNearestToCenterOfScreen();
.getPageNearestToCenterOfScreen());
int centermostTaskFlags = centermostTask == null ? 0 int centermostTaskFlags = centermostTask == null ? 0
: centermostTask.getThumbnail().getSysUiStatusNavFlags(); : centermostTask.getThumbnail().getSysUiStatusNavFlags();
boolean useHomeScreenFlags = windowProgress > 1 - UPDATE_SYSUI_FLAGS_THRESHOLD; boolean useHomeScreenFlags = windowProgress > 1 - UPDATE_SYSUI_FLAGS_THRESHOLD;
@@ -176,7 +176,7 @@ public class FallbackRecentsView extends RecentsView<RecentsActivity> {
protected void applyLoadPlan(ArrayList<Task> tasks) { protected void applyLoadPlan(ArrayList<Task> tasks) {
// When quick-switching on 3p-launcher, we add a "dummy" tile corresponding to Launcher // When quick-switching on 3p-launcher, we add a "dummy" tile corresponding to Launcher
// as well. This tile is never shown as we have setCurrentTaskHidden, but allows use to // as well. This tile is never shown as we have setCurrentTaskHidden, but allows use to
// track the index of the next task appropriately, as it we are switching on any other app. // track the index of the next task appropriately, as if we are switching on any other app.
if (mRunningTaskInfo != null && mRunningTaskInfo.taskId == mRunningTaskId) { if (mRunningTaskInfo != null && mRunningTaskInfo.taskId == mRunningTaskId) {
// Check if the task list has running task // Check if the task list has running task
boolean found = false; boolean found = false;
@@ -306,6 +306,9 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
private Layout mEmptyTextLayout; private Layout mEmptyTextLayout;
private LiveTileOverlay mLiveTileOverlay; private LiveTileOverlay mLiveTileOverlay;
// Keeps track of the index where the first TaskView should be
private int mTaskViewStartIndex = 0;
private BaseActivity.MultiWindowModeChangedListener mMultiWindowModeChangedListener = private BaseActivity.MultiWindowModeChangedListener mMultiWindowModeChangedListener =
(inMultiWindowMode) -> { (inMultiWindowMode) -> {
if (!inMultiWindowMode && mOverviewStateEnabled) { if (!inMultiWindowMode && mOverviewStateEnabled) {
@@ -329,7 +332,6 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
mClearAllButton = (ClearAllButton) LayoutInflater.from(context) mClearAllButton = (ClearAllButton) LayoutInflater.from(context)
.inflate(R.layout.overview_clear_all_button, this, false); .inflate(R.layout.overview_clear_all_button, this, false);
mClearAllButton.setOnClickListener(this::dismissAllTasks); mClearAllButton.setOnClickListener(this::dismissAllTasks);
mTaskViewPool = new ViewPool<>(context, this, R.layout.task, 20 /* max size */, mTaskViewPool = new ViewPool<>(context, this, R.layout.task, 20 /* max size */,
10 /* initial size */); 10 /* initial size */);
@@ -430,7 +432,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
super.onViewRemoved(child); super.onViewRemoved(child);
// Clear the task data for the removed child if it was visible // Clear the task data for the removed child if it was visible
if (child != mClearAllButton) { if (child instanceof TaskView) {
TaskView taskView = (TaskView) child; TaskView taskView = (TaskView) child;
mHasVisibleTaskData.delete(taskView.getTask().key.id); mHasVisibleTaskData.delete(taskView.getTask().key.id);
mTaskViewPool.recycle(taskView); mTaskViewPool.recycle(taskView);
@@ -444,7 +446,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
public TaskView getTaskView(int taskId) { public TaskView getTaskView(int taskId) {
for (int i = 0; i < getTaskViewCount(); i++) { for (int i = 0; i < getTaskViewCount(); i++) {
TaskView tv = (TaskView) getChildAt(i); TaskView tv = getTaskViewAt(i);
if (tv.getTask() != null && tv.getTask().key != null && tv.getTask().key.id == taskId) { if (tv.getTask() != null && tv.getTask().key != null && tv.getTask().key.id == taskId) {
return tv; return tv;
} }
@@ -536,28 +538,26 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
} }
if (tasks == null || tasks.isEmpty()) { if (tasks == null || tasks.isEmpty()) {
removeAllViews(); removeTasksViewsAndClearAllButton();
onTaskStackUpdated(); onTaskStackUpdated();
return; return;
} }
int oldChildCount = getChildCount();
// Unload existing visible task data // Unload existing visible task data
unloadVisibleTaskData(); unloadVisibleTaskData();
TaskView ignoreRestTaskView = TaskView ignoreResetTaskView =
mIgnoreResetTaskId == -1 ? null : getTaskView(mIgnoreResetTaskId); mIgnoreResetTaskId == -1 ? null : getTaskView(mIgnoreResetTaskId);
final int requiredTaskCount = tasks.size(); final int requiredTaskCount = tasks.size();
if (getTaskViewCount() != requiredTaskCount) { if (getTaskViewCount() != requiredTaskCount) {
if (oldChildCount > 0) { if (indexOfChild(mClearAllButton) != -1) {
removeView(mClearAllButton); removeView(mClearAllButton);
} }
for (int i = getChildCount(); i < requiredTaskCount; i++) { for (int i = getTaskViewCount(); i < requiredTaskCount; i++) {
addView(mTaskViewPool.getView()); addView(mTaskViewPool.getView());
} }
while (getChildCount() > requiredTaskCount) { while (getTaskViewCount() > requiredTaskCount) {
removeView(getChildAt(getChildCount() - 1)); removeView(getChildAt(getChildCount() - 1));
} }
if (requiredTaskCount > 0) { if (requiredTaskCount > 0) {
@@ -567,17 +567,20 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
// Rebind and reset all task views // Rebind and reset all task views
for (int i = requiredTaskCount - 1; i >= 0; i--) { for (int i = requiredTaskCount - 1; i >= 0; i--) {
final int pageIndex = requiredTaskCount - i - 1; final int pageIndex = requiredTaskCount - i - 1 + mTaskViewStartIndex;
final Task task = tasks.get(i); final Task task = tasks.get(i);
final TaskView taskView = (TaskView) getChildAt(pageIndex); final TaskView taskView = (TaskView) getChildAt(pageIndex);
taskView.bind(task); taskView.bind(task);
} }
TaskView runningTaskView = getRunningTaskView(); TaskView runningTaskView = getRunningTaskView();
if (runningTaskView != null) { if (runningTaskView != null) {
setCurrentPage(indexOfChild(runningTaskView)); setCurrentPage(indexOfChild(runningTaskView));
} else if (getTaskViewCount() > 0) {
setCurrentPage(indexOfChild(getTaskViewAt(0)));
} }
if (mIgnoreResetTaskId != -1 && getTaskView(mIgnoreResetTaskId) != ignoreRestTaskView) { if (mIgnoreResetTaskId != -1 && getTaskView(mIgnoreResetTaskId) != ignoreResetTaskView) {
// If the taskView mapping is changing, do not preserve the visuals. Since we are // If the taskView mapping is changing, do not preserve the visuals. Since we are
// mostly preserving the first task, and new taskViews are added to the end, it should // mostly preserving the first task, and new taskViews are added to the end, it should
// generally map to the same task. // generally map to the same task.
@@ -588,17 +591,28 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
updateEnabledOverlays(); updateEnabledOverlays();
} }
private void removeTasksViewsAndClearAllButton() {
for (int i = getTaskViewCount() - 1; i >= 0; i--) {
removeView(getTaskViewAt(i));
}
if (indexOfChild(mClearAllButton) != -1) {
removeView(mClearAllButton);
}
}
public int getTaskViewCount() { public int getTaskViewCount() {
// Account for the clear all button. int taskViewCount = getChildCount() - mTaskViewStartIndex;
int childCount = getChildCount(); if (indexOfChild(mClearAllButton) != -1) {
return childCount == 0 ? 0 : childCount - 1; taskViewCount--;
}
return taskViewCount;
} }
protected void onTaskStackUpdated() { } protected void onTaskStackUpdated() { }
public void resetTaskVisuals() { public void resetTaskVisuals() {
for (int i = getTaskViewCount() - 1; i >= 0; i--) { for (int i = getTaskViewCount() - 1; i >= 0; i--) {
TaskView taskView = (TaskView) getChildAt(i); TaskView taskView = getTaskViewAt(i);
if (mIgnoreResetTaskId != taskView.getTask().key.id) { if (mIgnoreResetTaskId != taskView.getTask().key.id) {
taskView.resetVisualProperties(); taskView.resetVisualProperties();
taskView.setStableAlpha(mContentAlpha); taskView.setStableAlpha(mContentAlpha);
@@ -704,7 +718,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
} }
/** /**
* Iterates through all thet asks, and loads the associated task data for newly visible tasks, * Iterates through all the tasks, and loads the associated task data for newly visible tasks,
* and unloads the associated task data for tasks that are no longer visible. * and unloads the associated task data for tasks that are no longer visible.
*/ */
public void loadVisibleTaskData() { public void loadVisibleTaskData() {
@@ -715,15 +729,16 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
} }
int centerPageIndex = getPageNearestToCenterOfScreen(); int centerPageIndex = getPageNearestToCenterOfScreen();
int numChildren = getTaskViewCount(); int numChildren = getChildCount();
int lower = Math.max(0, centerPageIndex - 2); int lower = Math.max(0, centerPageIndex - 2);
int upper = Math.min(centerPageIndex + 2, numChildren - 1); int upper = Math.min(centerPageIndex + 2, numChildren - 1);
// Update the task data for the in/visible children // Update the task data for the in/visible children
for (int i = 0; i < numChildren; i++) { for (int i = 0; i < getTaskViewCount(); i++) {
TaskView taskView = (TaskView) getChildAt(i); TaskView taskView = getTaskViewAt(i);
Task task = taskView.getTask(); Task task = taskView.getTask();
boolean visible = lower <= i && i <= upper; int index = indexOfChild(taskView);
boolean visible = lower <= index && index <= upper;
if (visible) { if (visible) {
if (task == mTmpRunningTask) { if (task == mTmpRunningTask) {
// Skip loading if this is the task that we are animating into // Skip loading if this is the task that we are animating into
@@ -798,6 +813,10 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
return tv == null ? -1 : indexOfChild(tv); return tv == null ? -1 : indexOfChild(tv);
} }
public int getTaskViewStartIndex() {
return mTaskViewStartIndex;
}
/** /**
* Reloads the view if anything in recents changed. * Reloads the view if anything in recents changed.
*/ */
@@ -853,10 +872,10 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
*/ */
public void showCurrentTask(int runningTaskId) { public void showCurrentTask(int runningTaskId) {
if (getTaskView(runningTaskId) == null) { if (getTaskView(runningTaskId) == null) {
boolean wasEmpty = getChildCount() == 0; boolean wasEmpty = getTaskViewCount() == 0;
// Add an empty view for now until the task plan is loaded and applied // Add an empty view for now until the task plan is loaded and applied
final TaskView taskView = mTaskViewPool.getView(); final TaskView taskView = mTaskViewPool.getView();
addView(taskView, 0); addView(taskView, mTaskViewStartIndex);
if (wasEmpty) { if (wasEmpty) {
addView(mClearAllButton); addView(mClearAllButton);
} }
@@ -922,14 +941,13 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
if (runningTaskView == null) { if (runningTaskView == null) {
// Launch the first task // Launch the first task
if (getTaskViewCount() > 0) { if (getTaskViewCount() > 0) {
getTaskViewAt(0).launchTask(true /* animate */); getTaskViewAt(0).launchTask(true);
} }
} else { } else {
TaskView nextTaskView = getNextTaskView(); if (getNextTaskView() != null) {
if (nextTaskView != null) { getNextTaskView().launchTask(true);
nextTaskView.launchTask(true /* animate */);
} else { } else {
runningTaskView.launchTask(true /* animate */); runningTaskView.launchTask(true);
} }
} }
} }
@@ -1189,7 +1207,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
int count = getTaskViewCount(); int count = getTaskViewCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
addDismissedTaskAnimations(getChildAt(i), anim, duration); addDismissedTaskAnimations(getTaskViewAt(i), anim, duration);
} }
mPendingAnimation = pendingAnimation; mPendingAnimation = pendingAnimation;
@@ -1197,7 +1215,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
if (onEndListener.isSuccess) { if (onEndListener.isSuccess) {
// Remove all the task views now // Remove all the task views now
ActivityManagerWrapper.getInstance().removeAllRecentTasks(); ActivityManagerWrapper.getInstance().removeAllRecentTasks();
removeAllViews(); removeTasksViewsAndClearAllButton();
startHome(); startHome();
} }
mPendingAnimation = null; mPendingAnimation = null;
@@ -1344,26 +1362,50 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
child.setAlpha(mContentAlpha); child.setAlpha(mContentAlpha);
} }
/**
* @return The most recent task that is older than the currently running task. If there is
* currently no running task or there is no task older than it, then return null.
*/
@Nullable @Nullable
public TaskView getNextTaskView() { public TaskView getNextTaskView() {
TaskView runningTaskView = getRunningTaskView(); return getTaskViewAtByAbsoluteIndex(getRunningTaskIndex() + 1);
if (runningTaskView == null) {
return null;
}
return getTaskViewAt(indexOfChild(runningTaskView) + 1);
} }
@Nullable
public TaskView getPreviousTaskView() {
return getTaskViewAtByAbsoluteIndex(getRunningTaskIndex() - 1);
}
@Nullable
public TaskView getCurrentPageTaskView() {
return getTaskViewAtByAbsoluteIndex(getCurrentPage());
}
@Nullable
public TaskView getNextPageTaskView() {
return getTaskViewAtByAbsoluteIndex(getNextPage());
}
@Nullable
public TaskView getTaskViewNearestToCenterOfScreen() {
return getTaskViewAtByAbsoluteIndex(getPageNearestToCenterOfScreen());
}
/**
* Returns null instead of indexOutOfBoundsError when index is not in range
*/
@Nullable
public TaskView getTaskViewAt(int index) { public TaskView getTaskViewAt(int index) {
View child = getChildAt(index); return getTaskViewAtByAbsoluteIndex(index + mTaskViewStartIndex);
return child == mClearAllButton ? null : (TaskView) child; }
@Nullable
private TaskView getTaskViewAtByAbsoluteIndex(int index) {
if (index < getChildCount() && index >= 0) {
View child = getChildAt(index);
return child instanceof TaskView ? (TaskView) child : null;
}
return null;
} }
public void updateEmptyMessage() { public void updateEmptyMessage() {
boolean isEmpty = getChildCount() == 0; boolean isEmpty = getTaskViewCount() == 0;
boolean hasSizeChanged = mLastMeasureSize.x != getWidth() boolean hasSizeChanged = mLastMeasureSize.x != getWidth()
|| mLastMeasureSize.y != getHeight(); || mLastMeasureSize.y != getHeight();
if (isEmpty == mShowEmptyMessage && !hasSizeChanged) { if (isEmpty == mShowEmptyMessage && !hasSizeChanged) {
@@ -1497,7 +1539,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
throw new IllegalStateException("Another pending animation is still running"); throw new IllegalStateException("Another pending animation is still running");
} }
int count = getChildCount(); int count = getTaskViewCount();
if (count == 0) { if (count == 0) {
return new PendingAnimation(new AnimatorSet()); return new PendingAnimation(new AnimatorSet());
} }
@@ -1670,18 +1712,38 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
@Override @Override
protected int computeMinScrollX() { protected int computeMinScrollX() {
if (mIsRtl && mDisallowScrollToClearAll) { if (getTaskViewCount() > 0) {
// We aren't showing the clear all button, so use the leftmost task as the min scroll. if (mDisallowScrollToClearAll) {
return getScrollForPage(getTaskViewCount() - 1); // We aren't showing the clear all button,
// so use the leftmost task as the min scroll.
if (mIsRtl) {
return getScrollForPage(indexOfChild(getTaskViewAt(getTaskViewCount() - 1)));
}
return getScrollForPage(mTaskViewStartIndex);
}
if (mIsRtl) {
return getScrollForPage(indexOfChild(getTaskViewAt(getTaskViewCount() - 1)) + 1);
}
return getScrollForPage(mTaskViewStartIndex);
} }
return super.computeMinScrollX(); return super.computeMinScrollX();
} }
@Override @Override
protected int computeMaxScrollX() { protected int computeMaxScrollX() {
if (!mIsRtl && mDisallowScrollToClearAll) { if (getTaskViewCount() > 0) {
// We aren't showing the clear all button, so use the rightmost task as the max scroll. if (mDisallowScrollToClearAll) {
return getScrollForPage(getTaskViewCount() - 1); // We aren't showing the clear all button,
// so use the rightmost task as the min scroll.
if (mIsRtl) {
return getScrollForPage(mTaskViewStartIndex);
}
return getScrollForPage(indexOfChild(getTaskViewAt(getTaskViewCount() - 1)));
}
if (mIsRtl) {
return getScrollForPage(mTaskViewStartIndex);
}
return getScrollForPage(indexOfChild(getTaskViewAt(getTaskViewCount() - 1)) + 1);
} }
return super.computeMaxScrollX(); return super.computeMaxScrollX();
} }
@@ -1733,7 +1795,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
int overlayEnabledPage = mOverlayEnabled ? getNextPage() : -1; int overlayEnabledPage = mOverlayEnabled ? getNextPage() : -1;
int taskCount = getTaskViewCount(); int taskCount = getTaskViewCount();
for (int i = 0; i < taskCount; i++) { for (int i = 0; i < taskCount; i++) {
((TaskView) getChildAt(i)).setOverlayEnabled(i == overlayEnabledPage); getTaskViewAt(i).setOverlayEnabled(i == overlayEnabledPage);
} }
} }