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