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 | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 20 | import android.graphics.Point; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 21 | import android.graphics.Rect; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 23 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 24 | import android.view.View; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 25 | import android.widget.FrameLayout; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 26 | import com.android.systemui.R; |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 27 | import com.android.systemui.recents.BakedBezierInterpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import com.android.systemui.recents.RecentsConfiguration; |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 29 | import com.android.systemui.recents.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 30 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 31 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 32 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 33 | /* A task view */ |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 34 | public class TaskView extends FrameLayout implements View.OnClickListener, |
| 35 | Task.TaskCallbacks { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 36 | /** The TaskView callbacks */ |
| 37 | interface TaskViewCallbacks { |
| 38 | public void onTaskIconClicked(TaskView tv); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 39 | public void onTaskInfoPanelShown(TaskView tv); |
| 40 | public void onTaskInfoPanelHidden(TaskView tv); |
| 41 | public void onTaskAppInfoClicked(TaskView tv); |
| 42 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 43 | // public void onTaskViewReboundToTask(TaskView tv, Task t); |
| 44 | } |
| 45 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 46 | Task mTask; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 47 | boolean mTaskDataLoaded; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 48 | boolean mTaskInfoPaneVisible; |
| 49 | Point mLastTouchDown = new Point(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 50 | |
| 51 | TaskThumbnailView mThumbnailView; |
| 52 | TaskBarView mBarView; |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 53 | TaskInfoView mInfoView; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 54 | TaskViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 55 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 56 | |
| 57 | public TaskView(Context context) { |
| 58 | this(context, null); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 61 | public TaskView(Context context, AttributeSet attrs) { |
| 62 | this(context, attrs, 0); |
| 63 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 64 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 65 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 66 | this(context, attrs, defStyleAttr, 0); |
| 67 | } |
| 68 | |
| 69 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 70 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void onFinishInflate() { |
| 75 | // Bind the views |
| 76 | mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail); |
| 77 | mBarView = (TaskBarView) findViewById(R.id.task_view_bar); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 78 | mInfoView = (TaskInfoView) findViewById(R.id.task_view_info_pane); |
| 79 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 80 | if (mTaskDataLoaded) { |
| 81 | onTaskDataLoaded(false); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 85 | @Override |
| 86 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 87 | switch (ev.getAction()) { |
| 88 | case MotionEvent.ACTION_DOWN: |
| 89 | case MotionEvent.ACTION_MOVE: |
| 90 | mLastTouchDown.set((int) ev.getX(), (int) ev.getY()); |
| 91 | break; |
| 92 | } |
| 93 | return super.onInterceptTouchEvent(ev); |
| 94 | } |
| 95 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 96 | /** Set callback */ |
| 97 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 98 | mCb = cb; |
| 99 | } |
| 100 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 101 | /** Gets the task */ |
| 102 | Task getTask() { |
| 103 | return mTask; |
| 104 | } |
| 105 | |
| 106 | /** Synchronizes this view's properties with the task's transform */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 107 | void updateViewPropertiesToTaskTransform(TaskViewTransform animateFromTransform, |
| 108 | TaskViewTransform toTransform, int duration) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 109 | if (duration > 0) { |
| 110 | if (animateFromTransform != null) { |
| 111 | setTranslationY(animateFromTransform.translationY); |
| 112 | setScaleX(animateFromTransform.scale); |
| 113 | setScaleY(animateFromTransform.scale); |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 114 | setAlpha(animateFromTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 115 | } |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 116 | animate().translationY(toTransform.translationY) |
| 117 | .scaleX(toTransform.scale) |
| 118 | .scaleY(toTransform.scale) |
| 119 | .alpha(toTransform.alpha) |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 120 | .setDuration(duration) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 121 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 122 | .withLayer() |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 123 | .start(); |
| 124 | } else { |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 125 | setTranslationY(toTransform.translationY); |
| 126 | setScaleX(toTransform.scale); |
| 127 | setScaleY(toTransform.scale); |
| 128 | setAlpha(toTransform.alpha); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | /** Resets this view's properties */ |
| 133 | void resetViewProperties() { |
| 134 | setTranslationX(0f); |
| 135 | setTranslationY(0f); |
| 136 | setScaleX(1f); |
| 137 | setScaleY(1f); |
| 138 | setAlpha(1f); |
| 139 | } |
| 140 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 141 | /** |
| 142 | * When we are un/filtering, this method will set up the transform that we are animating to, |
| 143 | * in order to hide the task. |
| 144 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 145 | void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { |
| 146 | // Fade the view out and slide it away |
| 147 | toTransform.alpha = 0f; |
| 148 | toTransform.translationY += 200; |
| 149 | } |
| 150 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 151 | /** |
| 152 | * When we are un/filtering, this method will setup the transform that we are animating from, |
| 153 | * in order to show the task. |
| 154 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 155 | void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { |
| 156 | // Fade the view in |
| 157 | fromTransform.alpha = 0f; |
| 158 | } |
| 159 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 160 | /** Animates this task view as it enters recents */ |
| 161 | public void animateOnEnterRecents() { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 162 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 163 | int translate = config.pxFromDp(10); |
| 164 | mBarView.setScaleX(1.25f); |
| 165 | mBarView.setScaleY(1.25f); |
| 166 | mBarView.setAlpha(0f); |
| 167 | mBarView.setTranslationX(translate / 2); |
| 168 | mBarView.setTranslationY(-translate); |
| 169 | mBarView.animate() |
| 170 | .alpha(1f) |
| 171 | .scaleX(1f) |
| 172 | .scaleY(1f) |
| 173 | .translationX(0) |
| 174 | .translationY(0) |
| 175 | .setStartDelay(235) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 176 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 177 | .setDuration(config.taskBarEnterAnimDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 178 | .withLayer() |
| 179 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** Animates this task view as it exits recents */ |
| 183 | public void animateOnLeavingRecents(final Runnable r) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 184 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 185 | int translate = config.pxFromDp(10); |
| 186 | mBarView.animate() |
| 187 | .alpha(0f) |
| 188 | .scaleX(1.1f) |
| 189 | .scaleY(1.1f) |
| 190 | .translationX(translate / 2) |
| 191 | .translationY(-translate) |
| 192 | .setStartDelay(0) |
Winson Chung | 2f2ca08 | 2014-04-03 18:05:29 -0700 | [diff] [blame] | 193 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
| 194 | .setDuration(Utilities.calculateTranslationAnimationDuration(translate)) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 195 | .withLayer() |
Winson Chung | 0d76755 | 2014-04-09 14:33:23 -0700 | [diff] [blame] | 196 | .withEndAction(new Runnable() { |
| 197 | @Override |
| 198 | public void run() { |
| 199 | post(r); |
| 200 | } |
| 201 | }) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 202 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** 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] | 206 | Rect getClippingRect(Rect outRect) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 207 | getHitRect(outRect); |
| 208 | // XXX: We should get the hit rect of the thumbnail view and intersect, but this is faster |
| 209 | outRect.right = outRect.left + mThumbnailView.getRight(); |
| 210 | outRect.bottom = outRect.top + mThumbnailView.getBottom(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 211 | return outRect; |
| 212 | } |
| 213 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 214 | /** Returns whether this task has an info pane visible */ |
| 215 | boolean isInfoPaneVisible() { |
| 216 | return mTaskInfoPaneVisible; |
| 217 | } |
| 218 | |
| 219 | /** Shows the info pane if it is not visible. */ |
| 220 | void showInfoPane(Rect taskVisibleRect) { |
| 221 | if (mTaskInfoPaneVisible) return; |
| 222 | |
| 223 | // Remove the bar view from the visible rect and update the info pane contents |
| 224 | taskVisibleRect.top += mBarView.getMeasuredHeight(); |
| 225 | mInfoView.updateContents(taskVisibleRect); |
| 226 | |
| 227 | // Show the info pane and animate it into view |
| 228 | mInfoView.setVisibility(View.VISIBLE); |
| 229 | mInfoView.animateCircularClip(mLastTouchDown, 0f, 1f, null, true); |
| 230 | mInfoView.setOnClickListener(this); |
| 231 | mTaskInfoPaneVisible = true; |
| 232 | |
| 233 | // Notify any callbacks |
| 234 | if (mCb != null) { |
| 235 | mCb.onTaskInfoPanelShown(this); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /** Hides the info pane if it is visible. */ |
| 240 | void hideInfoPane() { |
| 241 | if (!mTaskInfoPaneVisible) return; |
| 242 | RecentsConfiguration config = RecentsConfiguration.getInstance(); |
| 243 | |
| 244 | // Cancel any circular clip animation |
| 245 | mInfoView.cancelCircularClipAnimation(); |
| 246 | |
| 247 | // Animate the info pane out |
| 248 | mInfoView.animate() |
| 249 | .alpha(0f) |
| 250 | .setDuration(config.taskViewInfoPaneAnimDuration) |
| 251 | .setInterpolator(BakedBezierInterpolator.INSTANCE) |
| 252 | .withLayer() |
| 253 | .withEndAction(new Runnable() { |
| 254 | @Override |
| 255 | public void run() { |
| 256 | mInfoView.setVisibility(View.INVISIBLE); |
| 257 | mInfoView.setOnClickListener(null); |
| 258 | |
| 259 | mInfoView.setAlpha(1f); |
| 260 | } |
| 261 | }) |
| 262 | .start(); |
| 263 | mTaskInfoPaneVisible = false; |
| 264 | |
| 265 | // Notify any callbacks |
| 266 | if (mCb != null) { |
| 267 | mCb.onTaskInfoPanelHidden(this); |
| 268 | } |
| 269 | } |
| 270 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 271 | /** Enable the hw layers on this task view */ |
| 272 | void enableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 273 | mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 274 | } |
| 275 | |
| 276 | /** Disable the hw layers on this task view */ |
| 277 | void disableHwLayers() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 278 | mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 279 | } |
| 280 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 281 | /**** TaskCallbacks Implementation ****/ |
| 282 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 283 | /** Binds this task view to the task */ |
| 284 | public void onTaskBound(Task t) { |
| 285 | mTask = t; |
| 286 | mTask.setCallbacks(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 290 | public void onTaskDataLoaded(boolean reloadingTaskData) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 291 | if (mThumbnailView != null && mBarView != null && mInfoView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 292 | // Bind each of the views to the new task data |
| 293 | mThumbnailView.rebindToTask(mTask, reloadingTaskData); |
| 294 | mBarView.rebindToTask(mTask, reloadingTaskData); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 295 | // Rebind any listeners |
| 296 | mBarView.mApplicationIcon.setOnClickListener(this); |
| 297 | mInfoView.mAppInfoButton.setOnClickListener(this); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 298 | } |
| 299 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 303 | public void onTaskDataUnloaded() { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 304 | if (mThumbnailView != null && mBarView != null && mInfoView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 305 | // Unbind each of the views from the task data and remove the task callback |
| 306 | mTask.setCallbacks(null); |
| 307 | mThumbnailView.unbindFromTask(); |
| 308 | mBarView.unbindFromTask(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 309 | // Unbind any listeners |
| 310 | mBarView.mApplicationIcon.setOnClickListener(null); |
| 311 | mInfoView.mAppInfoButton.setOnClickListener(null); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 312 | } |
| 313 | mTaskDataLoaded = false; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 317 | public void onClick(View v) { |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame^] | 318 | if (v == mInfoView) { |
| 319 | // Do nothing |
| 320 | } else if (v == mBarView.mApplicationIcon) { |
| 321 | mCb.onTaskIconClicked(this); |
| 322 | } else if (v == mInfoView.mAppInfoButton) { |
| 323 | mCb.onTaskAppInfoClicked(this); |
| 324 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 325 | } |
| 326 | } |