Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Hyunyoung Song | 7f7894e | 2020-04-27 01:12:01 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION; |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 21 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 22 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 23 | import android.app.ActivityOptions; |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 24 | import android.app.WallpaperColors; |
| 25 | import android.app.WallpaperManager; |
| 26 | import android.app.WallpaperManager.OnColorsChangedListener; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 28 | import android.content.Context; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 30 | import android.content.pm.LauncherApps; |
Lucas Dupin | eca08a1 | 2018-08-11 15:53:40 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 32 | import android.graphics.Insets; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 35 | import android.graphics.drawable.Drawable; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
| 37 | import android.os.Process; |
| 38 | import android.os.StrictMode; |
| 39 | import android.os.UserHandle; |
| 40 | import android.util.Log; |
| 41 | import android.view.ActionMode; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 42 | import android.view.Display; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 43 | import android.view.View; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 44 | import android.view.View.OnClickListener; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 45 | import android.view.WindowInsets.Type; |
| 46 | import android.view.WindowMetrics; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 47 | import android.widget.Toast; |
| 48 | |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 49 | import androidx.annotation.NonNull; |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 50 | import androidx.annotation.Nullable; |
| 51 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 52 | import com.android.launcher3.LauncherSettings.Favorites; |
Samuel Fufa | a60d1f9 | 2021-01-12 20:39:46 -0600 | [diff] [blame] | 53 | import com.android.launcher3.allapps.AllAppsContainerView; |
Samuel Fufa | fd58d23 | 2021-01-12 12:59:39 -0600 | [diff] [blame] | 54 | import com.android.launcher3.allapps.search.DefaultSearchAdapterProvider; |
| 55 | import com.android.launcher3.allapps.search.SearchAdapterProvider; |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 56 | import com.android.launcher3.logging.InstanceId; |
| 57 | import com.android.launcher3.logging.InstanceIdSequence; |
Sunny Goyal | e396abf | 2020-04-06 15:11:17 -0700 | [diff] [blame] | 58 | import com.android.launcher3.model.data.ItemInfo; |
| 59 | import com.android.launcher3.model.data.WorkspaceItemInfo; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 60 | import com.android.launcher3.touch.ItemClickHandler; |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 61 | import com.android.launcher3.util.ActivityOptionsWrapper; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 62 | import com.android.launcher3.util.DisplayController; |
| 63 | import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener; |
| 64 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 9dbb27c | 2019-07-17 15:12:56 -0700 | [diff] [blame] | 65 | import com.android.launcher3.util.PackageManagerHelper; |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 66 | import com.android.launcher3.util.RunnableList; |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 67 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 68 | import com.android.launcher3.util.TraceHelper; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 69 | import com.android.launcher3.util.WindowBounds; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Extension of BaseActivity allowing support for drag-n-drop |
| 73 | */ |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 74 | @SuppressWarnings("NewApi") |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 75 | public abstract class BaseDraggingActivity extends BaseActivity |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 76 | implements OnColorsChangedListener, DisplayInfoChangeListener { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 77 | |
| 78 | private static final String TAG = "BaseDraggingActivity"; |
| 79 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 80 | // When starting an action mode, setting this tag will cause the action mode to be cancelled |
| 81 | // automatically when user interacts with the launcher. |
| 82 | public static final Object AUTO_CANCEL_ACTION_MODE = new Object(); |
| 83 | |
| 84 | private ActionMode mCurrentActionMode; |
| 85 | protected boolean mIsSafeModeEnabled; |
| 86 | |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 87 | private Runnable mOnStartCallback; |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 88 | private RunnableList mOnResumeCallbacks = new RunnableList(); |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 89 | |
Sunny Goyal | bd88f39 | 2018-06-07 15:42:57 -0700 | [diff] [blame] | 90 | private int mThemeRes = R.style.AppTheme; |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 91 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 92 | @Override |
| 93 | protected void onCreate(Bundle savedInstanceState) { |
| 94 | super.onCreate(savedInstanceState); |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 95 | |
Sunny Goyal | 5d09b2e | 2020-07-09 12:21:40 -0700 | [diff] [blame] | 96 | mIsSafeModeEnabled = TraceHelper.allowIpcs("isSafeMode", |
Sunny Goyal | 17c72fb | 2019-10-14 14:06:38 -0700 | [diff] [blame] | 97 | () -> getPackageManager().isSafeMode()); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 98 | DisplayController.INSTANCE.get(this).addChangeListener(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 99 | |
| 100 | // Update theme |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 101 | if (Utilities.ATLEAST_P) { |
| 102 | getSystemService(WallpaperManager.class) |
| 103 | .addOnColorsChangedListener(this, MAIN_EXECUTOR.getHandler()); |
| 104 | } |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 105 | int themeRes = Themes.getActivityThemeRes(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 106 | if (themeRes != mThemeRes) { |
| 107 | mThemeRes = themeRes; |
| 108 | setTheme(themeRes); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | @Override |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 113 | protected void onResume() { |
| 114 | super.onResume(); |
| 115 | mOnResumeCallbacks.executeAllAndClear(); |
| 116 | } |
| 117 | |
| 118 | public void addOnResumeCallback(Runnable callback) { |
| 119 | mOnResumeCallbacks.add(callback); |
| 120 | } |
| 121 | |
| 122 | @Override |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 123 | public void onColorsChanged(WallpaperColors wallpaperColors, int which) { |
Lucas Dupin | eca08a1 | 2018-08-11 15:53:40 -0700 | [diff] [blame] | 124 | updateTheme(); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void onConfigurationChanged(Configuration newConfig) { |
| 129 | super.onConfigurationChanged(newConfig); |
| 130 | updateTheme(); |
| 131 | } |
| 132 | |
| 133 | private void updateTheme() { |
Hyunyoung Song | fcd090d | 2019-05-01 13:15:29 -0700 | [diff] [blame] | 134 | if (mThemeRes != Themes.getActivityThemeRes(this)) { |
Winson Chung | c4bef35 | 2020-10-28 00:13:03 -0700 | [diff] [blame] | 135 | recreate(); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 139 | @Override |
| 140 | public void onActionModeStarted(ActionMode mode) { |
| 141 | super.onActionModeStarted(mode); |
| 142 | mCurrentActionMode = mode; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onActionModeFinished(ActionMode mode) { |
| 147 | super.onActionModeFinished(mode); |
| 148 | mCurrentActionMode = null; |
| 149 | } |
| 150 | |
Sunny Goyal | 87b5eb6 | 2018-07-03 15:53:39 -0700 | [diff] [blame] | 151 | @Override |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 152 | public boolean finishAutoCancelActionMode() { |
| 153 | if (mCurrentActionMode != null && AUTO_CANCEL_ACTION_MODE == mCurrentActionMode.getTag()) { |
| 154 | mCurrentActionMode.finish(); |
| 155 | return true; |
| 156 | } |
| 157 | return false; |
| 158 | } |
| 159 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 160 | public abstract <T extends View> T getOverviewPanel(); |
| 161 | |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 162 | public abstract View getRootView(); |
| 163 | |
Vinit Nayak | f9b585b | 2019-07-10 14:25:32 -0700 | [diff] [blame] | 164 | public void returnToHomescreen() { |
| 165 | // no-op |
| 166 | } |
| 167 | |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 168 | public Rect getViewBounds(View v) { |
| 169 | int[] pos = new int[2]; |
| 170 | v.getLocationOnScreen(pos); |
| 171 | return new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); |
| 172 | } |
| 173 | |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 174 | @NonNull |
Winson Chung | 2b09394 | 2021-04-09 14:00:25 -0700 | [diff] [blame] | 175 | public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) { |
Sunny Goyal | b65d766 | 2021-03-07 15:09:11 -0800 | [diff] [blame] | 176 | int left = 0, top = 0; |
| 177 | int width = v.getMeasuredWidth(), height = v.getMeasuredHeight(); |
| 178 | if (v instanceof BubbleTextView) { |
| 179 | // Launch from center of icon, not entire view |
| 180 | Drawable icon = ((BubbleTextView) v).getIcon(); |
| 181 | if (icon != null) { |
| 182 | Rect bounds = icon.getBounds(); |
| 183 | left = (width - bounds.width()) / 2; |
| 184 | top = v.getPaddingTop(); |
| 185 | width = bounds.width(); |
| 186 | height = bounds.height(); |
| 187 | } |
| 188 | } |
| 189 | ActivityOptions options = |
| 190 | ActivityOptions.makeClipRevealAnimation(v, left, top, width, height); |
| 191 | RunnableList callback = new RunnableList(); |
| 192 | addOnResumeCallback(callback::executeAllAndDestroy); |
| 193 | return new ActivityOptionsWrapper(options, callback); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 196 | public boolean startActivitySafely(View v, Intent intent, @Nullable ItemInfo item) { |
Sunny Goyal | 9dbb27c | 2019-07-17 15:12:56 -0700 | [diff] [blame] | 197 | if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 198 | Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); |
| 199 | return false; |
| 200 | } |
| 201 | |
Winson Chung | 2b09394 | 2021-04-09 14:00:25 -0700 | [diff] [blame] | 202 | Bundle optsBundle = (v != null) ? getActivityLaunchOptions(v, item).toBundle() : null; |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 203 | UserHandle user = item == null ? null : item.user; |
| 204 | |
| 205 | // Prepare intent |
| 206 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 207 | if (v != null) { |
| 208 | intent.setSourceBounds(getViewBounds(v)); |
| 209 | } |
| 210 | try { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 211 | boolean isShortcut = (item instanceof WorkspaceItemInfo) |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 212 | && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT |
| 213 | || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 214 | && !((WorkspaceItemInfo) item).isPromise(); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 215 | if (isShortcut) { |
| 216 | // Shortcuts need some special checks due to legacy reasons. |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 217 | startShortcutIntentSafely(intent, optsBundle, item); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 218 | } else if (user == null || user.equals(Process.myUserHandle())) { |
| 219 | // Could be launching some bookkeeping activity |
| 220 | startActivity(intent, optsBundle); |
| 221 | } else { |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 222 | getSystemService(LauncherApps.class).startMainActivity( |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 223 | intent.getComponent(), user, intent.getSourceBounds(), optsBundle); |
| 224 | } |
Hyunyoung Song | f26c793 | 2020-06-06 14:44:27 -0700 | [diff] [blame] | 225 | if (item != null) { |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 226 | InstanceId instanceId = new InstanceIdSequence().newInstanceId(); |
| 227 | logAppLaunch(item, instanceId); |
Hyunyoung Song | f26c793 | 2020-06-06 14:44:27 -0700 | [diff] [blame] | 228 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 229 | return true; |
Samuel Fufa | fd58d23 | 2021-01-12 12:59:39 -0600 | [diff] [blame] | 230 | } catch (NullPointerException | ActivityNotFoundException | SecurityException e) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 231 | Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); |
| 232 | Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); |
| 233 | } |
| 234 | return false; |
| 235 | } |
| 236 | |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 237 | protected void logAppLaunch(ItemInfo info, InstanceId instanceId) { |
thiruram | c6a38ba | 2020-06-16 18:58:13 -0700 | [diff] [blame] | 238 | getStatsLogManager().logger().withItemInfo(info).withInstanceId(instanceId) |
| 239 | .log(LAUNCHER_APP_LAUNCH_TAP); |
Samuel Fufa | e9c4f40 | 2020-06-14 22:39:51 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Sunny Goyal | 852537f | 2020-07-15 17:02:16 -0700 | [diff] [blame] | 242 | private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) { |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 243 | try { |
| 244 | StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy(); |
| 245 | try { |
| 246 | // Temporarily disable deathPenalty on all default checks. For eg, shortcuts |
| 247 | // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure |
| 248 | // is enabled by default on NYC. |
| 249 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll() |
| 250 | .penaltyLog().build()); |
| 251 | |
| 252 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { |
Sunny Goyal | 9589916 | 2019-03-27 16:03:06 -0700 | [diff] [blame] | 253 | String id = ((WorkspaceItemInfo) info).getDeepShortcutId(); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 254 | String packageName = intent.getPackage(); |
Sunny Goyal | fa39536 | 2019-12-11 10:00:47 -0800 | [diff] [blame] | 255 | startShortcut(packageName, id, intent.getSourceBounds(), optsBundle, info.user); |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 256 | } else { |
| 257 | // Could be launching some bookkeeping activity |
| 258 | startActivity(intent, optsBundle); |
| 259 | } |
| 260 | } finally { |
| 261 | StrictMode.setVmPolicy(oldPolicy); |
| 262 | } |
| 263 | } catch (SecurityException e) { |
| 264 | if (!onErrorStartingShortcut(intent, info)) { |
| 265 | throw e; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | protected boolean onErrorStartingShortcut(Intent intent, ItemInfo info) { |
| 271 | return false; |
| 272 | } |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 273 | |
| 274 | @Override |
| 275 | protected void onStart() { |
| 276 | super.onStart(); |
| 277 | |
| 278 | if (mOnStartCallback != null) { |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 279 | mOnStartCallback.run(); |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 280 | mOnStartCallback = null; |
| 281 | } |
| 282 | } |
| 283 | |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 284 | @Override |
| 285 | protected void onDestroy() { |
| 286 | super.onDestroy(); |
Sunny Goyal | 4ed0fb5 | 2021-04-26 09:52:47 -0700 | [diff] [blame^] | 287 | if (Utilities.ATLEAST_P) { |
| 288 | getSystemService(WallpaperManager.class).removeOnColorsChangedListener(this); |
| 289 | } |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 290 | DisplayController.INSTANCE.get(this).removeChangeListener(this); |
Sunny Goyal | ab83773 | 2018-03-27 17:35:54 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Winson Chung | a19a2b7 | 2019-10-14 16:30:38 -0700 | [diff] [blame] | 293 | public void runOnceOnStart(Runnable action) { |
| 294 | mOnStartCallback = action; |
| 295 | } |
| 296 | |
| 297 | public void clearRunOnceOnStartCallback() { |
| 298 | mOnStartCallback = null; |
Sunny Goyal | 9d69c8d | 2018-03-19 13:41:31 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 301 | protected void onDeviceProfileInitiated() { |
| 302 | if (mDeviceProfile.isVerticalBarLayout()) { |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 303 | mDeviceProfile.updateIsSeascape(this); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 307 | @Override |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 308 | public void onDisplayInfoChanged(Context context, Info info, int flags) { |
Sunny Goyal | 9f56a2f | 2020-02-03 14:22:09 -0800 | [diff] [blame] | 309 | if ((flags & CHANGE_ROTATION) != 0 && mDeviceProfile.updateIsSeascape(this)) { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 310 | reapplyUi(); |
| 311 | } |
| 312 | } |
| 313 | |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 314 | public OnClickListener getItemOnClickListener() { |
| 315 | return ItemClickHandler.INSTANCE; |
| 316 | } |
| 317 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 318 | protected abstract void reapplyUi(); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 319 | |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 320 | protected WindowBounds getMultiWindowDisplaySize() { |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 321 | if (Utilities.ATLEAST_R) { |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 322 | WindowMetrics wm = getWindowManager().getCurrentWindowMetrics(); |
| 323 | |
| 324 | Insets insets = wm.getWindowInsets().getInsets(Type.systemBars()); |
| 325 | return new WindowBounds(wm.getBounds(), |
| 326 | new Rect(insets.left, insets.top, insets.right, insets.bottom)); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 327 | } |
| 328 | // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return |
| 329 | // the app window size |
| 330 | Display display = getWindowManager().getDefaultDisplay(); |
| 331 | Point mwSize = new Point(); |
| 332 | display.getSize(mwSize); |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 333 | return new WindowBounds(new Rect(0, 0, mwSize.x, mwSize.y), new Rect()); |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 334 | } |
Samuel Fufa | fd58d23 | 2021-01-12 12:59:39 -0600 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Creates and returns {@link SearchAdapterProvider} for build variant specific search result |
| 338 | * views |
| 339 | */ |
Samuel Fufa | a60d1f9 | 2021-01-12 20:39:46 -0600 | [diff] [blame] | 340 | public SearchAdapterProvider createSearchAdapterProvider(AllAppsContainerView allapps) { |
Hyunyoung Song | c07e3b3 | 2021-03-28 23:46:50 -0700 | [diff] [blame] | 341 | return new DefaultSearchAdapterProvider(this, allapps); |
Samuel Fufa | fd58d23 | 2021-01-12 12:59:39 -0600 | [diff] [blame] | 342 | } |
Sunny Goyal | 0b0847b | 2018-03-14 12:30:11 -0700 | [diff] [blame] | 343 | } |