blob: 633091d87ba6e6bfb6ecfb9b76258cd37bb988fe [file] [log] [blame]
Sunny Goyal27835952017-01-13 12:15:53 -08001/*
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
17package com.android.launcher3;
18
Mike Schneidera79d4602023-03-03 15:58:06 +010019import static com.android.launcher3.util.FlagDebugUtils.appendFlag;
20import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange;
Tony Wickhamb4821882021-04-23 14:26:45 -070021import static com.android.launcher3.util.SystemUiController.UI_STATE_FULLSCREEN_TASK;
Sunny Goyal8c48d8b2019-01-25 15:10:18 -080022
Sunny Goyal7eff40f2018-04-11 15:30:46 -070023import static java.lang.annotation.RetentionPolicy.SOURCE;
24
Sunny Goyal27835952017-01-13 12:15:53 -080025import android.app.Activity;
26import android.content.Context;
27import android.content.ContextWrapper;
Sunny Goyal64a75aa2017-07-03 13:50:52 -070028import android.content.Intent;
Winson Chung1a77c3d2018-04-11 12:47:47 -070029import android.content.res.Configuration;
Yein Jo18446d02022-09-19 22:18:09 +000030import android.os.Bundle;
Mike Schneidera79d4602023-03-03 15:58:06 +010031import android.util.Log;
Yein Jo18446d02022-09-19 22:18:09 +000032import android.window.OnBackInvokedDispatcher;
Sunny Goyal27835952017-01-13 12:15:53 -080033
Winson Chungef528762019-09-06 12:05:52 -070034import androidx.annotation.IntDef;
35
Sunny Goyalfde55052018-02-01 14:46:13 -080036import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
Hyunyoung Songfc007472018-10-25 14:09:50 -070037import com.android.launcher3.logging.StatsLogManager;
Yein Jo18446d02022-09-19 22:18:09 +000038import com.android.launcher3.testing.TestLogging;
39import com.android.launcher3.testing.shared.TestProtocol;
Sunny Goyale82a20a2023-10-19 13:52:49 -070040import com.android.launcher3.util.RunnableList;
Sunny Goyal8392c822017-06-20 10:03:56 -070041import com.android.launcher3.util.SystemUiController;
Sunny Goyal56863332019-05-22 14:13:53 -070042import com.android.launcher3.util.ViewCache;
Sunny Goyal54fa1102022-12-07 22:48:37 -080043import com.android.launcher3.views.ActivityContext;
Tony Wickhamb4821882021-04-23 14:26:45 -070044import com.android.launcher3.views.ScrimView;
Sunny Goyala535ae42017-02-27 10:07:13 -080045
Sunny Goyale43d00d2018-05-14 14:23:18 -070046import java.io.PrintWriter;
Sunny Goyal7eff40f2018-04-11 15:30:46 -070047import java.lang.annotation.Retention;
Sunny Goyalfde55052018-02-01 14:46:13 -080048import java.util.ArrayList;
Brian Isganitis099945b2022-01-31 18:15:00 -050049import java.util.List;
Mike Schneidera79d4602023-03-03 15:58:06 +010050import java.util.StringJoiner;
Sunny Goyalfde55052018-02-01 14:46:13 -080051
Samuel Fufaa579ddc2020-02-27 16:59:19 -080052/**
53 * Launcher BaseActivity
54 */
Sunny Goyal54fa1102022-12-07 22:48:37 -080055public abstract class BaseActivity extends Activity implements ActivityContext {
Sunny Goyal27835952017-01-13 12:15:53 -080056
Sunny Goyalfa395362019-12-11 10:00:47 -080057 private static final String TAG = "BaseActivity";
Mike Schneidera79d4602023-03-03 15:58:06 +010058 static final boolean DEBUG = false;
Sunny Goyalfa395362019-12-11 10:00:47 -080059
Sunny Goyal7eff40f2018-04-11 15:30:46 -070060 public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0;
61 public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1;
Sunny Goyal1c63c722018-06-05 16:00:34 -070062 public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2;
63
64 // This is not treated as invisibility flag, but adds as a hint for an incomplete transition.
65 // When the wallpaper animation runs, it replaces this flag with a proper invisibility
66 // flag, INVISIBLE_BY_PENDING_FLAGS only for the duration of that animation.
67 public static final int PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION = 1 << 3;
68
69 private static final int INVISIBLE_FLAGS =
70 INVISIBLE_BY_STATE_HANDLER | INVISIBLE_BY_APP_TRANSITIONS | INVISIBLE_BY_PENDING_FLAGS;
71 public static final int STATE_HANDLER_INVISIBILITY_FLAGS =
72 INVISIBLE_BY_STATE_HANDLER | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION;
Sunny Goyal7eff40f2018-04-11 15:30:46 -070073 public static final int INVISIBLE_ALL =
Sunny Goyal1c63c722018-06-05 16:00:34 -070074 INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION;
Sunny Goyal7eff40f2018-04-11 15:30:46 -070075
76 @Retention(SOURCE)
77 @IntDef(
78 flag = true,
Sunny Goyal1c63c722018-06-05 16:00:34 -070079 value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS,
80 INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION})
Mike Schneidera79d4602023-03-03 15:58:06 +010081 public @interface InvisibilityFlags {
82 }
Sunny Goyal7eff40f2018-04-11 15:30:46 -070083
Sunny Goyalfde55052018-02-01 14:46:13 -080084 private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>();
Winson Chung1a77c3d2018-04-11 12:47:47 -070085 private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners =
86 new ArrayList<>();
Sunny Goyalfde55052018-02-01 14:46:13 -080087
Sunny Goyal27835952017-01-13 12:15:53 -080088 protected DeviceProfile mDeviceProfile;
Sunny Goyal8392c822017-06-20 10:03:56 -070089 protected SystemUiController mSystemUiController;
Sunny Goyal977838b2022-06-27 13:15:41 -070090 private StatsLogManager mStatsLogManager;
Sunny Goyal27835952017-01-13 12:15:53 -080091
Sunny Goyal210e1742019-10-17 12:05:38 -070092
93 public static final int ACTIVITY_STATE_STARTED = 1 << 0;
94 public static final int ACTIVITY_STATE_RESUMED = 1 << 1;
95
Sunny Goyal3483c522018-04-12 11:23:33 -070096 /**
Sunny Goyal210e1742019-10-17 12:05:38 -070097 * State flags indicating that the activity has received one frame after resume, and was
98 * not immediately paused.
99 */
100 public static final int ACTIVITY_STATE_DEFERRED_RESUMED = 1 << 2;
101
102 public static final int ACTIVITY_STATE_WINDOW_FOCUSED = 1 << 3;
103
104 /**
105 * State flag indicating if the user is active or the activity when to background as a result
Sunny Goyal3483c522018-04-12 11:23:33 -0700106 * of user action.
Mike Schneidera79d4602023-03-03 15:58:06 +0100107 *
Sunny Goyal3483c522018-04-12 11:23:33 -0700108 * @see #isUserActive()
109 */
Sunny Goyal210e1742019-10-17 12:05:38 -0700110 public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4;
111
112 /**
Winson Chung034ce6f2020-05-14 10:49:30 -0700113 * State flag indicating if the user will be active shortly.
114 */
115 public static final int ACTIVITY_STATE_USER_WILL_BE_ACTIVE = 1 << 5;
116
117 /**
Sunny Goyal210e1742019-10-17 12:05:38 -0700118 * State flag indicating that a state transition is in progress
119 */
Winson Chung034ce6f2020-05-14 10:49:30 -0700120 public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 6;
Sunny Goyal3483c522018-04-12 11:23:33 -0700121
122 @Retention(SOURCE)
123 @IntDef(
124 flag = true,
Sunny Goyal210e1742019-10-17 12:05:38 -0700125 value = {ACTIVITY_STATE_STARTED,
126 ACTIVITY_STATE_RESUMED,
127 ACTIVITY_STATE_DEFERRED_RESUMED,
128 ACTIVITY_STATE_WINDOW_FOCUSED,
129 ACTIVITY_STATE_USER_ACTIVE,
130 ACTIVITY_STATE_TRANSITION_ACTIVE})
Mike Schneidera79d4602023-03-03 15:58:06 +0100131 public @interface ActivityFlags {
132 }
133
134 /** Returns a human-readable string for the specified {@link ActivityFlags}. */
135 public static String getActivityStateString(@ActivityFlags int flags) {
136 StringJoiner result = new StringJoiner("|");
137 appendFlag(result, flags, ACTIVITY_STATE_STARTED, "state_started");
138 appendFlag(result, flags, ACTIVITY_STATE_RESUMED, "state_resumed");
139 appendFlag(result, flags, ACTIVITY_STATE_DEFERRED_RESUMED, "state_deferred_resumed");
140 appendFlag(result, flags, ACTIVITY_STATE_WINDOW_FOCUSED, "state_window_focused");
141 appendFlag(result, flags, ACTIVITY_STATE_USER_ACTIVE, "state_user_active");
142 appendFlag(result, flags, ACTIVITY_STATE_TRANSITION_ACTIVE, "state_transition_active");
143 return result.toString();
144 }
Sunny Goyal3483c522018-04-12 11:23:33 -0700145
146 @ActivityFlags
147 private int mActivityFlags;
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700148
Winson Chung9800e732018-04-04 13:33:23 -0700149 // When the recents animation is running, the visibility of the Launcher is managed by the
150 // animation
Mike Schneidera79d4602023-03-03 15:58:06 +0100151 @InvisibilityFlags
152 private int mForceInvisible;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800153
Sunny Goyal56863332019-05-22 14:13:53 -0700154 private final ViewCache mViewCache = new ViewCache();
155
Sunny Goyale82a20a2023-10-19 13:52:49 -0700156 @Retention(SOURCE)
157 @IntDef({EVENT_STARTED, EVENT_RESUMED, EVENT_STOPPED, EVENT_DESTROYED})
158 public @interface ActivityEvent { }
159 public static final int EVENT_STARTED = 0;
160 public static final int EVENT_RESUMED = 1;
161 public static final int EVENT_STOPPED = 2;
162 public static final int EVENT_DESTROYED = 3;
163
164 // Callback array that corresponds to events defined in @ActivityEvent
165 private final RunnableList[] mEventCallbacks =
166 {new RunnableList(), new RunnableList(), new RunnableList(), new RunnableList()};
167
Sunny Goyal59969372021-05-06 12:11:44 -0700168 @Override
Sunny Goyal56863332019-05-22 14:13:53 -0700169 public ViewCache getViewCache() {
170 return mViewCache;
171 }
172
Sunny Goyalfe8e4a92018-11-13 19:43:57 -0800173 @Override
Sunny Goyal27835952017-01-13 12:15:53 -0800174 public DeviceProfile getDeviceProfile() {
175 return mDeviceProfile;
176 }
177
Brian Isganitis099945b2022-01-31 18:15:00 -0500178 @Override
179 public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() {
180 return mDPChangeListeners;
181 }
182
thiruramc96873c2021-02-11 15:13:47 -0800183 /**
184 * Returns {@link StatsLogManager} for user event logging.
185 */
Sunny Goyal177785e2021-07-29 15:48:24 -0700186 @Override
thiruramc96873c2021-02-11 15:13:47 -0800187 public StatsLogManager getStatsLogManager() {
Hyunyoung Songfc007472018-10-25 14:09:50 -0700188 if (mStatsLogManager == null) {
Hyunyoung Song801f81f2020-06-19 02:58:53 -0700189 mStatsLogManager = StatsLogManager.newInstance(this);
Hyunyoung Songfc007472018-10-25 14:09:50 -0700190 }
191 return mStatsLogManager;
192 }
193
Sunny Goyal8392c822017-06-20 10:03:56 -0700194 public SystemUiController getSystemUiController() {
195 if (mSystemUiController == null) {
196 mSystemUiController = new SystemUiController(getWindow());
197 }
198 return mSystemUiController;
199 }
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700200
Tony Wickhamb4821882021-04-23 14:26:45 -0700201 public ScrimView getScrimView() {
202 return null;
203 }
204
Sunny Goyal64a75aa2017-07-03 13:50:52 -0700205 @Override
206 public void onActivityResult(int requestCode, int resultCode, Intent data) {
207 super.onActivityResult(requestCode, resultCode, data);
208 }
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800209
210 @Override
Yein Jo18446d02022-09-19 22:18:09 +0000211 protected void onCreate(Bundle savedInstanceState) {
212 super.onCreate(savedInstanceState);
Fengjiang Lie884c2c2022-12-19 14:42:14 -0800213 registerBackDispatcher();
Yein Jo18446d02022-09-19 22:18:09 +0000214 }
215
216 @Override
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800217 protected void onStart() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700218 addActivityFlags(ACTIVITY_STATE_STARTED);
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800219 super.onStart();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700220 mEventCallbacks[EVENT_STARTED].executeAllAndClear();
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800221 }
222
223 @Override
Tracy Zhoua706f002018-03-28 13:55:19 -0700224 protected void onResume() {
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700225 setResumed();
Tracy Zhoua706f002018-03-28 13:55:19 -0700226 super.onResume();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700227 mEventCallbacks[EVENT_RESUMED].executeAllAndClear();
Tracy Zhoua706f002018-03-28 13:55:19 -0700228 }
229
230 @Override
231 protected void onUserLeaveHint() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700232 removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE);
Tracy Zhoua706f002018-03-28 13:55:19 -0700233 super.onUserLeaveHint();
234 }
235
236 @Override
Winson Chung1a77c3d2018-04-11 12:47:47 -0700237 public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
238 super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
239 for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) {
240 mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode);
241 }
242 }
243
244 @Override
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800245 protected void onStop() {
Sunny Goyal210e1742019-10-17 12:05:38 -0700246 removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE);
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700247 mForceInvisible = 0;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800248 super.onStop();
Sunny Goyale82a20a2023-10-19 13:52:49 -0700249 mEventCallbacks[EVENT_STOPPED].executeAllAndClear();
250
Winson Chunga36c8002019-06-11 16:15:54 -0700251
252 // Reset the overridden sysui flags used for the task-swipe launch animation, this is a
253 // catch all for if we do not get resumed (and therefore not paused below)
Tony Wickhamb4821882021-04-23 14:26:45 -0700254 getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800255 }
256
Sunny Goyal3483c522018-04-12 11:23:33 -0700257 @Override
Sunny Goyale82a20a2023-10-19 13:52:49 -0700258 protected void onDestroy() {
259 super.onDestroy();
260 mEventCallbacks[EVENT_DESTROYED].executeAllAndClear();
261 }
262
263 @Override
Sunny Goyal3483c522018-04-12 11:23:33 -0700264 protected void onPause() {
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700265 setPaused();
Sunny Goyal3483c522018-04-12 11:23:33 -0700266 super.onPause();
Winson Chunga0f09f92018-05-11 21:55:21 +0000267
268 // Reset the overridden sysui flags used for the task-swipe launch animation, we do this
269 // here instead of at the end of the animation because the start of the new activity does
270 // not happen immediately, which would cause us to reset to launcher's sysui flags and then
271 // back to the new app (causing a flash)
Tony Wickhamb4821882021-04-23 14:26:45 -0700272 getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
Sunny Goyal3483c522018-04-12 11:23:33 -0700273 }
274
Sunny Goyal210e1742019-10-17 12:05:38 -0700275 @Override
276 public void onWindowFocusChanged(boolean hasFocus) {
277 super.onWindowFocusChanged(hasFocus);
278 if (hasFocus) {
279 addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
280 } else {
281 removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
282 }
Sunny Goyal210e1742019-10-17 12:05:38 -0700283 }
284
Fengjiang Lie884c2c2022-12-19 14:42:14 -0800285 protected void registerBackDispatcher() {
286 if (Utilities.ATLEAST_T) {
287 getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
288 OnBackInvokedDispatcher.PRIORITY_DEFAULT,
289 () -> {
290 onBackPressed();
291 TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onBackInvoked");
292 });
293 }
294 }
295
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800296 public boolean isStarted() {
Sunny Goyal3483c522018-04-12 11:23:33 -0700297 return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0;
298 }
299
300 /**
301 * isResumed in already defined as a hidden final method in Activity.java
302 */
303 public boolean hasBeenResumed() {
304 return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0;
Sunny Goyalcc96aa12018-01-11 09:56:07 -0800305 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800306
Mady Mellor9a90c2d2022-09-14 15:17:21 -0700307 /**
308 * Sets the activity to appear as paused.
309 */
310 public void setPaused() {
311 removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED);
312 }
313
314 /**
315 * Sets the activity to appear as resumed.
316 */
317 public void setResumed() {
318 addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE);
319 removeActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE);
320 }
321
Tracy Zhoua706f002018-03-28 13:55:19 -0700322 public boolean isUserActive() {
Sunny Goyal3483c522018-04-12 11:23:33 -0700323 return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0;
Tracy Zhoua706f002018-03-28 13:55:19 -0700324 }
325
Sunny Goyal210e1742019-10-17 12:05:38 -0700326 public int getActivityFlags() {
327 return mActivityFlags;
328 }
329
Mike Schneidera79d4602023-03-03 15:58:06 +0100330 protected void addActivityFlags(int toAdd) {
331 final int oldFlags = mActivityFlags;
332 mActivityFlags |= toAdd;
333 if (DEBUG) {
334 Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags,
335 BaseActivity::getActivityStateString));
336 }
337 onActivityFlagsChanged(toAdd);
Sunny Goyal210e1742019-10-17 12:05:38 -0700338 }
339
Mike Schneidera79d4602023-03-03 15:58:06 +0100340 protected void removeActivityFlags(int toRemove) {
341 final int oldFlags = mActivityFlags;
342 mActivityFlags &= ~toRemove;
343 if (DEBUG) {
344 Log.d(TAG, "Launcher flags updated: " + formatFlagChange(mActivityFlags, oldFlags,
345 BaseActivity::getActivityStateString));
346 }
347
348 onActivityFlagsChanged(toRemove);
Sunny Goyal210e1742019-10-17 12:05:38 -0700349 }
350
Mike Schneidera79d4602023-03-03 15:58:06 +0100351 protected void onActivityFlagsChanged(int changeBits) {
352 }
Sunny Goyal210e1742019-10-17 12:05:38 -0700353
Winson Chung1a77c3d2018-04-11 12:47:47 -0700354 public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
355 mMultiWindowModeChangedListeners.add(listener);
356 }
357
358 public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
359 mMultiWindowModeChangedListeners.remove(listener);
360 }
361
Sunny Goyalf633ef52018-03-13 09:57:05 -0700362 /**
Winson Chung9800e732018-04-04 13:33:23 -0700363 * Used to set the override visibility state, used only to handle the transition home with the
364 * recents animation.
Mike Schneidera79d4602023-03-03 15:58:06 +0100365 *
Sunny Goyalb65d7662021-03-07 15:09:11 -0800366 * @see QuickstepTransitionManager#createWallpaperOpenRunner
Winson Chung9800e732018-04-04 13:33:23 -0700367 */
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700368 public void addForceInvisibleFlag(@InvisibilityFlags int flag) {
369 mForceInvisible |= flag;
Winson Chung9800e732018-04-04 13:33:23 -0700370 }
371
Sunny Goyal7eff40f2018-04-11 15:30:46 -0700372 public void clearForceInvisibleFlag(@InvisibilityFlags int flag) {
373 mForceInvisible &= ~flag;
374 }
375
Winson Chung9800e732018-04-04 13:33:23 -0700376 /**
377 * @return Wether this activity should be considered invisible regardless of actual visibility.
378 */
379 public boolean isForceInvisible() {
Sunny Goyal1c63c722018-06-05 16:00:34 -0700380 return hasSomeInvisibleFlag(INVISIBLE_FLAGS);
381 }
382
383 public boolean hasSomeInvisibleFlag(int mask) {
384 return (mForceInvisible & mask) != 0;
Winson Chung9800e732018-04-04 13:33:23 -0700385 }
386
Jon Mirandacb582592023-04-19 15:40:04 -0700387 /**
Sunny Goyale82a20a2023-10-19 13:52:49 -0700388 * Adds a callback for the provided activity event
Jon Mirandacb582592023-04-19 15:40:04 -0700389 */
Sunny Goyale82a20a2023-10-19 13:52:49 -0700390 public void addEventCallback(@ActivityEvent int event, Runnable callback) {
391 mEventCallbacks[event].add(callback);
392 }
393
394 /** Removes a previously added callback */
395 public void removeEventCallback(@ActivityEvent int event, Runnable callback) {
396 mEventCallbacks[event].remove(callback);
Jon Mirandacb582592023-04-19 15:40:04 -0700397 }
398
Winson Chung1a77c3d2018-04-11 12:47:47 -0700399 public interface MultiWindowModeChangedListener {
400 void onMultiWindowModeChanged(boolean isInMultiWindowMode);
401 }
Sunny Goyale43d00d2018-05-14 14:23:18 -0700402
Winson Chungef528762019-09-06 12:05:52 -0700403 protected void dumpMisc(String prefix, PrintWriter writer) {
404 writer.println(prefix + "deviceProfile isTransposed="
405 + getDeviceProfile().isVerticalBarLayout());
406 writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation);
407 writer.println(prefix + "mSystemUiController: " + mSystemUiController);
Mike Schneidera79d4602023-03-03 15:58:06 +0100408 writer.println(prefix + "mActivityFlags: " + getActivityStateString(mActivityFlags));
Winson Chungef528762019-09-06 12:05:52 -0700409 writer.println(prefix + "mForceInvisible: " + mForceInvisible);
Sunny Goyale43d00d2018-05-14 14:23:18 -0700410 }
Sunny Goyal87b5eb62018-07-03 15:53:39 -0700411
412 public static <T extends BaseActivity> T fromContext(Context context) {
413 if (context instanceof BaseActivity) {
414 return (T) context;
Fengjiang Lib2d08452024-04-25 15:51:09 -0700415 } else if (context instanceof ActivityContextDelegate) {
416 return (T) ((ActivityContextDelegate) context).mDelegate;
Tony Wickham1906cc32021-02-11 11:55:24 -0800417 } else if (context instanceof ContextWrapper) {
Sunny Goyal87b5eb62018-07-03 15:53:39 -0700418 return fromContext(((ContextWrapper) context).getBaseContext());
419 } else {
420 throw new IllegalArgumentException("Cannot find BaseActivity in parent tree");
421 }
422 }
Sunny Goyal27835952017-01-13 12:15:53 -0800423}