Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.recents.views; |
| 18 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 19 | import android.animation.ObjectAnimator; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 20 | import android.animation.TimeInterpolator; |
| 21 | import android.animation.ValueAnimator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 23 | import android.graphics.Canvas; |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 24 | import android.graphics.Outline; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 25 | import android.graphics.Path; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 26 | import android.graphics.Point; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 28 | import android.graphics.RectF; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 30 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 31 | import android.view.View; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 32 | import android.view.ViewPropertyAnimator; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 33 | import android.view.animation.AccelerateInterpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 34 | import android.widget.FrameLayout; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 35 | import com.android.systemui.R; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 36 | import com.android.systemui.recents.Console; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 37 | import com.android.systemui.recents.Constants; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 38 | import com.android.systemui.recents.RecentsConfiguration; |
| 39 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 40 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 41 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 42 | /* A task view */ |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 43 | public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.OnClickListener, |
| 44 | View.OnLongClickListener { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 45 | /** The TaskView callbacks */ |
| 46 | interface TaskViewCallbacks { |
| 47 | public void onTaskIconClicked(TaskView tv); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 48 | public void onTaskAppInfoClicked(TaskView tv); |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 49 | public void onTaskFocused(TaskView tv); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 50 | public void onTaskDismissed(TaskView tv); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 53 | RecentsConfiguration mConfig; |
| 54 | |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 55 | int mDim; |
| 56 | int mMaxDim; |
| 57 | TimeInterpolator mDimInterpolator = new AccelerateInterpolator(); |
| 58 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 59 | Task mTask; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 60 | boolean mTaskDataLoaded; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 61 | boolean mIsFocused; |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 62 | boolean mClipViewInStack; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 63 | Point mLastTouchDown = new Point(); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 64 | Path mRoundedRectClipPath = new Path(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 65 | Rect mTmpRect = new Rect(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 66 | |
| 67 | TaskThumbnailView mThumbnailView; |
| 68 | TaskBarView mBarView; |
| 69 | TaskViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 70 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 71 | // Optimizations |
| 72 | ValueAnimator.AnimatorUpdateListener mUpdateDimListener = |
| 73 | new ValueAnimator.AnimatorUpdateListener() { |
| 74 | @Override |
| 75 | public void onAnimationUpdate(ValueAnimator animation) { |
| 76 | updateDimOverlayFromScale(); |
| 77 | } |
| 78 | }; |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 79 | Runnable mEnableThumbnailClip = new Runnable() { |
| 80 | @Override |
| 81 | public void run() { |
| 82 | mThumbnailView.updateTaskBarClip(mBarView); |
| 83 | } |
| 84 | }; |
| 85 | Runnable mDisableThumbnailClip = new Runnable() { |
| 86 | @Override |
| 87 | public void run() { |
| 88 | mThumbnailView.disableClipTaskBarView(); |
| 89 | } |
| 90 | }; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 91 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 92 | |
| 93 | public TaskView(Context context) { |
| 94 | this(context, null); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 97 | public TaskView(Context context, AttributeSet attrs) { |
| 98 | this(context, attrs, 0); |
| 99 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 100 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 101 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 102 | this(context, attrs, defStyleAttr, 0); |
| 103 | } |
| 104 | |
| 105 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 106 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 107 | mConfig = RecentsConfiguration.getInstance(); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 108 | setWillNotDraw(false); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 109 | setDim(getDim()); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | protected void onFinishInflate() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 114 | mMaxDim = mConfig.taskStackMaxDim; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 115 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 116 | // By default, all views are clipped to other views in their stack |
| 117 | mClipViewInStack = true; |
| 118 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 119 | // Bind the views |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 120 | mBarView = (TaskBarView) findViewById(R.id.task_view_bar); |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 121 | mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 122 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 123 | if (mTaskDataLoaded) { |
| 124 | onTaskDataLoaded(false); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 128 | @Override |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 129 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 130 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 131 | |
| 132 | // Update the rounded rect clip path |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 133 | float radius = mConfig.taskViewRoundedCornerRadiusPx; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 134 | mRoundedRectClipPath.reset(); |
| 135 | mRoundedRectClipPath.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()), |
| 136 | radius, radius, Path.Direction.CW); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 137 | |
| 138 | // Update the outline |
| 139 | Outline o = new Outline(); |
Winson Chung | 602de03 | 2014-05-27 12:19:28 -0700 | [diff] [blame] | 140 | o.setRoundRect(0, 0, getMeasuredWidth(), getMeasuredHeight() - |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 141 | mConfig.taskViewShadowOutlineBottomInsetPx, radius); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 142 | setOutline(o); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 146 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 147 | switch (ev.getAction()) { |
| 148 | case MotionEvent.ACTION_DOWN: |
| 149 | case MotionEvent.ACTION_MOVE: |
| 150 | mLastTouchDown.set((int) ev.getX(), (int) ev.getY()); |
| 151 | break; |
| 152 | } |
| 153 | return super.onInterceptTouchEvent(ev); |
| 154 | } |
| 155 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 156 | /** Set callback */ |
| 157 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 158 | mCb = cb; |
| 159 | } |
| 160 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 161 | /** Gets the task */ |
| 162 | Task getTask() { |
| 163 | return mTask; |
| 164 | } |
| 165 | |
| 166 | /** Synchronizes this view's properties with the task's transform */ |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 167 | void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, int duration) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 168 | if (Console.Enabled) { |
| 169 | Console.log(Constants.Log.UI.Draw, "[TaskView|updateViewPropertiesToTaskTransform]", |
| 170 | "duration: " + duration, Console.AnsiPurple); |
| 171 | } |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 172 | |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 173 | // Update the bar view |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 174 | mBarView.updateViewPropertiesToTaskTransform(toTransform, duration); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 175 | |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 176 | // Check to see if any properties have changed, and update the task view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 177 | if (duration > 0) { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 178 | ViewPropertyAnimator anim = animate(); |
| 179 | boolean useLayers = false; |
| 180 | |
| 181 | // Animate to the final state |
| 182 | if (toTransform.hasTranslationYChangedFrom(getTranslationY())) { |
| 183 | anim.translationY(toTransform.translationY); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 184 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 185 | if (Constants.DebugFlags.App.EnableShadows && |
| 186 | toTransform.hasTranslationZChangedFrom(getTranslationZ())) { |
| 187 | anim.translationZ(toTransform.translationZ); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 188 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 189 | if (toTransform.hasScaleChangedFrom(getScaleX())) { |
| 190 | anim.scaleX(toTransform.scale) |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 191 | .scaleY(toTransform.scale) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 192 | .setUpdateListener(mUpdateDimListener); |
| 193 | useLayers = true; |
| 194 | } |
| 195 | if (toTransform.hasAlphaChangedFrom(getAlpha())) { |
| 196 | // Use layers if we animate alpha |
| 197 | anim.alpha(toTransform.alpha); |
| 198 | useLayers = true; |
| 199 | } |
| 200 | if (useLayers) { |
| 201 | anim.withLayer(); |
| 202 | } |
| 203 | anim.setStartDelay(0) |
| 204 | .setDuration(duration) |
| 205 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 206 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 207 | } else { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 208 | // Set the changed properties |
| 209 | if (toTransform.hasTranslationYChangedFrom(getTranslationY())) { |
| 210 | setTranslationY(toTransform.translationY); |
| 211 | } |
| 212 | if (Constants.DebugFlags.App.EnableShadows && |
| 213 | toTransform.hasTranslationZChangedFrom(getTranslationZ())) { |
Winson Chung | b13c46e | 2014-06-09 18:33:08 -0700 | [diff] [blame] | 214 | setTranslationZ(toTransform.translationZ); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 215 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 216 | if (toTransform.hasScaleChangedFrom(getScaleX())) { |
| 217 | setScaleX(toTransform.scale); |
| 218 | setScaleY(toTransform.scale); |
| 219 | updateDimOverlayFromScale(); |
| 220 | } |
| 221 | if (toTransform.hasAlphaChangedFrom(getAlpha())) { |
| 222 | setAlpha(toTransform.alpha); |
| 223 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | /** Resets this view's properties */ |
| 228 | void resetViewProperties() { |
| 229 | setTranslationX(0f); |
| 230 | setTranslationY(0f); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 231 | if (Constants.DebugFlags.App.EnableShadows) { |
| 232 | setTranslationZ(0f); |
| 233 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 234 | setScaleX(1f); |
| 235 | setScaleY(1f); |
| 236 | setAlpha(1f); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 237 | setDim(0); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 238 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 241 | /** |
| 242 | * When we are un/filtering, this method will set up the transform that we are animating to, |
| 243 | * in order to hide the task. |
| 244 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 245 | void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { |
| 246 | // Fade the view out and slide it away |
| 247 | toTransform.alpha = 0f; |
| 248 | toTransform.translationY += 200; |
| 249 | } |
| 250 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 251 | /** |
| 252 | * When we are un/filtering, this method will setup the transform that we are animating from, |
| 253 | * in order to show the task. |
| 254 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 255 | void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { |
| 256 | // Fade the view in |
| 257 | fromTransform.alpha = 0f; |
| 258 | } |
| 259 | |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 260 | /** Prepares this task view for the enter-recents animations. This is called earlier in the |
| 261 | * first layout because the actual animation into recents may take a long time. */ |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 262 | public void prepareAnimateEnterRecents(boolean isTaskViewFrontMost, int offsetY, int offscreenY, |
| 263 | Rect taskRect) { |
| 264 | if (mConfig.launchedFromAppWithScreenshot) { |
| 265 | if (isTaskViewFrontMost) { |
| 266 | // Hide the task view as we are going to animate the full screenshot into view |
| 267 | // and then replace it with this view once we are done |
| 268 | setVisibility(View.INVISIBLE); |
| 269 | // Also hide the front most task bar view so we can animate it in |
| 270 | mBarView.prepareAnimateEnterRecents(); |
| 271 | } else { |
| 272 | // Top align the task views |
| 273 | setTranslationY(offsetY); |
| 274 | setScaleX(1f); |
| 275 | setScaleY(1f); |
| 276 | } |
| 277 | |
| 278 | } else if (mConfig.launchedFromAppWithThumbnail) { |
| 279 | if (isTaskViewFrontMost) { |
| 280 | // Hide the front most task bar view so we can animate it in |
| 281 | mBarView.prepareAnimateEnterRecents(); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 282 | // Set the dim to 0 so we can animate it in |
| 283 | setDim(0); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | } else if (mConfig.launchedFromHome) { |
| 287 | // Move the task view off screen (below) so we can animate it in |
| 288 | setTranslationY(offscreenY); |
| 289 | setScaleX(1f); |
| 290 | setScaleY(1f); |
| 291 | } |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 294 | /** Animates this task view as it enters recents */ |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 295 | public void animateOnEnterRecents(ViewAnimation.TaskViewEnterContext ctx) { |
| 296 | TaskViewTransform transform = ctx.transform; |
| 297 | |
| 298 | if (mConfig.launchedFromAppWithScreenshot) { |
| 299 | if (ctx.isFrontMost) { |
| 300 | // Animate the full screenshot down first, before swapping with this task view |
| 301 | ctx.fullScreenshot.animateOnEnterRecents(ctx, new Runnable() { |
| 302 | @Override |
| 303 | public void run() { |
| 304 | // Animate the task bar of the first task view |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 305 | mBarView.animateOnEnterRecents(0, mEnableThumbnailClip); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 306 | setVisibility(View.VISIBLE); |
| 307 | } |
| 308 | }); |
| 309 | } else { |
| 310 | // Animate the tasks down behind the full screenshot |
| 311 | animate() |
| 312 | .scaleX(transform.scale) |
| 313 | .scaleY(transform.scale) |
| 314 | .translationY(transform.translationY) |
| 315 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 316 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 317 | .setInterpolator(mConfig.linearOutSlowInInterpolator) |
| 318 | .setDuration(475) |
| 319 | .withLayer() |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 320 | .withEndAction(mEnableThumbnailClip) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 321 | .start(); |
| 322 | } |
| 323 | |
| 324 | } else if (mConfig.launchedFromAppWithThumbnail) { |
| 325 | if (ctx.isFrontMost) { |
| 326 | // Animate the task bar of the first task view |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 327 | mBarView.animateOnEnterRecents(mConfig.taskBarEnterAnimDelay, mEnableThumbnailClip); |
| 328 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 329 | // Animate the dim into view as well |
| 330 | ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", getDimOverlayFromScale()); |
| 331 | anim.setStartDelay(mConfig.taskBarEnterAnimDelay); |
| 332 | anim.setDuration(mConfig.taskBarEnterAnimDuration); |
| 333 | anim.setInterpolator(mConfig.fastOutLinearInInterpolator); |
| 334 | anim.start(); |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 335 | } else { |
| 336 | mEnableThumbnailClip.run(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | } else if (mConfig.launchedFromHome) { |
| 340 | // Animate the tasks up |
| 341 | int frontIndex = (ctx.stackViewCount - ctx.stackViewIndex - 1); |
| 342 | int delay = mConfig.taskBarEnterAnimDelay + |
| 343 | frontIndex * mConfig.taskViewEnterFromHomeDelay; |
| 344 | animate() |
| 345 | .scaleX(transform.scale) |
| 346 | .scaleY(transform.scale) |
| 347 | .translationY(transform.translationY) |
| 348 | .setStartDelay(delay) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 349 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 350 | .setInterpolator(mConfig.quintOutInterpolator) |
| 351 | .setDuration(mConfig.taskViewEnterFromHomeDuration) |
| 352 | .withLayer() |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 353 | .withEndAction(mEnableThumbnailClip) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 354 | .start(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /** Animates this task view as it leaves recents */ |
| 359 | public void animateOnExitRecents(ViewAnimation.TaskViewExitContext ctx) { |
| 360 | animate() |
| 361 | .translationY(ctx.offscreenTranslationY) |
| 362 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 363 | .setUpdateListener(null) |
Winson Chung | ad6f276 | 2014-06-13 09:41:09 -0700 | [diff] [blame] | 364 | .setInterpolator(mConfig.fastOutLinearInInterpolator) |
| 365 | .setDuration(mConfig.taskViewExitToHomeDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 366 | .withLayer() |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 367 | .withEndAction(ctx.postAnimationTrigger.decrementAsRunnable()) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 368 | .start(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 369 | ctx.postAnimationTrigger.increment(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 372 | /** Animates this task view if the user does not interact with the stack after a certain time. */ |
| 373 | public void animateOnNoUserInteraction() { |
| 374 | mBarView.animateOnNoUserInteraction(); |
| 375 | } |
| 376 | |
| 377 | /** Mark this task view that the user does has not interacted with the stack after a certain time. */ |
| 378 | public void setOnNoUserInteraction() { |
| 379 | mBarView.setOnNoUserInteraction(); |
| 380 | } |
| 381 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 382 | /** Animates this task view as it exits recents */ |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 383 | public void animateOnLaunchingTask(final Runnable r) { |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 384 | // Disable the thumbnail clip and animate the bar out |
| 385 | mBarView.animateOnLaunchingTask(mDisableThumbnailClip, r); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 386 | |
| 387 | // Animate the dim |
| 388 | if (mDim > 0) { |
| 389 | ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", 0); |
| 390 | anim.setDuration(mConfig.taskBarExitAnimDuration); |
| 391 | anim.setInterpolator(mConfig.fastOutLinearInInterpolator); |
| 392 | anim.start(); |
| 393 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 396 | /** Animates the deletion of this task view */ |
| 397 | public void animateRemoval(final Runnable r) { |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 398 | // Disabling clipping with the stack while the view is animating away |
| 399 | setClipViewInStack(false); |
| 400 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 401 | animate().translationX(mConfig.taskViewRemoveAnimTranslationXPx) |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 402 | .alpha(0f) |
| 403 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame^] | 404 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 405 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 406 | .setDuration(mConfig.taskViewRemoveAnimDuration) |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 407 | .withLayer() |
| 408 | .withEndAction(new Runnable() { |
| 409 | @Override |
| 410 | public void run() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 411 | // We just throw this into a runnable because starting a view property |
| 412 | // animation using layers can cause inconsisten results if we try and |
| 413 | // update the layers while the animation is running. In some cases, |
| 414 | // the runnabled passed in may start an animation which also uses layers |
| 415 | // so we defer all this by posting this. |
| 416 | r.run(); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 417 | |
| 418 | // Re-enable clipping with the stack (we will reuse this view) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 419 | setClipViewInStack(true); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 420 | } |
| 421 | }) |
| 422 | .start(); |
| 423 | } |
| 424 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 425 | /** Returns the rect we want to clip (it may not be the full rect) */ |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 426 | Rect getClippingRect(Rect outRect) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 427 | getHitRect(outRect); |
| 428 | // XXX: We should get the hit rect of the thumbnail view and intersect, but this is faster |
| 429 | outRect.right = outRect.left + mThumbnailView.getRight(); |
| 430 | outRect.bottom = outRect.top + mThumbnailView.getBottom(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 431 | return outRect; |
| 432 | } |
| 433 | |
| 434 | /** Enable the hw layers on this task view */ |
| 435 | void enableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 436 | mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 437 | mBarView.enableHwLayers(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** Disable the hw layers on this task view */ |
| 441 | void disableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 442 | mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, null); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 443 | mBarView.disableHwLayers(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 446 | /** |
| 447 | * Returns whether this view should be clipped, or any views below should clip against this |
| 448 | * view. |
| 449 | */ |
| 450 | boolean shouldClipViewInStack() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 451 | return mClipViewInStack && (getVisibility() == View.VISIBLE); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** Sets whether this view should be clipped, or clipped against. */ |
| 455 | void setClipViewInStack(boolean clip) { |
| 456 | if (clip != mClipViewInStack) { |
| 457 | mClipViewInStack = clip; |
| 458 | if (getParent() instanceof View) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 459 | getHitRect(mTmpRect); |
| 460 | ((View) getParent()).invalidate(mTmpRect); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 465 | /** Returns the current dim. */ |
| 466 | public void setDim(int dim) { |
| 467 | mDim = dim; |
| 468 | postInvalidateOnAnimation(); |
| 469 | } |
| 470 | |
| 471 | /** Returns the current dim. */ |
| 472 | public int getDim() { |
| 473 | return mDim; |
| 474 | } |
| 475 | |
| 476 | /** Compute the dim as a function of the scale of this view. */ |
| 477 | int getDimOverlayFromScale() { |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 478 | float minScale = Constants.Values.TaskStackView.StackPeekMinScale; |
| 479 | float scaleRange = 1f - minScale; |
| 480 | float dim = (1f - getScaleX()) / scaleRange; |
| 481 | dim = mDimInterpolator.getInterpolation(Math.min(dim, 1f)); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 482 | return Math.max(0, Math.min(mMaxDim, (int) (dim * 255))); |
| 483 | } |
| 484 | |
| 485 | /** Update the dim as a function of the scale of this view. */ |
| 486 | void updateDimOverlayFromScale() { |
| 487 | setDim(getDimOverlayFromScale()); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void draw(Canvas canvas) { |
| 492 | // Apply the rounded rect clip path on the whole view |
| 493 | canvas.clipPath(mRoundedRectClipPath); |
| 494 | |
| 495 | super.draw(canvas); |
| 496 | |
| 497 | // Apply the dim if necessary |
| 498 | if (mDim > 0) { |
| 499 | canvas.drawColor(mDim << 24); |
| 500 | } |
| 501 | } |
| 502 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 503 | /** |
| 504 | * Sets the focused task explicitly. We need a separate flag because requestFocus() won't happen |
| 505 | * if the view is not currently visible, or we are in touch state (where we still want to keep |
| 506 | * track of focus). |
| 507 | */ |
| 508 | public void setFocusedTask() { |
| 509 | mIsFocused = true; |
| 510 | requestFocus(); |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 511 | invalidate(); |
| 512 | mCb.onTaskFocused(this); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Updates the explicitly focused state when the view focus changes. |
| 517 | */ |
| 518 | @Override |
| 519 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
| 520 | super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
| 521 | if (!gainFocus) { |
| 522 | mIsFocused = false; |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 523 | invalidate(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Returns whether we have explicitly been focused. |
| 529 | */ |
| 530 | public boolean isFocusedTask() { |
| 531 | return mIsFocused || isFocused(); |
| 532 | } |
| 533 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 534 | /**** TaskCallbacks Implementation ****/ |
| 535 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 536 | /** Binds this task view to the task */ |
| 537 | public void onTaskBound(Task t) { |
| 538 | mTask = t; |
| 539 | mTask.setCallbacks(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | @Override |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 543 | public void onTaskDataLoaded(boolean reloadingTaskData) { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 544 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 545 | // Bind each of the views to the new task data |
| 546 | mThumbnailView.rebindToTask(mTask, reloadingTaskData); |
| 547 | mBarView.rebindToTask(mTask, reloadingTaskData); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 548 | // Rebind any listeners |
| 549 | mBarView.mApplicationIcon.setOnClickListener(this); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 550 | mBarView.mDismissButton.setOnClickListener(this); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 551 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 552 | if (mConfig.developerOptionsEnabled) { |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 553 | mBarView.mApplicationIcon.setOnLongClickListener(this); |
| 554 | } |
| 555 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 556 | } |
| 557 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 561 | public void onTaskDataUnloaded() { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 562 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 563 | // Unbind each of the views from the task data and remove the task callback |
| 564 | mTask.setCallbacks(null); |
| 565 | mThumbnailView.unbindFromTask(); |
| 566 | mBarView.unbindFromTask(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 567 | // Unbind any listeners |
| 568 | mBarView.mApplicationIcon.setOnClickListener(null); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 569 | mBarView.mDismissButton.setOnClickListener(null); |
| 570 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
| 571 | mBarView.mApplicationIcon.setOnLongClickListener(null); |
| 572 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 573 | } |
| 574 | mTaskDataLoaded = false; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 578 | public void onClick(View v) { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 579 | if (v == mBarView.mApplicationIcon) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 580 | mCb.onTaskIconClicked(this); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 581 | } else if (v == mBarView.mDismissButton) { |
| 582 | // Animate out the view and call the callback |
| 583 | final TaskView tv = this; |
| 584 | animateRemoval(new Runnable() { |
| 585 | @Override |
| 586 | public void run() { |
| 587 | mCb.onTaskDismissed(tv); |
| 588 | } |
| 589 | }); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 590 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 591 | } |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 592 | |
| 593 | @Override |
| 594 | public boolean onLongClick(View v) { |
| 595 | if (v == mBarView.mApplicationIcon) { |
| 596 | mCb.onTaskAppInfoClicked(this); |
| 597 | return true; |
| 598 | } |
| 599 | return false; |
| 600 | } |
Winson Chung | 7bb1885 | 2014-05-20 23:25:41 +0000 | [diff] [blame] | 601 | } |