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 | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 24 | import android.graphics.Canvas; |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 25 | import android.graphics.Outline; |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 26 | import android.graphics.Paint; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 29 | import android.view.View; |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame^] | 30 | import android.view.ViewOutlineProvider; |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 31 | import android.view.ViewPropertyAnimator; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 32 | import android.view.animation.AccelerateInterpolator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 34 | import com.android.systemui.R; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 35 | import com.android.systemui.recents.misc.Console; |
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 | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 39 | import com.android.systemui.recents.model.TaskStack; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 40 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 41 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 42 | /* A task view */ |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 43 | public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.OnClickListener, |
| 44 | View.OnLongClickListener { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 45 | /** The TaskView callbacks */ |
| 46 | interface TaskViewCallbacks { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 47 | public void onTaskViewAppIconClicked(TaskView tv); |
| 48 | public void onTaskViewAppInfoClicked(TaskView tv); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 49 | public void onTaskViewClicked(TaskView tv, Task t, boolean lockToTask); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 50 | public void onTaskViewDismissed(TaskView tv); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 53 | RecentsConfiguration mConfig; |
| 54 | |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 55 | int mFooterHeight; |
| 56 | int mMaxFooterHeight; |
| 57 | ObjectAnimator mFooterAnimator; |
| 58 | |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 59 | int mDim; |
| 60 | int mMaxDim; |
Winson Chung | 6057c91 | 2014-07-08 14:39:08 -0700 | [diff] [blame] | 61 | AccelerateInterpolator mDimInterpolator = new AccelerateInterpolator(); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 62 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 63 | Task mTask; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 64 | boolean mTaskDataLoaded; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 65 | boolean mIsFocused; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 66 | boolean mIsStub; |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 67 | boolean mClipViewInStack; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 68 | Rect mTmpRect = new Rect(); |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 69 | Paint mLayerPaint = new Paint(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 70 | |
| 71 | TaskThumbnailView mThumbnailView; |
| 72 | TaskBarView mBarView; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 73 | View mLockToAppButtonView; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 74 | TaskViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 75 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 76 | // Optimizations |
| 77 | ValueAnimator.AnimatorUpdateListener mUpdateDimListener = |
| 78 | new ValueAnimator.AnimatorUpdateListener() { |
| 79 | @Override |
| 80 | public void onAnimationUpdate(ValueAnimator animation) { |
| 81 | updateDimOverlayFromScale(); |
| 82 | } |
| 83 | }; |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 84 | Runnable mEnableThumbnailClip = new Runnable() { |
| 85 | @Override |
| 86 | public void run() { |
| 87 | mThumbnailView.updateTaskBarClip(mBarView); |
| 88 | } |
| 89 | }; |
| 90 | Runnable mDisableThumbnailClip = new Runnable() { |
| 91 | @Override |
| 92 | public void run() { |
| 93 | mThumbnailView.disableClipTaskBarView(); |
| 94 | } |
| 95 | }; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 96 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 97 | |
| 98 | public TaskView(Context context) { |
| 99 | this(context, null); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 102 | public TaskView(Context context, AttributeSet attrs) { |
| 103 | this(context, attrs, 0); |
| 104 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 105 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 106 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 107 | this(context, attrs, defStyleAttr, 0); |
| 108 | } |
| 109 | |
| 110 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 111 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 112 | mConfig = RecentsConfiguration.getInstance(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 113 | mMaxFooterHeight = mConfig.taskViewLockToAppButtonHeight; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 114 | setWillNotDraw(false); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 115 | setClipToOutline(true); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 116 | setDim(getDim()); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 117 | setFooterHeight(getFooterHeight()); |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame^] | 118 | setOutlineProvider(new ViewOutlineProvider() { |
| 119 | @Override |
| 120 | public boolean getOutline(View view, Outline outline) { |
| 121 | int height = getHeight() - mMaxFooterHeight + mFooterHeight; |
| 122 | outline.setRoundRect(0, 0, getWidth(), height, |
| 123 | mConfig.taskViewRoundedCornerRadiusPx); |
| 124 | return true; |
| 125 | } |
| 126 | }); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
| 130 | protected void onFinishInflate() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 131 | mMaxDim = mConfig.taskStackMaxDim; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 132 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 133 | // By default, all views are clipped to other views in their stack |
| 134 | mClipViewInStack = true; |
| 135 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 136 | // Bind the views |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 137 | mBarView = (TaskBarView) findViewById(R.id.task_view_bar); |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 138 | mThumbnailView = (TaskThumbnailView) findViewById(R.id.task_view_thumbnail); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 139 | mLockToAppButtonView = findViewById(R.id.lock_to_app); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 140 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 141 | if (mTaskDataLoaded) { |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 142 | onTaskDataLoaded(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 146 | @Override |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 147 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 148 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 149 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 150 | |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 151 | // Measure the bar view, thumbnail, and lock-to-app buttons |
| 152 | mBarView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 153 | MeasureSpec.makeMeasureSpec(mConfig.taskBarHeight, MeasureSpec.EXACTLY)); |
| 154 | mLockToAppButtonView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 155 | MeasureSpec.makeMeasureSpec(mConfig.taskViewLockToAppButtonHeight, |
| 156 | MeasureSpec.EXACTLY)); |
| 157 | // Measure the thumbnail height to be the same as the width |
| 158 | mThumbnailView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 159 | MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY)); |
| 160 | setMeasuredDimension(width, height); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 163 | /** Set callback */ |
| 164 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 165 | mCb = cb; |
| 166 | } |
| 167 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 168 | /** Gets the task */ |
| 169 | Task getTask() { |
| 170 | return mTask; |
| 171 | } |
| 172 | |
| 173 | /** Synchronizes this view's properties with the task's transform */ |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 174 | void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, int duration) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 175 | if (Console.Enabled) { |
| 176 | Console.log(Constants.Log.UI.Draw, "[TaskView|updateViewPropertiesToTaskTransform]", |
| 177 | "duration: " + duration, Console.AnsiPurple); |
| 178 | } |
Winson Chung | 96e3bc1 | 2014-05-06 16:44:12 -0700 | [diff] [blame] | 179 | |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 180 | // Update the bar view |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 181 | mBarView.updateViewPropertiesToTaskTransform(toTransform, duration); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 182 | |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 183 | // Check to see if any properties have changed, and update the task view |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 184 | if (duration > 0) { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 185 | ViewPropertyAnimator anim = animate(); |
| 186 | boolean useLayers = false; |
| 187 | |
| 188 | // Animate to the final state |
| 189 | if (toTransform.hasTranslationYChangedFrom(getTranslationY())) { |
| 190 | anim.translationY(toTransform.translationY); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 191 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 192 | if (Constants.DebugFlags.App.EnableShadows && |
| 193 | toTransform.hasTranslationZChangedFrom(getTranslationZ())) { |
| 194 | anim.translationZ(toTransform.translationZ); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 195 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 196 | if (toTransform.hasScaleChangedFrom(getScaleX())) { |
| 197 | anim.scaleX(toTransform.scale) |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 198 | .scaleY(toTransform.scale) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 199 | .setUpdateListener(mUpdateDimListener); |
| 200 | useLayers = true; |
| 201 | } |
| 202 | if (toTransform.hasAlphaChangedFrom(getAlpha())) { |
| 203 | // Use layers if we animate alpha |
| 204 | anim.alpha(toTransform.alpha); |
| 205 | useLayers = true; |
| 206 | } |
| 207 | if (useLayers) { |
| 208 | anim.withLayer(); |
| 209 | } |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 210 | anim.setStartDelay(toTransform.startDelay) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 211 | .setDuration(duration) |
| 212 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 213 | .start(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 214 | } else { |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 215 | // Set the changed properties |
| 216 | if (toTransform.hasTranslationYChangedFrom(getTranslationY())) { |
| 217 | setTranslationY(toTransform.translationY); |
| 218 | } |
| 219 | if (Constants.DebugFlags.App.EnableShadows && |
| 220 | toTransform.hasTranslationZChangedFrom(getTranslationZ())) { |
Winson Chung | b13c46e | 2014-06-09 18:33:08 -0700 | [diff] [blame] | 221 | setTranslationZ(toTransform.translationZ); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 222 | } |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 223 | if (toTransform.hasScaleChangedFrom(getScaleX())) { |
| 224 | setScaleX(toTransform.scale); |
| 225 | setScaleY(toTransform.scale); |
| 226 | updateDimOverlayFromScale(); |
| 227 | } |
| 228 | if (toTransform.hasAlphaChangedFrom(getAlpha())) { |
| 229 | setAlpha(toTransform.alpha); |
| 230 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | /** Resets this view's properties */ |
| 235 | void resetViewProperties() { |
| 236 | setTranslationX(0f); |
| 237 | setTranslationY(0f); |
Winson Chung | 814086d | 2014-05-07 15:01:14 -0700 | [diff] [blame] | 238 | if (Constants.DebugFlags.App.EnableShadows) { |
| 239 | setTranslationZ(0f); |
| 240 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 241 | setScaleX(1f); |
| 242 | setScaleY(1f); |
| 243 | setAlpha(1f); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 244 | setDim(0); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 245 | invalidate(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 248 | /** |
| 249 | * When we are un/filtering, this method will set up the transform that we are animating to, |
| 250 | * in order to hide the task. |
| 251 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 252 | void prepareTaskTransformForFilterTaskHidden(TaskViewTransform toTransform) { |
| 253 | // Fade the view out and slide it away |
| 254 | toTransform.alpha = 0f; |
| 255 | toTransform.translationY += 200; |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 256 | toTransform.translationZ = 0; |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Winson Chung | 11ca76a5 | 2014-04-10 17:29:13 -0700 | [diff] [blame] | 259 | /** |
| 260 | * When we are un/filtering, this method will setup the transform that we are animating from, |
| 261 | * in order to show the task. |
| 262 | */ |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 263 | void prepareTaskTransformForFilterTaskVisible(TaskViewTransform fromTransform) { |
| 264 | // Fade the view in |
| 265 | fromTransform.alpha = 0f; |
| 266 | } |
| 267 | |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 268 | /** Prepares this task view for the enter-recents animations. This is called earlier in the |
| 269 | * first layout because the actual animation into recents may take a long time. */ |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 270 | public void prepareEnterRecentsAnimation(boolean isTaskViewLaunchTargetTask, int offsetY, |
| 271 | int offscreenY) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 272 | if (mConfig.launchedFromAppWithScreenshot) { |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 273 | if (isTaskViewLaunchTargetTask) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 274 | // Hide the task view as we are going to animate the full screenshot into view |
| 275 | // and then replace it with this view once we are done |
| 276 | setVisibility(View.INVISIBLE); |
| 277 | // Also hide the front most task bar view so we can animate it in |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 278 | mBarView.prepareEnterRecentsAnimation(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 279 | } else { |
| 280 | // Top align the task views |
| 281 | setTranslationY(offsetY); |
| 282 | setScaleX(1f); |
| 283 | setScaleY(1f); |
| 284 | } |
| 285 | |
| 286 | } else if (mConfig.launchedFromAppWithThumbnail) { |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 287 | if (isTaskViewLaunchTargetTask) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 288 | // Hide the front most task bar view so we can animate it in |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 289 | mBarView.prepareEnterRecentsAnimation(); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 290 | // Set the dim to 0 so we can animate it in |
| 291 | setDim(0); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | } else if (mConfig.launchedFromHome) { |
| 295 | // Move the task view off screen (below) so we can animate it in |
| 296 | setTranslationY(offscreenY); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 297 | if (Constants.DebugFlags.App.EnableShadows) { |
| 298 | setTranslationZ(0); |
| 299 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 300 | setScaleX(1f); |
| 301 | setScaleY(1f); |
| 302 | } |
Winson Chung | 24cf152 | 2014-05-29 12:03:33 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 305 | /** Animates this task view as it enters recents */ |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 306 | public void startEnterRecentsAnimation(final ViewAnimation.TaskViewEnterContext ctx) { |
Winson Chung | 6057c91 | 2014-07-08 14:39:08 -0700 | [diff] [blame] | 307 | TaskViewTransform transform = ctx.currentTaskTransform; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 308 | |
| 309 | if (mConfig.launchedFromAppWithScreenshot) { |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 310 | if (ctx.isCurrentTaskLaunchTarget) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 311 | // Animate the full screenshot down first, before swapping with this task view |
Winson Chung | 6057c91 | 2014-07-08 14:39:08 -0700 | [diff] [blame] | 312 | ctx.fullScreenshotView.animateOnEnterRecents(ctx, new Runnable() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 313 | @Override |
| 314 | public void run() { |
| 315 | // Animate the task bar of the first task view |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 316 | mBarView.startEnterRecentsAnimation(0, mEnableThumbnailClip); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 317 | setVisibility(View.VISIBLE); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 318 | // Animate the footer into view |
| 319 | animateFooterVisibility(true, mConfig.taskBarEnterAnimDuration, 0); |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 320 | // Decrement the post animation trigger |
| 321 | ctx.postAnimationTrigger.decrement(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 322 | } |
| 323 | }); |
| 324 | } else { |
| 325 | // Animate the tasks down behind the full screenshot |
| 326 | animate() |
| 327 | .scaleX(transform.scale) |
| 328 | .scaleY(transform.scale) |
| 329 | .translationY(transform.translationY) |
| 330 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 331 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 332 | .setInterpolator(mConfig.linearOutSlowInInterpolator) |
| 333 | .setDuration(475) |
| 334 | .withLayer() |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 335 | .withEndAction(new Runnable() { |
| 336 | @Override |
| 337 | public void run() { |
| 338 | mEnableThumbnailClip.run(); |
| 339 | // Decrement the post animation trigger |
| 340 | ctx.postAnimationTrigger.decrement(); |
| 341 | } |
| 342 | }) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 343 | .start(); |
| 344 | } |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 345 | ctx.postAnimationTrigger.increment(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 346 | |
| 347 | } else if (mConfig.launchedFromAppWithThumbnail) { |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 348 | if (ctx.isCurrentTaskLaunchTarget) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 349 | // Animate the task bar of the first task view |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 350 | mBarView.startEnterRecentsAnimation(mConfig.taskBarEnterAnimDelay, mEnableThumbnailClip); |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 351 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 352 | // Animate the dim into view as well |
| 353 | ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", getDimOverlayFromScale()); |
| 354 | anim.setStartDelay(mConfig.taskBarEnterAnimDelay); |
| 355 | anim.setDuration(mConfig.taskBarEnterAnimDuration); |
| 356 | anim.setInterpolator(mConfig.fastOutLinearInInterpolator); |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 357 | anim.addListener(new AnimatorListenerAdapter() { |
| 358 | @Override |
| 359 | public void onAnimationEnd(Animator animation) { |
| 360 | // Decrement the post animation trigger |
| 361 | ctx.postAnimationTrigger.decrement(); |
| 362 | } |
| 363 | }); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 364 | anim.start(); |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 365 | ctx.postAnimationTrigger.increment(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 366 | |
| 367 | // Animate the footer into view |
| 368 | animateFooterVisibility(true, mConfig.taskBarEnterAnimDuration, |
| 369 | mConfig.taskBarEnterAnimDelay); |
Winson Chung | 743d5c9 | 2014-06-13 10:14:53 -0700 | [diff] [blame] | 370 | } else { |
| 371 | mEnableThumbnailClip.run(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | } else if (mConfig.launchedFromHome) { |
| 375 | // Animate the tasks up |
Winson Chung | 6057c91 | 2014-07-08 14:39:08 -0700 | [diff] [blame] | 376 | int frontIndex = (ctx.currentStackViewCount - ctx.currentStackViewIndex - 1); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 377 | int delay = mConfig.taskBarEnterAnimDelay + |
| 378 | frontIndex * mConfig.taskViewEnterFromHomeDelay; |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 379 | if (Constants.DebugFlags.App.EnableShadows) { |
| 380 | animate().translationZ(transform.translationZ); |
| 381 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 382 | animate() |
| 383 | .scaleX(transform.scale) |
| 384 | .scaleY(transform.scale) |
| 385 | .translationY(transform.translationY) |
| 386 | .setStartDelay(delay) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 387 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 388 | .setInterpolator(mConfig.quintOutInterpolator) |
| 389 | .setDuration(mConfig.taskViewEnterFromHomeDuration) |
| 390 | .withLayer() |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 391 | .withEndAction(new Runnable() { |
| 392 | @Override |
| 393 | public void run() { |
| 394 | mEnableThumbnailClip.run(); |
| 395 | // Decrement the post animation trigger |
| 396 | ctx.postAnimationTrigger.decrement(); |
| 397 | } |
| 398 | }) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 399 | .start(); |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 400 | ctx.postAnimationTrigger.increment(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 401 | |
| 402 | // Animate the footer into view |
| 403 | animateFooterVisibility(true, mConfig.taskViewEnterFromHomeDuration, |
| 404 | mConfig.taskBarEnterAnimDelay); |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 405 | } else { |
| 406 | // Otherwise, just enable the thumbnail clip |
| 407 | mEnableThumbnailClip.run(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 408 | |
| 409 | // Animate the footer into view |
| 410 | animateFooterVisibility(true, 0, 0); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 414 | /** Animates this task view as it leaves recents by pressing home. */ |
| 415 | public void startExitToHomeAnimation(ViewAnimation.TaskViewExitContext ctx) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 416 | animate() |
| 417 | .translationY(ctx.offscreenTranslationY) |
| 418 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 419 | .setUpdateListener(null) |
Winson Chung | ad6f276 | 2014-06-13 09:41:09 -0700 | [diff] [blame] | 420 | .setInterpolator(mConfig.fastOutLinearInInterpolator) |
| 421 | .setDuration(mConfig.taskViewExitToHomeDuration) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 422 | .withLayer() |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 423 | .withEndAction(ctx.postAnimationTrigger.decrementAsRunnable()) |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 424 | .start(); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 425 | ctx.postAnimationTrigger.increment(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** Animates this task view as it exits recents */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 429 | public void startLaunchTaskAnimation(final Runnable r, boolean isLaunchingTask) { |
| 430 | if (isLaunchingTask) { |
| 431 | // Disable the thumbnail clip and animate the bar out |
| 432 | mBarView.startLaunchTaskAnimation(mDisableThumbnailClip, r); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 433 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 434 | // Animate the dim |
| 435 | if (mDim > 0) { |
| 436 | ObjectAnimator anim = ObjectAnimator.ofInt(this, "dim", 0); |
| 437 | anim.setDuration(mConfig.taskBarExitAnimDuration); |
| 438 | anim.setInterpolator(mConfig.fastOutLinearInInterpolator); |
| 439 | anim.start(); |
| 440 | } |
| 441 | } else { |
| 442 | // Hide the dismiss button |
| 443 | mBarView.startLaunchTaskDismissAnimation(); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 444 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 447 | /** Animates the deletion of this task view */ |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 448 | public void startDeleteTaskAnimation(final Runnable r) { |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 449 | // Disabling clipping with the stack while the view is animating away |
| 450 | setClipViewInStack(false); |
| 451 | |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 452 | animate().translationX(mConfig.taskViewRemoveAnimTranslationXPx) |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 453 | .alpha(0f) |
| 454 | .setStartDelay(0) |
Winson Chung | b5ddfc3 | 2014-06-13 17:23:12 -0700 | [diff] [blame] | 455 | .setUpdateListener(null) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 456 | .setInterpolator(mConfig.fastOutSlowInInterpolator) |
| 457 | .setDuration(mConfig.taskViewRemoveAnimDuration) |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 458 | .withLayer() |
| 459 | .withEndAction(new Runnable() { |
| 460 | @Override |
| 461 | public void run() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 462 | // We just throw this into a runnable because starting a view property |
| 463 | // animation using layers can cause inconsisten results if we try and |
| 464 | // update the layers while the animation is running. In some cases, |
| 465 | // the runnabled passed in may start an animation which also uses layers |
| 466 | // so we defer all this by posting this. |
| 467 | r.run(); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 468 | |
| 469 | // Re-enable clipping with the stack (we will reuse this view) |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 470 | setClipViewInStack(true); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 471 | } |
| 472 | }) |
| 473 | .start(); |
| 474 | } |
| 475 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 476 | /** Animates this task view if the user does not interact with the stack after a certain time. */ |
| 477 | public void startNoUserInteractionAnimation() { |
| 478 | mBarView.startNoUserInteractionAnimation(); |
| 479 | } |
| 480 | |
| 481 | /** Mark this task view that the user does has not interacted with the stack after a certain time. */ |
| 482 | public void setNoUserInteractionState() { |
| 483 | mBarView.setNoUserInteractionState(); |
| 484 | } |
| 485 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 486 | /** 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] | 487 | Rect getClippingRect(Rect outRect) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 488 | getHitRect(outRect); |
| 489 | // XXX: We should get the hit rect of the thumbnail view and intersect, but this is faster |
| 490 | outRect.right = outRect.left + mThumbnailView.getRight(); |
| 491 | outRect.bottom = outRect.top + mThumbnailView.getBottom(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 492 | return outRect; |
| 493 | } |
| 494 | |
| 495 | /** Enable the hw layers on this task view */ |
| 496 | void enableHwLayers() { |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 497 | mThumbnailView.setLayerType(View.LAYER_TYPE_HARDWARE, mLayerPaint); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 498 | mBarView.enableHwLayers(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 499 | mLockToAppButtonView.setLayerType(View.LAYER_TYPE_HARDWARE, mLayerPaint); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** Disable the hw layers on this task view */ |
| 503 | void disableHwLayers() { |
Winson Chung | c9567c0 | 2014-06-16 20:25:51 -0700 | [diff] [blame] | 504 | mThumbnailView.setLayerType(View.LAYER_TYPE_NONE, mLayerPaint); |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 505 | mBarView.disableHwLayers(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 506 | mLockToAppButtonView.setLayerType(View.LAYER_TYPE_NONE, mLayerPaint); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 509 | /** Sets the stubbed state of this task view. */ |
| 510 | void setStubState(boolean isStub) { |
| 511 | if (!mIsStub && isStub) { |
| 512 | // This is now a stub task view, so clip to the bar height, hide the thumbnail |
| 513 | setClipBounds(new Rect(0, 0, getMeasuredWidth(), mBarView.getMeasuredHeight())); |
| 514 | mThumbnailView.setVisibility(View.INVISIBLE); |
| 515 | // Temporary |
| 516 | mBarView.mActivityDescription.setText("Stub"); |
| 517 | } else if (mIsStub && !isStub) { |
| 518 | setClipBounds(null); |
| 519 | mThumbnailView.setVisibility(View.VISIBLE); |
| 520 | } |
| 521 | mIsStub = isStub; |
| 522 | } |
| 523 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 524 | /** |
| 525 | * Returns whether this view should be clipped, or any views below should clip against this |
| 526 | * view. |
| 527 | */ |
| 528 | boolean shouldClipViewInStack() { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 529 | return mClipViewInStack && (getVisibility() == View.VISIBLE); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** Sets whether this view should be clipped, or clipped against. */ |
| 533 | void setClipViewInStack(boolean clip) { |
| 534 | if (clip != mClipViewInStack) { |
| 535 | mClipViewInStack = clip; |
| 536 | if (getParent() instanceof View) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 537 | getHitRect(mTmpRect); |
| 538 | ((View) getParent()).invalidate(mTmpRect); |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 543 | /** Sets the footer height. */ |
| 544 | public void setFooterHeight(int height) { |
| 545 | mFooterHeight = height; |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame^] | 546 | invalidateOutline(); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 547 | invalidate(0, getMeasuredHeight() - mMaxFooterHeight, getMeasuredWidth(), |
| 548 | getMeasuredHeight()); |
| 549 | } |
| 550 | |
| 551 | /** Gets the footer height. */ |
| 552 | public int getFooterHeight() { |
| 553 | return mFooterHeight; |
| 554 | } |
| 555 | |
| 556 | /** Animates the footer into and out of view. */ |
| 557 | public void animateFooterVisibility(boolean visible, int duration, int delay) { |
| 558 | if (!mTask.canLockToTask) return; |
| 559 | if (mMaxFooterHeight <= 0) return; |
| 560 | |
| 561 | if (mFooterAnimator != null) { |
| 562 | mFooterAnimator.removeAllListeners(); |
| 563 | mFooterAnimator.cancel(); |
| 564 | } |
| 565 | int height = visible ? mMaxFooterHeight : 0; |
| 566 | if (visible && mLockToAppButtonView.getVisibility() != View.VISIBLE) { |
| 567 | if (duration > 0) { |
| 568 | setFooterHeight(0); |
| 569 | } else { |
| 570 | setFooterHeight(mMaxFooterHeight); |
| 571 | } |
| 572 | mLockToAppButtonView.setVisibility(View.VISIBLE); |
| 573 | } |
| 574 | if (duration > 0) { |
| 575 | mFooterAnimator = ObjectAnimator.ofInt(this, "footerHeight", height); |
| 576 | mFooterAnimator.setDuration(duration); |
| 577 | mFooterAnimator.setInterpolator(mConfig.fastOutSlowInInterpolator); |
| 578 | if (!visible) { |
| 579 | mFooterAnimator.addListener(new AnimatorListenerAdapter() { |
| 580 | @Override |
| 581 | public void onAnimationEnd(Animator animation) { |
| 582 | mLockToAppButtonView.setVisibility(View.INVISIBLE); |
| 583 | } |
| 584 | }); |
| 585 | } |
| 586 | mFooterAnimator.start(); |
| 587 | } else { |
| 588 | if (!visible) { |
| 589 | mLockToAppButtonView.setVisibility(View.INVISIBLE); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 594 | /** Returns the current dim. */ |
| 595 | public void setDim(int dim) { |
| 596 | mDim = dim; |
| 597 | postInvalidateOnAnimation(); |
| 598 | } |
| 599 | |
| 600 | /** Returns the current dim. */ |
| 601 | public int getDim() { |
| 602 | return mDim; |
| 603 | } |
| 604 | |
| 605 | /** Compute the dim as a function of the scale of this view. */ |
| 606 | int getDimOverlayFromScale() { |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 607 | float minScale = TaskStackViewLayoutAlgorithm.StackPeekMinScale; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 608 | float scaleRange = 1f - minScale; |
| 609 | float dim = (1f - getScaleX()) / scaleRange; |
| 610 | dim = mDimInterpolator.getInterpolation(Math.min(dim, 1f)); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 611 | return Math.max(0, Math.min(mMaxDim, (int) (dim * 255))); |
| 612 | } |
| 613 | |
| 614 | /** Update the dim as a function of the scale of this view. */ |
| 615 | void updateDimOverlayFromScale() { |
| 616 | setDim(getDimOverlayFromScale()); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public void draw(Canvas canvas) { |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 621 | super.draw(canvas); |
| 622 | |
| 623 | // Apply the dim if necessary |
| 624 | if (mDim > 0) { |
| 625 | canvas.drawColor(mDim << 24); |
| 626 | } |
| 627 | } |
| 628 | |
Winson Chung | bdbb87d | 2014-07-09 14:29:13 -0700 | [diff] [blame] | 629 | @Override |
| 630 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
| 631 | if (mIsStub && (child == mThumbnailView)) { |
| 632 | // Skip the thumbnail view if we are in stub mode |
| 633 | return false; |
| 634 | } |
| 635 | return super.drawChild(canvas, child, drawingTime); |
| 636 | } |
| 637 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 638 | /** |
| 639 | * Sets the focused task explicitly. We need a separate flag because requestFocus() won't happen |
| 640 | * if the view is not currently visible, or we are in touch state (where we still want to keep |
| 641 | * track of focus). |
| 642 | */ |
| 643 | public void setFocusedTask() { |
| 644 | mIsFocused = true; |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 645 | // Workaround, we don't always want it focusable in touch mode, but we want the first task |
| 646 | // to be focused after the enter-recents animation, which can be triggered from either touch |
| 647 | // or keyboard |
| 648 | setFocusableInTouchMode(true); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 649 | requestFocus(); |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 650 | setFocusableInTouchMode(false); |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 651 | invalidate(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Updates the explicitly focused state when the view focus changes. |
| 656 | */ |
| 657 | @Override |
| 658 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
| 659 | super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); |
| 660 | if (!gainFocus) { |
| 661 | mIsFocused = false; |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 662 | invalidate(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Returns whether we have explicitly been focused. |
| 668 | */ |
| 669 | public boolean isFocusedTask() { |
| 670 | return mIsFocused || isFocused(); |
| 671 | } |
| 672 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 673 | /**** TaskCallbacks Implementation ****/ |
| 674 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 675 | /** Binds this task view to the task */ |
| 676 | public void onTaskBound(Task t) { |
| 677 | mTask = t; |
| 678 | mTask.setCallbacks(this); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 679 | if (getMeasuredWidth() == 0) { |
| 680 | animateFooterVisibility(t.canLockToTask, 0, 0); |
| 681 | } else { |
| 682 | animateFooterVisibility(t.canLockToTask, mConfig.taskViewLockToAppLongAnimDuration, 0); |
| 683 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 687 | public void onTaskDataLoaded() { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 688 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 689 | // Bind each of the views to the new task data |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 690 | mThumbnailView.rebindToTask(mTask); |
| 691 | mBarView.rebindToTask(mTask); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 692 | // Rebind any listeners |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 693 | if (Constants.DebugFlags.App.EnableTaskFiltering) { |
| 694 | mBarView.mApplicationIcon.setOnClickListener(this); |
| 695 | } |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 696 | mBarView.mDismissButton.setOnClickListener(this); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 697 | mLockToAppButtonView.setOnClickListener(this); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 698 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 699 | if (mConfig.developerOptionsEnabled) { |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 700 | mBarView.mApplicationIcon.setOnLongClickListener(this); |
| 701 | } |
| 702 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 703 | } |
| 704 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 708 | public void onTaskDataUnloaded() { |
Winson Chung | 863db8a | 2014-05-20 14:27:39 -0700 | [diff] [blame] | 709 | if (mThumbnailView != null && mBarView != null) { |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 710 | // Unbind each of the views from the task data and remove the task callback |
| 711 | mTask.setCallbacks(null); |
| 712 | mThumbnailView.unbindFromTask(); |
| 713 | mBarView.unbindFromTask(); |
Winson Chung | 9f9679d | 2014-04-11 16:49:09 -0700 | [diff] [blame] | 714 | // Unbind any listeners |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 715 | if (Constants.DebugFlags.App.EnableTaskFiltering) { |
| 716 | mBarView.mApplicationIcon.setOnClickListener(null); |
| 717 | } |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 718 | mBarView.mDismissButton.setOnClickListener(null); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 719 | mLockToAppButtonView.setOnClickListener(null); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 720 | if (Constants.DebugFlags.App.EnableDevAppInfoOnLongPress) { |
| 721 | mBarView.mApplicationIcon.setOnLongClickListener(null); |
| 722 | } |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 723 | } |
| 724 | mTaskDataLoaded = false; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 727 | /** Enables/disables handling touch on this task view. */ |
| 728 | void setTouchEnabled(boolean enabled) { |
| 729 | setOnClickListener(enabled ? this : null); |
| 730 | } |
| 731 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 732 | @Override |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 733 | public void onClick(final View v) { |
| 734 | // We purposely post the handler delayed to allow for the touch feedback to draw |
| 735 | final TaskView tv = this; |
| 736 | postDelayed(new Runnable() { |
| 737 | @Override |
| 738 | public void run() { |
| 739 | if (v == mBarView.mApplicationIcon) { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 740 | mCb.onTaskViewAppIconClicked(tv); |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 741 | } else if (v == mBarView.mDismissButton) { |
| 742 | // Animate out the view and call the callback |
| 743 | startDeleteTaskAnimation(new Runnable() { |
| 744 | @Override |
| 745 | public void run() { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 746 | mCb.onTaskViewDismissed(tv); |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 747 | } |
| 748 | }); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 749 | // Hide the footer |
| 750 | tv.animateFooterVisibility(false, mConfig.taskViewRemoveAnimDuration, 0); |
| 751 | } else if (v == tv || v == mLockToAppButtonView) { |
| 752 | mCb.onTaskViewClicked(tv, tv.getTask(), (v == mLockToAppButtonView)); |
Winson Chung | 54e297a | 2014-05-09 17:15:32 -0700 | [diff] [blame] | 753 | } |
Winson Chung | 7ab650c | 2014-06-18 14:25:34 -0700 | [diff] [blame] | 754 | } |
| 755 | }, 125); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 756 | } |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 757 | |
| 758 | @Override |
| 759 | public boolean onLongClick(View v) { |
| 760 | if (v == mBarView.mApplicationIcon) { |
Winson Chung | 7aceb9a | 2014-07-03 13:38:01 -0700 | [diff] [blame] | 761 | mCb.onTaskViewAppInfoClicked(this); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 762 | return true; |
| 763 | } |
| 764 | return false; |
| 765 | } |
Winson Chung | 7bb1885 | 2014-05-20 23:25:41 +0000 | [diff] [blame] | 766 | } |