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