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