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 | * |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 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; |
| 18 | |
| 19 | import android.app.Activity; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 20 | import android.app.ActivityOptions; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 21 | import android.app.TaskStackBuilder; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 22 | import android.content.BroadcastReceiver; |
| 23 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 25 | import android.content.IntentFilter; |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 28 | import android.os.Bundle; |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 29 | import android.os.SystemClock; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 31 | import android.provider.Settings; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 32 | import android.util.Log; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 33 | import android.view.KeyEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 34 | import android.view.View; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 35 | import android.view.ViewTreeObserver; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 36 | import android.view.WindowManager; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 37 | import android.view.WindowManager.LayoutParams; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 38 | |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 39 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 40 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 41 | import com.android.systemui.R; |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 42 | import com.android.systemui.recents.events.EventBus; |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 43 | import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 44 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 45 | import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 46 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 47 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 48 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 49 | import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 50 | import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 51 | import com.android.systemui.recents.events.activity.HideRecentsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 52 | import com.android.systemui.recents.events.activity.IterateRecentsEvent; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 53 | import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent; |
| 54 | import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.ToggleRecentsEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 58 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 60 | import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 62 | import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 63 | import com.android.systemui.recents.events.ui.StackViewScrolledEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 64 | import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 65 | import com.android.systemui.recents.events.ui.UserInteractionEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 66 | import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent; |
| 67 | import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent; |
| 68 | import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.DozeTrigger; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 70 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 71 | import com.android.systemui.recents.model.RecentsPackageMonitor; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 72 | import com.android.systemui.recents.model.RecentsTaskLoadPlan; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 73 | import com.android.systemui.recents.model.RecentsTaskLoader; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 74 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 75 | import com.android.systemui.recents.model.TaskStack; |
| 76 | import com.android.systemui.recents.views.RecentsView; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 77 | import com.android.systemui.recents.views.SystemBarScrimViews; |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 78 | import com.android.systemui.statusbar.BaseStatusBar; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 79 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 80 | /** |
| 81 | * The main Recents activity that is started from AlternateRecentsComponent. |
| 82 | */ |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 83 | public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreDrawListener { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 84 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 85 | private final static String TAG = "RecentsActivity"; |
| 86 | private final static boolean DEBUG = false; |
| 87 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 88 | public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1; |
| 89 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 90 | private RecentsPackageMonitor mPackageMonitor; |
| 91 | private long mLastTabKeyEventTime; |
| 92 | private boolean mFinishedOnStartup; |
| 93 | private boolean mIgnoreAltTabRelease; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 94 | private boolean mIsVisible; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 95 | |
| 96 | // Top level views |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 97 | private RecentsView mRecentsView; |
| 98 | private SystemBarScrimViews mScrimViews; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 99 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 100 | // Runnables to finish the Recents activity |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 101 | private Intent mHomeIntent; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 102 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 103 | // The trigger to automatically launch the current task |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 104 | private int mFocusTimerDuration; |
| 105 | private DozeTrigger mIterateTrigger; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 106 | private final UserInteractionEvent mUserInteractionEvent = new UserInteractionEvent(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 107 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 108 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 109 | * A common Runnable to finish Recents by launching Home with an animation depending on the |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 110 | * last activity launch state. Generally we always launch home when we exit Recents rather than |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 111 | * just finishing the activity since we don't know what is behind Recents in the task stack. |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 112 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 113 | class LaunchHomeRunnable implements Runnable { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 114 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 115 | Intent mLaunchIntent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 116 | ActivityOptions mOpts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 117 | |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 118 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 119 | * Creates a finish runnable that starts the specified intent. |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 120 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 121 | public LaunchHomeRunnable(Intent launchIntent, ActivityOptions opts) { |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 122 | mLaunchIntent = launchIntent; |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 123 | mOpts = opts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void run() { |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 128 | try { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 129 | ActivityOptions opts = mOpts; |
| 130 | if (opts == null) { |
| 131 | opts = ActivityOptions.makeCustomAnimation(RecentsActivity.this, |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 132 | R.anim.recents_to_launcher_enter, R.anim.recents_to_launcher_exit); |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 133 | } |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 134 | startActivityAsUser(mLaunchIntent, opts.toBundle(), UserHandle.CURRENT); |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 135 | } catch (Exception e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 136 | Log.e(TAG, getString(R.string.recents_launch_error_message, "Home"), e); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 141 | /** |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 142 | * Broadcast receiver to handle messages from the system |
| 143 | */ |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 144 | final BroadcastReceiver mSystemBroadcastReceiver = new BroadcastReceiver() { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 145 | @Override |
| 146 | public void onReceive(Context context, Intent intent) { |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 147 | String action = intent.getAction(); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 148 | if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| 149 | // When the screen turns off, dismiss Recents to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 150 | dismissRecentsToHomeIfVisible(false); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 151 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 152 | } |
| 153 | }; |
| 154 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 157 | */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 158 | boolean dismissRecentsToFocusedTask(int logCategory) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 159 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 160 | if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 161 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 162 | if (mRecentsView.launchFocusedTask(logCategory)) return true; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | /** |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 168 | * Dismisses recents back to the launch target task. |
| 169 | */ |
| 170 | boolean dismissRecentsToLaunchTargetTaskOrHome() { |
| 171 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 172 | if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) { |
| 173 | // If we have a focused Task, launch that Task now |
| 174 | if (mRecentsView.launchPreviousTask()) return true; |
| 175 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 176 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 177 | } |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | /** |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 182 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 183 | */ |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 184 | boolean dismissRecentsToFocusedTaskOrHome() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 185 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 186 | if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 187 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 188 | if (mRecentsView.launchFocusedTask(0 /* logCategory */)) return true; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 189 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 190 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 191 | return true; |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 198 | */ |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 199 | void dismissRecentsToHome(boolean animateTaskViews) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 200 | dismissRecentsToHome(animateTaskViews, null); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 205 | * |
| 206 | * @param overrideAnimation If not null, will override the default animation that is based on |
| 207 | * how Recents was launched. |
| 208 | */ |
| 209 | void dismissRecentsToHome(boolean animateTaskViews, ActivityOptions overrideAnimation) { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 210 | DismissRecentsToHomeAnimationStarted dismissEvent = |
| 211 | new DismissRecentsToHomeAnimationStarted(animateTaskViews); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 212 | dismissEvent.addPostAnimationCallback(new LaunchHomeRunnable(mHomeIntent, |
| 213 | overrideAnimation)); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 214 | dismissEvent.addPostAnimationCallback(new Runnable() { |
| 215 | @Override |
| 216 | public void run() { |
| 217 | Recents.getSystemServices().sendCloseSystemWindows( |
| 218 | BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); |
| 219 | } |
| 220 | }); |
| 221 | EventBus.getDefault().send(dismissEvent); |
Wale Ogunwale | d351ada | 2015-04-04 11:53:14 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 224 | /** Dismisses Recents directly to Home if we currently aren't transitioning. */ |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 225 | boolean dismissRecentsToHomeIfVisible(boolean animated) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 226 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson Chung | 2cf8b22 | 2015-01-20 11:44:05 -0800 | [diff] [blame] | 227 | if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 228 | // Return to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 229 | dismissRecentsToHome(animated); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 230 | return true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 231 | } |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | /** Called with the activity is first created. */ |
| 236 | @Override |
| 237 | public void onCreate(Bundle savedInstanceState) { |
| 238 | super.onCreate(savedInstanceState); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 239 | mFinishedOnStartup = false; |
| 240 | |
| 241 | // In the case that the activity starts up before the Recents component has initialized |
| 242 | // (usually when debugging/pushing the SysUI apk), just finish this activity. |
| 243 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 244 | if (ssp == null) { |
| 245 | mFinishedOnStartup = true; |
| 246 | finish(); |
| 247 | return; |
| 248 | } |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 249 | |
| 250 | // Register this activity with the event bus |
| 251 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
| 252 | |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 253 | // Initialize the package monitor |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 254 | mPackageMonitor = new RecentsPackageMonitor(); |
| 255 | mPackageMonitor.register(this); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 256 | |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 257 | // Set the Recents layout |
| 258 | setContentView(R.layout.recents); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 259 | takeKeyEvents(true); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 260 | mRecentsView = (RecentsView) findViewById(R.id.recents_view); |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 261 | mRecentsView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
| 262 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| 263 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 264 | mScrimViews = new SystemBarScrimViews(this); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 265 | getWindow().getAttributes().privateFlags |= |
| 266 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 267 | |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 268 | mFocusTimerDuration = getResources().getInteger(R.integer.recents_auto_advance_duration); |
| 269 | mIterateTrigger = new DozeTrigger(mFocusTimerDuration, new Runnable() { |
| 270 | @Override |
| 271 | public void run() { |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 272 | dismissRecentsToFocusedTask(MetricsEvent.OVERVIEW_SELECT_TIMEOUT); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 273 | } |
| 274 | }); |
| 275 | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 276 | // Create the home intent runnable |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 277 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 278 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 279 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 280 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 281 | |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 282 | // Register the broadcast receiver to handle messages when the screen is turned off |
| 283 | IntentFilter filter = new IntentFilter(); |
| 284 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 285 | registerReceiver(mSystemBroadcastReceiver, filter); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 286 | |
| 287 | getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION); |
Winson Chung | 521e7dc | 2014-06-02 15:31:56 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 290 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 291 | protected void onStart() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 292 | super.onStart(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 293 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 294 | // Notify that recents is now visible |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 295 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 296 | MetricsLogger.visible(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | @Override |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 300 | public void onEnterAnimationComplete() { |
| 301 | super.onEnterAnimationComplete(); |
| 302 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
| 303 | } |
| 304 | |
| 305 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 306 | protected void onResume() { |
| 307 | super.onResume(); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 308 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 309 | // If the Recents component has preloaded a load plan, then use that to prevent |
| 310 | // reconstructing the task stack |
| 311 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 312 | RecentsTaskLoadPlan loadPlan = RecentsImpl.consumeInstanceLoadPlan(); |
| 313 | if (loadPlan == null) { |
| 314 | loadPlan = loader.createLoadPlan(this); |
| 315 | } |
| 316 | |
| 317 | // Start loading tasks according to the load plan |
| 318 | RecentsConfiguration config = Recents.getConfiguration(); |
| 319 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 320 | if (!loadPlan.hasTasks()) { |
Winson | 96e6134 | 2016-03-15 16:47:19 -0700 | [diff] [blame] | 321 | loader.preloadTasks(loadPlan, launchState.launchedToTaskId, |
| 322 | launchState.launchedFromHome); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 326 | loadOpts.runningTaskId = launchState.launchedToTaskId; |
| 327 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 328 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 329 | loader.loadTasks(this, loadPlan, loadOpts); |
| 330 | TaskStack stack = loadPlan.getTaskStack(); |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 331 | mRecentsView.onResume(mIsVisible, false /* multiWindowChange */, stack); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 332 | |
| 333 | // Animate the SystemUI scrims into view |
| 334 | Task launchTarget = stack.getLaunchTarget(); |
| 335 | int taskCount = stack.getTaskCount(); |
| 336 | int launchTaskIndexInStack = launchTarget != null |
| 337 | ? stack.indexOfStackTask(launchTarget) |
| 338 | : 0; |
| 339 | boolean hasNavBarScrim = (taskCount > 0) && !config.hasTransposedNavBar; |
| 340 | boolean animateNavBarScrim = !launchState.launchedWhileDocking; |
| 341 | mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim); |
| 342 | |
| 343 | // If this is a new instance from a configuration change, then we have to manually trigger |
| 344 | // the enter animation state, or if recents was relaunched by AM, without going through |
| 345 | // the normal mechanisms |
| 346 | boolean wasLaunchedByAm = !launchState.launchedFromHome && |
| 347 | !launchState.launchedFromApp; |
| 348 | if (launchState.launchedHasConfigurationChanged || wasLaunchedByAm) { |
| 349 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
| 350 | } |
| 351 | |
| 352 | mRecentsView.getViewTreeObserver().addOnPreDrawListener( |
| 353 | new ViewTreeObserver.OnPreDrawListener() { |
| 354 | |
| 355 | @Override |
| 356 | public boolean onPreDraw() { |
| 357 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 358 | EventBus.getDefault().post(new RecentsDrawnEvent()); |
| 359 | return true; |
| 360 | } |
| 361 | }); |
| 362 | |
| 363 | // Keep track of whether we launched from the nav bar button or via alt-tab |
| 364 | if (launchState.launchedWithAltTab) { |
| 365 | MetricsLogger.count(this, "overview_trigger_alttab", 1); |
| 366 | } else { |
| 367 | MetricsLogger.count(this, "overview_trigger_nav_btn", 1); |
| 368 | } |
| 369 | |
| 370 | // Keep track of whether we launched from an app or from home |
| 371 | if (launchState.launchedFromApp) { |
| 372 | MetricsLogger.count(this, "overview_source_app", 1); |
| 373 | // If from an app, track the stack index of the app in the stack (for affiliated tasks) |
| 374 | MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack); |
| 375 | } else { |
| 376 | MetricsLogger.count(this, "overview_source_home", 1); |
| 377 | } |
| 378 | |
| 379 | // Keep track of the total stack task count |
| 380 | MetricsLogger.histogram(this, "overview_task_count", taskCount); |
| 381 | |
| 382 | // After we have resumed, set the visible state until the next onStop() call |
| 383 | mIsVisible = true; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 387 | protected void onPause() { |
| 388 | super.onPause(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 389 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 390 | mIgnoreAltTabRelease = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 391 | mIterateTrigger.stopDozing(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 392 | } |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 393 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 394 | @Override |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 395 | public void onConfigurationChanged(Configuration newConfig) { |
| 396 | super.onConfigurationChanged(newConfig); |
| 397 | |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 398 | EventBus.getDefault().send(new ConfigurationChangedEvent()); |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 402 | protected void onStop() { |
| 403 | super.onStop(); |
| 404 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 405 | // Notify that recents is now hidden |
| 406 | mIsVisible = false; |
| 407 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, false)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 408 | MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Winson | 73492c5 | 2016-03-09 17:44:54 -0800 | [diff] [blame] | 409 | |
| 410 | // Workaround for b/22542869, if the RecentsActivity is started again, but without going |
| 411 | // through SystemUI, we need to reset the config launch flags to ensure that we do not |
| 412 | // wait on the system to send a signal that was never queued. |
| 413 | RecentsConfiguration config = Recents.getConfiguration(); |
| 414 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 415 | launchState.reset(); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | @Override |
| 419 | protected void onDestroy() { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 420 | super.onDestroy(); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 421 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 422 | // In the case that the activity finished on startup, just skip the unregistration below |
| 423 | if (mFinishedOnStartup) { |
| 424 | return; |
| 425 | } |
| 426 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 427 | // Unregister the system broadcast receivers |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 428 | unregisterReceiver(mSystemBroadcastReceiver); |
Winson Chung | 905950a | 2014-09-17 09:25:27 +0200 | [diff] [blame] | 429 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 430 | // Unregister any broadcast receivers for the task loader |
| 431 | mPackageMonitor.unregister(); |
| 432 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 433 | EventBus.getDefault().unregister(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 436 | @Override |
| 437 | public void onAttachedToWindow() { |
| 438 | super.onAttachedToWindow(); |
| 439 | EventBus.getDefault().register(mScrimViews, EVENT_BUS_PRIORITY); |
| 440 | } |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 441 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 442 | @Override |
| 443 | public void onDetachedFromWindow() { |
| 444 | super.onDetachedFromWindow(); |
| 445 | EventBus.getDefault().unregister(mScrimViews); |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Override |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 449 | public void onTrimMemory(int level) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 450 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 451 | if (loader != null) { |
| 452 | loader.onTrimMemory(level); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | @Override |
Wale Ogunwale | 3b93a4d | 2016-01-29 17:46:53 -0800 | [diff] [blame] | 457 | public void onMultiWindowChanged(boolean inMultiWindow) { |
| 458 | super.onMultiWindowChanged(inMultiWindow); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 459 | EventBus.getDefault().send(new ConfigurationChangedEvent()); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 460 | |
| 461 | // Reload the task stack completely |
| 462 | RecentsConfiguration config = Recents.getConfiguration(); |
| 463 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 464 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 931845f | 2016-02-24 19:38:41 -0800 | [diff] [blame] | 465 | RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 466 | loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */); |
| 467 | |
| 468 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 469 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 470 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 471 | loader.loadTasks(this, loadPlan, loadOpts); |
| 472 | |
Winson | 59924fe | 2016-03-17 14:13:18 -0700 | [diff] [blame] | 473 | mRecentsView.onResume(mIsVisible, true /* multiWindowChange */, loadPlan.getTaskStack()); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 474 | |
| 475 | EventBus.getDefault().send(new MultiWindowStateChangedEvent(inMultiWindow)); |
Winson Chung | 0626677 | 2015-12-11 10:24:21 -0500 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Override |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 479 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 480 | switch (keyCode) { |
| 481 | case KeyEvent.KEYCODE_TAB: { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 482 | int altTabKeyDelay = getResources().getInteger(R.integer.recents_alt_tab_key_delay); |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 483 | boolean hasRepKeyTimeElapsed = (SystemClock.elapsedRealtime() - |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 484 | mLastTabKeyEventTime) > altTabKeyDelay; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 485 | if (event.getRepeatCount() <= 0 || hasRepKeyTimeElapsed) { |
| 486 | // Focus the next task in the stack |
| 487 | final boolean backward = event.isShiftPressed(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 488 | if (backward) { |
| 489 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
| 490 | } else { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 491 | EventBus.getDefault().send( |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 492 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 493 | } |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 494 | mLastTabKeyEventTime = SystemClock.elapsedRealtime(); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 495 | |
| 496 | // In the case of another ALT event, don't ignore the next release |
| 497 | if (event.isAltPressed()) { |
| 498 | mIgnoreAltTabRelease = false; |
| 499 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 500 | } |
| 501 | return true; |
| 502 | } |
| 503 | case KeyEvent.KEYCODE_DPAD_UP: { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 504 | EventBus.getDefault().send( |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 505 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 506 | return true; |
| 507 | } |
| 508 | case KeyEvent.KEYCODE_DPAD_DOWN: { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 509 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 510 | return true; |
| 511 | } |
| 512 | case KeyEvent.KEYCODE_DEL: |
| 513 | case KeyEvent.KEYCODE_FORWARD_DEL: { |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 514 | if (event.getRepeatCount() <= 0) { |
| 515 | EventBus.getDefault().send(new DismissFocusedTaskViewEvent()); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 516 | |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 517 | // Keep track of deletions by keyboard |
| 518 | MetricsLogger.histogram(this, "overview_task_dismissed_source", |
| 519 | Constants.Metrics.DismissSourceKeyboard); |
| 520 | return true; |
| 521 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 522 | } |
| 523 | default: |
| 524 | break; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 525 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 526 | return super.onKeyDown(keyCode, event); |
| 527 | } |
| 528 | |
| 529 | @Override |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 530 | public void onUserInteraction() { |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 531 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 535 | public void onBackPressed() { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 536 | // Back behaves like the recents button so just trigger a toggle event |
| 537 | EventBus.getDefault().send(new ToggleRecentsEvent()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 538 | } |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 539 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 540 | /**** EventBus events ****/ |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 541 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 542 | public final void onBusEvent(ToggleRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 543 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 544 | if (launchState.launchedFromHome) { |
| 545 | dismissRecentsToHome(true /* animateTaskViews */); |
| 546 | } else { |
| 547 | dismissRecentsToLaunchTargetTaskOrHome(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 548 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 551 | public final void onBusEvent(IterateRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 552 | final RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 553 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 554 | // Start dozing after the recents button is clicked |
| 555 | int timerIndicatorDuration = 0; |
| 556 | if (debugFlags.isFastToggleRecentsEnabled()) { |
| 557 | timerIndicatorDuration = getResources().getInteger( |
| 558 | R.integer.recents_subsequent_auto_advance_duration); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 559 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 560 | mIterateTrigger.setDozeDuration(timerIndicatorDuration); |
| 561 | if (!mIterateTrigger.isDozing()) { |
| 562 | mIterateTrigger.startDozing(); |
| 563 | } else { |
| 564 | mIterateTrigger.poke(); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 567 | |
| 568 | // Focus the next task |
| 569 | EventBus.getDefault().send(new FocusNextTaskViewEvent(timerIndicatorDuration)); |
| 570 | |
| 571 | MetricsLogger.action(this, MetricsEvent.ACTION_OVERVIEW_PAGE); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | public final void onBusEvent(UserInteractionEvent event) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 575 | // Stop the fast-toggle dozer |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 576 | mIterateTrigger.stopDozing(); |
| 577 | } |
| 578 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 579 | public final void onBusEvent(HideRecentsEvent event) { |
| 580 | if (event.triggeredFromAltTab) { |
| 581 | // If we are hiding from releasing Alt-Tab, dismiss Recents to the focused app |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 582 | if (!mIgnoreAltTabRelease) { |
| 583 | dismissRecentsToFocusedTaskOrHome(); |
| 584 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 585 | } else if (event.triggeredFromHomeKey) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 586 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 587 | |
| 588 | // Cancel any pending dozes |
| 589 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 590 | } else { |
| 591 | // Do nothing |
| 592 | } |
| 593 | } |
| 594 | |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 595 | public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 596 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(true)); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 597 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 598 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 601 | public final void onBusEvent(ExitRecentsWindowFirstAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 602 | if (mRecentsView.isLastTaskLaunchedFreeform()) { |
| 603 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(false)); |
| 604 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 605 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 606 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 609 | public final void onBusEvent(DockedFirstAnimationFrameEvent event) { |
| 610 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
| 611 | mRecentsView.invalidate(); |
| 612 | } |
| 613 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 614 | public final void onBusEvent(CancelEnterRecentsWindowAnimationEvent event) { |
| 615 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 616 | int launchToTaskId = launchState.launchedToTaskId; |
| 617 | if (launchToTaskId != -1 && |
| 618 | (event.launchTask == null || launchToTaskId != event.launchTask.key.id)) { |
| 619 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 620 | ssp.cancelWindowTransition(launchState.launchedToTaskId); |
| 621 | ssp.cancelThumbnailTransition(getTaskId()); |
| 622 | } |
| 623 | } |
| 624 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 625 | public final void onBusEvent(ShowApplicationInfoEvent event) { |
| 626 | // Create a new task stack with the application info details activity |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 627 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 628 | Uri.fromParts("package", event.task.key.getComponent().getPackageName(), null)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 629 | intent.setComponent(intent.resolveActivity(getPackageManager())); |
| 630 | TaskStackBuilder.create(this) |
| 631 | .addNextIntentWithParentStack(intent).startActivities(null, |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 632 | new UserHandle(event.task.key.userId)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 633 | |
| 634 | // Keep track of app-info invocations |
| 635 | MetricsLogger.count(this, "overview_app_info", 1); |
| 636 | } |
| 637 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 638 | public final void onBusEvent(DeleteTaskDataEvent event) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 639 | // Remove any stored data from the loader |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 640 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 641 | loader.deleteTaskData(event.task, false); |
| 642 | |
| 643 | // Remove the task from activity manager |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 644 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 645 | ssp.removeTask(event.task.key.id); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 648 | public final void onBusEvent(AllTaskViewsDismissedEvent event) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 649 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 650 | if (ssp.hasDockedTask()) { |
Winson | 2068408 | 2016-03-16 17:13:34 -0700 | [diff] [blame] | 651 | mRecentsView.showEmptyView(event.msgResId); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 652 | } else { |
| 653 | // Just go straight home (no animation necessary because there are no more task views) |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 654 | dismissRecentsToHome(false /* animateTaskViews */); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 655 | } |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 656 | |
| 657 | // Keep track of all-deletions |
| 658 | MetricsLogger.count(this, "overview_task_all_dismissed", 1); |
| 659 | } |
| 660 | |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 661 | public final void onBusEvent(LaunchTaskSucceededEvent event) { |
| 662 | MetricsLogger.histogram(this, "overview_task_launch_index", event.taskIndexFromStackFront); |
| 663 | } |
| 664 | |
| 665 | public final void onBusEvent(LaunchTaskFailedEvent event) { |
| 666 | // Return to Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 667 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 668 | |
| 669 | MetricsLogger.count(this, "overview_task_launch_failed", 1); |
| 670 | } |
| 671 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 672 | public final void onBusEvent(ScreenPinningRequestEvent event) { |
| 673 | MetricsLogger.count(this, "overview_screen_pinned", 1); |
| 674 | } |
| 675 | |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 676 | public final void onBusEvent(DebugFlagsChangedEvent event) { |
| 677 | // Just finish recents so that we can reload the flags anew on the next instantiation |
| 678 | finish(); |
| 679 | } |
| 680 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 681 | public final void onBusEvent(StackViewScrolledEvent event) { |
| 682 | // Once the user has scrolled while holding alt-tab, then we should ignore the release of |
| 683 | // the key |
| 684 | mIgnoreAltTabRelease = true; |
| 685 | } |
| 686 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 687 | @Override |
| 688 | public boolean onPreDraw() { |
| 689 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 690 | // We post to make sure that this information is delivered after this traversals is |
| 691 | // finished. |
| 692 | mRecentsView.post(new Runnable() { |
| 693 | @Override |
| 694 | public void run() { |
| 695 | Recents.getSystemServices().endProlongedAnimations(); |
| 696 | } |
| 697 | }); |
| 698 | return true; |
| 699 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 700 | } |