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 | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 20 | |
Winson Chung | c6011de | 2014-06-30 18:04:55 -0700 | [diff] [blame] | 21 | import android.animation.Animator; |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 23 | import android.animation.ObjectAnimator; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 27 | import android.content.res.Resources; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 28 | import android.graphics.Outline; |
| 29 | import android.graphics.Paint; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 30 | import android.graphics.Point; |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 31 | import android.graphics.PorterDuff; |
| 32 | import android.graphics.PorterDuffColorFilter; |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 33 | import android.graphics.Rect; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 34 | import android.util.AttributeSet; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 35 | import android.util.FloatProperty; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 36 | import android.util.Property; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 37 | import android.view.MotionEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 38 | import android.view.View; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 39 | import android.view.ViewDebug; |
Winson Chung | f95c7f5 | 2014-08-18 17:09:45 -0700 | [diff] [blame] | 40 | import android.view.ViewOutlineProvider; |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 41 | import android.widget.Toast; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 42 | |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 43 | import com.android.internal.logging.MetricsLogger; |
| 44 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 45 | import com.android.systemui.Interpolators; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 46 | import com.android.systemui.R; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 47 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 48 | import com.android.systemui.recents.RecentsActivity; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 49 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 50 | import com.android.systemui.recents.events.EventBus; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 51 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 52 | import com.android.systemui.recents.events.ui.DismissTaskViewEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 53 | import com.android.systemui.recents.events.ui.TaskViewDismissedEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 54 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 55 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 56 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.model.Task; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 60 | import com.android.systemui.recents.model.TaskStack; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 61 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 62 | import java.util.ArrayList; |
| 63 | |
Winson | 3c10716 | 2016-01-22 15:53:00 -0800 | [diff] [blame] | 64 | /** |
| 65 | * A {@link TaskView} represents a fixed view of a task. Because the TaskView's layout is directed |
| 66 | * solely by the {@link TaskStackView}, we make it a fixed size layout which allows relayouts down |
| 67 | * the view hierarchy, but not upwards from any of its children (the TaskView will relayout itself |
| 68 | * with the previous bounds if any child requests layout). |
| 69 | */ |
| 70 | public class TaskView extends FixedSizeFrameLayout implements Task.TaskCallbacks, |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 71 | TaskStackAnimationHelper.Callbacks, View.OnClickListener, View.OnLongClickListener { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 72 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 73 | /** The TaskView callbacks */ |
| 74 | interface TaskViewCallbacks { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 75 | void onTaskViewClipStateChanged(TaskView tv); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 78 | /** |
| 79 | * The dim overlay is generally calculated from the task progress, but occasionally (like when |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 80 | * launching) needs to be animated independently of the task progress. This call is only used |
| 81 | * when animating the task into Recents, when the header dim is already applied |
| 82 | */ |
| 83 | public static final Property<TaskView, Float> DIM_ALPHA_WITHOUT_HEADER = |
| 84 | new FloatProperty<TaskView>("dimAlphaWithoutHeader") { |
| 85 | @Override |
| 86 | public void setValue(TaskView tv, float dimAlpha) { |
| 87 | tv.setDimAlphaWithoutHeader(dimAlpha); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Float get(TaskView tv) { |
| 92 | return tv.getDimAlpha(); |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | /** |
| 97 | * The dim overlay is generally calculated from the task progress, but occasionally (like when |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 98 | * launching) needs to be animated independently of the task progress. |
| 99 | */ |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 100 | public static final Property<TaskView, Float> DIM_ALPHA = |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 101 | new FloatProperty<TaskView>("dimAlpha") { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 102 | @Override |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 103 | public void setValue(TaskView tv, float dimAlpha) { |
| 104 | tv.setDimAlpha(dimAlpha); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public Float get(TaskView tv) { |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 109 | return tv.getDimAlpha(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 110 | } |
| 111 | }; |
| 112 | |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 113 | /** |
| 114 | * The dim overlay is generally calculated from the task progress, but occasionally (like when |
| 115 | * launching) needs to be animated independently of the task progress. |
| 116 | */ |
| 117 | public static final Property<TaskView, Float> VIEW_OUTLINE_ALPHA = |
| 118 | new FloatProperty<TaskView>("viewOutlineAlpha") { |
| 119 | @Override |
| 120 | public void setValue(TaskView tv, float alpha) { |
| 121 | tv.getViewBounds().setAlpha(alpha); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public Float get(TaskView tv) { |
| 126 | return tv.getViewBounds().getAlpha(); |
| 127 | } |
| 128 | }; |
| 129 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 130 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 131 | float mDimAlpha; |
Winson Chung | 86677c9 | 2014-11-14 11:30:39 -0800 | [diff] [blame] | 132 | float mActionButtonTranslationZ; |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 133 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 134 | @ViewDebug.ExportedProperty(deepExport=true, prefix="task_") |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 135 | Task mTask; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 136 | @ViewDebug.ExportedProperty(category="recents") |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 137 | boolean mTaskDataLoaded; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 138 | @ViewDebug.ExportedProperty(category="recents") |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 139 | boolean mClipViewInStack = true; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 140 | @ViewDebug.ExportedProperty(category="recents") |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 141 | boolean mTouchExplorationEnabled; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 142 | @ViewDebug.ExportedProperty(category="recents") |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 143 | boolean mIsDisabledInSafeMode; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 144 | @ViewDebug.ExportedProperty(deepExport=true, prefix="view_bounds_") |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 145 | AnimateableViewBounds mViewBounds; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 146 | |
| 147 | private AnimatorSet mTransformAnimation; |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 148 | private final TaskViewTransform mTargetAnimationTransform = new TaskViewTransform(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 149 | private ArrayList<Animator> mTmpAnimators = new ArrayList<>(); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 150 | |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 151 | View mContent; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 152 | @ViewDebug.ExportedProperty(deepExport=true, prefix="thumbnail_") |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 153 | TaskViewThumbnail mThumbnailView; |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 154 | @ViewDebug.ExportedProperty(deepExport=true, prefix="header_") |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 155 | TaskViewHeader mHeaderView; |
Winson Chung | 2915b9d | 2014-07-28 11:01:57 -0700 | [diff] [blame] | 156 | View mActionButtonView; |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 157 | TaskViewCallbacks mCb; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 158 | |
Winson | 231bc9c | 2016-02-09 12:31:00 -0800 | [diff] [blame] | 159 | @ViewDebug.ExportedProperty(category="recents") |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 160 | Point mDownTouchPos = new Point(); |
| 161 | |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 162 | private Toast mDisabledAppToast; |
| 163 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 164 | public TaskView(Context context) { |
| 165 | this(context, null); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 168 | public TaskView(Context context, AttributeSet attrs) { |
| 169 | this(context, attrs, 0); |
| 170 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 171 | |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 172 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 173 | this(context, attrs, defStyleAttr, 0); |
| 174 | } |
| 175 | |
| 176 | public TaskView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 177 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 178 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 179 | Resources res = context.getResources(); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 180 | mViewBounds = new AnimateableViewBounds(this, res.getDimensionPixelSize( |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 181 | R.dimen.recents_task_view_shadow_rounded_corners_radius)); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 182 | if (config.fakeShadows) { |
| 183 | setBackground(new FakeShadowDrawable(res, config)); |
Jorim Jaggi | cb55703 | 2014-09-16 23:09:24 +0200 | [diff] [blame] | 184 | } |
| 185 | setOutlineProvider(mViewBounds); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 186 | setOnLongClickListener(this); |
Winson Chung | 1492646 | 2014-04-14 18:57:14 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 189 | /** Set callback */ |
| 190 | void setCallbacks(TaskViewCallbacks cb) { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 191 | mCb = cb; |
| 192 | } |
| 193 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 194 | /** Resets this TaskView for reuse. */ |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 195 | void onResume(boolean isResumingFromVisible) { |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 196 | resetNoUserInteractionState(); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 197 | readSystemFlags(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 198 | if (!isResumingFromVisible) { |
| 199 | resetViewProperties(); |
| 200 | setClipViewInStack(false); |
| 201 | } |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 202 | setCallbacks(null); |
| 203 | } |
| 204 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 205 | /** Gets the task */ |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 206 | public Task getTask() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 207 | return mTask; |
| 208 | } |
| 209 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 210 | /** Returns the view bounds. */ |
| 211 | AnimateableViewBounds getViewBounds() { |
| 212 | return mViewBounds; |
| 213 | } |
| 214 | |
| 215 | @Override |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 216 | protected void onAttachedToWindow() { |
| 217 | super.onAttachedToWindow(); |
| 218 | readSystemFlags(); |
| 219 | } |
| 220 | |
| 221 | @Override |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 222 | protected void onFinishInflate() { |
| 223 | // Bind the views |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 224 | mContent = findViewById(R.id.task_view_content); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 225 | mHeaderView = (TaskViewHeader) findViewById(R.id.task_view_bar); |
Winson Chung | ec396d6 | 2014-08-06 17:08:00 -0700 | [diff] [blame] | 226 | mThumbnailView = (TaskViewThumbnail) findViewById(R.id.task_view_thumbnail); |
Winson Chung | 2915b9d | 2014-07-28 11:01:57 -0700 | [diff] [blame] | 227 | mActionButtonView = findViewById(R.id.lock_to_app_fab); |
Winson Chung | f95c7f5 | 2014-08-18 17:09:45 -0700 | [diff] [blame] | 228 | mActionButtonView.setOutlineProvider(new ViewOutlineProvider() { |
| 229 | @Override |
| 230 | public void getOutline(View view, Outline outline) { |
| 231 | // Set the outline to match the FAB background |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 232 | outline.setOval(0, 0, mActionButtonView.getWidth(), mActionButtonView.getHeight()); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 233 | outline.setAlpha(0.35f); |
Winson Chung | f95c7f5 | 2014-08-18 17:09:45 -0700 | [diff] [blame] | 234 | } |
| 235 | }); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 236 | mActionButtonView.setOnClickListener(this); |
Winson Chung | 86677c9 | 2014-11-14 11:30:39 -0800 | [diff] [blame] | 237 | mActionButtonTranslationZ = mActionButtonView.getTranslationZ(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 241 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 242 | super.onSizeChanged(w, h, oldw, oldh); |
Winson | 94a0e89 | 2016-01-08 16:06:50 -0800 | [diff] [blame] | 243 | if (w > 0 && h > 0) { |
| 244 | mHeaderView.onTaskViewSizeChanged(w, h); |
| 245 | mThumbnailView.onTaskViewSizeChanged(w, h); |
| 246 | } |
Winson | de0591a | 2015-12-04 17:24:35 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
Winson | ad66efa | 2016-01-08 16:40:30 -0800 | [diff] [blame] | 250 | public boolean hasOverlappingRendering() { |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | @Override |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 255 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 256 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 257 | mDownTouchPos.set((int) (ev.getX() * getScaleX()), (int) (ev.getY() * getScaleY())); |
| 258 | } |
| 259 | return super.onInterceptTouchEvent(ev); |
| 260 | } |
| 261 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 262 | |
Winson | 3c10716 | 2016-01-22 15:53:00 -0800 | [diff] [blame] | 263 | @Override |
| 264 | protected void measureContents(int width, int height) { |
Jorim Jaggi | cb55703 | 2014-09-16 23:09:24 +0200 | [diff] [blame] | 265 | int widthWithoutPadding = width - mPaddingLeft - mPaddingRight; |
| 266 | int heightWithoutPadding = height - mPaddingTop - mPaddingBottom; |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 267 | |
| 268 | // Measure the content |
| 269 | mContent.measure(MeasureSpec.makeMeasureSpec(widthWithoutPadding, MeasureSpec.EXACTLY), |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 270 | MeasureSpec.makeMeasureSpec(heightWithoutPadding, MeasureSpec.EXACTLY)); |
Winson Chung | bf5dbf1 | 2014-09-16 00:58:25 +0200 | [diff] [blame] | 271 | |
Winson | 3c10716 | 2016-01-22 15:53:00 -0800 | [diff] [blame] | 272 | // Optimization: Prevent overdraw of the thumbnail under the header view |
Winson | d477d53 | 2015-10-13 15:13:40 -0700 | [diff] [blame] | 273 | mThumbnailView.updateClipToTaskBar(mHeaderView); |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 274 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 275 | setMeasuredDimension(width, height); |
| 276 | } |
| 277 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 278 | void updateViewPropertiesToTaskTransform(TaskViewTransform toTransform, |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 279 | AnimationProps toAnimation, ValueAnimator.AnimatorUpdateListener updateCallback) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 280 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 281 | cancelTransformAnimation(); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 282 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 283 | // Compose the animations for the transform |
| 284 | mTmpAnimators.clear(); |
Winson | ad66efa | 2016-01-08 16:40:30 -0800 | [diff] [blame] | 285 | toTransform.applyToTaskView(this, mTmpAnimators, toAnimation, !config.fakeShadows); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 286 | if (toAnimation.isImmediate()) { |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 287 | if (Float.compare(getDimAlpha(), toTransform.dimAlpha) != 0) { |
| 288 | setDimAlpha(toTransform.dimAlpha); |
Winson | 5500390 | 2016-01-12 12:00:37 -0800 | [diff] [blame] | 289 | } |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 290 | if (Float.compare(mViewBounds.getAlpha(), toTransform.viewOutlineAlpha) != 0) { |
| 291 | mViewBounds.setAlpha(toTransform.viewOutlineAlpha); |
| 292 | } |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 293 | // Manually call back to the animator listener and update callback |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 294 | if (toAnimation.getListener() != null) { |
| 295 | toAnimation.getListener().onAnimationEnd(null); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 296 | } |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 297 | if (updateCallback != null) { |
| 298 | updateCallback.onAnimationUpdate(null); |
| 299 | } |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 300 | } else { |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 301 | // Both the progress and the update are a function of the bounds movement of the task |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 302 | if (Float.compare(getDimAlpha(), toTransform.dimAlpha) != 0) { |
| 303 | ObjectAnimator anim = ObjectAnimator.ofFloat(this, DIM_ALPHA, getDimAlpha(), |
| 304 | toTransform.dimAlpha); |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 305 | mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, anim)); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 306 | } |
Winson | 1499150 | 2016-02-15 15:40:08 -0800 | [diff] [blame] | 307 | if (Float.compare(mViewBounds.getAlpha(), toTransform.viewOutlineAlpha) != 0) { |
| 308 | ObjectAnimator anim = ObjectAnimator.ofFloat(this, VIEW_OUTLINE_ALPHA, |
| 309 | mViewBounds.getAlpha(), toTransform.viewOutlineAlpha); |
| 310 | mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, anim)); |
| 311 | } |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 312 | if (updateCallback != null) { |
| 313 | ValueAnimator updateCallbackAnim = ValueAnimator.ofInt(0, 1); |
| 314 | updateCallbackAnim.addUpdateListener(updateCallback); |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 315 | mTmpAnimators.add(toAnimation.apply(AnimationProps.BOUNDS, updateCallbackAnim)); |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 316 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 317 | |
| 318 | // Create the animator |
| 319 | mTransformAnimation = toAnimation.createAnimator(mTmpAnimators); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 320 | mTransformAnimation.start(); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 321 | mTargetAnimationTransform.copyFrom(toTransform); |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 322 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** Resets this view's properties */ |
| 326 | void resetViewProperties() { |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 327 | cancelTransformAnimation(); |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 328 | setDimAlpha(0); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 329 | setVisibility(View.VISIBLE); |
| 330 | getViewBounds().reset(); |
Winson | 4c84a8c | 2016-01-21 18:14:12 -0800 | [diff] [blame] | 331 | getHeaderView().reset(); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 332 | TaskViewTransform.reset(this); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 333 | |
| 334 | mActionButtonView.setScaleX(1f); |
| 335 | mActionButtonView.setScaleY(1f); |
Winson | 6ea2588 | 2016-01-13 10:59:04 -0800 | [diff] [blame] | 336 | mActionButtonView.setAlpha(0f); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 337 | mActionButtonView.setTranslationZ(mActionButtonTranslationZ); |
Winson Chung | c6a1623 | 2014-04-01 14:04:48 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 340 | /** |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 341 | * @return whether we are animating towards {@param transform} |
| 342 | */ |
| 343 | boolean isAnimatingTo(TaskViewTransform transform) { |
| 344 | return mTransformAnimation != null && mTransformAnimation.isStarted() |
| 345 | && mTargetAnimationTransform.isSame(transform); |
| 346 | } |
| 347 | |
| 348 | /** |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 349 | * Cancels any current transform animations. |
| 350 | */ |
| 351 | public void cancelTransformAnimation() { |
Winson | ad66efa | 2016-01-08 16:40:30 -0800 | [diff] [blame] | 352 | Utilities.cancelAnimationWithoutCallbacks(mTransformAnimation); |
Winson Chung | 9f49df9 | 2014-05-07 18:08:34 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 355 | /** Enables/disables handling touch on this task view. */ |
| 356 | void setTouchEnabled(boolean enabled) { |
| 357 | setOnClickListener(enabled ? this : null); |
| 358 | } |
| 359 | |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 360 | /** Animates this task view if the user does not interact with the stack after a certain time. */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 361 | void startNoUserInteractionAnimation() { |
| 362 | mHeaderView.startNoUserInteractionAnimation(); |
Winson Chung | 969f586 | 2014-06-16 17:08:24 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /** Mark this task view that the user does has not interacted with the stack after a certain time. */ |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 366 | void setNoUserInteractionState() { |
| 367 | mHeaderView.setNoUserInteractionState(); |
| 368 | } |
| 369 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 370 | /** Resets the state tracking that the user has not interacted with the stack after a certain time. */ |
| 371 | void resetNoUserInteractionState() { |
| 372 | mHeaderView.resetNoUserInteractionState(); |
| 373 | } |
| 374 | |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 375 | /** Dismisses this task. */ |
| 376 | void dismissTask() { |
| 377 | // Animate out the view and call the callback |
| 378 | final TaskView tv = this; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 379 | DismissTaskViewEvent dismissEvent = new DismissTaskViewEvent(tv, mTask); |
| 380 | dismissEvent.addPostAnimationCallback(new Runnable() { |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 381 | @Override |
| 382 | public void run() { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 383 | EventBus.getDefault().send(new TaskViewDismissedEvent(mTask, tv)); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 384 | } |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 385 | }); |
| 386 | EventBus.getDefault().send(dismissEvent); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 389 | /** |
| 390 | * Returns whether this view should be clipped, or any views below should clip against this |
| 391 | * view. |
| 392 | */ |
| 393 | boolean shouldClipViewInStack() { |
Winson | 36a5a2c | 2015-10-29 18:04:39 -0700 | [diff] [blame] | 394 | // Never clip for freeform tasks or if invisible |
| 395 | if (mTask.isFreeformTask() || getVisibility() != View.VISIBLE) { |
| 396 | return false; |
| 397 | } |
| 398 | return mClipViewInStack; |
Winson Chung | 5a9b0b0 | 2014-05-20 17:32:03 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /** Sets whether this view should be clipped, or clipped against. */ |
| 402 | void setClipViewInStack(boolean clip) { |
| 403 | if (clip != mClipViewInStack) { |
| 404 | mClipViewInStack = clip; |
Winson Chung | fe03b40 | 2014-11-17 11:47:09 -0800 | [diff] [blame] | 405 | if (mCb != null) { |
| 406 | mCb.onTaskViewClipStateChanged(this); |
| 407 | } |
Winson Chung | 93748a1 | 2014-07-13 17:43:31 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 411 | public TaskViewHeader getHeaderView() { |
| 412 | return mHeaderView; |
| 413 | } |
| 414 | |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 415 | /** |
| 416 | * Sets the current dim. |
| 417 | */ |
| 418 | public void setDimAlpha(float dimAlpha) { |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 419 | mDimAlpha = dimAlpha; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 420 | mThumbnailView.setDimAlpha(dimAlpha); |
| 421 | mHeaderView.setDimAlpha(dimAlpha); |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Sets the current dim without updating the header's dim. |
| 426 | */ |
| 427 | public void setDimAlphaWithoutHeader(float dimAlpha) { |
| 428 | mDimAlpha = dimAlpha; |
| 429 | mThumbnailView.setDimAlpha(dimAlpha); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 432 | /** |
| 433 | * Returns the current dim. |
| 434 | */ |
| 435 | public float getDimAlpha() { |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 436 | return mDimAlpha; |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 439 | /** |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 440 | * Explicitly sets the focused state of this task. |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 441 | */ |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 442 | public void setFocusedState(boolean isFocused, boolean requestViewFocus) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 443 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 444 | if (isFocused) { |
| 445 | if (requestViewFocus && !isFocused()) { |
| 446 | requestFocus(); |
| 447 | } |
| 448 | if (requestViewFocus && !isAccessibilityFocused() && ssp.isTouchExplorationEnabled()) { |
| 449 | requestAccessibilityFocus(); |
| 450 | } |
| 451 | } else { |
| 452 | if (isAccessibilityFocused() && ssp.isTouchExplorationEnabled()) { |
| 453 | clearAccessibilityFocus(); |
| 454 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 458 | /** |
| 459 | * Shows the action button. |
| 460 | * @param fadeIn whether or not to animate the action button in. |
| 461 | * @param fadeInDuration the duration of the action button animation, only used if |
| 462 | * {@param fadeIn} is true. |
| 463 | */ |
| 464 | public void showActionButton(boolean fadeIn, int fadeInDuration) { |
| 465 | mActionButtonView.setVisibility(View.VISIBLE); |
| 466 | |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 467 | if (fadeIn && mActionButtonView.getAlpha() < 1f) { |
| 468 | mActionButtonView.animate() |
| 469 | .alpha(1f) |
| 470 | .scaleX(1f) |
| 471 | .scaleY(1f) |
| 472 | .setDuration(fadeInDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 473 | .setInterpolator(Interpolators.ALPHA_IN) |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 474 | .start(); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 475 | } else { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 476 | mActionButtonView.setScaleX(1f); |
| 477 | mActionButtonView.setScaleY(1f); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 478 | mActionButtonView.setAlpha(1f); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 479 | mActionButtonView.setTranslationZ(mActionButtonTranslationZ); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Immediately hides the action button. |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 485 | * |
| 486 | * @param fadeOut whether or not to animate the action button out. |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 487 | */ |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 488 | public void hideActionButton(boolean fadeOut, int fadeOutDuration, boolean scaleDown, |
| 489 | final Animator.AnimatorListener animListener) { |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 490 | if (fadeOut && mActionButtonView.getAlpha() > 0f) { |
| 491 | if (scaleDown) { |
| 492 | float toScale = 0.9f; |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 493 | mActionButtonView.animate() |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 494 | .scaleX(toScale) |
| 495 | .scaleY(toScale); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 496 | } |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 497 | mActionButtonView.animate() |
| 498 | .alpha(0f) |
| 499 | .setDuration(fadeOutDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 500 | .setInterpolator(Interpolators.ALPHA_OUT) |
Winson | 65c851e | 2016-01-20 12:43:35 -0800 | [diff] [blame] | 501 | .withEndAction(new Runnable() { |
| 502 | @Override |
| 503 | public void run() { |
| 504 | if (animListener != null) { |
| 505 | animListener.onAnimationEnd(null); |
| 506 | } |
| 507 | mActionButtonView.setVisibility(View.INVISIBLE); |
| 508 | } |
| 509 | }) |
| 510 | .start(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 511 | } else { |
| 512 | mActionButtonView.setAlpha(0f); |
| 513 | mActionButtonView.setVisibility(View.INVISIBLE); |
| 514 | if (animListener != null) { |
| 515 | animListener.onAnimationEnd(null); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /**** TaskStackAnimationHelper.Callbacks Implementation ****/ |
| 521 | |
| 522 | @Override |
| 523 | public void onPrepareLaunchTargetForEnterAnimation() { |
| 524 | // These values will be animated in when onStartLaunchTargetEnterAnimation() is called |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 525 | setDimAlphaWithoutHeader(0); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 526 | mActionButtonView.setAlpha(0f); |
| 527 | } |
| 528 | |
| 529 | @Override |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 530 | public void onStartLaunchTargetEnterAnimation(TaskViewTransform transform, int duration, |
| 531 | boolean screenPinningEnabled, ReferenceCountedTrigger postAnimationTrigger) { |
| 532 | // Dim the view after the app window transitions down into recents |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 533 | postAnimationTrigger.increment(); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 534 | AnimationProps animation = new AnimationProps(duration, Interpolators.ALPHA_OUT); |
| 535 | Animator anim = animation.apply(AnimationProps.DIM_ALPHA, ObjectAnimator.ofFloat(this, |
| 536 | DIM_ALPHA_WITHOUT_HEADER, getDimAlpha(), transform.dimAlpha)); |
| 537 | anim.addListener(postAnimationTrigger.decrementOnAnimationEnd()); |
| 538 | anim.start(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 539 | |
| 540 | if (screenPinningEnabled) { |
| 541 | showActionButton(true /* fadeIn */, duration /* fadeInDuration */); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | @Override |
| 546 | public void onStartLaunchTargetLaunchAnimation(int duration, boolean screenPinningRequested, |
| 547 | ReferenceCountedTrigger postAnimationTrigger) { |
Winson | 6808881 | 2016-02-12 16:06:04 -0800 | [diff] [blame] | 548 | // Un-dim the view before/while launching the target |
Winson | 1bcf3c4 | 2016-02-10 13:29:39 -0800 | [diff] [blame] | 549 | AnimationProps animation = new AnimationProps(duration, Interpolators.ALPHA_OUT); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 550 | Animator anim = animation.apply(AnimationProps.DIM_ALPHA, ObjectAnimator.ofFloat(this, |
| 551 | DIM_ALPHA, getDimAlpha(), 0)); |
| 552 | anim.start(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 553 | |
| 554 | postAnimationTrigger.increment(); |
| 555 | hideActionButton(true /* fadeOut */, duration, |
| 556 | !screenPinningRequested /* scaleDown */, |
| 557 | postAnimationTrigger.decrementOnAnimationEnd()); |
Winson Chung | 931c51f | 2015-12-17 17:08:55 -0500 | [diff] [blame] | 558 | } |
| 559 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 560 | @Override |
| 561 | public void onStartFrontTaskEnterAnimation(boolean screenPinningEnabled) { |
| 562 | if (screenPinningEnabled) { |
| 563 | showActionButton(false /* fadeIn */, 0 /* fadeInDuration */); |
| 564 | } |
| 565 | } |
| 566 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 567 | /**** TaskCallbacks Implementation ****/ |
| 568 | |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 569 | public void onTaskBound(Task t) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 570 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 571 | mTask = t; |
Winson Chung | b169ebd | 2015-12-14 13:57:36 -0500 | [diff] [blame] | 572 | mTask.addCallback(this); |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 573 | mIsDisabledInSafeMode = !mTask.isSystemApp && ssp.isInSafeMode(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | @Override |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 577 | public void onTaskDataLoaded(Task task, ActivityManager.TaskThumbnailInfo thumbnailInfo) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 578 | // Bind each of the views to the new task data |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 579 | mThumbnailView.rebindToTask(mTask, thumbnailInfo, mIsDisabledInSafeMode); |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 580 | mHeaderView.rebindToTask(mTask, mTouchExplorationEnabled, mIsDisabledInSafeMode); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 581 | mTaskDataLoaded = true; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | @Override |
Winson Chung | 04dfe0d | 2014-03-14 14:06:29 -0700 | [diff] [blame] | 585 | public void onTaskDataUnloaded() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 586 | // Unbind each of the views from the task data and remove the task callback |
| 587 | mTask.removeCallback(this); |
| 588 | mThumbnailView.unbindFromTask(); |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 589 | mHeaderView.unbindFromTask(mTouchExplorationEnabled); |
Winson Chung | 37c8d8e | 2014-03-24 14:53:07 -0700 | [diff] [blame] | 590 | mTaskDataLoaded = false; |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 593 | @Override |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 594 | public void onTaskStackIdChanged() { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 595 | mHeaderView.rebindToTask(mTask, mTouchExplorationEnabled, mIsDisabledInSafeMode); |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 598 | /**** View.OnClickListener Implementation ****/ |
| 599 | |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 600 | @Override |
Winson Chung | 7ea62ba | 2014-07-22 16:30:37 -0700 | [diff] [blame] | 601 | public void onClick(final View v) { |
Winson | 8be1634 | 2016-02-09 11:53:27 -0800 | [diff] [blame] | 602 | if (mIsDisabledInSafeMode) { |
| 603 | Context context = getContext(); |
| 604 | String msg = context.getString(R.string.recents_launch_disabled_message, mTask.title); |
| 605 | if (mDisabledAppToast != null) { |
| 606 | mDisabledAppToast.cancel(); |
| 607 | } |
| 608 | mDisabledAppToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); |
| 609 | mDisabledAppToast.show(); |
| 610 | return; |
| 611 | } |
| 612 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 613 | boolean screenPinningRequested = false; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 614 | if (v == mActionButtonView) { |
| 615 | // Reset the translation of the action button before we animate it out |
| 616 | mActionButtonView.setTranslationZ(0f); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 617 | screenPinningRequested = true; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 618 | } |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 619 | EventBus.getDefault().send(new LaunchTaskEvent(this, mTask, null, INVALID_STACK_ID, |
| 620 | screenPinningRequested)); |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 621 | |
Chris Wren | 7c51684 | 2016-03-01 16:44:32 -0500 | [diff] [blame] | 622 | MetricsLogger.action(v.getContext(), MetricsEvent.ACTION_OVERVIEW_SELECT, |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 623 | mTask.key.getComponent().toString()); |
Winson Chung | 6cb485f | 2014-05-19 10:30:43 -0700 | [diff] [blame] | 624 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 625 | |
| 626 | /**** View.OnLongClickListener Implementation ****/ |
| 627 | |
| 628 | @Override |
| 629 | public boolean onLongClick(View v) { |
Winson | 37fc513 | 2015-11-30 14:53:12 -0800 | [diff] [blame] | 630 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 5b7dd53 | 2015-12-01 16:02:12 -0800 | [diff] [blame] | 631 | // Since we are clipping the view to the bounds, manually do the hit test |
| 632 | Rect clipBounds = new Rect(mViewBounds.mClipBounds); |
| 633 | clipBounds.scale(getScaleX()); |
| 634 | boolean inBounds = clipBounds.contains(mDownTouchPos.x, mDownTouchPos.y); |
| 635 | if (v == this && inBounds && !ssp.hasDockedTask()) { |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 636 | // Start listening for drag events |
| 637 | setClipViewInStack(false); |
| 638 | |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 639 | mDownTouchPos.x += ((1f - getScaleX()) * getWidth()) / 2; |
| 640 | mDownTouchPos.y += ((1f - getScaleY()) * getHeight()) / 2; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 641 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 642 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 643 | EventBus.getDefault().send(new DragStartEvent(mTask, this, mDownTouchPos)); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 644 | return true; |
| 645 | } |
| 646 | return false; |
| 647 | } |
| 648 | |
| 649 | /**** Events ****/ |
| 650 | |
| 651 | public final void onBusEvent(DragEndEvent event) { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 652 | if (!(event.dropTarget instanceof TaskStack.DockState)) { |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 653 | event.addPostAnimationCallback(new Runnable() { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 654 | @Override |
| 655 | public void run() { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 656 | // Animate the drag view back from where it is, to the view location, then after |
| 657 | // it returns, update the clip state |
| 658 | setClipViewInStack(true); |
| 659 | } |
| 660 | }); |
| 661 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 662 | EventBus.getDefault().unregister(this); |
| 663 | } |
Winson Chung | bbb3d3d | 2016-01-30 01:09:20 +0000 | [diff] [blame] | 664 | |
| 665 | /** |
| 666 | * Reads current system flags related to accessibility and screen pinning. |
| 667 | */ |
| 668 | private void readSystemFlags() { |
| 669 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 670 | mTouchExplorationEnabled = ssp.isTouchExplorationEnabled(); |
| 671 | } |
Winson Chung | 7bb1885 | 2014-05-20 23:25:41 +0000 | [diff] [blame] | 672 | } |