/** Handler for the first layout. */
  void onFirstLayout() {
    int offscreenY =
        mLayoutAlgorithm.mViewRect.bottom
            - (mLayoutAlgorithm.mTaskRect.top - mLayoutAlgorithm.mViewRect.top);

    // Find the launch target task
    Task launchTargetTask = null;
    int childCount = getChildCount();
    for (int i = childCount - 1; i >= 0; i--) {
      TaskView tv = (TaskView) getChildAt(i);
      Task task = tv.getTask();
      if (task.isLaunchTarget) {
        launchTargetTask = task;
        break;
      }
    }

    // Prepare the first view for its enter animation
    for (int i = childCount - 1; i >= 0; i--) {
      TaskView tv = (TaskView) getChildAt(i);
      Task task = tv.getTask();
      boolean occludesLaunchTarget =
          (launchTargetTask != null)
              && launchTargetTask.group.isTaskAboveTask(task, launchTargetTask);
      tv.prepareEnterRecentsAnimation(task.isLaunchTarget, occludesLaunchTarget, offscreenY);
    }

    // If the enter animation started already and we haven't completed a layout yet, do the
    // enter animation now
    if (mStartEnterAnimationRequestedAfterLayout) {
      startEnterRecentsAnimation(mStartEnterAnimationContext);
      mStartEnterAnimationRequestedAfterLayout = false;
      mStartEnterAnimationContext = null;
    }

    // When Alt-Tabbing, we scroll to and focus the previous task
    if (mConfig.launchedWithAltTab) {
      if (mConfig.launchedFromHome) {
        focusTask(Math.max(0, mStack.getTaskCount() - 1), false);
      } else {
        focusTask(Math.max(0, mStack.getTaskCount() - 2), false);
      }
    }
  }
  /** Focuses the next task in the stack */
  void focusNextTask(boolean forward) {
    // Find the next index to focus
    int numTasks = mStack.getTaskCount();
    if (numTasks == 0) return;

    int nextFocusIndex = numTasks - 1;
    if (0 <= mFocusedTaskIndex && mFocusedTaskIndex < numTasks) {
      nextFocusIndex = Math.max(0, Math.min(numTasks - 1, mFocusedTaskIndex + (forward ? -1 : 1)));
    }
    focusTask(nextFocusIndex, true);
  }