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