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