Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 19 | import static com.android.launcher3.util.FlagDebugUtils.appendFlag; |
| 20 | import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK; |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 22 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 23 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 24 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 25 | import android.app.Activity; |
| 26 | import android.content.Context; |
| 27 | import android.content.ContextWrapper; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 30 | import android.os.Bundle; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 31 | import android.util.Log; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 32 | import android.window.OnBackInvokedDispatcher; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 33 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 34 | import androidx.annotation.IntDef; |
| 35 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 36 | import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 37 | import com.android.launcher3.logging.StatsLogManager; |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 38 | import com.android.launcher3.testing.TestLogging; |
| 39 | import com.android.launcher3.testing.shared.TestProtocol; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 40 | import com.android.launcher3.util.SystemUiController; |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 41 | import com.android.launcher3.util.ViewCache; |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 42 | import com.android.launcher3.views.ActivityContext; |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 43 | import com.android.launcher3.views.ScrimView; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 44 | |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 45 | import java.io.PrintWriter; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 46 | import java.lang.annotation.Retention; |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 47 | import java.util.ArrayList; |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 48 | import java.util.List; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 49 | import java.util.StringJoiner; |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 50 | |
Samuel Fufa | a579ddc | 2020-02-27 16:59:19 -0800 | [diff] [blame] | 51 | /** |
| 52 | * Launcher BaseActivity |
| 53 | */ |
Sunny Goyal | 54fa110 | 2022-12-07 22:48:37 -0800 | [diff] [blame] | 54 | public abstract class BaseActivity extends Activity implements ActivityContext { |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 55 | |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 56 | private static final String TAG = "BaseActivity"; |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 57 | static final boolean DEBUG = false; |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 58 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 59 | public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0; |
| 60 | public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1; |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 61 | public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2; |
| 62 | |
| 63 | // This is not treated as invisibility flag, but adds as a hint for an incomplete transition. |
| 64 | // When the wallpaper animation runs, it replaces this flag with a proper invisibility |
| 65 | // flag, INVISIBLE_BY_PENDING_FLAGS only for the duration of that animation. |
| 66 | public static final int PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION = 1 << 3; |
| 67 | |
| 68 | private static final int INVISIBLE_FLAGS = |
| 69 | INVISIBLE_BY_STATE_HANDLER | INVISIBLE_BY_APP_TRANSITIONS | INVISIBLE_BY_PENDING_FLAGS; |
| 70 | public static final int STATE_HANDLER_INVISIBILITY_FLAGS = |
| 71 | INVISIBLE_BY_STATE_HANDLER | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 72 | public static final int INVISIBLE_ALL = |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 73 | INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 74 | |
| 75 | @Retention(SOURCE) |
| 76 | @IntDef( |
| 77 | flag = true, |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 78 | value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS, |
| 79 | INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION}) |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 80 | public @interface InvisibilityFlags { |
| 81 | } |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 82 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 83 | private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>(); |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 84 | private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners = |
| 85 | new ArrayList<>(); |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 86 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 87 | protected DeviceProfile mDeviceProfile; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 88 | protected SystemUiController mSystemUiController; |
Sunny Goyal | 977838b | 2022-06-27 13:15:41 -0700 | [diff] [blame] | 89 | private StatsLogManager mStatsLogManager; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 90 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 91 | |
| 92 | public static final int ACTIVITY_STATE_STARTED = 1 << 0; |
| 93 | public static final int ACTIVITY_STATE_RESUMED = 1 << 1; |
| 94 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 95 | /** |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 96 | * State flags indicating that the activity has received one frame after resume, and was |
| 97 | * not immediately paused. |
| 98 | */ |
| 99 | public static final int ACTIVITY_STATE_DEFERRED_RESUMED = 1 << 2; |
| 100 | |
| 101 | public static final int ACTIVITY_STATE_WINDOW_FOCUSED = 1 << 3; |
| 102 | |
| 103 | /** |
| 104 | * State flag indicating if the user is active or the activity when to background as a result |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 105 | * of user action. |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 106 | * |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 107 | * @see #isUserActive() |
| 108 | */ |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 109 | public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4; |
| 110 | |
| 111 | /** |
Winson Chung | 034ce6f | 2020-05-14 10:49:30 -0700 | [diff] [blame] | 112 | * State flag indicating if the user will be active shortly. |
| 113 | */ |
| 114 | public static final int ACTIVITY_STATE_USER_WILL_BE_ACTIVE = 1 << 5; |
| 115 | |
| 116 | /** |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 117 | * State flag indicating that a state transition is in progress |
| 118 | */ |
Winson Chung | 034ce6f | 2020-05-14 10:49:30 -0700 | [diff] [blame] | 119 | public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 6; |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 120 | |
| 121 | @Retention(SOURCE) |
| 122 | @IntDef( |
| 123 | flag = true, |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 124 | value = {ACTIVITY_STATE_STARTED, |
| 125 | ACTIVITY_STATE_RESUMED, |
| 126 | ACTIVITY_STATE_DEFERRED_RESUMED, |
| 127 | ACTIVITY_STATE_WINDOW_FOCUSED, |
| 128 | ACTIVITY_STATE_USER_ACTIVE, |
| 129 | ACTIVITY_STATE_TRANSITION_ACTIVE}) |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 130 | public @interface ActivityFlags { |
| 131 | } |
| 132 | |
| 133 | /** Returns a human-readable string for the specified {@link ActivityFlags}. */ |
| 134 | public static String getActivityStateString(@ActivityFlags int flags) { |
| 135 | StringJoiner result = new StringJoiner("|"); |
| 136 | appendFlag(result, flags, ACTIVITY_STATE_STARTED, "state_started"); |
| 137 | appendFlag(result, flags, ACTIVITY_STATE_RESUMED, "state_resumed"); |
| 138 | appendFlag(result, flags, ACTIVITY_STATE_DEFERRED_RESUMED, "state_deferred_resumed"); |
| 139 | appendFlag(result, flags, ACTIVITY_STATE_WINDOW_FOCUSED, "state_window_focused"); |
| 140 | appendFlag(result, flags, ACTIVITY_STATE_USER_ACTIVE, "state_user_active"); |
| 141 | appendFlag(result, flags, ACTIVITY_STATE_TRANSITION_ACTIVE, "state_transition_active"); |
| 142 | return result.toString(); |
| 143 | } |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 144 | |
| 145 | @ActivityFlags |
| 146 | private int mActivityFlags; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 147 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 148 | // When the recents animation is running, the visibility of the Launcher is managed by the |
| 149 | // animation |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 150 | @InvisibilityFlags |
| 151 | private int mForceInvisible; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 152 | |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 153 | private final ViewCache mViewCache = new ViewCache(); |
| 154 | |
Sunny Goyal | 5996937 | 2021-05-06 12:11:44 -0700 | [diff] [blame] | 155 | @Override |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 156 | public ViewCache getViewCache() { |
| 157 | return mViewCache; |
| 158 | } |
| 159 | |
Sunny Goyal | fe8e4a9 | 2018-11-13 19:43:57 -0800 | [diff] [blame] | 160 | @Override |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 161 | public DeviceProfile getDeviceProfile() { |
| 162 | return mDeviceProfile; |
| 163 | } |
| 164 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 165 | @Override |
| 166 | public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() { |
| 167 | return mDPChangeListeners; |
| 168 | } |
| 169 | |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Returns {@link StatsLogManager} for user event logging. |
| 172 | */ |
Sunny Goyal | 177785e | 2021-07-29 15:48:24 -0700 | [diff] [blame] | 173 | @Override |
thiruram | c96873c | 2021-02-11 15:13:47 -0800 | [diff] [blame] | 174 | public StatsLogManager getStatsLogManager() { |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 175 | if (mStatsLogManager == null) { |
Hyunyoung Song | 801f81f | 2020-06-19 02:58:53 -0700 | [diff] [blame] | 176 | mStatsLogManager = StatsLogManager.newInstance(this); |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 177 | } |
| 178 | return mStatsLogManager; |
| 179 | } |
| 180 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 181 | public SystemUiController getSystemUiController() { |
| 182 | if (mSystemUiController == null) { |
| 183 | mSystemUiController = new SystemUiController(getWindow()); |
| 184 | } |
| 185 | return mSystemUiController; |
| 186 | } |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 187 | |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 188 | public ScrimView getScrimView() { |
| 189 | return null; |
| 190 | } |
| 191 | |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 192 | @Override |
| 193 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 194 | super.onActivityResult(requestCode, resultCode, data); |
| 195 | } |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 196 | |
| 197 | @Override |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 198 | protected void onCreate(Bundle savedInstanceState) { |
| 199 | super.onCreate(savedInstanceState); |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 200 | registerBackDispatcher(); |
Yein Jo | 18446d0 | 2022-09-19 22:18:09 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 204 | protected void onStart() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 205 | addActivityFlags(ACTIVITY_STATE_STARTED); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 206 | super.onStart(); |
| 207 | } |
| 208 | |
| 209 | @Override |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 210 | protected void onResume() { |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 211 | setResumed(); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 212 | super.onResume(); |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | protected void onUserLeaveHint() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 217 | removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 218 | super.onUserLeaveHint(); |
| 219 | } |
| 220 | |
| 221 | @Override |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 222 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 223 | super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
| 224 | for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) { |
| 225 | mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | @Override |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 230 | protected void onStop() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 231 | removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE); |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 232 | mForceInvisible = 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 233 | super.onStop(); |
Winson Chung | a36c800 | 2019-06-11 16:15:54 -0700 | [diff] [blame] | 234 | |
| 235 | // Reset the overridden sysui flags used for the task-swipe launch animation, this is a |
| 236 | // catch all for if we do not get resumed (and therefore not paused below) |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 237 | getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 240 | @Override |
| 241 | protected void onPause() { |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 242 | setPaused(); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 243 | super.onPause(); |
Winson Chung | a0f09f9 | 2018-05-11 21:55:21 +0000 | [diff] [blame] | 244 | |
| 245 | // Reset the overridden sysui flags used for the task-swipe launch animation, we do this |
| 246 | // here instead of at the end of the animation because the start of the new activity does |
| 247 | // not happen immediately, which would cause us to reset to launcher's sysui flags and then |
| 248 | // back to the new app (causing a flash) |
Tony Wickham | b482188 | 2021-04-23 14:26:45 -0700 | [diff] [blame] | 249 | getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 252 | @Override |
| 253 | public void onWindowFocusChanged(boolean hasFocus) { |
| 254 | super.onWindowFocusChanged(hasFocus); |
| 255 | if (hasFocus) { |
| 256 | addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 257 | } else { |
| 258 | removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 259 | } |
| 260 | |
| 261 | } |
| 262 | |
Fengjiang Li | e884c2c | 2022-12-19 14:42:14 -0800 | [diff] [blame] | 263 | protected void registerBackDispatcher() { |
| 264 | if (Utilities.ATLEAST_T) { |
| 265 | getOnBackInvokedDispatcher().registerOnBackInvokedCallback( |
| 266 | OnBackInvokedDispatcher.PRIORITY_DEFAULT, |
| 267 | () -> { |
| 268 | onBackPressed(); |
| 269 | TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked"); |
| 270 | }); |
| 271 | } |
| 272 | } |
| 273 | |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 274 | public boolean isStarted() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 275 | return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * isResumed in already defined as a hidden final method in Activity.java |
| 280 | */ |
| 281 | public boolean hasBeenResumed() { |
| 282 | return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 283 | } |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 284 | |
Mady Mellor | 9a90c2d | 2022-09-14 15:17:21 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Sets the activity to appear as paused. |
| 287 | */ |
| 288 | public void setPaused() { |
| 289 | removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Sets the activity to appear as resumed. |
| 294 | */ |
| 295 | public void setResumed() { |
| 296 | addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE); |
| 297 | removeActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE); |
| 298 | } |
| 299 | |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 300 | public boolean isUserActive() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 301 | return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0; |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 304 | public int getActivityFlags() { |
| 305 | return mActivityFlags; |
| 306 | } |
| 307 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 308 | protected void addActivityFlags(int toAdd) { |
| 309 | final int oldFlags = mActivityFlags; |
| 310 | mActivityFlags |= toAdd; |
| 311 | if (DEBUG) { |
| 312 | Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags, |
| 313 | BaseActivity::getActivityStateString)); |
| 314 | } |
| 315 | onActivityFlagsChanged(toAdd); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 318 | protected void removeActivityFlags(int toRemove) { |
| 319 | final int oldFlags = mActivityFlags; |
| 320 | mActivityFlags &= ~toRemove; |
| 321 | if (DEBUG) { |
| 322 | Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags, |
| 323 | BaseActivity::getActivityStateString)); |
| 324 | } |
| 325 | |
| 326 | onActivityFlagsChanged(toRemove); |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 329 | protected void onActivityFlagsChanged(int changeBits) { |
| 330 | } |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 331 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 332 | public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 333 | mMultiWindowModeChangedListeners.add(listener); |
| 334 | } |
| 335 | |
| 336 | public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 337 | mMultiWindowModeChangedListeners.remove(listener); |
| 338 | } |
| 339 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 340 | /** |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 341 | * Used to set the override visibility state, used only to handle the transition home with the |
| 342 | * recents animation. |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 343 | * |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 344 | * @see QuickstepTransitionManager#createWallpaperOpenRunner |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 345 | */ |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 346 | public void addForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 347 | mForceInvisible |= flag; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 350 | public void clearForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 351 | mForceInvisible &= ~flag; |
| 352 | } |
| 353 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 354 | /** |
| 355 | * @return Wether this activity should be considered invisible regardless of actual visibility. |
| 356 | */ |
| 357 | public boolean isForceInvisible() { |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 358 | return hasSomeInvisibleFlag(INVISIBLE_FLAGS); |
| 359 | } |
| 360 | |
| 361 | public boolean hasSomeInvisibleFlag(int mask) { |
| 362 | return (mForceInvisible & mask) != 0; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 365 | public interface MultiWindowModeChangedListener { |
| 366 | void onMultiWindowModeChanged(boolean isInMultiWindowMode); |
| 367 | } |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 368 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 369 | protected void dumpMisc(String prefix, PrintWriter writer) { |
| 370 | writer.println(prefix + "deviceProfile isTransposed=" |
| 371 | + getDeviceProfile().isVerticalBarLayout()); |
| 372 | writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation); |
| 373 | writer.println(prefix + "mSystemUiController: " + mSystemUiController); |
Mike Schneider | a79d460 | 2023-03-03 15:58:06 +0100 | [diff] [blame^] | 374 | writer.println(prefix + "mActivityFlags: " + getActivityStateString(mActivityFlags)); |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 375 | writer.println(prefix + "mForceInvisible: " + mForceInvisible); |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 376 | } |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 377 | |
| 378 | public static <T extends BaseActivity> T fromContext(Context context) { |
| 379 | if (context instanceof BaseActivity) { |
| 380 | return (T) context; |
Tony Wickham | 1906cc3 | 2021-02-11 11:55:24 -0800 | [diff] [blame] | 381 | } else if (context instanceof ContextWrapper) { |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 382 | return fromContext(((ContextWrapper) context).getBaseContext()); |
| 383 | } else { |
| 384 | throw new IllegalArgumentException("Cannot find BaseActivity in parent tree"); |
| 385 | } |
| 386 | } |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 387 | } |