blob: 81aa2b278213085c4f146168d3f90cc6d3a60d30 [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
Thales Lima1de4d552021-10-13 16:13:25 +01002 * Copyright (C) 2021 The Android Open Source Project
Adam Cohen2e6da152015-05-06 11:42:25 -07003 *
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
17package com.android.launcher3;
18
Stefan Andonian4c9612b2023-02-22 00:00:03 +000019import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070020import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030021import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Alex Chau6ed408f2022-03-04 12:58:05 +000023import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070024import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080025import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070026
Sunny Goyalc6205602015-05-21 20:46:33 -070027import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070028import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080029import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080030import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070031import android.content.res.TypedArray;
32import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070033import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010034import android.graphics.PointF;
Sunny Goyal415f1732018-11-29 10:33:47 -080035import android.text.TextUtils;
36import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070037import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010038import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080039import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070040import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080041import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070042
Thales Limab35faed2022-09-05 16:30:01 -030043import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000044import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030045import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070046import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000047import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010048import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070049
Thales Limaec5abba2023-04-05 16:33:50 +010050import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070051import com.android.launcher3.icons.DotRenderer;
Sunny Goyal68031ca2021-08-02 12:23:44 -070052import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010053import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070054import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070055import com.android.launcher3.util.DisplayController;
56import com.android.launcher3.util.DisplayController.Info;
Stefan Andonian5bd9a222023-02-23 00:58:33 +000057import com.android.launcher3.util.LockedUserState;
Sunny Goyald0e360a2018-06-29 14:40:18 -070058import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080059import com.android.launcher3.util.Partner;
Sunny Goyal19ff7282021-04-22 10:12:54 -070060import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080061import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070062
Sunny Goyal819e1932016-07-07 16:43:58 -070063import org.xmlpull.v1.XmlPullParser;
64import org.xmlpull.v1.XmlPullParserException;
65
66import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000067import java.lang.annotation.Retention;
68import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070069import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070070import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080071import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070072import java.util.List;
Sunny Goyal076e04b2023-04-03 12:38:30 -070073import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070074
75public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070076
Hyunyoung Songc55a3502018-12-04 15:43:16 -080077 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070078 // We do not need any synchronization for this variable as its only written on UI thread.
79 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070080 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070081
Alex Chau1c883d82021-12-01 18:43:10 +000082 @Retention(RetentionPolicy.SOURCE)
83 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010084 public @interface DeviceType {}
85
Alex Chau1c883d82021-12-01 18:43:10 +000086 public static final int TYPE_PHONE = 0;
87 public static final int TYPE_MULTI_DISPLAY = 1;
88 public static final int TYPE_TABLET = 2;
89
Sunny Goyal53d7ee42015-05-22 12:25:45 -070090 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
91
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070092 // Constants that affects the interpolation curve between statically defined device profile
93 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080094 private static final float KNEARESTNEIGHBOR = 3;
95 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070096
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070097 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080098 private static final float WEIGHT_EFFICIENT = 100000f;
99
Thales Lima83bedbf2021-10-05 17:47:39 +0100100 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
101 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000102 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100103 static final int INDEX_DEFAULT = 0;
104 static final int INDEX_LANDSCAPE = 1;
105 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
106 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100107
Thales Limaec5abba2023-04-05 16:33:50 +0100108 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800109 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
110 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
111 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
112
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700113 /**
114 * Number of icons per row and column in the workspace.
115 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700116 public int numRows;
117 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000118 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700119
120 /**
121 * Number of icons per row and column in the folder.
122 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700123 public int numFolderRows;
124 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public float[] iconSize;
126 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700127 public int iconBitmapSize;
128 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000129 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700130
Thales Lima83bedbf2021-10-05 17:47:39 +0100131 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100132
Thales Lima83bedbf2021-10-05 17:47:39 +0100133 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300134 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100135
Thales Limab35faed2022-09-05 16:30:01 -0300136 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100137
Thales Limad852d652023-01-17 14:01:13 +0000138 public @StyleRes int cellStyle;
139
Thales Lima83bedbf2021-10-05 17:47:39 +0100140 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500141
Thales Limab7ef5692022-03-10 10:32:36 +0000142 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000143 public float[] allAppsIconSize;
144 public float[] allAppsIconTextSize;
145 public PointF[] allAppsBorderSpaces;
146
Jon Miranda9c478b62023-03-23 21:38:49 -0700147 public float[] transientTaskbarIconSize;
148
Jon Miranda04f05102023-04-04 12:16:31 -0700149 public boolean[] startAlignTaskbar;
150
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700151 /**
152 * Number of icons inside the hotseat area.
153 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800154 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700155
156 /**
157 * Number of icons inside the hotseat area that is stored in the database. This is greater than
158 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
159 * sizes that share the same DB.
160 */
161 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700162
Thales Lima425f6822022-05-10 13:44:58 -0300163 public int[] hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100164 public float[] hotseatBarBottomSpace;
165 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300166
Jon Miranda6f7e9702019-09-16 14:44:14 -0700167 /**
168 * Number of columns in the all apps list.
169 */
170 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700171 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000172 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700173
Jon Mirandae126d722021-02-25 10:45:20 -0500174 /**
175 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
176 */
177 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000178 @XmlRes
179 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100180 @XmlRes
181 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100182 @XmlRes
183 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500184
Tracy Zhou7df93d22020-01-27 13:44:06 -0800185 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800186 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700187 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100188 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700189
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000190 /**
191 * An immutable list of supported profiles.
192 */
193 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700194
Sunny Goyal6f866092016-03-17 17:04:15 -0700195 public Point defaultWallpaperSize;
196
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700197 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700198
Sunny Goyalf633ef52018-03-13 09:57:05 -0700199 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800200 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700201
Sunny Goyalbbf01842015-10-08 07:41:15 -0700202 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700203 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700204 String gridName = getCurrentGridName(context);
205 String newGridName = initGrid(context, gridName);
206 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000207 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700208 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000209 LockedUserState.get(context).runOnUserUnlocked(() -> {
210 new DeviceGridState(this).writeToPrefs(context);
211 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700212
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700213 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100214 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000215 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
216 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100217 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700218 }
219 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700220 }
221
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700222 /**
223 * This constructor should NOT have any monitors by design.
224 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800225 public InvariantDeviceProfile(Context context, String gridName) {
226 String newName = initGrid(context, gridName);
227 if (newName == null || !newName.equals(gridName)) {
228 throw new IllegalArgumentException("Unknown grid name");
229 }
230 }
231
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700232 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800233 * This constructor should NOT have any monitors by design.
234 */
235 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100237 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700238 String gridName = getCurrentGridName(context);
239
240 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000241 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
242 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700243 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000244 defaultInfo,
245 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
246 /*allowDisabledGrid=*/false),
247 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700248
Alex Chau661f02d2022-06-07 14:03:43 +0100249 Context displayContext = context.createDisplayContext(display);
250 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000251 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700252 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000253 myInfo,
254 getPredefinedDeviceProfiles(context, gridName, deviceType,
255 /*allowDisabledGrid=*/false),
256 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700257
258 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
259 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100260 result.iconSizes[INDEX_DEFAULT] =
261 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
262 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700263 result.iconSizes[i] = Math.min(
264 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000265 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700266
Thales Lima83bedbf2021-10-05 17:47:39 +0100267 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
268 COUNT_SIZES);
269 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
270 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500271
Alex Chau1c883d82021-12-01 18:43:10 +0000272 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800273 }
274
Alex Chau238aaee2021-10-06 16:15:24 +0100275 /**
276 * Reinitialize the current grid after a restore, where some grids might now be disabled.
277 */
278 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000279 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100280 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000281 String newGridName = initGrid(context, currentGridName);
282 String newDbFile = dbFile;
283 if (!newDbFile.equals(currentDbFile)) {
284 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100285 + ", migrating to: " + newGridName
286 + ", removing all other grid db files");
287 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
288 if (gridDbFile.equals(currentDbFile)) {
289 continue;
290 }
291 if (context.getDatabasePath(gridDbFile).delete()) {
292 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
293 }
294 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000295 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100296 }
297 }
298
Alex Chau1c883d82021-12-01 18:43:10 +0000299 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800300 int flagPhone = 1 << 0;
301 int flagTablet = 1 << 1;
302
303 int type = displayInfo.supportedBounds.stream()
304 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
305 .reduce(0, (a, b) -> a | b);
Sebastian Franco76a1ceb2023-06-08 13:26:20 -0700306 if ((type == (flagPhone | flagTablet))) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800307 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000308 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800309 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000310 return TYPE_TABLET;
311 } else {
312 return TYPE_PHONE;
313 }
314 }
315
Tracy Zhou42255d22020-03-13 00:38:11 -0700316 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000317 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700318 }
319
Sunny Goyaleff44f32019-01-09 17:29:49 -0800320 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700321 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000322 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700323
324 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000325 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100326 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700327 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000328 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
329 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700330 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800331 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700332
Thales Limab67bfa72022-11-02 15:30:11 +0000333 @VisibleForTesting
334 public static String getDefaultGridName(Context context) {
335 return new InvariantDeviceProfile().initGrid(context, null);
336 }
337
Alex Chau1c883d82021-12-01 18:43:10 +0000338 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
339 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700340 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700341 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000342 numRows = closestProfile.numRows;
343 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000344 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000345 dbFile = closestProfile.dbFile;
346 defaultLayoutId = closestProfile.defaultLayoutId;
347 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300348
Sunny Goyalae190ff2020-04-14 00:19:01 +0000349 numFolderRows = closestProfile.numFolderRows;
350 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300351 folderStyle = closestProfile.folderStyle;
352
Thales Limad852d652023-01-17 14:01:13 +0000353 cellStyle = closestProfile.cellStyle;
354
Jon Mirandae126d722021-02-25 10:45:20 -0500355 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400356 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100357 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Thales Limaabfe3642023-05-24 18:08:53 +0100358 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Alex Chau1c883d82021-12-01 18:43:10 +0000359 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000360
Vinit Nayakc7293172022-07-18 16:41:50 -0700361 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
362
Thales Lima83bedbf2021-10-05 17:47:39 +0100363 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100364 float maxIconSize = iconSize[0];
365 for (int i = 1; i < iconSize.length; i++) {
366 maxIconSize = Math.max(maxIconSize, iconSize[i]);
367 }
368 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000369 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
370
Thales Lima83bedbf2021-10-05 17:47:39 +0100371 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700372
Thales Lima83bedbf2021-10-05 17:47:39 +0100373 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100374
Thales Lima83bedbf2021-10-05 17:47:39 +0100375 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100376
Thales Limad90faab2021-09-21 17:18:47 +0100377 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100378
Sunny Goyal19ff7282021-04-22 10:12:54 -0700379 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000380 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700381 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300382 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100383 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
384 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700385
Thales Limae9273ea2023-01-26 12:33:52 +0000386 allAppsStyle = closestProfile.allAppsStyle;
387
Sunny Goyal19ff7282021-04-22 10:12:54 -0700388 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000389 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700390 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500391
Thales Limab7ef5692022-03-10 10:32:36 +0000392 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000393 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
394 allAppsIconSize = displayOption.allAppsIconSizes;
395 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000396
Thales Lima11af7bc2022-08-12 15:24:54 +0100397 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000398
Jon Miranda9c478b62023-03-23 21:38:49 -0700399 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
400
Jon Miranda04f05102023-04-04 12:16:31 -0700401 startAlignTaskbar = displayOption.startAlignTaskbar;
402
Sunny Goyalae190ff2020-04-14 00:19:01 +0000403 // If the partner customization apk contains any grid overrides, apply them
404 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700405 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700406
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000407 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700408 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700409 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700410 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000411 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000412 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000413 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700414 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000415 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700416
Sunny Goyal19ff7282021-04-22 10:12:54 -0700417 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
418 int displayWidth = bounds.bounds.width();
419 int displayHeight = bounds.bounds.height();
420 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700421
Sunny Goyal19ff7282021-04-22 10:12:54 -0700422 // We need to ensure that there is enough extra space in the wallpaper
423 // for the intended parallax effects
424 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300425 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
426 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700427 ? 2
428 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
429 defaultWallpaperSize.x =
430 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700431 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000432 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700433
Thales Lima6a590062022-11-22 15:52:49 +0000434 int numMinShownHotseatIconsForTablet = supportedProfiles
435 .stream()
436 .filter(deviceProfile -> deviceProfile.isTablet)
437 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
438 .min()
439 .orElse(0);
440
441 supportedProfiles
442 .stream()
443 .filter(deviceProfile -> deviceProfile.isTablet)
444 .forEach(deviceProfile -> {
445 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
446 deviceProfile.recalculateHotseatWidthAndBorderSpace();
447 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700448 }
449
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700450 public void addOnChangeListener(OnIDPChangeListener listener) {
451 mChangeListeners.add(listener);
452 }
453
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800454 public void removeOnChangeListener(OnIDPChangeListener listener) {
455 mChangeListeners.remove(listener);
456 }
457
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800458
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800459 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000460 LauncherPrefs.get(context).put(GRID_NAME, gridName);
461 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800462 }
463
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700464 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700465 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000466 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
467 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700468 }
469
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700470 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700471 Object[] oldState = toModelState();
472
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700473 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700474 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700475 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700476
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700477 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700478 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700479 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700480 }
481 }
482
Alex Chau1c883d82021-12-01 18:43:10 +0000483 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
484 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800485 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100486
Alex Chau1c883d82021-12-01 18:43:10 +0000487 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700488 final int depth = parser.getDepth();
489 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700490 while (((type = parser.next()) != XmlPullParser.END_TAG ||
491 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800492 if ((type == XmlPullParser.START_TAG)
493 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800494
Sunny Goyal076e04b2023-04-03 12:38:30 -0700495 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
496 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100497 final int displayDepth = parser.getDepth();
498 while (((type = parser.next()) != XmlPullParser.END_TAG
499 || parser.getDepth() > displayDepth)
500 && type != XmlPullParser.END_DOCUMENT) {
501 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
502 parser.getName())) {
503 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100504 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100505 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800506 }
507 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700508 }
509 }
sfufa@google.comde013292021-09-21 18:22:44 -0700510 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700511 throw new RuntimeException(e);
512 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800513
Sunny Goyalae190ff2020-04-14 00:19:01 +0000514 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800515 if (!TextUtils.isEmpty(gridName)) {
516 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100517 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700518 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000519 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800520 }
521 }
522 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000523 if (filteredProfiles.isEmpty()) {
524 // No grid found, use the default options
525 for (DisplayOption option : profiles) {
526 if (option.canBeDefault) {
527 filteredProfiles.add(option);
528 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800529 }
530 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000531 if (filteredProfiles.isEmpty()) {
532 throw new RuntimeException("No display option with canBeDefault=true");
533 }
534 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700535 }
536
Thales Lima7ec83822021-08-05 13:32:10 +0100537 /**
538 * @return all the grid options that can be shown on the device
539 */
540 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700541 return parseAllDefinedGridOptions(context)
542 .stream()
543 .filter(go -> go.isEnabled(deviceType))
544 .collect(Collectors.toList());
545 }
546
547 /**
548 * @return all the grid options that can be shown on the device
549 */
550 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100551 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100552
Alex Chau1c883d82021-12-01 18:43:10 +0000553 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100554 final int depth = parser.getDepth();
555 int type;
556 while (((type = parser.next()) != XmlPullParser.END_TAG
557 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
558 if ((type == XmlPullParser.START_TAG)
559 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700560 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100561 }
562 }
563 } catch (IOException | XmlPullParserException e) {
564 Log.e(TAG, "Error parsing device profile", e);
565 return Collections.emptyList();
566 }
567 return result;
568 }
569
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700570 private int getLauncherIconDensity(int requiredSize) {
571 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700572 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700573 DisplayMetrics.DENSITY_LOW,
574 DisplayMetrics.DENSITY_MEDIUM,
575 DisplayMetrics.DENSITY_TV,
576 DisplayMetrics.DENSITY_HIGH,
577 DisplayMetrics.DENSITY_XHIGH,
578 DisplayMetrics.DENSITY_XXHIGH,
579 DisplayMetrics.DENSITY_XXXHIGH
580 };
581
582 int density = DisplayMetrics.DENSITY_XXXHIGH;
583 for (int i = densityBuckets.length - 1; i >= 0; i--) {
584 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
585 / DisplayMetrics.DENSITY_DEFAULT;
586 if (expectedSize >= requiredSize) {
587 density = densityBuckets[i];
588 }
589 }
590
591 return density;
592 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700593
Adam Cohen2e6da152015-05-06 11:42:25 -0700594 /**
595 * Apply any Partner customization grid overrides.
596 *
597 * Currently we support: all apps row / column count.
598 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700599 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
600 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800601 if (p == null) {
602 return;
603 }
604 try {
605 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
606 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
607 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
608
609 if (numRows > 0 && numColumns > 0) {
610 this.numRows = numRows;
611 this.numColumns = numColumns;
612 }
613 if (iconSizePx > 0) {
614 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
615 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
616 }
617 } catch (Resources.NotFoundException ex) {
618 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700619 }
620 }
621
Sunny Goyal415f1732018-11-29 10:33:47 -0800622 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700623 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700624 }
625
Sunny Goyal19ff7282021-04-22 10:12:54 -0700626 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000627 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700628 int minWidthPx = Integer.MAX_VALUE;
629 int minHeightPx = Integer.MAX_VALUE;
630 for (WindowBounds bounds : displayInfo.supportedBounds) {
631 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000632 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700633 // For split displays, take half width per page
634 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
635 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700636
Sunny Goyal19ff7282021-04-22 10:12:54 -0700637 } else if (!isTablet && bounds.isLandscape()) {
638 // We will use transposed layout in this case
639 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
640 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
641 } else {
642 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
643 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
644 }
645 }
646
Thales Lima425f6822022-05-10 13:44:58 -0300647 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
648 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700649
650 // Sort the profiles based on the closeness to the device size
651 Collections.sort(points, (a, b) ->
652 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
653 dist(width, height, b.minWidthDps, b.minHeightDps)));
654
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700655 DisplayOption closestPoint = points.get(0);
656 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700657 float weights = 0;
658
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700659 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
660 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700661 }
662
663 DisplayOption out = new DisplayOption(closestOption);
664 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700665 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700666 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
667 weights += w;
668 out.add(new DisplayOption().add(p).multiply(w));
669 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700670 out.multiply(1.0f / weights);
671
Thales Lima6e0005a2021-10-27 15:53:41 +0100672 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700673 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100674 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
675 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700676 }
677
678 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700679 }
680
Sunny Goyal27835952017-01-13 12:15:53 -0800681 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700682 Resources res = context.getResources();
683 Configuration config = context.getResources().getConfiguration();
684
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400685 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
686 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100687 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
688
Alex Chaud3e8cc42022-05-03 17:45:34 +0100689 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400690 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700691
Sunny Goyal187b16c2022-03-01 16:53:23 -0800692 /**
693 * Returns the device profile matching the provided screen configuration
694 */
695 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700696 DeviceProfile bestMatch = supportedProfiles.get(0);
697 float minDiff = Float.MAX_VALUE;
698
699 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400700 float diff = Math.abs(profile.widthPx - screenWidth)
701 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700702 if (diff < minDiff) {
703 minDiff = diff;
704 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800705 } else if (diff == minDiff && profile.rotationHint == rotation) {
706 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700707 }
708 }
709 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800710 }
711
Sunny Goyal415f1732018-11-29 10:33:47 -0800712 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700713 float d = dist(x0, y0, x1, y1);
714 if (Float.compare(d, 0f) == 0) {
715 return Float.POSITIVE_INFINITY;
716 }
717 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
718 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700719
720 /**
721 * As a ratio of screen height, the total distance we want the parallax effect to span
722 * horizontally
723 */
724 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
725 float aspectRatio = width / (float) height;
726
727 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
728 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
729 // We will use these two data points to extrapolate how much the wallpaper parallax effect
730 // to span (ie travel) at any aspect ratio:
731
sfufa@google.comde013292021-09-21 18:22:44 -0700732 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
733 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700734 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
735 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
736
737 // To find out the desired width at different aspect ratios, we use the following two
738 // formulas, where the coefficient on x is the aspect ratio (width/height):
739 // (16/10)x + y = 1.5
740 // (10/16)x + y = 1.2
741 // We solve for x and y and end up with a final formula:
742 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700743 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
744 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700745 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
746 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
747 return x * aspectRatio + y;
748 }
749
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700750 public interface OnIDPChangeListener {
751
Sunny Goyalb47172b2021-05-03 19:59:51 -0700752 /**
753 * Called when the device provide changes
754 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700755 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700756 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800757
758
Sunny Goyaleff44f32019-01-09 17:29:49 -0800759 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800760
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800761 public static final String TAG_NAME = "grid-option";
762
Alex Chau1c883d82021-12-01 18:43:10 +0000763 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
764 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
765 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
766 private static final int DEVICE_CATEGORY_ALL =
767 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
768
Thales Lima11af7bc2022-08-12 15:24:54 +0100769 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
770 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
771 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
772 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
773 private static final int DONT_INLINE_QSB = 0;
774
Sunny Goyaleff44f32019-01-09 17:29:49 -0800775 public final String name;
776 public final int numRows;
777 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000778 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700779 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800780
781 private final int numFolderRows;
782 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300783 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000784 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800785
Thales Limae9273ea2023-01-26 12:33:52 +0000786 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700787 private final int numAllAppsColumns;
788 private final int numDatabaseAllAppsColumns;
789 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700790 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100791
Thales Lima425f6822022-05-10 13:44:58 -0300792 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800793
Thales Lima11af7bc2022-08-12 15:24:54 +0100794 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
795
Thales Limab35faed2022-09-05 16:30:01 -0300796 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800797 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000798
Sunny Goyal415f1732018-11-29 10:33:47 -0800799 private final int defaultLayoutId;
800 private final int demoModeLayoutId;
801
Jon Mirandae126d722021-02-25 10:45:20 -0500802 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400803 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100804 private final int mWorkspaceSpecsId;
Thales Limaabfe3642023-05-24 18:08:53 +0100805 private final int mAllAppsSpecsId;
Jon Mirandae126d722021-02-25 10:45:20 -0500806
Sunny Goyal076e04b2023-04-03 12:38:30 -0700807 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800808 TypedArray a = context.obtainStyledAttributes(
809 attrs, R.styleable.GridDisplayOption);
810 name = a.getString(R.styleable.GridDisplayOption_name);
811 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
812 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000813 numSearchContainerColumns = a.getInt(
814 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800815
Tracy Zhou7df93d22020-01-27 13:44:06 -0800816 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100817 defaultLayoutId = a.getResourceId(
818 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800819 demoModeLayoutId = a.getResourceId(
820 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700821
Thales Limae9273ea2023-01-26 12:33:52 +0000822 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
823 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700824 numAllAppsColumns = a.getInt(
825 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
826 numDatabaseAllAppsColumns = a.getInt(
827 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
828
829 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800830 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700831 numDatabaseHotseatIcons = a.getInt(
832 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100833
Thales Lima425f6822022-05-10 13:44:58 -0300834 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
835 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
836 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
837 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
838 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
839 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
840 numColumns);
841 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
842 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
843 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844
Vinit Nayakc7293172022-07-18 16:41:50 -0700845 inlineNavButtonsEndSpacing =
846 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100847 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300848
Sunny Goyal415f1732018-11-29 10:33:47 -0800849 numFolderRows = a.getInt(
850 R.styleable.GridDisplayOption_numFolderRows, numRows);
851 numFolderColumns = a.getInt(
852 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700853
Thales Limab35faed2022-09-05 16:30:01 -0300854 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
855 INVALID_RESOURCE_HANDLE);
856
Thales Limad852d652023-01-17 14:01:13 +0000857 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
858 R.style.CellStyleDefault);
859
Jon Mirandae126d722021-02-25 10:45:20 -0500860 isScalable = a.getBoolean(
861 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400862 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000863 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700864 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000865 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100866
Thales Limaec5abba2023-04-05 16:33:50 +0100867 if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
868 mWorkspaceSpecsId = a.getResourceId(
869 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100870 mAllAppsSpecsId = a.getResourceId(
871 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100872 } else {
873 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100874 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100875 }
876
Thales Lima11af7bc2022-08-12 15:24:54 +0100877 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
878 DONT_INLINE_QSB);
879 inlineQsb[INDEX_DEFAULT] =
880 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
881 inlineQsb[INDEX_LANDSCAPE] =
882 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
883 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
884 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
885 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
886 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
887 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
888 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
889
Sunny Goyal415f1732018-11-29 10:33:47 -0800890 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700891 }
892
893 public boolean isEnabled(@DeviceType int deviceType) {
894 switch (deviceType) {
895 case TYPE_PHONE:
896 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
897 case TYPE_TABLET:
898 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
899 case TYPE_MULTI_DISPLAY:
900 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
901 == DEVICE_CATEGORY_MULTI_DISPLAY;
902 default:
903 return false;
904 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800905 }
906 }
907
Sunny Goyal19ff7282021-04-22 10:12:54 -0700908 @VisibleForTesting
909 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700910 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800911
Sunny Goyal415f1732018-11-29 10:33:47 -0800912 private final float minWidthDps;
913 private final float minHeightDps;
914 private final boolean canBeDefault;
915
Thales Lima83bedbf2021-10-05 17:47:39 +0100916 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100917
Thales Lima78d00ad2021-09-30 11:29:06 +0100918 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100919 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100920 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
921 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100922
Thales Lima78d00ad2021-09-30 11:29:06 +0100923 private final float[] iconSizes = new float[COUNT_SIZES];
924 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800925
Thales Limab7ef5692022-03-10 10:32:36 +0000926 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000927 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
928 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
929 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
930
Jon Miranda9c478b62023-03-23 21:38:49 -0700931 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
932
Jon Miranda04f05102023-04-04 12:16:31 -0700933 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
934
Thales Lima1de4d552021-10-13 16:13:25 +0100935 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800936 this.grid = grid;
937
Jon Miranda9c478b62023-03-23 21:38:49 -0700938 Resources res = context.getResources();
939
Thales Lima1de4d552021-10-13 16:13:25 +0100940 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800941
Sunny Goyal415f1732018-11-29 10:33:47 -0800942 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
943 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700944
Thales Lima1de4d552021-10-13 16:13:25 +0100945 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800946
Thales Lima83bedbf2021-10-05 17:47:39 +0100947 float x;
948 float y;
949
Thales Lima85c942f2021-12-31 13:04:20 +0000950 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
951 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100952 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000953
954 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
955 minCellSize[INDEX_DEFAULT].x);
956 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
957 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100958 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100959
Thales Lima85c942f2021-12-31 13:04:20 +0000960 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100961 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000962 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100963 minCellSize[INDEX_DEFAULT].y);
964 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
965
Thales Lima85c942f2021-12-31 13:04:20 +0000966 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100967 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000968 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100969 minCellSize[INDEX_DEFAULT].y);
970 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100971
Thales Lima85c942f2021-12-31 13:04:20 +0000972 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000973 float borderSpaceLandscape = a.getFloat(
974 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000975 float borderSpaceTwoPanelPortrait = a.getFloat(
976 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
977 float borderSpaceTwoPanelLandscape = a.getFloat(
978 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100979
Thales Lima85c942f2021-12-31 13:04:20 +0000980 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
981 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100982 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000983
984 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
985 borderSpaceLandscape);
986 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
987 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100988 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
989
990 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000991 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
992 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100993 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000994 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
995 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100996 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
997
998 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000999 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1000 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001001 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001002 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1003 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001004 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1005
Thales Limab7ef5692022-03-10 10:32:36 +00001006 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1007 minCellSize[INDEX_DEFAULT].x);
1008 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1009 minCellSize[INDEX_DEFAULT].y);
1010 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1011
1012 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1013 allAppsCellSize[INDEX_DEFAULT].x);
1014 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1015 allAppsCellSize[INDEX_DEFAULT].y);
1016 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1017
1018 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1019 allAppsCellSize[INDEX_DEFAULT].x);
1020 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1021 allAppsCellSize[INDEX_DEFAULT].y);
1022 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1023
1024 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1025 allAppsCellSize[INDEX_DEFAULT].x);
1026 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1027 allAppsCellSize[INDEX_DEFAULT].y);
1028 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1029
Thales Lima080d8902022-03-28 15:30:29 +01001030 float allAppsBorderSpace = a.getFloat(
1031 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1032 float allAppsBorderSpaceLandscape = a.getFloat(
1033 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1034 allAppsBorderSpace);
1035 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001036 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001037 allAppsBorderSpace);
1038 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001039 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001040 allAppsBorderSpace);
1041
1042 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1043 allAppsBorderSpace);
1044 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1045 allAppsBorderSpace);
1046 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1047
1048 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1049 allAppsBorderSpaceLandscape);
1050 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1051 allAppsBorderSpaceLandscape);
1052 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1053
1054 x = a.getFloat(
1055 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1056 allAppsBorderSpaceTwoPanelPortrait);
1057 y = a.getFloat(
1058 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1059 allAppsBorderSpaceTwoPanelPortrait);
1060 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1061
1062 x = a.getFloat(
1063 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1064 allAppsBorderSpaceTwoPanelLandscape);
1065 y = a.getFloat(
1066 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1067 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001068 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001069
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001070 iconSizes[INDEX_DEFAULT] =
1071 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1072 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001073 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001074 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001075 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001076 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001077 iconSizes[INDEX_DEFAULT]);
1078 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001079 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001080 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001081
Thales Limabb7d3882021-12-22 12:56:29 +00001082 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1083 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001084 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1085 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001086 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001087 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1088 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1089 allAppsIconSizes[INDEX_DEFAULT]);
1090 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1091 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1092 allAppsIconSizes[INDEX_DEFAULT]);
1093
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001094 textSizes[INDEX_DEFAULT] =
1095 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1096 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001097 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001098 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001099 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001100 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001101 textSizes[INDEX_DEFAULT]);
1102 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001103 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001104 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001105
Thales Limabb7d3882021-12-22 12:56:29 +00001106 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1107 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1108 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1109 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1110 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1111 allAppsIconTextSizes[INDEX_DEFAULT]);
1112 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1113 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1114 allAppsIconTextSizes[INDEX_DEFAULT]);
1115
Thales Lima83bedbf2021-10-05 17:47:39 +01001116 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1117 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001118 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1119 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1120 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001121 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001122 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001123 horizontalMargin[INDEX_DEFAULT]);
1124 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001125 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001126 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001127
Thales Limab8c05952022-05-23 16:58:38 +01001128 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1129 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001130 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001131 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1132 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1133 hotseatBarBottomSpace[INDEX_DEFAULT]);
1134 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1135 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1136 hotseatBarBottomSpace[INDEX_DEFAULT]);
1137 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1138 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1139 hotseatBarBottomSpace[INDEX_DEFAULT]);
1140
1141 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1142 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001143 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001144 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1145 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1146 hotseatQsbSpace[INDEX_DEFAULT]);
1147 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1148 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1149 hotseatQsbSpace[INDEX_DEFAULT]);
1150 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1151 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1152 hotseatQsbSpace[INDEX_DEFAULT]);
1153
Jon Miranda9c478b62023-03-23 21:38:49 -07001154 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1155 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1156 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1157 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1158 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1159 transientTaskbarIconSize[INDEX_DEFAULT]);
1160 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1161 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1162 transientTaskbarIconSize[INDEX_DEFAULT]);
1163 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1164 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001165 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001166
Jon Miranda04f05102023-04-04 12:16:31 -07001167 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1168 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1169 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1170 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1171 startAlignTaskbar[INDEX_DEFAULT]);
1172 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1173 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1174 startAlignTaskbar[INDEX_LANDSCAPE]);
1175 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1176 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1177 startAlignTaskbar[INDEX_DEFAULT]);
1178
Sunny Goyal415f1732018-11-29 10:33:47 -08001179 a.recycle();
1180 }
1181
1182 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001183 this(null);
1184 }
1185
1186 DisplayOption(GridOption grid) {
1187 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001188 minWidthDps = 0;
1189 minHeightDps = 0;
1190 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001191 for (int i = 0; i < COUNT_SIZES; i++) {
1192 iconSizes[i] = 0;
1193 textSizes[i] = 0;
1194 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001195 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001196 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001197 allAppsIconSizes[i] = 0;
1198 allAppsIconTextSizes[i] = 0;
1199 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001200 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001201 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001202 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001203 }
1204
1205 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001206 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001207 iconSizes[i] *= w;
1208 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001209 borderSpaces[i].x *= w;
1210 borderSpaces[i].y *= w;
1211 minCellSize[i].x *= w;
1212 minCellSize[i].y *= w;
1213 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001214 hotseatBarBottomSpace[i] *= w;
1215 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001216 allAppsCellSize[i].x *= w;
1217 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001218 allAppsIconSizes[i] *= w;
1219 allAppsIconTextSizes[i] *= w;
1220 allAppsBorderSpaces[i].x *= w;
1221 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001222 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001223 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001224
Sunny Goyal415f1732018-11-29 10:33:47 -08001225 return this;
1226 }
1227
1228 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001229 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001230 iconSizes[i] += p.iconSizes[i];
1231 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001232 borderSpaces[i].x += p.borderSpaces[i].x;
1233 borderSpaces[i].y += p.borderSpaces[i].y;
1234 minCellSize[i].x += p.minCellSize[i].x;
1235 minCellSize[i].y += p.minCellSize[i].y;
1236 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001237 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1238 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001239 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1240 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001241 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1242 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1243 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1244 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001245 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001246 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001247 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001248
Sunny Goyal415f1732018-11-29 10:33:47 -08001249 return this;
1250 }
1251 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001252}