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