blob: 4d8cf20d29332e6c7c72dc2dd17b8fe3a11e2f4a [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
fbarond1cd8c22024-11-26 10:13:36 -0800191 public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;;
fbaronebc10c92024-09-03 12:51:41 -0700192 @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 */
fbarond1cd8c22024-11-26 10:13:36 -0800219 public boolean isFixedLandscape = false;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700220 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);
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800243 initGrid(context, gridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700244
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700245 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100246 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000247 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700248 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
249 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100250 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700251 }
252 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700253 if (Flags.oneGridSpecs()) {
254 mLandscapeModePreferenceListener = (String s) -> {
fbarond1cd8c22024-11-26 10:13:36 -0800255 if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
256 MAIN_EXECUTOR.execute(() -> {
257 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
258 onConfigChanged(context.getApplicationContext());
259 Trace.endSection();
260 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700261 }
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,
fbarond1cd8c22024-11-26 10:13:36 -0800298 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700299 ),
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,
fbarond1cd8c22024-11-26 10:13:36 -0800312 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700313 ),
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) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700348 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700349 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
350 context,
351 gridName,
352 displayInfo,
353 RestoreDbTask.isPending(context),
354 FIXED_LANDSCAPE_MODE.get(context)
355 );
fbaronebc10c92024-09-03 12:51:41 -0700356
357 // Filter out options that don't have the same number of columns as the grid
358 DeviceGridState deviceGridState = new DeviceGridState(context);
359 List<DisplayOption> allOptionsFilteredByColCount =
360 filterByColumnCount(allOptions, deviceGridState.getColumns());
361
Sunny Goyal19ff7282021-04-22 10:12:54 -0700362 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700363 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700364 ? new ArrayList<>(allOptions)
365 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000366 displayInfo.getDeviceType());
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800367
368 if (!displayOption.grid.name.equals(gridName)) {
369 LauncherPrefs.get(context).put(GRID_NAME, displayOption.grid.name);
370 }
371
Federico Baron56307d22024-11-06 18:48:48 +0000372 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700373 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800374 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700375
fbaronebc10c92024-09-03 12:51:41 -0700376 private List<DisplayOption> filterByColumnCount(
377 List<DisplayOption> allOptions, int numColumns) {
378 return allOptions.stream().filter(
379 option -> option.grid.numColumns == numColumns).toList();
380 }
381
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700382 /**
383 * @deprecated This is a temporary solution because on the backup and restore case we modify the
384 * IDP, this resets it. b/332974074
385 */
386 @Deprecated
387 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700388 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700389 }
390
Thales Limab67bfa72022-11-02 15:30:11 +0000391 @VisibleForTesting
392 public static String getDefaultGridName(Context context) {
393 return new InvariantDeviceProfile().initGrid(context, null);
394 }
395
Federico Baron56307d22024-11-06 18:48:48 +0000396 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700397 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700398 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000399 numRows = closestProfile.numRows;
400 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000401 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000402 dbFile = closestProfile.dbFile;
403 defaultLayoutId = closestProfile.defaultLayoutId;
404 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300405
Sunny Goyalae190ff2020-04-14 00:19:01 +0000406 numFolderRows = closestProfile.numFolderRows;
407 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300408 folderStyle = closestProfile.folderStyle;
409
Thales Limad852d652023-01-17 14:01:13 +0000410 cellStyle = closestProfile.cellStyle;
411
Jon Mirandae126d722021-02-25 10:45:20 -0500412 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400413 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100414 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800415 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100416 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100417 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100418 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100419 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100420 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100421 hotseatSpecsId = closestProfile.mHotseatSpecsId;
422 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000423 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
424 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
425 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
426 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300427 numAllAppsRowsForCellHeightCalculation =
428 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000429 this.deviceType = displayInfo.getDeviceType();
430 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000431
Vinit Nayakc7293172022-07-18 16:41:50 -0700432 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
433
Thales Lima83bedbf2021-10-05 17:47:39 +0100434 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100435 float maxIconSize = iconSize[0];
436 for (int i = 1; i < iconSize.length; i++) {
437 maxIconSize = Math.max(maxIconSize, iconSize[i]);
438 }
439 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000440 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
441
Thales Lima83bedbf2021-10-05 17:47:39 +0100442 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700443
Thales Lima83bedbf2021-10-05 17:47:39 +0100444 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100445
Thales Lima83bedbf2021-10-05 17:47:39 +0100446 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100447
Thales Limad90faab2021-09-21 17:18:47 +0100448 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100449
Sunny Goyal19ff7282021-04-22 10:12:54 -0700450 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000451 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700452 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100453 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
454 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700455
Thales Limae9273ea2023-01-26 12:33:52 +0000456 allAppsStyle = closestProfile.allAppsStyle;
457
Sunny Goyal19ff7282021-04-22 10:12:54 -0700458 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300459
Alex Chau1c883d82021-12-01 18:43:10 +0000460 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700461 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500462
Thales Limab7ef5692022-03-10 10:32:36 +0000463 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000464 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
465 allAppsIconSize = displayOption.allAppsIconSizes;
466 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000467
Thales Lima11af7bc2022-08-12 15:24:54 +0100468 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000469
Jon Miranda9c478b62023-03-23 21:38:49 -0700470 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
471
Jon Miranda04f05102023-04-04 12:16:31 -0700472 startAlignTaskbar = displayOption.startAlignTaskbar;
473
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700474 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800475 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700476
Sunny Goyalae190ff2020-04-14 00:19:01 +0000477 // If the partner customization apk contains any grid overrides, apply them
478 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700479 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700480
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000481 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700482 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700483 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700484 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000485 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000486 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000487 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700488 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000489 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700490
Sunny Goyal19ff7282021-04-22 10:12:54 -0700491 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
492 int displayWidth = bounds.bounds.width();
493 int displayHeight = bounds.bounds.height();
494 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700495
Sunny Goyal19ff7282021-04-22 10:12:54 -0700496 // We need to ensure that there is enough extra space in the wallpaper
497 // for the intended parallax effects
498 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300499 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
500 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700501 ? 2
502 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
503 defaultWallpaperSize.x =
504 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700505 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000506 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700507
Thales Lima6a590062022-11-22 15:52:49 +0000508 int numMinShownHotseatIconsForTablet = supportedProfiles
509 .stream()
510 .filter(deviceProfile -> deviceProfile.isTablet)
511 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
512 .min()
513 .orElse(0);
514
515 supportedProfiles
516 .stream()
517 .filter(deviceProfile -> deviceProfile.isTablet)
518 .forEach(deviceProfile -> {
519 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
520 deviceProfile.recalculateHotseatWidthAndBorderSpace();
521 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700522 }
523
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700524 public void addOnChangeListener(OnIDPChangeListener listener) {
525 mChangeListeners.add(listener);
526 }
527
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800528 public void removeOnChangeListener(OnIDPChangeListener listener) {
529 mChangeListeners.remove(listener);
530 }
531
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700532 /**
533 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
534 * migration.
535 */
536 public void setCurrentGrid(Context context, String newGridName) {
537 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700538 MAIN_EXECUTOR.execute(() -> {
539 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
540 onConfigChanged(context.getApplicationContext());
541 Trace.endSection();
542 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800543 }
544
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700545 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700546 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000547 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
548 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700549 }
550
Pat Manning24cec692023-10-13 10:36:57 +0000551 /** Updates IDP using the provided context. Notifies listeners of change. */
552 @VisibleForTesting
553 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700554 Object[] oldState = toModelState();
555
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700556 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700557 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700558 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700559
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700560 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700561 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700562 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700563 }
564 }
565
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700566 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
567 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
568 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800569 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700570 }
571
572 private static List<DisplayOption> getPredefinedDeviceProfiles(
573 Context context,
574 String gridName,
575 Info displayInfo,
576 boolean allowDisabledGrid,
577 boolean isFixedLandscapeMode
578 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800579 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100580
Alex Chau1c883d82021-12-01 18:43:10 +0000581 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700582 final int depth = parser.getDepth();
583 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700584 while (((type = parser.next()) != XmlPullParser.END_TAG ||
585 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800586 if ((type == XmlPullParser.START_TAG)
587 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000588 GridOption gridOption = new GridOption(
589 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700590 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
591 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100592 final int displayDepth = parser.getDepth();
593 while (((type = parser.next()) != XmlPullParser.END_TAG
594 || parser.getDepth() > displayDepth)
595 && type != XmlPullParser.END_DOCUMENT) {
596 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
597 parser.getName())) {
598 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100599 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100600 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800601 }
602 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700603 }
604 }
sfufa@google.comde013292021-09-21 18:22:44 -0700605 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700606 throw new RuntimeException(e);
607 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000608 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800609 if (!TextUtils.isEmpty(gridName)) {
610 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000611 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
612 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000613 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800614 }
615 }
616 }
fbaronebc10c92024-09-03 12:51:41 -0700617 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
618 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000619 for (DisplayOption option : profiles) {
620 if (option.canBeDefault) {
621 filteredProfiles.add(option);
622 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800623 }
fbaronebc10c92024-09-03 12:51:41 -0700624 } else if (filteredProfiles.isEmpty()) {
625 // In this case we had a grid selected but we couldn't find it.
626 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800627 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000628 if (filteredProfiles.isEmpty()) {
629 throw new RuntimeException("No display option with canBeDefault=true");
630 }
631 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700632 }
633
Thales Lima7ec83822021-08-05 13:32:10 +0100634 /**
fbarond1cd8c22024-11-26 10:13:36 -0800635 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
636 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700637 *
fbarond1cd8c22024-11-26 10:13:36 -0800638 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700639 */
fbarond1cd8c22024-11-26 10:13:36 -0800640 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000641 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800642 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700643
644 try (XmlResourceParser parser = resourceHelper.getXml()) {
645 final int depth = parser.getDepth();
646 int type;
647 while (((type = parser.next()) != XmlPullParser.END_TAG
648 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
649 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800650 && "GridSize".equals(parser.getName())) {
651 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700652 }
653 }
654 } catch (IOException | XmlPullParserException e) {
655 throw new RuntimeException(e);
656 }
657
fbaron49358342024-11-22 17:38:56 -0800658 // Finds the min width and height in dp for all displays.
659 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
660
fbarond1cd8c22024-11-26 10:13:36 -0800661 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700662 }
663
664 /**
fbarond1cd8c22024-11-26 10:13:36 -0800665 * @return the biggest grid size that fits the display dimensions.
666 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700667 */
fbarond1cd8c22024-11-26 10:13:36 -0800668 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800669 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800670 GridSize selectedGridSize = null;
671 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800672 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800673 if (selectedGridSize == null
674 || (selectedGridSize.mNumColumns <= item.mNumColumns
675 && selectedGridSize.mNumRows <= item.mNumRows)) {
676 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800677 }
678 }
679 }
fbarond1cd8c22024-11-26 10:13:36 -0800680 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800681 }
682
683 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700684 int minWidthPx = Integer.MAX_VALUE;
685 int minHeightPx = Integer.MAX_VALUE;
686 for (WindowBounds bounds : displayInfo.supportedBounds) {
687 boolean isTablet = displayInfo.isTablet(bounds);
Federico Baron56307d22024-11-06 18:48:48 +0000688 if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) {
fbaron49358342024-11-22 17:38:56 -0800689 // For split displays, take half width per page.
fbaronebc10c92024-09-03 12:51:41 -0700690 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
691 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
692 } else if (!isTablet && bounds.isLandscape()) {
fbaron49358342024-11-22 17:38:56 -0800693 // We will use transposed layout in this case.
fbaronebc10c92024-09-03 12:51:41 -0700694 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
695 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
696 } else {
697 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
698 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
699 }
700 }
701
fbaron49358342024-11-22 17:38:56 -0800702 int minWidthDp = (int) dpiFromPx(minWidthPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
703 int minHeightDp = (int) dpiFromPx(minHeightPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
704
705 return new int[]{minWidthDp, minHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700706 }
707
708 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000709 * Returns the GridOption associated to the given file name or null if the fileName is not
710 * supported.
711 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
712 */
713 public GridOption getGridOptionFromFileName(Context context, String fileName) {
714 return parseAllGridOptions(context).stream()
715 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
716 .findFirst()
717 .orElse(null);
718 }
719
720 /**
721 * Returns the name of the given size on the current device or empty string if the size is not
722 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
723 * (Note: the name of the grid can be different for the same grid size depending of
724 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000725 */
726 public String getGridNameFromSize(Context context, Point size) {
727 return parseAllGridOptions(context).stream()
728 .filter(gridOption -> gridOption.numColumns == size.x
729 && gridOption.numRows == size.y)
730 .map(gridOption -> gridOption.name)
731 .findFirst()
732 .orElse("");
733 }
734
735 /**
736 * Returns the grid option for the given gridName on the current device (Note: the gridOption
737 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
738 */
739 public GridOption getGridOptionFromName(Context context, String gridName) {
740 return parseAllGridOptions(context).stream()
741 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
742 .findFirst()
743 .orElse(null);
744 }
745
746 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100747 * @return all the grid options that can be shown on the device
748 */
749 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000750 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700751 .stream()
752 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800753 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700754 .collect(Collectors.toList());
755 }
756
757 /**
758 * @return all the grid options that can be shown on the device
759 */
Federico Baron56307d22024-11-06 18:48:48 +0000760 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100761 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000762 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100763 final int depth = parser.getDepth();
764 int type;
765 while (((type = parser.next()) != XmlPullParser.END_TAG
766 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
767 if ((type == XmlPullParser.START_TAG)
768 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000769 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100770 }
771 }
772 } catch (IOException | XmlPullParserException e) {
773 Log.e(TAG, "Error parsing device profile", e);
774 return Collections.emptyList();
775 }
776 return result;
777 }
778
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700779 private int getLauncherIconDensity(int requiredSize) {
780 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700781 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700782 DisplayMetrics.DENSITY_LOW,
783 DisplayMetrics.DENSITY_MEDIUM,
784 DisplayMetrics.DENSITY_TV,
785 DisplayMetrics.DENSITY_HIGH,
786 DisplayMetrics.DENSITY_XHIGH,
787 DisplayMetrics.DENSITY_XXHIGH,
788 DisplayMetrics.DENSITY_XXXHIGH
789 };
790
791 int density = DisplayMetrics.DENSITY_XXXHIGH;
792 for (int i = densityBuckets.length - 1; i >= 0; i--) {
793 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
794 / DisplayMetrics.DENSITY_DEFAULT;
795 if (expectedSize >= requiredSize) {
796 density = densityBuckets[i];
797 }
798 }
799
800 return density;
801 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700802
Adam Cohen2e6da152015-05-06 11:42:25 -0700803 /**
804 * Apply any Partner customization grid overrides.
805 *
806 * Currently we support: all apps row / column count.
807 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700808 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
809 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800810 if (p == null) {
811 return;
812 }
813 try {
814 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
815 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
816 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
817
818 if (numRows > 0 && numColumns > 0) {
819 this.numRows = numRows;
820 this.numColumns = numColumns;
821 }
822 if (iconSizePx > 0) {
823 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
824 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
825 }
826 } catch (Resources.NotFoundException ex) {
827 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700828 }
829 }
830
Sunny Goyal415f1732018-11-29 10:33:47 -0800831 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700832 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700833 }
834
Sunny Goyal19ff7282021-04-22 10:12:54 -0700835 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700836 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700837 int minWidthPx = Integer.MAX_VALUE;
838 int minHeightPx = Integer.MAX_VALUE;
839 for (WindowBounds bounds : displayInfo.supportedBounds) {
840 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000841 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700842 // For split displays, take half width per page
843 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
844 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700845
Sunny Goyal19ff7282021-04-22 10:12:54 -0700846 } else if (!isTablet && bounds.isLandscape()) {
847 // We will use transposed layout in this case
848 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
849 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
850 } else {
851 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
852 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
853 }
854 }
855
Thales Lima425f6822022-05-10 13:44:58 -0300856 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
857 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700858
859 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700860 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700861 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
862 dist(width, height, b.minWidthDps, b.minHeightDps)));
863
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700864 DisplayOption closestPoint = points.get(0);
865 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700866 float weights = 0;
867
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700868 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
869 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700870 }
871
872 DisplayOption out = new DisplayOption(closestOption);
873 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700874 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700875 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
876 weights += w;
877 out.add(new DisplayOption().add(p).multiply(w));
878 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700879 out.multiply(1.0f / weights);
880
Thales Lima6e0005a2021-10-27 15:53:41 +0100881 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700882 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100883 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
884 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700885 }
886
887 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700888 }
889
Sunny Goyal27835952017-01-13 12:15:53 -0800890 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000891 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
892 Rect bounds = windowManagerProxy.getCurrentBounds(context);
893 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700894
Alex Chauc09a98a2023-11-14 12:51:42 +0000895 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400896 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700897
Sunny Goyal187b16c2022-03-01 16:53:23 -0800898 /**
899 * Returns the device profile matching the provided screen configuration
900 */
901 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700902 DeviceProfile bestMatch = supportedProfiles.get(0);
903 float minDiff = Float.MAX_VALUE;
904
905 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400906 float diff = Math.abs(profile.widthPx - screenWidth)
907 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700908 if (diff < minDiff) {
909 minDiff = diff;
910 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800911 } else if (diff == minDiff && profile.rotationHint == rotation) {
912 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700913 }
914 }
915 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800916 }
917
Sunny Goyal415f1732018-11-29 10:33:47 -0800918 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700919 float d = dist(x0, y0, x1, y1);
920 if (Float.compare(d, 0f) == 0) {
921 return Float.POSITIVE_INFINITY;
922 }
923 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
924 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700925
926 /**
927 * As a ratio of screen height, the total distance we want the parallax effect to span
928 * horizontally
929 */
930 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
931 float aspectRatio = width / (float) height;
932
933 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
934 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
935 // We will use these two data points to extrapolate how much the wallpaper parallax effect
936 // to span (ie travel) at any aspect ratio:
937
sfufa@google.comde013292021-09-21 18:22:44 -0700938 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
939 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700940 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
941 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
942
943 // To find out the desired width at different aspect ratios, we use the following two
944 // formulas, where the coefficient on x is the aspect ratio (width/height):
945 // (16/10)x + y = 1.5
946 // (10/16)x + y = 1.2
947 // We solve for x and y and end up with a final formula:
948 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700949 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
950 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700951 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
952 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
953 return x * aspectRatio + y;
954 }
955
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700956 public interface OnIDPChangeListener {
957
Sunny Goyalb47172b2021-05-03 19:59:51 -0700958 /**
959 * Called when the device provide changes
960 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700961 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700962 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800963
964
Sunny Goyaleff44f32019-01-09 17:29:49 -0800965 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800966
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800967 public static final String TAG_NAME = "grid-option";
968
Alex Chau1c883d82021-12-01 18:43:10 +0000969 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
970 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
971 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
972 private static final int DEVICE_CATEGORY_ALL =
973 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
974
Thales Lima11af7bc2022-08-12 15:24:54 +0100975 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
976 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
977 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
978 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
979 private static final int DONT_INLINE_QSB = 0;
980
Sunny Goyaleff44f32019-01-09 17:29:49 -0800981 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700982 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800983 public final int numRows;
984 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000985 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700986 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800987
Thales Lima1faa4ed2023-12-01 16:48:19 +0000988 private final int[] numFolderRows = new int[COUNT_SIZES];
989 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300990 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000991 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800992
Thales Limae9273ea2023-01-26 12:33:52 +0000993 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700994 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300995 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700996 private final int numDatabaseAllAppsColumns;
997 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700998 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100999
Thales Lima11af7bc2022-08-12 15:24:54 +01001000 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
1001
Thales Limab35faed2022-09-05 16:30:01 -03001002 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001003 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001004
Sunny Goyal415f1732018-11-29 10:33:47 -08001005 private final int defaultLayoutId;
1006 private final int demoModeLayoutId;
1007
Jon Mirandae126d722021-02-25 10:45:20 -05001008 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001009 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001010 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001011 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001012 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001013 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001014 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001015 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001016 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001017 private final int mHotseatSpecsId;
1018 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001019 private final int mWorkspaceCellSpecsId;
1020 private final int mWorkspaceCellSpecsTwoPanelId;
1021 private final int mAllAppsCellSpecsId;
1022 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001023 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001024 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001025 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001026
Federico Baron56307d22024-11-06 18:48:48 +00001027 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001028 TypedArray a = context.obtainStyledAttributes(
1029 attrs, R.styleable.GridDisplayOption);
1030 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001031 title = a.getString(R.styleable.GridDisplayOption_title);
1032 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1033 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001034 mGridSizeSpecsId = a.getResourceId(
1035 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001036 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001037 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1038 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1039 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1040 numColumns = gridSize.mNumColumns;
1041 numRows = gridSize.mNumRows;
1042 dbFile = gridSize.mDbFile;
1043 defaultLayoutId = gridSize.mDefaultLayoutId;
1044 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001045 } else {
1046 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001047 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001048 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001049 defaultLayoutId = a.getResourceId(
1050 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1051 demoModeLayoutId = a.getResourceId(
1052 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001053 }
1054
Alex Chau9fee3fd2021-12-01 18:43:10 +00001055 numSearchContainerColumns = a.getInt(
1056 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001057
Thales Limae9273ea2023-01-26 12:33:52 +00001058 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1059 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001060 numAllAppsColumns = a.getInt(
1061 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1062 numDatabaseAllAppsColumns = a.getInt(
1063 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1064
1065 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001066 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001067 numDatabaseHotseatIcons = a.getInt(
1068 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001069
Vinit Nayakc7293172022-07-18 16:41:50 -07001070 inlineNavButtonsEndSpacing =
1071 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001072 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001073
Thales Lima1faa4ed2023-12-01 16:48:19 +00001074 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001075 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001076 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001077 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001078
Thales Lima1faa4ed2023-12-01 16:48:19 +00001079 if (FeatureFlags.enableResponsiveWorkspace()) {
1080 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1081 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1082 numFolderRows[INDEX_DEFAULT]);
1083 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1084 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1085 numFolderColumns[INDEX_DEFAULT]);
1086 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1087 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1088 numFolderRows[INDEX_DEFAULT]);
1089 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1090 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1091 numFolderColumns[INDEX_DEFAULT]);
1092 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1093 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1094 numFolderRows[INDEX_DEFAULT]);
1095 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1096 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1097 numFolderColumns[INDEX_DEFAULT]);
1098 } else {
1099 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1100 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1101 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1102 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1103 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1104 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1105 }
1106
Thales Limab35faed2022-09-05 16:30:01 -03001107 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1108 INVALID_RESOURCE_HANDLE);
1109
Thales Limad852d652023-01-17 14:01:13 +00001110 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1111 R.style.CellStyleDefault);
1112
Jon Mirandae126d722021-02-25 10:45:20 -05001113 isScalable = a.getBoolean(
1114 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001115 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001116 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001117
Thales Limaca31b612023-09-14 14:25:26 +01001118 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001119 mWorkspaceSpecsId = a.getResourceId(
1120 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001121 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1122 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001123 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001124 mAllAppsSpecsId = a.getResourceId(
1125 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001126 mAllAppsSpecsTwoPanelId = a.getResourceId(
1127 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001128 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001129 mFolderSpecsId = a.getResourceId(
1130 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001131 mFolderSpecsTwoPanelId = a.getResourceId(
1132 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001133 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001134 mHotseatSpecsId = a.getResourceId(
1135 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1136 mHotseatSpecsTwoPanelId = a.getResourceId(
1137 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001138 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001139 mWorkspaceCellSpecsId = a.getResourceId(
1140 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1141 INVALID_RESOURCE_HANDLE);
1142 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1143 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001144 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001145 mAllAppsCellSpecsId = a.getResourceId(
1146 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1147 INVALID_RESOURCE_HANDLE);
1148 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1149 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001150 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001151 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1152 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1153 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001154 } else {
1155 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001156 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001157 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001158 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001159 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001160 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001161 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1162 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001163 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1164 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1165 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1166 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001167 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001168 }
1169
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001170 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001171 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001172
Thales Lima11af7bc2022-08-12 15:24:54 +01001173 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1174 DONT_INLINE_QSB);
1175 inlineQsb[INDEX_DEFAULT] =
1176 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1177 inlineQsb[INDEX_LANDSCAPE] =
1178 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1179 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1180 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1181 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1182 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1183 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1184 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1185
Sunny Goyal415f1732018-11-29 10:33:47 -08001186 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001187 }
1188
1189 public boolean isEnabled(@DeviceType int deviceType) {
1190 switch (deviceType) {
1191 case TYPE_PHONE:
1192 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1193 case TYPE_TABLET:
1194 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1195 case TYPE_MULTI_DISPLAY:
1196 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1197 == DEVICE_CATEGORY_MULTI_DISPLAY;
1198 default:
1199 return false;
1200 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001201 }
fbaronebc10c92024-09-03 12:51:41 -07001202
fbaron6c91ef92024-11-12 22:22:43 -08001203 /**
1204 * Returns true if the grid option should be used given the flags that are toggled on/off.
1205 */
fbaronc1b68f42024-11-08 18:10:46 -08001206 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001207 if (deviceType == TYPE_TABLET) {
1208 return Flags.oneGridRotationHandling() == mIsDualGrid;
1209 }
fbaronc1b68f42024-11-08 18:10:46 -08001210
fbaron6c91ef92024-11-12 22:22:43 -08001211 // Here we return true if fixed landscape mode should be on.
1212 if (mIsFixedLandscape || isFixedLandscape) {
1213 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001214 }
1215
fbaron6c91ef92024-11-12 22:22:43 -08001216 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001217 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001218 return Flags.oneGridSpecs();
1219 }
1220
1221 // Here we return true if we want to show the old grids.
1222 if (mIsOldGrid) {
1223 return !Flags.oneGridSpecs();
1224 }
1225
1226 return true;
fbaron49f7df02024-11-05 16:15:19 -08001227 }
fbaronebc10c92024-09-03 12:51:41 -07001228 }
1229
fbarond1cd8c22024-11-26 10:13:36 -08001230 public static final class GridSize {
1231 final int mNumRows;
1232 final int mNumColumns;
1233 final float mMinDeviceWidthDp;
1234 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001235 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001236 final int mDefaultLayoutId;
1237 final int mDemoModeLayoutId;
1238
fbaronebc10c92024-09-03 12:51:41 -07001239
fbarond1cd8c22024-11-26 10:13:36 -08001240 GridSize(Context context, AttributeSet attrs) {
1241 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001242
fbarond1cd8c22024-11-26 10:13:36 -08001243 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1244 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1245 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1246 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1247 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001248 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001249 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001250 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001251 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001252
1253 a.recycle();
1254 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001255 }
1256
Sunny Goyal19ff7282021-04-22 10:12:54 -07001257 @VisibleForTesting
1258 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001259 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001260
Sunny Goyal415f1732018-11-29 10:33:47 -08001261 private final float minWidthDps;
1262 private final float minHeightDps;
1263 private final boolean canBeDefault;
1264
Thales Lima83bedbf2021-10-05 17:47:39 +01001265 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001266
Thales Lima78d00ad2021-09-30 11:29:06 +01001267 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001268 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001269 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1270 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001271
Thales Lima78d00ad2021-09-30 11:29:06 +01001272 private final float[] iconSizes = new float[COUNT_SIZES];
1273 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001274
Thales Limab7ef5692022-03-10 10:32:36 +00001275 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001276 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1277 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1278 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1279
Jon Miranda9c478b62023-03-23 21:38:49 -07001280 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1281
Jon Miranda04f05102023-04-04 12:16:31 -07001282 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1283
Thales Lima1de4d552021-10-13 16:13:25 +01001284 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001285 this.grid = grid;
1286
Jon Miranda9c478b62023-03-23 21:38:49 -07001287 Resources res = context.getResources();
1288
Thales Lima1de4d552021-10-13 16:13:25 +01001289 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001290
Sunny Goyal415f1732018-11-29 10:33:47 -08001291 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1292 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001293
Thales Lima1de4d552021-10-13 16:13:25 +01001294 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001295
Thales Lima83bedbf2021-10-05 17:47:39 +01001296 float x;
1297 float y;
1298
Thales Lima85c942f2021-12-31 13:04:20 +00001299 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1300 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001301 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001302
1303 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1304 minCellSize[INDEX_DEFAULT].x);
1305 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1306 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001307 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001308
Thales Lima85c942f2021-12-31 13:04:20 +00001309 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001310 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001311 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001312 minCellSize[INDEX_DEFAULT].y);
1313 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1314
Thales Lima85c942f2021-12-31 13:04:20 +00001315 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001316 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001317 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001318 minCellSize[INDEX_DEFAULT].y);
1319 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001320
Thales Lima85c942f2021-12-31 13:04:20 +00001321 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001322 float borderSpaceLandscape = a.getFloat(
1323 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001324 float borderSpaceTwoPanelPortrait = a.getFloat(
1325 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1326 float borderSpaceTwoPanelLandscape = a.getFloat(
1327 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001328
Thales Lima85c942f2021-12-31 13:04:20 +00001329 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1330 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001331 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001332
1333 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1334 borderSpaceLandscape);
1335 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1336 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001337 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1338
1339 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001340 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1341 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001342 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001343 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1344 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001345 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1346
1347 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001348 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1349 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001350 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001351 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1352 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001353 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1354
Thales Limab7ef5692022-03-10 10:32:36 +00001355 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1356 minCellSize[INDEX_DEFAULT].x);
1357 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1358 minCellSize[INDEX_DEFAULT].y);
1359 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1360
1361 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1362 allAppsCellSize[INDEX_DEFAULT].x);
1363 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1364 allAppsCellSize[INDEX_DEFAULT].y);
1365 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1366
1367 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1368 allAppsCellSize[INDEX_DEFAULT].x);
1369 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1370 allAppsCellSize[INDEX_DEFAULT].y);
1371 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1372
1373 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1374 allAppsCellSize[INDEX_DEFAULT].x);
1375 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1376 allAppsCellSize[INDEX_DEFAULT].y);
1377 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1378
Thales Lima080d8902022-03-28 15:30:29 +01001379 float allAppsBorderSpace = a.getFloat(
1380 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1381 float allAppsBorderSpaceLandscape = a.getFloat(
1382 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1383 allAppsBorderSpace);
1384 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001385 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001386 allAppsBorderSpace);
1387 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001388 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001389 allAppsBorderSpace);
1390
1391 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1392 allAppsBorderSpace);
1393 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1394 allAppsBorderSpace);
1395 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1396
1397 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1398 allAppsBorderSpaceLandscape);
1399 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1400 allAppsBorderSpaceLandscape);
1401 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1402
1403 x = a.getFloat(
1404 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1405 allAppsBorderSpaceTwoPanelPortrait);
1406 y = a.getFloat(
1407 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1408 allAppsBorderSpaceTwoPanelPortrait);
1409 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1410
1411 x = a.getFloat(
1412 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1413 allAppsBorderSpaceTwoPanelLandscape);
1414 y = a.getFloat(
1415 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1416 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001417 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001418
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001419 iconSizes[INDEX_DEFAULT] =
1420 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1421 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001422 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001423 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001424 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001425 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001426 iconSizes[INDEX_DEFAULT]);
1427 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001428 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001429 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001430
Thales Limabb7d3882021-12-22 12:56:29 +00001431 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1432 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001433 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1434 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001435 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001436 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1437 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1438 allAppsIconSizes[INDEX_DEFAULT]);
1439 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1440 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1441 allAppsIconSizes[INDEX_DEFAULT]);
1442
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001443 textSizes[INDEX_DEFAULT] =
1444 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1445 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001446 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001447 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001448 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001449 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001450 textSizes[INDEX_DEFAULT]);
1451 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001452 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001453 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001454
Thales Limabb7d3882021-12-22 12:56:29 +00001455 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1456 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1457 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1458 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1459 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1460 allAppsIconTextSizes[INDEX_DEFAULT]);
1461 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1462 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1463 allAppsIconTextSizes[INDEX_DEFAULT]);
1464
Thales Lima83bedbf2021-10-05 17:47:39 +01001465 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1466 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001467 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1468 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1469 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001470 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001471 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001472 horizontalMargin[INDEX_DEFAULT]);
1473 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001474 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001475 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001476
Thales Limab8c05952022-05-23 16:58:38 +01001477 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1478 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001479 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001480 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1481 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1482 hotseatBarBottomSpace[INDEX_DEFAULT]);
1483 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1484 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1485 hotseatBarBottomSpace[INDEX_DEFAULT]);
1486 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1487 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1488 hotseatBarBottomSpace[INDEX_DEFAULT]);
1489
1490 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1491 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001492 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001493 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1494 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1495 hotseatQsbSpace[INDEX_DEFAULT]);
1496 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1497 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1498 hotseatQsbSpace[INDEX_DEFAULT]);
1499 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1500 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1501 hotseatQsbSpace[INDEX_DEFAULT]);
1502
Jon Miranda9c478b62023-03-23 21:38:49 -07001503 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1504 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1505 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1506 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1507 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1508 transientTaskbarIconSize[INDEX_DEFAULT]);
1509 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1510 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1511 transientTaskbarIconSize[INDEX_DEFAULT]);
1512 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1513 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001514 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001515
Jon Miranda04f05102023-04-04 12:16:31 -07001516 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1517 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1518 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1519 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1520 startAlignTaskbar[INDEX_DEFAULT]);
1521 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1522 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1523 startAlignTaskbar[INDEX_LANDSCAPE]);
1524 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1525 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1526 startAlignTaskbar[INDEX_DEFAULT]);
1527
Sunny Goyal415f1732018-11-29 10:33:47 -08001528 a.recycle();
1529 }
1530
1531 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001532 this(null);
1533 }
1534
1535 DisplayOption(GridOption grid) {
1536 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001537 minWidthDps = 0;
1538 minHeightDps = 0;
1539 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001540 for (int i = 0; i < COUNT_SIZES; i++) {
1541 iconSizes[i] = 0;
1542 textSizes[i] = 0;
1543 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001544 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001545 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001546 allAppsIconSizes[i] = 0;
1547 allAppsIconTextSizes[i] = 0;
1548 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001549 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001550 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001551 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001552 }
1553
1554 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001555 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001556 iconSizes[i] *= w;
1557 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001558 borderSpaces[i].x *= w;
1559 borderSpaces[i].y *= w;
1560 minCellSize[i].x *= w;
1561 minCellSize[i].y *= w;
1562 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001563 hotseatBarBottomSpace[i] *= w;
1564 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001565 allAppsCellSize[i].x *= w;
1566 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001567 allAppsIconSizes[i] *= w;
1568 allAppsIconTextSizes[i] *= w;
1569 allAppsBorderSpaces[i].x *= w;
1570 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001571 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001572 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001573
Sunny Goyal415f1732018-11-29 10:33:47 -08001574 return this;
1575 }
1576
1577 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001578 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001579 iconSizes[i] += p.iconSizes[i];
1580 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001581 borderSpaces[i].x += p.borderSpaces[i].x;
1582 borderSpaces[i].y += p.borderSpaces[i].y;
1583 minCellSize[i].x += p.minCellSize[i].x;
1584 minCellSize[i].y += p.minCellSize[i].y;
1585 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001586 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1587 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001588 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1589 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001590 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1591 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1592 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1593 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001594 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001595 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001596 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001597
Sunny Goyal415f1732018-11-29 10:33:47 -08001598 return this;
1599 }
1600 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001601}