blob: a4d77bd64ea614dfc9b3bfd590e3c8e46bfd91b7 [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;
Sebastián Franco1f4d56c2023-08-08 03:29:10 +000021import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Thales Limab35faed2022-09-05 16:30:01 -030022import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070023import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Alex Chau6ed408f2022-03-04 12:58:05 +000024import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070025import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080026import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070027
Sunny Goyalc6205602015-05-21 20:46:33 -070028import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070029import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080030import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Sunny Goyal415f1732018-11-29 10:33:47 -080036import android.text.TextUtils;
37import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070038import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010039import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080040import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070041import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080042import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070043
Thales Limab35faed2022-09-05 16:30:01 -030044import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000045import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030046import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000048import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070050
Thales Limaec5abba2023-04-05 16:33:50 +010051import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070052import com.android.launcher3.icons.DotRenderer;
Sunny Goyal68031ca2021-08-02 12:23:44 -070053import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010054import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070055import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070056import com.android.launcher3.util.DisplayController;
57import com.android.launcher3.util.DisplayController.Info;
Stefan Andonian5bd9a222023-02-23 00:58:33 +000058import com.android.launcher3.util.LockedUserState;
Sunny Goyald0e360a2018-06-29 14:40:18 -070059import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080060import com.android.launcher3.util.Partner;
Sunny Goyal19ff7282021-04-22 10:12:54 -070061import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080062import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070063
Sunny Goyal819e1932016-07-07 16:43:58 -070064import org.xmlpull.v1.XmlPullParser;
65import org.xmlpull.v1.XmlPullParserException;
66
67import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000068import java.lang.annotation.Retention;
69import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070070import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070071import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080072import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070073import java.util.List;
Sunny Goyal076e04b2023-04-03 12:38:30 -070074import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070075
76public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070077
Hyunyoung Songc55a3502018-12-04 15:43:16 -080078 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070079 // We do not need any synchronization for this variable as its only written on UI thread.
80 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070081 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Alex Chau1c883d82021-12-01 18:43:10 +000083 @Retention(RetentionPolicy.SOURCE)
84 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010085 public @interface DeviceType {}
86
Alex Chau1c883d82021-12-01 18:43:10 +000087 public static final int TYPE_PHONE = 0;
88 public static final int TYPE_MULTI_DISPLAY = 1;
89 public static final int TYPE_TABLET = 2;
90
Sunny Goyal53d7ee42015-05-22 12:25:45 -070091 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
92
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070093 // Constants that affects the interpolation curve between statically defined device profile
94 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080095 private static final float KNEARESTNEIGHBOR = 3;
96 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070097
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070098 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080099 private static final float WEIGHT_EFFICIENT = 100000f;
100
Thales Lima83bedbf2021-10-05 17:47:39 +0100101 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
102 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000103 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104 static final int INDEX_DEFAULT = 0;
105 static final int INDEX_LANDSCAPE = 1;
106 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
107 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100108
Thales Limaec5abba2023-04-05 16:33:50 +0100109 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800110 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
111 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
112 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
113
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700114 /**
115 * Number of icons per row and column in the workspace.
116 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700117 public int numRows;
118 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000119 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700120
121 /**
122 * Number of icons per row and column in the folder.
123 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700124 public int numFolderRows;
125 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100126 public float[] iconSize;
127 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700128 public int iconBitmapSize;
129 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000130 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700131
Thales Lima83bedbf2021-10-05 17:47:39 +0100132 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100133
Thales Lima83bedbf2021-10-05 17:47:39 +0100134 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300135 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100136
Thales Limab35faed2022-09-05 16:30:01 -0300137 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100138
Thales Limad852d652023-01-17 14:01:13 +0000139 public @StyleRes int cellStyle;
140
Thales Lima83bedbf2021-10-05 17:47:39 +0100141 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500142
Thales Limab7ef5692022-03-10 10:32:36 +0000143 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000144 public float[] allAppsIconSize;
145 public float[] allAppsIconTextSize;
146 public PointF[] allAppsBorderSpaces;
147
Jon Miranda9c478b62023-03-23 21:38:49 -0700148 public float[] transientTaskbarIconSize;
149
Jon Miranda04f05102023-04-04 12:16:31 -0700150 public boolean[] startAlignTaskbar;
151
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700152 /**
153 * Number of icons inside the hotseat area.
154 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800155 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700156
157 /**
158 * Number of icons inside the hotseat area that is stored in the database. This is greater than
159 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
160 * sizes that share the same DB.
161 */
162 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700163
Thales Lima425f6822022-05-10 13:44:58 -0300164 public int[] hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100165 public float[] hotseatBarBottomSpace;
166 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300167
Jon Miranda6f7e9702019-09-16 14:44:14 -0700168 /**
169 * Number of columns in the all apps list.
170 */
171 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700172 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000173 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700174
Jon Mirandae126d722021-02-25 10:45:20 -0500175 /**
176 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
177 */
178 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000179 @XmlRes
180 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100181 @XmlRes
182 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100183 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100184 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
185 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100186 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100187 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100188 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
189 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100190 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100191 @XmlRes
192 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500193
Tracy Zhou7df93d22020-01-27 13:44:06 -0800194 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800195 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700196 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100197 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700198
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000199 /**
200 * An immutable list of supported profiles.
201 */
202 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700203
Sunny Goyal6f866092016-03-17 17:04:15 -0700204 public Point defaultWallpaperSize;
205
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700206 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700207
Sunny Goyalf633ef52018-03-13 09:57:05 -0700208 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800209 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700210
Sunny Goyalbbf01842015-10-08 07:41:15 -0700211 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700212 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700213 String gridName = getCurrentGridName(context);
214 String newGridName = initGrid(context, gridName);
215 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000216 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700217 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000218 LockedUserState.get(context).runOnUserUnlocked(() -> {
219 new DeviceGridState(this).writeToPrefs(context);
220 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700221
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700222 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100223 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000224 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
225 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100226 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700227 }
228 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700229 }
230
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700231 /**
232 * This constructor should NOT have any monitors by design.
233 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800234 public InvariantDeviceProfile(Context context, String gridName) {
235 String newName = initGrid(context, gridName);
236 if (newName == null || !newName.equals(gridName)) {
237 throw new IllegalArgumentException("Unknown grid name");
238 }
239 }
240
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700241 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800242 * This constructor should NOT have any monitors by design.
243 */
244 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700245 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100246 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700247 String gridName = getCurrentGridName(context);
248
249 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000250 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
251 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700252 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000253 defaultInfo,
254 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
255 /*allowDisabledGrid=*/false),
256 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700257
Alex Chau661f02d2022-06-07 14:03:43 +0100258 Context displayContext = context.createDisplayContext(display);
259 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000260 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000262 myInfo,
263 getPredefinedDeviceProfiles(context, gridName, deviceType,
264 /*allowDisabledGrid=*/false),
265 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700266
267 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
268 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100269 result.iconSizes[INDEX_DEFAULT] =
270 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
271 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700272 result.iconSizes[i] = Math.min(
273 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000274 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700275
Thales Lima83bedbf2021-10-05 17:47:39 +0100276 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
277 COUNT_SIZES);
278 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
279 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500280
Alex Chau1c883d82021-12-01 18:43:10 +0000281 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800282 }
283
Alex Chau238aaee2021-10-06 16:15:24 +0100284 /**
285 * Reinitialize the current grid after a restore, where some grids might now be disabled.
286 */
287 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000288 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100289 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000290 String newGridName = initGrid(context, currentGridName);
291 String newDbFile = dbFile;
292 if (!newDbFile.equals(currentDbFile)) {
293 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100294 + ", migrating to: " + newGridName
295 + ", removing all other grid db files");
296 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
297 if (gridDbFile.equals(currentDbFile)) {
298 continue;
299 }
300 if (context.getDatabasePath(gridDbFile).delete()) {
301 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
302 }
303 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000304 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100305 }
306 }
307
Alex Chau1c883d82021-12-01 18:43:10 +0000308 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800309 int flagPhone = 1 << 0;
310 int flagTablet = 1 << 1;
311
312 int type = displayInfo.supportedBounds.stream()
313 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
314 .reduce(0, (a, b) -> a | b);
Sebastián Franco1f4d56c2023-08-08 03:29:10 +0000315 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800316 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000317 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800318 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000319 return TYPE_TABLET;
320 } else {
321 return TYPE_PHONE;
322 }
323 }
324
Tracy Zhou42255d22020-03-13 00:38:11 -0700325 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000326 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700327 }
328
Sunny Goyaleff44f32019-01-09 17:29:49 -0800329 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700330 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000331 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700332
333 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000334 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100335 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700336 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000337 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
338 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700339 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800340 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700341
Thales Limab67bfa72022-11-02 15:30:11 +0000342 @VisibleForTesting
343 public static String getDefaultGridName(Context context) {
344 return new InvariantDeviceProfile().initGrid(context, null);
345 }
346
Alex Chau1c883d82021-12-01 18:43:10 +0000347 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
348 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700349 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700350 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000351 numRows = closestProfile.numRows;
352 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000353 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000354 dbFile = closestProfile.dbFile;
355 defaultLayoutId = closestProfile.defaultLayoutId;
356 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300357
Sunny Goyalae190ff2020-04-14 00:19:01 +0000358 numFolderRows = closestProfile.numFolderRows;
359 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300360 folderStyle = closestProfile.folderStyle;
361
Thales Limad852d652023-01-17 14:01:13 +0000362 cellStyle = closestProfile.cellStyle;
363
Jon Mirandae126d722021-02-25 10:45:20 -0500364 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400365 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100366 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100367 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100368 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100369 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100370 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100371 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Alex Chau1c883d82021-12-01 18:43:10 +0000372 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000373
Vinit Nayakc7293172022-07-18 16:41:50 -0700374 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
375
Thales Lima83bedbf2021-10-05 17:47:39 +0100376 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100377 float maxIconSize = iconSize[0];
378 for (int i = 1; i < iconSize.length; i++) {
379 maxIconSize = Math.max(maxIconSize, iconSize[i]);
380 }
381 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000382 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
383
Thales Lima83bedbf2021-10-05 17:47:39 +0100384 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700385
Thales Lima83bedbf2021-10-05 17:47:39 +0100386 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100387
Thales Lima83bedbf2021-10-05 17:47:39 +0100388 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100389
Thales Limad90faab2021-09-21 17:18:47 +0100390 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100391
Sunny Goyal19ff7282021-04-22 10:12:54 -0700392 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000393 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700394 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300395 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100396 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
397 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700398
Thales Limae9273ea2023-01-26 12:33:52 +0000399 allAppsStyle = closestProfile.allAppsStyle;
400
Sunny Goyal19ff7282021-04-22 10:12:54 -0700401 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000402 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700403 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500404
Thales Limab7ef5692022-03-10 10:32:36 +0000405 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000406 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
407 allAppsIconSize = displayOption.allAppsIconSizes;
408 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000409
Thales Lima11af7bc2022-08-12 15:24:54 +0100410 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000411
Jon Miranda9c478b62023-03-23 21:38:49 -0700412 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
413
Jon Miranda04f05102023-04-04 12:16:31 -0700414 startAlignTaskbar = displayOption.startAlignTaskbar;
415
Sunny Goyalae190ff2020-04-14 00:19:01 +0000416 // If the partner customization apk contains any grid overrides, apply them
417 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700418 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700419
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000420 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700421 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700422 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700423 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000424 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000425 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000426 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700427 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000428 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700429
Sunny Goyal19ff7282021-04-22 10:12:54 -0700430 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
431 int displayWidth = bounds.bounds.width();
432 int displayHeight = bounds.bounds.height();
433 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700434
Sunny Goyal19ff7282021-04-22 10:12:54 -0700435 // We need to ensure that there is enough extra space in the wallpaper
436 // for the intended parallax effects
437 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300438 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
439 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700440 ? 2
441 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
442 defaultWallpaperSize.x =
443 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700444 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000445 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700446
Thales Lima6a590062022-11-22 15:52:49 +0000447 int numMinShownHotseatIconsForTablet = supportedProfiles
448 .stream()
449 .filter(deviceProfile -> deviceProfile.isTablet)
450 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
451 .min()
452 .orElse(0);
453
454 supportedProfiles
455 .stream()
456 .filter(deviceProfile -> deviceProfile.isTablet)
457 .forEach(deviceProfile -> {
458 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
459 deviceProfile.recalculateHotseatWidthAndBorderSpace();
460 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700461 }
462
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700463 public void addOnChangeListener(OnIDPChangeListener listener) {
464 mChangeListeners.add(listener);
465 }
466
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800467 public void removeOnChangeListener(OnIDPChangeListener listener) {
468 mChangeListeners.remove(listener);
469 }
470
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800471
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800472 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000473 LauncherPrefs.get(context).put(GRID_NAME, gridName);
474 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800475 }
476
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700477 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700478 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000479 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
480 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700481 }
482
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700483 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700484 Object[] oldState = toModelState();
485
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700486 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700487 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700488 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700489
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700490 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700491 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700492 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700493 }
494 }
495
Alex Chau1c883d82021-12-01 18:43:10 +0000496 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
497 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800498 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100499
Alex Chau1c883d82021-12-01 18:43:10 +0000500 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700501 final int depth = parser.getDepth();
502 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700503 while (((type = parser.next()) != XmlPullParser.END_TAG ||
504 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800505 if ((type == XmlPullParser.START_TAG)
506 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800507
Sunny Goyal076e04b2023-04-03 12:38:30 -0700508 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
509 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100510 final int displayDepth = parser.getDepth();
511 while (((type = parser.next()) != XmlPullParser.END_TAG
512 || parser.getDepth() > displayDepth)
513 && type != XmlPullParser.END_DOCUMENT) {
514 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
515 parser.getName())) {
516 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100517 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100518 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800519 }
520 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700521 }
522 }
sfufa@google.comde013292021-09-21 18:22:44 -0700523 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700524 throw new RuntimeException(e);
525 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800526
Sunny Goyalae190ff2020-04-14 00:19:01 +0000527 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800528 if (!TextUtils.isEmpty(gridName)) {
529 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100530 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700531 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000532 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800533 }
534 }
535 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000536 if (filteredProfiles.isEmpty()) {
537 // No grid found, use the default options
538 for (DisplayOption option : profiles) {
539 if (option.canBeDefault) {
540 filteredProfiles.add(option);
541 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800542 }
543 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000544 if (filteredProfiles.isEmpty()) {
545 throw new RuntimeException("No display option with canBeDefault=true");
546 }
547 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700548 }
549
Thales Lima7ec83822021-08-05 13:32:10 +0100550 /**
551 * @return all the grid options that can be shown on the device
552 */
553 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700554 return parseAllDefinedGridOptions(context)
555 .stream()
556 .filter(go -> go.isEnabled(deviceType))
557 .collect(Collectors.toList());
558 }
559
560 /**
561 * @return all the grid options that can be shown on the device
562 */
563 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100564 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100565
Alex Chau1c883d82021-12-01 18:43:10 +0000566 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100567 final int depth = parser.getDepth();
568 int type;
569 while (((type = parser.next()) != XmlPullParser.END_TAG
570 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
571 if ((type == XmlPullParser.START_TAG)
572 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700573 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100574 }
575 }
576 } catch (IOException | XmlPullParserException e) {
577 Log.e(TAG, "Error parsing device profile", e);
578 return Collections.emptyList();
579 }
580 return result;
581 }
582
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700583 private int getLauncherIconDensity(int requiredSize) {
584 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700585 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700586 DisplayMetrics.DENSITY_LOW,
587 DisplayMetrics.DENSITY_MEDIUM,
588 DisplayMetrics.DENSITY_TV,
589 DisplayMetrics.DENSITY_HIGH,
590 DisplayMetrics.DENSITY_XHIGH,
591 DisplayMetrics.DENSITY_XXHIGH,
592 DisplayMetrics.DENSITY_XXXHIGH
593 };
594
595 int density = DisplayMetrics.DENSITY_XXXHIGH;
596 for (int i = densityBuckets.length - 1; i >= 0; i--) {
597 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
598 / DisplayMetrics.DENSITY_DEFAULT;
599 if (expectedSize >= requiredSize) {
600 density = densityBuckets[i];
601 }
602 }
603
604 return density;
605 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700606
Adam Cohen2e6da152015-05-06 11:42:25 -0700607 /**
608 * Apply any Partner customization grid overrides.
609 *
610 * Currently we support: all apps row / column count.
611 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700612 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
613 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800614 if (p == null) {
615 return;
616 }
617 try {
618 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
619 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
620 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
621
622 if (numRows > 0 && numColumns > 0) {
623 this.numRows = numRows;
624 this.numColumns = numColumns;
625 }
626 if (iconSizePx > 0) {
627 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
628 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
629 }
630 } catch (Resources.NotFoundException ex) {
631 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700632 }
633 }
634
Sunny Goyal415f1732018-11-29 10:33:47 -0800635 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700636 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700637 }
638
Sunny Goyal19ff7282021-04-22 10:12:54 -0700639 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000640 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700641 int minWidthPx = Integer.MAX_VALUE;
642 int minHeightPx = Integer.MAX_VALUE;
643 for (WindowBounds bounds : displayInfo.supportedBounds) {
644 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000645 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700646 // For split displays, take half width per page
647 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
648 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700649
Sunny Goyal19ff7282021-04-22 10:12:54 -0700650 } else if (!isTablet && bounds.isLandscape()) {
651 // We will use transposed layout in this case
652 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
653 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
654 } else {
655 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
656 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
657 }
658 }
659
Thales Lima425f6822022-05-10 13:44:58 -0300660 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
661 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700662
663 // Sort the profiles based on the closeness to the device size
664 Collections.sort(points, (a, b) ->
665 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
666 dist(width, height, b.minWidthDps, b.minHeightDps)));
667
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700668 DisplayOption closestPoint = points.get(0);
669 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700670 float weights = 0;
671
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700672 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
673 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700674 }
675
676 DisplayOption out = new DisplayOption(closestOption);
677 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700678 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700679 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
680 weights += w;
681 out.add(new DisplayOption().add(p).multiply(w));
682 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700683 out.multiply(1.0f / weights);
684
Thales Lima6e0005a2021-10-27 15:53:41 +0100685 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700686 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100687 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
688 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700689 }
690
691 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700692 }
693
Sunny Goyal27835952017-01-13 12:15:53 -0800694 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700695 Resources res = context.getResources();
696 Configuration config = context.getResources().getConfiguration();
697
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400698 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
699 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100700 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
701
Alex Chaud3e8cc42022-05-03 17:45:34 +0100702 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400703 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700704
Sunny Goyal187b16c2022-03-01 16:53:23 -0800705 /**
706 * Returns the device profile matching the provided screen configuration
707 */
708 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700709 DeviceProfile bestMatch = supportedProfiles.get(0);
710 float minDiff = Float.MAX_VALUE;
711
712 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400713 float diff = Math.abs(profile.widthPx - screenWidth)
714 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700715 if (diff < minDiff) {
716 minDiff = diff;
717 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800718 } else if (diff == minDiff && profile.rotationHint == rotation) {
719 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700720 }
721 }
722 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800723 }
724
Sunny Goyal415f1732018-11-29 10:33:47 -0800725 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700726 float d = dist(x0, y0, x1, y1);
727 if (Float.compare(d, 0f) == 0) {
728 return Float.POSITIVE_INFINITY;
729 }
730 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
731 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700732
733 /**
734 * As a ratio of screen height, the total distance we want the parallax effect to span
735 * horizontally
736 */
737 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
738 float aspectRatio = width / (float) height;
739
740 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
741 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
742 // We will use these two data points to extrapolate how much the wallpaper parallax effect
743 // to span (ie travel) at any aspect ratio:
744
sfufa@google.comde013292021-09-21 18:22:44 -0700745 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
746 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700747 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
748 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
749
750 // To find out the desired width at different aspect ratios, we use the following two
751 // formulas, where the coefficient on x is the aspect ratio (width/height):
752 // (16/10)x + y = 1.5
753 // (10/16)x + y = 1.2
754 // We solve for x and y and end up with a final formula:
755 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700756 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
757 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700758 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
759 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
760 return x * aspectRatio + y;
761 }
762
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700763 public interface OnIDPChangeListener {
764
Sunny Goyalb47172b2021-05-03 19:59:51 -0700765 /**
766 * Called when the device provide changes
767 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700768 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700769 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800770
771
Sunny Goyaleff44f32019-01-09 17:29:49 -0800772 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800773
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800774 public static final String TAG_NAME = "grid-option";
775
Alex Chau1c883d82021-12-01 18:43:10 +0000776 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
777 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
778 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
779 private static final int DEVICE_CATEGORY_ALL =
780 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
781
Thales Lima11af7bc2022-08-12 15:24:54 +0100782 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
783 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
784 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
785 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
786 private static final int DONT_INLINE_QSB = 0;
787
Sunny Goyaleff44f32019-01-09 17:29:49 -0800788 public final String name;
789 public final int numRows;
790 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000791 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700792 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800793
794 private final int numFolderRows;
795 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300796 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000797 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800798
Thales Limae9273ea2023-01-26 12:33:52 +0000799 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700800 private final int numAllAppsColumns;
801 private final int numDatabaseAllAppsColumns;
802 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700803 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100804
Thales Lima425f6822022-05-10 13:44:58 -0300805 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800806
Thales Lima11af7bc2022-08-12 15:24:54 +0100807 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
808
Thales Limab35faed2022-09-05 16:30:01 -0300809 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800810 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000811
Sunny Goyal415f1732018-11-29 10:33:47 -0800812 private final int defaultLayoutId;
813 private final int demoModeLayoutId;
814
Jon Mirandae126d722021-02-25 10:45:20 -0500815 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400816 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100817 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100818 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100819 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100820 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100821 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100822 private final int mFolderSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500823
Sunny Goyal076e04b2023-04-03 12:38:30 -0700824 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800825 TypedArray a = context.obtainStyledAttributes(
826 attrs, R.styleable.GridDisplayOption);
827 name = a.getString(R.styleable.GridDisplayOption_name);
828 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
829 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000830 numSearchContainerColumns = a.getInt(
831 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800832
Tracy Zhou7df93d22020-01-27 13:44:06 -0800833 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100834 defaultLayoutId = a.getResourceId(
835 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800836 demoModeLayoutId = a.getResourceId(
837 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700838
Thales Limae9273ea2023-01-26 12:33:52 +0000839 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
840 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700841 numAllAppsColumns = a.getInt(
842 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
843 numDatabaseAllAppsColumns = a.getInt(
844 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
845
846 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800847 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700848 numDatabaseHotseatIcons = a.getInt(
849 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100850
Thales Lima425f6822022-05-10 13:44:58 -0300851 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
852 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
853 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
854 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
855 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
856 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
857 numColumns);
858 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
859 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
860 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700861
Vinit Nayakc7293172022-07-18 16:41:50 -0700862 inlineNavButtonsEndSpacing =
863 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100864 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300865
Sunny Goyal415f1732018-11-29 10:33:47 -0800866 numFolderRows = a.getInt(
867 R.styleable.GridDisplayOption_numFolderRows, numRows);
868 numFolderColumns = a.getInt(
869 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700870
Thales Limab35faed2022-09-05 16:30:01 -0300871 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
872 INVALID_RESOURCE_HANDLE);
873
Thales Limad852d652023-01-17 14:01:13 +0000874 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
875 R.style.CellStyleDefault);
876
Jon Mirandae126d722021-02-25 10:45:20 -0500877 isScalable = a.getBoolean(
878 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400879 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000880 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700881 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000882 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100883
Thales Limaec5abba2023-04-05 16:33:50 +0100884 if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
885 mWorkspaceSpecsId = a.getResourceId(
886 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100887 mWorkspaceSpecsTwoPanelId = a.getResourceId(
888 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
889 INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100890 mAllAppsSpecsId = a.getResourceId(
891 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100892 mAllAppsSpecsTwoPanelId = a.getResourceId(
893 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
894 INVALID_RESOURCE_HANDLE);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100895 mFolderSpecsId = a.getResourceId(
896 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100897 mFolderSpecsTwoPanelId = a.getResourceId(
898 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
899 INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100900 } else {
901 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100902 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100903 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100904 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100905 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100906 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100907 }
908
Thales Lima11af7bc2022-08-12 15:24:54 +0100909 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
910 DONT_INLINE_QSB);
911 inlineQsb[INDEX_DEFAULT] =
912 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
913 inlineQsb[INDEX_LANDSCAPE] =
914 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
915 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
916 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
917 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
918 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
919 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
920 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
921
Sunny Goyal415f1732018-11-29 10:33:47 -0800922 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700923 }
924
925 public boolean isEnabled(@DeviceType int deviceType) {
926 switch (deviceType) {
927 case TYPE_PHONE:
928 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
929 case TYPE_TABLET:
930 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
931 case TYPE_MULTI_DISPLAY:
932 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
933 == DEVICE_CATEGORY_MULTI_DISPLAY;
934 default:
935 return false;
936 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800937 }
938 }
939
Sunny Goyal19ff7282021-04-22 10:12:54 -0700940 @VisibleForTesting
941 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700942 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800943
Sunny Goyal415f1732018-11-29 10:33:47 -0800944 private final float minWidthDps;
945 private final float minHeightDps;
946 private final boolean canBeDefault;
947
Thales Lima83bedbf2021-10-05 17:47:39 +0100948 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100949
Thales Lima78d00ad2021-09-30 11:29:06 +0100950 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100951 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100952 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
953 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100954
Thales Lima78d00ad2021-09-30 11:29:06 +0100955 private final float[] iconSizes = new float[COUNT_SIZES];
956 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800957
Thales Limab7ef5692022-03-10 10:32:36 +0000958 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000959 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
960 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
961 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
962
Jon Miranda9c478b62023-03-23 21:38:49 -0700963 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
964
Jon Miranda04f05102023-04-04 12:16:31 -0700965 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
966
Thales Lima1de4d552021-10-13 16:13:25 +0100967 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800968 this.grid = grid;
969
Jon Miranda9c478b62023-03-23 21:38:49 -0700970 Resources res = context.getResources();
971
Thales Lima1de4d552021-10-13 16:13:25 +0100972 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800973
Sunny Goyal415f1732018-11-29 10:33:47 -0800974 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
975 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700976
Thales Lima1de4d552021-10-13 16:13:25 +0100977 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800978
Thales Lima83bedbf2021-10-05 17:47:39 +0100979 float x;
980 float y;
981
Thales Lima85c942f2021-12-31 13:04:20 +0000982 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
983 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100984 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000985
986 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
987 minCellSize[INDEX_DEFAULT].x);
988 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
989 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100990 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100991
Thales Lima85c942f2021-12-31 13:04:20 +0000992 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100993 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000994 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100995 minCellSize[INDEX_DEFAULT].y);
996 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
997
Thales Lima85c942f2021-12-31 13:04:20 +0000998 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100999 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001000 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001001 minCellSize[INDEX_DEFAULT].y);
1002 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001003
Thales Lima85c942f2021-12-31 13:04:20 +00001004 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001005 float borderSpaceLandscape = a.getFloat(
1006 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001007 float borderSpaceTwoPanelPortrait = a.getFloat(
1008 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1009 float borderSpaceTwoPanelLandscape = a.getFloat(
1010 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001011
Thales Lima85c942f2021-12-31 13:04:20 +00001012 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1013 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001014 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001015
1016 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1017 borderSpaceLandscape);
1018 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1019 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001020 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1021
1022 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001023 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1024 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001025 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001026 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1027 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001028 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1029
1030 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001031 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1032 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001033 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001034 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1035 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001036 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1037
Thales Limab7ef5692022-03-10 10:32:36 +00001038 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1039 minCellSize[INDEX_DEFAULT].x);
1040 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1041 minCellSize[INDEX_DEFAULT].y);
1042 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1043
1044 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1045 allAppsCellSize[INDEX_DEFAULT].x);
1046 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1047 allAppsCellSize[INDEX_DEFAULT].y);
1048 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1049
1050 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1051 allAppsCellSize[INDEX_DEFAULT].x);
1052 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1053 allAppsCellSize[INDEX_DEFAULT].y);
1054 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1055
1056 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1057 allAppsCellSize[INDEX_DEFAULT].x);
1058 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1059 allAppsCellSize[INDEX_DEFAULT].y);
1060 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1061
Thales Lima080d8902022-03-28 15:30:29 +01001062 float allAppsBorderSpace = a.getFloat(
1063 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1064 float allAppsBorderSpaceLandscape = a.getFloat(
1065 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1066 allAppsBorderSpace);
1067 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001068 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001069 allAppsBorderSpace);
1070 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001071 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001072 allAppsBorderSpace);
1073
1074 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1075 allAppsBorderSpace);
1076 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1077 allAppsBorderSpace);
1078 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1079
1080 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1081 allAppsBorderSpaceLandscape);
1082 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1083 allAppsBorderSpaceLandscape);
1084 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1085
1086 x = a.getFloat(
1087 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1088 allAppsBorderSpaceTwoPanelPortrait);
1089 y = a.getFloat(
1090 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1091 allAppsBorderSpaceTwoPanelPortrait);
1092 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1093
1094 x = a.getFloat(
1095 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1096 allAppsBorderSpaceTwoPanelLandscape);
1097 y = a.getFloat(
1098 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1099 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001100 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001101
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001102 iconSizes[INDEX_DEFAULT] =
1103 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1104 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001105 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001106 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001107 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001108 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001109 iconSizes[INDEX_DEFAULT]);
1110 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001111 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001112 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001113
Thales Limabb7d3882021-12-22 12:56:29 +00001114 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1115 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001116 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1117 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001118 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001119 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1120 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1121 allAppsIconSizes[INDEX_DEFAULT]);
1122 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1123 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1124 allAppsIconSizes[INDEX_DEFAULT]);
1125
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001126 textSizes[INDEX_DEFAULT] =
1127 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1128 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001129 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001130 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001131 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001132 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001133 textSizes[INDEX_DEFAULT]);
1134 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001135 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001136 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001137
Thales Limabb7d3882021-12-22 12:56:29 +00001138 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1139 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1140 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1141 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1142 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1143 allAppsIconTextSizes[INDEX_DEFAULT]);
1144 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1145 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1146 allAppsIconTextSizes[INDEX_DEFAULT]);
1147
Thales Lima83bedbf2021-10-05 17:47:39 +01001148 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1149 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001150 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1151 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1152 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001153 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001154 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001155 horizontalMargin[INDEX_DEFAULT]);
1156 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001157 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001158 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001159
Thales Limab8c05952022-05-23 16:58:38 +01001160 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1161 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001162 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001163 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1164 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1165 hotseatBarBottomSpace[INDEX_DEFAULT]);
1166 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1167 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1168 hotseatBarBottomSpace[INDEX_DEFAULT]);
1169 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1170 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1171 hotseatBarBottomSpace[INDEX_DEFAULT]);
1172
1173 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1174 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001175 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001176 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1177 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1178 hotseatQsbSpace[INDEX_DEFAULT]);
1179 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1180 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1181 hotseatQsbSpace[INDEX_DEFAULT]);
1182 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1183 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1184 hotseatQsbSpace[INDEX_DEFAULT]);
1185
Jon Miranda9c478b62023-03-23 21:38:49 -07001186 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1187 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1188 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1189 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1190 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1191 transientTaskbarIconSize[INDEX_DEFAULT]);
1192 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1193 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1194 transientTaskbarIconSize[INDEX_DEFAULT]);
1195 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1196 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001197 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001198
Jon Miranda04f05102023-04-04 12:16:31 -07001199 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1200 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1201 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1202 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1203 startAlignTaskbar[INDEX_DEFAULT]);
1204 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1205 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1206 startAlignTaskbar[INDEX_LANDSCAPE]);
1207 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1208 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1209 startAlignTaskbar[INDEX_DEFAULT]);
1210
Sunny Goyal415f1732018-11-29 10:33:47 -08001211 a.recycle();
1212 }
1213
1214 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001215 this(null);
1216 }
1217
1218 DisplayOption(GridOption grid) {
1219 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001220 minWidthDps = 0;
1221 minHeightDps = 0;
1222 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001223 for (int i = 0; i < COUNT_SIZES; i++) {
1224 iconSizes[i] = 0;
1225 textSizes[i] = 0;
1226 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001227 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001228 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001229 allAppsIconSizes[i] = 0;
1230 allAppsIconTextSizes[i] = 0;
1231 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001232 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001233 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001234 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001235 }
1236
1237 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001238 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001239 iconSizes[i] *= w;
1240 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001241 borderSpaces[i].x *= w;
1242 borderSpaces[i].y *= w;
1243 minCellSize[i].x *= w;
1244 minCellSize[i].y *= w;
1245 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001246 hotseatBarBottomSpace[i] *= w;
1247 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001248 allAppsCellSize[i].x *= w;
1249 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001250 allAppsIconSizes[i] *= w;
1251 allAppsIconTextSizes[i] *= w;
1252 allAppsBorderSpaces[i].x *= w;
1253 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001254 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001255 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001256
Sunny Goyal415f1732018-11-29 10:33:47 -08001257 return this;
1258 }
1259
1260 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001261 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001262 iconSizes[i] += p.iconSizes[i];
1263 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001264 borderSpaces[i].x += p.borderSpaces[i].x;
1265 borderSpaces[i].y += p.borderSpaces[i].y;
1266 minCellSize[i].x += p.minCellSize[i].x;
1267 minCellSize[i].y += p.minCellSize[i].y;
1268 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001269 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1270 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001271 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1272 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001273 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1274 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1275 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1276 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001277 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001278 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001279 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001280
Sunny Goyal415f1732018-11-29 10:33:47 -08001281 return this;
1282 }
1283 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001284}