TaskView.java revision 67387af732f1b5e9b9bc270f03dbb1aedd5632cc
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 static android.app.ActivityManager.StackId.INVALID_STACK_ID; 20 21import android.animation.Animator; 22import android.animation.AnimatorSet; 23import android.animation.ObjectAnimator; 24import android.animation.ValueAnimator; 25import android.app.ActivityManager; 26import android.content.Context; 27import android.content.res.Resources; 28import android.graphics.Outline; 29import android.graphics.Point; 30import android.graphics.Rect; 31import android.util.AttributeSet; 32import android.util.FloatProperty; 33import android.util.Property; 34import android.view.MotionEvent; 35import android.view.View; 36import android.view.ViewDebug; 37import android.view.ViewOutlineProvider; 38import android.widget.TextView; 39import android.widget.Toast; 40 41import com.android.internal.logging.MetricsLogger; 42import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 43import com.android.systemui.Interpolators; 44import com.android.systemui.R; 45import com.android.systemui.recents.Recents; 46import com.android.systemui.recents.RecentsActivity; 47import com.android.systemui.recents.RecentsConfiguration; 48import com.android.systemui.recents.events.EventBus; 49import com.android.systemui.recents.events.activity.LaunchTaskEvent; 50import com.android.systemui.recents.events.ui.DismissTaskViewEvent; 51import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; 52import com.android.systemui.recents.events.ui.dragndrop.DragEndCancelledEvent; 53import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; 54import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; 55import com.android.systemui.recents.misc.ReferenceCountedTrigger; 56import com.android.systemui.recents.misc.SystemServicesProxy; 57import com.android.systemui.recents.misc.Utilities; 58import com.android.systemui.recents.model.Task; 59import com.android.systemui.recents.model.TaskStack; 60 61import java.util.ArrayList; 62 63/** 64 * A {@link TaskView} represents a fixed view of a task. Because the TaskView's layout is directed 65 * solely by the {@link TaskStackView}, we make it a fixed size layout which allows relayouts down 66 * the view hierarchy, but not upwards from any of its children (the TaskView will relayout itself 67 * with the previous bounds if any child requests layout). 68 */ 69public class TaskView extends FixedSizeFrameLayout implements Task.TaskCallbacks, 70 TaskStackAnimationHelper.Callbacks, View.OnClickListener, View.OnLongClickListener { 71 72 /** The TaskView callbacks */ 73 interface TaskViewCallbacks { 74 void onTaskViewClipStateChanged(TaskView tv); 75 } 76 77 /** 78 * The dim overlay is generally calculated from the task progress, but occasionally (like when 79 * launching) needs to be animated independently of the task progress. This call is only used 80 * when animating the task into Recents, when the header dim is already applied 81 */ 82 public static final Property<TaskView, Float> DIM_ALPHA_WITHOUT_HEADER = 83 new FloatProperty<TaskView>("dimAlphaWithoutHeader") { 84 @Override 85 public void setValue(TaskView tv, float dimAlpha) { 86 tv.setDimAlphaWithoutHeader(dimAlpha); 87 } 88 89 @Override 90 public Float get(TaskView tv) { 91 return tv.getDimAlpha(); 92 } 93 }; 94 95 /** 96 * The dim overlay is generally calculated from the task progress, but occasionally (like when 97 * launching) needs to be animated independently of the task progress. 98 */ 99 public static final Property<TaskView, Float> DIM_ALPHA = 100 new FloatProperty<TaskView>("dimAlpha") { 101 @Override 102 public void setValue(TaskView tv, float dimAlpha) { 103 tv.setDimAlpha(dimAlpha); 104 } 105 106 @Override 107 public Float get(TaskView tv) { 108 return tv.getDimAlpha(); 109 } 110 }; 111 112 /** 113 * The dim overlay is generally calculated from the task progress, but occasionally (like when 114 * launching) needs to be animated independently of the task progress. 115 */ 116 public static final Property<TaskView, Float> VIEW_OUTLINE_ALPHA = 117 new FloatProperty<TaskView>("viewOutlineAlpha") { 118 @Override 119 public void setValue(TaskView tv, float alpha) { 120 tv.getViewBounds().setAlpha(alpha); 121 } 122 123 @Override 124 public Float get(TaskView tv) { 125 return tv.getViewBounds().getAlpha(); 126 } 127 }; 128 129 @ViewDebug.ExportedProperty(category="recents") 130 private float mDimAlpha; 131 private float mActionButtonTranslationZ; 132 133 @ViewDebug.ExportedProperty(deepExport=true, prefix="task_") 134 private Task mTask; 135 @ViewDebug.ExportedProperty(category="recents") 136 private boolean mClipViewInStack = true; 137 @ViewDebug.ExportedProperty(category="recents") 138 private boolean mTouchExplorationEnabled; 139 @ViewDebug.ExportedProperty(category="recents") 140 private boolean mIsDisabledInSafeMode; 141 @ViewDebug.ExportedProperty(deepExport=true, prefix="view_bounds_") 142 private AnimateableViewBounds mViewBounds; 143 144 private AnimatorSet mTransformAnimation; 145 private ObjectAnimator mDimAnimator; 146 private ObjectAnimator mOutlineAnimator; 147 private final TaskViewTransform mTargetAnimationTransform = new TaskViewTransform(); 148 private ArrayList<Animator> mTmpAnimators = new ArrayList<>(); 149 150 @ViewDebug.ExportedProperty(deepExport=true, prefix="thumbnail_") 151 TaskViewThumbnail mThumbnailView; 152 @ViewDebug.ExportedProperty(deepExport=true, prefix="header_") 153 TaskViewHeader mHeaderView; 154 private View mActionButtonView; 155 private View mIncompatibleAppToastView; 156 private TaskViewCallbacks mCb; 157 158 @ViewDebug.ExportedProperty(category="recents") 159 private Point mDownTouchPos = new Point(); 160 161 private Toast mDisabledAppToast; 162 163 public TaskView(Context context) { 164 this(context, null); 165 } 166 167 public TaskView(Context context, AttributeSet attrs) { 168 this(context, attrs, 0); 169 } 170 171 public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { 172 this(context, attrs, defStyleAttr, 0); 173 } 174 175 public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 176 super(context, attrs, defStyleAttr, defStyleRes); 177 RecentsConfiguration config = Recents.getConfiguration(); 178 Resources res = context.getResources(); 179 mViewBounds = new AnimateableViewBounds(this, res.getDimensionPixelSize( 180 R.dimen.recents_task_view_shadow_rounded_corners_radius)); 181 if (config.fakeShadows) { 182 setBackground(new FakeShadowDrawable(res, config)); 183 } 184 setOutlineProvider(mViewBounds); 185 setOnLongClickListener(this); 186 } 187 188 /** Set callback */ 189 void setCallbacks(TaskViewCallbacks cb) { 190 mCb = cb; 191 } 192 193 /** 194 * Called from RecentsActivity when it is relaunched. 195 */ 196 void onReload(boolean isResumingFromVisible) { 197 if (!Recents.getSystemServices().hasFreeformWorkspaceSupport()) { 198 resetNoUserInteractionState(); 199 } 200 if (!isResumingFromVisible) { 201 resetViewProperties(); 202 } 203 } 204 205 /** Gets the task */ 206 public Task getTask() { 207 return mTask; 208 } 209 210 /** Returns the view bounds. */ 211 AnimateableViewBounds getViewBounds() { 212 return mViewBounds; 213 } 214 215 @Override 216 protected void onFinishInflate() { 217 // Bind the views 218 mHeaderView = (TaskViewHeader) findViewById(R.id.task_view_bar); 219 mThumbnailView = (TaskViewThumbnail) findViewById(R.id.task_view_thumbnail); 220 mThumbnailView.updateClipToTaskBar(mHeaderView); 221 mActionButtonView = findViewById(R.id.lock_to_app_fab); 222 mActionButtonView.setOutlineProvider(new ViewOutlineProvider() { 223 @Override 224 public void getOutline(View view, Outline outline) { 225 // Set the outline to match the FAB background 226 outline.setOval(0, 0, mActionButtonView.getWidth(), mActionButtonView.getHeight()); 227 outline.setAlpha(0.35f); 228 } 229 }); 230 mActionButtonView.setOnClickListener(this); 231 mActionButtonTranslationZ = mActionButtonView.getTranslationZ(); 232 } 233 234 /** 235 * Update the task view when the configuration changes. 236 */ 237 void onConfigurationChanged() { 238 mHeaderView.onConfigurationChanged(); 239 } 240 241 @Override 242 protected void onSizeChanged(int w, int h, int oldw, int oldh) { 243 super.onSizeChanged(w, h, oldw, oldh); 244 if (w > 0 && h > 0) { 245 mHeaderView.onTaskViewSizeChanged(w, h); 246 mThumbnailView.onTaskViewSizeChanged(w, h); 247 248 mActionButtonView.setTranslationX(w - getMeasuredWidth()); 249 mActionButtonView.setTranslationY(h - getMeasuredHeight()); 250 } 251 } 252 253 @Override 254 public boolean hasOverlappingRendering() { 255 return false; 256 } 257 258 @Override 259 public boolean onInterceptTouchEvent(MotionEvent ev) { 260 if (ev.getAction() == MotionEvent.ACTION_DOWN) { 261 mDownTouchPos.set((int) (ev.getX() * getScaleX()), (int) (ev.getY() * getScaleY())); 262 } 263 return super.onInterceptTouchEvent(ev); 264 } 265 266 267 @Override 268 protected void measureContents(int width, int height) { 269 int widthWithoutPadding = width - mPaddingLeft - mPaddingRight; 270 int heightWithoutPadding = height - mPaddingTop - mPaddingBottom; 271 int widthSpec = MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY); 272 int heightSpec = MeasureSpec.makeMeasureSpec(heightWithoutPadding, MeasureSpec.EXACTLY); 273 274 // Measure the content 275 measureChildren(widthSpec, heightSpec); 276 277 setMeasuredDimension(width, height); 278 } 279 280 void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, 281 AnimationProps toAnimation, ValueAnimator.AnimatorUpdateListener updateCallback) { 282 RecentsConfiguration config = Recents.getConfiguration(); 283 cancelTransformAnimation(); 284 285 // Compose the animations for the transform 286 mTmpAnimators.clear(); 287 toTransform.applyToTaskView(this, mTmpAnimators, toAnimation, !config.fakeShadows); 288 if (toAnimation.isImmediate()) { 289 if (Float.compare(getDimAlpha(), toTransform.dimAlpha) != 0) { 290 setDimAlpha(toTransform.dimAlpha); 291 } 292 if (Float.compare(mViewBounds.getAlpha(), toTransform.viewOutlineAlpha) != 0) { 293 mViewBounds.setAlpha(toTransform.viewOutlineAlpha); 294 } 295 // Manually call back to the animator listener and update callback 296 if (toAnimation.getListener() != null) { 297 toAnimation.getListener().onAnimationEnd(null); 298 } 299 if (updateCallback != null) { 300 updateCallback.onAnimationUpdate(null); 301 } 302 } else { 303 // Both the progress and the update are a function of the bounds movement of the task 304 if (Float.compare(getDimAlpha(), toTransform.dimAlpha) != 0) { 305 mDimAnimator = ObjectAnimator.ofFloat(this, DIM_ALPHA, getDimAlpha(), 306 toTransform.dimAlpha); 307 mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, mDimAnimator)); 308 } 309 if (Float.compare(mViewBounds.getAlpha(), toTransform.viewOutlineAlpha) != 0) { 310 mOutlineAnimator = ObjectAnimator.ofFloat(this, VIEW_OUTLINE_ALPHA, 311 mViewBounds.getAlpha(), toTransform.viewOutlineAlpha); 312 mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, mOutlineAnimator)); 313 } 314 if (updateCallback != null) { 315 ValueAnimator updateCallbackAnim = ValueAnimator.ofInt(0, 1); 316 updateCallbackAnim.addUpdateListener(updateCallback); 317 mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, updateCallbackAnim)); 318 } 319 320 // Create the animator 321 mTransformAnimation = toAnimation.createAnimator(mTmpAnimators); 322 mTransformAnimation.start(); 323 mTargetAnimationTransform.copyFrom(toTransform); 324 } 325 } 326 327 /** Resets this view's properties */ 328 void resetViewProperties() { 329 cancelTransformAnimation(); 330 setDimAlpha(0); 331 setVisibility(View.VISIBLE); 332 getViewBounds().reset(); 333 getHeaderView().reset(); 334 TaskViewTransform.reset(this); 335 336 mActionButtonView.setScaleX(1f); 337 mActionButtonView.setScaleY(1f); 338 mActionButtonView.setAlpha(0f); 339 mActionButtonView.setTranslationX(0f); 340 mActionButtonView.setTranslationY(0f); 341 mActionButtonView.setTranslationZ(mActionButtonTranslationZ); 342 if (mIncompatibleAppToastView != null) { 343 mIncompatibleAppToastView.setVisibility(View.INVISIBLE); 344 } 345 } 346 347 /** 348 * @return whether we are animating towards {@param transform} 349 */ 350 boolean isAnimatingTo(TaskViewTransform transform) { 351 return mTransformAnimation != null && mTransformAnimation.isStarted() 352 && mTargetAnimationTransform.isSame(transform); 353 } 354 355 /** 356 * Cancels any current transform animations. 357 */ 358 public void cancelTransformAnimation() { 359 Utilities.cancelAnimationWithoutCallbacks(mTransformAnimation); 360 Utilities.cancelAnimationWithoutCallbacks(mDimAnimator); 361 Utilities.cancelAnimationWithoutCallbacks(mOutlineAnimator); 362 } 363 364 /** Enables/disables handling touch on this task view. */ 365 public void setTouchEnabled(boolean enabled) { 366 setOnClickListener(enabled ? this : null); 367 } 368 369 /** Animates this task view if the user does not interact with the stack after a certain time. */ 370 public void startNoUserInteractionAnimation() { 371 mHeaderView.startNoUserInteractionAnimation(); 372 } 373 374 /** Mark this task view that the user does has not interacted with the stack after a certain time. */ 375 void setNoUserInteractionState() { 376 mHeaderView.setNoUserInteractionState(); 377 } 378 379 /** Resets the state tracking that the user has not interacted with the stack after a certain time. */ 380 void resetNoUserInteractionState() { 381 mHeaderView.resetNoUserInteractionState(); 382 } 383 384 /** Dismisses this task. */ 385 void dismissTask() { 386 // Animate out the view and call the callback 387 final TaskView tv = this; 388 DismissTaskViewEvent dismissEvent = new DismissTaskViewEvent(tv); 389 dismissEvent.addPostAnimationCallback(new Runnable() { 390 @Override 391 public void run() { 392 EventBus.getDefault().send(new TaskViewDismissedEvent(mTask, tv, 393 new AnimationProps(TaskStackView.DEFAULT_SYNC_STACK_DURATION, 394 Interpolators.FAST_OUT_SLOW_IN))); 395 } 396 }); 397 EventBus.getDefault().send(dismissEvent); 398 } 399 400 /** 401 * Returns whether this view should be clipped, or any views below should clip against this 402 * view. 403 */ 404 boolean shouldClipViewInStack() { 405 // Never clip for freeform tasks or if invisible 406 if (mTask.isFreeformTask() || getVisibility() != View.VISIBLE) { 407 return false; 408 } 409 return mClipViewInStack; 410 } 411 412 /** Sets whether this view should be clipped, or clipped against. */ 413 void setClipViewInStack(boolean clip) { 414 if (clip != mClipViewInStack) { 415 mClipViewInStack = clip; 416 if (mCb != null) { 417 mCb.onTaskViewClipStateChanged(this); 418 } 419 } 420 } 421 422 public TaskViewHeader getHeaderView() { 423 return mHeaderView; 424 } 425 426 /** 427 * Sets the current dim. 428 */ 429 public void setDimAlpha(float dimAlpha) { 430 mDimAlpha = dimAlpha; 431 mThumbnailView.setDimAlpha(dimAlpha); 432 mHeaderView.setDimAlpha(dimAlpha); 433 } 434 435 /** 436 * Sets the current dim without updating the header's dim. 437 */ 438 public void setDimAlphaWithoutHeader(float dimAlpha) { 439 mDimAlpha = dimAlpha; 440 mThumbnailView.setDimAlpha(dimAlpha); 441 } 442 443 /** 444 * Returns the current dim. 445 */ 446 public float getDimAlpha() { 447 return mDimAlpha; 448 } 449 450 /** 451 * Explicitly sets the focused state of this task. 452 */ 453 public void setFocusedState(boolean isFocused, boolean requestViewFocus) { 454 if (isFocused) { 455 if (requestViewFocus && !isFocused()) { 456 requestFocus(); 457 } 458 } else { 459 if (isAccessibilityFocused() && mTouchExplorationEnabled) { 460 clearAccessibilityFocus(); 461 } 462 } 463 } 464 465 /** 466 * Shows the action button. 467 * @param fadeIn whether or not to animate the action button in. 468 * @param fadeInDuration the duration of the action button animation, only used if 469 * {@param fadeIn} is true. 470 */ 471 public void showActionButton(boolean fadeIn, int fadeInDuration) { 472 mActionButtonView.setVisibility(View.VISIBLE); 473 474 if (fadeIn && mActionButtonView.getAlpha() < 1f) { 475 mActionButtonView.animate() 476 .alpha(1f) 477 .scaleX(1f) 478 .scaleY(1f) 479 .setDuration(fadeInDuration) 480 .setInterpolator(Interpolators.ALPHA_IN) 481 .start(); 482 } else { 483 mActionButtonView.setScaleX(1f); 484 mActionButtonView.setScaleY(1f); 485 mActionButtonView.setAlpha(1f); 486 mActionButtonView.setTranslationZ(mActionButtonTranslationZ); 487 } 488 } 489 490 /** 491 * Immediately hides the action button. 492 * 493 * @param fadeOut whether or not to animate the action button out. 494 */ 495 public void hideActionButton(boolean fadeOut, int fadeOutDuration, boolean scaleDown, 496 final Animator.AnimatorListener animListener) { 497 if (fadeOut && mActionButtonView.getAlpha() > 0f) { 498 if (scaleDown) { 499 float toScale = 0.9f; 500 mActionButtonView.animate() 501 .scaleX(toScale) 502 .scaleY(toScale); 503 } 504 mActionButtonView.animate() 505 .alpha(0f) 506 .setDuration(fadeOutDuration) 507 .setInterpolator(Interpolators.ALPHA_OUT) 508 .withEndAction(new Runnable() { 509 @Override 510 public void run() { 511 if (animListener != null) { 512 animListener.onAnimationEnd(null); 513 } 514 mActionButtonView.setVisibility(View.INVISIBLE); 515 } 516 }) 517 .start(); 518 } else { 519 mActionButtonView.setAlpha(0f); 520 mActionButtonView.setVisibility(View.INVISIBLE); 521 if (animListener != null) { 522 animListener.onAnimationEnd(null); 523 } 524 } 525 } 526 527 /**** TaskStackAnimationHelper.Callbacks Implementation ****/ 528 529 @Override 530 public void onPrepareLaunchTargetForEnterAnimation() { 531 // These values will be animated in when onStartLaunchTargetEnterAnimation() is called 532 setDimAlphaWithoutHeader(0); 533 mActionButtonView.setAlpha(0f); 534 if (mIncompatibleAppToastView != null && 535 mIncompatibleAppToastView.getVisibility() == View.VISIBLE) { 536 mIncompatibleAppToastView.setAlpha(0f); 537 } 538 } 539 540 @Override 541 public void onStartLaunchTargetEnterAnimation(TaskViewTransform transform, int duration, 542 boolean screenPinningEnabled, ReferenceCountedTrigger postAnimationTrigger) { 543 Utilities.cancelAnimationWithoutCallbacks(mDimAnimator); 544 545 // Dim the view after the app window transitions down into recents 546 postAnimationTrigger.increment(); 547 AnimationProps animation = new AnimationProps(duration, Interpolators.ALPHA_OUT); 548 mDimAnimator = animation.apply(AnimationProps.DIM_ALPHA, ObjectAnimator.ofFloat(this, 549 DIM_ALPHA_WITHOUT_HEADER, getDimAlpha(), transform.dimAlpha)); 550 mDimAnimator.addListener(postAnimationTrigger.decrementOnAnimationEnd()); 551 mDimAnimator.start(); 552 553 if (screenPinningEnabled) { 554 showActionButton(true /* fadeIn */, duration /* fadeInDuration */); 555 } 556 557 if (mIncompatibleAppToastView != null && 558 mIncompatibleAppToastView.getVisibility() == View.VISIBLE) { 559 mIncompatibleAppToastView.animate() 560 .alpha(1f) 561 .setDuration(duration) 562 .setInterpolator(Interpolators.ALPHA_IN) 563 .start(); 564 } 565 } 566 567 @Override 568 public void onStartLaunchTargetLaunchAnimation(int duration, boolean screenPinningRequested, 569 ReferenceCountedTrigger postAnimationTrigger) { 570 Utilities.cancelAnimationWithoutCallbacks(mDimAnimator); 571 572 // Un-dim the view before/while launching the target 573 AnimationProps animation = new AnimationProps(duration, Interpolators.ALPHA_OUT); 574 mDimAnimator = animation.apply(AnimationProps.DIM_ALPHA, ObjectAnimator.ofFloat(this, 575 DIM_ALPHA, getDimAlpha(), 0)); 576 mDimAnimator.start(); 577 578 postAnimationTrigger.increment(); 579 hideActionButton(true /* fadeOut */, duration, 580 !screenPinningRequested /* scaleDown */, 581 postAnimationTrigger.decrementOnAnimationEnd()); 582 } 583 584 @Override 585 public void onStartFrontTaskEnterAnimation(boolean screenPinningEnabled) { 586 if (screenPinningEnabled) { 587 showActionButton(false /* fadeIn */, 0 /* fadeInDuration */); 588 } 589 } 590 591 /**** TaskCallbacks Implementation ****/ 592 593 public void onTaskBound(Task t, boolean touchExplorationEnabled, int displayOrientation, 594 Rect displayRect) { 595 SystemServicesProxy ssp = Recents.getSystemServices(); 596 mTouchExplorationEnabled = touchExplorationEnabled; 597 mTask = t; 598 mTask.addCallback(this); 599 mIsDisabledInSafeMode = !mTask.isSystemApp && ssp.isInSafeMode(); 600 mThumbnailView.bindToTask(mTask, mIsDisabledInSafeMode, displayOrientation, displayRect); 601 mHeaderView.bindToTask(mTask, mTouchExplorationEnabled, mIsDisabledInSafeMode); 602 603 if (!t.isDockable && ssp.hasDockedTask()) { 604 if (mIncompatibleAppToastView == null) { 605 mIncompatibleAppToastView = Utilities.findViewStubById(this, 606 R.id.incompatible_app_toast_stub).inflate(); 607 TextView msg = (TextView) findViewById(com.android.internal.R.id.message); 608 msg.setText(R.string.recents_incompatible_app_message); 609 } 610 mIncompatibleAppToastView.setVisibility(View.VISIBLE); 611 } else if (mIncompatibleAppToastView != null) { 612 mIncompatibleAppToastView.setVisibility(View.INVISIBLE); 613 } 614 } 615 616 @Override 617 public void onTaskDataLoaded(Task task, ActivityManager.TaskThumbnailInfo thumbnailInfo) { 618 // Update each of the views to the new task data 619 mThumbnailView.onTaskDataLoaded(thumbnailInfo); 620 mHeaderView.onTaskDataLoaded(); 621 } 622 623 @Override 624 public void onTaskDataUnloaded() { 625 // Unbind each of the views from the task and remove the task callback 626 mTask.removeCallback(this); 627 mThumbnailView.unbindFromTask(); 628 mHeaderView.unbindFromTask(mTouchExplorationEnabled); 629 } 630 631 @Override 632 public void onTaskStackIdChanged() { 633 // Force rebind the header, the thumbnail does not change due to stack changes 634 mHeaderView.bindToTask(mTask, mTouchExplorationEnabled, mIsDisabledInSafeMode); 635 mHeaderView.onTaskDataLoaded(); 636 } 637 638 /**** View.OnClickListener Implementation ****/ 639 640 @Override 641 public void onClick(final View v) { 642 if (mIsDisabledInSafeMode) { 643 Context context = getContext(); 644 String msg = context.getString(R.string.recents_launch_disabled_message, mTask.title); 645 if (mDisabledAppToast != null) { 646 mDisabledAppToast.cancel(); 647 } 648 mDisabledAppToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); 649 mDisabledAppToast.show(); 650 return; 651 } 652 653 boolean screenPinningRequested = false; 654 if (v == mActionButtonView) { 655 // Reset the translation of the action button before we animate it out 656 mActionButtonView.setTranslationZ(0f); 657 screenPinningRequested = true; 658 } 659 EventBus.getDefault().send(new LaunchTaskEvent(this, mTask, null, INVALID_STACK_ID, 660 screenPinningRequested)); 661 662 MetricsLogger.action(v.getContext(), MetricsEvent.ACTION_OVERVIEW_SELECT, 663 mTask.key.getComponent().toString()); 664 } 665 666 /**** View.OnLongClickListener Implementation ****/ 667 668 @Override 669 public boolean onLongClick(View v) { 670 SystemServicesProxy ssp = Recents.getSystemServices(); 671 boolean inBounds = false; 672 Rect clipBounds = new Rect(mViewBounds.mClipBounds); 673 if (!clipBounds.isEmpty()) { 674 // If we are clipping the view to the bounds, manually do the hit test. 675 clipBounds.scale(getScaleX()); 676 inBounds = clipBounds.contains(mDownTouchPos.x, mDownTouchPos.y); 677 } else { 678 // Otherwise just make sure we're within the view's bounds. 679 inBounds = mDownTouchPos.x <= getWidth() && mDownTouchPos.y <= getHeight(); 680 } 681 if (v == this && inBounds && !ssp.hasDockedTask()) { 682 // Start listening for drag events 683 setClipViewInStack(false); 684 685 mDownTouchPos.x += ((1f - getScaleX()) * getWidth()) / 2; 686 mDownTouchPos.y += ((1f - getScaleY()) * getHeight()) / 2; 687 688 EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); 689 EventBus.getDefault().send(new DragStartEvent(mTask, this, mDownTouchPos)); 690 return true; 691 } 692 return false; 693 } 694 695 /**** Events ****/ 696 697 public final void onBusEvent(DragEndEvent event) { 698 if (!(event.dropTarget instanceof TaskStack.DockState)) { 699 event.addPostAnimationCallback(() -> { 700 // Reset the clip state for the drag view after the end animation completes 701 setClipViewInStack(true); 702 }); 703 } 704 EventBus.getDefault().unregister(this); 705 } 706 707 public final void onBusEvent(DragEndCancelledEvent event) { 708 // Reset the clip state for the drag view after the cancel animation completes 709 event.addPostAnimationCallback(() -> { 710 setClipViewInStack(true); 711 }); 712 } 713} 714