@Override
 public void onTaskViewDismissed(TaskView tv) {
   Task task = tv.getTask();
   int taskIndex = mStack.indexOfTask(task);
   boolean taskWasFocused = tv.isFocusedTask();
   // Announce for accessibility
   tv.announceForAccessibility(
       getContext()
           .getString(R.string.accessibility_recents_item_dismissed, tv.getTask().activityLabel));
   // Remove the task from the view
   mStack.removeTask(task);
   // If the dismissed task was focused, then we should focus the next task in front
   if (taskWasFocused) {
     ArrayList<Task> tasks = mStack.getTasks();
     int nextTaskIndex = Math.min(tasks.size() - 1, taskIndex);
     if (nextTaskIndex >= 0) {
       Task nextTask = tasks.get(nextTaskIndex);
       TaskView nextTv = getChildViewForTask(nextTask);
       nextTv.setFocusedTask();
     }
   }
 }
 /** ** RecentsPackageMonitor.PackageCallbacks Implementation *** */
 @Override
 public void onComponentRemoved(HashSet<ComponentName> cns) {
   // For other tasks, just remove them directly if they no longer exist
   ArrayList<Task> tasks = mStack.getTasks();
   for (int i = tasks.size() - 1; i >= 0; i--) {
     final Task t = tasks.get(i);
     if (cns.contains(t.key.baseIntent.getComponent())) {
       TaskView tv = getChildViewForTask(t);
       if (tv != null) {
         // For visible children, defer removing the task until after the animation
         tv.startDeleteTaskAnimation(
             new Runnable() {
               @Override
               public void run() {
                 mStack.removeTask(t);
               }
             });
       } else {
         // Otherwise, remove the task from the stack immediately
         mStack.removeTask(t);
       }
     }
   }
 }