blob: be14844fbc38f6d24da232a286f4d7a46660d3f3 [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;
Thales Limaf8bfb032023-07-24 15:08:05 +0100193 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
194 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500195
Tracy Zhou7df93d22020-01-27 13:44:06 -0800196 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800197 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700198 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100199 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700200
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000201 /**
202 * An immutable list of supported profiles.
203 */
204 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700205
Sunny Goyal6f866092016-03-17 17:04:15 -0700206 public Point defaultWallpaperSize;
207
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700208 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700209
Sunny Goyalf633ef52018-03-13 09:57:05 -0700210 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800211 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700212
Sunny Goyalbbf01842015-10-08 07:41:15 -0700213 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700214 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700215 String gridName = getCurrentGridName(context);
216 String newGridName = initGrid(context, gridName);
217 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000218 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700219 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000220 LockedUserState.get(context).runOnUserUnlocked(() -> {
221 new DeviceGridState(this).writeToPrefs(context);
222 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700224 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100225 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000226 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
227 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100228 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700229 }
230 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700231 }
232
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700233 /**
234 * This constructor should NOT have any monitors by design.
235 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800236 public InvariantDeviceProfile(Context context, String gridName) {
237 String newName = initGrid(context, gridName);
238 if (newName == null || !newName.equals(gridName)) {
239 throw new IllegalArgumentException("Unknown grid name");
240 }
241 }
242
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700243 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800244 * This constructor should NOT have any monitors by design.
245 */
246 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700247 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100248 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700249 String gridName = getCurrentGridName(context);
250
251 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000252 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
253 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700254 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000255 defaultInfo,
256 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
257 /*allowDisabledGrid=*/false),
258 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700259
Alex Chau661f02d2022-06-07 14:03:43 +0100260 Context displayContext = context.createDisplayContext(display);
261 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000262 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700263 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000264 myInfo,
265 getPredefinedDeviceProfiles(context, gridName, deviceType,
266 /*allowDisabledGrid=*/false),
267 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700268
269 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
270 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100271 result.iconSizes[INDEX_DEFAULT] =
272 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
273 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700274 result.iconSizes[i] = Math.min(
275 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000276 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700277
Thales Lima83bedbf2021-10-05 17:47:39 +0100278 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
279 COUNT_SIZES);
280 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
281 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500282
Alex Chau1c883d82021-12-01 18:43:10 +0000283 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800284 }
285
Alex Chau238aaee2021-10-06 16:15:24 +0100286 /**
287 * Reinitialize the current grid after a restore, where some grids might now be disabled.
288 */
289 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000290 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100291 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000292 String newGridName = initGrid(context, currentGridName);
293 String newDbFile = dbFile;
294 if (!newDbFile.equals(currentDbFile)) {
295 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100296 + ", migrating to: " + newGridName
297 + ", removing all other grid db files");
298 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
299 if (gridDbFile.equals(currentDbFile)) {
300 continue;
301 }
302 if (context.getDatabasePath(gridDbFile).delete()) {
303 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
304 }
305 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000306 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100307 }
308 }
309
Alex Chau1c883d82021-12-01 18:43:10 +0000310 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800311 int flagPhone = 1 << 0;
312 int flagTablet = 1 << 1;
313
314 int type = displayInfo.supportedBounds.stream()
315 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
316 .reduce(0, (a, b) -> a | b);
Sebastián Franco1f4d56c2023-08-08 03:29:10 +0000317 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800318 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000319 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800320 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000321 return TYPE_TABLET;
322 } else {
323 return TYPE_PHONE;
324 }
325 }
326
Tracy Zhou42255d22020-03-13 00:38:11 -0700327 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000328 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700329 }
330
Sunny Goyaleff44f32019-01-09 17:29:49 -0800331 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700332 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000333 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700334
335 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000336 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100337 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700338 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000339 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
340 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700341 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800342 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700343
Thales Limab67bfa72022-11-02 15:30:11 +0000344 @VisibleForTesting
345 public static String getDefaultGridName(Context context) {
346 return new InvariantDeviceProfile().initGrid(context, null);
347 }
348
Alex Chau1c883d82021-12-01 18:43:10 +0000349 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
350 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700351 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700352 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000353 numRows = closestProfile.numRows;
354 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000355 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000356 dbFile = closestProfile.dbFile;
357 defaultLayoutId = closestProfile.defaultLayoutId;
358 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300359
Sunny Goyalae190ff2020-04-14 00:19:01 +0000360 numFolderRows = closestProfile.numFolderRows;
361 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300362 folderStyle = closestProfile.folderStyle;
363
Thales Limad852d652023-01-17 14:01:13 +0000364 cellStyle = closestProfile.cellStyle;
365
Jon Mirandae126d722021-02-25 10:45:20 -0500366 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400367 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100368 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100369 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100370 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100371 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100372 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100373 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100374 hotseatSpecsId = closestProfile.mHotseatSpecsId;
375 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Alex Chau1c883d82021-12-01 18:43:10 +0000376 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000377
Vinit Nayakc7293172022-07-18 16:41:50 -0700378 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
379
Thales Lima83bedbf2021-10-05 17:47:39 +0100380 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100381 float maxIconSize = iconSize[0];
382 for (int i = 1; i < iconSize.length; i++) {
383 maxIconSize = Math.max(maxIconSize, iconSize[i]);
384 }
385 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000386 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
387
Thales Lima83bedbf2021-10-05 17:47:39 +0100388 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700389
Thales Lima83bedbf2021-10-05 17:47:39 +0100390 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100391
Thales Lima83bedbf2021-10-05 17:47:39 +0100392 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100393
Thales Limad90faab2021-09-21 17:18:47 +0100394 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100395
Sunny Goyal19ff7282021-04-22 10:12:54 -0700396 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000397 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700398 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300399 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100400 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
401 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700402
Thales Limae9273ea2023-01-26 12:33:52 +0000403 allAppsStyle = closestProfile.allAppsStyle;
404
Sunny Goyal19ff7282021-04-22 10:12:54 -0700405 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000406 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700407 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500408
Thales Limab7ef5692022-03-10 10:32:36 +0000409 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000410 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
411 allAppsIconSize = displayOption.allAppsIconSizes;
412 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000413
Thales Lima11af7bc2022-08-12 15:24:54 +0100414 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000415
Jon Miranda9c478b62023-03-23 21:38:49 -0700416 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
417
Jon Miranda04f05102023-04-04 12:16:31 -0700418 startAlignTaskbar = displayOption.startAlignTaskbar;
419
Sunny Goyalae190ff2020-04-14 00:19:01 +0000420 // If the partner customization apk contains any grid overrides, apply them
421 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700422 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700423
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000424 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700425 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700426 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700427 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000428 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000429 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000430 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700431 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000432 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700433
Sunny Goyal19ff7282021-04-22 10:12:54 -0700434 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
435 int displayWidth = bounds.bounds.width();
436 int displayHeight = bounds.bounds.height();
437 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700438
Sunny Goyal19ff7282021-04-22 10:12:54 -0700439 // We need to ensure that there is enough extra space in the wallpaper
440 // for the intended parallax effects
441 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300442 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
443 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700444 ? 2
445 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
446 defaultWallpaperSize.x =
447 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700448 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000449 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700450
Thales Lima6a590062022-11-22 15:52:49 +0000451 int numMinShownHotseatIconsForTablet = supportedProfiles
452 .stream()
453 .filter(deviceProfile -> deviceProfile.isTablet)
454 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
455 .min()
456 .orElse(0);
457
458 supportedProfiles
459 .stream()
460 .filter(deviceProfile -> deviceProfile.isTablet)
461 .forEach(deviceProfile -> {
462 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
463 deviceProfile.recalculateHotseatWidthAndBorderSpace();
464 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700465 }
466
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700467 public void addOnChangeListener(OnIDPChangeListener listener) {
468 mChangeListeners.add(listener);
469 }
470
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800471 public void removeOnChangeListener(OnIDPChangeListener listener) {
472 mChangeListeners.remove(listener);
473 }
474
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800475
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800476 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000477 LauncherPrefs.get(context).put(GRID_NAME, gridName);
478 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800479 }
480
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700481 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700482 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000483 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
484 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700485 }
486
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700487 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700488 Object[] oldState = toModelState();
489
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700490 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700491 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700492 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700493
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700494 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700495 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700496 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700497 }
498 }
499
Alex Chau1c883d82021-12-01 18:43:10 +0000500 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
501 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800502 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100503
Alex Chau1c883d82021-12-01 18:43:10 +0000504 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700505 final int depth = parser.getDepth();
506 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700507 while (((type = parser.next()) != XmlPullParser.END_TAG ||
508 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800509 if ((type == XmlPullParser.START_TAG)
510 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800511
Sunny Goyal076e04b2023-04-03 12:38:30 -0700512 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
513 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100514 final int displayDepth = parser.getDepth();
515 while (((type = parser.next()) != XmlPullParser.END_TAG
516 || parser.getDepth() > displayDepth)
517 && type != XmlPullParser.END_DOCUMENT) {
518 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
519 parser.getName())) {
520 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100521 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100522 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800523 }
524 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700525 }
526 }
sfufa@google.comde013292021-09-21 18:22:44 -0700527 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700528 throw new RuntimeException(e);
529 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800530
Sunny Goyalae190ff2020-04-14 00:19:01 +0000531 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800532 if (!TextUtils.isEmpty(gridName)) {
533 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100534 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700535 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000536 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800537 }
538 }
539 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000540 if (filteredProfiles.isEmpty()) {
541 // No grid found, use the default options
542 for (DisplayOption option : profiles) {
543 if (option.canBeDefault) {
544 filteredProfiles.add(option);
545 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800546 }
547 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000548 if (filteredProfiles.isEmpty()) {
549 throw new RuntimeException("No display option with canBeDefault=true");
550 }
551 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700552 }
553
Thales Lima7ec83822021-08-05 13:32:10 +0100554 /**
555 * @return all the grid options that can be shown on the device
556 */
557 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700558 return parseAllDefinedGridOptions(context)
559 .stream()
560 .filter(go -> go.isEnabled(deviceType))
561 .collect(Collectors.toList());
562 }
563
564 /**
565 * @return all the grid options that can be shown on the device
566 */
567 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100568 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100569
Alex Chau1c883d82021-12-01 18:43:10 +0000570 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100571 final int depth = parser.getDepth();
572 int type;
573 while (((type = parser.next()) != XmlPullParser.END_TAG
574 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
575 if ((type == XmlPullParser.START_TAG)
576 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700577 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100578 }
579 }
580 } catch (IOException | XmlPullParserException e) {
581 Log.e(TAG, "Error parsing device profile", e);
582 return Collections.emptyList();
583 }
584 return result;
585 }
586
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700587 private int getLauncherIconDensity(int requiredSize) {
588 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700589 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700590 DisplayMetrics.DENSITY_LOW,
591 DisplayMetrics.DENSITY_MEDIUM,
592 DisplayMetrics.DENSITY_TV,
593 DisplayMetrics.DENSITY_HIGH,
594 DisplayMetrics.DENSITY_XHIGH,
595 DisplayMetrics.DENSITY_XXHIGH,
596 DisplayMetrics.DENSITY_XXXHIGH
597 };
598
599 int density = DisplayMetrics.DENSITY_XXXHIGH;
600 for (int i = densityBuckets.length - 1; i >= 0; i--) {
601 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
602 / DisplayMetrics.DENSITY_DEFAULT;
603 if (expectedSize >= requiredSize) {
604 density = densityBuckets[i];
605 }
606 }
607
608 return density;
609 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700610
Adam Cohen2e6da152015-05-06 11:42:25 -0700611 /**
612 * Apply any Partner customization grid overrides.
613 *
614 * Currently we support: all apps row / column count.
615 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700616 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
617 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800618 if (p == null) {
619 return;
620 }
621 try {
622 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
623 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
624 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
625
626 if (numRows > 0 && numColumns > 0) {
627 this.numRows = numRows;
628 this.numColumns = numColumns;
629 }
630 if (iconSizePx > 0) {
631 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
632 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
633 }
634 } catch (Resources.NotFoundException ex) {
635 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700636 }
637 }
638
Sunny Goyal415f1732018-11-29 10:33:47 -0800639 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700640 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700641 }
642
Sunny Goyal19ff7282021-04-22 10:12:54 -0700643 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000644 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700645 int minWidthPx = Integer.MAX_VALUE;
646 int minHeightPx = Integer.MAX_VALUE;
647 for (WindowBounds bounds : displayInfo.supportedBounds) {
648 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000649 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700650 // For split displays, take half width per page
651 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
652 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700653
Sunny Goyal19ff7282021-04-22 10:12:54 -0700654 } else if (!isTablet && bounds.isLandscape()) {
655 // We will use transposed layout in this case
656 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
657 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
658 } else {
659 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
660 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
661 }
662 }
663
Thales Lima425f6822022-05-10 13:44:58 -0300664 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
665 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700666
667 // Sort the profiles based on the closeness to the device size
668 Collections.sort(points, (a, b) ->
669 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
670 dist(width, height, b.minWidthDps, b.minHeightDps)));
671
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700672 DisplayOption closestPoint = points.get(0);
673 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700674 float weights = 0;
675
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700676 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
677 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700678 }
679
680 DisplayOption out = new DisplayOption(closestOption);
681 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700682 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700683 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
684 weights += w;
685 out.add(new DisplayOption().add(p).multiply(w));
686 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700687 out.multiply(1.0f / weights);
688
Thales Lima6e0005a2021-10-27 15:53:41 +0100689 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700690 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100691 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
692 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700693 }
694
695 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700696 }
697
Sunny Goyal27835952017-01-13 12:15:53 -0800698 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700699 Resources res = context.getResources();
700 Configuration config = context.getResources().getConfiguration();
701
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400702 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
703 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100704 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
705
Alex Chaud3e8cc42022-05-03 17:45:34 +0100706 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400707 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700708
Sunny Goyal187b16c2022-03-01 16:53:23 -0800709 /**
710 * Returns the device profile matching the provided screen configuration
711 */
712 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700713 DeviceProfile bestMatch = supportedProfiles.get(0);
714 float minDiff = Float.MAX_VALUE;
715
716 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400717 float diff = Math.abs(profile.widthPx - screenWidth)
718 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700719 if (diff < minDiff) {
720 minDiff = diff;
721 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800722 } else if (diff == minDiff && profile.rotationHint == rotation) {
723 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700724 }
725 }
726 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800727 }
728
Sunny Goyal415f1732018-11-29 10:33:47 -0800729 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700730 float d = dist(x0, y0, x1, y1);
731 if (Float.compare(d, 0f) == 0) {
732 return Float.POSITIVE_INFINITY;
733 }
734 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
735 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700736
737 /**
738 * As a ratio of screen height, the total distance we want the parallax effect to span
739 * horizontally
740 */
741 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
742 float aspectRatio = width / (float) height;
743
744 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
745 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
746 // We will use these two data points to extrapolate how much the wallpaper parallax effect
747 // to span (ie travel) at any aspect ratio:
748
sfufa@google.comde013292021-09-21 18:22:44 -0700749 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
750 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700751 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
752 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
753
754 // To find out the desired width at different aspect ratios, we use the following two
755 // formulas, where the coefficient on x is the aspect ratio (width/height):
756 // (16/10)x + y = 1.5
757 // (10/16)x + y = 1.2
758 // We solve for x and y and end up with a final formula:
759 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700760 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
761 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700762 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
763 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
764 return x * aspectRatio + y;
765 }
766
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700767 public interface OnIDPChangeListener {
768
Sunny Goyalb47172b2021-05-03 19:59:51 -0700769 /**
770 * Called when the device provide changes
771 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700772 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700773 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800774
775
Sunny Goyaleff44f32019-01-09 17:29:49 -0800776 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800777
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800778 public static final String TAG_NAME = "grid-option";
779
Alex Chau1c883d82021-12-01 18:43:10 +0000780 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
781 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
782 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
783 private static final int DEVICE_CATEGORY_ALL =
784 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
785
Thales Lima11af7bc2022-08-12 15:24:54 +0100786 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
787 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
788 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
789 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
790 private static final int DONT_INLINE_QSB = 0;
791
Sunny Goyaleff44f32019-01-09 17:29:49 -0800792 public final String name;
793 public final int numRows;
794 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000795 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700796 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800797
798 private final int numFolderRows;
799 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300800 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000801 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800802
Thales Limae9273ea2023-01-26 12:33:52 +0000803 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700804 private final int numAllAppsColumns;
805 private final int numDatabaseAllAppsColumns;
806 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700807 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100808
Thales Lima425f6822022-05-10 13:44:58 -0300809 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800810
Thales Lima11af7bc2022-08-12 15:24:54 +0100811 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
812
Thales Limab35faed2022-09-05 16:30:01 -0300813 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800814 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000815
Sunny Goyal415f1732018-11-29 10:33:47 -0800816 private final int defaultLayoutId;
817 private final int demoModeLayoutId;
818
Jon Mirandae126d722021-02-25 10:45:20 -0500819 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400820 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100821 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100822 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100823 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100824 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100825 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100826 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100827 private final int mHotseatSpecsId;
828 private final int mHotseatSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500829
Sunny Goyal076e04b2023-04-03 12:38:30 -0700830 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800831 TypedArray a = context.obtainStyledAttributes(
832 attrs, R.styleable.GridDisplayOption);
833 name = a.getString(R.styleable.GridDisplayOption_name);
834 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
835 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000836 numSearchContainerColumns = a.getInt(
837 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800838
Tracy Zhou7df93d22020-01-27 13:44:06 -0800839 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100840 defaultLayoutId = a.getResourceId(
841 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800842 demoModeLayoutId = a.getResourceId(
843 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844
Thales Limae9273ea2023-01-26 12:33:52 +0000845 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
846 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700847 numAllAppsColumns = a.getInt(
848 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
849 numDatabaseAllAppsColumns = a.getInt(
850 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
851
852 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800853 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700854 numDatabaseHotseatIcons = a.getInt(
855 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100856
Thales Lima425f6822022-05-10 13:44:58 -0300857 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
858 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
859 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
860 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
861 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
862 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
863 numColumns);
864 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
865 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
866 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700867
Vinit Nayakc7293172022-07-18 16:41:50 -0700868 inlineNavButtonsEndSpacing =
869 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100870 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300871
Sunny Goyal415f1732018-11-29 10:33:47 -0800872 numFolderRows = a.getInt(
873 R.styleable.GridDisplayOption_numFolderRows, numRows);
874 numFolderColumns = a.getInt(
875 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700876
Thales Limab35faed2022-09-05 16:30:01 -0300877 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
878 INVALID_RESOURCE_HANDLE);
879
Thales Limad852d652023-01-17 14:01:13 +0000880 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
881 R.style.CellStyleDefault);
882
Jon Mirandae126d722021-02-25 10:45:20 -0500883 isScalable = a.getBoolean(
884 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400885 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000886 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700887 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000888 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100889
Thales Limaec5abba2023-04-05 16:33:50 +0100890 if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
891 mWorkspaceSpecsId = a.getResourceId(
892 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100893 mWorkspaceSpecsTwoPanelId = a.getResourceId(
894 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
895 INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100896 mAllAppsSpecsId = a.getResourceId(
897 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100898 mAllAppsSpecsTwoPanelId = a.getResourceId(
899 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
900 INVALID_RESOURCE_HANDLE);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100901 mFolderSpecsId = a.getResourceId(
902 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100903 mFolderSpecsTwoPanelId = a.getResourceId(
904 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
905 INVALID_RESOURCE_HANDLE);
Thales Limaf8bfb032023-07-24 15:08:05 +0100906 mHotseatSpecsId = a.getResourceId(
907 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
908 mHotseatSpecsTwoPanelId = a.getResourceId(
909 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
910 INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100911 } else {
912 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100913 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100914 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100915 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100916 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100917 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100918 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
919 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100920 }
921
Thales Lima11af7bc2022-08-12 15:24:54 +0100922 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
923 DONT_INLINE_QSB);
924 inlineQsb[INDEX_DEFAULT] =
925 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
926 inlineQsb[INDEX_LANDSCAPE] =
927 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
928 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
929 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
930 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
931 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
932 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
933 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
934
Sunny Goyal415f1732018-11-29 10:33:47 -0800935 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700936 }
937
938 public boolean isEnabled(@DeviceType int deviceType) {
939 switch (deviceType) {
940 case TYPE_PHONE:
941 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
942 case TYPE_TABLET:
943 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
944 case TYPE_MULTI_DISPLAY:
945 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
946 == DEVICE_CATEGORY_MULTI_DISPLAY;
947 default:
948 return false;
949 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800950 }
951 }
952
Sunny Goyal19ff7282021-04-22 10:12:54 -0700953 @VisibleForTesting
954 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700955 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800956
Sunny Goyal415f1732018-11-29 10:33:47 -0800957 private final float minWidthDps;
958 private final float minHeightDps;
959 private final boolean canBeDefault;
960
Thales Lima83bedbf2021-10-05 17:47:39 +0100961 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100962
Thales Lima78d00ad2021-09-30 11:29:06 +0100963 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100964 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100965 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
966 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100967
Thales Lima78d00ad2021-09-30 11:29:06 +0100968 private final float[] iconSizes = new float[COUNT_SIZES];
969 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800970
Thales Limab7ef5692022-03-10 10:32:36 +0000971 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000972 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
973 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
974 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
975
Jon Miranda9c478b62023-03-23 21:38:49 -0700976 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
977
Jon Miranda04f05102023-04-04 12:16:31 -0700978 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
979
Thales Lima1de4d552021-10-13 16:13:25 +0100980 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800981 this.grid = grid;
982
Jon Miranda9c478b62023-03-23 21:38:49 -0700983 Resources res = context.getResources();
984
Thales Lima1de4d552021-10-13 16:13:25 +0100985 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800986
Sunny Goyal415f1732018-11-29 10:33:47 -0800987 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
988 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700989
Thales Lima1de4d552021-10-13 16:13:25 +0100990 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800991
Thales Lima83bedbf2021-10-05 17:47:39 +0100992 float x;
993 float y;
994
Thales Lima85c942f2021-12-31 13:04:20 +0000995 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
996 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100997 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000998
999 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1000 minCellSize[INDEX_DEFAULT].x);
1001 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1002 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001003 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001004
Thales Lima85c942f2021-12-31 13:04:20 +00001005 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001006 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001007 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001008 minCellSize[INDEX_DEFAULT].y);
1009 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1010
Thales Lima85c942f2021-12-31 13:04:20 +00001011 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001012 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001013 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001014 minCellSize[INDEX_DEFAULT].y);
1015 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001016
Thales Lima85c942f2021-12-31 13:04:20 +00001017 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001018 float borderSpaceLandscape = a.getFloat(
1019 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001020 float borderSpaceTwoPanelPortrait = a.getFloat(
1021 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1022 float borderSpaceTwoPanelLandscape = a.getFloat(
1023 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001024
Thales Lima85c942f2021-12-31 13:04:20 +00001025 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1026 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001027 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001028
1029 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1030 borderSpaceLandscape);
1031 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1032 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001033 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1034
1035 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001036 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1037 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001038 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001039 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1040 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001041 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1042
1043 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001044 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1045 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001046 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001047 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1048 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001049 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1050
Thales Limab7ef5692022-03-10 10:32:36 +00001051 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1052 minCellSize[INDEX_DEFAULT].x);
1053 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1054 minCellSize[INDEX_DEFAULT].y);
1055 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1056
1057 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1058 allAppsCellSize[INDEX_DEFAULT].x);
1059 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1060 allAppsCellSize[INDEX_DEFAULT].y);
1061 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1062
1063 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1064 allAppsCellSize[INDEX_DEFAULT].x);
1065 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1066 allAppsCellSize[INDEX_DEFAULT].y);
1067 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1068
1069 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1070 allAppsCellSize[INDEX_DEFAULT].x);
1071 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1072 allAppsCellSize[INDEX_DEFAULT].y);
1073 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1074
Thales Lima080d8902022-03-28 15:30:29 +01001075 float allAppsBorderSpace = a.getFloat(
1076 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1077 float allAppsBorderSpaceLandscape = a.getFloat(
1078 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1079 allAppsBorderSpace);
1080 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001081 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001082 allAppsBorderSpace);
1083 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001084 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001085 allAppsBorderSpace);
1086
1087 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1088 allAppsBorderSpace);
1089 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1090 allAppsBorderSpace);
1091 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1092
1093 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1094 allAppsBorderSpaceLandscape);
1095 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1096 allAppsBorderSpaceLandscape);
1097 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1098
1099 x = a.getFloat(
1100 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1101 allAppsBorderSpaceTwoPanelPortrait);
1102 y = a.getFloat(
1103 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1104 allAppsBorderSpaceTwoPanelPortrait);
1105 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1106
1107 x = a.getFloat(
1108 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1109 allAppsBorderSpaceTwoPanelLandscape);
1110 y = a.getFloat(
1111 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1112 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001113 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001114
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001115 iconSizes[INDEX_DEFAULT] =
1116 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1117 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001118 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001119 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001120 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001121 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001122 iconSizes[INDEX_DEFAULT]);
1123 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001124 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001125 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001126
Thales Limabb7d3882021-12-22 12:56:29 +00001127 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1128 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001129 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1130 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001131 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001132 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1133 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1134 allAppsIconSizes[INDEX_DEFAULT]);
1135 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1136 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1137 allAppsIconSizes[INDEX_DEFAULT]);
1138
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001139 textSizes[INDEX_DEFAULT] =
1140 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1141 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001142 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001143 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001144 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001145 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001146 textSizes[INDEX_DEFAULT]);
1147 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001148 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001149 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001150
Thales Limabb7d3882021-12-22 12:56:29 +00001151 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1152 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1153 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1154 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1155 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1156 allAppsIconTextSizes[INDEX_DEFAULT]);
1157 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1158 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1159 allAppsIconTextSizes[INDEX_DEFAULT]);
1160
Thales Lima83bedbf2021-10-05 17:47:39 +01001161 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1162 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001163 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1164 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1165 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001166 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001167 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001168 horizontalMargin[INDEX_DEFAULT]);
1169 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001170 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001171 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001172
Thales Limab8c05952022-05-23 16:58:38 +01001173 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1174 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001175 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001176 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1177 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1178 hotseatBarBottomSpace[INDEX_DEFAULT]);
1179 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1180 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1181 hotseatBarBottomSpace[INDEX_DEFAULT]);
1182 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1183 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1184 hotseatBarBottomSpace[INDEX_DEFAULT]);
1185
1186 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1187 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001188 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001189 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1190 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1191 hotseatQsbSpace[INDEX_DEFAULT]);
1192 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1193 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1194 hotseatQsbSpace[INDEX_DEFAULT]);
1195 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1196 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1197 hotseatQsbSpace[INDEX_DEFAULT]);
1198
Jon Miranda9c478b62023-03-23 21:38:49 -07001199 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1200 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1201 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1202 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1203 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1204 transientTaskbarIconSize[INDEX_DEFAULT]);
1205 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1206 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1207 transientTaskbarIconSize[INDEX_DEFAULT]);
1208 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1209 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001210 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001211
Jon Miranda04f05102023-04-04 12:16:31 -07001212 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1213 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1214 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1215 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1216 startAlignTaskbar[INDEX_DEFAULT]);
1217 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1218 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1219 startAlignTaskbar[INDEX_LANDSCAPE]);
1220 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1221 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1222 startAlignTaskbar[INDEX_DEFAULT]);
1223
Sunny Goyal415f1732018-11-29 10:33:47 -08001224 a.recycle();
1225 }
1226
1227 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001228 this(null);
1229 }
1230
1231 DisplayOption(GridOption grid) {
1232 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001233 minWidthDps = 0;
1234 minHeightDps = 0;
1235 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001236 for (int i = 0; i < COUNT_SIZES; i++) {
1237 iconSizes[i] = 0;
1238 textSizes[i] = 0;
1239 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001240 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001241 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001242 allAppsIconSizes[i] = 0;
1243 allAppsIconTextSizes[i] = 0;
1244 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001245 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001246 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001247 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001248 }
1249
1250 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001251 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001252 iconSizes[i] *= w;
1253 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001254 borderSpaces[i].x *= w;
1255 borderSpaces[i].y *= w;
1256 minCellSize[i].x *= w;
1257 minCellSize[i].y *= w;
1258 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001259 hotseatBarBottomSpace[i] *= w;
1260 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001261 allAppsCellSize[i].x *= w;
1262 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001263 allAppsIconSizes[i] *= w;
1264 allAppsIconTextSizes[i] *= w;
1265 allAppsBorderSpaces[i].x *= w;
1266 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001267 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001268 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001269
Sunny Goyal415f1732018-11-29 10:33:47 -08001270 return this;
1271 }
1272
1273 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001274 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001275 iconSizes[i] += p.iconSizes[i];
1276 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001277 borderSpaces[i].x += p.borderSpaces[i].x;
1278 borderSpaces[i].y += p.borderSpaces[i].y;
1279 minCellSize[i].x += p.minCellSize[i].x;
1280 minCellSize[i].y += p.minCellSize[i].y;
1281 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001282 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1283 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001284 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1285 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001286 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1287 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1288 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1289 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001290 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001291 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001292 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001293
Sunny Goyal415f1732018-11-29 10:33:47 -08001294 return this;
1295 }
1296 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001297}