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 | |
Winson Chung | a0f09f9 | 2018-05-11 21:55:21 +0000 | [diff] [blame] | 19 | import static com.android.launcher3.util.SystemUiController.UI_STATE_OVERVIEW; |
Sunny Goyal | 8c48d8b | 2019-01-25 15:10:18 -0800 | [diff] [blame] | 20 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 21 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 22 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 23 | import android.app.Activity; |
| 24 | import android.content.Context; |
| 25 | import android.content.ContextWrapper; |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 28 | import android.view.ContextThemeWrapper; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 29 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 30 | import androidx.annotation.IntDef; |
| 31 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 32 | import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 33 | import com.android.launcher3.logging.StatsLogManager; |
| 34 | import com.android.launcher3.logging.StatsLogUtils; |
| 35 | import com.android.launcher3.logging.StatsLogUtils.LogStateProvider; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 36 | import com.android.launcher3.logging.UserEventDispatcher; |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 37 | import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate; |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 38 | import com.android.launcher3.userevent.nano.LauncherLogProto; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 39 | import com.android.launcher3.util.SystemUiController; |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 40 | import com.android.launcher3.util.ViewCache; |
Sunny Goyal | fe8e4a9 | 2018-11-13 19:43:57 -0800 | [diff] [blame] | 41 | import com.android.launcher3.views.ActivityContext; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 42 | |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 43 | import java.io.PrintWriter; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 44 | import java.lang.annotation.Retention; |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 45 | import java.util.ArrayList; |
| 46 | |
Sunny Goyal | fe8e4a9 | 2018-11-13 19:43:57 -0800 | [diff] [blame] | 47 | public abstract class BaseActivity extends Activity |
| 48 | implements UserEventDelegate, LogStateProvider, ActivityContext { |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 49 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 50 | public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0; |
| 51 | public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1; |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 52 | public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2; |
| 53 | |
| 54 | // This is not treated as invisibility flag, but adds as a hint for an incomplete transition. |
| 55 | // When the wallpaper animation runs, it replaces this flag with a proper invisibility |
| 56 | // flag, INVISIBLE_BY_PENDING_FLAGS only for the duration of that animation. |
| 57 | public static final int PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION = 1 << 3; |
| 58 | |
| 59 | private static final int INVISIBLE_FLAGS = |
| 60 | INVISIBLE_BY_STATE_HANDLER | INVISIBLE_BY_APP_TRANSITIONS | INVISIBLE_BY_PENDING_FLAGS; |
| 61 | public static final int STATE_HANDLER_INVISIBILITY_FLAGS = |
| 62 | INVISIBLE_BY_STATE_HANDLER | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 63 | public static final int INVISIBLE_ALL = |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 64 | INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 65 | |
| 66 | @Retention(SOURCE) |
| 67 | @IntDef( |
| 68 | flag = true, |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 69 | value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS, |
| 70 | INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION}) |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 71 | public @interface InvisibilityFlags{} |
| 72 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 73 | private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>(); |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 74 | private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners = |
| 75 | new ArrayList<>(); |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 76 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 77 | protected DeviceProfile mDeviceProfile; |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 78 | protected UserEventDispatcher mUserEventDispatcher; |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 79 | protected StatsLogManager mStatsLogManager; |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 80 | protected SystemUiController mSystemUiController; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 81 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 82 | |
| 83 | public static final int ACTIVITY_STATE_STARTED = 1 << 0; |
| 84 | public static final int ACTIVITY_STATE_RESUMED = 1 << 1; |
| 85 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 86 | /** |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 87 | * State flags indicating that the activity has received one frame after resume, and was |
| 88 | * not immediately paused. |
| 89 | */ |
| 90 | public static final int ACTIVITY_STATE_DEFERRED_RESUMED = 1 << 2; |
| 91 | |
| 92 | public static final int ACTIVITY_STATE_WINDOW_FOCUSED = 1 << 3; |
| 93 | |
| 94 | /** |
| 95 | * 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] | 96 | * of user action. |
| 97 | * @see #isUserActive() |
| 98 | */ |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 99 | public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4; |
| 100 | |
| 101 | /** |
| 102 | * State flag indicating that a state transition is in progress |
| 103 | */ |
| 104 | public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 5; |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 105 | |
| 106 | @Retention(SOURCE) |
| 107 | @IntDef( |
| 108 | flag = true, |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 109 | value = {ACTIVITY_STATE_STARTED, |
| 110 | ACTIVITY_STATE_RESUMED, |
| 111 | ACTIVITY_STATE_DEFERRED_RESUMED, |
| 112 | ACTIVITY_STATE_WINDOW_FOCUSED, |
| 113 | ACTIVITY_STATE_USER_ACTIVE, |
| 114 | ACTIVITY_STATE_TRANSITION_ACTIVE}) |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 115 | public @interface ActivityFlags{} |
| 116 | |
| 117 | @ActivityFlags |
| 118 | private int mActivityFlags; |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 119 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 120 | // When the recents animation is running, the visibility of the Launcher is managed by the |
| 121 | // animation |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 122 | @InvisibilityFlags private int mForceInvisible; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 123 | |
Sunny Goyal | 5686333 | 2019-05-22 14:13:53 -0700 | [diff] [blame] | 124 | private final ViewCache mViewCache = new ViewCache(); |
| 125 | |
| 126 | public ViewCache getViewCache() { |
| 127 | return mViewCache; |
| 128 | } |
| 129 | |
Sunny Goyal | fe8e4a9 | 2018-11-13 19:43:57 -0800 | [diff] [blame] | 130 | @Override |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 131 | public DeviceProfile getDeviceProfile() { |
| 132 | return mDeviceProfile; |
| 133 | } |
| 134 | |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 135 | public int getCurrentState() { return StatsLogUtils.LAUNCHER_STATE_BACKGROUND; } |
| 136 | |
Hyunyoung Song | 46d07f7 | 2018-05-22 15:41:25 -0700 | [diff] [blame] | 137 | public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {} |
| 138 | |
Hyunyoung Song | fc00747 | 2018-10-25 14:09:50 -0700 | [diff] [blame] | 139 | public final StatsLogManager getStatsLogManager() { |
| 140 | if (mStatsLogManager == null) { |
| 141 | mStatsLogManager = StatsLogManager.newInstance(this, this); |
| 142 | } |
| 143 | return mStatsLogManager; |
| 144 | } |
| 145 | |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 146 | public final UserEventDispatcher getUserEventDispatcher() { |
| 147 | if (mUserEventDispatcher == null) { |
Hyunyoung Song | 956ec4b | 2018-07-02 13:17:32 -0700 | [diff] [blame] | 148 | mUserEventDispatcher = UserEventDispatcher.newInstance(this, this); |
Sunny Goyal | a535ae4 | 2017-02-27 10:07:13 -0800 | [diff] [blame] | 149 | } |
| 150 | return mUserEventDispatcher; |
| 151 | } |
| 152 | |
Sunny Goyal | 8392c82 | 2017-06-20 10:03:56 -0700 | [diff] [blame] | 153 | public SystemUiController getSystemUiController() { |
| 154 | if (mSystemUiController == null) { |
| 155 | mSystemUiController = new SystemUiController(getWindow()); |
| 156 | } |
| 157 | return mSystemUiController; |
| 158 | } |
Sunny Goyal | 64a75aa | 2017-07-03 13:50:52 -0700 | [diff] [blame] | 159 | |
| 160 | @Override |
| 161 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 162 | super.onActivityResult(requestCode, resultCode, data); |
| 163 | } |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 164 | |
| 165 | @Override |
| 166 | protected void onStart() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 167 | addActivityFlags(ACTIVITY_STATE_STARTED); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 168 | super.onStart(); |
| 169 | } |
| 170 | |
| 171 | @Override |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 172 | protected void onResume() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 173 | addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 174 | super.onResume(); |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | protected void onUserLeaveHint() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 179 | removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE); |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 180 | super.onUserLeaveHint(); |
| 181 | } |
| 182 | |
| 183 | @Override |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 184 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) { |
| 185 | super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig); |
| 186 | for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) { |
| 187 | mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | @Override |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 192 | protected void onStop() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 193 | removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE); |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 194 | mForceInvisible = 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 195 | super.onStop(); |
Winson Chung | a36c800 | 2019-06-11 16:15:54 -0700 | [diff] [blame] | 196 | |
| 197 | // Reset the overridden sysui flags used for the task-swipe launch animation, this is a |
| 198 | // catch all for if we do not get resumed (and therefore not paused below) |
| 199 | getSystemUiController().updateUiState(UI_STATE_OVERVIEW, 0); |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 202 | @Override |
| 203 | protected void onPause() { |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 204 | removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 205 | super.onPause(); |
Winson Chung | a0f09f9 | 2018-05-11 21:55:21 +0000 | [diff] [blame] | 206 | |
| 207 | // Reset the overridden sysui flags used for the task-swipe launch animation, we do this |
| 208 | // here instead of at the end of the animation because the start of the new activity does |
| 209 | // not happen immediately, which would cause us to reset to launcher's sysui flags and then |
| 210 | // back to the new app (causing a flash) |
| 211 | getSystemUiController().updateUiState(UI_STATE_OVERVIEW, 0); |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 214 | @Override |
| 215 | public void onWindowFocusChanged(boolean hasFocus) { |
| 216 | super.onWindowFocusChanged(hasFocus); |
| 217 | if (hasFocus) { |
| 218 | addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 219 | } else { |
| 220 | removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED); |
| 221 | } |
| 222 | |
| 223 | } |
| 224 | |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 225 | public boolean isStarted() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 226 | return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * isResumed in already defined as a hidden final method in Activity.java |
| 231 | */ |
| 232 | public boolean hasBeenResumed() { |
| 233 | return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0; |
Sunny Goyal | cc96aa1 | 2018-01-11 09:56:07 -0800 | [diff] [blame] | 234 | } |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 235 | |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 236 | public boolean isUserActive() { |
Sunny Goyal | 3483c52 | 2018-04-12 11:23:33 -0700 | [diff] [blame] | 237 | return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0; |
Tracy Zhou | a706f00 | 2018-03-28 13:55:19 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 240 | public int getActivityFlags() { |
| 241 | return mActivityFlags; |
| 242 | } |
| 243 | |
| 244 | protected void addActivityFlags(int flags) { |
| 245 | mActivityFlags |= flags; |
| 246 | onActivityFlagsChanged(flags); |
| 247 | } |
| 248 | |
| 249 | protected void removeActivityFlags(int flags) { |
| 250 | mActivityFlags &= ~flags; |
| 251 | onActivityFlagsChanged(flags); |
| 252 | } |
| 253 | |
| 254 | protected void onActivityFlagsChanged(int changeBits) { } |
| 255 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 256 | public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) { |
| 257 | mDPChangeListeners.add(listener); |
| 258 | } |
| 259 | |
Winson Chung | 8a968fa | 2018-03-15 17:59:04 -0700 | [diff] [blame] | 260 | public void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) { |
| 261 | mDPChangeListeners.remove(listener); |
| 262 | } |
| 263 | |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 264 | protected void dispatchDeviceProfileChanged() { |
Winson Chung | 8a968fa | 2018-03-15 17:59:04 -0700 | [diff] [blame] | 265 | for (int i = mDPChangeListeners.size() - 1; i >= 0; i--) { |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 266 | mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile); |
| 267 | } |
| 268 | } |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 269 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 270 | public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 271 | mMultiWindowModeChangedListeners.add(listener); |
| 272 | } |
| 273 | |
| 274 | public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) { |
| 275 | mMultiWindowModeChangedListeners.remove(listener); |
| 276 | } |
| 277 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 278 | /** |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 279 | * Used to set the override visibility state, used only to handle the transition home with the |
| 280 | * recents animation. |
Sunny Goyal | 210e174 | 2019-10-17 12:05:38 -0700 | [diff] [blame] | 281 | * @see QuickstepAppTransitionManagerImpl#getWallpaperOpenRunner |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 282 | */ |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 283 | public void addForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 284 | mForceInvisible |= flag; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Sunny Goyal | 7eff40f | 2018-04-11 15:30:46 -0700 | [diff] [blame] | 287 | public void clearForceInvisibleFlag(@InvisibilityFlags int flag) { |
| 288 | mForceInvisible &= ~flag; |
| 289 | } |
| 290 | |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 291 | /** |
| 292 | * @return Wether this activity should be considered invisible regardless of actual visibility. |
| 293 | */ |
| 294 | public boolean isForceInvisible() { |
Sunny Goyal | 1c63c72 | 2018-06-05 16:00:34 -0700 | [diff] [blame] | 295 | return hasSomeInvisibleFlag(INVISIBLE_FLAGS); |
| 296 | } |
| 297 | |
| 298 | public boolean hasSomeInvisibleFlag(int mask) { |
| 299 | return (mForceInvisible & mask) != 0; |
Winson Chung | 9800e73 | 2018-04-04 13:33:23 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Winson Chung | 1a77c3d | 2018-04-11 12:47:47 -0700 | [diff] [blame] | 302 | public interface MultiWindowModeChangedListener { |
| 303 | void onMultiWindowModeChanged(boolean isInMultiWindowMode); |
| 304 | } |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 305 | |
Winson Chung | ef52876 | 2019-09-06 12:05:52 -0700 | [diff] [blame] | 306 | protected void dumpMisc(String prefix, PrintWriter writer) { |
| 307 | writer.println(prefix + "deviceProfile isTransposed=" |
| 308 | + getDeviceProfile().isVerticalBarLayout()); |
| 309 | writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation); |
| 310 | writer.println(prefix + "mSystemUiController: " + mSystemUiController); |
| 311 | writer.println(prefix + "mActivityFlags: " + mActivityFlags); |
| 312 | writer.println(prefix + "mForceInvisible: " + mForceInvisible); |
Sunny Goyal | e43d00d | 2018-05-14 14:23:18 -0700 | [diff] [blame] | 313 | } |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 314 | |
| 315 | public static <T extends BaseActivity> T fromContext(Context context) { |
| 316 | if (context instanceof BaseActivity) { |
| 317 | return (T) context; |
| 318 | } else if (context instanceof ContextThemeWrapper) { |
| 319 | return fromContext(((ContextWrapper) context).getBaseContext()); |
| 320 | } else { |
| 321 | throw new IllegalArgumentException("Cannot find BaseActivity in parent tree"); |
| 322 | } |
| 323 | } |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 324 | } |