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 | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 23 | import android.graphics.Canvas; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 24 | import android.graphics.Color; |
| 25 | import android.graphics.Outline; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 27 | import android.graphics.drawable.ColorDrawable; |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 29 | import android.os.Handler; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 30 | import android.util.ArraySet; |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 31 | import android.util.AttributeSet; |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 33 | import android.view.MotionEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 34 | import android.view.View; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 35 | import android.view.ViewOutlineProvider; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 36 | import android.view.ViewPropertyAnimator; |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 37 | import android.view.WindowInsets; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 38 | import android.widget.FrameLayout; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 39 | import android.widget.TextView; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 40 | |
Winson | dc8de84 | 2016-01-06 15:21:41 -0800 | [diff] [blame] | 41 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 42 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 43 | import com.android.systemui.Interpolators; |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 44 | import com.android.systemui.R; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 45 | import com.android.systemui.recents.Recents; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 46 | import com.android.systemui.recents.RecentsActivity; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 47 | import com.android.systemui.recents.RecentsActivityLaunchState; |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 48 | import com.android.systemui.recents.RecentsAppWidgetHostView; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 49 | import com.android.systemui.recents.RecentsConfiguration; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 50 | import com.android.systemui.recents.RecentsDebugFlags; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 51 | import com.android.systemui.recents.events.EventBus; |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 52 | import com.android.systemui.recents.events.activity.ClearHistoryEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 53 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 54 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.HideHistoryButtonEvent; |
| 56 | import com.android.systemui.recents.events.activity.HideHistoryEvent; |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.LaunchTaskEvent; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.ShowHistoryButtonEvent; |
| 59 | import com.android.systemui.recents.events.activity.ShowHistoryEvent; |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 60 | import com.android.systemui.recents.events.activity.TaskStackUpdatedEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.ToggleHistoryEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 62 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent; |
| 64 | import com.android.systemui.recents.events.ui.DraggingInRecentsEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 65 | import com.android.systemui.recents.events.ui.ResetBackgroundScrimEvent; |
| 66 | import com.android.systemui.recents.events.ui.UpdateBackgroundScrimEvent; |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 67 | import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 68 | import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent; |
| 69 | import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 70 | import com.android.systemui.recents.history.RecentsHistoryView; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 71 | import com.android.systemui.recents.misc.ReferenceCountedTrigger; |
Winson Chung | 1f24c7e | 2014-07-11 17:06:48 -0700 | [diff] [blame] | 72 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 73 | import com.android.systemui.recents.misc.Utilities; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 74 | import com.android.systemui.recents.model.Task; |
| 75 | import com.android.systemui.recents.model.TaskStack; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 76 | import com.android.systemui.stackdivider.WindowManagerProxy; |
| 77 | import com.android.systemui.statusbar.FlingAnimationUtils; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 78 | |
| 79 | import java.util.ArrayList; |
Winson Chung | 6ac8bd6 | 2015-01-07 16:38:35 -0800 | [diff] [blame] | 80 | import java.util.List; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 81 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 82 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 83 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 84 | /** |
| 85 | * This view is the the top level layout that contains TaskStacks (which are laid out according |
| 86 | * to their SpaceNode bounds. |
| 87 | */ |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 88 | public class RecentsView extends FrameLayout { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 89 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 90 | private static final int DOCK_AREA_OVERLAY_TRANSITION_DURATION = 135; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 91 | private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200; |
| 92 | private static final float DEFAULT_SCRIM_ALPHA = 0.33f; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 93 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 94 | private final Handler mHandler; |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 95 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 96 | private TaskStack mStack; |
| 97 | private TaskStackView mTaskStackView; |
| 98 | private RecentsAppWidgetHostView mSearchBar; |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 99 | private TextView mHistoryButton; |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 100 | private TextView mHistoryClearAllButton; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 101 | private View mEmptyView; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 102 | private RecentsHistoryView mHistoryView; |
| 103 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 104 | private boolean mAwaitingFirstLayout = true; |
| 105 | private boolean mLastTaskLaunchedWasFreeform; |
| 106 | private Rect mSystemInsets = new Rect(); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 107 | private int mDividerSize; |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 108 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 109 | private ColorDrawable mBackgroundScrim = new ColorDrawable(Color.BLACK); |
| 110 | private Animator mBackgroundScrimAnimator; |
| 111 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 112 | private RecentsTransitionHelper mTransitionHelper; |
| 113 | private RecentsViewTouchHandler mTouchHandler; |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 114 | private final FlingAnimationUtils mFlingAnimationUtils; |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 115 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 116 | public RecentsView(Context context) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 117 | this(context, null); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public RecentsView(Context context, AttributeSet attrs) { |
| 121 | this(context, attrs, 0); |
| 122 | } |
| 123 | |
| 124 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 125 | this(context, attrs, defStyleAttr, 0); |
| 126 | } |
| 127 | |
| 128 | public RecentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 129 | super(context, attrs, defStyleAttr, defStyleRes); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 130 | setWillNotDraw(false); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 131 | |
| 132 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 133 | mHandler = new Handler(); |
| 134 | mTransitionHelper = new RecentsTransitionHelper(getContext(), mHandler); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 135 | mDividerSize = ssp.getDockedDividerSize(context); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 136 | mTouchHandler = new RecentsViewTouchHandler(this); |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 137 | mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 138 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 139 | final float cornerRadius = context.getResources().getDimensionPixelSize( |
| 140 | R.dimen.recents_task_view_rounded_corners_radius); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 141 | LayoutInflater inflater = LayoutInflater.from(context); |
Winson Chung | de750de | 2015-12-11 10:26:06 -0500 | [diff] [blame] | 142 | mHistoryButton = (TextView) inflater.inflate(R.layout.recents_history_button, this, false); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 143 | mHistoryButton.setOnClickListener(new View.OnClickListener() { |
| 144 | @Override |
| 145 | public void onClick(View v) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 146 | EventBus.getDefault().send(new ToggleHistoryEvent()); |
| 147 | } |
| 148 | }); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 149 | addView(mHistoryButton); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 150 | mHistoryButton.setClipToOutline(true); |
| 151 | mHistoryButton.setOutlineProvider(new ViewOutlineProvider() { |
| 152 | @Override |
| 153 | public void getOutline(View view, Outline outline) { |
| 154 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 155 | } |
| 156 | }); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 157 | mEmptyView = inflater.inflate(R.layout.recents_empty, this, false); |
| 158 | addView(mEmptyView); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 159 | |
| 160 | setBackground(mBackgroundScrim); |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 163 | /** Set/get the bsp root node */ |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 164 | public void setTaskStack(TaskStack stack) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 165 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 166 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 167 | mStack = stack; |
Winson | 55e20d5 | 2016-01-06 15:21:29 -0800 | [diff] [blame] | 168 | if (launchState.launchedReuseTaskStackViews) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 169 | if (mTaskStackView != null) { |
| 170 | // If onRecentsHidden is not triggered, we need to the stack view again here |
| 171 | mTaskStackView.reset(); |
| 172 | mTaskStackView.setStack(stack); |
| 173 | } else { |
| 174 | mTaskStackView = new TaskStackView(getContext(), stack); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 175 | addView(mTaskStackView); |
| 176 | } |
| 177 | } else { |
| 178 | if (mTaskStackView != null) { |
| 179 | removeView(mTaskStackView); |
| 180 | } |
| 181 | mTaskStackView = new TaskStackView(getContext(), stack); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 182 | addView(mTaskStackView); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 183 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 184 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 185 | // If we are already occluded by the app, then just set the default background scrim now. |
| 186 | // Otherwise, defer until the enter animation completes to animate the scrim with the |
| 187 | // tasks for the home animation. |
| 188 | if (launchState.launchedFromAppWithThumbnail || mStack.getTaskCount() == 0) { |
| 189 | mBackgroundScrim.setAlpha((int) (DEFAULT_SCRIM_ALPHA * 255)); |
| 190 | } else { |
| 191 | mBackgroundScrim.setAlpha(0); |
| 192 | } |
| 193 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 194 | // Update the top level view's visibilities |
Winson | 4b057c6 | 2016-01-12 15:01:52 -0800 | [diff] [blame] | 195 | if (stack.getTaskCount() > 0) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 196 | hideEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 197 | } else { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 198 | showEmptyView(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 199 | } |
Winson Chung | 02d4927 | 2014-08-29 13:57:29 -0700 | [diff] [blame] | 200 | |
Winson Chung | b0a28ea | 2014-10-28 15:21:35 -0700 | [diff] [blame] | 201 | // Trigger a new layout |
| 202 | requestLayout(); |
Winson Chung | 19fc117 | 2014-07-31 18:40:03 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 205 | /** |
| 206 | * Returns whether the last task launched was in the freeform stack or not. |
| 207 | */ |
| 208 | public boolean isLastTaskLaunchedFreeform() { |
| 209 | return mLastTaskLaunchedWasFreeform; |
| 210 | } |
| 211 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 212 | /** |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 213 | * Returns whether the history is visible or not. |
| 214 | */ |
| 215 | public boolean isHistoryVisible() { |
| 216 | return mHistoryView != null && mHistoryView.isVisible(); |
| 217 | } |
| 218 | |
| 219 | /** |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 220 | * Returns the currently set task stack. |
| 221 | */ |
| 222 | public TaskStack getTaskStack() { |
| 223 | return mStack; |
| 224 | } |
| 225 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 226 | /** Gets the next task in the stack - or if the last - the top task */ |
| 227 | public Task getNextTaskOrTopTask(Task taskToSearch) { |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 228 | Task returnTask = null; |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 229 | boolean found = false; |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 230 | if (mTaskStackView != null) { |
| 231 | TaskStack stack = mTaskStackView.getStack(); |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 232 | ArrayList<Task> taskList = stack.getStackTasks(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 233 | // Iterate the stack views and try and find the focused task |
| 234 | for (int j = taskList.size() - 1; j >= 0; --j) { |
| 235 | Task task = taskList.get(j); |
| 236 | // Return the next task in the line. |
| 237 | if (found) |
| 238 | return task; |
| 239 | // Remember the first possible task as the top task. |
| 240 | if (returnTask == null) |
| 241 | returnTask = task; |
| 242 | if (task == taskToSearch) |
| 243 | found = true; |
| 244 | } |
| 245 | } |
| 246 | return returnTask; |
| 247 | } |
| 248 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 249 | /** Launches the focused task from the first stack if possible */ |
| 250 | public boolean launchFocusedTask() { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 251 | if (mTaskStackView != null) { |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 252 | Task task = mTaskStackView.getFocusedTask(); |
| 253 | if (task != null) { |
| 254 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 255 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 256 | INVALID_STACK_ID, false)); |
Winson | 142af42 | 2015-11-09 10:39:57 -0800 | [diff] [blame] | 257 | return true; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 260 | return false; |
| 261 | } |
| 262 | |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 263 | /** Launches the task that recents was launched from if possible */ |
| 264 | public boolean launchPreviousTask() { |
| 265 | if (mTaskStackView != null) { |
| 266 | TaskStack stack = mTaskStackView.getStack(); |
| 267 | Task task = stack.getLaunchTarget(); |
| 268 | if (task != null) { |
| 269 | TaskView taskView = mTaskStackView.getChildViewForTask(task); |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 270 | EventBus.getDefault().send(new LaunchTaskEvent(taskView, task, null, |
| 271 | INVALID_STACK_ID, false)); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 272 | return true; |
| 273 | } |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 278 | /** Launches a given task. */ |
Filip Gruszczynski | f48b585 | 2015-10-13 10:28:22 -0700 | [diff] [blame] | 279 | public boolean launchTask(Task task, Rect taskBounds, int destinationStack) { |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 280 | if (mTaskStackView != null) { |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 281 | // Iterate the stack views and try and find the given task. |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 282 | List<TaskView> taskViews = mTaskStackView.getTaskViews(); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 283 | int taskViewCount = taskViews.size(); |
| 284 | for (int j = 0; j < taskViewCount; j++) { |
| 285 | TaskView tv = taskViews.get(j); |
| 286 | if (tv.getTask() == task) { |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 287 | EventBus.getDefault().send(new LaunchTaskEvent(tv, task, taskBounds, |
| 288 | destinationStack, false)); |
Skuhne | 8aa7d16 | 2015-03-20 13:40:53 -0700 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | return false; |
| 294 | } |
| 295 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 296 | /** Adds the search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 297 | public void setSearchBar(RecentsAppWidgetHostView searchBar) { |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 298 | // Remove the previous search bar if one exists |
| 299 | if (mSearchBar != null && indexOfChild(mSearchBar) > -1) { |
| 300 | removeView(mSearchBar); |
| 301 | } |
| 302 | // Add the new search bar |
| 303 | if (searchBar != null) { |
| 304 | mSearchBar = searchBar; |
| 305 | addView(mSearchBar); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 306 | } |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 309 | /** Returns whether there is currently a search bar */ |
Winson Chung | aee097c | 2015-04-02 18:16:02 -0700 | [diff] [blame] | 310 | public boolean hasValidSearchBar() { |
| 311 | return mSearchBar != null && !mSearchBar.isReinflateRequired(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 314 | /** |
| 315 | * Hides the task stack and shows the empty view. |
| 316 | */ |
| 317 | public void showEmptyView() { |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 318 | if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 319 | mSearchBar.setVisibility(View.INVISIBLE); |
| 320 | } |
| 321 | mTaskStackView.setVisibility(View.INVISIBLE); |
| 322 | mEmptyView.setVisibility(View.VISIBLE); |
| 323 | mEmptyView.bringToFront(); |
| 324 | mHistoryButton.bringToFront(); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Shows the task stack and hides the empty view. |
| 329 | */ |
| 330 | public void hideEmptyView() { |
| 331 | mEmptyView.setVisibility(View.INVISIBLE); |
| 332 | mTaskStackView.setVisibility(View.VISIBLE); |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 333 | if (RecentsDebugFlags.Static.EnableSearchBar && (mSearchBar != null)) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 334 | mSearchBar.setVisibility(View.VISIBLE); |
| 335 | } |
| 336 | mTaskStackView.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 337 | if (mSearchBar != null) { |
Winson Chung | 012ef36 | 2014-07-31 18:36:25 -0700 | [diff] [blame] | 338 | mSearchBar.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 339 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 340 | mHistoryButton.bringToFront(); |
Winson Chung | 772b6b1 | 2014-07-03 15:54:02 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 343 | @Override |
| 344 | protected void onAttachedToWindow() { |
| 345 | EventBus.getDefault().register(this, RecentsActivity.EVENT_BUS_PRIORITY + 1); |
Winson | c8a4cdc | 2016-01-19 11:30:51 -0800 | [diff] [blame] | 346 | EventBus.getDefault().register(mTouchHandler, RecentsActivity.EVENT_BUS_PRIORITY + 2); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 347 | super.onAttachedToWindow(); |
| 348 | } |
| 349 | |
| 350 | @Override |
| 351 | protected void onDetachedFromWindow() { |
| 352 | super.onDetachedFromWindow(); |
| 353 | EventBus.getDefault().unregister(this); |
| 354 | EventBus.getDefault().unregister(mTouchHandler); |
| 355 | } |
| 356 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 357 | /** |
| 358 | * This is called with the full size of the window since we are handling our own insets. |
| 359 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 360 | @Override |
| 361 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 362 | RecentsConfiguration config = Recents.getConfiguration(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 363 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 364 | int height = MeasureSpec.getSize(heightMeasureSpec); |
Winson Chung | bd91297 | 2014-03-18 14:36:35 -0700 | [diff] [blame] | 365 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 366 | // Get the search bar bounds and measure the search bar layout |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 367 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 368 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 369 | config.getSearchBarBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 370 | searchBarSpaceBounds); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 371 | mSearchBar.measure( |
| 372 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY), |
| 373 | MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.height(), MeasureSpec.EXACTLY)); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 376 | Rect taskStackBounds = new Rect(); |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 377 | config.getTaskStackBounds(new Rect(0, 0, width, height), mSystemInsets.top, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 378 | mSystemInsets.right, searchBarSpaceBounds, taskStackBounds); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 379 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
Winson | 88f00ab | 2015-10-05 17:24:00 -0700 | [diff] [blame] | 380 | mTaskStackView.setTaskStackBounds(taskStackBounds, mSystemInsets); |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 381 | mTaskStackView.measure(widthMeasureSpec, heightMeasureSpec); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 384 | // Measure the empty view to the full size of the screen |
| 385 | if (mEmptyView.getVisibility() != GONE) { |
| 386 | measureChild(mEmptyView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 387 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 388 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 389 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 390 | // Measure the history view |
| 391 | if (mHistoryView != null && mHistoryView.getVisibility() != GONE) { |
| 392 | measureChild(mHistoryView, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 393 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
| 394 | } |
| 395 | |
| 396 | // Measure the history button within the constraints of the space above the stack |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 397 | Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 398 | measureChild(mHistoryButton, |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 399 | MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST), |
| 400 | MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST)); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 401 | if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) { |
| 402 | measureChild(mHistoryClearAllButton, |
| 403 | MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST), |
| 404 | MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST)); |
| 405 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 406 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 407 | setMeasuredDimension(width, height); |
| 408 | } |
| 409 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 410 | /** |
| 411 | * This is called with the full size of the window since we are handling our own insets. |
| 412 | */ |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 413 | @Override |
| 414 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 415 | RecentsConfiguration config = Recents.getConfiguration(); |
| 416 | |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 417 | // Get the search bar bounds so that we lay it out |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 418 | Rect measuredRect = new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 419 | Rect searchBarSpaceBounds = new Rect(); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 420 | if (mSearchBar != null) { |
Winson | 53ec42c | 2015-10-28 15:55:35 -0700 | [diff] [blame] | 421 | config.getSearchBarBounds(measuredRect, |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 422 | mSystemInsets.top, searchBarSpaceBounds); |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 423 | mSearchBar.layout(searchBarSpaceBounds.left, searchBarSpaceBounds.top, |
| 424 | searchBarSpaceBounds.right, searchBarSpaceBounds.bottom); |
Winson Chung | ecd9b30 | 2014-04-16 17:07:18 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Winson | 147ecaf | 2015-09-16 16:49:55 -0700 | [diff] [blame] | 427 | if (mTaskStackView != null && mTaskStackView.getVisibility() != GONE) { |
| 428 | mTaskStackView.layout(left, top, left + getMeasuredWidth(), top + getMeasuredHeight()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 429 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 430 | |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 431 | // Layout the empty view |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 432 | if (mEmptyView.getVisibility() != GONE) { |
| 433 | mEmptyView.layout(left, top, right, bottom); |
| 434 | } |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 435 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 436 | // Layout the history view |
| 437 | if (mHistoryView != null && mHistoryView.getVisibility() != GONE) { |
| 438 | mHistoryView.layout(left, top, right, bottom); |
| 439 | } |
| 440 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 441 | // Layout the history button such that its drawable is start-aligned with the stack, |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 442 | // vertically centered in the available space above the stack |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 443 | Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect; |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 444 | int historyLeft = isLayoutRtl() |
| 445 | ? historyButtonRect.right + mHistoryButton.getPaddingStart() |
| 446 | - mHistoryButton.getMeasuredWidth() |
| 447 | : historyButtonRect.left - mHistoryButton.getPaddingStart(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 448 | int historyTop = historyButtonRect.top + |
| 449 | (historyButtonRect.height() - mHistoryButton.getMeasuredHeight()) / 2; |
| 450 | mHistoryButton.layout(historyLeft, historyTop, |
| 451 | historyLeft + mHistoryButton.getMeasuredWidth(), |
| 452 | historyTop + mHistoryButton.getMeasuredHeight()); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 453 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 454 | // Layout the history clear all button such that it is end-aligned with the stack, |
| 455 | // vertically centered in the available space above the stack |
| 456 | if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) { |
| 457 | int clearAllLeft = isLayoutRtl() |
| 458 | ? historyButtonRect.left - mHistoryClearAllButton.getPaddingStart() |
| 459 | : historyButtonRect.right + mHistoryClearAllButton.getPaddingStart() |
| 460 | - mHistoryClearAllButton.getMeasuredWidth(); |
| 461 | int clearAllTop = historyButtonRect.top + |
| 462 | (historyButtonRect.height() - mHistoryClearAllButton.getMeasuredHeight()) / 2; |
| 463 | mHistoryClearAllButton.layout(clearAllLeft, clearAllTop, |
| 464 | clearAllLeft + mHistoryClearAllButton.getMeasuredWidth(), |
| 465 | clearAllTop + mHistoryClearAllButton.getMeasuredHeight()); |
| 466 | } |
| 467 | |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 468 | if (mAwaitingFirstLayout) { |
| 469 | mAwaitingFirstLayout = false; |
| 470 | |
| 471 | // If launched via dragging from the nav bar, then we should translate the whole view |
| 472 | // down offscreen |
| 473 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 474 | if (launchState.launchedViaDragGesture) { |
| 475 | setTranslationY(getMeasuredHeight()); |
Jorim Jaggi | 0ca8826 | 2015-12-07 17:15:16 -0800 | [diff] [blame] | 476 | } else { |
| 477 | setTranslationY(0f); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 478 | } |
| 479 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 480 | } |
| 481 | |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 482 | @Override |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 483 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 484 | mSystemInsets.set(insets.getSystemWindowInsets()); |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 485 | requestLayout(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 486 | return insets; |
Winson Chung | 8eaeb7d | 2014-06-25 15:10:59 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 489 | @Override |
| 490 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 491 | return mTouchHandler.onInterceptTouchEvent(ev); |
| 492 | } |
| 493 | |
| 494 | @Override |
| 495 | public boolean onTouchEvent(MotionEvent ev) { |
| 496 | return mTouchHandler.onTouchEvent(ev); |
| 497 | } |
| 498 | |
| 499 | @Override |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 500 | public void onDrawForeground(Canvas canvas) { |
| 501 | super.onDrawForeground(canvas); |
| 502 | |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 503 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 504 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 505 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 506 | if (d.getAlpha() > 0) { |
| 507 | d.draw(canvas); |
| 508 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 512 | @Override |
| 513 | protected boolean verifyDrawable(Drawable who) { |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 514 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 515 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 516 | Drawable d = visDockStates.get(i).viewState.dockAreaOverlay; |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 517 | if (d == who) { |
| 518 | return true; |
| 519 | } |
| 520 | } |
| 521 | return super.verifyDrawable(who); |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 524 | /**** EventBus Events ****/ |
| 525 | |
Winson Chung | 48f2cda | 2015-12-11 13:20:12 -0500 | [diff] [blame] | 526 | public final void onBusEvent(LaunchTaskEvent event) { |
| 527 | mLastTaskLaunchedWasFreeform = event.task.isFreeformTask(); |
| 528 | mTransitionHelper.launchTaskFromRecents(mStack, event.task, mTaskStackView, event.taskView, |
| 529 | event.screenPinningRequested, event.targetTaskBounds, event.targetTaskStack); |
| 530 | } |
| 531 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 532 | public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { |
| 533 | // Hide the history button |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 534 | int taskViewExitToHomeDuration = TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 535 | hideHistoryButton(taskViewExitToHomeDuration, false /* translate */); |
| 536 | animateBackgroundScrim(0f, taskViewExitToHomeDuration); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 539 | public final void onBusEvent(DragStartEvent event) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 540 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 541 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 542 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 545 | public final void onBusEvent(DragDropTargetChangedEvent event) { |
| 546 | if (event.dropTarget == null || !(event.dropTarget instanceof TaskStack.DockState)) { |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 547 | updateVisibleDockRegions(mTouchHandler.getDockStatesForCurrentOrientation(), |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 548 | true /* isDefaultDockState */, TaskStack.DockState.NONE.viewState.dockAreaAlpha, |
| 549 | true /* animateAlpha */, true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 550 | } else { |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 551 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 552 | updateVisibleDockRegions(new TaskStack.DockState[] {dockState}, |
| 553 | false /* isDefaultDockState */, -1, true /* animateAlpha */, |
| 554 | true /* animateBounds */); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 555 | } |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | public final void onBusEvent(final DragEndEvent event) { |
Winson | 479f744 | 2015-11-25 15:16:27 -0800 | [diff] [blame] | 559 | // Handle the case where we drop onto a dock region |
| 560 | if (event.dropTarget instanceof TaskStack.DockState) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 561 | final TaskStack.DockState dockState = (TaskStack.DockState) event.dropTarget; |
| 562 | |
| 563 | // Hide the dock region |
| 564 | updateVisibleDockRegions(null, false /* isDefaultDockState */, -1, |
| 565 | false /* animateAlpha */, false /* animateBounds */); |
| 566 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 567 | TaskStackLayoutAlgorithm stackLayout = mTaskStackView.getStackAlgorithm(); |
| 568 | TaskStackViewScroller stackScroller = mTaskStackView.getScroller(); |
| 569 | TaskViewTransform tmpTransform = new TaskViewTransform(); |
Winson | eca4ab6 | 2015-11-04 10:50:28 -0800 | [diff] [blame] | 570 | |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 571 | // We translated the view but we need to animate it back from the current layout-space |
| 572 | // rect to its final layout-space rect |
| 573 | int x = (int) event.taskView.getTranslationX(); |
| 574 | int y = (int) event.taskView.getTranslationY(); |
| 575 | Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(), |
| 576 | event.taskView.getRight(), event.taskView.getBottom()); |
| 577 | taskViewRect.offset(x, y); |
| 578 | event.taskView.setTranslationX(0); |
| 579 | event.taskView.setTranslationY(0); |
| 580 | event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top, |
| 581 | taskViewRect.right, taskViewRect.bottom); |
| 582 | |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 583 | // Remove the task view after it is docked |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 584 | mTaskStackView.updateLayoutAlgorithm(false /* boundScroll */); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 585 | stackLayout.getStackTransform(event.task, stackScroller.getStackScroll(), tmpTransform, |
| 586 | null); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 587 | tmpTransform.alpha = 0; |
| 588 | tmpTransform.scale = 1f; |
| 589 | tmpTransform.rect.set(taskViewRect); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 590 | mTaskStackView.updateTaskViewToTransform(event.taskView, tmpTransform, |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 591 | new AnimationProps(125, Interpolators.ALPHA_OUT, |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 592 | new AnimatorListenerAdapter() { |
| 593 | @Override |
| 594 | public void onAnimationEnd(Animator animation) { |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 595 | // Dock the task and launch it |
| 596 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Filip Gruszczynski | f298e90 | 2016-01-18 08:59:45 -0800 | [diff] [blame] | 597 | ssp.startTaskInDockedMode(getContext(), event.taskView, |
| 598 | event.task.key.id, dockState.createMode); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 599 | |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 600 | // Animate the stack accordingly |
Winson | be8e696 | 2016-02-01 14:27:52 -0800 | [diff] [blame] | 601 | AnimationProps stackAnim = new AnimationProps( |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 602 | TaskStackView.DEFAULT_SYNC_STACK_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 603 | Interpolators.FAST_OUT_SLOW_IN); |
Winson | 8aa9959 | 2016-01-19 15:07:07 -0800 | [diff] [blame] | 604 | mTaskStackView.getStack().removeTask(event.task, stackAnim); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 605 | } |
| 606 | })); |
Winson | a0a8ae4 | 2015-12-01 10:43:02 -0800 | [diff] [blame] | 607 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 608 | MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 609 | } else { |
| 610 | // Animate the overlay alpha back to 0 |
| 611 | updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, |
| 612 | true /* animateAlpha */, false /* animateBounds */); |
Winson | be7607a | 2015-10-01 17:24:51 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 615 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 616 | public final void onBusEvent(DraggingInRecentsEvent event) { |
Jorim Jaggi | 54b1a6d | 2015-11-24 17:48:26 -0800 | [diff] [blame] | 617 | if (mTaskStackView.getTaskViews().size() > 0) { |
| 618 | setTranslationY(event.distanceFromTop - mTaskStackView.getTaskViews().get(0).getY()); |
| 619 | } |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | public final void onBusEvent(DraggingInRecentsEndedEvent event) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 623 | ViewPropertyAnimator animator = animate(); |
Jorim Jaggi | 8fccfe2 | 2015-12-03 16:58:08 -0800 | [diff] [blame] | 624 | if (event.velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) { |
Jorim Jaggi | 870ab5a | 2015-12-02 18:37:54 -0800 | [diff] [blame] | 625 | animator.translationY(getHeight()); |
| 626 | animator.withEndAction(new Runnable() { |
| 627 | @Override |
| 628 | public void run() { |
| 629 | WindowManagerProxy.getInstance().maximizeDockedStack(); |
| 630 | } |
| 631 | }); |
| 632 | mFlingAnimationUtils.apply(animator, getTranslationY(), getHeight(), event.velocity); |
| 633 | } else { |
| 634 | animator.translationY(0f); |
| 635 | animator.setListener(null); |
| 636 | mFlingAnimationUtils.apply(animator, getTranslationY(), 0, event.velocity); |
| 637 | } |
| 638 | animator.start(); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 641 | public final void onBusEvent(TaskStackUpdatedEvent event) { |
| 642 | mStack.setTasks(event.stack.computeAllTasksList(), true /* notifyStackChanges */); |
Winson Chung | 9756755 | 2015-12-16 17:07:19 -0500 | [diff] [blame] | 643 | mStack.createAffiliatedGroupings(getContext()); |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 646 | public final void onBusEvent(EnterRecentsWindowAnimationCompletedEvent event) { |
| 647 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 648 | if (!launchState.launchedFromAppWithThumbnail && mStack.getTaskCount() > 0) { |
Winson | 5044863 | 2016-02-01 18:04:59 -0800 | [diff] [blame] | 649 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, |
| 650 | TaskStackAnimationHelper.ENTER_FROM_HOME_TRANSLATION_DURATION); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | public final void onBusEvent(UpdateBackgroundScrimEvent event) { |
| 655 | animateBackgroundScrim(event.alpha, DEFAULT_UPDATE_SCRIM_DURATION); |
| 656 | } |
| 657 | |
| 658 | public final void onBusEvent(ResetBackgroundScrimEvent event) { |
| 659 | animateBackgroundScrim(DEFAULT_SCRIM_ALPHA, DEFAULT_UPDATE_SCRIM_DURATION); |
| 660 | } |
| 661 | |
| 662 | public final void onBusEvent(RecentsVisibilityChangedEvent event) { |
| 663 | if (!event.visible) { |
| 664 | // Reset the view state |
| 665 | mAwaitingFirstLayout = true; |
| 666 | mLastTaskLaunchedWasFreeform = false; |
| 667 | hideHistoryButton(0, false /* translate */); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | public final void onBusEvent(ToggleHistoryEvent event) { |
| 672 | if (mHistoryView != null && mHistoryView.isVisible()) { |
| 673 | EventBus.getDefault().send(new HideHistoryEvent(true /* animate */)); |
| 674 | } else { |
| 675 | EventBus.getDefault().send(new ShowHistoryEvent()); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | public final void onBusEvent(ShowHistoryEvent event) { |
| 680 | if (mHistoryView == null) { |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 681 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
| 682 | mHistoryView = (RecentsHistoryView) inflater.inflate(R.layout.recents_history, this, |
| 683 | false); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 684 | addView(mHistoryView); |
| 685 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 686 | final float cornerRadius = getResources().getDimensionPixelSize( |
| 687 | R.dimen.recents_task_view_rounded_corners_radius); |
| 688 | mHistoryClearAllButton = (TextView) inflater.inflate( |
| 689 | R.layout.recents_history_clear_all_button, this, false); |
| 690 | mHistoryClearAllButton.setOnClickListener(new View.OnClickListener() { |
| 691 | @Override |
| 692 | public void onClick(View v) { |
| 693 | EventBus.getDefault().send(new ClearHistoryEvent()); |
| 694 | } |
| 695 | }); |
| 696 | mHistoryClearAllButton.setClipToOutline(true); |
| 697 | mHistoryClearAllButton.setOutlineProvider(new ViewOutlineProvider() { |
| 698 | @Override |
| 699 | public void getOutline(View view, Outline outline) { |
| 700 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius); |
| 701 | } |
| 702 | }); |
| 703 | addView(mHistoryClearAllButton); |
| 704 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 705 | // Since this history view is inflated by a view stub after the insets have already |
| 706 | // been applied, we have to set them ourselves initial from the insets that were last |
| 707 | // provided. |
| 708 | mHistoryView.setSystemInsets(mSystemInsets); |
| 709 | mHistoryView.setHeaderHeight(mHistoryButton.getMeasuredHeight()); |
| 710 | mHistoryButton.bringToFront(); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 711 | mHistoryClearAllButton.bringToFront(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | // Animate the empty view in parallel with the history view (the task view animations are |
| 715 | // handled in TaskStackView) |
| 716 | Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect; |
| 717 | if (mEmptyView.getVisibility() == View.VISIBLE) { |
| 718 | int historyTransitionDuration = getResources().getInteger( |
| 719 | R.integer.recents_history_transition_duration); |
| 720 | mEmptyView.animate() |
| 721 | .alpha(0f) |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 722 | .translationY(stackRect.height() / 2) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 723 | .setDuration(historyTransitionDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 724 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 725 | .withEndAction(new Runnable() { |
| 726 | @Override |
| 727 | public void run() { |
| 728 | mEmptyView.setVisibility(View.INVISIBLE); |
| 729 | } |
| 730 | }) |
| 731 | .start(); |
| 732 | } |
| 733 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 734 | mHistoryView.show(mStack, stackRect.height(), mHistoryClearAllButton); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | public final void onBusEvent(HideHistoryEvent event) { |
| 738 | // Animate the empty view in parallel with the history view (the task view animations are |
| 739 | // handled in TaskStackView) |
| 740 | Rect stackRect = mTaskStackView.mLayoutAlgorithm.mStackRect; |
| 741 | if (mStack.getTaskCount() == 0) { |
| 742 | int historyTransitionDuration = getResources().getInteger( |
| 743 | R.integer.recents_history_transition_duration); |
| 744 | mEmptyView.setVisibility(View.VISIBLE); |
| 745 | mEmptyView.animate() |
| 746 | .alpha(1f) |
| 747 | .translationY(0) |
| 748 | .setDuration(historyTransitionDuration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 749 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 750 | .start(); |
| 751 | } |
| 752 | |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 753 | mHistoryView.hide(event.animate, stackRect.height(), mHistoryClearAllButton); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | public final void onBusEvent(ShowHistoryButtonEvent event) { |
| 757 | showHistoryButton(150, event.translate); |
| 758 | } |
| 759 | |
| 760 | public final void onBusEvent(HideHistoryButtonEvent event) { |
| 761 | hideHistoryButton(100, true /* translate */); |
| 762 | } |
| 763 | |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 764 | /** |
| 765 | * Shows the history button. |
| 766 | */ |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 767 | private void showHistoryButton(final int duration, final boolean translate) { |
| 768 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 769 | if (mHistoryButton.getVisibility() == View.INVISIBLE) { |
| 770 | mHistoryButton.setVisibility(View.VISIBLE); |
| 771 | mHistoryButton.setAlpha(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 772 | if (translate) { |
| 773 | mHistoryButton.setTranslationY(-mHistoryButton.getMeasuredHeight() * 0.25f); |
Winson | 214f0f0 | 2016-01-26 13:37:37 -0800 | [diff] [blame] | 774 | } else { |
| 775 | mHistoryButton.setTranslationY(0f); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 776 | } |
| 777 | postAnimationTrigger.addLastDecrementRunnable(new Runnable() { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 778 | @Override |
| 779 | public void run() { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 780 | if (translate) { |
| 781 | mHistoryButton.animate() |
| 782 | .translationY(0f); |
| 783 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 784 | mHistoryButton.animate() |
| 785 | .alpha(1f) |
| 786 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 787 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 788 | .withLayer() |
| 789 | .start(); |
| 790 | } |
| 791 | }); |
| 792 | } |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 793 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /** |
| 797 | * Hides the history button. |
| 798 | */ |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 799 | private void hideHistoryButton(int duration, boolean translate) { |
| 800 | final ReferenceCountedTrigger postAnimationTrigger = new ReferenceCountedTrigger(); |
| 801 | hideHistoryButton(duration, translate, postAnimationTrigger); |
Winson Chung | aaeaac1 | 2015-12-16 16:49:36 -0500 | [diff] [blame] | 802 | postAnimationTrigger.flushLastDecrementRunnables(); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 803 | } |
| 804 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 805 | /** |
| 806 | * Hides the history button. |
| 807 | */ |
| 808 | private void hideHistoryButton(int duration, boolean translate, |
| 809 | final ReferenceCountedTrigger postAnimationTrigger) { |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 810 | if (mHistoryButton.getVisibility() == View.VISIBLE) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 811 | if (translate) { |
| 812 | mHistoryButton.animate() |
| 813 | .translationY(-mHistoryButton.getMeasuredHeight() * 0.25f); |
| 814 | } |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 815 | mHistoryButton.animate() |
| 816 | .alpha(0f) |
| 817 | .setDuration(duration) |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 818 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 819 | .withEndAction(new Runnable() { |
| 820 | @Override |
| 821 | public void run() { |
| 822 | mHistoryButton.setVisibility(View.INVISIBLE); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 823 | postAnimationTrigger.decrement(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 824 | } |
| 825 | }) |
| 826 | .withLayer() |
| 827 | .start(); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 828 | postAnimationTrigger.increment(); |
Winson | f24f216 | 2016-01-05 12:11:55 -0800 | [diff] [blame] | 829 | } |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 830 | } |
| 831 | |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 832 | /** |
| 833 | * Updates the dock region to match the specified dock state. |
| 834 | */ |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 835 | private void updateVisibleDockRegions(TaskStack.DockState[] newDockStates, |
| 836 | boolean isDefaultDockState, int overrideAlpha, boolean animateAlpha, |
| 837 | boolean animateBounds) { |
Winson | c5fd350 | 2016-01-18 15:18:37 -0800 | [diff] [blame] | 838 | ArraySet<TaskStack.DockState> newDockStatesSet = Utilities.arrayToSet(newDockStates, |
| 839 | new ArraySet<TaskStack.DockState>()); |
Winson | 036693c | 2016-01-14 17:16:06 -0800 | [diff] [blame] | 840 | ArrayList<TaskStack.DockState> visDockStates = mTouchHandler.getVisibleDockStates(); |
| 841 | for (int i = visDockStates.size() - 1; i >= 0; i--) { |
| 842 | TaskStack.DockState dockState = visDockStates.get(i); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 843 | TaskStack.DockState.ViewState viewState = dockState.viewState; |
| 844 | if (newDockStates == null || !newDockStatesSet.contains(dockState)) { |
| 845 | // This is no longer visible, so hide it |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 846 | viewState.startAnimation(null, 0, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 847 | Interpolators.ALPHA_OUT, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 848 | } else { |
| 849 | // This state is now visible, update the bounds and show it |
| 850 | int alpha = (overrideAlpha != -1 ? overrideAlpha : viewState.dockAreaAlpha); |
Winson | 3e87474 | 2016-01-07 10:08:17 -0800 | [diff] [blame] | 851 | Rect bounds = isDefaultDockState |
| 852 | ? dockState.getPreDockedBounds(getMeasuredWidth(), getMeasuredHeight()) |
| 853 | : dockState.getDockedBounds(getMeasuredWidth(), getMeasuredHeight(), |
| 854 | mDividerSize, mSystemInsets, getResources()); |
| 855 | if (viewState.dockAreaOverlay.getCallback() != this) { |
| 856 | viewState.dockAreaOverlay.setCallback(this); |
| 857 | viewState.dockAreaOverlay.setBounds(bounds); |
| 858 | } |
| 859 | viewState.startAnimation(bounds, alpha, DOCK_AREA_OVERLAY_TRANSITION_DURATION, |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 860 | Interpolators.ALPHA_IN, animateAlpha, animateBounds); |
Winson | 882072b | 2015-10-12 11:26:33 -0700 | [diff] [blame] | 861 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 862 | } |
Winson | 4165d336 | 2015-10-10 14:40:35 -0700 | [diff] [blame] | 863 | } |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 864 | |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 865 | /** |
| 866 | * Animates the background scrim to the given {@param alpha}. |
| 867 | */ |
| 868 | private void animateBackgroundScrim(float alpha, int duration) { |
| 869 | Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator); |
| 870 | int alphaInt = (int) (alpha * 255); |
| 871 | mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA, |
| 872 | mBackgroundScrim.getAlpha(), alphaInt); |
| 873 | mBackgroundScrimAnimator.setDuration(duration); |
| 874 | mBackgroundScrimAnimator.setInterpolator(alphaInt > mBackgroundScrim.getAlpha() |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 875 | ? Interpolators.ALPHA_OUT |
| 876 | : Interpolators.ALPHA_IN); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 877 | mBackgroundScrimAnimator.start(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 878 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 879 | } |