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