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