blob: 5becddeed71e4fde41aa23d2ef907f77ef41dd9e [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;
fbaron9ce45ba2024-12-03 02:17:00 -080066import com.android.launcher3.util.window.CachedDisplayInfo;
Sunny Goyal187b16c2022-03-01 16:53:23 -080067import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070068
Sunny Goyal819e1932016-07-07 16:43:58 -070069import org.xmlpull.v1.XmlPullParser;
70import org.xmlpull.v1.XmlPullParserException;
71
72import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000073import java.lang.annotation.Retention;
74import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070075import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070076import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080077import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070078import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000079import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070080import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070081
Sunny Goyal10fa0162024-04-21 00:13:35 -070082public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070083
Hyunyoung Songc55a3502018-12-04 15:43:16 -080084 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070085 // We do not need any synchronization for this variable as its only written on UI thread.
86 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070087 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070088
Alex Chau1c883d82021-12-01 18:43:10 +000089 @Retention(RetentionPolicy.SOURCE)
90 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070091 public @interface DeviceType {
92 }
Thales Limab8c05952022-05-23 16:58:38 +010093
Alex Chau1c883d82021-12-01 18:43:10 +000094 public static final int TYPE_PHONE = 0;
95 public static final int TYPE_MULTI_DISPLAY = 1;
96 public static final int TYPE_TABLET = 2;
97
Sunny Goyal53d7ee42015-05-22 12:25:45 -070098 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
99
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700100 // Constants that affects the interpolation curve between statically defined device profile
101 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800102 private static final float KNEARESTNEIGHBOR = 3;
103 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700104
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700105 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800106 private static final float WEIGHT_EFFICIENT = 100000f;
107
Thales Lima83bedbf2021-10-05 17:47:39 +0100108 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
109 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000110 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100111 static final int INDEX_DEFAULT = 0;
112 static final int INDEX_LANDSCAPE = 1;
113 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
114 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100115
Thales Limaec5abba2023-04-05 16:33:50 +0100116 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800117 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
118 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
119 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
120
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700121 /**
122 * Number of icons per row and column in the workspace.
123 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700124 public int numRows;
125 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000126 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700127
128 /**
129 * Number of icons per row and column in the folder.
130 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000131 public int[] numFolderRows;
132 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100133 public float[] iconSize;
134 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700135 public int iconBitmapSize;
136 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000137 public @DeviceType int deviceType;
Federico Baron56307d22024-11-06 18:48:48 +0000138 public Info displayInfo;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700139
Thales Lima83bedbf2021-10-05 17:47:39 +0100140 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100141
Thales Lima83bedbf2021-10-05 17:47:39 +0100142 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300143 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100144
Thales Limab35faed2022-09-05 16:30:01 -0300145 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100146
Thales Limad852d652023-01-17 14:01:13 +0000147 public @StyleRes int cellStyle;
148
Thales Lima83bedbf2021-10-05 17:47:39 +0100149 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500150
Thales Limab7ef5692022-03-10 10:32:36 +0000151 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000152 public float[] allAppsIconSize;
153 public float[] allAppsIconTextSize;
154 public PointF[] allAppsBorderSpaces;
155
Jon Miranda9c478b62023-03-23 21:38:49 -0700156 public float[] transientTaskbarIconSize;
157
Jon Miranda04f05102023-04-04 12:16:31 -0700158 public boolean[] startAlignTaskbar;
159
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700160 /**
161 * Number of icons inside the hotseat area.
162 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800163 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700164
165 /**
166 * Number of icons inside the hotseat area that is stored in the database. This is greater than
167 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
168 * sizes that share the same DB.
169 */
170 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700171
Thales Limab8c05952022-05-23 16:58:38 +0100172 public float[] hotseatBarBottomSpace;
173 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300174
Jon Miranda6f7e9702019-09-16 14:44:14 -0700175 /**
176 * Number of columns in the all apps list.
177 */
178 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300179 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700180 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000181 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700182
Jon Mirandae126d722021-02-25 10:45:20 -0500183 /**
184 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
185 */
186 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000187 @XmlRes
188 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100189 @XmlRes
190 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100191 @XmlRes
fbarond1cd8c22024-11-26 10:13:36 -0800192 public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;;
fbaronebc10c92024-09-03 12:51:41 -0700193 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100194 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
195 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100196 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100197 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100198 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
199 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100200 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100201 @XmlRes
202 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000203 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100204 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000205 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100206 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000207 @XmlRes
208 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
209 @XmlRes
210 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
211 @XmlRes
212 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
213 @XmlRes
214 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500215
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700216
217 /**
218 * Fixed landscape mode is the landscape on the phones.
219 */
fbarond1cd8c22024-11-26 10:13:36 -0800220 public boolean isFixedLandscape = false;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700221 private LauncherPrefChangeListener mLandscapeModePreferenceListener;
222
Tracy Zhou7df93d22020-01-27 13:44:06 -0800223 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800224 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700225 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100226 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700227
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000228 /**
229 * An immutable list of supported profiles.
230 */
231 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700232
Sunny Goyal6f866092016-03-17 17:04:15 -0700233 public Point defaultWallpaperSize;
234
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700235 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700236
Sunny Goyalf633ef52018-03-13 09:57:05 -0700237 @VisibleForTesting
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700238 public InvariantDeviceProfile() {
239 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700240
Sunny Goyalbbf01842015-10-08 07:41:15 -0700241 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700242 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700243 String gridName = getCurrentGridName(context);
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800244 initGrid(context, gridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700245
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700246 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100247 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000248 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700249 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
250 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100251 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700252 }
253 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700254 if (Flags.oneGridSpecs()) {
255 mLandscapeModePreferenceListener = (String s) -> {
fbarond1cd8c22024-11-26 10:13:36 -0800256 if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
257 MAIN_EXECUTOR.execute(() -> {
258 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
259 onConfigChanged(context.getApplicationContext());
260 Trace.endSection();
261 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700262 }
263 };
264 LauncherPrefs.INSTANCE.get(context).addListener(
265 mLandscapeModePreferenceListener,
266 FIXED_LANDSCAPE_MODE
267 );
268 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700269 }
270
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700271 /**
272 * This constructor should NOT have any monitors by design.
273 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800274 public InvariantDeviceProfile(Context context, String gridName) {
275 String newName = initGrid(context, gridName);
276 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000277 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800278 }
279 }
280
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800282 * This constructor should NOT have any monitors by design.
283 */
284 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700285 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100286 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700287 String gridName = getCurrentGridName(context);
288
289 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000290 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700291 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700292 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000293 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700294 getPredefinedDeviceProfiles(
295 context,
296 gridName,
297 defaultInfo,
298 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800299 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700300 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000301 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700302
Alex Chau661f02d2022-06-07 14:03:43 +0100303 Context displayContext = context.createDisplayContext(display);
304 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700305 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700306 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000307 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700308 getPredefinedDeviceProfiles(
309 context,
310 gridName,
311 myInfo,
312 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800313 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700314 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000315 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700316
317 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
318 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100319 result.iconSizes[INDEX_DEFAULT] =
320 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
321 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700322 result.iconSizes[i] = Math.min(
323 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000324 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700325
Thales Lima83bedbf2021-10-05 17:47:39 +0100326 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
327 COUNT_SIZES);
328 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
329 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500330
Federico Baron56307d22024-11-06 18:48:48 +0000331 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800332 }
333
Sunny Goyal10fa0162024-04-21 00:13:35 -0700334 @Override
335 public void close() {
336 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700337 if (mLandscapeModePreferenceListener != null) {
338 LauncherPrefs.INSTANCE.executeIfCreated(
339 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
340 );
341 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700342 }
343
Tracy Zhou42255d22020-03-13 00:38:11 -0700344 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000345 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700346 }
347
Sunny Goyaleff44f32019-01-09 17:29:49 -0800348 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700349 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700350 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
351 context,
352 gridName,
353 displayInfo,
354 RestoreDbTask.isPending(context),
355 FIXED_LANDSCAPE_MODE.get(context)
356 );
fbaronebc10c92024-09-03 12:51:41 -0700357
358 // Filter out options that don't have the same number of columns as the grid
359 DeviceGridState deviceGridState = new DeviceGridState(context);
360 List<DisplayOption> allOptionsFilteredByColCount =
361 filterByColumnCount(allOptions, deviceGridState.getColumns());
362
Sunny Goyal19ff7282021-04-22 10:12:54 -0700363 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700364 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700365 ? new ArrayList<>(allOptions)
366 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000367 displayInfo.getDeviceType());
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800368
369 if (!displayOption.grid.name.equals(gridName)) {
370 LauncherPrefs.get(context).put(GRID_NAME, displayOption.grid.name);
371 }
372
Federico Baron56307d22024-11-06 18:48:48 +0000373 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700374 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800375 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700376
fbaronebc10c92024-09-03 12:51:41 -0700377 private List<DisplayOption> filterByColumnCount(
378 List<DisplayOption> allOptions, int numColumns) {
379 return allOptions.stream().filter(
380 option -> option.grid.numColumns == numColumns).toList();
381 }
382
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700383 /**
384 * @deprecated This is a temporary solution because on the backup and restore case we modify the
385 * IDP, this resets it. b/332974074
386 */
387 @Deprecated
388 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700389 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700390 }
391
Thales Limab67bfa72022-11-02 15:30:11 +0000392 @VisibleForTesting
393 public static String getDefaultGridName(Context context) {
394 return new InvariantDeviceProfile().initGrid(context, null);
395 }
396
Federico Baron56307d22024-11-06 18:48:48 +0000397 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700398 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700399 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000400 numRows = closestProfile.numRows;
401 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000402 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000403 dbFile = closestProfile.dbFile;
404 defaultLayoutId = closestProfile.defaultLayoutId;
405 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300406
Sunny Goyalae190ff2020-04-14 00:19:01 +0000407 numFolderRows = closestProfile.numFolderRows;
408 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300409 folderStyle = closestProfile.folderStyle;
410
Thales Limad852d652023-01-17 14:01:13 +0000411 cellStyle = closestProfile.cellStyle;
412
Jon Mirandae126d722021-02-25 10:45:20 -0500413 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400414 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100415 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800416 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100417 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100418 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100419 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100420 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100421 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100422 hotseatSpecsId = closestProfile.mHotseatSpecsId;
423 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000424 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
425 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
426 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
427 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300428 numAllAppsRowsForCellHeightCalculation =
429 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000430 this.deviceType = displayInfo.getDeviceType();
431 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000432
Vinit Nayakc7293172022-07-18 16:41:50 -0700433 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
434
Thales Lima83bedbf2021-10-05 17:47:39 +0100435 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100436 float maxIconSize = iconSize[0];
437 for (int i = 1; i < iconSize.length; i++) {
438 maxIconSize = Math.max(maxIconSize, iconSize[i]);
439 }
440 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000441 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
442
Thales Lima83bedbf2021-10-05 17:47:39 +0100443 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700444
Thales Lima83bedbf2021-10-05 17:47:39 +0100445 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100446
Thales Lima83bedbf2021-10-05 17:47:39 +0100447 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100448
Thales Limad90faab2021-09-21 17:18:47 +0100449 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100450
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000452 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700453 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100454 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
455 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700456
Thales Limae9273ea2023-01-26 12:33:52 +0000457 allAppsStyle = closestProfile.allAppsStyle;
458
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300460
Alex Chau1c883d82021-12-01 18:43:10 +0000461 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700462 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500463
Thales Limab7ef5692022-03-10 10:32:36 +0000464 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000465 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
466 allAppsIconSize = displayOption.allAppsIconSizes;
467 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000468
Thales Lima11af7bc2022-08-12 15:24:54 +0100469 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000470
Jon Miranda9c478b62023-03-23 21:38:49 -0700471 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
472
Jon Miranda04f05102023-04-04 12:16:31 -0700473 startAlignTaskbar = displayOption.startAlignTaskbar;
474
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700475 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800476 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700477
Sunny Goyalae190ff2020-04-14 00:19:01 +0000478 // If the partner customization apk contains any grid overrides, apply them
479 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700480 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700481
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000482 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700483 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700484 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700485 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000486 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000487 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000488 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700489 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000490 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700491
Sunny Goyal19ff7282021-04-22 10:12:54 -0700492 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
493 int displayWidth = bounds.bounds.width();
494 int displayHeight = bounds.bounds.height();
495 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700496
Sunny Goyal19ff7282021-04-22 10:12:54 -0700497 // We need to ensure that there is enough extra space in the wallpaper
498 // for the intended parallax effects
499 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300500 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
501 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700502 ? 2
503 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
504 defaultWallpaperSize.x =
505 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700506 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000507 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700508
Thales Lima6a590062022-11-22 15:52:49 +0000509 int numMinShownHotseatIconsForTablet = supportedProfiles
510 .stream()
511 .filter(deviceProfile -> deviceProfile.isTablet)
512 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
513 .min()
514 .orElse(0);
515
516 supportedProfiles
517 .stream()
518 .filter(deviceProfile -> deviceProfile.isTablet)
519 .forEach(deviceProfile -> {
520 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
521 deviceProfile.recalculateHotseatWidthAndBorderSpace();
522 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700523 }
524
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700525 public void addOnChangeListener(OnIDPChangeListener listener) {
526 mChangeListeners.add(listener);
527 }
528
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800529 public void removeOnChangeListener(OnIDPChangeListener listener) {
530 mChangeListeners.remove(listener);
531 }
532
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700533 /**
534 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
535 * migration.
536 */
537 public void setCurrentGrid(Context context, String newGridName) {
538 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700539 MAIN_EXECUTOR.execute(() -> {
540 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
541 onConfigChanged(context.getApplicationContext());
542 Trace.endSection();
543 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800544 }
545
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700546 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700547 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000548 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
549 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700550 }
551
Pat Manning24cec692023-10-13 10:36:57 +0000552 /** Updates IDP using the provided context. Notifies listeners of change. */
553 @VisibleForTesting
554 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700555 Object[] oldState = toModelState();
556
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700557 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700558 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700559 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700560
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700561 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700562 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700563 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700564 }
565 }
566
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700567 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
568 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
569 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800570 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700571 }
572
573 private static List<DisplayOption> getPredefinedDeviceProfiles(
574 Context context,
575 String gridName,
576 Info displayInfo,
577 boolean allowDisabledGrid,
578 boolean isFixedLandscapeMode
579 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800580 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100581
Alex Chau1c883d82021-12-01 18:43:10 +0000582 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700583 final int depth = parser.getDepth();
584 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700585 while (((type = parser.next()) != XmlPullParser.END_TAG ||
586 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800587 if ((type == XmlPullParser.START_TAG)
588 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000589 GridOption gridOption = new GridOption(
590 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700591 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
592 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100593 final int displayDepth = parser.getDepth();
594 while (((type = parser.next()) != XmlPullParser.END_TAG
595 || parser.getDepth() > displayDepth)
596 && type != XmlPullParser.END_DOCUMENT) {
597 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
598 parser.getName())) {
599 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100600 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100601 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800602 }
603 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700604 }
605 }
sfufa@google.comde013292021-09-21 18:22:44 -0700606 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700607 throw new RuntimeException(e);
608 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000609 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800610 if (!TextUtils.isEmpty(gridName)) {
611 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000612 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
613 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000614 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800615 }
616 }
617 }
fbaronebc10c92024-09-03 12:51:41 -0700618 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
619 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000620 for (DisplayOption option : profiles) {
621 if (option.canBeDefault) {
622 filteredProfiles.add(option);
623 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800624 }
fbaronebc10c92024-09-03 12:51:41 -0700625 } else if (filteredProfiles.isEmpty()) {
626 // In this case we had a grid selected but we couldn't find it.
627 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800628 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000629 if (filteredProfiles.isEmpty()) {
630 throw new RuntimeException("No display option with canBeDefault=true");
631 }
632 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700633 }
634
Thales Lima7ec83822021-08-05 13:32:10 +0100635 /**
fbarond1cd8c22024-11-26 10:13:36 -0800636 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
637 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700638 *
fbarond1cd8c22024-11-26 10:13:36 -0800639 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700640 */
fbarond1cd8c22024-11-26 10:13:36 -0800641 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000642 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800643 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700644
645 try (XmlResourceParser parser = resourceHelper.getXml()) {
646 final int depth = parser.getDepth();
647 int type;
648 while (((type = parser.next()) != XmlPullParser.END_TAG
649 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
650 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800651 && "GridSize".equals(parser.getName())) {
652 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700653 }
654 }
655 } catch (IOException | XmlPullParserException e) {
656 throw new RuntimeException(e);
657 }
658
fbaron49358342024-11-22 17:38:56 -0800659 // Finds the min width and height in dp for all displays.
660 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
661
fbarond1cd8c22024-11-26 10:13:36 -0800662 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700663 }
664
665 /**
fbarond1cd8c22024-11-26 10:13:36 -0800666 * @return the biggest grid size that fits the display dimensions.
667 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700668 */
fbarond1cd8c22024-11-26 10:13:36 -0800669 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800670 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800671 GridSize selectedGridSize = null;
672 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800673 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800674 if (selectedGridSize == null
675 || (selectedGridSize.mNumColumns <= item.mNumColumns
676 && selectedGridSize.mNumRows <= item.mNumRows)) {
677 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800678 }
679 }
680 }
fbarond1cd8c22024-11-26 10:13:36 -0800681 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800682 }
683
684 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaron9ce45ba2024-12-03 02:17:00 -0800685 int minDisplayWidthDp = Integer.MAX_VALUE;
686 int minDisplayHeightDp = Integer.MAX_VALUE;
687 for (CachedDisplayInfo display: displayInfo.getAllDisplays()) {
688 minDisplayWidthDp = Math.min(minDisplayWidthDp,
689 (int) dpiFromPx(display.size.x, DisplayMetrics.DENSITY_DEVICE_STABLE));
690 minDisplayHeightDp = Math.min(minDisplayHeightDp,
691 (int) dpiFromPx(display.size.y, DisplayMetrics.DENSITY_DEVICE_STABLE));
fbaronebc10c92024-09-03 12:51:41 -0700692 }
fbaron9ce45ba2024-12-03 02:17:00 -0800693 return new int[]{minDisplayWidthDp, minDisplayHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700694 }
695
696 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000697 * Returns the GridOption associated to the given file name or null if the fileName is not
698 * supported.
699 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
700 */
701 public GridOption getGridOptionFromFileName(Context context, String fileName) {
702 return parseAllGridOptions(context).stream()
703 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
704 .findFirst()
705 .orElse(null);
706 }
707
708 /**
709 * Returns the name of the given size on the current device or empty string if the size is not
710 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
711 * (Note: the name of the grid can be different for the same grid size depending of
712 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000713 */
714 public String getGridNameFromSize(Context context, Point size) {
715 return parseAllGridOptions(context).stream()
716 .filter(gridOption -> gridOption.numColumns == size.x
717 && gridOption.numRows == size.y)
718 .map(gridOption -> gridOption.name)
719 .findFirst()
720 .orElse("");
721 }
722
723 /**
724 * Returns the grid option for the given gridName on the current device (Note: the gridOption
725 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
726 */
727 public GridOption getGridOptionFromName(Context context, String gridName) {
728 return parseAllGridOptions(context).stream()
729 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
730 .findFirst()
731 .orElse(null);
732 }
733
734 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100735 * @return all the grid options that can be shown on the device
736 */
737 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000738 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700739 .stream()
740 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800741 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700742 .collect(Collectors.toList());
743 }
744
745 /**
746 * @return all the grid options that can be shown on the device
747 */
Federico Baron56307d22024-11-06 18:48:48 +0000748 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100749 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000750 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100751 final int depth = parser.getDepth();
752 int type;
753 while (((type = parser.next()) != XmlPullParser.END_TAG
754 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
755 if ((type == XmlPullParser.START_TAG)
756 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000757 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100758 }
759 }
760 } catch (IOException | XmlPullParserException e) {
761 Log.e(TAG, "Error parsing device profile", e);
762 return Collections.emptyList();
763 }
764 return result;
765 }
766
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700767 private int getLauncherIconDensity(int requiredSize) {
768 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700769 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700770 DisplayMetrics.DENSITY_LOW,
771 DisplayMetrics.DENSITY_MEDIUM,
772 DisplayMetrics.DENSITY_TV,
773 DisplayMetrics.DENSITY_HIGH,
774 DisplayMetrics.DENSITY_XHIGH,
775 DisplayMetrics.DENSITY_XXHIGH,
776 DisplayMetrics.DENSITY_XXXHIGH
777 };
778
779 int density = DisplayMetrics.DENSITY_XXXHIGH;
780 for (int i = densityBuckets.length - 1; i >= 0; i--) {
781 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
782 / DisplayMetrics.DENSITY_DEFAULT;
783 if (expectedSize >= requiredSize) {
784 density = densityBuckets[i];
785 }
786 }
787
788 return density;
789 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700790
Adam Cohen2e6da152015-05-06 11:42:25 -0700791 /**
792 * Apply any Partner customization grid overrides.
793 *
794 * Currently we support: all apps row / column count.
795 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700796 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
797 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800798 if (p == null) {
799 return;
800 }
801 try {
802 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
803 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
804 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
805
806 if (numRows > 0 && numColumns > 0) {
807 this.numRows = numRows;
808 this.numColumns = numColumns;
809 }
810 if (iconSizePx > 0) {
811 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
812 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
813 }
814 } catch (Resources.NotFoundException ex) {
815 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700816 }
817 }
818
Sunny Goyal415f1732018-11-29 10:33:47 -0800819 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700820 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700821 }
822
Sunny Goyal19ff7282021-04-22 10:12:54 -0700823 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700824 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700825 int minWidthPx = Integer.MAX_VALUE;
826 int minHeightPx = Integer.MAX_VALUE;
827 for (WindowBounds bounds : displayInfo.supportedBounds) {
828 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000829 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700830 // For split displays, take half width per page
831 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
832 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700833
Sunny Goyal19ff7282021-04-22 10:12:54 -0700834 } else if (!isTablet && bounds.isLandscape()) {
835 // We will use transposed layout in this case
836 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
837 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
838 } else {
839 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
840 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
841 }
842 }
843
Thales Lima425f6822022-05-10 13:44:58 -0300844 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
845 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700846
847 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700848 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700849 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
850 dist(width, height, b.minWidthDps, b.minHeightDps)));
851
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700852 DisplayOption closestPoint = points.get(0);
853 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700854 float weights = 0;
855
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700856 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
857 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700858 }
859
860 DisplayOption out = new DisplayOption(closestOption);
861 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700862 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700863 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
864 weights += w;
865 out.add(new DisplayOption().add(p).multiply(w));
866 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700867 out.multiply(1.0f / weights);
868
Thales Lima6e0005a2021-10-27 15:53:41 +0100869 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700870 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100871 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
872 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700873 }
874
875 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700876 }
877
Sunny Goyal27835952017-01-13 12:15:53 -0800878 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000879 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
880 Rect bounds = windowManagerProxy.getCurrentBounds(context);
881 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700882
Alex Chauc09a98a2023-11-14 12:51:42 +0000883 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400884 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700885
Sunny Goyal187b16c2022-03-01 16:53:23 -0800886 /**
887 * Returns the device profile matching the provided screen configuration
888 */
889 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700890 DeviceProfile bestMatch = supportedProfiles.get(0);
891 float minDiff = Float.MAX_VALUE;
892
893 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400894 float diff = Math.abs(profile.widthPx - screenWidth)
895 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700896 if (diff < minDiff) {
897 minDiff = diff;
898 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800899 } else if (diff == minDiff && profile.rotationHint == rotation) {
900 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700901 }
902 }
903 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800904 }
905
Sunny Goyal415f1732018-11-29 10:33:47 -0800906 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700907 float d = dist(x0, y0, x1, y1);
908 if (Float.compare(d, 0f) == 0) {
909 return Float.POSITIVE_INFINITY;
910 }
911 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
912 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700913
914 /**
915 * As a ratio of screen height, the total distance we want the parallax effect to span
916 * horizontally
917 */
918 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
919 float aspectRatio = width / (float) height;
920
921 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
922 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
923 // We will use these two data points to extrapolate how much the wallpaper parallax effect
924 // to span (ie travel) at any aspect ratio:
925
sfufa@google.comde013292021-09-21 18:22:44 -0700926 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
927 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700928 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
929 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
930
931 // To find out the desired width at different aspect ratios, we use the following two
932 // formulas, where the coefficient on x is the aspect ratio (width/height):
933 // (16/10)x + y = 1.5
934 // (10/16)x + y = 1.2
935 // We solve for x and y and end up with a final formula:
936 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700937 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
938 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700939 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
940 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
941 return x * aspectRatio + y;
942 }
943
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700944 public interface OnIDPChangeListener {
945
Sunny Goyalb47172b2021-05-03 19:59:51 -0700946 /**
947 * Called when the device provide changes
948 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700949 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700950 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800951
952
Sunny Goyaleff44f32019-01-09 17:29:49 -0800953 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800954
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800955 public static final String TAG_NAME = "grid-option";
956
Alex Chau1c883d82021-12-01 18:43:10 +0000957 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
958 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
959 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
960 private static final int DEVICE_CATEGORY_ALL =
961 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
962
Thales Lima11af7bc2022-08-12 15:24:54 +0100963 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
964 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
965 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
966 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
967 private static final int DONT_INLINE_QSB = 0;
968
Sunny Goyaleff44f32019-01-09 17:29:49 -0800969 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700970 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800971 public final int numRows;
972 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000973 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700974 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800975
Thales Lima1faa4ed2023-12-01 16:48:19 +0000976 private final int[] numFolderRows = new int[COUNT_SIZES];
977 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300978 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000979 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800980
Thales Limae9273ea2023-01-26 12:33:52 +0000981 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700982 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300983 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700984 private final int numDatabaseAllAppsColumns;
985 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700986 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100987
Thales Lima11af7bc2022-08-12 15:24:54 +0100988 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
989
Thales Limab35faed2022-09-05 16:30:01 -0300990 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800991 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000992
Sunny Goyal415f1732018-11-29 10:33:47 -0800993 private final int defaultLayoutId;
994 private final int demoModeLayoutId;
995
Jon Mirandae126d722021-02-25 10:45:20 -0500996 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -0800997 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400998 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100999 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001000 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001001 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001002 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001003 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001004 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001005 private final int mHotseatSpecsId;
1006 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001007 private final int mWorkspaceCellSpecsId;
1008 private final int mWorkspaceCellSpecsTwoPanelId;
1009 private final int mAllAppsCellSpecsId;
1010 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001011 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001012 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001013 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001014
Federico Baron56307d22024-11-06 18:48:48 +00001015 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001016 TypedArray a = context.obtainStyledAttributes(
1017 attrs, R.styleable.GridDisplayOption);
1018 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001019 title = a.getString(R.styleable.GridDisplayOption_title);
1020 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1021 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001022 mGridSizeSpecsId = a.getResourceId(
1023 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001024 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001025 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1026 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1027 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1028 numColumns = gridSize.mNumColumns;
1029 numRows = gridSize.mNumRows;
1030 dbFile = gridSize.mDbFile;
1031 defaultLayoutId = gridSize.mDefaultLayoutId;
1032 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001033 } else {
1034 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001035 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001036 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001037 defaultLayoutId = a.getResourceId(
1038 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1039 demoModeLayoutId = a.getResourceId(
1040 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001041 }
1042
Alex Chau9fee3fd2021-12-01 18:43:10 +00001043 numSearchContainerColumns = a.getInt(
1044 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001045
Thales Limae9273ea2023-01-26 12:33:52 +00001046 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1047 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001048 numAllAppsColumns = a.getInt(
1049 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1050 numDatabaseAllAppsColumns = a.getInt(
1051 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1052
1053 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001054 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001055 numDatabaseHotseatIcons = a.getInt(
1056 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001057
Vinit Nayakc7293172022-07-18 16:41:50 -07001058 inlineNavButtonsEndSpacing =
1059 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001060 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001061
Thales Lima1faa4ed2023-12-01 16:48:19 +00001062 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001063 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001064 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001065 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001066
Thales Lima1faa4ed2023-12-01 16:48:19 +00001067 if (FeatureFlags.enableResponsiveWorkspace()) {
1068 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1069 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1070 numFolderRows[INDEX_DEFAULT]);
1071 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1072 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1073 numFolderColumns[INDEX_DEFAULT]);
1074 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1075 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1076 numFolderRows[INDEX_DEFAULT]);
1077 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1078 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1079 numFolderColumns[INDEX_DEFAULT]);
1080 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1081 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1082 numFolderRows[INDEX_DEFAULT]);
1083 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1084 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1085 numFolderColumns[INDEX_DEFAULT]);
1086 } else {
1087 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1088 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1089 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1090 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1091 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1092 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1093 }
1094
Thales Limab35faed2022-09-05 16:30:01 -03001095 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1096 INVALID_RESOURCE_HANDLE);
1097
Thales Limad852d652023-01-17 14:01:13 +00001098 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1099 R.style.CellStyleDefault);
1100
Jon Mirandae126d722021-02-25 10:45:20 -05001101 isScalable = a.getBoolean(
1102 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001103 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001104 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001105
Thales Limaca31b612023-09-14 14:25:26 +01001106 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001107 mWorkspaceSpecsId = a.getResourceId(
1108 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001109 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1110 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001111 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001112 mAllAppsSpecsId = a.getResourceId(
1113 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001114 mAllAppsSpecsTwoPanelId = a.getResourceId(
1115 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001116 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001117 mFolderSpecsId = a.getResourceId(
1118 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001119 mFolderSpecsTwoPanelId = a.getResourceId(
1120 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001121 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001122 mHotseatSpecsId = a.getResourceId(
1123 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1124 mHotseatSpecsTwoPanelId = a.getResourceId(
1125 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001126 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001127 mWorkspaceCellSpecsId = a.getResourceId(
1128 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1129 INVALID_RESOURCE_HANDLE);
1130 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1131 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001132 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001133 mAllAppsCellSpecsId = a.getResourceId(
1134 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1135 INVALID_RESOURCE_HANDLE);
1136 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1137 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001138 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001139 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1140 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1141 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001142 } else {
1143 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001144 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001145 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001146 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001147 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001148 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001149 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1150 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001151 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1152 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1153 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1154 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001155 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001156 }
1157
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001158 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001159 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001160
Thales Lima11af7bc2022-08-12 15:24:54 +01001161 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1162 DONT_INLINE_QSB);
1163 inlineQsb[INDEX_DEFAULT] =
1164 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1165 inlineQsb[INDEX_LANDSCAPE] =
1166 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1167 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1168 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1169 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1170 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1171 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1172 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1173
Sunny Goyal415f1732018-11-29 10:33:47 -08001174 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001175 }
1176
1177 public boolean isEnabled(@DeviceType int deviceType) {
1178 switch (deviceType) {
1179 case TYPE_PHONE:
1180 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1181 case TYPE_TABLET:
1182 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1183 case TYPE_MULTI_DISPLAY:
1184 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1185 == DEVICE_CATEGORY_MULTI_DISPLAY;
1186 default:
1187 return false;
1188 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001189 }
fbaronebc10c92024-09-03 12:51:41 -07001190
fbaron6c91ef92024-11-12 22:22:43 -08001191 /**
1192 * Returns true if the grid option should be used given the flags that are toggled on/off.
1193 */
fbaronc1b68f42024-11-08 18:10:46 -08001194 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001195 if (deviceType == TYPE_TABLET) {
1196 return Flags.oneGridRotationHandling() == mIsDualGrid;
1197 }
fbaronc1b68f42024-11-08 18:10:46 -08001198
fbaron6c91ef92024-11-12 22:22:43 -08001199 // Here we return true if fixed landscape mode should be on.
1200 if (mIsFixedLandscape || isFixedLandscape) {
1201 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001202 }
1203
fbaron6c91ef92024-11-12 22:22:43 -08001204 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001205 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001206 return Flags.oneGridSpecs();
1207 }
1208
1209 // Here we return true if we want to show the old grids.
1210 if (mIsOldGrid) {
1211 return !Flags.oneGridSpecs();
1212 }
1213
1214 return true;
fbaron49f7df02024-11-05 16:15:19 -08001215 }
fbaronebc10c92024-09-03 12:51:41 -07001216 }
1217
fbarond1cd8c22024-11-26 10:13:36 -08001218 public static final class GridSize {
1219 final int mNumRows;
1220 final int mNumColumns;
1221 final float mMinDeviceWidthDp;
1222 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001223 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001224 final int mDefaultLayoutId;
1225 final int mDemoModeLayoutId;
1226
fbaronebc10c92024-09-03 12:51:41 -07001227
fbarond1cd8c22024-11-26 10:13:36 -08001228 GridSize(Context context, AttributeSet attrs) {
1229 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001230
fbarond1cd8c22024-11-26 10:13:36 -08001231 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1232 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1233 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1234 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1235 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001236 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001237 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001238 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001239 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001240
1241 a.recycle();
1242 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001243 }
1244
Sunny Goyal19ff7282021-04-22 10:12:54 -07001245 @VisibleForTesting
1246 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001247 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001248
Sunny Goyal415f1732018-11-29 10:33:47 -08001249 private final float minWidthDps;
1250 private final float minHeightDps;
1251 private final boolean canBeDefault;
1252
Thales Lima83bedbf2021-10-05 17:47:39 +01001253 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001254
Thales Lima78d00ad2021-09-30 11:29:06 +01001255 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001256 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001257 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1258 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001259
Thales Lima78d00ad2021-09-30 11:29:06 +01001260 private final float[] iconSizes = new float[COUNT_SIZES];
1261 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001262
Thales Limab7ef5692022-03-10 10:32:36 +00001263 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001264 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1265 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1266 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1267
Jon Miranda9c478b62023-03-23 21:38:49 -07001268 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1269
Jon Miranda04f05102023-04-04 12:16:31 -07001270 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1271
Thales Lima1de4d552021-10-13 16:13:25 +01001272 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001273 this.grid = grid;
1274
Jon Miranda9c478b62023-03-23 21:38:49 -07001275 Resources res = context.getResources();
1276
Thales Lima1de4d552021-10-13 16:13:25 +01001277 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001278
Sunny Goyal415f1732018-11-29 10:33:47 -08001279 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1280 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001281
Thales Lima1de4d552021-10-13 16:13:25 +01001282 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001283
Thales Lima83bedbf2021-10-05 17:47:39 +01001284 float x;
1285 float y;
1286
Thales Lima85c942f2021-12-31 13:04:20 +00001287 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1288 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001289 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001290
1291 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1292 minCellSize[INDEX_DEFAULT].x);
1293 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1294 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001295 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001296
Thales Lima85c942f2021-12-31 13:04:20 +00001297 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001298 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001299 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001300 minCellSize[INDEX_DEFAULT].y);
1301 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1302
Thales Lima85c942f2021-12-31 13:04:20 +00001303 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001304 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001305 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001306 minCellSize[INDEX_DEFAULT].y);
1307 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001308
Thales Lima85c942f2021-12-31 13:04:20 +00001309 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001310 float borderSpaceLandscape = a.getFloat(
1311 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001312 float borderSpaceTwoPanelPortrait = a.getFloat(
1313 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1314 float borderSpaceTwoPanelLandscape = a.getFloat(
1315 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001316
Thales Lima85c942f2021-12-31 13:04:20 +00001317 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1318 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001319 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001320
1321 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1322 borderSpaceLandscape);
1323 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1324 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001325 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1326
1327 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001328 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1329 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001330 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001331 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1332 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001333 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1334
1335 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001336 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1337 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001338 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001339 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1340 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001341 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1342
Thales Limab7ef5692022-03-10 10:32:36 +00001343 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1344 minCellSize[INDEX_DEFAULT].x);
1345 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1346 minCellSize[INDEX_DEFAULT].y);
1347 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1348
1349 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1350 allAppsCellSize[INDEX_DEFAULT].x);
1351 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1352 allAppsCellSize[INDEX_DEFAULT].y);
1353 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1354
1355 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1356 allAppsCellSize[INDEX_DEFAULT].x);
1357 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1358 allAppsCellSize[INDEX_DEFAULT].y);
1359 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1360
1361 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1362 allAppsCellSize[INDEX_DEFAULT].x);
1363 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1364 allAppsCellSize[INDEX_DEFAULT].y);
1365 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1366
Thales Lima080d8902022-03-28 15:30:29 +01001367 float allAppsBorderSpace = a.getFloat(
1368 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1369 float allAppsBorderSpaceLandscape = a.getFloat(
1370 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1371 allAppsBorderSpace);
1372 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001373 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001374 allAppsBorderSpace);
1375 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001376 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001377 allAppsBorderSpace);
1378
1379 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1380 allAppsBorderSpace);
1381 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1382 allAppsBorderSpace);
1383 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1384
1385 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1386 allAppsBorderSpaceLandscape);
1387 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1388 allAppsBorderSpaceLandscape);
1389 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1390
1391 x = a.getFloat(
1392 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1393 allAppsBorderSpaceTwoPanelPortrait);
1394 y = a.getFloat(
1395 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1396 allAppsBorderSpaceTwoPanelPortrait);
1397 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1398
1399 x = a.getFloat(
1400 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1401 allAppsBorderSpaceTwoPanelLandscape);
1402 y = a.getFloat(
1403 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1404 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001405 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001406
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001407 iconSizes[INDEX_DEFAULT] =
1408 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1409 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001410 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001411 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001412 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001413 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001414 iconSizes[INDEX_DEFAULT]);
1415 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001416 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001417 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001418
Thales Limabb7d3882021-12-22 12:56:29 +00001419 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1420 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001421 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1422 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001423 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001424 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1425 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1426 allAppsIconSizes[INDEX_DEFAULT]);
1427 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1428 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1429 allAppsIconSizes[INDEX_DEFAULT]);
1430
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001431 textSizes[INDEX_DEFAULT] =
1432 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1433 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001434 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001435 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001436 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001437 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001438 textSizes[INDEX_DEFAULT]);
1439 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001440 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001441 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001442
Thales Limabb7d3882021-12-22 12:56:29 +00001443 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1444 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1445 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1446 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1447 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1448 allAppsIconTextSizes[INDEX_DEFAULT]);
1449 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1450 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1451 allAppsIconTextSizes[INDEX_DEFAULT]);
1452
Thales Lima83bedbf2021-10-05 17:47:39 +01001453 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1454 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001455 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1456 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1457 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001458 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001459 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001460 horizontalMargin[INDEX_DEFAULT]);
1461 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001462 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001463 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001464
Thales Limab8c05952022-05-23 16:58:38 +01001465 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1466 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001467 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001468 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1469 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1470 hotseatBarBottomSpace[INDEX_DEFAULT]);
1471 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1472 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1473 hotseatBarBottomSpace[INDEX_DEFAULT]);
1474 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1475 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1476 hotseatBarBottomSpace[INDEX_DEFAULT]);
1477
1478 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1479 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001480 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001481 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1482 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1483 hotseatQsbSpace[INDEX_DEFAULT]);
1484 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1485 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1486 hotseatQsbSpace[INDEX_DEFAULT]);
1487 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1488 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1489 hotseatQsbSpace[INDEX_DEFAULT]);
1490
Jon Miranda9c478b62023-03-23 21:38:49 -07001491 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1492 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1493 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1494 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1495 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1496 transientTaskbarIconSize[INDEX_DEFAULT]);
1497 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1498 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1499 transientTaskbarIconSize[INDEX_DEFAULT]);
1500 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1501 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001502 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001503
Jon Miranda04f05102023-04-04 12:16:31 -07001504 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1505 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1506 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1507 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1508 startAlignTaskbar[INDEX_DEFAULT]);
1509 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1510 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1511 startAlignTaskbar[INDEX_LANDSCAPE]);
1512 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1513 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1514 startAlignTaskbar[INDEX_DEFAULT]);
1515
Sunny Goyal415f1732018-11-29 10:33:47 -08001516 a.recycle();
1517 }
1518
1519 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001520 this(null);
1521 }
1522
1523 DisplayOption(GridOption grid) {
1524 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001525 minWidthDps = 0;
1526 minHeightDps = 0;
1527 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001528 for (int i = 0; i < COUNT_SIZES; i++) {
1529 iconSizes[i] = 0;
1530 textSizes[i] = 0;
1531 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001532 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001533 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001534 allAppsIconSizes[i] = 0;
1535 allAppsIconTextSizes[i] = 0;
1536 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001537 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001538 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001539 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001540 }
1541
1542 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001543 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001544 iconSizes[i] *= w;
1545 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001546 borderSpaces[i].x *= w;
1547 borderSpaces[i].y *= w;
1548 minCellSize[i].x *= w;
1549 minCellSize[i].y *= w;
1550 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001551 hotseatBarBottomSpace[i] *= w;
1552 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001553 allAppsCellSize[i].x *= w;
1554 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001555 allAppsIconSizes[i] *= w;
1556 allAppsIconTextSizes[i] *= w;
1557 allAppsBorderSpaces[i].x *= w;
1558 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001559 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001560 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001561
Sunny Goyal415f1732018-11-29 10:33:47 -08001562 return this;
1563 }
1564
1565 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001566 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001567 iconSizes[i] += p.iconSizes[i];
1568 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001569 borderSpaces[i].x += p.borderSpaces[i].x;
1570 borderSpaces[i].y += p.borderSpaces[i].y;
1571 minCellSize[i].x += p.minCellSize[i].x;
1572 minCellSize[i].y += p.minCellSize[i].y;
1573 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001574 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1575 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001576 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1577 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001578 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1579 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1580 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1581 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001582 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001583 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001584 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001585
Sunny Goyal415f1732018-11-29 10:33:47 -08001586 return this;
1587 }
1588 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001589}