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 | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 19 | import android.animation.TimeInterpolator; |
| 20 | import android.animation.ValueAnimator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 22 | import android.graphics.Canvas; |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 23 | import android.graphics.Outline; |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 24 | import android.graphics.Paint; |
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 | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 35 | import com.android.systemui.recents.Constants; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 36 | import com.android.systemui.recents.RecentsConfiguration; |
| 37 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 38 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 39 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 40 | /* A task view */ |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 41 | public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.OnClickListener, |
| 42 | View.OnLongClickListener { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 43 | /** The TaskView callbacks */ |
| 44 | interface TaskViewCallbacks { |
| 45 | public void onTaskIconClicked(TaskView tv); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 46 | public void onTaskAppInfoClicked(TaskView tv); |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 47 | public void onTaskFocused(TaskView tv); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 48 | public void onTaskDismissed(TaskView tv); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 49 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 50 | // public void onTaskViewReboundToTask(TaskView tv, Task t); |
| 51 | } |
| 52 | |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 53 | int mDim; |
| 54 | int mMaxDim; |
| 55 | TimeInterpolator mDimInterpolator = new AccelerateInterpolator(); |
| 56 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 57 | Task mTask; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 58 | boolean mTaskDataLoaded; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 59 | boolean mIsFocused; |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 60 | boolean mClipViewInStack; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 61 | Point mLastTouchDown = new Point(); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 62 | Path mRoundedRectClipPath = new Path(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 63 | |
| 64 | TaskThumbnailView mThumbnailView; |
| 65 | TaskBarView mBarView; |
| 66 | TaskViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 67 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 68 | |
| 69 | public TaskView(Context context) { |
| 70 | this(context, null); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 73 | public TaskView(Context context, AttributeSet attrs) { |
| 74 | this(context, attrs, 0); |
| 75 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 76 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 77 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 78 | this(context, attrs, defStyleAttr, 0); |
| 79 | } |
| 80 | |
| 81 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 82 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 83 | setWillNotDraw(false); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
| 87 | protected void onFinishInflate() { |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 88 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 89 | mMaxDim = config.taskStackMaxDim; |
| 90 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 91 | // By default, all views are clipped to other views in their stack |
| 92 | mClipViewInStack = true; |
| 93 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 94 | // Bind the views |
| 95 | mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail); |
| 96 | mBarView = (TaskBarView) findViewById(R.id.task_view_bar); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 97 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 98 | if (mTaskDataLoaded) { |
| 99 | onTaskDataLoaded(false); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 103 | @Override |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 104 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 105 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 106 | |
| 107 | // Update the rounded rect clip path |
| 108 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 109 | float radius = config.taskViewRoundedCornerRadiusPx; |
| 110 | mRoundedRectClipPath.reset(); |
| 111 | mRoundedRectClipPath.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()), |
| 112 | radius, radius, Path.Direction.CW); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 113 | |
| 114 | // Update the outline |
| 115 | Outline o = new Outline(); |
| 116 | o.setRoundRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), radius); |
| 117 | setOutline(o); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Override |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 121 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 122 | switch (ev.getAction()) { |
| 123 | case MotionEvent.ACTION_DOWN: |
| 124 | case MotionEvent.ACTION_MOVE: |
| 125 | mLastTouchDown.set((int) ev.getX(), (int) ev.getY()); |
| 126 | break; |
| 127 | } |
| 128 | return super.onInterceptTouchEvent(ev); |
| 129 | } |
| 130 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 131 | /** Set callback */ |
| 132 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 133 | mCb = cb; |
| 134 | } |
| 135 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 136 | /** Gets the task */ |
| 137 | Task getTask() { |
| 138 | return mTask; |
| 139 | } |
| 140 | |
| 141 | /** Synchronizes this view's properties with the task's transform */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 142 | void updateViewPropertiesToTaskTransform(TaskViewTransform animateFromTransform, |
| 143 | TaskViewTransform toTransform, int duration) { |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 144 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 145 | int minZ = config.taskViewTranslationZMinPx; |
| 146 | int incZ = config.taskViewTranslationZIncrementPx; |
| 147 | |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 148 | // Update the bar view |
| 149 | mBarView.updateViewPropertiesToTaskTransform(animateFromTransform, toTransform, duration); |
| 150 | |
| 151 | // Update this task view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 152 | if (duration > 0) { |
| 153 | if (animateFromTransform != null) { |
| 154 | setTranslationY(animateFromTransform.translationY); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 155 | if (Constants.DebugFlags.App.EnableShadows) { |
| 156 | setTranslationZ(Math.max(minZ, minZ + (animateFromTransform.t * incZ))); |
| 157 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 158 | setScaleX(animateFromTransform.scale); |
| 159 | setScaleY(animateFromTransform.scale); |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 160 | setAlpha(animateFromTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 161 | } |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 162 | if (Constants.DebugFlags.App.EnableShadows) { |
| 163 | animate().translationZ(Math.max(minZ, minZ + (toTransform.t * incZ))); |
| 164 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 165 | animate().translationY(toTransform.translationY) |
| 166 | .scaleX(toTransform.scale) |
| 167 | .scaleY(toTransform.scale) |
| 168 | .alpha(toTransform.alpha) |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 169 | .setDuration(duration) |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 170 | .setInterpolator(config.defaultBezierInterpolator) |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 171 | .withLayer() |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 172 | .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 173 | @Override |
| 174 | public void onAnimationUpdate(ValueAnimator animation) { |
| 175 | updateDimOverlayFromScale(); |
| 176 | } |
| 177 | }) |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 178 | .start(); |
| 179 | } else { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 180 | setTranslationY(toTransform.translationY); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 181 | if (Constants.DebugFlags.App.EnableShadows) { |
| 182 | setTranslationZ(Math.max(minZ, minZ + (toTransform.t * incZ))); |
| 183 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 184 | setScaleX(toTransform.scale); |
| 185 | setScaleY(toTransform.scale); |
| 186 | setAlpha(toTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 187 | } |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 188 | updateDimOverlayFromScale(); |
| 189 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** Resets this view's properties */ |
| 193 | void resetViewProperties() { |
| 194 | setTranslationX(0f); |
| 195 | setTranslationY(0f); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 196 | if (Constants.DebugFlags.App.EnableShadows) { |
| 197 | setTranslationZ(0f); |
| 198 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 199 | setScaleX(1f); |
| 200 | setScaleY(1f); |
| 201 | setAlpha(1f); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 202 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 205 | /** |
| 206 | * When we are un/filtering, this method will set up the transform that we are animating to, |
| 207 | * in order to hide the task. |
| 208 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 209 | void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { |
| 210 | // Fade the view out and slide it away |
| 211 | toTransform.alpha = 0f; |
| 212 | toTransform.translationY += 200; |
| 213 | } |
| 214 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 215 | /** |
| 216 | * When we are un/filtering, this method will setup the transform that we are animating from, |
| 217 | * in order to show the task. |
| 218 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 219 | void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { |
| 220 | // Fade the view in |
| 221 | fromTransform.alpha = 0f; |
| 222 | } |
| 223 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 224 | /** Animates this task view as it enters recents */ |
| 225 | public void animateOnEnterRecents() { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 226 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 227 | mBarView.setAlpha(0f); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 228 | mBarView.animate() |
| 229 | .alpha(1f) |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 230 | .setStartDelay(300) |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 231 | .setInterpolator(config.defaultBezierInterpolator) |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 232 | .setDuration(config.taskBarEnterAnimDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 233 | .withLayer() |
| 234 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** Animates this task view as it exits recents */ |
| 238 | public void animateOnLeavingRecents(final Runnable r) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 239 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 240 | mBarView.animate() |
| 241 | .alpha(0f) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 242 | .setStartDelay(0) |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 243 | .setInterpolator(config.defaultBezierInterpolator) |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 244 | .setDuration(config.taskBarExitAnimDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 245 | .withLayer() |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 246 | .withEndAction(new Runnable() { |
| 247 | @Override |
| 248 | public void run() { |
| 249 | post(r); |
| 250 | } |
| 251 | }) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 252 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 255 | /** Animates the deletion of this task view */ |
| 256 | public void animateRemoval(final Runnable r) { |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 257 | // Disabling clipping with the stack while the view is animating away |
| 258 | setClipViewInStack(false); |
| 259 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 260 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 261 | animate().translationX(config.taskViewRemoveAnimTranslationXPx) |
| 262 | .alpha(0f) |
| 263 | .setStartDelay(0) |
Winson Chung | 918c072 | 2014-05-08 15:04:23 -0700 | [diff] [blame] | 264 | .setInterpolator(config.defaultBezierInterpolator) |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 265 | .setDuration(config.taskViewRemoveAnimDuration) |
| 266 | .withLayer() |
| 267 | .withEndAction(new Runnable() { |
| 268 | @Override |
| 269 | public void run() { |
| 270 | post(r); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 271 | |
| 272 | // Re-enable clipping with the stack (we will reuse this view) |
| 273 | setClipViewInStack(false); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 274 | } |
| 275 | }) |
| 276 | .start(); |
| 277 | } |
| 278 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 279 | /** 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] | 280 | Rect getClippingRect(Rect outRect) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 281 | getHitRect(outRect); |
| 282 | // XXX: We should get the hit rect of the thumbnail view and intersect, but this is faster |
| 283 | outRect.right = outRect.left + mThumbnailView.getRight(); |
| 284 | outRect.bottom = outRect.top + mThumbnailView.getBottom(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 285 | return outRect; |
| 286 | } |
| 287 | |
| 288 | /** Enable the hw layers on this task view */ |
| 289 | void enableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 290 | mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 291 | } |
| 292 | |
| 293 | /** Disable the hw layers on this task view */ |
| 294 | void disableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 295 | mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 296 | } |
| 297 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 298 | /** |
| 299 | * Returns whether this view should be clipped, or any views below should clip against this |
| 300 | * view. |
| 301 | */ |
| 302 | boolean shouldClipViewInStack() { |
| 303 | return mClipViewInStack; |
| 304 | } |
| 305 | |
| 306 | /** Sets whether this view should be clipped, or clipped against. */ |
| 307 | void setClipViewInStack(boolean clip) { |
| 308 | if (clip != mClipViewInStack) { |
| 309 | mClipViewInStack = clip; |
| 310 | if (getParent() instanceof View) { |
| 311 | Rect r = new Rect(); |
| 312 | getHitRect(r); |
| 313 | ((View) getParent()).invalidate(r); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 318 | /** Update the dim as a function of the scale of this view. */ |
| 319 | void updateDimOverlayFromScale() { |
| 320 | float minScale = Constants.Values.TaskStackView.StackPeekMinScale; |
| 321 | float scaleRange = 1f - minScale; |
| 322 | float dim = (1f - getScaleX()) / scaleRange; |
| 323 | dim = mDimInterpolator.getInterpolation(Math.min(dim, 1f)); |
| 324 | mDim = Math.max(0, Math.min(mMaxDim, (int) (dim * 255))); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | @Override |
| 328 | public void draw(Canvas canvas) { |
| 329 | // Apply the rounded rect clip path on the whole view |
| 330 | canvas.clipPath(mRoundedRectClipPath); |
| 331 | |
| 332 | super.draw(canvas); |
| 333 | |
| 334 | // Apply the dim if necessary |
| 335 | if (mDim > 0) { |
| 336 | canvas.drawColor(mDim << 24); |
| 337 | } |
| 338 | } |
| 339 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 340 | /** |
| 341 | * Sets the focused task explicitly. We need a separate flag because requestFocus() won't happen |
| 342 | * if the view is not currently visible, or we are in touch state (where we still want to keep |
| 343 | * track of focus). |
| 344 | */ |
| 345 | public void setFocusedTask() { |
| 346 | mIsFocused = true; |
| 347 | requestFocus(); |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 348 | invalidate(); |
| 349 | mCb.onTaskFocused(this); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Updates the explicitly focused state when the view focus changes. |
| 354 | */ |
| 355 | @Override |
| 356 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
| 357 | super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
| 358 | if (!gainFocus) { |
| 359 | mIsFocused = false; |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 360 | invalidate(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Returns whether we have explicitly been focused. |
| 366 | */ |
| 367 | public boolean isFocusedTask() { |
| 368 | return mIsFocused || isFocused(); |
| 369 | } |
| 370 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 371 | /**** TaskCallbacks Implementation ****/ |
| 372 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 373 | /** Binds this task view to the task */ |
| 374 | public void onTaskBound(Task t) { |
| 375 | mTask = t; |
| 376 | mTask.setCallbacks(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 380 | public void onTaskDataLoaded(boolean reloadingTaskData) { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 381 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 382 | // Bind each of the views to the new task data |
| 383 | mThumbnailView.rebindToTask(mTask, reloadingTaskData); |
| 384 | mBarView.rebindToTask(mTask, reloadingTaskData); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 385 | // Rebind any listeners |
| 386 | mBarView.mApplicationIcon.setOnClickListener(this); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 387 | mBarView.mDismissButton.setOnClickListener(this); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 388 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame^] | 389 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 390 | if (config.developerOptionsEnabled) { |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 391 | mBarView.mApplicationIcon.setOnLongClickListener(this); |
| 392 | } |
| 393 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 394 | } |
| 395 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 399 | public void onTaskDataUnloaded() { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 400 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 401 | // Unbind each of the views from the task data and remove the task callback |
| 402 | mTask.setCallbacks(null); |
| 403 | mThumbnailView.unbindFromTask(); |
| 404 | mBarView.unbindFromTask(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 405 | // Unbind any listeners |
| 406 | mBarView.mApplicationIcon.setOnClickListener(null); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 407 | mBarView.mDismissButton.setOnClickListener(null); |
| 408 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
| 409 | mBarView.mApplicationIcon.setOnLongClickListener(null); |
| 410 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 411 | } |
| 412 | mTaskDataLoaded = false; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 416 | public void onClick(View v) { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 417 | if (v == mBarView.mApplicationIcon) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 418 | mCb.onTaskIconClicked(this); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 419 | } else if (v == mBarView.mDismissButton) { |
| 420 | // Animate out the view and call the callback |
| 421 | final TaskView tv = this; |
| 422 | animateRemoval(new Runnable() { |
| 423 | @Override |
| 424 | public void run() { |
| 425 | mCb.onTaskDismissed(tv); |
| 426 | } |
| 427 | }); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 428 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 429 | } |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 430 | |
| 431 | @Override |
| 432 | public boolean onLongClick(View v) { |
| 433 | if (v == mBarView.mApplicationIcon) { |
| 434 | mCb.onTaskAppInfoClicked(this); |
| 435 | return true; |
| 436 | } |
| 437 | return false; |
| 438 | } |
Winson Chung | 7bb1885 | 2014-05-20 23:25:41 +0000 | [diff] [blame] | 439 | } |