blob: c044c52e3edeecad80a4aebb954c6e6a23b283ec [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
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070019import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE;
Stefan Andonian4c9612b2023-02-22 00:00:03 +000020import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070021import static com.android.launcher3.Utilities.dpiFromPx;
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;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070024import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000025import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070026import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070027import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080028import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070029
Sunny Goyalc6205602015-05-21 20:46:33 -070030import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070031import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080032import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070033import android.content.res.TypedArray;
34import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070035import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010036import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000037import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070038import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080039import android.text.TextUtils;
40import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070041import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010042import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080043import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070044import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080045import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070046
Thales Limab35faed2022-09-05 16:30:01 -030047import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000048import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030049import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070050import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000051import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010052import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070053
Thales Limaec5abba2023-04-05 16:33:50 +010054import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070055import com.android.launcher3.icons.DotRenderer;
Sunny Goyal68031ca2021-08-02 12:23:44 -070056import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010057import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070058import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070059import com.android.launcher3.util.DisplayController;
60import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070061import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080062import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070063import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070064import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070065import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080066import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070067
Sunny Goyal819e1932016-07-07 16:43:58 -070068import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70
71import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000072import java.lang.annotation.Retention;
73import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070074import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070075import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080076import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070077import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000078import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070079import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Sunny Goyal10fa0162024-04-21 00:13:35 -070081public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070084 // We do not need any synchronization for this variable as its only written on UI thread.
85 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070086 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070087
Alex Chau1c883d82021-12-01 18:43:10 +000088 @Retention(RetentionPolicy.SOURCE)
89 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070090 public @interface DeviceType {
91 }
Thales Limab8c05952022-05-23 16:58:38 +010092
Alex Chau1c883d82021-12-01 18:43:10 +000093 public static final int TYPE_PHONE = 0;
94 public static final int TYPE_MULTI_DISPLAY = 1;
95 public static final int TYPE_TABLET = 2;
96
Sunny Goyal53d7ee42015-05-22 12:25:45 -070097 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
98
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070099 // Constants that affects the interpolation curve between statically defined device profile
100 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800101 private static final float KNEARESTNEIGHBOR = 3;
102 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700103
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700104 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800105 private static final float WEIGHT_EFFICIENT = 100000f;
106
Thales Lima83bedbf2021-10-05 17:47:39 +0100107 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
108 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000109 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100110 static final int INDEX_DEFAULT = 0;
111 static final int INDEX_LANDSCAPE = 1;
112 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
113 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100114
Thales Limaec5abba2023-04-05 16:33:50 +0100115 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800116 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
117 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
118 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
119
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700120 /**
121 * Number of icons per row and column in the workspace.
122 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700123 public int numRows;
124 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000125 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700126
127 /**
128 * Number of icons per row and column in the folder.
129 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000130 public int[] numFolderRows;
131 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100132 public float[] iconSize;
133 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700134 public int iconBitmapSize;
135 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000136 public @DeviceType int deviceType;
Federico Baron56307d22024-11-06 18:48:48 +0000137 public Info displayInfo;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700138
Thales Lima83bedbf2021-10-05 17:47:39 +0100139 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100140
Thales Lima83bedbf2021-10-05 17:47:39 +0100141 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300142 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100143
Thales Limab35faed2022-09-05 16:30:01 -0300144 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100145
Thales Limad852d652023-01-17 14:01:13 +0000146 public @StyleRes int cellStyle;
147
Thales Lima83bedbf2021-10-05 17:47:39 +0100148 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500149
Thales Limab7ef5692022-03-10 10:32:36 +0000150 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000151 public float[] allAppsIconSize;
152 public float[] allAppsIconTextSize;
153 public PointF[] allAppsBorderSpaces;
154
Jon Miranda9c478b62023-03-23 21:38:49 -0700155 public float[] transientTaskbarIconSize;
156
Jon Miranda04f05102023-04-04 12:16:31 -0700157 public boolean[] startAlignTaskbar;
158
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700159 /**
160 * Number of icons inside the hotseat area.
161 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800162 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700163
164 /**
165 * Number of icons inside the hotseat area that is stored in the database. This is greater than
166 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
167 * sizes that share the same DB.
168 */
169 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700170
Thales Limab8c05952022-05-23 16:58:38 +0100171 public float[] hotseatBarBottomSpace;
172 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300173
Jon Miranda6f7e9702019-09-16 14:44:14 -0700174 /**
175 * Number of columns in the all apps list.
176 */
177 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300178 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700179 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000180 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700181
Jon Mirandae126d722021-02-25 10:45:20 -0500182 /**
183 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
184 */
185 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000186 @XmlRes
187 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100188 @XmlRes
189 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100190 @XmlRes
fbaronebc10c92024-09-03 12:51:41 -0700191 public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
192 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100193 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
194 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100195 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100196 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100197 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
198 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100199 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100200 @XmlRes
201 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000202 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100203 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000204 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100205 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000206 @XmlRes
207 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
208 @XmlRes
209 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
210 @XmlRes
211 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
212 @XmlRes
213 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500214
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700215
216 /**
217 * Fixed landscape mode is the landscape on the phones.
218 */
219 public boolean isFixedLandscapeMode = false;
220 private LauncherPrefChangeListener mLandscapeModePreferenceListener;
221
Tracy Zhou7df93d22020-01-27 13:44:06 -0800222 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800223 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700224 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100225 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700226
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000227 /**
228 * An immutable list of supported profiles.
229 */
230 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700231
Sunny Goyal6f866092016-03-17 17:04:15 -0700232 public Point defaultWallpaperSize;
233
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700234 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700235
Sunny Goyalf633ef52018-03-13 09:57:05 -0700236 @VisibleForTesting
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700237 public InvariantDeviceProfile() {
238 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700239
Sunny Goyalbbf01842015-10-08 07:41:15 -0700240 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700241 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700242 String gridName = getCurrentGridName(context);
243 String newGridName = initGrid(context, gridName);
244 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000245 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700246 }
247
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700248 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100249 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000250 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700251 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
252 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100253 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700254 }
255 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700256 if (Flags.oneGridSpecs()) {
257 mLandscapeModePreferenceListener = (String s) -> {
258 boolean newFixedLandscapeValue = FIXED_LANDSCAPE_MODE.get(context);
259 if (isFixedLandscapeMode != newFixedLandscapeValue) {
260 setFixedLandscape(context, newFixedLandscapeValue);
261 }
262 };
263 LauncherPrefs.INSTANCE.get(context).addListener(
264 mLandscapeModePreferenceListener,
265 FIXED_LANDSCAPE_MODE
266 );
267 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700268 }
269
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700270 /**
271 * This constructor should NOT have any monitors by design.
272 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800273 public InvariantDeviceProfile(Context context, String gridName) {
274 String newName = initGrid(context, gridName);
275 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000276 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800277 }
278 }
279
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800281 * This constructor should NOT have any monitors by design.
282 */
283 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700284 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100285 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700286 String gridName = getCurrentGridName(context);
287
288 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000289 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700290 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000292 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700293 getPredefinedDeviceProfiles(
294 context,
295 gridName,
296 defaultInfo,
297 /*allowDisabledGrid=*/false,
298 isFixedLandscapeMode
299 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000300 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700301
Alex Chau661f02d2022-06-07 14:03:43 +0100302 Context displayContext = context.createDisplayContext(display);
303 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700304 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700305 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000306 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700307 getPredefinedDeviceProfiles(
308 context,
309 gridName,
310 myInfo,
311 /*allowDisabledGrid=*/false,
312 isFixedLandscapeMode
313 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000314 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700315
316 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
317 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100318 result.iconSizes[INDEX_DEFAULT] =
319 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
320 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700321 result.iconSizes[i] = Math.min(
322 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000323 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700324
Thales Lima83bedbf2021-10-05 17:47:39 +0100325 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
326 COUNT_SIZES);
327 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
328 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500329
Federico Baron56307d22024-11-06 18:48:48 +0000330 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800331 }
332
Sunny Goyal10fa0162024-04-21 00:13:35 -0700333 @Override
334 public void close() {
335 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700336 if (mLandscapeModePreferenceListener != null) {
337 LauncherPrefs.INSTANCE.executeIfCreated(
338 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
339 );
340 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700341 }
342
Tracy Zhou42255d22020-03-13 00:38:11 -0700343 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000344 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700345 }
346
Sunny Goyaleff44f32019-01-09 17:29:49 -0800347 private String initGrid(Context context, String gridName) {
fbaronc1b68f42024-11-08 18:10:46 -0800348 if (!Flags.oneGridSpecs() && (isFixedLandscapeMode || FIXED_LANDSCAPE_MODE.get(context))) {
349 LauncherPrefs.get(context).put(FIXED_LANDSCAPE_MODE, false);
350 isFixedLandscapeMode = false;
351 }
352
Sunny Goyal35c7b192021-04-20 16:51:10 -0700353 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700354
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700355 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
356 context,
357 gridName,
358 displayInfo,
359 RestoreDbTask.isPending(context),
360 FIXED_LANDSCAPE_MODE.get(context)
361 );
fbaronebc10c92024-09-03 12:51:41 -0700362
363 // Filter out options that don't have the same number of columns as the grid
364 DeviceGridState deviceGridState = new DeviceGridState(context);
365 List<DisplayOption> allOptionsFilteredByColCount =
366 filterByColumnCount(allOptions, deviceGridState.getColumns());
367
Sunny Goyal19ff7282021-04-22 10:12:54 -0700368 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700369 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700370 ? new ArrayList<>(allOptions)
371 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000372 displayInfo.getDeviceType());
373 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700374 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800375 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700376
fbaronebc10c92024-09-03 12:51:41 -0700377 private List<DisplayOption> filterByColumnCount(
378 List<DisplayOption> allOptions, int numColumns) {
379 return allOptions.stream().filter(
380 option -> option.grid.numColumns == numColumns).toList();
381 }
382
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700383 /**
384 * @deprecated This is a temporary solution because on the backup and restore case we modify the
385 * IDP, this resets it. b/332974074
386 */
387 @Deprecated
388 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700389 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700390 }
391
Thales Limab67bfa72022-11-02 15:30:11 +0000392 @VisibleForTesting
393 public static String getDefaultGridName(Context context) {
394 return new InvariantDeviceProfile().initGrid(context, null);
395 }
396
Federico Baron56307d22024-11-06 18:48:48 +0000397 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700398 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700399 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000400 numRows = closestProfile.numRows;
401 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000402 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000403 dbFile = closestProfile.dbFile;
404 defaultLayoutId = closestProfile.defaultLayoutId;
405 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300406
Sunny Goyalae190ff2020-04-14 00:19:01 +0000407 numFolderRows = closestProfile.numFolderRows;
408 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300409 folderStyle = closestProfile.folderStyle;
410
Thales Limad852d652023-01-17 14:01:13 +0000411 cellStyle = closestProfile.cellStyle;
412
Jon Mirandae126d722021-02-25 10:45:20 -0500413 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400414 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100415 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbaronebc10c92024-09-03 12:51:41 -0700416 rowCountSpecsId = closestProfile.mRowCountSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100417 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100418 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100419 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100420 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100421 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100422 hotseatSpecsId = closestProfile.mHotseatSpecsId;
423 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000424 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
425 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
426 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
427 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300428 numAllAppsRowsForCellHeightCalculation =
429 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000430 this.deviceType = displayInfo.getDeviceType();
431 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000432
Vinit Nayakc7293172022-07-18 16:41:50 -0700433 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
434
Thales Lima83bedbf2021-10-05 17:47:39 +0100435 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100436 float maxIconSize = iconSize[0];
437 for (int i = 1; i < iconSize.length; i++) {
438 maxIconSize = Math.max(maxIconSize, iconSize[i]);
439 }
440 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000441 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
442
Thales Lima83bedbf2021-10-05 17:47:39 +0100443 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700444
Thales Lima83bedbf2021-10-05 17:47:39 +0100445 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100446
Thales Lima83bedbf2021-10-05 17:47:39 +0100447 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100448
Thales Limad90faab2021-09-21 17:18:47 +0100449 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100450
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000452 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700453 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100454 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
455 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700456
Thales Limae9273ea2023-01-26 12:33:52 +0000457 allAppsStyle = closestProfile.allAppsStyle;
458
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300460
Alex Chau1c883d82021-12-01 18:43:10 +0000461 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700462 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500463
Thales Limab7ef5692022-03-10 10:32:36 +0000464 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000465 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
466 allAppsIconSize = displayOption.allAppsIconSizes;
467 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000468
Thales Lima11af7bc2022-08-12 15:24:54 +0100469 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000470
Jon Miranda9c478b62023-03-23 21:38:49 -0700471 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
472
Jon Miranda04f05102023-04-04 12:16:31 -0700473 startAlignTaskbar = displayOption.startAlignTaskbar;
474
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700475 // Fixed Landscape mode
476 isFixedLandscapeMode = FIXED_LANDSCAPE_MODE.get(context) && Flags.oneGridSpecs();
477
Sunny Goyalae190ff2020-04-14 00:19:01 +0000478 // If the partner customization apk contains any grid overrides, apply them
479 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700480 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700481
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000482 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700483 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700484 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700485 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000486 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000487 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000488 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700489 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000490 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700491
Sunny Goyal19ff7282021-04-22 10:12:54 -0700492 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
493 int displayWidth = bounds.bounds.width();
494 int displayHeight = bounds.bounds.height();
495 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700496
Sunny Goyal19ff7282021-04-22 10:12:54 -0700497 // We need to ensure that there is enough extra space in the wallpaper
498 // for the intended parallax effects
499 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300500 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
501 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700502 ? 2
503 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
504 defaultWallpaperSize.x =
505 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700506 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000507 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700508
Thales Lima6a590062022-11-22 15:52:49 +0000509 int numMinShownHotseatIconsForTablet = supportedProfiles
510 .stream()
511 .filter(deviceProfile -> deviceProfile.isTablet)
512 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
513 .min()
514 .orElse(0);
515
516 supportedProfiles
517 .stream()
518 .filter(deviceProfile -> deviceProfile.isTablet)
519 .forEach(deviceProfile -> {
520 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
521 deviceProfile.recalculateHotseatWidthAndBorderSpace();
522 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700523 }
524
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700525 public void addOnChangeListener(OnIDPChangeListener listener) {
526 mChangeListeners.add(listener);
527 }
528
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800529 public void removeOnChangeListener(OnIDPChangeListener listener) {
530 mChangeListeners.remove(listener);
531 }
532
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700533 /**
534 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
535 * migration.
536 */
537 public void setCurrentGrid(Context context, String newGridName) {
538 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700539 MAIN_EXECUTOR.execute(() -> {
540 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
541 onConfigChanged(context.getApplicationContext());
542 Trace.endSection();
543 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800544 }
545
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700546 /**
fbaronc1b68f42024-11-08 18:10:46 -0800547 * Updates the fixed landscape mode, this triggers a new IDP, reloads the database and triggers
548 * a grid migration.
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700549 */
550 public void setFixedLandscape(Context context, boolean isFixedLandscape) {
551 this.isFixedLandscapeMode = isFixedLandscape;
552 if (isFixedLandscape) {
553 // When in isFixedLandscape there should only be one default grid to choose from
554 MAIN_EXECUTOR.execute(() -> {
555 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
556 onConfigChanged(context.getApplicationContext());
557 Trace.endSection();
558 });
559 } else {
560 setCurrentGrid(context, LauncherPrefs.get(context).get(GRID_NAME));
561 }
562 }
563
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700564 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700565 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000566 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
567 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700568 }
569
Pat Manning24cec692023-10-13 10:36:57 +0000570 /** Updates IDP using the provided context. Notifies listeners of change. */
571 @VisibleForTesting
572 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700573 Object[] oldState = toModelState();
574
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700575 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700576 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700577 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700578
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700579 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700580 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700581 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700582 }
583 }
584
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700585 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
586 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
587 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800588 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700589 }
590
591 private static List<DisplayOption> getPredefinedDeviceProfiles(
592 Context context,
593 String gridName,
594 Info displayInfo,
595 boolean allowDisabledGrid,
596 boolean isFixedLandscapeMode
597 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800598 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100599
Alex Chau1c883d82021-12-01 18:43:10 +0000600 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700601 final int depth = parser.getDepth();
602 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700603 while (((type = parser.next()) != XmlPullParser.END_TAG ||
604 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800605 if ((type == XmlPullParser.START_TAG)
606 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000607 GridOption gridOption = new GridOption(
608 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700609 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
610 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100611 final int displayDepth = parser.getDepth();
612 while (((type = parser.next()) != XmlPullParser.END_TAG
613 || parser.getDepth() > displayDepth)
614 && type != XmlPullParser.END_DOCUMENT) {
615 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
616 parser.getName())) {
617 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100618 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100619 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800620 }
621 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700622 }
623 }
sfufa@google.comde013292021-09-21 18:22:44 -0700624 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700625 throw new RuntimeException(e);
626 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000627 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800628 if (!TextUtils.isEmpty(gridName)) {
629 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000630 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
631 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000632 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800633 }
634 }
635 }
fbaronebc10c92024-09-03 12:51:41 -0700636 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
637 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000638 for (DisplayOption option : profiles) {
639 if (option.canBeDefault) {
640 filteredProfiles.add(option);
641 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800642 }
fbaronebc10c92024-09-03 12:51:41 -0700643 } else if (filteredProfiles.isEmpty()) {
644 // In this case we had a grid selected but we couldn't find it.
645 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800646 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000647 if (filteredProfiles.isEmpty()) {
648 throw new RuntimeException("No display option with canBeDefault=true");
649 }
650 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700651 }
652
Thales Lima7ec83822021-08-05 13:32:10 +0100653 /**
Sebastian Franco394a7e62024-11-14 18:47:45 -0800654 * Parses through the xml to find GridDimension specs. Then calls findBestRowCount to get the
655 * correct row count for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700656 *
fbaron49358342024-11-22 17:38:56 -0800657 * @return the result of {@link #findBestRowCount(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700658 */
fbaron49358342024-11-22 17:38:56 -0800659 private static GridDimension getRowCount(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000660 Info displayInfo) {
Sebastian Franco394a7e62024-11-14 18:47:45 -0800661 ArrayList<GridDimension> rowCounts = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700662
663 try (XmlResourceParser parser = resourceHelper.getXml()) {
664 final int depth = parser.getDepth();
665 int type;
666 while (((type = parser.next()) != XmlPullParser.END_TAG
667 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
668 if ((type == XmlPullParser.START_TAG)
Sebastian Franco394a7e62024-11-14 18:47:45 -0800669 && "GridDimension".equals(parser.getName())) {
670 rowCounts.add(new GridDimension(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700671 }
672 }
673 } catch (IOException | XmlPullParserException e) {
674 throw new RuntimeException(e);
675 }
676
fbaron49358342024-11-22 17:38:56 -0800677 // Finds the min width and height in dp for all displays.
678 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
679
680 return findBestRowCount(rowCounts, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700681 }
682
683 /**
Sebastian Franco394a7e62024-11-14 18:47:45 -0800684 * @return the biggest row count that fits the display dimensions spec using GridDimension to
fbaron49358342024-11-22 17:38:56 -0800685 * determine that. If no best row count is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700686 */
fbaron49358342024-11-22 17:38:56 -0800687 private static GridDimension findBestRowCount(List<GridDimension> list, int minWidthDp,
688 int minHeightDp) {
689 GridDimension selectedRow = null;
690 for (GridDimension item: list) {
691 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
692 if (selectedRow == null || selectedRow.mNumGridDimension < item.mNumGridDimension) {
693 selectedRow = item;
694 }
695 }
696 }
697 return selectedRow;
698 }
699
700 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700701 int minWidthPx = Integer.MAX_VALUE;
702 int minHeightPx = Integer.MAX_VALUE;
703 for (WindowBounds bounds : displayInfo.supportedBounds) {
704 boolean isTablet = displayInfo.isTablet(bounds);
Federico Baron56307d22024-11-06 18:48:48 +0000705 if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) {
fbaron49358342024-11-22 17:38:56 -0800706 // For split displays, take half width per page.
fbaronebc10c92024-09-03 12:51:41 -0700707 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
708 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
709 } else if (!isTablet && bounds.isLandscape()) {
fbaron49358342024-11-22 17:38:56 -0800710 // We will use transposed layout in this case.
fbaronebc10c92024-09-03 12:51:41 -0700711 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
712 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
713 } else {
714 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
715 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
716 }
717 }
718
fbaron49358342024-11-22 17:38:56 -0800719 int minWidthDp = (int) dpiFromPx(minWidthPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
720 int minHeightDp = (int) dpiFromPx(minHeightPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
721
722 return new int[]{minWidthDp, minHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700723 }
724
725 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000726 * Returns the GridOption associated to the given file name or null if the fileName is not
727 * supported.
728 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
729 */
730 public GridOption getGridOptionFromFileName(Context context, String fileName) {
731 return parseAllGridOptions(context).stream()
732 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
733 .findFirst()
734 .orElse(null);
735 }
736
737 /**
738 * Returns the name of the given size on the current device or empty string if the size is not
739 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
740 * (Note: the name of the grid can be different for the same grid size depending of
741 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000742 */
743 public String getGridNameFromSize(Context context, Point size) {
744 return parseAllGridOptions(context).stream()
745 .filter(gridOption -> gridOption.numColumns == size.x
746 && gridOption.numRows == size.y)
747 .map(gridOption -> gridOption.name)
748 .findFirst()
749 .orElse("");
750 }
751
752 /**
753 * Returns the grid option for the given gridName on the current device (Note: the gridOption
754 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
755 */
756 public GridOption getGridOptionFromName(Context context, String gridName) {
757 return parseAllGridOptions(context).stream()
758 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
759 .findFirst()
760 .orElse(null);
761 }
762
763 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100764 * @return all the grid options that can be shown on the device
765 */
766 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000767 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700768 .stream()
769 .filter(go -> go.isEnabled(deviceType))
fbaronc1b68f42024-11-08 18:10:46 -0800770 .filter(go -> go.filterByFlag(deviceType, isFixedLandscapeMode))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700771 .collect(Collectors.toList());
772 }
773
774 /**
775 * @return all the grid options that can be shown on the device
776 */
Federico Baron56307d22024-11-06 18:48:48 +0000777 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100778 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000779 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100780 final int depth = parser.getDepth();
781 int type;
782 while (((type = parser.next()) != XmlPullParser.END_TAG
783 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
784 if ((type == XmlPullParser.START_TAG)
785 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000786 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100787 }
788 }
789 } catch (IOException | XmlPullParserException e) {
790 Log.e(TAG, "Error parsing device profile", e);
791 return Collections.emptyList();
792 }
793 return result;
794 }
795
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700796 private int getLauncherIconDensity(int requiredSize) {
797 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700798 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700799 DisplayMetrics.DENSITY_LOW,
800 DisplayMetrics.DENSITY_MEDIUM,
801 DisplayMetrics.DENSITY_TV,
802 DisplayMetrics.DENSITY_HIGH,
803 DisplayMetrics.DENSITY_XHIGH,
804 DisplayMetrics.DENSITY_XXHIGH,
805 DisplayMetrics.DENSITY_XXXHIGH
806 };
807
808 int density = DisplayMetrics.DENSITY_XXXHIGH;
809 for (int i = densityBuckets.length - 1; i >= 0; i--) {
810 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
811 / DisplayMetrics.DENSITY_DEFAULT;
812 if (expectedSize >= requiredSize) {
813 density = densityBuckets[i];
814 }
815 }
816
817 return density;
818 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700819
Adam Cohen2e6da152015-05-06 11:42:25 -0700820 /**
821 * Apply any Partner customization grid overrides.
822 *
823 * Currently we support: all apps row / column count.
824 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700825 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
826 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800827 if (p == null) {
828 return;
829 }
830 try {
831 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
832 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
833 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
834
835 if (numRows > 0 && numColumns > 0) {
836 this.numRows = numRows;
837 this.numColumns = numColumns;
838 }
839 if (iconSizePx > 0) {
840 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
841 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
842 }
843 } catch (Resources.NotFoundException ex) {
844 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700845 }
846 }
847
Sunny Goyal415f1732018-11-29 10:33:47 -0800848 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700849 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700850 }
851
Sunny Goyal19ff7282021-04-22 10:12:54 -0700852 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700853 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700854 int minWidthPx = Integer.MAX_VALUE;
855 int minHeightPx = Integer.MAX_VALUE;
856 for (WindowBounds bounds : displayInfo.supportedBounds) {
857 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000858 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700859 // For split displays, take half width per page
860 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
861 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700862
Sunny Goyal19ff7282021-04-22 10:12:54 -0700863 } else if (!isTablet && bounds.isLandscape()) {
864 // We will use transposed layout in this case
865 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
866 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
867 } else {
868 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
869 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
870 }
871 }
872
Thales Lima425f6822022-05-10 13:44:58 -0300873 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
874 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700875
876 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700877 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700878 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
879 dist(width, height, b.minWidthDps, b.minHeightDps)));
880
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700881 DisplayOption closestPoint = points.get(0);
882 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700883 float weights = 0;
884
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700885 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
886 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700887 }
888
889 DisplayOption out = new DisplayOption(closestOption);
890 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700891 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700892 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
893 weights += w;
894 out.add(new DisplayOption().add(p).multiply(w));
895 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700896 out.multiply(1.0f / weights);
897
Thales Lima6e0005a2021-10-27 15:53:41 +0100898 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700899 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100900 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
901 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700902 }
903
904 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700905 }
906
Sunny Goyal27835952017-01-13 12:15:53 -0800907 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000908 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
909 Rect bounds = windowManagerProxy.getCurrentBounds(context);
910 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700911
Alex Chauc09a98a2023-11-14 12:51:42 +0000912 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400913 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700914
Sunny Goyal187b16c2022-03-01 16:53:23 -0800915 /**
916 * Returns the device profile matching the provided screen configuration
917 */
918 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700919 DeviceProfile bestMatch = supportedProfiles.get(0);
920 float minDiff = Float.MAX_VALUE;
921
922 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400923 float diff = Math.abs(profile.widthPx - screenWidth)
924 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700925 if (diff < minDiff) {
926 minDiff = diff;
927 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800928 } else if (diff == minDiff && profile.rotationHint == rotation) {
929 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700930 }
931 }
932 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800933 }
934
Sunny Goyal415f1732018-11-29 10:33:47 -0800935 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700936 float d = dist(x0, y0, x1, y1);
937 if (Float.compare(d, 0f) == 0) {
938 return Float.POSITIVE_INFINITY;
939 }
940 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
941 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700942
943 /**
944 * As a ratio of screen height, the total distance we want the parallax effect to span
945 * horizontally
946 */
947 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
948 float aspectRatio = width / (float) height;
949
950 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
951 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
952 // We will use these two data points to extrapolate how much the wallpaper parallax effect
953 // to span (ie travel) at any aspect ratio:
954
sfufa@google.comde013292021-09-21 18:22:44 -0700955 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
956 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700957 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
958 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
959
960 // To find out the desired width at different aspect ratios, we use the following two
961 // formulas, where the coefficient on x is the aspect ratio (width/height):
962 // (16/10)x + y = 1.5
963 // (10/16)x + y = 1.2
964 // We solve for x and y and end up with a final formula:
965 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700966 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
967 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700968 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
969 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
970 return x * aspectRatio + y;
971 }
972
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700973 public interface OnIDPChangeListener {
974
Sunny Goyalb47172b2021-05-03 19:59:51 -0700975 /**
976 * Called when the device provide changes
977 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700978 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700979 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800980
981
Sunny Goyaleff44f32019-01-09 17:29:49 -0800982 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800983
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800984 public static final String TAG_NAME = "grid-option";
985
Alex Chau1c883d82021-12-01 18:43:10 +0000986 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
987 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
988 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
989 private static final int DEVICE_CATEGORY_ALL =
990 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
991
Thales Lima11af7bc2022-08-12 15:24:54 +0100992 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
993 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
994 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
995 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
996 private static final int DONT_INLINE_QSB = 0;
997
Sunny Goyaleff44f32019-01-09 17:29:49 -0800998 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700999 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -08001000 public final int numRows;
1001 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +00001002 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -07001003 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -08001004
Thales Lima1faa4ed2023-12-01 16:48:19 +00001005 private final int[] numFolderRows = new int[COUNT_SIZES];
1006 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -03001007 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +00001008 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -08001009
Thales Limae9273ea2023-01-26 12:33:52 +00001010 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001011 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -03001012 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001013 private final int numDatabaseAllAppsColumns;
1014 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -07001015 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +01001016
Thales Lima11af7bc2022-08-12 15:24:54 +01001017 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
1018
Thales Limab35faed2022-09-05 16:30:01 -03001019 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001020 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001021
Sunny Goyal415f1732018-11-29 10:33:47 -08001022 private final int defaultLayoutId;
1023 private final int demoModeLayoutId;
1024
Jon Mirandae126d722021-02-25 10:45:20 -05001025 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001026 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001027 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001028 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001029 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001030 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001031 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001032 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001033 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001034 private final int mHotseatSpecsId;
1035 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001036 private final int mWorkspaceCellSpecsId;
1037 private final int mWorkspaceCellSpecsTwoPanelId;
1038 private final int mAllAppsCellSpecsId;
1039 private final int mAllAppsCellSpecsTwoPanelId;
fbaronebc10c92024-09-03 12:51:41 -07001040 private final int mRowCountSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001041 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001042 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001043
Federico Baron56307d22024-11-06 18:48:48 +00001044 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001045 TypedArray a = context.obtainStyledAttributes(
1046 attrs, R.styleable.GridDisplayOption);
1047 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001048 title = a.getString(R.styleable.GridDisplayOption_title);
1049 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1050 DEVICE_CATEGORY_ALL);
1051 mRowCountSpecsId = a.getResourceId(
1052 R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001053 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbaronebc10c92024-09-03 12:51:41 -07001054 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
1055 ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
Sebastian Franco394a7e62024-11-14 18:47:45 -08001056 GridDimension numR = getRowCount(resourceHelper, context, displayInfo);
1057 numRows = numR.mNumGridDimension;
fbaronebc10c92024-09-03 12:51:41 -07001058 dbFile = numR.mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001059 defaultLayoutId = numR.mDefaultLayoutId;
1060 demoModeLayoutId = numR.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001061 } else {
1062 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
1063 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001064 defaultLayoutId = a.getResourceId(
1065 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1066 demoModeLayoutId = a.getResourceId(
1067 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001068 }
1069
Sunny Goyal415f1732018-11-29 10:33:47 -08001070 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001071 numSearchContainerColumns = a.getInt(
1072 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001073
Thales Limae9273ea2023-01-26 12:33:52 +00001074 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1075 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001076 numAllAppsColumns = a.getInt(
1077 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1078 numDatabaseAllAppsColumns = a.getInt(
1079 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1080
1081 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001082 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001083 numDatabaseHotseatIcons = a.getInt(
1084 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001085
Vinit Nayakc7293172022-07-18 16:41:50 -07001086 inlineNavButtonsEndSpacing =
1087 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001088 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001089
Thales Lima1faa4ed2023-12-01 16:48:19 +00001090 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001091 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001092 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001093 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001094
Thales Lima1faa4ed2023-12-01 16:48:19 +00001095 if (FeatureFlags.enableResponsiveWorkspace()) {
1096 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1097 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1098 numFolderRows[INDEX_DEFAULT]);
1099 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1100 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1101 numFolderColumns[INDEX_DEFAULT]);
1102 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1103 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1104 numFolderRows[INDEX_DEFAULT]);
1105 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1106 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1107 numFolderColumns[INDEX_DEFAULT]);
1108 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1109 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1110 numFolderRows[INDEX_DEFAULT]);
1111 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1112 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1113 numFolderColumns[INDEX_DEFAULT]);
1114 } else {
1115 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1116 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1117 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1118 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1119 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1120 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1121 }
1122
Thales Limab35faed2022-09-05 16:30:01 -03001123 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1124 INVALID_RESOURCE_HANDLE);
1125
Thales Limad852d652023-01-17 14:01:13 +00001126 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1127 R.style.CellStyleDefault);
1128
Jon Mirandae126d722021-02-25 10:45:20 -05001129 isScalable = a.getBoolean(
1130 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001131 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001132 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001133
Thales Limaca31b612023-09-14 14:25:26 +01001134 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001135 mWorkspaceSpecsId = a.getResourceId(
1136 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001137 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1138 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001139 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001140 mAllAppsSpecsId = a.getResourceId(
1141 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001142 mAllAppsSpecsTwoPanelId = a.getResourceId(
1143 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001144 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001145 mFolderSpecsId = a.getResourceId(
1146 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001147 mFolderSpecsTwoPanelId = a.getResourceId(
1148 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001149 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001150 mHotseatSpecsId = a.getResourceId(
1151 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1152 mHotseatSpecsTwoPanelId = a.getResourceId(
1153 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001154 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001155 mWorkspaceCellSpecsId = a.getResourceId(
1156 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1157 INVALID_RESOURCE_HANDLE);
1158 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1159 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001160 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001161 mAllAppsCellSpecsId = a.getResourceId(
1162 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1163 INVALID_RESOURCE_HANDLE);
1164 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1165 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001166 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001167 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1168 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1169 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001170 } else {
1171 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001172 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001173 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001174 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001175 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001176 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001177 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1178 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001179 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1180 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1181 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1182 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001183 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001184 }
1185
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001186 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001187 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001188
Thales Lima11af7bc2022-08-12 15:24:54 +01001189 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1190 DONT_INLINE_QSB);
1191 inlineQsb[INDEX_DEFAULT] =
1192 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1193 inlineQsb[INDEX_LANDSCAPE] =
1194 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1195 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1196 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1197 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1198 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1199 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1200 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1201
Sunny Goyal415f1732018-11-29 10:33:47 -08001202 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001203 }
1204
1205 public boolean isEnabled(@DeviceType int deviceType) {
1206 switch (deviceType) {
1207 case TYPE_PHONE:
1208 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1209 case TYPE_TABLET:
1210 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1211 case TYPE_MULTI_DISPLAY:
1212 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1213 == DEVICE_CATEGORY_MULTI_DISPLAY;
1214 default:
1215 return false;
1216 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001217 }
fbaronebc10c92024-09-03 12:51:41 -07001218
fbaron6c91ef92024-11-12 22:22:43 -08001219 /**
1220 * Returns true if the grid option should be used given the flags that are toggled on/off.
1221 */
fbaronc1b68f42024-11-08 18:10:46 -08001222 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001223 if (deviceType == TYPE_TABLET) {
1224 return Flags.oneGridRotationHandling() == mIsDualGrid;
1225 }
fbaronc1b68f42024-11-08 18:10:46 -08001226
fbaron6c91ef92024-11-12 22:22:43 -08001227 // Here we return true if fixed landscape mode should be on.
1228 if (mIsFixedLandscape || isFixedLandscape) {
1229 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001230 }
1231
fbaron6c91ef92024-11-12 22:22:43 -08001232 // Here we return true if we want to show the new grids.
1233 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
1234 return Flags.oneGridSpecs();
1235 }
1236
1237 // Here we return true if we want to show the old grids.
1238 if (mIsOldGrid) {
1239 return !Flags.oneGridSpecs();
1240 }
1241
1242 return true;
fbaron49f7df02024-11-05 16:15:19 -08001243 }
fbaronebc10c92024-09-03 12:51:41 -07001244 }
1245
Sebastian Franco394a7e62024-11-14 18:47:45 -08001246 public static final class GridDimension {
1247 final int mNumGridDimension;
fbaron49358342024-11-22 17:38:56 -08001248 final int mMinDeviceWidthDp;
1249 final int mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001250 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001251 final int mDefaultLayoutId;
1252 final int mDemoModeLayoutId;
1253
fbaronebc10c92024-09-03 12:51:41 -07001254
Sebastian Franco394a7e62024-11-14 18:47:45 -08001255 GridDimension(Context context, AttributeSet attrs) {
1256 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridDimension);
fbaronebc10c92024-09-03 12:51:41 -07001257
Sebastian Franco394a7e62024-11-14 18:47:45 -08001258 mNumGridDimension = (int) a.getFloat(R.styleable.GridDimension_numGridDimension, 0);
fbaron49358342024-11-22 17:38:56 -08001259 mMinDeviceWidthDp = a.getInt(R.styleable.GridDimension_minDeviceWidthDp, 0);
1260 mMinDeviceHeightDp = a.getInt(R.styleable.GridDimension_minDeviceHeightDp, 0);
Sebastian Franco394a7e62024-11-14 18:47:45 -08001261 mDbFile = a.getString(R.styleable.GridDimension_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001262 mDefaultLayoutId = a.getResourceId(
Sebastian Franco394a7e62024-11-14 18:47:45 -08001263 R.styleable.GridDimension_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001264 mDemoModeLayoutId = a.getResourceId(
Sebastian Franco394a7e62024-11-14 18:47:45 -08001265 R.styleable.GridDimension_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001266
1267 a.recycle();
1268 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001269 }
1270
Sunny Goyal19ff7282021-04-22 10:12:54 -07001271 @VisibleForTesting
1272 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001273 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001274
Sunny Goyal415f1732018-11-29 10:33:47 -08001275 private final float minWidthDps;
1276 private final float minHeightDps;
1277 private final boolean canBeDefault;
1278
Thales Lima83bedbf2021-10-05 17:47:39 +01001279 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001280
Thales Lima78d00ad2021-09-30 11:29:06 +01001281 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001282 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001283 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1284 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001285
Thales Lima78d00ad2021-09-30 11:29:06 +01001286 private final float[] iconSizes = new float[COUNT_SIZES];
1287 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001288
Thales Limab7ef5692022-03-10 10:32:36 +00001289 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001290 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1291 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1292 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1293
Jon Miranda9c478b62023-03-23 21:38:49 -07001294 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1295
Jon Miranda04f05102023-04-04 12:16:31 -07001296 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1297
Thales Lima1de4d552021-10-13 16:13:25 +01001298 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001299 this.grid = grid;
1300
Jon Miranda9c478b62023-03-23 21:38:49 -07001301 Resources res = context.getResources();
1302
Thales Lima1de4d552021-10-13 16:13:25 +01001303 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001304
Sunny Goyal415f1732018-11-29 10:33:47 -08001305 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1306 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001307
Thales Lima1de4d552021-10-13 16:13:25 +01001308 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001309
Thales Lima83bedbf2021-10-05 17:47:39 +01001310 float x;
1311 float y;
1312
Thales Lima85c942f2021-12-31 13:04:20 +00001313 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1314 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001315 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001316
1317 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1318 minCellSize[INDEX_DEFAULT].x);
1319 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1320 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001321 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001322
Thales Lima85c942f2021-12-31 13:04:20 +00001323 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001324 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001325 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001326 minCellSize[INDEX_DEFAULT].y);
1327 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1328
Thales Lima85c942f2021-12-31 13:04:20 +00001329 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001330 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001331 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001332 minCellSize[INDEX_DEFAULT].y);
1333 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001334
Thales Lima85c942f2021-12-31 13:04:20 +00001335 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001336 float borderSpaceLandscape = a.getFloat(
1337 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001338 float borderSpaceTwoPanelPortrait = a.getFloat(
1339 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1340 float borderSpaceTwoPanelLandscape = a.getFloat(
1341 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001342
Thales Lima85c942f2021-12-31 13:04:20 +00001343 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1344 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001345 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001346
1347 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1348 borderSpaceLandscape);
1349 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1350 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001351 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1352
1353 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001354 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1355 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001356 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001357 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1358 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001359 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1360
1361 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001362 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1363 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001364 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001365 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1366 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001367 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1368
Thales Limab7ef5692022-03-10 10:32:36 +00001369 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1370 minCellSize[INDEX_DEFAULT].x);
1371 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1372 minCellSize[INDEX_DEFAULT].y);
1373 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1374
1375 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1376 allAppsCellSize[INDEX_DEFAULT].x);
1377 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1378 allAppsCellSize[INDEX_DEFAULT].y);
1379 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1380
1381 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1382 allAppsCellSize[INDEX_DEFAULT].x);
1383 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1384 allAppsCellSize[INDEX_DEFAULT].y);
1385 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1386
1387 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1388 allAppsCellSize[INDEX_DEFAULT].x);
1389 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1390 allAppsCellSize[INDEX_DEFAULT].y);
1391 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1392
Thales Lima080d8902022-03-28 15:30:29 +01001393 float allAppsBorderSpace = a.getFloat(
1394 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1395 float allAppsBorderSpaceLandscape = a.getFloat(
1396 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1397 allAppsBorderSpace);
1398 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001399 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001400 allAppsBorderSpace);
1401 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001402 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001403 allAppsBorderSpace);
1404
1405 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1406 allAppsBorderSpace);
1407 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1408 allAppsBorderSpace);
1409 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1410
1411 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1412 allAppsBorderSpaceLandscape);
1413 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1414 allAppsBorderSpaceLandscape);
1415 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1416
1417 x = a.getFloat(
1418 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1419 allAppsBorderSpaceTwoPanelPortrait);
1420 y = a.getFloat(
1421 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1422 allAppsBorderSpaceTwoPanelPortrait);
1423 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1424
1425 x = a.getFloat(
1426 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1427 allAppsBorderSpaceTwoPanelLandscape);
1428 y = a.getFloat(
1429 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1430 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001431 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001432
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001433 iconSizes[INDEX_DEFAULT] =
1434 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1435 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001436 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001437 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001438 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001439 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001440 iconSizes[INDEX_DEFAULT]);
1441 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001442 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001443 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001444
Thales Limabb7d3882021-12-22 12:56:29 +00001445 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1446 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001447 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1448 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001449 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001450 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1451 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1452 allAppsIconSizes[INDEX_DEFAULT]);
1453 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1454 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1455 allAppsIconSizes[INDEX_DEFAULT]);
1456
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001457 textSizes[INDEX_DEFAULT] =
1458 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1459 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001460 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001461 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001462 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001463 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001464 textSizes[INDEX_DEFAULT]);
1465 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001466 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001467 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001468
Thales Limabb7d3882021-12-22 12:56:29 +00001469 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1470 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1471 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1472 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1473 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1474 allAppsIconTextSizes[INDEX_DEFAULT]);
1475 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1476 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1477 allAppsIconTextSizes[INDEX_DEFAULT]);
1478
Thales Lima83bedbf2021-10-05 17:47:39 +01001479 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1480 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001481 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1482 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1483 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001484 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001485 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001486 horizontalMargin[INDEX_DEFAULT]);
1487 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001488 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001489 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001490
Thales Limab8c05952022-05-23 16:58:38 +01001491 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1492 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001493 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001494 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1495 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1496 hotseatBarBottomSpace[INDEX_DEFAULT]);
1497 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1498 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1499 hotseatBarBottomSpace[INDEX_DEFAULT]);
1500 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1501 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1502 hotseatBarBottomSpace[INDEX_DEFAULT]);
1503
1504 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1505 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001506 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001507 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1508 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1509 hotseatQsbSpace[INDEX_DEFAULT]);
1510 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1511 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1512 hotseatQsbSpace[INDEX_DEFAULT]);
1513 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1514 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1515 hotseatQsbSpace[INDEX_DEFAULT]);
1516
Jon Miranda9c478b62023-03-23 21:38:49 -07001517 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1518 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1519 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1520 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1521 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1522 transientTaskbarIconSize[INDEX_DEFAULT]);
1523 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1524 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1525 transientTaskbarIconSize[INDEX_DEFAULT]);
1526 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1527 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001528 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001529
Jon Miranda04f05102023-04-04 12:16:31 -07001530 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1531 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1532 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1533 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1534 startAlignTaskbar[INDEX_DEFAULT]);
1535 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1536 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1537 startAlignTaskbar[INDEX_LANDSCAPE]);
1538 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1539 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1540 startAlignTaskbar[INDEX_DEFAULT]);
1541
Sunny Goyal415f1732018-11-29 10:33:47 -08001542 a.recycle();
1543 }
1544
1545 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001546 this(null);
1547 }
1548
1549 DisplayOption(GridOption grid) {
1550 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001551 minWidthDps = 0;
1552 minHeightDps = 0;
1553 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001554 for (int i = 0; i < COUNT_SIZES; i++) {
1555 iconSizes[i] = 0;
1556 textSizes[i] = 0;
1557 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001558 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001559 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001560 allAppsIconSizes[i] = 0;
1561 allAppsIconTextSizes[i] = 0;
1562 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001563 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001564 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001565 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001566 }
1567
1568 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001569 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001570 iconSizes[i] *= w;
1571 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001572 borderSpaces[i].x *= w;
1573 borderSpaces[i].y *= w;
1574 minCellSize[i].x *= w;
1575 minCellSize[i].y *= w;
1576 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001577 hotseatBarBottomSpace[i] *= w;
1578 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001579 allAppsCellSize[i].x *= w;
1580 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001581 allAppsIconSizes[i] *= w;
1582 allAppsIconTextSizes[i] *= w;
1583 allAppsBorderSpaces[i].x *= w;
1584 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001585 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001586 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001587
Sunny Goyal415f1732018-11-29 10:33:47 -08001588 return this;
1589 }
1590
1591 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001592 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001593 iconSizes[i] += p.iconSizes[i];
1594 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001595 borderSpaces[i].x += p.borderSpaces[i].x;
1596 borderSpaces[i].y += p.borderSpaces[i].y;
1597 minCellSize[i].x += p.minCellSize[i].x;
1598 minCellSize[i].y += p.minCellSize[i].y;
1599 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001600 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1601 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001602 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1603 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001604 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1605 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1606 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1607 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001608 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001609 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001610 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001611
Sunny Goyal415f1732018-11-29 10:33:47 -08001612 return this;
1613 }
1614 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001615}