RecentsView.java revision b1bbaedb1a02fb74dd1f85977783e9cb446331e4
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.systemui.recents.views; 18 19import android.app.ActivityManager; 20import android.app.ActivityOptions; 21import android.app.TaskStackBuilder; 22import android.content.Context; 23import android.content.Intent; 24import android.graphics.Bitmap; 25import android.graphics.Canvas; 26import android.graphics.Rect; 27import android.net.Uri; 28import android.os.Bundle; 29import android.os.IRemoteCallback; 30import android.os.RemoteException; 31import android.os.UserHandle; 32import android.provider.Settings; 33import android.util.AttributeSet; 34import android.util.Log; 35import android.util.SparseArray; 36import android.view.AppTransitionAnimationSpec; 37import android.view.LayoutInflater; 38import android.view.View; 39import android.view.WindowInsets; 40import android.view.WindowManagerGlobal; 41import android.widget.FrameLayout; 42 43import com.android.internal.logging.MetricsLogger; 44import com.android.systemui.R; 45import com.android.systemui.recents.Constants; 46import com.android.systemui.recents.RecentsAppWidgetHostView; 47import com.android.systemui.recents.RecentsConfiguration; 48import com.android.systemui.recents.misc.SystemServicesProxy; 49import com.android.systemui.recents.model.RecentsPackageMonitor; 50import com.android.systemui.recents.model.RecentsTaskLoader; 51import com.android.systemui.recents.model.Task; 52import com.android.systemui.recents.model.TaskStack; 53 54import java.util.ArrayList; 55import java.util.List; 56 57/** 58 * This view is the the top level layout that contains TaskStacks (which are laid out according 59 * to their SpaceNode bounds. 60 */ 61public class RecentsView extends FrameLayout implements TaskStackView.TaskStackViewCallbacks, 62 RecentsPackageMonitor.PackageCallbacks { 63 64 private static final String TAG = "RecentsView"; 65 66 private static final boolean ADD_HEADER_BITMAP = true; 67 68 /** The RecentsView callbacks */ 69 public interface RecentsViewCallbacks { 70 public void onTaskViewClicked(); 71 public void onTaskLaunchFailed(); 72 public void onAllTaskViewsDismissed(); 73 public void onExitToHomeAnimationTriggered(); 74 public void onScreenPinningRequest(); 75 public void onTaskResize(Task t); 76 public void runAfterPause(Runnable r); 77 } 78 79 RecentsConfiguration mConfig; 80 LayoutInflater mInflater; 81 DebugOverlayView mDebugOverlay; 82 83 ArrayList<TaskStack> mStacks; 84 TaskStackView mTaskStackView; 85 RecentsAppWidgetHostView mSearchBar; 86 RecentsViewCallbacks mCb; 87 88 public RecentsView(Context context) { 89 super(context); 90 } 91 92 public RecentsView(Context context, AttributeSet attrs) { 93 this(context, attrs, 0); 94 } 95 96 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { 97 this(context, attrs, defStyleAttr, 0); 98 } 99 100 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 101 super(context, attrs, defStyleAttr, defStyleRes); 102 mConfig = RecentsConfiguration.getInstance(); 103 mInflater = LayoutInflater.from(context); 104 } 105 106 /** Sets the callbacks */ 107 public void setCallbacks(RecentsViewCallbacks cb) { 108 mCb = cb; 109 } 110 111 /** Sets the debug overlay */ 112 public void setDebugOverlay(DebugOverlayView overlay) { 113 mDebugOverlay = overlay; 114 } 115 116 /** Set/get the bsp root node */ 117 public void setTaskStack(TaskStack stack) { 118 if (mConfig.launchedReuseTaskStackViews) { 119 if (mTaskStackView != null) { 120 // If onRecentsHidden is not triggered, we need to the stack view again here 121 mTaskStackView.reset(); 122 mTaskStackView.setStack(stack); 123 } else { 124 mTaskStackView = new TaskStackView(getContext(), stack); 125 mTaskStackView.setCallbacks(this); 126 addView(mTaskStackView); 127 } 128 } else { 129 if (mTaskStackView != null) { 130 removeView(mTaskStackView); 131 } 132 mTaskStackView = new TaskStackView(getContext(), stack); 133 mTaskStackView.setCallbacks(this); 134 addView(mTaskStackView); 135 } 136 137 // Enable debug mode drawing on all the stacks if necessary 138 if (mConfig.debugModeEnabled) { 139 mTaskStackView.setDebugOverlay(mDebugOverlay); 140 } 141 142 // Trigger a new layout 143 requestLayout(); 144 } 145 146 /** Gets the next task in the stack - or if the last - the top task */ 147 public Task getNextTaskOrTopTask(Task taskToSearch) { 148 Task returnTask = null; 149 boolean found = false; 150 if (mTaskStackView != null) { 151 TaskStack stack = mTaskStackView.getStack(); 152 ArrayList<Task> taskList = stack.getTasks(); 153 // Iterate the stack views and try and find the focused task 154 for (int j = taskList.size() - 1; j >= 0; --j) { 155 Task task = taskList.get(j); 156 // Return the next task in the line. 157 if (found) 158 return task; 159 // Remember the first possible task as the top task. 160 if (returnTask == null) 161 returnTask = task; 162 if (task == taskToSearch) 163 found = true; 164 } 165 } 166 return returnTask; 167 } 168 169 /** Launches the focused task from the first stack if possible */ 170 public boolean launchFocusedTask() { 171 if (mTaskStackView != null) { 172 TaskStack stack = mTaskStackView.getStack(); 173 // Iterate the stack views and try and find the focused task 174 List<TaskView> taskViews = mTaskStackView.getTaskViews(); 175 int taskViewCount = taskViews.size(); 176 for (int j = 0; j < taskViewCount; j++) { 177 TaskView tv = taskViews.get(j); 178 Task task = tv.getTask(); 179 if (tv.isFocusedTask()) { 180 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null); 181 return true; 182 } 183 } 184 } 185 return false; 186 } 187 188 /** Launches a given task. */ 189 public boolean launchTask(Task task, Rect taskBounds) { 190 if (mTaskStackView != null) { 191 TaskStack stack = mTaskStackView.getStack(); 192 // Iterate the stack views and try and find the given task. 193 List<TaskView> taskViews = mTaskStackView.getTaskViews(); 194 int taskViewCount = taskViews.size(); 195 for (int j = 0; j < taskViewCount; j++) { 196 TaskView tv = taskViews.get(j); 197 if (tv.getTask() == task) { 198 onTaskViewClicked(mTaskStackView, tv, stack, task, false, taskBounds != null, 199 taskBounds); 200 return true; 201 } 202 } 203 } 204 return false; 205 } 206 207 /** Launches the task that Recents was launched from, if possible */ 208 public boolean launchPreviousTask() { 209 if (mTaskStackView != null) { 210 TaskStack stack = mTaskStackView.getStack(); 211 ArrayList<Task> tasks = stack.getTasks(); 212 213 // Find the launch task in the stack 214 if (!tasks.isEmpty()) { 215 int taskCount = tasks.size(); 216 for (int j = 0; j < taskCount; j++) { 217 if (tasks.get(j).isLaunchTarget) { 218 Task task = tasks.get(j); 219 TaskView tv = mTaskStackView.getChildViewForTask(task); 220 onTaskViewClicked(mTaskStackView, tv, stack, task, false, false, null); 221 return true; 222 } 223 } 224 } 225 } 226 return false; 227 } 228 229 /** Requests all task stacks to start their enter-recents animation */ 230 public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) { 231 // We have to increment/decrement the post animation trigger in case there are no children 232 // to ensure that it runs 233 ctx.postAnimationTrigger.increment(); 234 if (mTaskStackView != null) { 235 mTaskStackView.startEnterRecentsAnimation(ctx); 236 } 237 ctx.postAnimationTrigger.decrement(); 238 } 239 240 /** Requests all task stacks to start their exit-recents animation */ 241 public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { 242 // We have to increment/decrement the post animation trigger in case there are no children 243 // to ensure that it runs 244 ctx.postAnimationTrigger.increment(); 245 if (mTaskStackView != null) { 246 mTaskStackView.startExitToHomeAnimation(ctx); 247 } 248 ctx.postAnimationTrigger.decrement(); 249 250 // Notify of the exit animation 251 mCb.onExitToHomeAnimationTriggered(); 252 } 253 254 /** Adds the search bar */ 255 public void setSearchBar(RecentsAppWidgetHostView searchBar) { 256 // Remove the previous search bar if one exists 257 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { 258 removeView(mSearchBar); 259 } 260 // Add the new search bar 261 if (searchBar != null) { 262 mSearchBar = searchBar; 263 addView(mSearchBar); 264 } 265 } 266 267 /** Returns whether there is currently a search bar */ 268 public boolean hasValidSearchBar() { 269 return mSearchBar != null && !mSearchBar.isReinflateRequired(); 270 } 271 272 /** Sets the visibility of the search bar */ 273 public void setSearchBarVisibility(int visibility) { 274 if (mSearchBar != null) { 275 mSearchBar.setVisibility(visibility); 276 // Always bring the search bar to the top 277 mSearchBar.bringToFront(); 278 } 279 } 280 281 /** 282 * This is called with the full size of the window since we are handling our own insets. 283 */ 284 @Override 285 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 286 int width = MeasureSpec.getSize(widthMeasureSpec); 287 int height = MeasureSpec.getSize(heightMeasureSpec); 288 289 // Get the search bar bounds and measure the search bar layout 290 Rect searchBarSpaceBounds = new Rect(); 291 if (mSearchBar != null) { 292 mConfig.getSearchBarBounds(new Rect(0, 0, width, height), mConfig.systemInsets.top, 293 searchBarSpaceBounds); 294 mSearchBar.measure( 295 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), 296 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); 297 } 298 299 Rect taskStackBounds = new Rect(); 300 mConfig.getAvailableTaskStackBounds(new Rect(0, 0, width, height), mConfig.systemInsets.top, 301 mConfig.systemInsets.right, searchBarSpaceBounds, taskStackBounds); 302 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { 303 mTaskStackView.setTaskStackBounds(taskStackBounds); 304 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); 305 } 306 307 setMeasuredDimension(width, height); 308 } 309 310 /** 311 * This is called with the full size of the window since we are handling our own insets. 312 */ 313 @Override 314 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 315 // Get the search bar bounds so that we lay it out 316 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); 317 Rect searchBarSpaceBounds = new Rect(); 318 if (mSearchBar != null) { 319 mConfig.getSearchBarBounds(measuredRect, 320 mConfig.systemInsets.top, searchBarSpaceBounds); 321 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, 322 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); 323 } 324 325 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { 326 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); 327 } 328 } 329 330 @Override 331 public WindowInsets onApplyWindowInsets(WindowInsets insets) { 332 // Update the configuration with the latest system insets and trigger a relayout 333 mConfig.updateSystemInsets(insets.getSystemWindowInsets()); 334 requestLayout(); 335 return insets.consumeSystemWindowInsets(); 336 } 337 338 /** Notifies each task view of the user interaction. */ 339 public void onUserInteraction() { 340 // Get the first stack view 341 if (mTaskStackView != null) { 342 mTaskStackView.onUserInteraction(); 343 } 344 } 345 346 /** Focuses the next task in the first stack view */ 347 public void focusNextTask(boolean forward) { 348 // Get the first stack view 349 if (mTaskStackView != null) { 350 mTaskStackView.focusNextTask(forward, true); 351 } 352 } 353 354 /** Dismisses the focused task. */ 355 public void dismissFocusedTask() { 356 // Get the first stack view 357 if (mTaskStackView != null) { 358 mTaskStackView.dismissFocusedTask(); 359 } 360 } 361 362 /** Unfilters any filtered stacks */ 363 public boolean unfilterFilteredStacks() { 364 if (mStacks != null) { 365 // Check if there are any filtered stacks and unfilter them before we back out of Recents 366 boolean stacksUnfiltered = false; 367 int numStacks = mStacks.size(); 368 for (int i = 0; i < numStacks; i++) { 369 TaskStack stack = mStacks.get(i); 370 if (stack.hasFilteredTasks()) { 371 stack.unfilterTasks(); 372 stacksUnfiltered = true; 373 } 374 } 375 return stacksUnfiltered; 376 } 377 return false; 378 } 379 380 public void disableLayersForOneFrame() { 381 if (mTaskStackView != null) { 382 mTaskStackView.disableLayersForOneFrame(); 383 } 384 } 385 386 private void postDrawHeaderThumbnailTransitionRunnable(final TaskStackView view, 387 final TaskView clickedView, final int offsetX, final int offsetY, 388 final float stackScroll, 389 final ActivityOptions.OnAnimationStartedListener animStartedListener) { 390 Runnable r = new Runnable() { 391 @Override 392 public void run() { 393 overrideDrawHeaderThumbnailTransition(view, clickedView, offsetX, offsetY, 394 stackScroll, animStartedListener); 395 396 } 397 }; 398 399 mCb.runAfterPause(r); 400 } 401 402 private void overrideDrawHeaderThumbnailTransition(TaskStackView stackView, 403 TaskView clickedTask, int offsetX, int offsetY, float stackScroll, 404 final ActivityOptions.OnAnimationStartedListener animStartedListener) { 405 List<AppTransitionAnimationSpec> specs = getAppTransitionAnimationSpecs(stackView, 406 clickedTask, offsetX, offsetY, stackScroll); 407 if (specs == null) { 408 return; 409 } 410 411 IRemoteCallback.Stub callback = new IRemoteCallback.Stub() { 412 @Override 413 public void sendResult(Bundle data) throws RemoteException { 414 post(new Runnable() { 415 @Override 416 public void run() { 417 if (animStartedListener != null) { 418 animStartedListener.onAnimationStarted(); 419 } 420 } 421 }); 422 } 423 }; 424 425 AppTransitionAnimationSpec[] specsArray = 426 new AppTransitionAnimationSpec[specs.size()]; 427 try { 428 WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionMultiThumb( 429 specs.toArray(specsArray), callback, true /* scaleUp */); 430 431 } catch (RemoteException e) { 432 Log.w(TAG, "Error overriding app transition", e); 433 } 434 } 435 436 private List<AppTransitionAnimationSpec> getAppTransitionAnimationSpecs(TaskStackView stackView, 437 TaskView clickedTask, int offsetX, int offsetY, float stackScroll) { 438 final int targetStackId = clickedTask.getTask().key.stackId; 439 if (targetStackId != ActivityManager.FREEFORM_WORKSPACE_STACK_ID 440 && targetStackId != ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) { 441 return null; 442 } 443 // If this is a full screen stack, the transition will be towards the single, full screen 444 // task. We only need the transition spec for this task. 445 List<AppTransitionAnimationSpec> specs = new ArrayList<>(); 446 if (targetStackId == ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID) { 447 specs.add(createThumbnailHeaderAnimationSpec( 448 stackView, offsetX, offsetY, stackScroll, clickedTask, 449 clickedTask.getTask().key.id, ADD_HEADER_BITMAP)); 450 return specs; 451 } 452 // This is a free form stack or full screen stack, so there will be multiple windows 453 // animating from thumbnails. We need transition animation specs for all of them. 454 455 // We will use top and bottom task views as a base for tasks, that aren't visible on the 456 // screen. This is necessary for cascade recents list, where some of the tasks might be 457 // hidden. 458 List<TaskView> taskViews = stackView.getTaskViews(); 459 int childCount = taskViews.size(); 460 TaskView topChild = taskViews.get(0); 461 TaskView bottomChild = taskViews.get(childCount - 1); 462 SparseArray<TaskView> taskViewsByTaskId = new SparseArray<>(); 463 for (int i = 0; i < childCount; i++) { 464 TaskView taskView = taskViews.get(i); 465 taskViewsByTaskId.put(taskView.getTask().key.id, taskView); 466 } 467 468 TaskStack stack = stackView.getStack(); 469 // We go through all tasks now and for each generate transition animation spec. If there is 470 // a view associated with a task, we use that view as a base for the animation. If there 471 // isn't, we use bottom or top view, depending on which one would be closer to the task 472 // view if it existed. 473 ArrayList<Task> tasks = stack.getTasks(); 474 boolean passedClickedTask = false; 475 for (int i = 0, n = tasks.size(); i < n; i++) { 476 Task task = tasks.get(i); 477 TaskView taskView = taskViewsByTaskId.get(task.key.id); 478 if (taskView != null) { 479 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY, 480 stackScroll, taskView, taskView.getTask().key.id, ADD_HEADER_BITMAP)); 481 if (taskView == clickedTask) { 482 passedClickedTask = true; 483 } 484 } else { 485 taskView = passedClickedTask ? bottomChild : topChild; 486 specs.add(createThumbnailHeaderAnimationSpec(stackView, offsetX, offsetY, 487 stackScroll, taskView, task.key.id, !ADD_HEADER_BITMAP)); 488 } 489 } 490 491 return specs; 492 } 493 494 private AppTransitionAnimationSpec createThumbnailHeaderAnimationSpec(TaskStackView stackView, 495 int offsetX, int offsetY, float stackScroll, TaskView tv, int taskId, 496 boolean addHeaderBitmap) { 497 // Disable any focused state before we draw the header 498 // Upfront the processing of the thumbnail 499 if (tv.isFocusedTask()) { 500 tv.unsetFocusedTask(); 501 } 502 TaskViewTransform transform = new TaskViewTransform(); 503 transform = stackView.getStackAlgorithm().getStackTransform(tv.mTask, stackScroll, 504 transform, null); 505 506 float scale = tv.getScaleX(); 507 int fromHeaderWidth = (int) (tv.mHeaderView.getMeasuredWidth() * scale); 508 int fromHeaderHeight = (int) (tv.mHeaderView.getMeasuredHeight() * scale); 509 510 Bitmap b = null; 511 if (addHeaderBitmap) { 512 b = Bitmap.createBitmap(fromHeaderWidth, fromHeaderHeight, 513 Bitmap.Config.ARGB_8888); 514 515 if (Constants.DebugFlags.App.EnableTransitionThumbnailDebugMode) { 516 b.eraseColor(0xFFff0000); 517 } else { 518 Canvas c = new Canvas(b); 519 c.scale(tv.getScaleX(), tv.getScaleY()); 520 tv.mHeaderView.draw(c); 521 c.setBitmap(null); 522 523 } 524 b = b.createAshmemBitmap(); 525 } 526 527 int[] pts = new int[2]; 528 tv.getLocationOnScreen(pts); 529 530 final int left = pts[0] + offsetX; 531 final int top = pts[1] + offsetY; 532 final Rect rect = new Rect(left, top, left + transform.rect.width(), 533 top + transform.rect.height()); 534 535 return new AppTransitionAnimationSpec(taskId, b, rect); 536 } 537 538 /**** TaskStackView.TaskStackCallbacks Implementation ****/ 539 540 @Override 541 public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv, 542 final TaskStack stack, final Task task, final boolean lockToTask, 543 final boolean boundsValid, final Rect bounds) { 544 545 // Notify any callbacks of the launching of a new task 546 if (mCb != null) { 547 mCb.onTaskViewClicked(); 548 } 549 550 // Upfront the processing of the thumbnail 551 TaskViewTransform transform = new TaskViewTransform(); 552 View sourceView; 553 int offsetX = 0; 554 int offsetY = 0; 555 float stackScroll = stackView.getScroller().getStackScroll(); 556 if (tv == null) { 557 // If there is no actual task view, then use the stack view as the source view 558 // and then offset to the expected transform rect, but bound this to just 559 // outside the display rect (to ensure we don't animate from too far away) 560 sourceView = stackView; 561 offsetX = transform.rect.left; 562 offsetY = mConfig.displayRect.height(); 563 } else { 564 sourceView = tv.mThumbnailView; 565 } 566 567 // Compute the thumbnail to scale up from 568 final SystemServicesProxy ssp = 569 RecentsTaskLoader.getInstance().getSystemServicesProxy(); 570 ActivityOptions opts = null; 571 ActivityOptions.OnAnimationStartedListener animStartedListener = null; 572 if (task.thumbnail != null && task.thumbnail.getWidth() > 0 && 573 task.thumbnail.getHeight() > 0) { 574 if (lockToTask) { 575 animStartedListener = new ActivityOptions.OnAnimationStartedListener() { 576 boolean mTriggered = false; 577 @Override 578 public void onAnimationStarted() { 579 if (!mTriggered) { 580 postDelayed(new Runnable() { 581 @Override 582 public void run() { 583 mCb.onScreenPinningRequest(); 584 } 585 }, 350); 586 mTriggered = true; 587 } 588 } 589 }; 590 } 591 postDrawHeaderThumbnailTransitionRunnable(stackView, tv, offsetX, offsetY, stackScroll, 592 animStartedListener); 593 if (mConfig.multiWindowEnabled) { 594 opts = ActivityOptions.makeCustomAnimation(sourceView.getContext(), 595 R.anim.recents_from_unknown_enter, 596 R.anim.recents_from_unknown_exit, 597 sourceView.getHandler(), animStartedListener); 598 } else { 599 opts = ActivityOptions.makeThumbnailAspectScaleUpAnimation(sourceView, 600 Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(), 601 offsetX, offsetY, transform.rect.width(), transform.rect.height(), 602 sourceView.getHandler(), animStartedListener); 603 } 604 } else { 605 opts = ActivityOptions.makeBasic(); 606 } 607 if (boundsValid) { 608 opts.setBounds(bounds.isEmpty() ? null : bounds); 609 } 610 final ActivityOptions launchOpts = opts; 611 final boolean screenPinningRequested = (animStartedListener == null) && lockToTask; 612 final Runnable launchRunnable = new Runnable() { 613 @Override 614 public void run() { 615 if (task.isActive) { 616 // Bring an active task to the foreground 617 ssp.moveTaskToFront(task.key.id, launchOpts); 618 } else { 619 if (ssp.startActivityFromRecents(getContext(), task.key.id, 620 task.activityLabel, launchOpts)) { 621 if (screenPinningRequested) { 622 mCb.onScreenPinningRequest(); 623 } 624 } else { 625 // Dismiss the task and return the user to home if we fail to 626 // launch the task 627 onTaskViewDismissed(task); 628 if (mCb != null) { 629 mCb.onTaskLaunchFailed(); 630 } 631 632 // Keep track of failed launches 633 MetricsLogger.count(getContext(), "overview_task_launch_failed", 1); 634 } 635 } 636 } 637 }; 638 639 // Keep track of the index of the task launch 640 int taskIndexFromFront = 0; 641 int taskIndex = stack.indexOfTask(task); 642 if (taskIndex > -1) { 643 taskIndexFromFront = stack.getTaskCount() - taskIndex - 1; 644 } 645 MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront); 646 647 // Launch the app right away if there is no task view, otherwise, animate the icon out first 648 if (tv == null) { 649 launchRunnable.run(); 650 } else { 651 if (task.group != null && !task.group.isFrontMostTask(task)) { 652 // For affiliated tasks that are behind other tasks, we must animate the front cards 653 // out of view before starting the task transition 654 stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask); 655 } else { 656 // Otherwise, we can start the task transition immediately 657 stackView.startLaunchTaskAnimation(tv, null, lockToTask); 658 launchRunnable.run(); 659 } 660 } 661 } 662 663 @Override 664 public void onTaskViewAppInfoClicked(Task t) { 665 // Create a new task stack with the application info details activity 666 Intent baseIntent = t.key.baseIntent; 667 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 668 Uri.fromParts("package", baseIntent.getComponent().getPackageName(), null)); 669 intent.setComponent(intent.resolveActivity(getContext().getPackageManager())); 670 TaskStackBuilder.create(getContext()) 671 .addNextIntentWithParentStack(intent).startActivities(null, 672 new UserHandle(t.key.userId)); 673 } 674 675 @Override 676 public void onTaskViewDismissed(Task t) { 677 // Remove any stored data from the loader. We currently don't bother notifying the views 678 // that the data has been unloaded because at the point we call onTaskViewDismissed(), the views 679 // either don't need to be updated, or have already been removed. 680 RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); 681 loader.deleteTaskData(t, false); 682 683 // Remove the old task from activity manager 684 loader.getSystemServicesProxy().removeTask(t.key.id); 685 } 686 687 @Override 688 public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks) { 689 if (removedTasks != null) { 690 int taskCount = removedTasks.size(); 691 for (int i = 0; i < taskCount; i++) { 692 onTaskViewDismissed(removedTasks.get(i)); 693 } 694 } 695 696 mCb.onAllTaskViewsDismissed(); 697 698 // Keep track of all-deletions 699 MetricsLogger.count(getContext(), "overview_task_all_dismissed", 1); 700 } 701 702 /** Final callback after Recents is finally hidden. */ 703 public void onRecentsHidden() { 704 // Notify each task stack view 705 if (mTaskStackView != null) { 706 mTaskStackView.onRecentsHidden(); 707 } 708 } 709 710 @Override 711 public void onTaskStackFilterTriggered() { 712 // Hide the search bar 713 if (mSearchBar != null) { 714 mSearchBar.animate() 715 .alpha(0f) 716 .setStartDelay(0) 717 .setInterpolator(mConfig.fastOutSlowInInterpolator) 718 .setDuration(mConfig.filteringCurrentViewsAnimDuration) 719 .withLayer() 720 .start(); 721 } 722 } 723 724 @Override 725 public void onTaskStackUnfilterTriggered() { 726 // Show the search bar 727 if (mSearchBar != null) { 728 mSearchBar.animate() 729 .alpha(1f) 730 .setStartDelay(0) 731 .setInterpolator(mConfig.fastOutSlowInInterpolator) 732 .setDuration(mConfig.filteringNewViewsAnimDuration) 733 .withLayer() 734 .start(); 735 } 736 } 737 738 @Override 739 public void onTaskResize(Task t) { 740 if (mCb != null) { 741 mCb.onTaskResize(t); 742 } 743 } 744 745 /**** RecentsPackageMonitor.PackageCallbacks Implementation ****/ 746 747 @Override 748 public void onPackagesChanged(RecentsPackageMonitor monitor, String packageName, int userId) { 749 // Propagate this event down to each task stack view 750 if (mTaskStackView != null) { 751 mTaskStackView.onPackagesChanged(monitor, packageName, userId); 752 } 753 } 754} 755