TaskView.java revision a74f385ba08922c09aa812f0d6fd2903a633da01
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.animation.Animator; 20import android.animation.ObjectAnimator; 21import android.animation.ValueAnimator; 22import android.content.Context; 23import android.graphics.*; 24import android.util.AttributeSet; 25import android.view.View; 26import android.view.ViewOutlineProvider; 27import android.view.animation.AccelerateInterpolator; 28import android.widget.FrameLayout; 29import com.android.systemui.R; 30import com.android.systemui.recents.Constants; 31import com.android.systemui.recents.RecentsConfiguration; 32import com.android.systemui.recents.misc.Utilities; 33import com.android.systemui.recents.model.Task; 34import com.android.systemui.statusbar.phone.PhoneStatusBar; 35 36/* A task view */ 37public class TaskView extends FrameLayout implements Task.TaskCallbacks, 38 View.OnClickListener, View.OnLongClickListener { 39 40 /** The TaskView callbacks */ 41 interface TaskViewCallbacks { 42 public void onTaskViewAppIconClicked(TaskView tv); 43 public void onTaskViewAppInfoClicked(TaskView tv); 44 public void onTaskViewClicked(TaskView tv, Task task, boolean lockToTask); 45 public void onTaskViewDismissed(TaskView tv); 46 public void onTaskViewClipStateChanged(TaskView tv); 47 public void onTaskViewFocusChanged(TaskView tv, boolean focused); 48 49 public void onTaskResize(TaskView tv); 50 } 51 52 RecentsConfiguration mConfig; 53 54 float mTaskProgress; 55 ObjectAnimator mTaskProgressAnimator; 56 float mMaxDimScale; 57 int mDimAlpha; 58 AccelerateInterpolator mDimInterpolator = new AccelerateInterpolator(1f); 59 PorterDuffColorFilter mDimColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_ATOP); 60 Paint mDimLayerPaint = new Paint(); 61 float mActionButtonTranslationZ; 62 63 Task mTask; 64 boolean mTaskDataLoaded; 65 boolean mIsFocused; 66 boolean mFocusAnimationsEnabled; 67 boolean mClipViewInStack; 68 AnimateableViewBounds mViewBounds; 69 70 View mContent; 71 TaskViewThumbnail mThumbnailView; 72 TaskViewHeader mHeaderView; 73 View mActionButtonView; 74 TaskViewCallbacks mCb; 75 76 // Optimizations 77 ValueAnimator.AnimatorUpdateListener mUpdateDimListener = 78 new ValueAnimator.AnimatorUpdateListener() { 79 @Override 80 public void onAnimationUpdate(ValueAnimator animation) { 81 setTaskProgress((Float) animation.getAnimatedValue()); 82 } 83 }; 84 85 86 public TaskView(Context context) { 87 this(context, null); 88 } 89 90 public TaskView(Context context, AttributeSet attrs) { 91 this(context, attrs, 0); 92 } 93 94 public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { 95 this(context, attrs, defStyleAttr, 0); 96 } 97 98 public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 99 super(context, attrs, defStyleAttr, defStyleRes); 100 mConfig = RecentsConfiguration.getInstance(); 101 mMaxDimScale = mConfig.taskStackMaxDim / 255f; 102 mClipViewInStack = true; 103 mViewBounds = new AnimateableViewBounds(this, mConfig.taskViewRoundedCornerRadiusPx); 104 setTaskProgress(getTaskProgress()); 105 setDim(getDim()); 106 if (mConfig.fakeShadows) { 107 setBackground(new FakeShadowDrawable(context.getResources(), mConfig)); 108 } 109 setOutlineProvider(mViewBounds); 110 } 111 112 /** Set callback */ 113 void setCallbacks(TaskViewCallbacks cb) { 114 mCb = cb; 115 } 116 117 /** Resets this TaskView for reuse. */ 118 void reset() { 119 resetViewProperties(); 120 resetNoUserInteractionState(); 121 setClipViewInStack(false); 122 setCallbacks(null); 123 } 124 125 /** Gets the task */ 126 Task getTask() { 127 return mTask; 128 } 129 130 /** Returns the view bounds. */ 131 AnimateableViewBounds getViewBounds() { 132 return mViewBounds; 133 } 134 135 @Override 136 protected void onFinishInflate() { 137 // Bind the views 138 mContent = findViewById(R.id.task_view_content); 139 mHeaderView = (TaskViewHeader) findViewById(R.id.task_view_bar); 140 mThumbnailView = (TaskViewThumbnail) findViewById(R.id.task_view_thumbnail); 141 mThumbnailView.updateClipToTaskBar(mHeaderView); 142 mActionButtonView = findViewById(R.id.lock_to_app_fab); 143 mActionButtonView.setOutlineProvider(new ViewOutlineProvider() { 144 @Override 145 public void getOutline(View view, Outline outline) { 146 // Set the outline to match the FAB background 147 outline.setOval(0, 0, mActionButtonView.getWidth(), mActionButtonView.getHeight()); 148 } 149 }); 150 mActionButtonTranslationZ = mActionButtonView.getTranslationZ(); 151 } 152 153 @Override 154 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 155 int width = MeasureSpec.getSize(widthMeasureSpec); 156 int height = MeasureSpec.getSize(heightMeasureSpec); 157 158 int widthWithoutPadding = width - mPaddingLeft - mPaddingRight; 159 int heightWithoutPadding = height - mPaddingTop - mPaddingBottom; 160 161 // Measure the content 162 mContent.measure(MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), 163 MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY)); 164 165 // Measure the bar view, and action button 166 mHeaderView.measure(MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), 167 MeasureSpec.makeMeasureSpec(mConfig.taskBarHeight, MeasureSpec.EXACTLY)); 168 mActionButtonView.measure( 169 MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.AT_MOST), 170 MeasureSpec.makeMeasureSpec(heightWithoutPadding, MeasureSpec.AT_MOST)); 171 // Measure the thumbnail to be square 172 mThumbnailView.measure( 173 MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), 174 MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY)); 175 setMeasuredDimension(width, height); 176 invalidateOutline(); 177 } 178 179 /** Synchronizes this view's properties with the task's transform */ 180 void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, int duration) { 181 updateViewPropertiesToTaskTransform(toTransform, duration, null); 182 } 183 184 void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, int duration, 185 ValueAnimator.AnimatorUpdateListener updateCallback) { 186 // Apply the transform 187 toTransform.applyToTaskView(this, duration, mConfig.fastOutSlowInInterpolator, false, 188 !mConfig.fakeShadows, updateCallback); 189 190 // Update the task progress 191 Utilities.cancelAnimationWithoutCallbacks(mTaskProgressAnimator); 192 if (duration <= 0) { 193 setTaskProgress(toTransform.p); 194 } else { 195 mTaskProgressAnimator = ObjectAnimator.ofFloat(this, "taskProgress", toTransform.p); 196 mTaskProgressAnimator.setDuration(duration); 197 mTaskProgressAnimator.addUpdateListener(mUpdateDimListener); 198 mTaskProgressAnimator.start(); 199 } 200 } 201 202 /** Resets this view's properties */ 203 void resetViewProperties() { 204 setDim(0); 205 setLayerType(View.LAYER_TYPE_NONE, null); 206 TaskViewTransform.reset(this); 207 if (mActionButtonView != null) { 208 mActionButtonView.setScaleX(1f); 209 mActionButtonView.setScaleY(1f); 210 mActionButtonView.setAlpha(1f); 211 mActionButtonView.setTranslationZ(mActionButtonTranslationZ); 212 } 213 } 214 215 /** 216 * When we are un/filtering, this method will set up the transform that we are animating to, 217 * in order to hide the task. 218 */ 219 void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { 220 // Fade the view out and slide it away 221 toTransform.alpha = 0f; 222 toTransform.translationY += 200; 223 toTransform.translationZ = 0; 224 } 225 226 /** 227 * When we are un/filtering, this method will setup the transform that we are animating from, 228 * in order to show the task. 229 */ 230 void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { 231 // Fade the view in 232 fromTransform.alpha = 0f; 233 } 234 235 /** Prepares this task view for the enter-recents animations. This is called earlier in the 236 * first layout because the actual animation into recents may take a long time. */ 237 void prepareEnterRecentsAnimation(boolean isTaskViewLaunchTargetTask, 238 boolean occludesLaunchTarget, int offscreenY) { 239 int initialDim = getDim(); 240 if (mConfig.launchedHasConfigurationChanged) { 241 // Just load the views as-is 242 } else if (mConfig.launchedFromAppWithThumbnail) { 243 if (isTaskViewLaunchTargetTask) { 244 // Set the dim to 0 so we can animate it in 245 initialDim = 0; 246 // Hide the action button 247 mActionButtonView.setAlpha(0f); 248 } else if (occludesLaunchTarget) { 249 // Move the task view off screen (below) so we can animate it in 250 setTranslationY(offscreenY); 251 } 252 253 } else if (mConfig.launchedFromHome) { 254 // Move the task view off screen (below) so we can animate it in 255 setTranslationY(offscreenY); 256 setTranslationZ(0); 257 setScaleX(1f); 258 setScaleY(1f); 259 } 260 // Apply the current dim 261 setDim(initialDim); 262 // Prepare the thumbnail view alpha 263 mThumbnailView.prepareEnterRecentsAnimation(isTaskViewLaunchTargetTask); 264 } 265 266 /** Animates this task view as it enters recents */ 267 void startEnterRecentsAnimation(final ViewAnimation.TaskViewEnterContext ctx) { 268 final TaskViewTransform transform = ctx.currentTaskTransform; 269 int startDelay = 0; 270 271 if (mConfig.launchedFromAppWithThumbnail) { 272 if (mTask.isLaunchTarget) { 273 // Animate the dim/overlay 274 if (Constants.DebugFlags.App.EnableThumbnailAlphaOnFrontmost) { 275 // Animate the thumbnail alpha before the dim animation (to prevent updating the 276 // hardware layer) 277 mThumbnailView.startEnterRecentsAnimation(mConfig.transitionEnterFromAppDelay, 278 new Runnable() { 279 @Override 280 public void run() { 281 animateDimToProgress(0, mConfig.taskViewEnterFromAppDuration, 282 ctx.postAnimationTrigger.decrementOnAnimationEnd()); 283 } 284 }); 285 } else { 286 // Immediately start the dim animation 287 animateDimToProgress(mConfig.transitionEnterFromAppDelay, 288 mConfig.taskViewEnterFromAppDuration, 289 ctx.postAnimationTrigger.decrementOnAnimationEnd()); 290 } 291 ctx.postAnimationTrigger.increment(); 292 293 // Animate the action button in 294 fadeInActionButton(mConfig.transitionEnterFromAppDelay, 295 mConfig.taskViewEnterFromAppDuration); 296 } else { 297 // Animate the task up if it was occluding the launch target 298 if (ctx.currentTaskOccludesLaunchTarget) { 299 setTranslationY(transform.translationY + mConfig.taskViewAffiliateGroupEnterOffsetPx); 300 setAlpha(0f); 301 animate().alpha(1f) 302 .translationY(transform.translationY) 303 .setStartDelay(mConfig.transitionEnterFromAppDelay) 304 .setUpdateListener(null) 305 .setInterpolator(mConfig.fastOutSlowInInterpolator) 306 .setDuration(mConfig.taskViewEnterFromHomeDuration) 307 .withEndAction(new Runnable() { 308 @Override 309 public void run() { 310 // Decrement the post animation trigger 311 ctx.postAnimationTrigger.decrement(); 312 } 313 }) 314 .start(); 315 ctx.postAnimationTrigger.increment(); 316 } 317 } 318 startDelay = mConfig.transitionEnterFromAppDelay; 319 320 } else if (mConfig.launchedFromHome) { 321 // Animate the tasks up 322 int frontIndex = (ctx.currentStackViewCount - ctx.currentStackViewIndex - 1); 323 int delay = mConfig.transitionEnterFromHomeDelay + 324 frontIndex * mConfig.taskViewEnterFromHomeStaggerDelay; 325 326 setScaleX(transform.scale); 327 setScaleY(transform.scale); 328 if (!mConfig.fakeShadows) { 329 animate().translationZ(transform.translationZ); 330 } 331 animate() 332 .translationY(transform.translationY) 333 .setStartDelay(delay) 334 .setUpdateListener(ctx.updateListener) 335 .setInterpolator(mConfig.quintOutInterpolator) 336 .setDuration(mConfig.taskViewEnterFromHomeDuration + 337 frontIndex * mConfig.taskViewEnterFromHomeStaggerDelay) 338 .withEndAction(new Runnable() { 339 @Override 340 public void run() { 341 // Decrement the post animation trigger 342 ctx.postAnimationTrigger.decrement(); 343 } 344 }) 345 .start(); 346 ctx.postAnimationTrigger.increment(); 347 startDelay = delay; 348 } 349 350 // Enable the focus animations from this point onwards so that they aren't affected by the 351 // window transitions 352 postDelayed(new Runnable() { 353 @Override 354 public void run() { 355 enableFocusAnimations(); 356 } 357 }, startDelay); 358 } 359 360 public void fadeInActionButton(int delay, int duration) { 361 // Hide the action button 362 mActionButtonView.setAlpha(0f); 363 364 // Animate the action button in 365 mActionButtonView.animate().alpha(1f) 366 .setStartDelay(delay) 367 .setDuration(duration) 368 .setInterpolator(PhoneStatusBar.ALPHA_IN) 369 .withLayer() 370 .start(); 371 } 372 373 /** Animates this task view as it leaves recents by pressing home. */ 374 void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { 375 animate() 376 .translationY(ctx.offscreenTranslationY) 377 .setStartDelay(0) 378 .setUpdateListener(null) 379 .setInterpolator(mConfig.fastOutLinearInInterpolator) 380 .setDuration(mConfig.taskViewExitToHomeDuration) 381 .withEndAction(ctx.postAnimationTrigger.decrementAsRunnable()) 382 .start(); 383 ctx.postAnimationTrigger.increment(); 384 } 385 386 /** Animates this task view away when dismissing all tasks. */ 387 void startDismissAllAnimation() { 388 dismissTask(); 389 } 390 391 /** Animates this task view as it exits recents */ 392 void startLaunchTaskAnimation(final Runnable postAnimRunnable, boolean isLaunchingTask, 393 boolean occludesLaunchTarget, boolean lockToTask) { 394 if (isLaunchingTask) { 395 // Animate the thumbnail alpha back into full opacity for the window animation out 396 mThumbnailView.startLaunchTaskAnimation(postAnimRunnable); 397 398 // Animate the dim 399 if (mDimAlpha > 0) { 400 ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", 0); 401 anim.setDuration(mConfig.taskViewExitToAppDuration); 402 anim.setInterpolator(mConfig.fastOutLinearInInterpolator); 403 anim.start(); 404 } 405 406 // Animate the action button away 407 if (!lockToTask) { 408 float toScale = 0.9f; 409 mActionButtonView.animate() 410 .scaleX(toScale) 411 .scaleY(toScale); 412 } 413 mActionButtonView.animate() 414 .alpha(0f) 415 .setStartDelay(0) 416 .setDuration(mConfig.taskViewExitToAppDuration) 417 .setInterpolator(mConfig.fastOutLinearInInterpolator) 418 .withLayer() 419 .start(); 420 } else { 421 // Hide the dismiss button 422 mHeaderView.startLaunchTaskDismissAnimation(); 423 // If this is another view in the task grouping and is in front of the launch task, 424 // animate it away first 425 if (occludesLaunchTarget) { 426 animate().alpha(0f) 427 .translationY(getTranslationY() + mConfig.taskViewAffiliateGroupEnterOffsetPx) 428 .setStartDelay(0) 429 .setUpdateListener(null) 430 .setInterpolator(mConfig.fastOutLinearInInterpolator) 431 .setDuration(mConfig.taskViewExitToAppDuration) 432 .start(); 433 } 434 } 435 } 436 437 /** Animates the deletion of this task view */ 438 void startDeleteTaskAnimation(final Runnable r, int delay) { 439 // Disabling clipping with the stack while the view is animating away 440 setClipViewInStack(false); 441 442 animate().translationX(mConfig.taskViewRemoveAnimTranslationXPx) 443 .alpha(0f) 444 .setStartDelay(delay) 445 .setUpdateListener(null) 446 .setInterpolator(mConfig.fastOutSlowInInterpolator) 447 .setDuration(mConfig.taskViewRemoveAnimDuration) 448 .withEndAction(new Runnable() { 449 @Override 450 public void run() { 451 if (r != null) { 452 r.run(); 453 } 454 455 // Re-enable clipping with the stack (we will reuse this view) 456 setClipViewInStack(true); 457 } 458 }) 459 .start(); 460 } 461 462 /** Enables/disables handling touch on this task view. */ 463 void setTouchEnabled(boolean enabled) { 464 setOnClickListener(enabled ? this : null); 465 } 466 467 /** Animates this task view if the user does not interact with the stack after a certain time. */ 468 void startNoUserInteractionAnimation() { 469 mHeaderView.startNoUserInteractionAnimation(); 470 } 471 472 /** Mark this task view that the user does has not interacted with the stack after a certain time. */ 473 void setNoUserInteractionState() { 474 mHeaderView.setNoUserInteractionState(); 475 } 476 477 /** Resets the state tracking that the user has not interacted with the stack after a certain time. */ 478 void resetNoUserInteractionState() { 479 mHeaderView.resetNoUserInteractionState(); 480 } 481 482 /** Dismisses this task. */ 483 void dismissTask() { 484 // Animate out the view and call the callback 485 final TaskView tv = this; 486 startDeleteTaskAnimation(new Runnable() { 487 @Override 488 public void run() { 489 if (mCb != null) { 490 mCb.onTaskViewDismissed(tv); 491 } 492 } 493 }, 0); 494 } 495 496 /** 497 * Returns whether this view should be clipped, or any views below should clip against this 498 * view. 499 */ 500 boolean shouldClipViewInStack() { 501 return mClipViewInStack && (getVisibility() == View.VISIBLE); 502 } 503 504 /** Sets whether this view should be clipped, or clipped against. */ 505 void setClipViewInStack(boolean clip) { 506 if (clip != mClipViewInStack) { 507 mClipViewInStack = clip; 508 if (mCb != null) { 509 mCb.onTaskViewClipStateChanged(this); 510 } 511 } 512 } 513 514 /** Sets the current task progress. */ 515 public void setTaskProgress(float p) { 516 mTaskProgress = p; 517 mViewBounds.setAlpha(p); 518 updateDimFromTaskProgress(); 519 } 520 521 /** Returns the current task progress. */ 522 public float getTaskProgress() { 523 return mTaskProgress; 524 } 525 526 /** Returns the current dim. */ 527 public void setDim(int dim) { 528 mDimAlpha = dim; 529 if (mConfig.useHardwareLayers) { 530 // Defer setting hardware layers if we have not yet measured, or there is no dim to draw 531 if (getMeasuredWidth() > 0 && getMeasuredHeight() > 0) { 532 mDimColorFilter.setColor(Color.argb(mDimAlpha, 0, 0, 0)); 533 mDimLayerPaint.setColorFilter(mDimColorFilter); 534 mContent.setLayerType(LAYER_TYPE_HARDWARE, mDimLayerPaint); 535 } 536 } else { 537 float dimAlpha = mDimAlpha / 255.0f; 538 if (mThumbnailView != null) { 539 mThumbnailView.setDimAlpha(dimAlpha); 540 } 541 if (mHeaderView != null) { 542 mHeaderView.setDimAlpha(dim); 543 } 544 } 545 } 546 547 /** Returns the current dim. */ 548 public int getDim() { 549 return mDimAlpha; 550 } 551 552 /** Animates the dim to the task progress. */ 553 void animateDimToProgress(int delay, int duration, Animator.AnimatorListener postAnimRunnable) { 554 // Animate the dim into view as well 555 int toDim = getDimFromTaskProgress(); 556 if (toDim != getDim()) { 557 ObjectAnimator anim = ObjectAnimator.ofInt(TaskView.this, "dim", toDim); 558 anim.setStartDelay(delay); 559 anim.setDuration(duration); 560 if (postAnimRunnable != null) { 561 anim.addListener(postAnimRunnable); 562 } 563 anim.start(); 564 } 565 } 566 567 /** Compute the dim as a function of the scale of this view. */ 568 int getDimFromTaskProgress() { 569 float dim = mMaxDimScale * mDimInterpolator.getInterpolation(1f - mTaskProgress); 570 return (int) (dim * 255); 571 } 572 573 /** Update the dim as a function of the scale of this view. */ 574 void updateDimFromTaskProgress() { 575 setDim(getDimFromTaskProgress()); 576 } 577 578 /**** View focus state ****/ 579 580 /** 581 * Sets the focused task explicitly. We need a separate flag because requestFocus() won't happen 582 * if the view is not currently visible, or we are in touch state (where we still want to keep 583 * track of focus). 584 */ 585 public void setFocusedTask(boolean animateFocusedState) { 586 mIsFocused = true; 587 if (mFocusAnimationsEnabled) { 588 // Focus the header bar 589 mHeaderView.onTaskViewFocusChanged(true, animateFocusedState); 590 } 591 // Update the thumbnail alpha with the focus 592 mThumbnailView.onFocusChanged(true); 593 // Call the callback 594 if (mCb != null) { 595 mCb.onTaskViewFocusChanged(this, true); 596 } 597 // Workaround, we don't always want it focusable in touch mode, but we want the first task 598 // to be focused after the enter-recents animation, which can be triggered from either touch 599 // or keyboard 600 setFocusableInTouchMode(true); 601 requestFocus(); 602 setFocusableInTouchMode(false); 603 invalidate(); 604 } 605 606 /** 607 * Unsets the focused task explicitly. 608 */ 609 void unsetFocusedTask() { 610 mIsFocused = false; 611 if (mFocusAnimationsEnabled) { 612 // Un-focus the header bar 613 mHeaderView.onTaskViewFocusChanged(false, true); 614 } 615 616 // Update the thumbnail alpha with the focus 617 mThumbnailView.onFocusChanged(false); 618 // Call the callback 619 if (mCb != null) { 620 mCb.onTaskViewFocusChanged(this, false); 621 } 622 invalidate(); 623 } 624 625 /** 626 * Updates the explicitly focused state when the view focus changes. 627 */ 628 @Override 629 protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { 630 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); 631 if (!gainFocus) { 632 unsetFocusedTask(); 633 } 634 } 635 636 /** 637 * Returns whether we have explicitly been focused. 638 */ 639 public boolean isFocusedTask() { 640 return mIsFocused || isFocused(); 641 } 642 643 /** Enables all focus animations. */ 644 void enableFocusAnimations() { 645 boolean wasFocusAnimationsEnabled = mFocusAnimationsEnabled; 646 mFocusAnimationsEnabled = true; 647 if (mIsFocused && !wasFocusAnimationsEnabled) { 648 // Re-notify the header if we were focused and animations were not previously enabled 649 mHeaderView.onTaskViewFocusChanged(true, true); 650 } 651 } 652 653 /**** TaskCallbacks Implementation ****/ 654 655 /** Binds this task view to the task */ 656 public void onTaskBound(Task t) { 657 mTask = t; 658 mTask.setCallbacks(this); 659 660 // Hide the action button if lock to app is disabled for this view 661 int lockButtonVisibility = (!t.lockToTaskEnabled || !t.lockToThisTask) ? GONE : VISIBLE; 662 if (mActionButtonView.getVisibility() != lockButtonVisibility) { 663 mActionButtonView.setVisibility(lockButtonVisibility); 664 requestLayout(); 665 } 666 } 667 668 @Override 669 public void onTaskDataLoaded() { 670 if (mThumbnailView != null && mHeaderView != null) { 671 // Bind each of the views to the new task data 672 mThumbnailView.rebindToTask(mTask); 673 mHeaderView.rebindToTask(mTask); 674 // Rebind any listeners 675 mHeaderView.mApplicationIcon.setOnClickListener(this); 676 mHeaderView.mDismissButton.setOnClickListener(this); 677 if (mConfig.multiStackEnabled) { 678 mHeaderView.mMoveTaskButton.setOnClickListener(this); 679 } 680 mActionButtonView.setOnClickListener(this); 681 mHeaderView.mApplicationIcon.setOnLongClickListener(this); 682 } 683 mTaskDataLoaded = true; 684 } 685 686 @Override 687 public void onTaskDataUnloaded() { 688 if (mThumbnailView != null && mHeaderView != null) { 689 // Unbind each of the views from the task data and remove the task callback 690 mTask.setCallbacks(null); 691 mThumbnailView.unbindFromTask(); 692 mHeaderView.unbindFromTask(); 693 // Unbind any listeners 694 mHeaderView.mApplicationIcon.setOnClickListener(null); 695 mHeaderView.mDismissButton.setOnClickListener(null); 696 if (mConfig.multiStackEnabled) { 697 mHeaderView.mMoveTaskButton.setOnClickListener(null); 698 } 699 mActionButtonView.setOnClickListener(null); 700 mHeaderView.mApplicationIcon.setOnLongClickListener(null); 701 } 702 mTaskDataLoaded = false; 703 } 704 705 @Override 706 public void onMultiStackDebugTaskStackIdChanged() { 707 mHeaderView.rebindToTask(mTask); 708 } 709 710 /**** View.OnClickListener Implementation ****/ 711 712 @Override 713 public void onClick(final View v) { 714 final TaskView tv = this; 715 final boolean delayViewClick = (v != this) && (v != mActionButtonView); 716 if (delayViewClick) { 717 // We purposely post the handler delayed to allow for the touch feedback to draw 718 postDelayed(new Runnable() { 719 @Override 720 public void run() { 721 if (Constants.DebugFlags.App.EnableTaskFiltering && v == mHeaderView.mApplicationIcon) { 722 if (mCb != null) { 723 mCb.onTaskViewAppIconClicked(tv); 724 } 725 } else if (v == mHeaderView.mDismissButton) { 726 dismissTask(); 727 } else if (v == mHeaderView.mMoveTaskButton) { 728 if (mCb != null) { 729 mCb.onTaskResize(tv); 730 } 731 } 732 } 733 }, 125); 734 } else { 735 if (v == mActionButtonView) { 736 // Reset the translation of the action button before we animate it out 737 mActionButtonView.setTranslationZ(0f); 738 } 739 if (mCb != null) { 740 mCb.onTaskViewClicked(tv, tv.getTask(), (v == mActionButtonView)); 741 } 742 } 743 } 744 745 /**** View.OnLongClickListener Implementation ****/ 746 747 @Override 748 public boolean onLongClick(View v) { 749 if (v == mHeaderView.mApplicationIcon) { 750 if (mCb != null) { 751 mCb.onTaskViewAppInfoClicked(this); 752 return true; 753 } 754 } 755 return false; 756 } 757} 758