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