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