blob: dfbcf5c43956ab81bc67273cbeabe240e5849ec3 [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);
243 String newGridName = initGrid(context, gridName);
244 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000245 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700246 }
247
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700248 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100249 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000250 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700251 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
252 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100253 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700254 }
255 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700256 if (Flags.oneGridSpecs()) {
257 mLandscapeModePreferenceListener = (String s) -> {
fbarond1cd8c22024-11-26 10:13:36 -0800258 if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
259 MAIN_EXECUTOR.execute(() -> {
260 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
261 onConfigChanged(context.getApplicationContext());
262 Trace.endSection();
263 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700264 }
265 };
266 LauncherPrefs.INSTANCE.get(context).addListener(
267 mLandscapeModePreferenceListener,
268 FIXED_LANDSCAPE_MODE
269 );
270 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700271 }
272
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700273 /**
274 * This constructor should NOT have any monitors by design.
275 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800276 public InvariantDeviceProfile(Context context, String gridName) {
277 String newName = initGrid(context, gridName);
278 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000279 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800280 }
281 }
282
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700283 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800284 * This constructor should NOT have any monitors by design.
285 */
286 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700287 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100288 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700289 String gridName = getCurrentGridName(context);
290
291 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000292 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700293 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700294 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000295 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700296 getPredefinedDeviceProfiles(
297 context,
298 gridName,
299 defaultInfo,
300 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800301 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700302 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000303 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700304
Alex Chau661f02d2022-06-07 14:03:43 +0100305 Context displayContext = context.createDisplayContext(display);
306 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700307 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700308 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000309 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700310 getPredefinedDeviceProfiles(
311 context,
312 gridName,
313 myInfo,
314 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800315 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700316 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000317 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700318
319 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
320 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100321 result.iconSizes[INDEX_DEFAULT] =
322 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
323 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700324 result.iconSizes[i] = Math.min(
325 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000326 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700327
Thales Lima83bedbf2021-10-05 17:47:39 +0100328 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
329 COUNT_SIZES);
330 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
331 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500332
Federico Baron56307d22024-11-06 18:48:48 +0000333 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800334 }
335
Sunny Goyal10fa0162024-04-21 00:13:35 -0700336 @Override
337 public void close() {
338 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700339 if (mLandscapeModePreferenceListener != null) {
340 LauncherPrefs.INSTANCE.executeIfCreated(
341 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
342 );
343 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700344 }
345
Tracy Zhou42255d22020-03-13 00:38:11 -0700346 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000347 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700348 }
349
Sunny Goyaleff44f32019-01-09 17:29:49 -0800350 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700351 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700352 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
353 context,
354 gridName,
355 displayInfo,
356 RestoreDbTask.isPending(context),
357 FIXED_LANDSCAPE_MODE.get(context)
358 );
fbaronebc10c92024-09-03 12:51:41 -0700359
360 // Filter out options that don't have the same number of columns as the grid
361 DeviceGridState deviceGridState = new DeviceGridState(context);
362 List<DisplayOption> allOptionsFilteredByColCount =
363 filterByColumnCount(allOptions, deviceGridState.getColumns());
364
Sunny Goyal19ff7282021-04-22 10:12:54 -0700365 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700366 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700367 ? new ArrayList<>(allOptions)
368 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000369 displayInfo.getDeviceType());
370 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700371 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800372 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700373
fbaronebc10c92024-09-03 12:51:41 -0700374 private List<DisplayOption> filterByColumnCount(
375 List<DisplayOption> allOptions, int numColumns) {
376 return allOptions.stream().filter(
377 option -> option.grid.numColumns == numColumns).toList();
378 }
379
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700380 /**
381 * @deprecated This is a temporary solution because on the backup and restore case we modify the
382 * IDP, this resets it. b/332974074
383 */
384 @Deprecated
385 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700386 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700387 }
388
Thales Limab67bfa72022-11-02 15:30:11 +0000389 @VisibleForTesting
390 public static String getDefaultGridName(Context context) {
391 return new InvariantDeviceProfile().initGrid(context, null);
392 }
393
Federico Baron56307d22024-11-06 18:48:48 +0000394 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700395 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700396 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000397 numRows = closestProfile.numRows;
398 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000399 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000400 dbFile = closestProfile.dbFile;
401 defaultLayoutId = closestProfile.defaultLayoutId;
402 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300403
Sunny Goyalae190ff2020-04-14 00:19:01 +0000404 numFolderRows = closestProfile.numFolderRows;
405 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300406 folderStyle = closestProfile.folderStyle;
407
Thales Limad852d652023-01-17 14:01:13 +0000408 cellStyle = closestProfile.cellStyle;
409
Jon Mirandae126d722021-02-25 10:45:20 -0500410 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400411 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100412 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800413 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100414 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100415 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100416 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100417 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100418 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100419 hotseatSpecsId = closestProfile.mHotseatSpecsId;
420 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000421 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
422 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
423 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
424 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300425 numAllAppsRowsForCellHeightCalculation =
426 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000427 this.deviceType = displayInfo.getDeviceType();
428 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000429
Vinit Nayakc7293172022-07-18 16:41:50 -0700430 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
431
Thales Lima83bedbf2021-10-05 17:47:39 +0100432 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100433 float maxIconSize = iconSize[0];
434 for (int i = 1; i < iconSize.length; i++) {
435 maxIconSize = Math.max(maxIconSize, iconSize[i]);
436 }
437 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000438 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
439
Thales Lima83bedbf2021-10-05 17:47:39 +0100440 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700441
Thales Lima83bedbf2021-10-05 17:47:39 +0100442 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100443
Thales Lima83bedbf2021-10-05 17:47:39 +0100444 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100445
Thales Limad90faab2021-09-21 17:18:47 +0100446 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100447
Sunny Goyal19ff7282021-04-22 10:12:54 -0700448 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000449 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700450 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100451 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
452 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700453
Thales Limae9273ea2023-01-26 12:33:52 +0000454 allAppsStyle = closestProfile.allAppsStyle;
455
Sunny Goyal19ff7282021-04-22 10:12:54 -0700456 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300457
Alex Chau1c883d82021-12-01 18:43:10 +0000458 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500460
Thales Limab7ef5692022-03-10 10:32:36 +0000461 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000462 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
463 allAppsIconSize = displayOption.allAppsIconSizes;
464 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000465
Thales Lima11af7bc2022-08-12 15:24:54 +0100466 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000467
Jon Miranda9c478b62023-03-23 21:38:49 -0700468 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
469
Jon Miranda04f05102023-04-04 12:16:31 -0700470 startAlignTaskbar = displayOption.startAlignTaskbar;
471
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700472 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800473 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700474
Sunny Goyalae190ff2020-04-14 00:19:01 +0000475 // If the partner customization apk contains any grid overrides, apply them
476 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700477 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700478
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000479 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700480 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700481 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700482 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000483 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000484 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000485 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700486 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000487 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700488
Sunny Goyal19ff7282021-04-22 10:12:54 -0700489 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
490 int displayWidth = bounds.bounds.width();
491 int displayHeight = bounds.bounds.height();
492 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700493
Sunny Goyal19ff7282021-04-22 10:12:54 -0700494 // We need to ensure that there is enough extra space in the wallpaper
495 // for the intended parallax effects
496 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300497 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
498 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700499 ? 2
500 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
501 defaultWallpaperSize.x =
502 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700503 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000504 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700505
Thales Lima6a590062022-11-22 15:52:49 +0000506 int numMinShownHotseatIconsForTablet = supportedProfiles
507 .stream()
508 .filter(deviceProfile -> deviceProfile.isTablet)
509 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
510 .min()
511 .orElse(0);
512
513 supportedProfiles
514 .stream()
515 .filter(deviceProfile -> deviceProfile.isTablet)
516 .forEach(deviceProfile -> {
517 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
518 deviceProfile.recalculateHotseatWidthAndBorderSpace();
519 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700520 }
521
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700522 public void addOnChangeListener(OnIDPChangeListener listener) {
523 mChangeListeners.add(listener);
524 }
525
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800526 public void removeOnChangeListener(OnIDPChangeListener listener) {
527 mChangeListeners.remove(listener);
528 }
529
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700530 /**
531 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
532 * migration.
533 */
534 public void setCurrentGrid(Context context, String newGridName) {
535 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700536 MAIN_EXECUTOR.execute(() -> {
537 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
538 onConfigChanged(context.getApplicationContext());
539 Trace.endSection();
540 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800541 }
542
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700543 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700544 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000545 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
546 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700547 }
548
Pat Manning24cec692023-10-13 10:36:57 +0000549 /** Updates IDP using the provided context. Notifies listeners of change. */
550 @VisibleForTesting
551 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700552 Object[] oldState = toModelState();
553
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700554 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700555 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700556 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700557
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700558 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700559 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700560 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700561 }
562 }
563
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700564 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
565 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
566 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800567 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700568 }
569
570 private static List<DisplayOption> getPredefinedDeviceProfiles(
571 Context context,
572 String gridName,
573 Info displayInfo,
574 boolean allowDisabledGrid,
575 boolean isFixedLandscapeMode
576 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800577 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100578
Alex Chau1c883d82021-12-01 18:43:10 +0000579 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700580 final int depth = parser.getDepth();
581 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700582 while (((type = parser.next()) != XmlPullParser.END_TAG ||
583 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800584 if ((type == XmlPullParser.START_TAG)
585 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000586 GridOption gridOption = new GridOption(
587 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700588 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
589 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100590 final int displayDepth = parser.getDepth();
591 while (((type = parser.next()) != XmlPullParser.END_TAG
592 || parser.getDepth() > displayDepth)
593 && type != XmlPullParser.END_DOCUMENT) {
594 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
595 parser.getName())) {
596 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100597 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100598 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800599 }
600 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700601 }
602 }
sfufa@google.comde013292021-09-21 18:22:44 -0700603 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700604 throw new RuntimeException(e);
605 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000606 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800607 if (!TextUtils.isEmpty(gridName)) {
608 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000609 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
610 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000611 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800612 }
613 }
614 }
fbaronebc10c92024-09-03 12:51:41 -0700615 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
616 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000617 for (DisplayOption option : profiles) {
618 if (option.canBeDefault) {
619 filteredProfiles.add(option);
620 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800621 }
fbaronebc10c92024-09-03 12:51:41 -0700622 } else if (filteredProfiles.isEmpty()) {
623 // In this case we had a grid selected but we couldn't find it.
624 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800625 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000626 if (filteredProfiles.isEmpty()) {
627 throw new RuntimeException("No display option with canBeDefault=true");
628 }
629 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700630 }
631
Thales Lima7ec83822021-08-05 13:32:10 +0100632 /**
fbarond1cd8c22024-11-26 10:13:36 -0800633 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
634 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700635 *
fbarond1cd8c22024-11-26 10:13:36 -0800636 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700637 */
fbarond1cd8c22024-11-26 10:13:36 -0800638 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000639 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800640 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700641
642 try (XmlResourceParser parser = resourceHelper.getXml()) {
643 final int depth = parser.getDepth();
644 int type;
645 while (((type = parser.next()) != XmlPullParser.END_TAG
646 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
647 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800648 && "GridSize".equals(parser.getName())) {
649 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700650 }
651 }
652 } catch (IOException | XmlPullParserException e) {
653 throw new RuntimeException(e);
654 }
655
fbaron49358342024-11-22 17:38:56 -0800656 // Finds the min width and height in dp for all displays.
657 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
658
fbarond1cd8c22024-11-26 10:13:36 -0800659 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700660 }
661
662 /**
fbarond1cd8c22024-11-26 10:13:36 -0800663 * @return the biggest grid size that fits the display dimensions.
664 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700665 */
fbarond1cd8c22024-11-26 10:13:36 -0800666 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800667 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800668 GridSize selectedGridSize = null;
669 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800670 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800671 if (selectedGridSize == null
672 || (selectedGridSize.mNumColumns <= item.mNumColumns
673 && selectedGridSize.mNumRows <= item.mNumRows)) {
674 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800675 }
676 }
677 }
fbarond1cd8c22024-11-26 10:13:36 -0800678 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800679 }
680
681 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700682 int minWidthPx = Integer.MAX_VALUE;
683 int minHeightPx = Integer.MAX_VALUE;
684 for (WindowBounds bounds : displayInfo.supportedBounds) {
685 boolean isTablet = displayInfo.isTablet(bounds);
Federico Baron56307d22024-11-06 18:48:48 +0000686 if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) {
fbaron49358342024-11-22 17:38:56 -0800687 // For split displays, take half width per page.
fbaronebc10c92024-09-03 12:51:41 -0700688 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
689 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
690 } else if (!isTablet && bounds.isLandscape()) {
fbaron49358342024-11-22 17:38:56 -0800691 // We will use transposed layout in this case.
fbaronebc10c92024-09-03 12:51:41 -0700692 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
693 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
694 } else {
695 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
696 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
697 }
698 }
699
fbaron49358342024-11-22 17:38:56 -0800700 int minWidthDp = (int) dpiFromPx(minWidthPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
701 int minHeightDp = (int) dpiFromPx(minHeightPx, DisplayMetrics.DENSITY_DEVICE_STABLE);
702
703 return new int[]{minWidthDp, minHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700704 }
705
706 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000707 * Returns the GridOption associated to the given file name or null if the fileName is not
708 * supported.
709 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
710 */
711 public GridOption getGridOptionFromFileName(Context context, String fileName) {
712 return parseAllGridOptions(context).stream()
713 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
714 .findFirst()
715 .orElse(null);
716 }
717
718 /**
719 * Returns the name of the given size on the current device or empty string if the size is not
720 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
721 * (Note: the name of the grid can be different for the same grid size depending of
722 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000723 */
724 public String getGridNameFromSize(Context context, Point size) {
725 return parseAllGridOptions(context).stream()
726 .filter(gridOption -> gridOption.numColumns == size.x
727 && gridOption.numRows == size.y)
728 .map(gridOption -> gridOption.name)
729 .findFirst()
730 .orElse("");
731 }
732
733 /**
734 * Returns the grid option for the given gridName on the current device (Note: the gridOption
735 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
736 */
737 public GridOption getGridOptionFromName(Context context, String gridName) {
738 return parseAllGridOptions(context).stream()
739 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
740 .findFirst()
741 .orElse(null);
742 }
743
744 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100745 * @return all the grid options that can be shown on the device
746 */
747 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000748 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700749 .stream()
750 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800751 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700752 .collect(Collectors.toList());
753 }
754
755 /**
756 * @return all the grid options that can be shown on the device
757 */
Federico Baron56307d22024-11-06 18:48:48 +0000758 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100759 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000760 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100761 final int depth = parser.getDepth();
762 int type;
763 while (((type = parser.next()) != XmlPullParser.END_TAG
764 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
765 if ((type == XmlPullParser.START_TAG)
766 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000767 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100768 }
769 }
770 } catch (IOException | XmlPullParserException e) {
771 Log.e(TAG, "Error parsing device profile", e);
772 return Collections.emptyList();
773 }
774 return result;
775 }
776
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700777 private int getLauncherIconDensity(int requiredSize) {
778 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700779 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700780 DisplayMetrics.DENSITY_LOW,
781 DisplayMetrics.DENSITY_MEDIUM,
782 DisplayMetrics.DENSITY_TV,
783 DisplayMetrics.DENSITY_HIGH,
784 DisplayMetrics.DENSITY_XHIGH,
785 DisplayMetrics.DENSITY_XXHIGH,
786 DisplayMetrics.DENSITY_XXXHIGH
787 };
788
789 int density = DisplayMetrics.DENSITY_XXXHIGH;
790 for (int i = densityBuckets.length - 1; i >= 0; i--) {
791 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
792 / DisplayMetrics.DENSITY_DEFAULT;
793 if (expectedSize >= requiredSize) {
794 density = densityBuckets[i];
795 }
796 }
797
798 return density;
799 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700800
Adam Cohen2e6da152015-05-06 11:42:25 -0700801 /**
802 * Apply any Partner customization grid overrides.
803 *
804 * Currently we support: all apps row / column count.
805 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700806 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
807 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800808 if (p == null) {
809 return;
810 }
811 try {
812 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
813 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
814 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
815
816 if (numRows > 0 && numColumns > 0) {
817 this.numRows = numRows;
818 this.numColumns = numColumns;
819 }
820 if (iconSizePx > 0) {
821 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
822 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
823 }
824 } catch (Resources.NotFoundException ex) {
825 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700826 }
827 }
828
Sunny Goyal415f1732018-11-29 10:33:47 -0800829 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700830 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700831 }
832
Sunny Goyal19ff7282021-04-22 10:12:54 -0700833 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700834 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700835 int minWidthPx = Integer.MAX_VALUE;
836 int minHeightPx = Integer.MAX_VALUE;
837 for (WindowBounds bounds : displayInfo.supportedBounds) {
838 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000839 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700840 // For split displays, take half width per page
841 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
842 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700843
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844 } else if (!isTablet && bounds.isLandscape()) {
845 // We will use transposed layout in this case
846 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
847 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
848 } else {
849 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
850 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
851 }
852 }
853
Thales Lima425f6822022-05-10 13:44:58 -0300854 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
855 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700856
857 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700858 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700859 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
860 dist(width, height, b.minWidthDps, b.minHeightDps)));
861
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700862 DisplayOption closestPoint = points.get(0);
863 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700864 float weights = 0;
865
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700866 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
867 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700868 }
869
870 DisplayOption out = new DisplayOption(closestOption);
871 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700872 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700873 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
874 weights += w;
875 out.add(new DisplayOption().add(p).multiply(w));
876 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700877 out.multiply(1.0f / weights);
878
Thales Lima6e0005a2021-10-27 15:53:41 +0100879 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700880 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100881 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
882 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700883 }
884
885 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700886 }
887
Sunny Goyal27835952017-01-13 12:15:53 -0800888 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000889 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
890 Rect bounds = windowManagerProxy.getCurrentBounds(context);
891 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700892
Alex Chauc09a98a2023-11-14 12:51:42 +0000893 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400894 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700895
Sunny Goyal187b16c2022-03-01 16:53:23 -0800896 /**
897 * Returns the device profile matching the provided screen configuration
898 */
899 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700900 DeviceProfile bestMatch = supportedProfiles.get(0);
901 float minDiff = Float.MAX_VALUE;
902
903 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400904 float diff = Math.abs(profile.widthPx - screenWidth)
905 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700906 if (diff < minDiff) {
907 minDiff = diff;
908 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800909 } else if (diff == minDiff && profile.rotationHint == rotation) {
910 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700911 }
912 }
913 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800914 }
915
Sunny Goyal415f1732018-11-29 10:33:47 -0800916 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700917 float d = dist(x0, y0, x1, y1);
918 if (Float.compare(d, 0f) == 0) {
919 return Float.POSITIVE_INFINITY;
920 }
921 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
922 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700923
924 /**
925 * As a ratio of screen height, the total distance we want the parallax effect to span
926 * horizontally
927 */
928 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
929 float aspectRatio = width / (float) height;
930
931 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
932 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
933 // We will use these two data points to extrapolate how much the wallpaper parallax effect
934 // to span (ie travel) at any aspect ratio:
935
sfufa@google.comde013292021-09-21 18:22:44 -0700936 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
937 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700938 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
939 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
940
941 // To find out the desired width at different aspect ratios, we use the following two
942 // formulas, where the coefficient on x is the aspect ratio (width/height):
943 // (16/10)x + y = 1.5
944 // (10/16)x + y = 1.2
945 // We solve for x and y and end up with a final formula:
946 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700947 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
948 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700949 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
950 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
951 return x * aspectRatio + y;
952 }
953
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700954 public interface OnIDPChangeListener {
955
Sunny Goyalb47172b2021-05-03 19:59:51 -0700956 /**
957 * Called when the device provide changes
958 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700959 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700960 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800961
962
Sunny Goyaleff44f32019-01-09 17:29:49 -0800963 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800964
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800965 public static final String TAG_NAME = "grid-option";
966
Alex Chau1c883d82021-12-01 18:43:10 +0000967 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
968 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
969 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
970 private static final int DEVICE_CATEGORY_ALL =
971 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
972
Thales Lima11af7bc2022-08-12 15:24:54 +0100973 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
974 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
975 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
976 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
977 private static final int DONT_INLINE_QSB = 0;
978
Sunny Goyaleff44f32019-01-09 17:29:49 -0800979 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700980 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800981 public final int numRows;
982 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000983 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700984 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800985
Thales Lima1faa4ed2023-12-01 16:48:19 +0000986 private final int[] numFolderRows = new int[COUNT_SIZES];
987 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300988 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000989 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800990
Thales Limae9273ea2023-01-26 12:33:52 +0000991 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700992 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300993 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700994 private final int numDatabaseAllAppsColumns;
995 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700996 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100997
Thales Lima11af7bc2022-08-12 15:24:54 +0100998 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
999
Thales Limab35faed2022-09-05 16:30:01 -03001000 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001001 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001002
Sunny Goyal415f1732018-11-29 10:33:47 -08001003 private final int defaultLayoutId;
1004 private final int demoModeLayoutId;
1005
Jon Mirandae126d722021-02-25 10:45:20 -05001006 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001007 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001008 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001009 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001010 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001011 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001012 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001013 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001014 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001015 private final int mHotseatSpecsId;
1016 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001017 private final int mWorkspaceCellSpecsId;
1018 private final int mWorkspaceCellSpecsTwoPanelId;
1019 private final int mAllAppsCellSpecsId;
1020 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001021 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001022 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001023 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001024
Federico Baron56307d22024-11-06 18:48:48 +00001025 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001026 TypedArray a = context.obtainStyledAttributes(
1027 attrs, R.styleable.GridDisplayOption);
1028 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001029 title = a.getString(R.styleable.GridDisplayOption_title);
1030 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1031 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001032 mGridSizeSpecsId = a.getResourceId(
1033 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001034 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001035 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1036 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1037 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1038 numColumns = gridSize.mNumColumns;
1039 numRows = gridSize.mNumRows;
1040 dbFile = gridSize.mDbFile;
1041 defaultLayoutId = gridSize.mDefaultLayoutId;
1042 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001043 } else {
1044 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001045 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001046 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001047 defaultLayoutId = a.getResourceId(
1048 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1049 demoModeLayoutId = a.getResourceId(
1050 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001051 }
1052
Alex Chau9fee3fd2021-12-01 18:43:10 +00001053 numSearchContainerColumns = a.getInt(
1054 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001055
Thales Limae9273ea2023-01-26 12:33:52 +00001056 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1057 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001058 numAllAppsColumns = a.getInt(
1059 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1060 numDatabaseAllAppsColumns = a.getInt(
1061 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1062
1063 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001064 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001065 numDatabaseHotseatIcons = a.getInt(
1066 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001067
Vinit Nayakc7293172022-07-18 16:41:50 -07001068 inlineNavButtonsEndSpacing =
1069 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001070 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001071
Thales Lima1faa4ed2023-12-01 16:48:19 +00001072 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001073 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001074 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001075 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001076
Thales Lima1faa4ed2023-12-01 16:48:19 +00001077 if (FeatureFlags.enableResponsiveWorkspace()) {
1078 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1079 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1080 numFolderRows[INDEX_DEFAULT]);
1081 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1082 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1083 numFolderColumns[INDEX_DEFAULT]);
1084 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1085 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1086 numFolderRows[INDEX_DEFAULT]);
1087 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1088 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1089 numFolderColumns[INDEX_DEFAULT]);
1090 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1091 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1092 numFolderRows[INDEX_DEFAULT]);
1093 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1094 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1095 numFolderColumns[INDEX_DEFAULT]);
1096 } else {
1097 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1098 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1099 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1100 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1101 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1102 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1103 }
1104
Thales Limab35faed2022-09-05 16:30:01 -03001105 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1106 INVALID_RESOURCE_HANDLE);
1107
Thales Limad852d652023-01-17 14:01:13 +00001108 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1109 R.style.CellStyleDefault);
1110
Jon Mirandae126d722021-02-25 10:45:20 -05001111 isScalable = a.getBoolean(
1112 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001113 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001114 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001115
Thales Limaca31b612023-09-14 14:25:26 +01001116 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001117 mWorkspaceSpecsId = a.getResourceId(
1118 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001119 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1120 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001121 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001122 mAllAppsSpecsId = a.getResourceId(
1123 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001124 mAllAppsSpecsTwoPanelId = a.getResourceId(
1125 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001126 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001127 mFolderSpecsId = a.getResourceId(
1128 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001129 mFolderSpecsTwoPanelId = a.getResourceId(
1130 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001131 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001132 mHotseatSpecsId = a.getResourceId(
1133 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1134 mHotseatSpecsTwoPanelId = a.getResourceId(
1135 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001136 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001137 mWorkspaceCellSpecsId = a.getResourceId(
1138 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1139 INVALID_RESOURCE_HANDLE);
1140 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1141 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001142 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001143 mAllAppsCellSpecsId = a.getResourceId(
1144 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1145 INVALID_RESOURCE_HANDLE);
1146 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1147 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001148 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001149 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1150 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1151 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001152 } else {
1153 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001154 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001155 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001156 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001157 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001158 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001159 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1160 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001161 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1162 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1163 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1164 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001165 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001166 }
1167
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001168 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001169 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001170
Thales Lima11af7bc2022-08-12 15:24:54 +01001171 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1172 DONT_INLINE_QSB);
1173 inlineQsb[INDEX_DEFAULT] =
1174 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1175 inlineQsb[INDEX_LANDSCAPE] =
1176 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1177 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1178 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1179 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1180 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1181 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1182 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1183
Sunny Goyal415f1732018-11-29 10:33:47 -08001184 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001185 }
1186
1187 public boolean isEnabled(@DeviceType int deviceType) {
1188 switch (deviceType) {
1189 case TYPE_PHONE:
1190 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1191 case TYPE_TABLET:
1192 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1193 case TYPE_MULTI_DISPLAY:
1194 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1195 == DEVICE_CATEGORY_MULTI_DISPLAY;
1196 default:
1197 return false;
1198 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001199 }
fbaronebc10c92024-09-03 12:51:41 -07001200
fbaron6c91ef92024-11-12 22:22:43 -08001201 /**
1202 * Returns true if the grid option should be used given the flags that are toggled on/off.
1203 */
fbaronc1b68f42024-11-08 18:10:46 -08001204 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001205 if (deviceType == TYPE_TABLET) {
1206 return Flags.oneGridRotationHandling() == mIsDualGrid;
1207 }
fbaronc1b68f42024-11-08 18:10:46 -08001208
fbaron6c91ef92024-11-12 22:22:43 -08001209 // Here we return true if fixed landscape mode should be on.
1210 if (mIsFixedLandscape || isFixedLandscape) {
1211 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001212 }
1213
fbaron6c91ef92024-11-12 22:22:43 -08001214 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001215 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001216 return Flags.oneGridSpecs();
1217 }
1218
1219 // Here we return true if we want to show the old grids.
1220 if (mIsOldGrid) {
1221 return !Flags.oneGridSpecs();
1222 }
1223
1224 return true;
fbaron49f7df02024-11-05 16:15:19 -08001225 }
fbaronebc10c92024-09-03 12:51:41 -07001226 }
1227
fbarond1cd8c22024-11-26 10:13:36 -08001228 public static final class GridSize {
1229 final int mNumRows;
1230 final int mNumColumns;
1231 final float mMinDeviceWidthDp;
1232 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001233 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001234 final int mDefaultLayoutId;
1235 final int mDemoModeLayoutId;
1236
fbaronebc10c92024-09-03 12:51:41 -07001237
fbarond1cd8c22024-11-26 10:13:36 -08001238 GridSize(Context context, AttributeSet attrs) {
1239 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001240
fbarond1cd8c22024-11-26 10:13:36 -08001241 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1242 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1243 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1244 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1245 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001246 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001247 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001248 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001249 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001250
1251 a.recycle();
1252 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001253 }
1254
Sunny Goyal19ff7282021-04-22 10:12:54 -07001255 @VisibleForTesting
1256 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001257 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001258
Sunny Goyal415f1732018-11-29 10:33:47 -08001259 private final float minWidthDps;
1260 private final float minHeightDps;
1261 private final boolean canBeDefault;
1262
Thales Lima83bedbf2021-10-05 17:47:39 +01001263 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001264
Thales Lima78d00ad2021-09-30 11:29:06 +01001265 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001266 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001267 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1268 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001269
Thales Lima78d00ad2021-09-30 11:29:06 +01001270 private final float[] iconSizes = new float[COUNT_SIZES];
1271 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001272
Thales Limab7ef5692022-03-10 10:32:36 +00001273 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001274 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1275 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1276 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1277
Jon Miranda9c478b62023-03-23 21:38:49 -07001278 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1279
Jon Miranda04f05102023-04-04 12:16:31 -07001280 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1281
Thales Lima1de4d552021-10-13 16:13:25 +01001282 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001283 this.grid = grid;
1284
Jon Miranda9c478b62023-03-23 21:38:49 -07001285 Resources res = context.getResources();
1286
Thales Lima1de4d552021-10-13 16:13:25 +01001287 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001288
Sunny Goyal415f1732018-11-29 10:33:47 -08001289 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1290 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001291
Thales Lima1de4d552021-10-13 16:13:25 +01001292 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001293
Thales Lima83bedbf2021-10-05 17:47:39 +01001294 float x;
1295 float y;
1296
Thales Lima85c942f2021-12-31 13:04:20 +00001297 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1298 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001299 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001300
1301 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1302 minCellSize[INDEX_DEFAULT].x);
1303 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1304 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001305 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001306
Thales Lima85c942f2021-12-31 13:04:20 +00001307 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001308 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001309 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001310 minCellSize[INDEX_DEFAULT].y);
1311 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1312
Thales Lima85c942f2021-12-31 13:04:20 +00001313 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001314 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001315 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001316 minCellSize[INDEX_DEFAULT].y);
1317 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001318
Thales Lima85c942f2021-12-31 13:04:20 +00001319 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001320 float borderSpaceLandscape = a.getFloat(
1321 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001322 float borderSpaceTwoPanelPortrait = a.getFloat(
1323 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1324 float borderSpaceTwoPanelLandscape = a.getFloat(
1325 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001326
Thales Lima85c942f2021-12-31 13:04:20 +00001327 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1328 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001329 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001330
1331 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1332 borderSpaceLandscape);
1333 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1334 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001335 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1336
1337 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001338 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1339 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001340 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001341 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1342 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001343 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1344
1345 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001346 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1347 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001348 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001349 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1350 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001351 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1352
Thales Limab7ef5692022-03-10 10:32:36 +00001353 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1354 minCellSize[INDEX_DEFAULT].x);
1355 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1356 minCellSize[INDEX_DEFAULT].y);
1357 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1358
1359 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1360 allAppsCellSize[INDEX_DEFAULT].x);
1361 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1362 allAppsCellSize[INDEX_DEFAULT].y);
1363 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1364
1365 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1366 allAppsCellSize[INDEX_DEFAULT].x);
1367 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1368 allAppsCellSize[INDEX_DEFAULT].y);
1369 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1370
1371 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1372 allAppsCellSize[INDEX_DEFAULT].x);
1373 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1374 allAppsCellSize[INDEX_DEFAULT].y);
1375 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1376
Thales Lima080d8902022-03-28 15:30:29 +01001377 float allAppsBorderSpace = a.getFloat(
1378 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1379 float allAppsBorderSpaceLandscape = a.getFloat(
1380 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1381 allAppsBorderSpace);
1382 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001383 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001384 allAppsBorderSpace);
1385 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001386 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001387 allAppsBorderSpace);
1388
1389 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1390 allAppsBorderSpace);
1391 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1392 allAppsBorderSpace);
1393 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1394
1395 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1396 allAppsBorderSpaceLandscape);
1397 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1398 allAppsBorderSpaceLandscape);
1399 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1400
1401 x = a.getFloat(
1402 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1403 allAppsBorderSpaceTwoPanelPortrait);
1404 y = a.getFloat(
1405 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1406 allAppsBorderSpaceTwoPanelPortrait);
1407 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1408
1409 x = a.getFloat(
1410 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1411 allAppsBorderSpaceTwoPanelLandscape);
1412 y = a.getFloat(
1413 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1414 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001415 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001416
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001417 iconSizes[INDEX_DEFAULT] =
1418 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1419 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001420 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001421 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001422 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001423 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001424 iconSizes[INDEX_DEFAULT]);
1425 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001426 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001427 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001428
Thales Limabb7d3882021-12-22 12:56:29 +00001429 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1430 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001431 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1432 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001433 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001434 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1435 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1436 allAppsIconSizes[INDEX_DEFAULT]);
1437 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1438 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1439 allAppsIconSizes[INDEX_DEFAULT]);
1440
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001441 textSizes[INDEX_DEFAULT] =
1442 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1443 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001444 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001445 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001446 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001447 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001448 textSizes[INDEX_DEFAULT]);
1449 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001450 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001451 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001452
Thales Limabb7d3882021-12-22 12:56:29 +00001453 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1454 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1455 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1456 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1457 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1458 allAppsIconTextSizes[INDEX_DEFAULT]);
1459 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1460 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1461 allAppsIconTextSizes[INDEX_DEFAULT]);
1462
Thales Lima83bedbf2021-10-05 17:47:39 +01001463 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1464 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001465 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1466 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1467 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001468 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001469 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001470 horizontalMargin[INDEX_DEFAULT]);
1471 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001472 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001473 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001474
Thales Limab8c05952022-05-23 16:58:38 +01001475 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1476 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001477 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001478 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1479 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1480 hotseatBarBottomSpace[INDEX_DEFAULT]);
1481 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1482 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1483 hotseatBarBottomSpace[INDEX_DEFAULT]);
1484 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1485 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1486 hotseatBarBottomSpace[INDEX_DEFAULT]);
1487
1488 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1489 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001490 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001491 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1492 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1493 hotseatQsbSpace[INDEX_DEFAULT]);
1494 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1495 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1496 hotseatQsbSpace[INDEX_DEFAULT]);
1497 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1498 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1499 hotseatQsbSpace[INDEX_DEFAULT]);
1500
Jon Miranda9c478b62023-03-23 21:38:49 -07001501 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1502 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1503 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1504 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1505 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1506 transientTaskbarIconSize[INDEX_DEFAULT]);
1507 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1508 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1509 transientTaskbarIconSize[INDEX_DEFAULT]);
1510 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1511 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001512 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001513
Jon Miranda04f05102023-04-04 12:16:31 -07001514 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1515 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1516 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1517 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1518 startAlignTaskbar[INDEX_DEFAULT]);
1519 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1520 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1521 startAlignTaskbar[INDEX_LANDSCAPE]);
1522 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1523 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1524 startAlignTaskbar[INDEX_DEFAULT]);
1525
Sunny Goyal415f1732018-11-29 10:33:47 -08001526 a.recycle();
1527 }
1528
1529 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001530 this(null);
1531 }
1532
1533 DisplayOption(GridOption grid) {
1534 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001535 minWidthDps = 0;
1536 minHeightDps = 0;
1537 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001538 for (int i = 0; i < COUNT_SIZES; i++) {
1539 iconSizes[i] = 0;
1540 textSizes[i] = 0;
1541 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001542 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001543 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001544 allAppsIconSizes[i] = 0;
1545 allAppsIconTextSizes[i] = 0;
1546 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001547 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001548 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001549 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001550 }
1551
1552 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001553 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001554 iconSizes[i] *= w;
1555 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001556 borderSpaces[i].x *= w;
1557 borderSpaces[i].y *= w;
1558 minCellSize[i].x *= w;
1559 minCellSize[i].y *= w;
1560 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001561 hotseatBarBottomSpace[i] *= w;
1562 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001563 allAppsCellSize[i].x *= w;
1564 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001565 allAppsIconSizes[i] *= w;
1566 allAppsIconTextSizes[i] *= w;
1567 allAppsBorderSpaces[i].x *= w;
1568 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001569 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001570 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001571
Sunny Goyal415f1732018-11-29 10:33:47 -08001572 return this;
1573 }
1574
1575 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001576 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001577 iconSizes[i] += p.iconSizes[i];
1578 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001579 borderSpaces[i].x += p.borderSpaces[i].x;
1580 borderSpaces[i].y += p.borderSpaces[i].y;
1581 minCellSize[i].x += p.minCellSize[i].x;
1582 minCellSize[i].y += p.minCellSize[i].y;
1583 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001584 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1585 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001586 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1587 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001588 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1589 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1590 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1591 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001592 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001593 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001594 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001595
Sunny Goyal415f1732018-11-29 10:33:47 -08001596 return this;
1597 }
1598 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001599}