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 | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 24 | import android.graphics.Path; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 25 | import android.graphics.Point; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 27 | import android.graphics.RectF; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 29 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 30 | import android.view.View; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 31 | import android.view.animation.AccelerateInterpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 32 | import android.widget.FrameLayout; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 33 | import com.android.systemui.R; |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 34 | import com.android.systemui.recents.BakedBezierInterpolator; |
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 | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 41 | public class TaskView extends FrameLayout implements View.OnClickListener, |
| 42 | Task.TaskCallbacks { |
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 onTaskInfoPanelShown(TaskView tv); |
| 47 | public void onTaskInfoPanelHidden(TaskView tv); |
| 48 | public void onTaskAppInfoClicked(TaskView tv); |
| 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 | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 59 | boolean mTaskInfoPaneVisible; |
| 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; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 65 | TaskInfoView mInfoView; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 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 | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 91 | // Bind the views |
| 92 | mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail); |
| 93 | mBarView = (TaskBarView) findViewById(R.id.task_view_bar); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 94 | mInfoView = (TaskInfoView) findViewById(R.id.task_view_info_pane); |
| 95 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 96 | if (mTaskDataLoaded) { |
| 97 | onTaskDataLoaded(false); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 101 | @Override |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 102 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 103 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 104 | |
| 105 | // Update the rounded rect clip path |
| 106 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 107 | float radius = config.taskViewRoundedCornerRadiusPx; |
| 108 | mRoundedRectClipPath.reset(); |
| 109 | mRoundedRectClipPath.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()), |
| 110 | radius, radius, Path.Direction.CW); |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 111 | |
| 112 | // Update the outline |
| 113 | Outline o = new Outline(); |
| 114 | o.setRoundRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), radius); |
| 115 | setOutline(o); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 119 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 120 | switch (ev.getAction()) { |
| 121 | case MotionEvent.ACTION_DOWN: |
| 122 | case MotionEvent.ACTION_MOVE: |
| 123 | mLastTouchDown.set((int) ev.getX(), (int) ev.getY()); |
| 124 | break; |
| 125 | } |
| 126 | return super.onInterceptTouchEvent(ev); |
| 127 | } |
| 128 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 129 | /** Set callback */ |
| 130 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 131 | mCb = cb; |
| 132 | } |
| 133 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 134 | /** Gets the task */ |
| 135 | Task getTask() { |
| 136 | return mTask; |
| 137 | } |
| 138 | |
| 139 | /** Synchronizes this view's properties with the task's transform */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 140 | void updateViewPropertiesToTaskTransform(TaskViewTransform animateFromTransform, |
| 141 | TaskViewTransform toTransform, int duration) { |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 142 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 143 | int minZ = config.taskViewTranslationZMinPx; |
| 144 | int incZ = config.taskViewTranslationZIncrementPx; |
| 145 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 146 | if (duration > 0) { |
| 147 | if (animateFromTransform != null) { |
| 148 | setTranslationY(animateFromTransform.translationY); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame^] | 149 | if (Constants.DebugFlags.App.EnableShadows) { |
| 150 | setTranslationZ(Math.max(minZ, minZ + (animateFromTransform.t * incZ))); |
| 151 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 152 | setScaleX(animateFromTransform.scale); |
| 153 | setScaleY(animateFromTransform.scale); |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 154 | setAlpha(animateFromTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 155 | } |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame^] | 156 | if (Constants.DebugFlags.App.EnableShadows) { |
| 157 | animate().translationZ(Math.max(minZ, minZ + (toTransform.t * incZ))); |
| 158 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 159 | animate().translationY(toTransform.translationY) |
| 160 | .scaleX(toTransform.scale) |
| 161 | .scaleY(toTransform.scale) |
| 162 | .alpha(toTransform.alpha) |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 163 | .setDuration(duration) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 164 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 165 | .withLayer() |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 166 | .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 167 | @Override |
| 168 | public void onAnimationUpdate(ValueAnimator animation) { |
| 169 | updateDimOverlayFromScale(); |
| 170 | } |
| 171 | }) |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 172 | .start(); |
| 173 | } else { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 174 | setTranslationY(toTransform.translationY); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame^] | 175 | if (Constants.DebugFlags.App.EnableShadows) { |
| 176 | setTranslationZ(Math.max(minZ, minZ + (toTransform.t * incZ))); |
| 177 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 178 | setScaleX(toTransform.scale); |
| 179 | setScaleY(toTransform.scale); |
| 180 | setAlpha(toTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 181 | } |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 182 | updateDimOverlayFromScale(); |
| 183 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** Resets this view's properties */ |
| 187 | void resetViewProperties() { |
| 188 | setTranslationX(0f); |
| 189 | setTranslationY(0f); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame^] | 190 | if (Constants.DebugFlags.App.EnableShadows) { |
| 191 | setTranslationZ(0f); |
| 192 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 193 | setScaleX(1f); |
| 194 | setScaleY(1f); |
| 195 | setAlpha(1f); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 196 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 199 | /** |
| 200 | * When we are un/filtering, this method will set up the transform that we are animating to, |
| 201 | * in order to hide the task. |
| 202 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 203 | void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { |
| 204 | // Fade the view out and slide it away |
| 205 | toTransform.alpha = 0f; |
| 206 | toTransform.translationY += 200; |
| 207 | } |
| 208 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 209 | /** |
| 210 | * When we are un/filtering, this method will setup the transform that we are animating from, |
| 211 | * in order to show the task. |
| 212 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 213 | void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { |
| 214 | // Fade the view in |
| 215 | fromTransform.alpha = 0f; |
| 216 | } |
| 217 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 218 | /** Animates this task view as it enters recents */ |
| 219 | public void animateOnEnterRecents() { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 220 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 221 | mBarView.setAlpha(0f); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 222 | mBarView.animate() |
| 223 | .alpha(1f) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 224 | .setStartDelay(235) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 225 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 226 | .setDuration(config.taskBarEnterAnimDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 227 | .withLayer() |
| 228 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /** Animates this task view as it exits recents */ |
| 232 | public void animateOnLeavingRecents(final Runnable r) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 233 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 234 | mBarView.animate() |
| 235 | .alpha(0f) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 236 | .setStartDelay(0) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 237 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 238 | .setDuration(config.taskBarExitAnimDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 239 | .withLayer() |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 240 | .withEndAction(new Runnable() { |
| 241 | @Override |
| 242 | public void run() { |
| 243 | post(r); |
| 244 | } |
| 245 | }) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 246 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** 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] | 250 | Rect getClippingRect(Rect outRect) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 251 | getHitRect(outRect); |
| 252 | // XXX: We should get the hit rect of the thumbnail view and intersect, but this is faster |
| 253 | outRect.right = outRect.left + mThumbnailView.getRight(); |
| 254 | outRect.bottom = outRect.top + mThumbnailView.getBottom(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 255 | return outRect; |
| 256 | } |
| 257 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 258 | /** Returns whether this task has an info pane visible */ |
| 259 | boolean isInfoPaneVisible() { |
| 260 | return mTaskInfoPaneVisible; |
| 261 | } |
| 262 | |
| 263 | /** Shows the info pane if it is not visible. */ |
| 264 | void showInfoPane(Rect taskVisibleRect) { |
| 265 | if (mTaskInfoPaneVisible) return; |
| 266 | |
| 267 | // Remove the bar view from the visible rect and update the info pane contents |
| 268 | taskVisibleRect.top += mBarView.getMeasuredHeight(); |
| 269 | mInfoView.updateContents(taskVisibleRect); |
| 270 | |
| 271 | // Show the info pane and animate it into view |
| 272 | mInfoView.setVisibility(View.VISIBLE); |
| 273 | mInfoView.animateCircularClip(mLastTouchDown, 0f, 1f, null, true); |
| 274 | mInfoView.setOnClickListener(this); |
| 275 | mTaskInfoPaneVisible = true; |
| 276 | |
| 277 | // Notify any callbacks |
| 278 | if (mCb != null) { |
| 279 | mCb.onTaskInfoPanelShown(this); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /** Hides the info pane if it is visible. */ |
| 284 | void hideInfoPane() { |
| 285 | if (!mTaskInfoPaneVisible) return; |
| 286 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 287 | |
| 288 | // Cancel any circular clip animation |
| 289 | mInfoView.cancelCircularClipAnimation(); |
| 290 | |
| 291 | // Animate the info pane out |
| 292 | mInfoView.animate() |
| 293 | .alpha(0f) |
| 294 | .setDuration(config.taskViewInfoPaneAnimDuration) |
| 295 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
| 296 | .withLayer() |
| 297 | .withEndAction(new Runnable() { |
| 298 | @Override |
| 299 | public void run() { |
| 300 | mInfoView.setVisibility(View.INVISIBLE); |
| 301 | mInfoView.setOnClickListener(null); |
| 302 | |
| 303 | mInfoView.setAlpha(1f); |
| 304 | } |
| 305 | }) |
| 306 | .start(); |
| 307 | mTaskInfoPaneVisible = false; |
| 308 | |
| 309 | // Notify any callbacks |
| 310 | if (mCb != null) { |
| 311 | mCb.onTaskInfoPanelHidden(this); |
| 312 | } |
| 313 | } |
| 314 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 315 | /** Enable the hw layers on this task view */ |
| 316 | void enableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 317 | mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 318 | } |
| 319 | |
| 320 | /** Disable the hw layers on this task view */ |
| 321 | void disableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 322 | mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 323 | } |
| 324 | |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 325 | /** Update the dim as a function of the scale of this view. */ |
| 326 | void updateDimOverlayFromScale() { |
| 327 | float minScale = Constants.Values.TaskStackView.StackPeekMinScale; |
| 328 | float scaleRange = 1f - minScale; |
| 329 | float dim = (1f - getScaleX()) / scaleRange; |
| 330 | dim = mDimInterpolator.getInterpolation(Math.min(dim, 1f)); |
| 331 | mDim = Math.max(0, Math.min(mMaxDim, (int) (dim * 255))); |
| 332 | invalidate(); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void draw(Canvas canvas) { |
| 337 | // Apply the rounded rect clip path on the whole view |
| 338 | canvas.clipPath(mRoundedRectClipPath); |
| 339 | |
| 340 | super.draw(canvas); |
| 341 | |
| 342 | // Apply the dim if necessary |
| 343 | if (mDim > 0) { |
| 344 | canvas.drawColor(mDim << 24); |
| 345 | } |
| 346 | } |
| 347 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 348 | /**** TaskCallbacks Implementation ****/ |
| 349 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 350 | /** Binds this task view to the task */ |
| 351 | public void onTaskBound(Task t) { |
| 352 | mTask = t; |
| 353 | mTask.setCallbacks(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Override |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 357 | public void onTaskDataLoaded(boolean reloadingTaskData) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 358 | if (mThumbnailView != null && mBarView != null && mInfoView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 359 | // Bind each of the views to the new task data |
| 360 | mThumbnailView.rebindToTask(mTask, reloadingTaskData); |
| 361 | mBarView.rebindToTask(mTask, reloadingTaskData); |
Winson Chung | f5e22e7 | 2014-05-02 18:35:35 -0700 | [diff] [blame] | 362 | mInfoView.rebindToTask(mTask, reloadingTaskData); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 363 | // Rebind any listeners |
| 364 | mBarView.mApplicationIcon.setOnClickListener(this); |
| 365 | mInfoView.mAppInfoButton.setOnClickListener(this); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 366 | } |
| 367 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 371 | public void onTaskDataUnloaded() { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 372 | if (mThumbnailView != null && mBarView != null && mInfoView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 373 | // Unbind each of the views from the task data and remove the task callback |
| 374 | mTask.setCallbacks(null); |
| 375 | mThumbnailView.unbindFromTask(); |
| 376 | mBarView.unbindFromTask(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 377 | // Unbind any listeners |
| 378 | mBarView.mApplicationIcon.setOnClickListener(null); |
| 379 | mInfoView.mAppInfoButton.setOnClickListener(null); |
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 | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 386 | if (v == mInfoView) { |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 387 | hideInfoPane(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 388 | } else if (v == mBarView.mApplicationIcon) { |
| 389 | mCb.onTaskIconClicked(this); |
| 390 | } else if (v == mInfoView.mAppInfoButton) { |
| 391 | mCb.onTaskAppInfoClicked(this); |
| 392 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 393 | } |
| 394 | } |