blob: dac6120e1b9028b153dabe7b8ba48c5d2866afd8 [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;
Jon Mirandae126d722021-02-25 10:45:20 -0500192
Tracy Zhou7df93d22020-01-27 13:44:06 -0800193 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800194 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700195 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100196 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700197
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000198 /**
199 * An immutable list of supported profiles.
200 */
201 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700202
Sunny Goyal6f866092016-03-17 17:04:15 -0700203 public Point defaultWallpaperSize;
204
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700205 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700206
Sunny Goyalf633ef52018-03-13 09:57:05 -0700207 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800208 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700209
Sunny Goyalbbf01842015-10-08 07:41:15 -0700210 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700211 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700212 String gridName = getCurrentGridName(context);
213 String newGridName = initGrid(context, gridName);
214 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000215 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700216 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000217 LockedUserState.get(context).runOnUserUnlocked(() -> {
218 new DeviceGridState(this).writeToPrefs(context);
219 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700221 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100222 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000223 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
224 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100225 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700226 }
227 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700228 }
229
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700230 /**
231 * This constructor should NOT have any monitors by design.
232 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800233 public InvariantDeviceProfile(Context context, String gridName) {
234 String newName = initGrid(context, gridName);
235 if (newName == null || !newName.equals(gridName)) {
236 throw new IllegalArgumentException("Unknown grid name");
237 }
238 }
239
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700240 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800241 * This constructor should NOT have any monitors by design.
242 */
243 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700244 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100245 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700246 String gridName = getCurrentGridName(context);
247
248 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000249 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
250 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700251 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000252 defaultInfo,
253 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
254 /*allowDisabledGrid=*/false),
255 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700256
Alex Chau661f02d2022-06-07 14:03:43 +0100257 Context displayContext = context.createDisplayContext(display);
258 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000259 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700260 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000261 myInfo,
262 getPredefinedDeviceProfiles(context, gridName, deviceType,
263 /*allowDisabledGrid=*/false),
264 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700265
266 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
267 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100268 result.iconSizes[INDEX_DEFAULT] =
269 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
270 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700271 result.iconSizes[i] = Math.min(
272 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000273 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700274
Thales Lima83bedbf2021-10-05 17:47:39 +0100275 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
276 COUNT_SIZES);
277 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
278 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500279
Alex Chau1c883d82021-12-01 18:43:10 +0000280 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800281 }
282
Alex Chau238aaee2021-10-06 16:15:24 +0100283 /**
284 * Reinitialize the current grid after a restore, where some grids might now be disabled.
285 */
286 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000287 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100288 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000289 String newGridName = initGrid(context, currentGridName);
290 String newDbFile = dbFile;
291 if (!newDbFile.equals(currentDbFile)) {
292 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100293 + ", migrating to: " + newGridName
294 + ", removing all other grid db files");
295 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
296 if (gridDbFile.equals(currentDbFile)) {
297 continue;
298 }
299 if (context.getDatabasePath(gridDbFile).delete()) {
300 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
301 }
302 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000303 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100304 }
305 }
306
Alex Chau1c883d82021-12-01 18:43:10 +0000307 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800308 int flagPhone = 1 << 0;
309 int flagTablet = 1 << 1;
310
311 int type = displayInfo.supportedBounds.stream()
312 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
313 .reduce(0, (a, b) -> a | b);
Sebastian Franco76a1ceb2023-06-08 13:26:20 -0700314 if ((type == (flagPhone | flagTablet))) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800315 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000316 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800317 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000318 return TYPE_TABLET;
319 } else {
320 return TYPE_PHONE;
321 }
322 }
323
Tracy Zhou42255d22020-03-13 00:38:11 -0700324 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000325 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700326 }
327
Sunny Goyaleff44f32019-01-09 17:29:49 -0800328 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700329 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000330 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700331
332 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000333 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100334 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700335 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000336 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
337 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700338 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800339 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700340
Thales Limab67bfa72022-11-02 15:30:11 +0000341 @VisibleForTesting
342 public static String getDefaultGridName(Context context) {
343 return new InvariantDeviceProfile().initGrid(context, null);
344 }
345
Alex Chau1c883d82021-12-01 18:43:10 +0000346 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
347 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700348 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700349 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000350 numRows = closestProfile.numRows;
351 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000352 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000353 dbFile = closestProfile.dbFile;
354 defaultLayoutId = closestProfile.defaultLayoutId;
355 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300356
Sunny Goyalae190ff2020-04-14 00:19:01 +0000357 numFolderRows = closestProfile.numFolderRows;
358 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300359 folderStyle = closestProfile.folderStyle;
360
Thales Limad852d652023-01-17 14:01:13 +0000361 cellStyle = closestProfile.cellStyle;
362
Jon Mirandae126d722021-02-25 10:45:20 -0500363 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400364 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100365 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100366 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100367 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100368 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100369 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100370 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Alex Chau1c883d82021-12-01 18:43:10 +0000371 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000372
Vinit Nayakc7293172022-07-18 16:41:50 -0700373 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
374
Thales Lima83bedbf2021-10-05 17:47:39 +0100375 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100376 float maxIconSize = iconSize[0];
377 for (int i = 1; i < iconSize.length; i++) {
378 maxIconSize = Math.max(maxIconSize, iconSize[i]);
379 }
380 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000381 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
382
Thales Lima83bedbf2021-10-05 17:47:39 +0100383 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700384
Thales Lima83bedbf2021-10-05 17:47:39 +0100385 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100386
Thales Lima83bedbf2021-10-05 17:47:39 +0100387 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100388
Thales Limad90faab2021-09-21 17:18:47 +0100389 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100390
Sunny Goyal19ff7282021-04-22 10:12:54 -0700391 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000392 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700393 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300394 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100395 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
396 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700397
Thales Limae9273ea2023-01-26 12:33:52 +0000398 allAppsStyle = closestProfile.allAppsStyle;
399
Sunny Goyal19ff7282021-04-22 10:12:54 -0700400 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000401 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700402 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500403
Thales Limab7ef5692022-03-10 10:32:36 +0000404 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000405 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
406 allAppsIconSize = displayOption.allAppsIconSizes;
407 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000408
Thales Lima11af7bc2022-08-12 15:24:54 +0100409 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000410
Jon Miranda9c478b62023-03-23 21:38:49 -0700411 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
412
Jon Miranda04f05102023-04-04 12:16:31 -0700413 startAlignTaskbar = displayOption.startAlignTaskbar;
414
Sunny Goyalae190ff2020-04-14 00:19:01 +0000415 // If the partner customization apk contains any grid overrides, apply them
416 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700417 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700418
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000419 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700420 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700421 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700422 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000423 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000424 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000425 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700426 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000427 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700428
Sunny Goyal19ff7282021-04-22 10:12:54 -0700429 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
430 int displayWidth = bounds.bounds.width();
431 int displayHeight = bounds.bounds.height();
432 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700433
Sunny Goyal19ff7282021-04-22 10:12:54 -0700434 // We need to ensure that there is enough extra space in the wallpaper
435 // for the intended parallax effects
436 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300437 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
438 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700439 ? 2
440 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
441 defaultWallpaperSize.x =
442 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700443 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000444 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700445
Thales Lima6a590062022-11-22 15:52:49 +0000446 int numMinShownHotseatIconsForTablet = supportedProfiles
447 .stream()
448 .filter(deviceProfile -> deviceProfile.isTablet)
449 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
450 .min()
451 .orElse(0);
452
453 supportedProfiles
454 .stream()
455 .filter(deviceProfile -> deviceProfile.isTablet)
456 .forEach(deviceProfile -> {
457 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
458 deviceProfile.recalculateHotseatWidthAndBorderSpace();
459 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700460 }
461
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700462 public void addOnChangeListener(OnIDPChangeListener listener) {
463 mChangeListeners.add(listener);
464 }
465
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800466 public void removeOnChangeListener(OnIDPChangeListener listener) {
467 mChangeListeners.remove(listener);
468 }
469
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800470
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800471 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000472 LauncherPrefs.get(context).put(GRID_NAME, gridName);
473 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800474 }
475
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700476 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700477 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000478 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
479 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700480 }
481
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700482 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700483 Object[] oldState = toModelState();
484
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700485 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700486 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700487 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700488
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700489 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700490 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700491 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700492 }
493 }
494
Alex Chau1c883d82021-12-01 18:43:10 +0000495 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
496 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800497 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100498
Alex Chau1c883d82021-12-01 18:43:10 +0000499 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700500 final int depth = parser.getDepth();
501 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700502 while (((type = parser.next()) != XmlPullParser.END_TAG ||
503 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800504 if ((type == XmlPullParser.START_TAG)
505 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800506
Sunny Goyal076e04b2023-04-03 12:38:30 -0700507 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
508 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100509 final int displayDepth = parser.getDepth();
510 while (((type = parser.next()) != XmlPullParser.END_TAG
511 || parser.getDepth() > displayDepth)
512 && type != XmlPullParser.END_DOCUMENT) {
513 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
514 parser.getName())) {
515 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100516 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100517 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800518 }
519 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700520 }
521 }
sfufa@google.comde013292021-09-21 18:22:44 -0700522 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700523 throw new RuntimeException(e);
524 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800525
Sunny Goyalae190ff2020-04-14 00:19:01 +0000526 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800527 if (!TextUtils.isEmpty(gridName)) {
528 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100529 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700530 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000531 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800532 }
533 }
534 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000535 if (filteredProfiles.isEmpty()) {
536 // No grid found, use the default options
537 for (DisplayOption option : profiles) {
538 if (option.canBeDefault) {
539 filteredProfiles.add(option);
540 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800541 }
542 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000543 if (filteredProfiles.isEmpty()) {
544 throw new RuntimeException("No display option with canBeDefault=true");
545 }
546 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700547 }
548
Thales Lima7ec83822021-08-05 13:32:10 +0100549 /**
550 * @return all the grid options that can be shown on the device
551 */
552 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700553 return parseAllDefinedGridOptions(context)
554 .stream()
555 .filter(go -> go.isEnabled(deviceType))
556 .collect(Collectors.toList());
557 }
558
559 /**
560 * @return all the grid options that can be shown on the device
561 */
562 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100563 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100564
Alex Chau1c883d82021-12-01 18:43:10 +0000565 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100566 final int depth = parser.getDepth();
567 int type;
568 while (((type = parser.next()) != XmlPullParser.END_TAG
569 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
570 if ((type == XmlPullParser.START_TAG)
571 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700572 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100573 }
574 }
575 } catch (IOException | XmlPullParserException e) {
576 Log.e(TAG, "Error parsing device profile", e);
577 return Collections.emptyList();
578 }
579 return result;
580 }
581
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700582 private int getLauncherIconDensity(int requiredSize) {
583 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700584 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700585 DisplayMetrics.DENSITY_LOW,
586 DisplayMetrics.DENSITY_MEDIUM,
587 DisplayMetrics.DENSITY_TV,
588 DisplayMetrics.DENSITY_HIGH,
589 DisplayMetrics.DENSITY_XHIGH,
590 DisplayMetrics.DENSITY_XXHIGH,
591 DisplayMetrics.DENSITY_XXXHIGH
592 };
593
594 int density = DisplayMetrics.DENSITY_XXXHIGH;
595 for (int i = densityBuckets.length - 1; i >= 0; i--) {
596 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
597 / DisplayMetrics.DENSITY_DEFAULT;
598 if (expectedSize >= requiredSize) {
599 density = densityBuckets[i];
600 }
601 }
602
603 return density;
604 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700605
Adam Cohen2e6da152015-05-06 11:42:25 -0700606 /**
607 * Apply any Partner customization grid overrides.
608 *
609 * Currently we support: all apps row / column count.
610 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700611 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
612 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800613 if (p == null) {
614 return;
615 }
616 try {
617 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
618 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
619 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
620
621 if (numRows > 0 && numColumns > 0) {
622 this.numRows = numRows;
623 this.numColumns = numColumns;
624 }
625 if (iconSizePx > 0) {
626 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
627 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
628 }
629 } catch (Resources.NotFoundException ex) {
630 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700631 }
632 }
633
Sunny Goyal415f1732018-11-29 10:33:47 -0800634 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700635 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700636 }
637
Sunny Goyal19ff7282021-04-22 10:12:54 -0700638 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000639 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700640 int minWidthPx = Integer.MAX_VALUE;
641 int minHeightPx = Integer.MAX_VALUE;
642 for (WindowBounds bounds : displayInfo.supportedBounds) {
643 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000644 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700645 // For split displays, take half width per page
646 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
647 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700648
Sunny Goyal19ff7282021-04-22 10:12:54 -0700649 } else if (!isTablet && bounds.isLandscape()) {
650 // We will use transposed layout in this case
651 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
652 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
653 } else {
654 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
655 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
656 }
657 }
658
Thales Lima425f6822022-05-10 13:44:58 -0300659 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
660 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700661
662 // Sort the profiles based on the closeness to the device size
663 Collections.sort(points, (a, b) ->
664 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
665 dist(width, height, b.minWidthDps, b.minHeightDps)));
666
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700667 DisplayOption closestPoint = points.get(0);
668 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700669 float weights = 0;
670
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700671 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
672 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700673 }
674
675 DisplayOption out = new DisplayOption(closestOption);
676 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700677 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700678 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
679 weights += w;
680 out.add(new DisplayOption().add(p).multiply(w));
681 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700682 out.multiply(1.0f / weights);
683
Thales Lima6e0005a2021-10-27 15:53:41 +0100684 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700685 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100686 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
687 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700688 }
689
690 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700691 }
692
Sunny Goyal27835952017-01-13 12:15:53 -0800693 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700694 Resources res = context.getResources();
695 Configuration config = context.getResources().getConfiguration();
696
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400697 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
698 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100699 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
700
Alex Chaud3e8cc42022-05-03 17:45:34 +0100701 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400702 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700703
Sunny Goyal187b16c2022-03-01 16:53:23 -0800704 /**
705 * Returns the device profile matching the provided screen configuration
706 */
707 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700708 DeviceProfile bestMatch = supportedProfiles.get(0);
709 float minDiff = Float.MAX_VALUE;
710
711 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400712 float diff = Math.abs(profile.widthPx - screenWidth)
713 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700714 if (diff < minDiff) {
715 minDiff = diff;
716 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800717 } else if (diff == minDiff && profile.rotationHint == rotation) {
718 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700719 }
720 }
721 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800722 }
723
Sunny Goyal415f1732018-11-29 10:33:47 -0800724 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700725 float d = dist(x0, y0, x1, y1);
726 if (Float.compare(d, 0f) == 0) {
727 return Float.POSITIVE_INFINITY;
728 }
729 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
730 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700731
732 /**
733 * As a ratio of screen height, the total distance we want the parallax effect to span
734 * horizontally
735 */
736 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
737 float aspectRatio = width / (float) height;
738
739 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
740 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
741 // We will use these two data points to extrapolate how much the wallpaper parallax effect
742 // to span (ie travel) at any aspect ratio:
743
sfufa@google.comde013292021-09-21 18:22:44 -0700744 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
745 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700746 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
747 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
748
749 // To find out the desired width at different aspect ratios, we use the following two
750 // formulas, where the coefficient on x is the aspect ratio (width/height):
751 // (16/10)x + y = 1.5
752 // (10/16)x + y = 1.2
753 // We solve for x and y and end up with a final formula:
754 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700755 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
756 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700757 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
758 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
759 return x * aspectRatio + y;
760 }
761
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700762 public interface OnIDPChangeListener {
763
Sunny Goyalb47172b2021-05-03 19:59:51 -0700764 /**
765 * Called when the device provide changes
766 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700767 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700768 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800769
770
Sunny Goyaleff44f32019-01-09 17:29:49 -0800771 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800772
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800773 public static final String TAG_NAME = "grid-option";
774
Alex Chau1c883d82021-12-01 18:43:10 +0000775 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
776 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
777 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
778 private static final int DEVICE_CATEGORY_ALL =
779 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
780
Thales Lima11af7bc2022-08-12 15:24:54 +0100781 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
782 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
783 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
784 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
785 private static final int DONT_INLINE_QSB = 0;
786
Sunny Goyaleff44f32019-01-09 17:29:49 -0800787 public final String name;
788 public final int numRows;
789 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000790 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700791 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800792
793 private final int numFolderRows;
794 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300795 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000796 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800797
Thales Limae9273ea2023-01-26 12:33:52 +0000798 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700799 private final int numAllAppsColumns;
800 private final int numDatabaseAllAppsColumns;
801 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700802 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100803
Thales Lima425f6822022-05-10 13:44:58 -0300804 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800805
Thales Lima11af7bc2022-08-12 15:24:54 +0100806 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
807
Thales Limab35faed2022-09-05 16:30:01 -0300808 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800809 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000810
Sunny Goyal415f1732018-11-29 10:33:47 -0800811 private final int defaultLayoutId;
812 private final int demoModeLayoutId;
813
Jon Mirandae126d722021-02-25 10:45:20 -0500814 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400815 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100816 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100817 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100818 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100819 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100820 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100821 private final int mFolderSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500822
Sunny Goyal076e04b2023-04-03 12:38:30 -0700823 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800824 TypedArray a = context.obtainStyledAttributes(
825 attrs, R.styleable.GridDisplayOption);
826 name = a.getString(R.styleable.GridDisplayOption_name);
827 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
828 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000829 numSearchContainerColumns = a.getInt(
830 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800831
Tracy Zhou7df93d22020-01-27 13:44:06 -0800832 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100833 defaultLayoutId = a.getResourceId(
834 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800835 demoModeLayoutId = a.getResourceId(
836 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700837
Thales Limae9273ea2023-01-26 12:33:52 +0000838 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
839 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700840 numAllAppsColumns = a.getInt(
841 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
842 numDatabaseAllAppsColumns = a.getInt(
843 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
844
845 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800846 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700847 numDatabaseHotseatIcons = a.getInt(
848 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100849
Thales Lima425f6822022-05-10 13:44:58 -0300850 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
851 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
852 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
853 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
854 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
855 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
856 numColumns);
857 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
858 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
859 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700860
Vinit Nayakc7293172022-07-18 16:41:50 -0700861 inlineNavButtonsEndSpacing =
862 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100863 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300864
Sunny Goyal415f1732018-11-29 10:33:47 -0800865 numFolderRows = a.getInt(
866 R.styleable.GridDisplayOption_numFolderRows, numRows);
867 numFolderColumns = a.getInt(
868 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700869
Thales Limab35faed2022-09-05 16:30:01 -0300870 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
871 INVALID_RESOURCE_HANDLE);
872
Thales Limad852d652023-01-17 14:01:13 +0000873 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
874 R.style.CellStyleDefault);
875
Jon Mirandae126d722021-02-25 10:45:20 -0500876 isScalable = a.getBoolean(
877 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400878 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000879 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700880 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000881 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100882
Thales Limaec5abba2023-04-05 16:33:50 +0100883 if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
884 mWorkspaceSpecsId = a.getResourceId(
885 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100886 mWorkspaceSpecsTwoPanelId = a.getResourceId(
887 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
888 INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100889 mAllAppsSpecsId = a.getResourceId(
890 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100891 mAllAppsSpecsTwoPanelId = a.getResourceId(
892 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
893 INVALID_RESOURCE_HANDLE);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100894 mFolderSpecsId = a.getResourceId(
895 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100896 mFolderSpecsTwoPanelId = a.getResourceId(
897 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
898 INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100899 } else {
900 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100901 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100902 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100903 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100904 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100905 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100906 }
907
Thales Lima11af7bc2022-08-12 15:24:54 +0100908 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
909 DONT_INLINE_QSB);
910 inlineQsb[INDEX_DEFAULT] =
911 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
912 inlineQsb[INDEX_LANDSCAPE] =
913 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
914 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
915 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
916 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
917 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
918 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
919 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
920
Sunny Goyal415f1732018-11-29 10:33:47 -0800921 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700922 }
923
924 public boolean isEnabled(@DeviceType int deviceType) {
925 switch (deviceType) {
926 case TYPE_PHONE:
927 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
928 case TYPE_TABLET:
929 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
930 case TYPE_MULTI_DISPLAY:
931 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
932 == DEVICE_CATEGORY_MULTI_DISPLAY;
933 default:
934 return false;
935 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800936 }
937 }
938
Sunny Goyal19ff7282021-04-22 10:12:54 -0700939 @VisibleForTesting
940 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700941 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800942
Sunny Goyal415f1732018-11-29 10:33:47 -0800943 private final float minWidthDps;
944 private final float minHeightDps;
945 private final boolean canBeDefault;
946
Thales Lima83bedbf2021-10-05 17:47:39 +0100947 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100948
Thales Lima78d00ad2021-09-30 11:29:06 +0100949 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100950 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100951 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
952 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100953
Thales Lima78d00ad2021-09-30 11:29:06 +0100954 private final float[] iconSizes = new float[COUNT_SIZES];
955 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800956
Thales Limab7ef5692022-03-10 10:32:36 +0000957 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000958 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
959 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
960 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
961
Jon Miranda9c478b62023-03-23 21:38:49 -0700962 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
963
Jon Miranda04f05102023-04-04 12:16:31 -0700964 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
965
Thales Lima1de4d552021-10-13 16:13:25 +0100966 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800967 this.grid = grid;
968
Jon Miranda9c478b62023-03-23 21:38:49 -0700969 Resources res = context.getResources();
970
Thales Lima1de4d552021-10-13 16:13:25 +0100971 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800972
Sunny Goyal415f1732018-11-29 10:33:47 -0800973 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
974 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700975
Thales Lima1de4d552021-10-13 16:13:25 +0100976 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800977
Thales Lima83bedbf2021-10-05 17:47:39 +0100978 float x;
979 float y;
980
Thales Lima85c942f2021-12-31 13:04:20 +0000981 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
982 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100983 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000984
985 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
986 minCellSize[INDEX_DEFAULT].x);
987 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
988 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100989 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100990
Thales Lima85c942f2021-12-31 13:04:20 +0000991 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100992 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000993 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100994 minCellSize[INDEX_DEFAULT].y);
995 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
996
Thales Lima85c942f2021-12-31 13:04:20 +0000997 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100998 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000999 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001000 minCellSize[INDEX_DEFAULT].y);
1001 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001002
Thales Lima85c942f2021-12-31 13:04:20 +00001003 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001004 float borderSpaceLandscape = a.getFloat(
1005 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001006 float borderSpaceTwoPanelPortrait = a.getFloat(
1007 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1008 float borderSpaceTwoPanelLandscape = a.getFloat(
1009 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001010
Thales Lima85c942f2021-12-31 13:04:20 +00001011 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1012 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001013 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001014
1015 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1016 borderSpaceLandscape);
1017 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1018 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001019 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1020
1021 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001022 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1023 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001024 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001025 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1026 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001027 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1028
1029 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001030 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1031 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001032 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001033 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1034 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001035 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1036
Thales Limab7ef5692022-03-10 10:32:36 +00001037 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1038 minCellSize[INDEX_DEFAULT].x);
1039 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1040 minCellSize[INDEX_DEFAULT].y);
1041 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1042
1043 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1044 allAppsCellSize[INDEX_DEFAULT].x);
1045 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1046 allAppsCellSize[INDEX_DEFAULT].y);
1047 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1048
1049 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1050 allAppsCellSize[INDEX_DEFAULT].x);
1051 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1052 allAppsCellSize[INDEX_DEFAULT].y);
1053 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1054
1055 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1056 allAppsCellSize[INDEX_DEFAULT].x);
1057 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1058 allAppsCellSize[INDEX_DEFAULT].y);
1059 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1060
Thales Lima080d8902022-03-28 15:30:29 +01001061 float allAppsBorderSpace = a.getFloat(
1062 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1063 float allAppsBorderSpaceLandscape = a.getFloat(
1064 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1065 allAppsBorderSpace);
1066 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001067 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001068 allAppsBorderSpace);
1069 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001070 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001071 allAppsBorderSpace);
1072
1073 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1074 allAppsBorderSpace);
1075 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1076 allAppsBorderSpace);
1077 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1078
1079 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1080 allAppsBorderSpaceLandscape);
1081 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1082 allAppsBorderSpaceLandscape);
1083 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1084
1085 x = a.getFloat(
1086 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1087 allAppsBorderSpaceTwoPanelPortrait);
1088 y = a.getFloat(
1089 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1090 allAppsBorderSpaceTwoPanelPortrait);
1091 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1092
1093 x = a.getFloat(
1094 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1095 allAppsBorderSpaceTwoPanelLandscape);
1096 y = a.getFloat(
1097 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1098 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001099 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001100
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001101 iconSizes[INDEX_DEFAULT] =
1102 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1103 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001104 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001105 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001106 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001107 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001108 iconSizes[INDEX_DEFAULT]);
1109 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001110 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001111 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001112
Thales Limabb7d3882021-12-22 12:56:29 +00001113 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1114 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001115 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1116 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001117 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001118 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1119 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1120 allAppsIconSizes[INDEX_DEFAULT]);
1121 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1122 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1123 allAppsIconSizes[INDEX_DEFAULT]);
1124
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001125 textSizes[INDEX_DEFAULT] =
1126 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1127 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001128 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001129 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001130 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001131 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001132 textSizes[INDEX_DEFAULT]);
1133 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001134 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001135 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001136
Thales Limabb7d3882021-12-22 12:56:29 +00001137 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1138 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1139 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1140 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1141 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1142 allAppsIconTextSizes[INDEX_DEFAULT]);
1143 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1144 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1145 allAppsIconTextSizes[INDEX_DEFAULT]);
1146
Thales Lima83bedbf2021-10-05 17:47:39 +01001147 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1148 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001149 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1150 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1151 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001152 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001153 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001154 horizontalMargin[INDEX_DEFAULT]);
1155 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001156 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001157 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001158
Thales Limab8c05952022-05-23 16:58:38 +01001159 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1160 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001161 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001162 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1163 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1164 hotseatBarBottomSpace[INDEX_DEFAULT]);
1165 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1166 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1167 hotseatBarBottomSpace[INDEX_DEFAULT]);
1168 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1169 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1170 hotseatBarBottomSpace[INDEX_DEFAULT]);
1171
1172 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1173 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001174 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001175 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1176 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1177 hotseatQsbSpace[INDEX_DEFAULT]);
1178 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1179 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1180 hotseatQsbSpace[INDEX_DEFAULT]);
1181 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1182 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1183 hotseatQsbSpace[INDEX_DEFAULT]);
1184
Jon Miranda9c478b62023-03-23 21:38:49 -07001185 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1186 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1187 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1188 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1189 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1190 transientTaskbarIconSize[INDEX_DEFAULT]);
1191 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1192 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1193 transientTaskbarIconSize[INDEX_DEFAULT]);
1194 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1195 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001196 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001197
Jon Miranda04f05102023-04-04 12:16:31 -07001198 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1199 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1200 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1201 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1202 startAlignTaskbar[INDEX_DEFAULT]);
1203 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1204 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1205 startAlignTaskbar[INDEX_LANDSCAPE]);
1206 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1207 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1208 startAlignTaskbar[INDEX_DEFAULT]);
1209
Sunny Goyal415f1732018-11-29 10:33:47 -08001210 a.recycle();
1211 }
1212
1213 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001214 this(null);
1215 }
1216
1217 DisplayOption(GridOption grid) {
1218 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001219 minWidthDps = 0;
1220 minHeightDps = 0;
1221 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001222 for (int i = 0; i < COUNT_SIZES; i++) {
1223 iconSizes[i] = 0;
1224 textSizes[i] = 0;
1225 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001226 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001227 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001228 allAppsIconSizes[i] = 0;
1229 allAppsIconTextSizes[i] = 0;
1230 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001231 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001232 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001233 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001234 }
1235
1236 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001237 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001238 iconSizes[i] *= w;
1239 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001240 borderSpaces[i].x *= w;
1241 borderSpaces[i].y *= w;
1242 minCellSize[i].x *= w;
1243 minCellSize[i].y *= w;
1244 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001245 hotseatBarBottomSpace[i] *= w;
1246 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001247 allAppsCellSize[i].x *= w;
1248 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001249 allAppsIconSizes[i] *= w;
1250 allAppsIconTextSizes[i] *= w;
1251 allAppsBorderSpaces[i].x *= w;
1252 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001253 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001254 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001255
Sunny Goyal415f1732018-11-29 10:33:47 -08001256 return this;
1257 }
1258
1259 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001260 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001261 iconSizes[i] += p.iconSizes[i];
1262 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001263 borderSpaces[i].x += p.borderSpaces[i].x;
1264 borderSpaces[i].y += p.borderSpaces[i].y;
1265 minCellSize[i].x += p.minCellSize[i].x;
1266 minCellSize[i].y += p.minCellSize[i].y;
1267 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001268 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1269 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001270 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1271 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001272 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1273 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1274 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1275 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001276 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001277 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001278 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001279
Sunny Goyal415f1732018-11-29 10:33:47 -08001280 return this;
1281 }
1282 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001283}