RecentsView.java revision ef06413afce31800dc8dfee65e5f89bb610f192a
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.content.Context; 20import android.content.res.Resources; 21import android.graphics.Canvas; 22import android.graphics.Rect; 23import android.graphics.drawable.Drawable; 24import android.os.Handler; 25import android.util.ArraySet; 26import android.util.AttributeSet; 27import android.view.LayoutInflater; 28import android.view.MotionEvent; 29import android.view.View; 30import android.view.ViewPropertyAnimator; 31import android.view.WindowInsets; 32import android.view.animation.AnimationUtils; 33import android.view.animation.Interpolator; 34import android.widget.FrameLayout; 35import com.android.internal.logging.MetricsLogger; 36import android.widget.TextView; 37import com.android.systemui.R; 38import com.android.systemui.recents.Recents; 39import com.android.systemui.recents.RecentsActivity; 40import com.android.systemui.recents.RecentsActivityLaunchState; 41import com.android.systemui.recents.RecentsAppWidgetHostView; 42import com.android.systemui.recents.RecentsConfiguration; 43import com.android.systemui.recents.RecentsDebugFlags; 44import com.android.systemui.recents.events.EventBus; 45import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; 46import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent; 47import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; 48import com.android.systemui.recents.events.activity.HideHistoryButtonEvent; 49import com.android.systemui.recents.events.activity.HideHistoryEvent; 50import com.android.systemui.recents.events.activity.LaunchTaskEvent; 51import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent; 52import com.android.systemui.recents.events.activity.ShowHistoryEvent; 53import com.android.systemui.recents.events.activity.TaskStackUpdatedEvent; 54import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; 55import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; 56import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; 57import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; 58import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; 59import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; 60import com.android.systemui.recents.misc.ReferenceCountedTrigger; 61import com.android.systemui.recents.misc.SystemServicesProxy; 62import com.android.systemui.recents.model.Task; 63import com.android.systemui.recents.model.TaskStack; 64import com.android.systemui.stackdivider.WindowManagerProxy; 65import com.android.systemui.statusbar.FlingAnimationUtils; 66 67import java.util.ArrayList; 68import java.util.List; 69 70import static android.app.ActivityManager.StackId.INVALID_STACK_ID; 71 72/** 73 * This view is the the top level layout that contains TaskStacks (which are laid out according 74 * to their SpaceNode bounds. 75 */ 76public class RecentsView extends FrameLayout { 77 78 private static final String TAG = "RecentsView"; 79 private static final boolean DEBUG = false; 80 81 private final Handler mHandler; 82 83 private TaskStack mStack; 84 private TaskStackView mTaskStackView; 85 private RecentsAppWidgetHostView mSearchBar; 86 private TextView mHistoryButton; 87 private View mEmptyView; 88 private boolean mAwaitingFirstLayout = true; 89 private boolean mLastTaskLaunchedWasFreeform; 90 private Rect mSystemInsets = new Rect(); 91 92 private RecentsTransitionHelper mTransitionHelper; 93 private RecentsViewTouchHandler mTouchHandler; 94 private TaskStack.DockState[] mVisibleDockStates = { 95 TaskStack.DockState.LEFT, 96 TaskStack.DockState.TOP, 97 TaskStack.DockState.RIGHT, 98 TaskStack.DockState.BOTTOM, 99 }; 100 101 private final Interpolator mFastOutSlowInInterpolator; 102 private final Interpolator mFastOutLinearInInterpolator; 103 private final FlingAnimationUtils mFlingAnimationUtils; 104 105 public RecentsView(Context context) { 106 this(context, null); 107 } 108 109 public RecentsView(Context context, AttributeSet attrs) { 110 this(context, attrs, 0); 111 } 112 113 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { 114 this(context, attrs, defStyleAttr, 0); 115 } 116 117 public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 118 super(context, attrs, defStyleAttr, defStyleRes); 119 Resources res = context.getResources(); 120 setWillNotDraw(false); 121 mHandler = new Handler(); 122 mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler); 123 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, 124 com.android.internal.R.interpolator.fast_out_slow_in); 125 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context, 126 com.android.internal.R.interpolator.fast_out_linear_in); 127 mTouchHandler = new RecentsViewTouchHandler(this); 128 mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f); 129 130 LayoutInflater inflater = LayoutInflater.from(context); 131 mHistoryButton = (TextView) inflater.inflate(R.layout.recents_history_button, this, false); 132 mHistoryButton.setOnClickListener(new View.OnClickListener() { 133 @Override 134 public void onClick(View v) { 135 EventBus.getDefault().send(new ShowHistoryEvent()); 136 } 137 }); 138 addView(mHistoryButton); 139 mEmptyView = inflater.inflate(R.layout.recents_empty, this, false); 140 addView(mEmptyView); 141 } 142 143 /** Set/get the bsp root node */ 144 public void setTaskStack(TaskStack stack) { 145 RecentsConfiguration config = Recents.getConfiguration(); 146 RecentsActivityLaunchState launchState = config.getLaunchState(); 147 mStack = stack; 148 // Disable reusing task stack views until the visibility bug is fixed. b/25998134 149 if (false && launchState.launchedReuseTaskStackViews) { 150 if (mTaskStackView != null) { 151 // If onRecentsHidden is not triggered, we need to the stack view again here 152 mTaskStackView.reset(); 153 mTaskStackView.setStack(stack); 154 removeView(mTaskStackView); 155 addView(mTaskStackView); 156 } else { 157 mTaskStackView = new TaskStackView(getContext(), stack); 158 addView(mTaskStackView); 159 } 160 } else { 161 if (mTaskStackView != null) { 162 removeView(mTaskStackView); 163 } 164 mTaskStackView = new TaskStackView(getContext(), stack); 165 addView(mTaskStackView); 166 } 167 168 // Update the top level view's visibilities 169 if (stack.getStackTaskCount() > 0) { 170 hideEmptyView(); 171 } else { 172 showEmptyView(); 173 } 174 175 // Trigger a new layout 176 requestLayout(); 177 } 178 179 /** 180 * Returns whether the last task launched was in the freeform stack or not. 181 */ 182 public boolean isLastTaskLaunchedFreeform() { 183 return mLastTaskLaunchedWasFreeform; 184 } 185 186 /** 187 * Returns the currently set task stack. 188 */ 189 public TaskStack getTaskStack() { 190 return mStack; 191 } 192 193 /** Gets the next task in the stack - or if the last - the top task */ 194 public Task getNextTaskOrTopTask(Task taskToSearch) { 195 Task returnTask = null; 196 boolean found = false; 197 if (mTaskStackView != null) { 198 TaskStack stack = mTaskStackView.getStack(); 199 ArrayList<Task> taskList = stack.getStackTasks(); 200 // Iterate the stack views and try and find the focused task 201 for (int j = taskList.size() - 1; j >= 0; --j) { 202 Task task = taskList.get(j); 203 // Return the next task in the line. 204 if (found) 205 return task; 206 // Remember the first possible task as the top task. 207 if (returnTask == null) 208 returnTask = task; 209 if (task == taskToSearch) 210 found = true; 211 } 212 } 213 return returnTask; 214 } 215 216 /** Launches the focused task from the first stack if possible */ 217 public boolean launchFocusedTask() { 218 if (mTaskStackView != null) { 219 TaskStack stack = mTaskStackView.getStack(); 220 Task task = mTaskStackView.getFocusedTask(); 221 if (task != null) { 222 TaskView taskView = mTaskStackView.getChildViewForTask(task); 223 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, 224 INVALID_STACK_ID, false)); 225 return true; 226 } 227 } 228 return false; 229 } 230 231 /** Launches the task that recents was launched from if possible */ 232 public boolean launchPreviousTask() { 233 if (mTaskStackView != null) { 234 TaskStack stack = mTaskStackView.getStack(); 235 Task task = stack.getLaunchTarget(); 236 if (task != null) { 237 TaskView taskView = mTaskStackView.getChildViewForTask(task); 238 EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, 239 INVALID_STACK_ID, false)); 240 return true; 241 } 242 } 243 return false; 244 } 245 246 /** Launches a given task. */ 247 public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { 248 if (mTaskStackView != null) { 249 TaskStack stack = mTaskStackView.getStack(); 250 // Iterate the stack views and try and find the given task. 251 List<TaskView> taskViews = mTaskStackView.getTaskViews(); 252 int taskViewCount = taskViews.size(); 253 for (int j = 0; j < taskViewCount; j++) { 254 TaskView tv = taskViews.get(j); 255 if (tv.getTask() == task) { 256 EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds, 257 destinationStack, false)); 258 return true; 259 } 260 } 261 } 262 return false; 263 } 264 265 /** Adds the search bar */ 266 public void setSearchBar(RecentsAppWidgetHostView searchBar) { 267 // Remove the previous search bar if one exists 268 if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { 269 removeView(mSearchBar); 270 } 271 // Add the new search bar 272 if (searchBar != null) { 273 mSearchBar = searchBar; 274 addView(mSearchBar); 275 } 276 } 277 278 /** Returns whether there is currently a search bar */ 279 public boolean hasValidSearchBar() { 280 return mSearchBar != null && !mSearchBar.isReinflateRequired(); 281 } 282 283 /** 284 * Hides the task stack and shows the empty view. 285 */ 286 public void showEmptyView() { 287 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { 288 mSearchBar.setVisibility(View.INVISIBLE); 289 } 290 mTaskStackView.setVisibility(View.INVISIBLE); 291 mEmptyView.setVisibility(View.VISIBLE); 292 mEmptyView.bringToFront(); 293 mHistoryButton.bringToFront(); 294 } 295 296 /** 297 * Shows the task stack and hides the empty view. 298 */ 299 public void hideEmptyView() { 300 mEmptyView.setVisibility(View.INVISIBLE); 301 mTaskStackView.setVisibility(View.VISIBLE); 302 if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { 303 mSearchBar.setVisibility(View.VISIBLE); 304 } 305 mTaskStackView.bringToFront(); 306 if (mSearchBar != null) { 307 mSearchBar.bringToFront(); 308 } 309 mHistoryButton.bringToFront(); 310 } 311 312 /** 313 * Returns the last known system insets. 314 */ 315 public Rect getSystemInsets() { 316 return mSystemInsets; 317 } 318 319 @Override 320 protected void onAttachedToWindow() { 321 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); 322 EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 1); 323 super.onAttachedToWindow(); 324 } 325 326 @Override 327 protected void onDetachedFromWindow() { 328 super.onDetachedFromWindow(); 329 EventBus.getDefault().unregister(this); 330 EventBus.getDefault().unregister(mTouchHandler); 331 } 332 333 /** 334 * This is called with the full size of the window since we are handling our own insets. 335 */ 336 @Override 337 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 338 RecentsConfiguration config = Recents.getConfiguration(); 339 int width = MeasureSpec.getSize(widthMeasureSpec); 340 int height = MeasureSpec.getSize(heightMeasureSpec); 341 342 // Get the search bar bounds and measure the search bar layout 343 Rect searchBarSpaceBounds = new Rect(); 344 if (mSearchBar != null) { 345 config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top, 346 searchBarSpaceBounds); 347 mSearchBar.measure( 348 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), 349 MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); 350 } 351 352 Rect taskStackBounds = new Rect(); 353 config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top, 354 mSystemInsets.right, searchBarSpaceBounds, taskStackBounds); 355 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { 356 mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets); 357 mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); 358 } 359 360 // Measure the empty view 361 measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 362 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); 363 364 // Measure the history button with the full space above the stack, but width-constrained 365 // to the stack 366 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; 367 measureChild(mHistoryButton, 368 MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.EXACTLY), 369 MeasureSpec.makeMeasureSpec(historyButtonRect.height(), 370 MeasureSpec.EXACTLY)); 371 372 setMeasuredDimension(width, height); 373 } 374 375 /** 376 * This is called with the full size of the window since we are handling our own insets. 377 */ 378 @Override 379 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 380 RecentsConfiguration config = Recents.getConfiguration(); 381 382 // Get the search bar bounds so that we lay it out 383 Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); 384 Rect searchBarSpaceBounds = new Rect(); 385 if (mSearchBar != null) { 386 config.getSearchBarBounds(measuredRect, 387 mSystemInsets.top, searchBarSpaceBounds); 388 mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, 389 searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); 390 } 391 392 if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { 393 mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); 394 } 395 396 // Layout the empty view 397 mEmptyView.layout(left, top, right, bottom); 398 399 // Layout the history button left-aligned with the stack, but offset from the top of the 400 // view 401 Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; 402 mHistoryButton.layout(historyButtonRect.left, historyButtonRect.top, 403 historyButtonRect.right, historyButtonRect.bottom); 404 405 if (mAwaitingFirstLayout) { 406 mAwaitingFirstLayout = false; 407 408 // If launched via dragging from the nav bar, then we should translate the whole view 409 // down offscreen 410 RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); 411 if (launchState.launchedViaDragGesture) { 412 setTranslationY(getMeasuredHeight()); 413 } else { 414 setTranslationY(0f); 415 } 416 } 417 } 418 419 @Override 420 public WindowInsets onApplyWindowInsets(WindowInsets insets) { 421 mSystemInsets.set(insets.getSystemWindowInsets()); 422 requestLayout(); 423 return insets; 424 } 425 426 @Override 427 public boolean onInterceptTouchEvent(MotionEvent ev) { 428 return mTouchHandler.onInterceptTouchEvent(ev); 429 } 430 431 @Override 432 public boolean onTouchEvent(MotionEvent ev) { 433 return mTouchHandler.onTouchEvent(ev); 434 } 435 436 @Override 437 protected void dispatchDraw(Canvas canvas) { 438 super.dispatchDraw(canvas); 439 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { 440 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; 441 if (d.getAlpha() > 0) { 442 d.draw(canvas); 443 } 444 } 445 } 446 447 @Override 448 protected boolean verifyDrawable(Drawable who) { 449 for (int i = mVisibleDockStates.length - 1; i >= 0; i--) { 450 Drawable d = mVisibleDockStates[i].viewState.dockAreaOverlay; 451 if (d == who) { 452 return true; 453 } 454 } 455 return super.verifyDrawable(who); 456 } 457 458 /**** EventBus Events ****/ 459 460 public final void onBusEvent(LaunchTaskEvent event) { 461 mLastTaskLaunchedWasFreeform = event.task.isFreeformTask(); 462 mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView, 463 event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack); 464 } 465 466 public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { 467 // Hide the history button 468 int taskViewExitToHomeDuration = getResources().getInteger( 469 R.integer.recents_task_exit_to_home_duration); 470 hideHistoryButton(taskViewExitToHomeDuration); 471 472 // If we are going home, cancel the previous task's window transition 473 EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(null)); 474 } 475 476 public final void onBusEvent(DragStartEvent event) { 477 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), 478 TaskStack.DockState.NONE.viewState.dockAreaAlpha); 479 } 480 481 public final void onBusEvent(DragDropTargetChangedEvent event) { 482 if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { 483 updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), 484 TaskStack.DockState.NONE.viewState.dockAreaAlpha); 485 } else { 486 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; 487 updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, -1); 488 } 489 } 490 491 public final void onBusEvent(final DragEndEvent event) { 492 // Animate the overlay alpha back to 0 493 updateVisibleDockRegions(null, -1); 494 495 // Handle the case where we drop onto a dock region 496 if (event.dropTarget instanceof TaskStack.DockState) { 497 final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; 498 499 // Remove the task after it is docked 500 event.taskView.animate() 501 .alpha(0f) 502 .setDuration(150) 503 .setInterpolator(mFastOutLinearInInterpolator) 504 .setUpdateListener(null) 505 .setListener(null) 506 .withEndAction(new Runnable() { 507 @Override 508 public void run() { 509 mTaskStackView.getStack().removeTask(event.task); 510 } 511 }) 512 .withLayer() 513 .start(); 514 515 // Dock the task and launch it 516 SystemServicesProxy ssp = Recents.getSystemServices(); 517 ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode); 518 launchTask(event.task, null, INVALID_STACK_ID); 519 520 MetricsLogger.action(mContext, 521 MetricsLogger.ACTION_WINDOW_DOCK_DRAG_DROP); 522 } 523 } 524 525 public final void onBusEvent(DraggingInRecentsEvent event) { 526 if (mTaskStackView.getTaskViews().size() > 0) { 527 setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); 528 } 529 } 530 531 public final void onBusEvent(DraggingInRecentsEndedEvent event) { 532 ViewPropertyAnimator animator = animate(); 533 if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) { 534 animator.translationY(getHeight()); 535 animator.withEndAction(new Runnable() { 536 @Override 537 public void run() { 538 WindowManagerProxy.getInstance().maximizeDockedStack(); 539 } 540 }); 541 mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity); 542 } else { 543 animator.translationY(0f); 544 animator.setListener(null); 545 mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity); 546 } 547 animator.start(); 548 } 549 550 public final void onBusEvent(ShowHistoryEvent event) { 551 // Hide the history button when the history view is shown 552 hideHistoryButton(getResources().getInteger(R.integer.recents_history_transition_duration), 553 event.getAnimationTrigger()); 554 event.addPostAnimationCallback(new Runnable() { 555 @Override 556 public void run() { 557 setAlpha(0f); 558 } 559 }); 560 } 561 562 public final void onBusEvent(HideHistoryEvent event) { 563 // Show the history button when the history view is hidden 564 setAlpha(1f); 565 showHistoryButton(getResources().getInteger(R.integer.recents_history_transition_duration), 566 event.getAnimationTrigger()); 567 } 568 569 public final void onBusEvent(ShowHistoryButtonEvent event) { 570 showHistoryButton(150); 571 } 572 573 public final void onBusEvent(HideHistoryButtonEvent event) { 574 hideHistoryButton(100); 575 } 576 577 public final void onBusEvent(TaskStackUpdatedEvent event) { 578 mStack.setTasks(event.stack.computeAllTasksList(), true /* notifyStackChanges */); 579 mStack.createAffiliatedGroupings(getContext()); 580 } 581 582 /** 583 * Shows the history button. 584 */ 585 private void showHistoryButton(final int duration) { 586 ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); 587 showHistoryButton(duration, postAnimationTrigger); 588 postAnimationTrigger.flushLastDecrementRunnables(); 589 } 590 591 private void showHistoryButton(final int duration, 592 final ReferenceCountedTrigger postHideHistoryAnimationTrigger) { 593 mHistoryButton.setVisibility(View.VISIBLE); 594 mHistoryButton.setAlpha(0f); 595 mHistoryButton.setText(getContext().getString(R.string.recents_history_label_format, 596 mStack.getHistoricalTasks().size())); 597 postHideHistoryAnimationTrigger.addLastDecrementRunnable(new Runnable() { 598 @Override 599 public void run() { 600 mHistoryButton.animate() 601 .alpha(1f) 602 .setDuration(duration) 603 .setInterpolator(mFastOutSlowInInterpolator) 604 .withLayer() 605 .start(); 606 } 607 }); 608 } 609 610 /** 611 * Hides the history button. 612 */ 613 private void hideHistoryButton(int duration) { 614 ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); 615 hideHistoryButton(duration, postAnimationTrigger); 616 postAnimationTrigger.flushLastDecrementRunnables(); 617 } 618 619 private void hideHistoryButton(int duration, 620 final ReferenceCountedTrigger postHideStackAnimationTrigger) { 621 mHistoryButton.animate() 622 .alpha(0f) 623 .setDuration(duration) 624 .setInterpolator(mFastOutLinearInInterpolator) 625 .withEndAction(new Runnable() { 626 @Override 627 public void run() { 628 mHistoryButton.setVisibility(View.INVISIBLE); 629 postHideStackAnimationTrigger.decrement(); 630 } 631 }) 632 .withLayer() 633 .start(); 634 postHideStackAnimationTrigger.increment(); 635 } 636 637 /** 638 * Updates the dock region to match the specified dock state. 639 */ 640 private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, int overrideAlpha) { 641 ArraySet<TaskStack.DockState> newDockStatesSet = new ArraySet<>(); 642 if (newDockStates != null) { 643 for (TaskStack.DockState dockState : newDockStates) { 644 newDockStatesSet.add(dockState); 645 } 646 } 647 for (TaskStack.DockState dockState : mVisibleDockStates) { 648 TaskStack.DockState.ViewState viewState = dockState.viewState; 649 if (newDockStates == null || !newDockStatesSet.contains(dockState)) { 650 // This is no longer visible, so hide it 651 viewState.startAlphaAnimation(0, 150); 652 } else { 653 // This state is now visible, update the bounds and show it 654 int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); 655 viewState.dockAreaOverlay.setBounds( 656 dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight())); 657 viewState.dockAreaOverlay.setCallback(this); 658 viewState.startAlphaAnimation(alpha, 150); 659 } 660 } 661 } 662 663 public final void onBusEvent(RecentsVisibilityChangedEvent event) { 664 if (!event.visible) { 665 // Reset the view state 666 mAwaitingFirstLayout = true; 667 mLastTaskLaunchedWasFreeform = false; 668 } 669 } 670} 671