@Override
  public void showPrevAffiliatedTask() {
    // Ensure the device has been provisioned before allowing the user to interact with
    // recents
    if (!isDeviceProvisioned()) {
      return;
    }

    // Keep track of when the affiliated task is triggered
    MetricsLogger.count(mContext, "overview_affiliated_task_prev", 1);
    showRelativeAffiliatedTask(false);
  }
Exemple #2
0
  @Override
  public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) {
    if (removedTasks != null) {
      int taskCount = removedTasks.size();
      for (int i = 0; i < taskCount; i++) {
        onTaskViewDismissed(removedTasks.get(i));
      }
    }

    mCb.onAllTaskViewsDismissed();

    // Keep track of all-deletions
    MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1);
  }
 void maybeCount(String name, int value) {
   if (value > 0) {
     MetricsLogger.count(mContext, name, value);
   }
 }
  void showRelativeAffiliatedTask(boolean showNextTask) {
    // Return early if there is no focused stack
    int focusedStackId = mSystemServicesProxy.getFocusedStack();
    TaskStack focusedStack = null;
    RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
    RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
    loader.preloadTasks(plan, true /* isTopTaskHome */);
    if (mConfig.multiStackEnabled) {
      if (focusedStackId < 0) return;
      focusedStack = plan.getTaskStack(focusedStackId);
    } else {
      focusedStack = plan.getAllTaskStacks().get(0);
    }

    // Return early if there are no tasks in the focused stack
    if (focusedStack == null || focusedStack.getTaskCount() == 0) return;

    ActivityManager.RunningTaskInfo runningTask = mSystemServicesProxy.getTopMostTask();
    // Return early if there is no running task (can't determine affiliated tasks in this case)
    if (runningTask == null) return;
    // Return early if the running task is in the home stack (optimization)
    if (mSystemServicesProxy.isInHomeStack(runningTask.id)) return;

    // Find the task in the recents list
    ArrayList<Task> tasks = focusedStack.getTasks();
    Task toTask = null;
    ActivityOptions launchOpts = null;
    int taskCount = tasks.size();
    int numAffiliatedTasks = 0;
    for (int i = 0; i < taskCount; i++) {
      Task task = tasks.get(i);
      if (task.key.id == runningTask.id) {
        TaskGrouping group = task.group;
        Task.TaskKey toTaskKey;
        if (showNextTask) {
          toTaskKey = group.getNextTaskInGroup(task);
          launchOpts =
              ActivityOptions.makeCustomAnimation(
                  mContext,
                  R.anim.recents_launch_next_affiliated_task_target,
                  R.anim.recents_launch_next_affiliated_task_source);
        } else {
          toTaskKey = group.getPrevTaskInGroup(task);
          launchOpts =
              ActivityOptions.makeCustomAnimation(
                  mContext,
                  R.anim.recents_launch_prev_affiliated_task_target,
                  R.anim.recents_launch_prev_affiliated_task_source);
        }
        if (toTaskKey != null) {
          toTask = focusedStack.findTaskWithId(toTaskKey.id);
        }
        numAffiliatedTasks = group.getTaskCount();
        break;
      }
    }

    // Return early if there is no next task
    if (toTask == null) {
      if (numAffiliatedTasks > 1) {
        if (showNextTask) {
          mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication(
              ActivityOptions.makeCustomInPlaceAnimation(
                  mContext, R.anim.recents_launch_next_affiliated_task_bounce));
        } else {
          mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication(
              ActivityOptions.makeCustomInPlaceAnimation(
                  mContext, R.anim.recents_launch_prev_affiliated_task_bounce));
        }
      }
      return;
    }

    // Keep track of actually launched affiliated tasks
    MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1);

    // Launch the task
    if (toTask.isActive) {
      // Bring an active task to the foreground
      mSystemServicesProxy.moveTaskToFront(toTask.key.id, launchOpts);
    } else {
      mSystemServicesProxy.startActivityFromRecents(
          mContext, toTask.key.id, toTask.activityLabel, launchOpts);
    }
  }