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