blob: 722991a8b63e1e4dd22819500dccb1ea13517c67 [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
Jordan Silva575c3bd2023-07-21 12:00:43 +0100183 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
184 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100185 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100186 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100187 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
188 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100189 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100190 @XmlRes
191 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100192 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
193 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500194
Tracy Zhou7df93d22020-01-27 13:44:06 -0800195 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800196 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700197 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100198 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700199
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000200 /**
201 * An immutable list of supported profiles.
202 */
203 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700204
Sunny Goyal6f866092016-03-17 17:04:15 -0700205 public Point defaultWallpaperSize;
206
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700207 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700208
Sunny Goyalf633ef52018-03-13 09:57:05 -0700209 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800210 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700211
Sunny Goyalbbf01842015-10-08 07:41:15 -0700212 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700213 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700214 String gridName = getCurrentGridName(context);
215 String newGridName = initGrid(context, gridName);
216 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000217 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700218 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000219 LockedUserState.get(context).runOnUserUnlocked(() -> {
220 new DeviceGridState(this).writeToPrefs(context);
221 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700222
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700223 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100224 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000225 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
226 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100227 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700228 }
229 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700230 }
231
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700232 /**
233 * This constructor should NOT have any monitors by design.
234 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800235 public InvariantDeviceProfile(Context context, String gridName) {
236 String newName = initGrid(context, gridName);
237 if (newName == null || !newName.equals(gridName)) {
238 throw new IllegalArgumentException("Unknown grid name");
239 }
240 }
241
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700242 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800243 * This constructor should NOT have any monitors by design.
244 */
245 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700246 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100247 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700248 String gridName = getCurrentGridName(context);
249
250 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000251 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
252 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700253 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000254 defaultInfo,
255 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
256 /*allowDisabledGrid=*/false),
257 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258
Alex Chau661f02d2022-06-07 14:03:43 +0100259 Context displayContext = context.createDisplayContext(display);
260 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000261 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000263 myInfo,
264 getPredefinedDeviceProfiles(context, gridName, deviceType,
265 /*allowDisabledGrid=*/false),
266 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700267
268 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
269 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100270 result.iconSizes[INDEX_DEFAULT] =
271 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
272 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700273 result.iconSizes[i] = Math.min(
274 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000275 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700276
Thales Lima83bedbf2021-10-05 17:47:39 +0100277 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
278 COUNT_SIZES);
279 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
280 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500281
Alex Chau1c883d82021-12-01 18:43:10 +0000282 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800283 }
284
Alex Chau238aaee2021-10-06 16:15:24 +0100285 /**
286 * Reinitialize the current grid after a restore, where some grids might now be disabled.
287 */
288 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000289 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100290 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000291 String newGridName = initGrid(context, currentGridName);
292 String newDbFile = dbFile;
293 if (!newDbFile.equals(currentDbFile)) {
294 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100295 + ", migrating to: " + newGridName
296 + ", removing all other grid db files");
297 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
298 if (gridDbFile.equals(currentDbFile)) {
299 continue;
300 }
301 if (context.getDatabasePath(gridDbFile).delete()) {
302 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
303 }
304 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000305 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100306 }
307 }
308
Alex Chau1c883d82021-12-01 18:43:10 +0000309 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800310 int flagPhone = 1 << 0;
311 int flagTablet = 1 << 1;
312
313 int type = displayInfo.supportedBounds.stream()
314 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
315 .reduce(0, (a, b) -> a | b);
Sebastian Franco76a1ceb2023-06-08 13:26:20 -0700316 if ((type == (flagPhone | flagTablet))) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800317 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000318 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800319 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000320 return TYPE_TABLET;
321 } else {
322 return TYPE_PHONE;
323 }
324 }
325
Tracy Zhou42255d22020-03-13 00:38:11 -0700326 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000327 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700328 }
329
Sunny Goyaleff44f32019-01-09 17:29:49 -0800330 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700331 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000332 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700333
334 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000335 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100336 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700337 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000338 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
339 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700340 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800341 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700342
Thales Limab67bfa72022-11-02 15:30:11 +0000343 @VisibleForTesting
344 public static String getDefaultGridName(Context context) {
345 return new InvariantDeviceProfile().initGrid(context, null);
346 }
347
Alex Chau1c883d82021-12-01 18:43:10 +0000348 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
349 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700350 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700351 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000352 numRows = closestProfile.numRows;
353 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000354 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000355 dbFile = closestProfile.dbFile;
356 defaultLayoutId = closestProfile.defaultLayoutId;
357 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300358
Sunny Goyalae190ff2020-04-14 00:19:01 +0000359 numFolderRows = closestProfile.numFolderRows;
360 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300361 folderStyle = closestProfile.folderStyle;
362
Thales Limad852d652023-01-17 14:01:13 +0000363 cellStyle = closestProfile.cellStyle;
364
Jon Mirandae126d722021-02-25 10:45:20 -0500365 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400366 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100367 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100368 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100369 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100370 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100371 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100372 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100373 hotseatSpecsId = closestProfile.mHotseatSpecsId;
374 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Alex Chau1c883d82021-12-01 18:43:10 +0000375 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000376
Vinit Nayakc7293172022-07-18 16:41:50 -0700377 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
378
Thales Lima83bedbf2021-10-05 17:47:39 +0100379 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100380 float maxIconSize = iconSize[0];
381 for (int i = 1; i < iconSize.length; i++) {
382 maxIconSize = Math.max(maxIconSize, iconSize[i]);
383 }
384 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000385 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
386
Thales Lima83bedbf2021-10-05 17:47:39 +0100387 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700388
Thales Lima83bedbf2021-10-05 17:47:39 +0100389 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100390
Thales Lima83bedbf2021-10-05 17:47:39 +0100391 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100392
Thales Limad90faab2021-09-21 17:18:47 +0100393 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100394
Sunny Goyal19ff7282021-04-22 10:12:54 -0700395 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000396 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700397 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300398 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100399 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
400 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700401
Thales Limae9273ea2023-01-26 12:33:52 +0000402 allAppsStyle = closestProfile.allAppsStyle;
403
Sunny Goyal19ff7282021-04-22 10:12:54 -0700404 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000405 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700406 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500407
Thales Limab7ef5692022-03-10 10:32:36 +0000408 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000409 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
410 allAppsIconSize = displayOption.allAppsIconSizes;
411 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000412
Thales Lima11af7bc2022-08-12 15:24:54 +0100413 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000414
Jon Miranda9c478b62023-03-23 21:38:49 -0700415 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
416
Jon Miranda04f05102023-04-04 12:16:31 -0700417 startAlignTaskbar = displayOption.startAlignTaskbar;
418
Sunny Goyalae190ff2020-04-14 00:19:01 +0000419 // If the partner customization apk contains any grid overrides, apply them
420 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700421 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700422
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000423 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700424 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700425 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700426 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000427 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000428 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000429 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700430 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000431 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700432
Sunny Goyal19ff7282021-04-22 10:12:54 -0700433 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
434 int displayWidth = bounds.bounds.width();
435 int displayHeight = bounds.bounds.height();
436 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700437
Sunny Goyal19ff7282021-04-22 10:12:54 -0700438 // We need to ensure that there is enough extra space in the wallpaper
439 // for the intended parallax effects
440 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300441 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
442 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700443 ? 2
444 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
445 defaultWallpaperSize.x =
446 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700447 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000448 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700449
Thales Lima6a590062022-11-22 15:52:49 +0000450 int numMinShownHotseatIconsForTablet = supportedProfiles
451 .stream()
452 .filter(deviceProfile -> deviceProfile.isTablet)
453 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
454 .min()
455 .orElse(0);
456
457 supportedProfiles
458 .stream()
459 .filter(deviceProfile -> deviceProfile.isTablet)
460 .forEach(deviceProfile -> {
461 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
462 deviceProfile.recalculateHotseatWidthAndBorderSpace();
463 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700464 }
465
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700466 public void addOnChangeListener(OnIDPChangeListener listener) {
467 mChangeListeners.add(listener);
468 }
469
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800470 public void removeOnChangeListener(OnIDPChangeListener listener) {
471 mChangeListeners.remove(listener);
472 }
473
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800474
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800475 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000476 LauncherPrefs.get(context).put(GRID_NAME, gridName);
477 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800478 }
479
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700480 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700481 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000482 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
483 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700484 }
485
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700486 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700487 Object[] oldState = toModelState();
488
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700489 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700490 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700491 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700492
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700493 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700494 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700495 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700496 }
497 }
498
Alex Chau1c883d82021-12-01 18:43:10 +0000499 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
500 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800501 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100502
Alex Chau1c883d82021-12-01 18:43:10 +0000503 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700504 final int depth = parser.getDepth();
505 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700506 while (((type = parser.next()) != XmlPullParser.END_TAG ||
507 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800508 if ((type == XmlPullParser.START_TAG)
509 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800510
Sunny Goyal076e04b2023-04-03 12:38:30 -0700511 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
512 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100513 final int displayDepth = parser.getDepth();
514 while (((type = parser.next()) != XmlPullParser.END_TAG
515 || parser.getDepth() > displayDepth)
516 && type != XmlPullParser.END_DOCUMENT) {
517 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
518 parser.getName())) {
519 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100520 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100521 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800522 }
523 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700524 }
525 }
sfufa@google.comde013292021-09-21 18:22:44 -0700526 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700527 throw new RuntimeException(e);
528 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800529
Sunny Goyalae190ff2020-04-14 00:19:01 +0000530 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800531 if (!TextUtils.isEmpty(gridName)) {
532 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100533 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700534 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000535 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800536 }
537 }
538 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000539 if (filteredProfiles.isEmpty()) {
540 // No grid found, use the default options
541 for (DisplayOption option : profiles) {
542 if (option.canBeDefault) {
543 filteredProfiles.add(option);
544 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800545 }
546 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000547 if (filteredProfiles.isEmpty()) {
548 throw new RuntimeException("No display option with canBeDefault=true");
549 }
550 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700551 }
552
Thales Lima7ec83822021-08-05 13:32:10 +0100553 /**
554 * @return all the grid options that can be shown on the device
555 */
556 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700557 return parseAllDefinedGridOptions(context)
558 .stream()
559 .filter(go -> go.isEnabled(deviceType))
560 .collect(Collectors.toList());
561 }
562
563 /**
564 * @return all the grid options that can be shown on the device
565 */
566 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100567 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100568
Alex Chau1c883d82021-12-01 18:43:10 +0000569 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100570 final int depth = parser.getDepth();
571 int type;
572 while (((type = parser.next()) != XmlPullParser.END_TAG
573 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
574 if ((type == XmlPullParser.START_TAG)
575 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700576 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100577 }
578 }
579 } catch (IOException | XmlPullParserException e) {
580 Log.e(TAG, "Error parsing device profile", e);
581 return Collections.emptyList();
582 }
583 return result;
584 }
585
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700586 private int getLauncherIconDensity(int requiredSize) {
587 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700588 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700589 DisplayMetrics.DENSITY_LOW,
590 DisplayMetrics.DENSITY_MEDIUM,
591 DisplayMetrics.DENSITY_TV,
592 DisplayMetrics.DENSITY_HIGH,
593 DisplayMetrics.DENSITY_XHIGH,
594 DisplayMetrics.DENSITY_XXHIGH,
595 DisplayMetrics.DENSITY_XXXHIGH
596 };
597
598 int density = DisplayMetrics.DENSITY_XXXHIGH;
599 for (int i = densityBuckets.length - 1; i >= 0; i--) {
600 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
601 / DisplayMetrics.DENSITY_DEFAULT;
602 if (expectedSize >= requiredSize) {
603 density = densityBuckets[i];
604 }
605 }
606
607 return density;
608 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700609
Adam Cohen2e6da152015-05-06 11:42:25 -0700610 /**
611 * Apply any Partner customization grid overrides.
612 *
613 * Currently we support: all apps row / column count.
614 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700615 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
616 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800617 if (p == null) {
618 return;
619 }
620 try {
621 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
622 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
623 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
624
625 if (numRows > 0 && numColumns > 0) {
626 this.numRows = numRows;
627 this.numColumns = numColumns;
628 }
629 if (iconSizePx > 0) {
630 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
631 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
632 }
633 } catch (Resources.NotFoundException ex) {
634 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700635 }
636 }
637
Sunny Goyal415f1732018-11-29 10:33:47 -0800638 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700639 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700640 }
641
Sunny Goyal19ff7282021-04-22 10:12:54 -0700642 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000643 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700644 int minWidthPx = Integer.MAX_VALUE;
645 int minHeightPx = Integer.MAX_VALUE;
646 for (WindowBounds bounds : displayInfo.supportedBounds) {
647 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000648 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700649 // For split displays, take half width per page
650 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
651 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700652
Sunny Goyal19ff7282021-04-22 10:12:54 -0700653 } else if (!isTablet && bounds.isLandscape()) {
654 // We will use transposed layout in this case
655 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
656 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
657 } else {
658 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
659 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
660 }
661 }
662
Thales Lima425f6822022-05-10 13:44:58 -0300663 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
664 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700665
666 // Sort the profiles based on the closeness to the device size
667 Collections.sort(points, (a, b) ->
668 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
669 dist(width, height, b.minWidthDps, b.minHeightDps)));
670
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700671 DisplayOption closestPoint = points.get(0);
672 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700673 float weights = 0;
674
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700675 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
676 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700677 }
678
679 DisplayOption out = new DisplayOption(closestOption);
680 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700681 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700682 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
683 weights += w;
684 out.add(new DisplayOption().add(p).multiply(w));
685 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700686 out.multiply(1.0f / weights);
687
Thales Lima6e0005a2021-10-27 15:53:41 +0100688 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700689 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100690 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
691 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700692 }
693
694 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700695 }
696
Sunny Goyal27835952017-01-13 12:15:53 -0800697 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700698 Resources res = context.getResources();
699 Configuration config = context.getResources().getConfiguration();
700
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400701 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
702 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100703 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
704
Alex Chaud3e8cc42022-05-03 17:45:34 +0100705 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400706 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700707
Sunny Goyal187b16c2022-03-01 16:53:23 -0800708 /**
709 * Returns the device profile matching the provided screen configuration
710 */
711 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700712 DeviceProfile bestMatch = supportedProfiles.get(0);
713 float minDiff = Float.MAX_VALUE;
714
715 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400716 float diff = Math.abs(profile.widthPx - screenWidth)
717 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700718 if (diff < minDiff) {
719 minDiff = diff;
720 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800721 } else if (diff == minDiff && profile.rotationHint == rotation) {
722 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700723 }
724 }
725 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800726 }
727
Sunny Goyal415f1732018-11-29 10:33:47 -0800728 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700729 float d = dist(x0, y0, x1, y1);
730 if (Float.compare(d, 0f) == 0) {
731 return Float.POSITIVE_INFINITY;
732 }
733 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
734 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700735
736 /**
737 * As a ratio of screen height, the total distance we want the parallax effect to span
738 * horizontally
739 */
740 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
741 float aspectRatio = width / (float) height;
742
743 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
744 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
745 // We will use these two data points to extrapolate how much the wallpaper parallax effect
746 // to span (ie travel) at any aspect ratio:
747
sfufa@google.comde013292021-09-21 18:22:44 -0700748 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
749 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700750 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
751 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
752
753 // To find out the desired width at different aspect ratios, we use the following two
754 // formulas, where the coefficient on x is the aspect ratio (width/height):
755 // (16/10)x + y = 1.5
756 // (10/16)x + y = 1.2
757 // We solve for x and y and end up with a final formula:
758 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700759 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
760 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700761 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
762 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
763 return x * aspectRatio + y;
764 }
765
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700766 public interface OnIDPChangeListener {
767
Sunny Goyalb47172b2021-05-03 19:59:51 -0700768 /**
769 * Called when the device provide changes
770 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700771 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700772 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800773
774
Sunny Goyaleff44f32019-01-09 17:29:49 -0800775 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800776
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800777 public static final String TAG_NAME = "grid-option";
778
Alex Chau1c883d82021-12-01 18:43:10 +0000779 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
780 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
781 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
782 private static final int DEVICE_CATEGORY_ALL =
783 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
784
Thales Lima11af7bc2022-08-12 15:24:54 +0100785 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
786 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
787 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
788 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
789 private static final int DONT_INLINE_QSB = 0;
790
Sunny Goyaleff44f32019-01-09 17:29:49 -0800791 public final String name;
792 public final int numRows;
793 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000794 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700795 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800796
797 private final int numFolderRows;
798 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300799 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000800 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800801
Thales Limae9273ea2023-01-26 12:33:52 +0000802 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700803 private final int numAllAppsColumns;
804 private final int numDatabaseAllAppsColumns;
805 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700806 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100807
Thales Lima425f6822022-05-10 13:44:58 -0300808 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800809
Thales Lima11af7bc2022-08-12 15:24:54 +0100810 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
811
Thales Limab35faed2022-09-05 16:30:01 -0300812 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800813 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000814
Sunny Goyal415f1732018-11-29 10:33:47 -0800815 private final int defaultLayoutId;
816 private final int demoModeLayoutId;
817
Jon Mirandae126d722021-02-25 10:45:20 -0500818 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400819 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100820 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100821 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100822 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100823 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100824 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100825 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100826 private final int mHotseatSpecsId;
827 private final int mHotseatSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500828
Sunny Goyal076e04b2023-04-03 12:38:30 -0700829 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800830 TypedArray a = context.obtainStyledAttributes(
831 attrs, R.styleable.GridDisplayOption);
832 name = a.getString(R.styleable.GridDisplayOption_name);
833 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
834 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000835 numSearchContainerColumns = a.getInt(
836 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800837
Tracy Zhou7df93d22020-01-27 13:44:06 -0800838 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100839 defaultLayoutId = a.getResourceId(
840 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800841 demoModeLayoutId = a.getResourceId(
842 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700843
Thales Limae9273ea2023-01-26 12:33:52 +0000844 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
845 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700846 numAllAppsColumns = a.getInt(
847 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
848 numDatabaseAllAppsColumns = a.getInt(
849 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
850
851 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800852 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700853 numDatabaseHotseatIcons = a.getInt(
854 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100855
Thales Lima425f6822022-05-10 13:44:58 -0300856 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
857 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
858 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
859 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
860 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
861 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
862 numColumns);
863 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
864 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
865 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700866
Vinit Nayakc7293172022-07-18 16:41:50 -0700867 inlineNavButtonsEndSpacing =
868 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100869 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300870
Sunny Goyal415f1732018-11-29 10:33:47 -0800871 numFolderRows = a.getInt(
872 R.styleable.GridDisplayOption_numFolderRows, numRows);
873 numFolderColumns = a.getInt(
874 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700875
Thales Limab35faed2022-09-05 16:30:01 -0300876 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
877 INVALID_RESOURCE_HANDLE);
878
Thales Limad852d652023-01-17 14:01:13 +0000879 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
880 R.style.CellStyleDefault);
881
Jon Mirandae126d722021-02-25 10:45:20 -0500882 isScalable = a.getBoolean(
883 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400884 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000885 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700886 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000887 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100888
Thales Limaec5abba2023-04-05 16:33:50 +0100889 if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
890 mWorkspaceSpecsId = a.getResourceId(
891 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100892 mWorkspaceSpecsTwoPanelId = a.getResourceId(
893 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
894 INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100895 mAllAppsSpecsId = a.getResourceId(
896 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100897 mAllAppsSpecsTwoPanelId = a.getResourceId(
898 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
899 INVALID_RESOURCE_HANDLE);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100900 mFolderSpecsId = a.getResourceId(
901 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100902 mFolderSpecsTwoPanelId = a.getResourceId(
903 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
904 INVALID_RESOURCE_HANDLE);
Thales Limaf8bfb032023-07-24 15:08:05 +0100905 mHotseatSpecsId = a.getResourceId(
906 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
907 mHotseatSpecsTwoPanelId = a.getResourceId(
908 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
909 INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100910 } else {
911 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100912 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100913 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100914 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100915 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100916 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100917 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
918 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100919 }
920
Thales Lima11af7bc2022-08-12 15:24:54 +0100921 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
922 DONT_INLINE_QSB);
923 inlineQsb[INDEX_DEFAULT] =
924 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
925 inlineQsb[INDEX_LANDSCAPE] =
926 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
927 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
928 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
929 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
930 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
931 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
932 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
933
Sunny Goyal415f1732018-11-29 10:33:47 -0800934 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700935 }
936
937 public boolean isEnabled(@DeviceType int deviceType) {
938 switch (deviceType) {
939 case TYPE_PHONE:
940 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
941 case TYPE_TABLET:
942 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
943 case TYPE_MULTI_DISPLAY:
944 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
945 == DEVICE_CATEGORY_MULTI_DISPLAY;
946 default:
947 return false;
948 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800949 }
950 }
951
Sunny Goyal19ff7282021-04-22 10:12:54 -0700952 @VisibleForTesting
953 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700954 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800955
Sunny Goyal415f1732018-11-29 10:33:47 -0800956 private final float minWidthDps;
957 private final float minHeightDps;
958 private final boolean canBeDefault;
959
Thales Lima83bedbf2021-10-05 17:47:39 +0100960 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100961
Thales Lima78d00ad2021-09-30 11:29:06 +0100962 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100963 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100964 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
965 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100966
Thales Lima78d00ad2021-09-30 11:29:06 +0100967 private final float[] iconSizes = new float[COUNT_SIZES];
968 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800969
Thales Limab7ef5692022-03-10 10:32:36 +0000970 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000971 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
972 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
973 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
974
Jon Miranda9c478b62023-03-23 21:38:49 -0700975 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
976
Jon Miranda04f05102023-04-04 12:16:31 -0700977 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
978
Thales Lima1de4d552021-10-13 16:13:25 +0100979 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800980 this.grid = grid;
981
Jon Miranda9c478b62023-03-23 21:38:49 -0700982 Resources res = context.getResources();
983
Thales Lima1de4d552021-10-13 16:13:25 +0100984 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800985
Sunny Goyal415f1732018-11-29 10:33:47 -0800986 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
987 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700988
Thales Lima1de4d552021-10-13 16:13:25 +0100989 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800990
Thales Lima83bedbf2021-10-05 17:47:39 +0100991 float x;
992 float y;
993
Thales Lima85c942f2021-12-31 13:04:20 +0000994 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
995 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100996 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000997
998 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
999 minCellSize[INDEX_DEFAULT].x);
1000 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1001 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001002 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001003
Thales Lima85c942f2021-12-31 13:04:20 +00001004 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001005 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001006 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001007 minCellSize[INDEX_DEFAULT].y);
1008 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1009
Thales Lima85c942f2021-12-31 13:04:20 +00001010 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001011 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001012 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001013 minCellSize[INDEX_DEFAULT].y);
1014 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001015
Thales Lima85c942f2021-12-31 13:04:20 +00001016 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001017 float borderSpaceLandscape = a.getFloat(
1018 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001019 float borderSpaceTwoPanelPortrait = a.getFloat(
1020 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1021 float borderSpaceTwoPanelLandscape = a.getFloat(
1022 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001023
Thales Lima85c942f2021-12-31 13:04:20 +00001024 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1025 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001026 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001027
1028 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1029 borderSpaceLandscape);
1030 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1031 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001032 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1033
1034 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001035 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1036 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001037 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001038 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1039 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001040 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1041
1042 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001043 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1044 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001045 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001046 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1047 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001048 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1049
Thales Limab7ef5692022-03-10 10:32:36 +00001050 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1051 minCellSize[INDEX_DEFAULT].x);
1052 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1053 minCellSize[INDEX_DEFAULT].y);
1054 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1055
1056 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1057 allAppsCellSize[INDEX_DEFAULT].x);
1058 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1059 allAppsCellSize[INDEX_DEFAULT].y);
1060 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1061
1062 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1063 allAppsCellSize[INDEX_DEFAULT].x);
1064 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1065 allAppsCellSize[INDEX_DEFAULT].y);
1066 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1067
1068 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1069 allAppsCellSize[INDEX_DEFAULT].x);
1070 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1071 allAppsCellSize[INDEX_DEFAULT].y);
1072 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1073
Thales Lima080d8902022-03-28 15:30:29 +01001074 float allAppsBorderSpace = a.getFloat(
1075 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1076 float allAppsBorderSpaceLandscape = a.getFloat(
1077 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1078 allAppsBorderSpace);
1079 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001080 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001081 allAppsBorderSpace);
1082 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001083 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001084 allAppsBorderSpace);
1085
1086 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1087 allAppsBorderSpace);
1088 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1089 allAppsBorderSpace);
1090 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1091
1092 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1093 allAppsBorderSpaceLandscape);
1094 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1095 allAppsBorderSpaceLandscape);
1096 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1097
1098 x = a.getFloat(
1099 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1100 allAppsBorderSpaceTwoPanelPortrait);
1101 y = a.getFloat(
1102 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1103 allAppsBorderSpaceTwoPanelPortrait);
1104 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1105
1106 x = a.getFloat(
1107 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1108 allAppsBorderSpaceTwoPanelLandscape);
1109 y = a.getFloat(
1110 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1111 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001112 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001113
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001114 iconSizes[INDEX_DEFAULT] =
1115 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1116 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001117 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001118 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001119 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001120 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001121 iconSizes[INDEX_DEFAULT]);
1122 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001123 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001124 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001125
Thales Limabb7d3882021-12-22 12:56:29 +00001126 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1127 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001128 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1129 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001130 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001131 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1132 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1133 allAppsIconSizes[INDEX_DEFAULT]);
1134 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1135 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1136 allAppsIconSizes[INDEX_DEFAULT]);
1137
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001138 textSizes[INDEX_DEFAULT] =
1139 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1140 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001141 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001142 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001143 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001144 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001145 textSizes[INDEX_DEFAULT]);
1146 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001147 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001148 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001149
Thales Limabb7d3882021-12-22 12:56:29 +00001150 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1151 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1152 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1153 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1154 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1155 allAppsIconTextSizes[INDEX_DEFAULT]);
1156 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1157 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1158 allAppsIconTextSizes[INDEX_DEFAULT]);
1159
Thales Lima83bedbf2021-10-05 17:47:39 +01001160 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1161 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001162 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1163 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1164 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001165 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001166 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001167 horizontalMargin[INDEX_DEFAULT]);
1168 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001169 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001170 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001171
Thales Limab8c05952022-05-23 16:58:38 +01001172 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1173 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001174 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001175 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1176 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1177 hotseatBarBottomSpace[INDEX_DEFAULT]);
1178 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1179 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1180 hotseatBarBottomSpace[INDEX_DEFAULT]);
1181 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1182 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1183 hotseatBarBottomSpace[INDEX_DEFAULT]);
1184
1185 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1186 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001187 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001188 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1189 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1190 hotseatQsbSpace[INDEX_DEFAULT]);
1191 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1192 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1193 hotseatQsbSpace[INDEX_DEFAULT]);
1194 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1195 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1196 hotseatQsbSpace[INDEX_DEFAULT]);
1197
Jon Miranda9c478b62023-03-23 21:38:49 -07001198 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1199 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1200 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1201 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1202 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1203 transientTaskbarIconSize[INDEX_DEFAULT]);
1204 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1205 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1206 transientTaskbarIconSize[INDEX_DEFAULT]);
1207 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1208 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001209 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001210
Jon Miranda04f05102023-04-04 12:16:31 -07001211 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1212 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1213 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1214 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1215 startAlignTaskbar[INDEX_DEFAULT]);
1216 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1217 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1218 startAlignTaskbar[INDEX_LANDSCAPE]);
1219 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1220 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1221 startAlignTaskbar[INDEX_DEFAULT]);
1222
Sunny Goyal415f1732018-11-29 10:33:47 -08001223 a.recycle();
1224 }
1225
1226 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001227 this(null);
1228 }
1229
1230 DisplayOption(GridOption grid) {
1231 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001232 minWidthDps = 0;
1233 minHeightDps = 0;
1234 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001235 for (int i = 0; i < COUNT_SIZES; i++) {
1236 iconSizes[i] = 0;
1237 textSizes[i] = 0;
1238 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001239 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001240 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001241 allAppsIconSizes[i] = 0;
1242 allAppsIconTextSizes[i] = 0;
1243 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001244 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001245 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001246 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001247 }
1248
1249 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001250 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001251 iconSizes[i] *= w;
1252 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001253 borderSpaces[i].x *= w;
1254 borderSpaces[i].y *= w;
1255 minCellSize[i].x *= w;
1256 minCellSize[i].y *= w;
1257 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001258 hotseatBarBottomSpace[i] *= w;
1259 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001260 allAppsCellSize[i].x *= w;
1261 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001262 allAppsIconSizes[i] *= w;
1263 allAppsIconTextSizes[i] *= w;
1264 allAppsBorderSpaces[i].x *= w;
1265 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001266 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001267 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001268
Sunny Goyal415f1732018-11-29 10:33:47 -08001269 return this;
1270 }
1271
1272 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001273 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001274 iconSizes[i] += p.iconSizes[i];
1275 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001276 borderSpaces[i].x += p.borderSpaces[i].x;
1277 borderSpaces[i].y += p.borderSpaces[i].y;
1278 minCellSize[i].x += p.minCellSize[i].x;
1279 minCellSize[i].y += p.minCellSize[i].y;
1280 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001281 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1282 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001283 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1284 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001285 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1286 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1287 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1288 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001289 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001290 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001291 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001292
Sunny Goyal415f1732018-11-29 10:33:47 -08001293 return this;
1294 }
1295 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001296}