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 | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 20 | import android.app.ActivityManager; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 21 | import android.app.ActivityOptions; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 22 | import android.app.TaskStackBuilder; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 26 | import android.content.IntentFilter; |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 29 | import android.os.Bundle; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 30 | import android.os.Handler; |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 31 | import android.os.SystemClock; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 32 | import android.os.UserHandle; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 33 | import android.provider.Settings; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 34 | import android.util.Log; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 35 | import android.view.KeyEvent; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 36 | import android.view.View; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 37 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 38 | import android.view.ViewTreeObserver.OnPreDrawListener; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 39 | import android.view.WindowManager; |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 40 | import android.view.WindowManager.LayoutParams; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 41 | |
Winson Chung | 5c9f4b9 | 2015-06-25 16:16:46 -0700 | [diff] [blame] | 42 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 43 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 44 | import com.android.systemui.Interpolators; |
Winson | 6976f7b | 2016-05-03 14:58:12 -0700 | [diff] [blame] | 45 | import com.android.systemui.Prefs; |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 46 | import com.android.systemui.R; |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 47 | import com.android.systemui.recents.events.EventBus; |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 48 | import com.android.systemui.recents.events.activity.CancelEnterRecentsWindowAnimationEvent; |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 49 | import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 50 | import com.android.systemui.recents.events.activity.DebugFlagsChangedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 51 | import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 52 | import com.android.systemui.recents.events.activity.DockedFirstAnimationFrameEvent; |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 53 | import com.android.systemui.recents.events.activity.DockedTopTaskEvent; |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 54 | import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 55 | import com.android.systemui.recents.events.activity.EnterRecentsWindowLastAnimationFrameEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 56 | import com.android.systemui.recents.events.activity.ExitRecentsWindowFirstAnimationFrameEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 57 | import com.android.systemui.recents.events.activity.HideRecentsEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 58 | import com.android.systemui.recents.events.activity.IterateRecentsEvent; |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 59 | import com.android.systemui.recents.events.activity.LaunchTaskFailedEvent; |
| 60 | import com.android.systemui.recents.events.activity.LaunchTaskSucceededEvent; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 61 | import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 62 | import com.android.systemui.recents.events.activity.ToggleRecentsEvent; |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 63 | import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent; |
| 64 | import com.android.systemui.recents.events.component.ScreenPinningRequestEvent; |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 65 | import com.android.systemui.recents.events.ui.AllTaskViewsDismissedEvent; |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 66 | import com.android.systemui.recents.events.ui.DeleteTaskDataEvent; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 67 | import com.android.systemui.recents.events.ui.HideIncompatibleAppOverlayEvent; |
Jorim Jaggi | 11cc01d | 2016-01-22 19:39:23 -0800 | [diff] [blame] | 68 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.events.ui.ShowApplicationInfoEvent; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 70 | import com.android.systemui.recents.events.ui.ShowIncompatibleAppOverlayEvent; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 71 | import com.android.systemui.recents.events.ui.StackViewScrolledEvent; |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 72 | import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent; |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 73 | import com.android.systemui.recents.events.ui.UserInteractionEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 74 | import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent; |
| 75 | import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent; |
| 76 | import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 77 | import com.android.systemui.recents.misc.DozeTrigger; |
Winson Chung | ffa2ec6 | 2014-07-03 15:54:42 -0700 | [diff] [blame] | 78 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 79 | import com.android.systemui.recents.misc.Utilities; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 80 | import com.android.systemui.recents.model.RecentsPackageMonitor; |
Winson Chung | a91c293 | 2014-11-07 15:02:38 -0800 | [diff] [blame] | 81 | import com.android.systemui.recents.model.RecentsTaskLoadPlan; |
Winson Chung | f1fbd77 | 2014-06-24 18:06:58 -0700 | [diff] [blame] | 82 | import com.android.systemui.recents.model.RecentsTaskLoader; |
Winson Chung | dcfa797 | 2014-07-22 12:27:13 -0700 | [diff] [blame] | 83 | import com.android.systemui.recents.model.Task; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 84 | import com.android.systemui.recents.model.TaskStack; |
| 85 | import com.android.systemui.recents.views.RecentsView; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 86 | import com.android.systemui.recents.views.SystemBarScrimViews; |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 87 | import com.android.systemui.statusbar.BaseStatusBar; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 88 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 89 | import java.io.FileDescriptor; |
| 90 | import java.io.PrintWriter; |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 91 | import java.util.List; |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 92 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 93 | /** |
Winson | 27c28f8 | 2016-05-05 16:16:50 -0700 | [diff] [blame] | 94 | * The main Recents activity that is started from RecentsComponent. |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 95 | */ |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 96 | public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreDrawListener { |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 97 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 98 | private final static String TAG = "RecentsActivity"; |
| 99 | private final static boolean DEBUG = false; |
| 100 | |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 101 | public final static int EVENT_BUS_PRIORITY = Recents.EVENT_BUS_PRIORITY + 1; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 102 | public final static int INCOMPATIBLE_APP_ALPHA_DURATION = 150; |
Winson | e6c9073 | 2015-09-24 16:06:29 -0700 | [diff] [blame] | 103 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 104 | private RecentsPackageMonitor mPackageMonitor; |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 105 | private Handler mHandler = new Handler(); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 106 | private long mLastTabKeyEventTime; |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 107 | private int mLastDeviceOrientation = Configuration.ORIENTATION_UNDEFINED; |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 108 | private int mLastDisplayDensity; |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 109 | private boolean mFinishedOnStartup; |
| 110 | private boolean mIgnoreAltTabRelease; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 111 | private boolean mIsVisible; |
Winson | 449a4e2 | 2016-05-11 14:29:33 -0700 | [diff] [blame] | 112 | private boolean mReceivedNewIntent; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 113 | |
| 114 | // Top level views |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 115 | private RecentsView mRecentsView; |
| 116 | private SystemBarScrimViews mScrimViews; |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 117 | private View mIncompatibleAppOverlay; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 118 | |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 119 | // Runnables to finish the Recents activity |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 120 | private Intent mHomeIntent; |
Winson Chung | cdbbb7e | 2014-06-24 12:11:49 -0700 | [diff] [blame] | 121 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 122 | // The trigger to automatically launch the current task |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 123 | private int mFocusTimerDuration; |
| 124 | private DozeTrigger mIterateTrigger; |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 125 | private final UserInteractionEvent mUserInteractionEvent = new UserInteractionEvent(); |
Winson | 449a4e2 | 2016-05-11 14:29:33 -0700 | [diff] [blame] | 126 | private final Runnable mSendEnterWindowAnimationCompleteRunnable = () -> { |
| 127 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
| 128 | }; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 129 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 130 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 131 | * 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] | 132 | * 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] | 133 | * 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] | 134 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 135 | class LaunchHomeRunnable implements Runnable { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 136 | |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 137 | Intent mLaunchIntent; |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 138 | ActivityOptions mOpts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 139 | |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 140 | /** |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 141 | * Creates a finish runnable that starts the specified intent. |
Winson Chung | d7b2cb1 | 2014-06-26 15:08:50 -0700 | [diff] [blame] | 142 | */ |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 143 | public LaunchHomeRunnable(Intent launchIntent, ActivityOptions opts) { |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 144 | mLaunchIntent = launchIntent; |
Winson | 40a2273 | 2016-02-02 18:07:00 -0800 | [diff] [blame] | 145 | mOpts = opts; |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void run() { |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 150 | try { |
Winson | 3f32e7e | 2016-04-20 17:18:08 -0700 | [diff] [blame] | 151 | mHandler.post(() -> { |
| 152 | ActivityOptions opts = mOpts; |
| 153 | if (opts == null) { |
| 154 | opts = ActivityOptions.makeCustomAnimation(RecentsActivity.this, |
| 155 | R.anim.recents_to_launcher_enter, R.anim.recents_to_launcher_exit); |
| 156 | } |
| 157 | startActivityAsUser(mLaunchIntent, opts.toBundle(), UserHandle.CURRENT); |
| 158 | }); |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 159 | } catch (Exception e) { |
Winson | 1b58561 | 2015-11-06 09:16:26 -0800 | [diff] [blame] | 160 | Log.e(TAG, getString(R.string.recents_launch_error_message, "Home"), e); |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 165 | /** |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 166 | * Broadcast receiver to handle messages from the system |
| 167 | */ |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 168 | final BroadcastReceiver mSystemBroadcastReceiver = new BroadcastReceiver() { |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 169 | @Override |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 170 | public void onReceive(Context ctx, Intent intent) { |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 171 | String action = intent.getAction(); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 172 | if (action.equals(Intent.ACTION_SCREEN_OFF)) { |
| 173 | // When the screen turns off, dismiss Recents to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 174 | dismissRecentsToHomeIfVisible(false); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 175 | } else if (action.equals(Intent.ACTION_TIME_CHANGED)) { |
Winson | a4fab41 | 2016-09-15 16:28:22 -0700 | [diff] [blame] | 176 | // If the time shifts but the currentTime >= lastStackActiveTime, then that boundary |
| 177 | // is still valid. Otherwise, we need to reset the lastStackactiveTime to the |
| 178 | // currentTime and remove the old tasks in between which would not be previously |
| 179 | // visible, but currently would be in the new currentTime |
| 180 | long oldLastStackActiveTime = Prefs.getLong(RecentsActivity.this, |
| 181 | Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1); |
| 182 | if (oldLastStackActiveTime != -1) { |
| 183 | long currentTime = System.currentTimeMillis(); |
| 184 | if (currentTime < oldLastStackActiveTime) { |
| 185 | // We are only removing tasks that are between the new current time |
| 186 | // and the old last stack active time, they were not visible and in the |
| 187 | // TaskStack so we don't need to remove any associated TaskViews but we do |
| 188 | // need to load the task id's from the system |
| 189 | RecentsTaskLoadPlan loadPlan = Recents.getTaskLoader().createLoadPlan(ctx); |
| 190 | loadPlan.preloadRawTasks(false /* includeFrontMostExcludedTask */); |
| 191 | List<ActivityManager.RecentTaskInfo> tasks = loadPlan.getRawTasks(); |
| 192 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 193 | ActivityManager.RecentTaskInfo task = tasks.get(i); |
| 194 | if (currentTime <= task.lastActiveTime && task.lastActiveTime < |
| 195 | oldLastStackActiveTime) { |
| 196 | Recents.getSystemServices().removeTask(task.persistentId); |
| 197 | } |
| 198 | } |
| 199 | Prefs.putLong(RecentsActivity.this, |
| 200 | Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, currentTime); |
| 201 | } |
| 202 | } |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 203 | } |
Winson Chung | d42a6cf | 2014-06-03 16:24:04 -0700 | [diff] [blame] | 204 | } |
| 205 | }; |
| 206 | |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 207 | private final OnPreDrawListener mRecentsDrawnEventListener = |
| 208 | new ViewTreeObserver.OnPreDrawListener() { |
| 209 | @Override |
| 210 | public boolean onPreDraw() { |
| 211 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 212 | EventBus.getDefault().post(new RecentsDrawnEvent()); |
| 213 | return true; |
| 214 | } |
| 215 | }; |
| 216 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 217 | /** |
| 218 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 219 | */ |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 220 | boolean dismissRecentsToFocusedTask(int logCategory) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 221 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 222 | if (ssp.isRecentsActivityVisible()) { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 223 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 224 | if (mRecentsView.launchFocusedTask(logCategory)) return true; |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 225 | } |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | /** |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 230 | * Dismisses recents back to the launch target task. |
| 231 | */ |
| 232 | boolean dismissRecentsToLaunchTargetTaskOrHome() { |
| 233 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 234 | if (ssp.isRecentsActivityVisible()) { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 235 | // If we have a focused Task, launch that Task now |
| 236 | if (mRecentsView.launchPreviousTask()) return true; |
| 237 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 238 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 239 | } |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | /** |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 244 | * Dismisses recents if we are already visible and the intent is to toggle the recents view. |
| 245 | */ |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 246 | boolean dismissRecentsToFocusedTaskOrHome() { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 247 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 248 | if (ssp.isRecentsActivityVisible()) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 249 | // If we have a focused Task, launch that Task now |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 250 | if (mRecentsView.launchFocusedTask(0 /* logCategory */)) return true; |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 251 | // If none of the other cases apply, then just go Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 252 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 258 | /** |
| 259 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 260 | */ |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 261 | void dismissRecentsToHome(boolean animateTaskViews) { |
Winson | 49df420 | 2016-01-25 17:33:34 -0800 | [diff] [blame] | 262 | dismissRecentsToHome(animateTaskViews, null); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Dismisses Recents directly to Home without checking whether it is currently visible. |
| 267 | * |
| 268 | * @param overrideAnimation If not null, will override the default animation that is based on |
| 269 | * how Recents was launched. |
| 270 | */ |
| 271 | void dismissRecentsToHome(boolean animateTaskViews, ActivityOptions overrideAnimation) { |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 272 | DismissRecentsToHomeAnimationStarted dismissEvent = |
| 273 | new DismissRecentsToHomeAnimationStarted(animateTaskViews); |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 274 | dismissEvent.addPostAnimationCallback(new LaunchHomeRunnable(mHomeIntent, |
| 275 | overrideAnimation)); |
Winson | 3ca1028 | 2016-04-21 15:20:21 -0700 | [diff] [blame] | 276 | Recents.getSystemServices().sendCloseSystemWindows( |
| 277 | BaseStatusBar.SYSTEM_DIALOG_REASON_HOME_KEY); |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 278 | EventBus.getDefault().send(dismissEvent); |
Wale Ogunwale | d351ada | 2015-04-04 11:53:14 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 281 | /** Dismisses Recents directly to Home if we currently aren't transitioning. */ |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 282 | boolean dismissRecentsToHomeIfVisible(boolean animated) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 283 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 284 | if (ssp.isRecentsActivityVisible()) { |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 285 | // Return to Home |
Winson | 2b9c1d3 | 2015-10-05 15:44:23 -0700 | [diff] [blame] | 286 | dismissRecentsToHome(animated); |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 287 | return true; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 288 | } |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | /** Called with the activity is first created. */ |
| 293 | @Override |
| 294 | public void onCreate(Bundle savedInstanceState) { |
| 295 | super.onCreate(savedInstanceState); |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 296 | mFinishedOnStartup = false; |
| 297 | |
| 298 | // In the case that the activity starts up before the Recents component has initialized |
| 299 | // (usually when debugging/pushing the SysUI apk), just finish this activity. |
| 300 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 301 | if (ssp == null) { |
| 302 | mFinishedOnStartup = true; |
| 303 | finish(); |
| 304 | return; |
| 305 | } |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 306 | |
| 307 | // Register this activity with the event bus |
| 308 | EventBus.getDefault().register(this, EVENT_BUS_PRIORITY); |
| 309 | |
Winson | 008ee15f | 2016-03-18 17:17:25 -0700 | [diff] [blame] | 310 | // Initialize the package monitor |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 311 | mPackageMonitor = new RecentsPackageMonitor(); |
| 312 | mPackageMonitor.register(this); |
Winson Chung | f7bca43 | 2014-04-30 17:11:13 -0700 | [diff] [blame] | 313 | |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 314 | // Set the Recents layout |
| 315 | setContentView(R.layout.recents); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 316 | takeKeyEvents(true); |
Winson Chung | 8e548f7 | 2014-06-24 14:40:53 -0700 | [diff] [blame] | 317 | mRecentsView = (RecentsView) findViewById(R.id.recents_view); |
Winson Chung | 653f70c2 | 2014-05-19 14:49:42 -0700 | [diff] [blame] | 318 | mRecentsView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | |
| 319 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | |
| 320 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 321 | mScrimViews = new SystemBarScrimViews(this); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 322 | getWindow().getAttributes().privateFlags |= |
| 323 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 324 | |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 325 | Configuration appConfiguration = Utilities.getAppConfiguration(this); |
| 326 | mLastDeviceOrientation = appConfiguration.orientation; |
| 327 | mLastDisplayDensity = appConfiguration.densityDpi; |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 328 | mFocusTimerDuration = getResources().getInteger(R.integer.recents_auto_advance_duration); |
| 329 | mIterateTrigger = new DozeTrigger(mFocusTimerDuration, new Runnable() { |
| 330 | @Override |
| 331 | public void run() { |
Winson | 4232952 | 2016-02-05 10:39:46 -0800 | [diff] [blame] | 332 | dismissRecentsToFocusedTask(MetricsEvent.OVERVIEW_SELECT_TIMEOUT); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 333 | } |
| 334 | }); |
| 335 | |
Winson | e8a4eff | 2016-03-28 16:20:35 -0700 | [diff] [blame] | 336 | // Set the window background |
| 337 | getWindow().setBackgroundDrawable(mRecentsView.getBackgroundScrim()); |
| 338 | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 339 | // Create the home intent runnable |
Winson | e693aaf | 2016-03-01 12:05:59 -0800 | [diff] [blame] | 340 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 341 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 342 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 343 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 344 | |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 345 | // Register the broadcast receiver to handle messages when the screen is turned off |
| 346 | IntentFilter filter = new IntentFilter(); |
| 347 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 348 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 349 | registerReceiver(mSystemBroadcastReceiver, filter); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 350 | |
| 351 | getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 352 | |
| 353 | // Reload the stack view |
| 354 | reloadStackView(); |
Winson Chung | 521e7dc | 2014-06-02 15:31:56 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 357 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 358 | protected void onStart() { |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 359 | super.onStart(); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 360 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 361 | // Notify that recents is now visible |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 362 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, true)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 363 | MetricsLogger.visible(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Jorim Jaggi | d6a3949 | 2016-04-25 17:31:22 -0700 | [diff] [blame] | 364 | |
| 365 | // Notify of the next draw |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 366 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener); |
Winson Chung | 6736905 | 2014-04-07 17:35:48 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | @Override |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 370 | protected void onNewIntent(Intent intent) { |
| 371 | super.onNewIntent(intent); |
Winson | 449a4e2 | 2016-05-11 14:29:33 -0700 | [diff] [blame] | 372 | mReceivedNewIntent = true; |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 373 | |
| 374 | // Reload the stack view |
| 375 | reloadStackView(); |
Winson | 3fb6756 | 2015-11-11 10:39:03 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 378 | /** |
| 379 | * Reloads the stack views upon launching Recents. |
| 380 | */ |
| 381 | private void reloadStackView() { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 382 | // If the Recents component has preloaded a load plan, then use that to prevent |
| 383 | // reconstructing the task stack |
| 384 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 385 | RecentsTaskLoadPlan loadPlan = RecentsImpl.consumeInstanceLoadPlan(); |
| 386 | if (loadPlan == null) { |
| 387 | loadPlan = loader.createLoadPlan(this); |
| 388 | } |
| 389 | |
| 390 | // Start loading tasks according to the load plan |
| 391 | RecentsConfiguration config = Recents.getConfiguration(); |
| 392 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 393 | if (!loadPlan.hasTasks()) { |
Winson | 96e6134 | 2016-03-15 16:47:19 -0700 | [diff] [blame] | 394 | loader.preloadTasks(loadPlan, launchState.launchedToTaskId, |
Yoshinori Hirano | 7bccd43 | 2016-11-21 15:42:20 +0900 | [diff] [blame] | 395 | !launchState.launchedFromHome && !launchState.launchedViaDockGesture); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 399 | loadOpts.runningTaskId = launchState.launchedToTaskId; |
| 400 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 401 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 402 | loader.loadTasks(this, loadPlan, loadOpts); |
| 403 | TaskStack stack = loadPlan.getTaskStack(); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 404 | mRecentsView.onReload(mIsVisible, stack.getTaskCount() == 0); |
Winson | d2a0306 | 2016-04-15 11:19:07 -0700 | [diff] [blame] | 405 | mRecentsView.updateStack(stack, true /* setStackViewTasks */); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 406 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 407 | // Update the nav bar scrim, but defer the animation until the enter-window event |
Winson | c69249f | 2016-03-28 13:38:39 -0700 | [diff] [blame] | 408 | boolean animateNavBarScrim = !launchState.launchedViaDockGesture; |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 409 | mScrimViews.updateNavBarScrim(animateNavBarScrim, stack.getTaskCount() > 0, null); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 410 | |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 411 | // If this is a new instance relaunched by AM, without going through the normal mechanisms, |
| 412 | // then we have to manually trigger the enter animation state |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 413 | boolean wasLaunchedByAm = !launchState.launchedFromHome && |
| 414 | !launchState.launchedFromApp; |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 415 | if (wasLaunchedByAm) { |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 416 | EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); |
| 417 | } |
| 418 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 419 | // Keep track of whether we launched from the nav bar button or via alt-tab |
| 420 | if (launchState.launchedWithAltTab) { |
| 421 | MetricsLogger.count(this, "overview_trigger_alttab", 1); |
| 422 | } else { |
| 423 | MetricsLogger.count(this, "overview_trigger_nav_btn", 1); |
| 424 | } |
| 425 | |
| 426 | // Keep track of whether we launched from an app or from home |
| 427 | if (launchState.launchedFromApp) { |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 428 | Task launchTarget = stack.getLaunchTarget(); |
| 429 | int launchTaskIndexInStack = launchTarget != null |
| 430 | ? stack.indexOfStackTask(launchTarget) |
| 431 | : 0; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 432 | MetricsLogger.count(this, "overview_source_app", 1); |
| 433 | // If from an app, track the stack index of the app in the stack (for affiliated tasks) |
| 434 | MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack); |
| 435 | } else { |
| 436 | MetricsLogger.count(this, "overview_source_home", 1); |
| 437 | } |
| 438 | |
| 439 | // Keep track of the total stack task count |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 440 | int taskCount = mRecentsView.getStack().getTaskCount(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 441 | MetricsLogger.histogram(this, "overview_task_count", taskCount); |
| 442 | |
| 443 | // After we have resumed, set the visible state until the next onStop() call |
| 444 | mIsVisible = true; |
Jorim Jaggi | 6e18e00 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | @Override |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 448 | public void onEnterAnimationComplete() { |
| 449 | super.onEnterAnimationComplete(); |
Winson | 449a4e2 | 2016-05-11 14:29:33 -0700 | [diff] [blame] | 450 | |
| 451 | // Workaround for b/28705801, on first docking, we may receive the enter animation callback |
| 452 | // before the first layout, so in such cases, send the event on the next frame after all |
| 453 | // the views are laid out and attached (and registered to the EventBus). |
| 454 | mHandler.removeCallbacks(mSendEnterWindowAnimationCompleteRunnable); |
| 455 | if (!mReceivedNewIntent) { |
| 456 | mHandler.post(mSendEnterWindowAnimationCompleteRunnable); |
| 457 | } else { |
| 458 | mSendEnterWindowAnimationCompleteRunnable.run(); |
| 459 | } |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 463 | protected void onPause() { |
| 464 | super.onPause(); |
Winson | 190fe3bf | 2015-10-20 14:57:24 -0700 | [diff] [blame] | 465 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 466 | mIgnoreAltTabRelease = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 467 | mIterateTrigger.stopDozing(); |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 468 | } |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 469 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 470 | @Override |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 471 | public void onConfigurationChanged(Configuration newConfig) { |
| 472 | super.onConfigurationChanged(newConfig); |
| 473 | |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 474 | // Notify of the config change |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 475 | Configuration newDeviceConfiguration = Utilities.getAppConfiguration(this); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 476 | int numStackTasks = mRecentsView.getStack().getStackTaskCount(); |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 477 | EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */, |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 478 | mLastDeviceOrientation != newDeviceConfiguration.orientation, |
| 479 | mLastDisplayDensity != newDeviceConfiguration.densityDpi, numStackTasks > 0)); |
| 480 | mLastDeviceOrientation = newDeviceConfiguration.orientation; |
| 481 | mLastDisplayDensity = newDeviceConfiguration.densityDpi; |
Winson | a180985 | 2016-03-15 11:41:37 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 485 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
| 486 | super.onMultiWindowModeChanged(isInMultiWindowMode); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 487 | |
| 488 | // Reload the task stack completely |
| 489 | RecentsConfiguration config = Recents.getConfiguration(); |
| 490 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 491 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
| 492 | RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); |
Winson | dfd7be0 | 2016-05-10 13:30:37 -0700 | [diff] [blame] | 493 | loader.preloadTasks(loadPlan, -1 /* runningTaskId */, |
| 494 | false /* includeFrontMostExcludedTask */); |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 495 | |
| 496 | RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); |
| 497 | loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; |
| 498 | loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; |
| 499 | loader.loadTasks(this, loadPlan, loadOpts); |
| 500 | |
| 501 | TaskStack stack = loadPlan.getTaskStack(); |
| 502 | int numStackTasks = stack.getStackTaskCount(); |
Winson | 95ee873 | 2016-04-26 14:46:58 -0700 | [diff] [blame] | 503 | boolean showDeferredAnimation = numStackTasks > 0; |
Winson | 500ba75 | 2016-03-30 11:59:22 -0700 | [diff] [blame] | 504 | |
Winson | 44849b8 | 2016-03-29 10:45:45 -0700 | [diff] [blame] | 505 | EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */, |
Jorim Jaggi | 25160db | 2016-04-18 16:03:36 -0700 | [diff] [blame] | 506 | false /* fromDeviceOrientationChange */, false /* fromDisplayDensityChange */, |
| 507 | numStackTasks > 0)); |
Winson | 95ee873 | 2016-04-26 14:46:58 -0700 | [diff] [blame] | 508 | EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode, |
| 509 | showDeferredAnimation, stack)); |
Winson | a1ededd | 2016-03-25 12:23:12 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | @Override |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 513 | protected void onStop() { |
| 514 | super.onStop(); |
| 515 | |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 516 | // Notify that recents is now hidden |
| 517 | mIsVisible = false; |
Winson | 449a4e2 | 2016-05-11 14:29:33 -0700 | [diff] [blame] | 518 | mReceivedNewIntent = false; |
Winson | 8873754 | 2016-02-17 13:27:33 -0800 | [diff] [blame] | 519 | EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, false)); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 520 | MetricsLogger.hidden(this, MetricsEvent.OVERVIEW_ACTIVITY); |
Winson | 73492c5 | 2016-03-09 17:44:54 -0800 | [diff] [blame] | 521 | |
Yoshinori Hirano | 7bccd43 | 2016-11-21 15:42:20 +0900 | [diff] [blame] | 522 | if (!isChangingConfigurations()) { |
| 523 | // Workaround for b/22542869, if the RecentsActivity is started again, but without going |
| 524 | // through SystemUI, we need to reset the config launch flags to ensure that we do not |
| 525 | // wait on the system to send a signal that was never queued. |
| 526 | RecentsConfiguration config = Recents.getConfiguration(); |
| 527 | RecentsActivityLaunchState launchState = config.getLaunchState(); |
| 528 | launchState.reset(); |
| 529 | } |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | @Override |
| 533 | protected void onDestroy() { |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 534 | super.onDestroy(); |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 535 | |
Winson | 3150e57 | 2015-10-23 15:07:24 -0700 | [diff] [blame] | 536 | // In the case that the activity finished on startup, just skip the unregistration below |
| 537 | if (mFinishedOnStartup) { |
| 538 | return; |
| 539 | } |
| 540 | |
Winson Chung | 85cfec8 | 2014-07-14 14:16:04 -0700 | [diff] [blame] | 541 | // Unregister the system broadcast receivers |
Winson Chung | 31d66c6 | 2014-06-30 13:12:54 -0700 | [diff] [blame] | 542 | unregisterReceiver(mSystemBroadcastReceiver); |
Winson Chung | 905950a | 2014-09-17 09:25:27 +0200 | [diff] [blame] | 543 | |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 544 | // Unregister any broadcast receivers for the task loader |
| 545 | mPackageMonitor.unregister(); |
| 546 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 547 | EventBus.getDefault().unregister(this); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 550 | @Override |
| 551 | public void onAttachedToWindow() { |
| 552 | super.onAttachedToWindow(); |
| 553 | EventBus.getDefault().register(mScrimViews, EVENT_BUS_PRIORITY); |
| 554 | } |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 555 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 556 | @Override |
| 557 | public void onDetachedFromWindow() { |
| 558 | super.onDetachedFromWindow(); |
| 559 | EventBus.getDefault().unregister(mScrimViews); |
Winson Chung | 353c0b9 | 2014-10-16 17:43:23 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | @Override |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 563 | public void onTrimMemory(int level) { |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 564 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson Chung | 4d7b092 | 2014-03-13 17:14:17 -0700 | [diff] [blame] | 565 | if (loader != null) { |
| 566 | loader.onTrimMemory(level); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | @Override |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 571 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 572 | switch (keyCode) { |
| 573 | case KeyEvent.KEYCODE_TAB: { |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 574 | int altTabKeyDelay = getResources().getInteger(R.integer.recents_alt_tab_key_delay); |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 575 | boolean hasRepKeyTimeElapsed = (SystemClock.elapsedRealtime() - |
Winson | 35f3050 | 2015-09-28 11:24:36 -0700 | [diff] [blame] | 576 | mLastTabKeyEventTime) > altTabKeyDelay; |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 577 | if (event.getRepeatCount() <= 0 || hasRepKeyTimeElapsed) { |
| 578 | // Focus the next task in the stack |
| 579 | final boolean backward = event.isShiftPressed(); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 580 | if (backward) { |
| 581 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
| 582 | } else { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 583 | EventBus.getDefault().send( |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 584 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 585 | } |
Winson Chung | 15a2ba8 | 2014-11-18 11:19:24 -0800 | [diff] [blame] | 586 | mLastTabKeyEventTime = SystemClock.elapsedRealtime(); |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 587 | |
| 588 | // In the case of another ALT event, don't ignore the next release |
| 589 | if (event.isAltPressed()) { |
| 590 | mIgnoreAltTabRelease = false; |
| 591 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 592 | } |
| 593 | return true; |
| 594 | } |
| 595 | case KeyEvent.KEYCODE_DPAD_UP: { |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 596 | EventBus.getDefault().send( |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 597 | new FocusNextTaskViewEvent(0 /* timerIndicatorDuration */)); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 598 | return true; |
| 599 | } |
| 600 | case KeyEvent.KEYCODE_DPAD_DOWN: { |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 601 | EventBus.getDefault().send(new FocusPreviousTaskViewEvent()); |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 602 | return true; |
| 603 | } |
| 604 | case KeyEvent.KEYCODE_DEL: |
| 605 | case KeyEvent.KEYCODE_FORWARD_DEL: { |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 606 | if (event.getRepeatCount() <= 0) { |
| 607 | EventBus.getDefault().send(new DismissFocusedTaskViewEvent()); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 608 | |
Winson | df3012b | 2016-01-12 15:35:05 -0800 | [diff] [blame] | 609 | // Keep track of deletions by keyboard |
| 610 | MetricsLogger.histogram(this, "overview_task_dismissed_source", |
| 611 | Constants.Metrics.DismissSourceKeyboard); |
| 612 | return true; |
| 613 | } |
Winson Chung | a0e88b5 | 2014-08-11 19:25:42 -0700 | [diff] [blame] | 614 | } |
| 615 | default: |
| 616 | break; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 617 | } |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 618 | return super.onKeyDown(keyCode, event); |
| 619 | } |
| 620 | |
| 621 | @Override |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 622 | public void onUserInteraction() { |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 623 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson Chung | a26fb78 | 2014-06-12 17:52:39 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | @Override |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 627 | public void onBackPressed() { |
Winson | a0731a1 | 2015-12-02 15:10:14 -0800 | [diff] [blame] | 628 | // Back behaves like the recents button so just trigger a toggle event |
| 629 | EventBus.getDefault().send(new ToggleRecentsEvent()); |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 630 | } |
Winson Chung | 47c4c69 | 2014-03-17 10:17:11 -0700 | [diff] [blame] | 631 | |
Winson | b78bb4f | 2015-09-24 17:22:57 -0700 | [diff] [blame] | 632 | /**** EventBus events ****/ |
Winson Chung | d543c1b | 2014-06-23 15:06:45 -0700 | [diff] [blame] | 633 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 634 | public final void onBusEvent(ToggleRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 635 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 636 | if (launchState.launchedFromHome) { |
| 637 | dismissRecentsToHome(true /* animateTaskViews */); |
| 638 | } else { |
| 639 | dismissRecentsToLaunchTargetTaskOrHome(); |
Winson | c29ff00 | 2015-11-20 16:00:45 -0800 | [diff] [blame] | 640 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 643 | public final void onBusEvent(IterateRecentsEvent event) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 644 | final RecentsDebugFlags debugFlags = Recents.getDebugFlags(); |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 645 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 646 | // Start dozing after the recents button is clicked |
| 647 | int timerIndicatorDuration = 0; |
| 648 | if (debugFlags.isFastToggleRecentsEnabled()) { |
| 649 | timerIndicatorDuration = getResources().getInteger( |
| 650 | R.integer.recents_subsequent_auto_advance_duration); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 651 | |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 652 | mIterateTrigger.setDozeDuration(timerIndicatorDuration); |
| 653 | if (!mIterateTrigger.isDozing()) { |
| 654 | mIterateTrigger.startDozing(); |
| 655 | } else { |
| 656 | mIterateTrigger.poke(); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 657 | } |
| 658 | } |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 659 | |
| 660 | // Focus the next task |
| 661 | EventBus.getDefault().send(new FocusNextTaskViewEvent(timerIndicatorDuration)); |
| 662 | |
| 663 | MetricsLogger.action(this, MetricsEvent.ACTION_OVERVIEW_PAGE); |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | public final void onBusEvent(UserInteractionEvent event) { |
Winson | b61e654 | 2016-02-04 14:37:18 -0800 | [diff] [blame] | 667 | // Stop the fast-toggle dozer |
Winson | 0d14d4d | 2015-10-26 17:05:04 -0700 | [diff] [blame] | 668 | mIterateTrigger.stopDozing(); |
| 669 | } |
| 670 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 671 | public final void onBusEvent(HideRecentsEvent event) { |
| 672 | if (event.triggeredFromAltTab) { |
| 673 | // 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] | 674 | if (!mIgnoreAltTabRelease) { |
| 675 | dismissRecentsToFocusedTaskOrHome(); |
| 676 | } |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 677 | } else if (event.triggeredFromHomeKey) { |
Winson | 8f6ee48 | 2016-03-18 17:51:48 -0700 | [diff] [blame] | 678 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 4b9cded | 2016-01-26 16:26:47 -0800 | [diff] [blame] | 679 | |
| 680 | // Cancel any pending dozes |
| 681 | EventBus.getDefault().send(mUserInteractionEvent); |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 682 | } else { |
| 683 | // Do nothing |
| 684 | } |
| 685 | } |
| 686 | |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 687 | public final void onBusEvent(EnterRecentsWindowLastAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 688 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(true)); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 689 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 690 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 693 | public final void onBusEvent(ExitRecentsWindowFirstAnimationFrameEvent event) { |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 694 | if (mRecentsView.isLastTaskLaunchedFreeform()) { |
| 695 | EventBus.getDefault().send(new UpdateFreeformTaskViewVisibilityEvent(false)); |
| 696 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 697 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
Winson | b1e71d0 | 2015-11-23 12:40:23 -0800 | [diff] [blame] | 698 | mRecentsView.invalidate(); |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 699 | } |
| 700 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 701 | public final void onBusEvent(DockedFirstAnimationFrameEvent event) { |
| 702 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); |
| 703 | mRecentsView.invalidate(); |
| 704 | } |
| 705 | |
Winson | 13d3066 | 2015-11-06 15:30:29 -0800 | [diff] [blame] | 706 | public final void onBusEvent(CancelEnterRecentsWindowAnimationEvent event) { |
| 707 | RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState(); |
| 708 | int launchToTaskId = launchState.launchedToTaskId; |
| 709 | if (launchToTaskId != -1 && |
| 710 | (event.launchTask == null || launchToTaskId != event.launchTask.key.id)) { |
| 711 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 712 | ssp.cancelWindowTransition(launchState.launchedToTaskId); |
| 713 | ssp.cancelThumbnailTransition(getTaskId()); |
| 714 | } |
| 715 | } |
| 716 | |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 717 | public final void onBusEvent(ShowApplicationInfoEvent event) { |
| 718 | // Create a new task stack with the application info details activity |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 719 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 720 | Uri.fromParts("package", event.task.key.getComponent().getPackageName(), null)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 721 | intent.setComponent(intent.resolveActivity(getPackageManager())); |
| 722 | TaskStackBuilder.create(this) |
| 723 | .addNextIntentWithParentStack(intent).startActivities(null, |
Peter Schiller | b124d56 | 2015-12-11 21:31:17 -0800 | [diff] [blame] | 724 | new UserHandle(event.task.key.userId)); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 725 | |
| 726 | // Keep track of app-info invocations |
| 727 | MetricsLogger.count(this, "overview_app_info", 1); |
| 728 | } |
| 729 | |
Winson | 9b00139 | 2016-04-08 14:54:02 -0700 | [diff] [blame] | 730 | public final void onBusEvent(ShowIncompatibleAppOverlayEvent event) { |
| 731 | if (mIncompatibleAppOverlay == null) { |
| 732 | mIncompatibleAppOverlay = Utilities.findViewStubById(this, |
| 733 | R.id.incompatible_app_overlay_stub).inflate(); |
| 734 | mIncompatibleAppOverlay.setWillNotDraw(false); |
| 735 | mIncompatibleAppOverlay.setVisibility(View.VISIBLE); |
| 736 | } |
| 737 | mIncompatibleAppOverlay.animate() |
| 738 | .alpha(1f) |
| 739 | .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION) |
| 740 | .setInterpolator(Interpolators.ALPHA_IN) |
| 741 | .start(); |
| 742 | } |
| 743 | |
| 744 | public final void onBusEvent(HideIncompatibleAppOverlayEvent event) { |
| 745 | if (mIncompatibleAppOverlay != null) { |
| 746 | mIncompatibleAppOverlay.animate() |
| 747 | .alpha(0f) |
| 748 | .setDuration(INCOMPATIBLE_APP_ALPHA_DURATION) |
| 749 | .setInterpolator(Interpolators.ALPHA_OUT) |
| 750 | .start(); |
| 751 | } |
| 752 | } |
| 753 | |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 754 | public final void onBusEvent(DeleteTaskDataEvent event) { |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 755 | // Remove any stored data from the loader |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 756 | RecentsTaskLoader loader = Recents.getTaskLoader(); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 757 | loader.deleteTaskData(event.task, false); |
| 758 | |
| 759 | // Remove the task from activity manager |
Winson | e7f138c | 2015-10-22 16:15:21 -0700 | [diff] [blame] | 760 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 761 | ssp.removeTask(event.task.key.id); |
Winson | 2536c7e | 2015-10-01 15:49:31 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 764 | public final void onBusEvent(AllTaskViewsDismissedEvent event) { |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 765 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 766 | if (ssp.hasDockedTask()) { |
Winson | 2068408 | 2016-03-16 17:13:34 -0700 | [diff] [blame] | 767 | mRecentsView.showEmptyView(event.msgResId); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 768 | } else { |
| 769 | // 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] | 770 | dismissRecentsToHome(false /* animateTaskViews */); |
Winson Chung | 9a74290 | 2015-12-11 10:25:40 -0500 | [diff] [blame] | 771 | } |
Winson | 397ae74 | 2015-11-20 11:27:33 -0800 | [diff] [blame] | 772 | |
| 773 | // Keep track of all-deletions |
| 774 | MetricsLogger.count(this, "overview_task_all_dismissed", 1); |
| 775 | } |
| 776 | |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 777 | public final void onBusEvent(LaunchTaskSucceededEvent event) { |
| 778 | MetricsLogger.histogram(this, "overview_task_launch_index", event.taskIndexFromStackFront); |
| 779 | } |
| 780 | |
| 781 | public final void onBusEvent(LaunchTaskFailedEvent event) { |
| 782 | // Return to Home |
Winson | ef06413 | 2016-01-05 12:11:31 -0800 | [diff] [blame] | 783 | dismissRecentsToHome(true /* animateTaskViews */); |
Winson | 83c1b07 | 2015-11-09 10:48:04 -0800 | [diff] [blame] | 784 | |
| 785 | MetricsLogger.count(this, "overview_task_launch_failed", 1); |
| 786 | } |
| 787 | |
Winson | 412e180 | 2015-10-20 16:57:57 -0700 | [diff] [blame] | 788 | public final void onBusEvent(ScreenPinningRequestEvent event) { |
| 789 | MetricsLogger.count(this, "overview_screen_pinned", 1); |
| 790 | } |
| 791 | |
Winson | c742f97 | 2015-11-12 11:32:21 -0800 | [diff] [blame] | 792 | public final void onBusEvent(DebugFlagsChangedEvent event) { |
| 793 | // Just finish recents so that we can reload the flags anew on the next instantiation |
| 794 | finish(); |
| 795 | } |
| 796 | |
Winson | e5f1faa | 2015-11-20 12:26:23 -0800 | [diff] [blame] | 797 | public final void onBusEvent(StackViewScrolledEvent event) { |
| 798 | // Once the user has scrolled while holding alt-tab, then we should ignore the release of |
| 799 | // the key |
| 800 | mIgnoreAltTabRelease = true; |
| 801 | } |
| 802 | |
Jorim Jaggi | 3273f31 | 2016-05-05 17:32:44 -0700 | [diff] [blame] | 803 | public final void onBusEvent(final DockedTopTaskEvent event) { |
| 804 | mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener); |
| 805 | mRecentsView.invalidate(); |
| 806 | } |
| 807 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 808 | @Override |
| 809 | public boolean onPreDraw() { |
| 810 | mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 811 | // We post to make sure that this information is delivered after this traversals is |
| 812 | // finished. |
| 813 | mRecentsView.post(new Runnable() { |
| 814 | @Override |
| 815 | public void run() { |
| 816 | Recents.getSystemServices().endProlongedAnimations(); |
| 817 | } |
| 818 | }); |
| 819 | return true; |
| 820 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 821 | |
| 822 | @Override |
| 823 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 824 | super.dump(prefix, fd, writer, args); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 825 | EventBus.getDefault().dump(prefix, writer); |
Winson | 29a763b | 2016-04-20 10:50:40 -0700 | [diff] [blame] | 826 | Recents.getTaskLoader().dump(prefix, writer); |
Winson | 67c7957 | 2016-04-13 14:02:18 -0700 | [diff] [blame] | 827 | |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 828 | String id = Integer.toHexString(System.identityHashCode(this)); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 829 | long lastStackActiveTime = Prefs.getLong(this, |
| 830 | Prefs.Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, -1); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 831 | |
| 832 | writer.print(prefix); writer.print(TAG); |
| 833 | writer.print(" visible="); writer.print(mIsVisible ? "Y" : "N"); |
Winson Chung | 36f3f03 | 2016-09-08 23:29:43 +0000 | [diff] [blame] | 834 | writer.print(" lastStackTaskActiveTime="); writer.print(lastStackActiveTime); |
| 835 | writer.print(" currentTime="); writer.print(System.currentTimeMillis()); |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 836 | writer.print(" [0x"); writer.print(id); writer.print("]"); |
| 837 | writer.println(); |
| 838 | |
| 839 | if (mRecentsView != null) { |
| 840 | mRecentsView.dump(prefix, writer); |
| 841 | } |
Winson | d72c315 | 2016-04-05 15:33:35 -0700 | [diff] [blame] | 842 | } |
Winson Chung | 303e1ff | 2014-03-07 15:06:19 -0800 | [diff] [blame] | 843 | } |