blob: 410f1305b507ae796a18403357b0c7327aef35dc [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);
244 String newGridName = initGrid(context, gridName);
245 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000246 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700247 }
248
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700249 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100250 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000251 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700252 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
253 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100254 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700255 }
256 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700257 if (Flags.oneGridSpecs()) {
258 mLandscapeModePreferenceListener = (String s) -> {
fbarond1cd8c22024-11-26 10:13:36 -0800259 if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
260 MAIN_EXECUTOR.execute(() -> {
261 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
262 onConfigChanged(context.getApplicationContext());
263 Trace.endSection();
264 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700265 }
266 };
267 LauncherPrefs.INSTANCE.get(context).addListener(
268 mLandscapeModePreferenceListener,
269 FIXED_LANDSCAPE_MODE
270 );
271 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700272 }
273
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700274 /**
275 * This constructor should NOT have any monitors by design.
276 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800277 public InvariantDeviceProfile(Context context, String gridName) {
278 String newName = initGrid(context, gridName);
279 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000280 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800281 }
282 }
283
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700284 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800285 * This constructor should NOT have any monitors by design.
286 */
287 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700288 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100289 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700290 String gridName = getCurrentGridName(context);
291
292 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000293 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700294 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700295 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000296 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700297 getPredefinedDeviceProfiles(
298 context,
299 gridName,
300 defaultInfo,
301 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800302 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700303 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000304 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700305
Alex Chau661f02d2022-06-07 14:03:43 +0100306 Context displayContext = context.createDisplayContext(display);
307 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700308 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700309 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000310 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700311 getPredefinedDeviceProfiles(
312 context,
313 gridName,
314 myInfo,
315 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800316 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700317 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000318 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700319
320 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
321 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100322 result.iconSizes[INDEX_DEFAULT] =
323 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
324 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700325 result.iconSizes[i] = Math.min(
326 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000327 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700328
Thales Lima83bedbf2021-10-05 17:47:39 +0100329 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
330 COUNT_SIZES);
331 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
332 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500333
Federico Baron56307d22024-11-06 18:48:48 +0000334 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800335 }
336
Sunny Goyal10fa0162024-04-21 00:13:35 -0700337 @Override
338 public void close() {
339 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700340 if (mLandscapeModePreferenceListener != null) {
341 LauncherPrefs.INSTANCE.executeIfCreated(
342 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
343 );
344 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700345 }
346
Tracy Zhou42255d22020-03-13 00:38:11 -0700347 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000348 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700349 }
350
Sunny Goyaleff44f32019-01-09 17:29:49 -0800351 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700352 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700353 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
354 context,
355 gridName,
356 displayInfo,
357 RestoreDbTask.isPending(context),
358 FIXED_LANDSCAPE_MODE.get(context)
359 );
fbaronebc10c92024-09-03 12:51:41 -0700360
361 // Filter out options that don't have the same number of columns as the grid
362 DeviceGridState deviceGridState = new DeviceGridState(context);
363 List<DisplayOption> allOptionsFilteredByColCount =
364 filterByColumnCount(allOptions, deviceGridState.getColumns());
365
Sunny Goyal19ff7282021-04-22 10:12:54 -0700366 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700367 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700368 ? new ArrayList<>(allOptions)
369 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000370 displayInfo.getDeviceType());
371 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700372 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800373 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700374
fbaronebc10c92024-09-03 12:51:41 -0700375 private List<DisplayOption> filterByColumnCount(
376 List<DisplayOption> allOptions, int numColumns) {
377 return allOptions.stream().filter(
378 option -> option.grid.numColumns == numColumns).toList();
379 }
380
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700381 /**
382 * @deprecated This is a temporary solution because on the backup and restore case we modify the
383 * IDP, this resets it. b/332974074
384 */
385 @Deprecated
386 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700387 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700388 }
389
Thales Limab67bfa72022-11-02 15:30:11 +0000390 @VisibleForTesting
391 public static String getDefaultGridName(Context context) {
392 return new InvariantDeviceProfile().initGrid(context, null);
393 }
394
Federico Baron56307d22024-11-06 18:48:48 +0000395 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700396 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700397 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000398 numRows = closestProfile.numRows;
399 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000400 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000401 dbFile = closestProfile.dbFile;
402 defaultLayoutId = closestProfile.defaultLayoutId;
403 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300404
Sunny Goyalae190ff2020-04-14 00:19:01 +0000405 numFolderRows = closestProfile.numFolderRows;
406 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300407 folderStyle = closestProfile.folderStyle;
408
Thales Limad852d652023-01-17 14:01:13 +0000409 cellStyle = closestProfile.cellStyle;
410
Jon Mirandae126d722021-02-25 10:45:20 -0500411 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400412 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100413 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800414 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100415 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100416 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100417 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100418 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100419 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100420 hotseatSpecsId = closestProfile.mHotseatSpecsId;
421 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000422 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
423 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
424 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
425 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300426 numAllAppsRowsForCellHeightCalculation =
427 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000428 this.deviceType = displayInfo.getDeviceType();
429 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000430
Vinit Nayakc7293172022-07-18 16:41:50 -0700431 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
432
Thales Lima83bedbf2021-10-05 17:47:39 +0100433 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100434 float maxIconSize = iconSize[0];
435 for (int i = 1; i < iconSize.length; i++) {
436 maxIconSize = Math.max(maxIconSize, iconSize[i]);
437 }
438 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000439 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
440
Thales Lima83bedbf2021-10-05 17:47:39 +0100441 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700442
Thales Lima83bedbf2021-10-05 17:47:39 +0100443 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100444
Thales Lima83bedbf2021-10-05 17:47:39 +0100445 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100446
Thales Limad90faab2021-09-21 17:18:47 +0100447 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100448
Sunny Goyal19ff7282021-04-22 10:12:54 -0700449 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000450 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100452 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
453 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700454
Thales Limae9273ea2023-01-26 12:33:52 +0000455 allAppsStyle = closestProfile.allAppsStyle;
456
Sunny Goyal19ff7282021-04-22 10:12:54 -0700457 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300458
Alex Chau1c883d82021-12-01 18:43:10 +0000459 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700460 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500461
Thales Limab7ef5692022-03-10 10:32:36 +0000462 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000463 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
464 allAppsIconSize = displayOption.allAppsIconSizes;
465 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000466
Thales Lima11af7bc2022-08-12 15:24:54 +0100467 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000468
Jon Miranda9c478b62023-03-23 21:38:49 -0700469 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
470
Jon Miranda04f05102023-04-04 12:16:31 -0700471 startAlignTaskbar = displayOption.startAlignTaskbar;
472
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700473 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800474 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700475
Sunny Goyalae190ff2020-04-14 00:19:01 +0000476 // If the partner customization apk contains any grid overrides, apply them
477 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700478 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700479
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000480 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700481 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700482 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700483 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000484 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000485 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000486 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700487 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000488 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700489
Sunny Goyal19ff7282021-04-22 10:12:54 -0700490 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
491 int displayWidth = bounds.bounds.width();
492 int displayHeight = bounds.bounds.height();
493 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700494
Sunny Goyal19ff7282021-04-22 10:12:54 -0700495 // We need to ensure that there is enough extra space in the wallpaper
496 // for the intended parallax effects
497 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300498 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
499 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700500 ? 2
501 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
502 defaultWallpaperSize.x =
503 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700504 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000505 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700506
Thales Lima6a590062022-11-22 15:52:49 +0000507 int numMinShownHotseatIconsForTablet = supportedProfiles
508 .stream()
509 .filter(deviceProfile -> deviceProfile.isTablet)
510 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
511 .min()
512 .orElse(0);
513
514 supportedProfiles
515 .stream()
516 .filter(deviceProfile -> deviceProfile.isTablet)
517 .forEach(deviceProfile -> {
518 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
519 deviceProfile.recalculateHotseatWidthAndBorderSpace();
520 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700521 }
522
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700523 public void addOnChangeListener(OnIDPChangeListener listener) {
524 mChangeListeners.add(listener);
525 }
526
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800527 public void removeOnChangeListener(OnIDPChangeListener listener) {
528 mChangeListeners.remove(listener);
529 }
530
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700531 /**
532 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
533 * migration.
534 */
535 public void setCurrentGrid(Context context, String newGridName) {
536 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700537 MAIN_EXECUTOR.execute(() -> {
538 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
539 onConfigChanged(context.getApplicationContext());
540 Trace.endSection();
541 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800542 }
543
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700544 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700545 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000546 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
547 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700548 }
549
Pat Manning24cec692023-10-13 10:36:57 +0000550 /** Updates IDP using the provided context. Notifies listeners of change. */
551 @VisibleForTesting
552 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700553 Object[] oldState = toModelState();
554
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700555 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700556 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700557 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700558
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700559 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700560 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700561 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700562 }
563 }
564
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700565 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
566 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
567 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800568 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700569 }
570
571 private static List<DisplayOption> getPredefinedDeviceProfiles(
572 Context context,
573 String gridName,
574 Info displayInfo,
575 boolean allowDisabledGrid,
576 boolean isFixedLandscapeMode
577 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800578 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100579
Alex Chau1c883d82021-12-01 18:43:10 +0000580 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700581 final int depth = parser.getDepth();
582 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700583 while (((type = parser.next()) != XmlPullParser.END_TAG ||
584 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800585 if ((type == XmlPullParser.START_TAG)
586 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000587 GridOption gridOption = new GridOption(
588 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700589 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
590 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100591 final int displayDepth = parser.getDepth();
592 while (((type = parser.next()) != XmlPullParser.END_TAG
593 || parser.getDepth() > displayDepth)
594 && type != XmlPullParser.END_DOCUMENT) {
595 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
596 parser.getName())) {
597 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100598 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100599 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800600 }
601 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700602 }
603 }
sfufa@google.comde013292021-09-21 18:22:44 -0700604 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700605 throw new RuntimeException(e);
606 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000607 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800608 if (!TextUtils.isEmpty(gridName)) {
609 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000610 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
611 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000612 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800613 }
614 }
615 }
fbaronebc10c92024-09-03 12:51:41 -0700616 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
617 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000618 for (DisplayOption option : profiles) {
619 if (option.canBeDefault) {
620 filteredProfiles.add(option);
621 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800622 }
fbaronebc10c92024-09-03 12:51:41 -0700623 } else if (filteredProfiles.isEmpty()) {
624 // In this case we had a grid selected but we couldn't find it.
625 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800626 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000627 if (filteredProfiles.isEmpty()) {
628 throw new RuntimeException("No display option with canBeDefault=true");
629 }
630 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700631 }
632
Thales Lima7ec83822021-08-05 13:32:10 +0100633 /**
fbarond1cd8c22024-11-26 10:13:36 -0800634 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
635 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700636 *
fbarond1cd8c22024-11-26 10:13:36 -0800637 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700638 */
fbarond1cd8c22024-11-26 10:13:36 -0800639 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000640 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800641 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700642
643 try (XmlResourceParser parser = resourceHelper.getXml()) {
644 final int depth = parser.getDepth();
645 int type;
646 while (((type = parser.next()) != XmlPullParser.END_TAG
647 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
648 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800649 && "GridSize".equals(parser.getName())) {
650 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700651 }
652 }
653 } catch (IOException | XmlPullParserException e) {
654 throw new RuntimeException(e);
655 }
656
fbaron49358342024-11-22 17:38:56 -0800657 // Finds the min width and height in dp for all displays.
658 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
659
fbarond1cd8c22024-11-26 10:13:36 -0800660 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700661 }
662
663 /**
fbarond1cd8c22024-11-26 10:13:36 -0800664 * @return the biggest grid size that fits the display dimensions.
665 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700666 */
fbarond1cd8c22024-11-26 10:13:36 -0800667 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800668 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800669 GridSize selectedGridSize = null;
670 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800671 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800672 if (selectedGridSize == null
673 || (selectedGridSize.mNumColumns <= item.mNumColumns
674 && selectedGridSize.mNumRows <= item.mNumRows)) {
675 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800676 }
677 }
678 }
fbarond1cd8c22024-11-26 10:13:36 -0800679 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800680 }
681
682 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaron9ce45ba2024-12-03 02:17:00 -0800683 int minDisplayWidthDp = Integer.MAX_VALUE;
684 int minDisplayHeightDp = Integer.MAX_VALUE;
685 for (CachedDisplayInfo display: displayInfo.getAllDisplays()) {
686 minDisplayWidthDp = Math.min(minDisplayWidthDp,
687 (int) dpiFromPx(display.size.x, DisplayMetrics.DENSITY_DEVICE_STABLE));
688 minDisplayHeightDp = Math.min(minDisplayHeightDp,
689 (int) dpiFromPx(display.size.y, DisplayMetrics.DENSITY_DEVICE_STABLE));
fbaronebc10c92024-09-03 12:51:41 -0700690 }
fbaron9ce45ba2024-12-03 02:17:00 -0800691 return new int[]{minDisplayWidthDp, minDisplayHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700692 }
693
694 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000695 * Returns the GridOption associated to the given file name or null if the fileName is not
696 * supported.
697 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
698 */
699 public GridOption getGridOptionFromFileName(Context context, String fileName) {
700 return parseAllGridOptions(context).stream()
701 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
702 .findFirst()
703 .orElse(null);
704 }
705
706 /**
707 * Returns the name of the given size on the current device or empty string if the size is not
708 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
709 * (Note: the name of the grid can be different for the same grid size depending of
710 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000711 */
712 public String getGridNameFromSize(Context context, Point size) {
713 return parseAllGridOptions(context).stream()
714 .filter(gridOption -> gridOption.numColumns == size.x
715 && gridOption.numRows == size.y)
716 .map(gridOption -> gridOption.name)
717 .findFirst()
718 .orElse("");
719 }
720
721 /**
722 * Returns the grid option for the given gridName on the current device (Note: the gridOption
723 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
724 */
725 public GridOption getGridOptionFromName(Context context, String gridName) {
726 return parseAllGridOptions(context).stream()
727 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
728 .findFirst()
729 .orElse(null);
730 }
731
732 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100733 * @return all the grid options that can be shown on the device
734 */
735 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000736 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700737 .stream()
738 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800739 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700740 .collect(Collectors.toList());
741 }
742
743 /**
744 * @return all the grid options that can be shown on the device
745 */
Federico Baron56307d22024-11-06 18:48:48 +0000746 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100747 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000748 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100749 final int depth = parser.getDepth();
750 int type;
751 while (((type = parser.next()) != XmlPullParser.END_TAG
752 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
753 if ((type == XmlPullParser.START_TAG)
754 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000755 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100756 }
757 }
758 } catch (IOException | XmlPullParserException e) {
759 Log.e(TAG, "Error parsing device profile", e);
760 return Collections.emptyList();
761 }
762 return result;
763 }
764
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700765 private int getLauncherIconDensity(int requiredSize) {
766 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700767 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700768 DisplayMetrics.DENSITY_LOW,
769 DisplayMetrics.DENSITY_MEDIUM,
770 DisplayMetrics.DENSITY_TV,
771 DisplayMetrics.DENSITY_HIGH,
772 DisplayMetrics.DENSITY_XHIGH,
773 DisplayMetrics.DENSITY_XXHIGH,
774 DisplayMetrics.DENSITY_XXXHIGH
775 };
776
777 int density = DisplayMetrics.DENSITY_XXXHIGH;
778 for (int i = densityBuckets.length - 1; i >= 0; i--) {
779 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
780 / DisplayMetrics.DENSITY_DEFAULT;
781 if (expectedSize >= requiredSize) {
782 density = densityBuckets[i];
783 }
784 }
785
786 return density;
787 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700788
Adam Cohen2e6da152015-05-06 11:42:25 -0700789 /**
790 * Apply any Partner customization grid overrides.
791 *
792 * Currently we support: all apps row / column count.
793 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700794 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
795 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800796 if (p == null) {
797 return;
798 }
799 try {
800 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
801 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
802 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
803
804 if (numRows > 0 && numColumns > 0) {
805 this.numRows = numRows;
806 this.numColumns = numColumns;
807 }
808 if (iconSizePx > 0) {
809 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
810 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
811 }
812 } catch (Resources.NotFoundException ex) {
813 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700814 }
815 }
816
Sunny Goyal415f1732018-11-29 10:33:47 -0800817 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700818 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700819 }
820
Sunny Goyal19ff7282021-04-22 10:12:54 -0700821 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700822 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700823 int minWidthPx = Integer.MAX_VALUE;
824 int minHeightPx = Integer.MAX_VALUE;
825 for (WindowBounds bounds : displayInfo.supportedBounds) {
826 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000827 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700828 // For split displays, take half width per page
829 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
830 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700831
Sunny Goyal19ff7282021-04-22 10:12:54 -0700832 } else if (!isTablet && bounds.isLandscape()) {
833 // We will use transposed layout in this case
834 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
835 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
836 } else {
837 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
838 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
839 }
840 }
841
Thales Lima425f6822022-05-10 13:44:58 -0300842 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
843 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700844
845 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700846 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700847 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
848 dist(width, height, b.minWidthDps, b.minHeightDps)));
849
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700850 DisplayOption closestPoint = points.get(0);
851 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700852 float weights = 0;
853
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700854 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
855 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700856 }
857
858 DisplayOption out = new DisplayOption(closestOption);
859 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700860 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700861 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
862 weights += w;
863 out.add(new DisplayOption().add(p).multiply(w));
864 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700865 out.multiply(1.0f / weights);
866
Thales Lima6e0005a2021-10-27 15:53:41 +0100867 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700868 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100869 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
870 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700871 }
872
873 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700874 }
875
Sunny Goyal27835952017-01-13 12:15:53 -0800876 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000877 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
878 Rect bounds = windowManagerProxy.getCurrentBounds(context);
879 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700880
Alex Chauc09a98a2023-11-14 12:51:42 +0000881 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400882 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700883
Sunny Goyal187b16c2022-03-01 16:53:23 -0800884 /**
885 * Returns the device profile matching the provided screen configuration
886 */
887 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700888 DeviceProfile bestMatch = supportedProfiles.get(0);
889 float minDiff = Float.MAX_VALUE;
890
891 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400892 float diff = Math.abs(profile.widthPx - screenWidth)
893 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700894 if (diff < minDiff) {
895 minDiff = diff;
896 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800897 } else if (diff == minDiff && profile.rotationHint == rotation) {
898 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700899 }
900 }
901 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800902 }
903
Sunny Goyal415f1732018-11-29 10:33:47 -0800904 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700905 float d = dist(x0, y0, x1, y1);
906 if (Float.compare(d, 0f) == 0) {
907 return Float.POSITIVE_INFINITY;
908 }
909 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
910 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700911
912 /**
913 * As a ratio of screen height, the total distance we want the parallax effect to span
914 * horizontally
915 */
916 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
917 float aspectRatio = width / (float) height;
918
919 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
920 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
921 // We will use these two data points to extrapolate how much the wallpaper parallax effect
922 // to span (ie travel) at any aspect ratio:
923
sfufa@google.comde013292021-09-21 18:22:44 -0700924 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
925 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700926 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
927 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
928
929 // To find out the desired width at different aspect ratios, we use the following two
930 // formulas, where the coefficient on x is the aspect ratio (width/height):
931 // (16/10)x + y = 1.5
932 // (10/16)x + y = 1.2
933 // We solve for x and y and end up with a final formula:
934 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700935 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
936 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700937 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
938 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
939 return x * aspectRatio + y;
940 }
941
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700942 public interface OnIDPChangeListener {
943
Sunny Goyalb47172b2021-05-03 19:59:51 -0700944 /**
945 * Called when the device provide changes
946 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700947 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700948 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800949
950
Sunny Goyaleff44f32019-01-09 17:29:49 -0800951 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800952
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800953 public static final String TAG_NAME = "grid-option";
954
Alex Chau1c883d82021-12-01 18:43:10 +0000955 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
956 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
957 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
958 private static final int DEVICE_CATEGORY_ALL =
959 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
960
Thales Lima11af7bc2022-08-12 15:24:54 +0100961 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
962 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
963 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
964 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
965 private static final int DONT_INLINE_QSB = 0;
966
Sunny Goyaleff44f32019-01-09 17:29:49 -0800967 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700968 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800969 public final int numRows;
970 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000971 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700972 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800973
Thales Lima1faa4ed2023-12-01 16:48:19 +0000974 private final int[] numFolderRows = new int[COUNT_SIZES];
975 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300976 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000977 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800978
Thales Limae9273ea2023-01-26 12:33:52 +0000979 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700980 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300981 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700982 private final int numDatabaseAllAppsColumns;
983 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700984 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100985
Thales Lima11af7bc2022-08-12 15:24:54 +0100986 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
987
Thales Limab35faed2022-09-05 16:30:01 -0300988 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800989 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000990
Sunny Goyal415f1732018-11-29 10:33:47 -0800991 private final int defaultLayoutId;
992 private final int demoModeLayoutId;
993
Jon Mirandae126d722021-02-25 10:45:20 -0500994 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -0800995 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400996 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100997 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100998 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100999 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001000 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001001 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001002 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001003 private final int mHotseatSpecsId;
1004 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001005 private final int mWorkspaceCellSpecsId;
1006 private final int mWorkspaceCellSpecsTwoPanelId;
1007 private final int mAllAppsCellSpecsId;
1008 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001009 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001010 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001011 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001012
Federico Baron56307d22024-11-06 18:48:48 +00001013 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001014 TypedArray a = context.obtainStyledAttributes(
1015 attrs, R.styleable.GridDisplayOption);
1016 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001017 title = a.getString(R.styleable.GridDisplayOption_title);
1018 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1019 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001020 mGridSizeSpecsId = a.getResourceId(
1021 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001022 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001023 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1024 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1025 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1026 numColumns = gridSize.mNumColumns;
1027 numRows = gridSize.mNumRows;
1028 dbFile = gridSize.mDbFile;
1029 defaultLayoutId = gridSize.mDefaultLayoutId;
1030 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001031 } else {
1032 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001033 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001034 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001035 defaultLayoutId = a.getResourceId(
1036 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1037 demoModeLayoutId = a.getResourceId(
1038 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001039 }
1040
Alex Chau9fee3fd2021-12-01 18:43:10 +00001041 numSearchContainerColumns = a.getInt(
1042 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001043
Thales Limae9273ea2023-01-26 12:33:52 +00001044 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1045 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001046 numAllAppsColumns = a.getInt(
1047 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1048 numDatabaseAllAppsColumns = a.getInt(
1049 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1050
1051 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001052 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001053 numDatabaseHotseatIcons = a.getInt(
1054 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001055
Vinit Nayakc7293172022-07-18 16:41:50 -07001056 inlineNavButtonsEndSpacing =
1057 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001058 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001059
Thales Lima1faa4ed2023-12-01 16:48:19 +00001060 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001061 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001062 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001063 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001064
Thales Lima1faa4ed2023-12-01 16:48:19 +00001065 if (FeatureFlags.enableResponsiveWorkspace()) {
1066 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1067 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1068 numFolderRows[INDEX_DEFAULT]);
1069 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1070 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1071 numFolderColumns[INDEX_DEFAULT]);
1072 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1073 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1074 numFolderRows[INDEX_DEFAULT]);
1075 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1076 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1077 numFolderColumns[INDEX_DEFAULT]);
1078 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1079 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1080 numFolderRows[INDEX_DEFAULT]);
1081 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1082 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1083 numFolderColumns[INDEX_DEFAULT]);
1084 } else {
1085 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1086 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1087 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1088 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1089 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1090 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1091 }
1092
Thales Limab35faed2022-09-05 16:30:01 -03001093 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1094 INVALID_RESOURCE_HANDLE);
1095
Thales Limad852d652023-01-17 14:01:13 +00001096 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1097 R.style.CellStyleDefault);
1098
Jon Mirandae126d722021-02-25 10:45:20 -05001099 isScalable = a.getBoolean(
1100 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001101 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001102 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001103
Thales Limaca31b612023-09-14 14:25:26 +01001104 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001105 mWorkspaceSpecsId = a.getResourceId(
1106 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001107 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1108 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001109 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001110 mAllAppsSpecsId = a.getResourceId(
1111 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001112 mAllAppsSpecsTwoPanelId = a.getResourceId(
1113 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001114 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001115 mFolderSpecsId = a.getResourceId(
1116 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001117 mFolderSpecsTwoPanelId = a.getResourceId(
1118 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001119 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001120 mHotseatSpecsId = a.getResourceId(
1121 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1122 mHotseatSpecsTwoPanelId = a.getResourceId(
1123 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001124 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001125 mWorkspaceCellSpecsId = a.getResourceId(
1126 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1127 INVALID_RESOURCE_HANDLE);
1128 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1129 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001130 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001131 mAllAppsCellSpecsId = a.getResourceId(
1132 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1133 INVALID_RESOURCE_HANDLE);
1134 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1135 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001136 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001137 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1138 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1139 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001140 } else {
1141 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001142 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001143 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001144 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001145 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001146 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001147 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1148 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001149 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1150 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1151 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1152 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001153 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001154 }
1155
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001156 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001157 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001158
Thales Lima11af7bc2022-08-12 15:24:54 +01001159 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1160 DONT_INLINE_QSB);
1161 inlineQsb[INDEX_DEFAULT] =
1162 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1163 inlineQsb[INDEX_LANDSCAPE] =
1164 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1165 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1166 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1167 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1168 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1169 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1170 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1171
Sunny Goyal415f1732018-11-29 10:33:47 -08001172 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001173 }
1174
1175 public boolean isEnabled(@DeviceType int deviceType) {
1176 switch (deviceType) {
1177 case TYPE_PHONE:
1178 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1179 case TYPE_TABLET:
1180 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1181 case TYPE_MULTI_DISPLAY:
1182 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1183 == DEVICE_CATEGORY_MULTI_DISPLAY;
1184 default:
1185 return false;
1186 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001187 }
fbaronebc10c92024-09-03 12:51:41 -07001188
fbaron6c91ef92024-11-12 22:22:43 -08001189 /**
1190 * Returns true if the grid option should be used given the flags that are toggled on/off.
1191 */
fbaronc1b68f42024-11-08 18:10:46 -08001192 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001193 if (deviceType == TYPE_TABLET) {
1194 return Flags.oneGridRotationHandling() == mIsDualGrid;
1195 }
fbaronc1b68f42024-11-08 18:10:46 -08001196
fbaron6c91ef92024-11-12 22:22:43 -08001197 // Here we return true if fixed landscape mode should be on.
1198 if (mIsFixedLandscape || isFixedLandscape) {
1199 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001200 }
1201
fbaron6c91ef92024-11-12 22:22:43 -08001202 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001203 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001204 return Flags.oneGridSpecs();
1205 }
1206
1207 // Here we return true if we want to show the old grids.
1208 if (mIsOldGrid) {
1209 return !Flags.oneGridSpecs();
1210 }
1211
1212 return true;
fbaron49f7df02024-11-05 16:15:19 -08001213 }
fbaronebc10c92024-09-03 12:51:41 -07001214 }
1215
fbarond1cd8c22024-11-26 10:13:36 -08001216 public static final class GridSize {
1217 final int mNumRows;
1218 final int mNumColumns;
1219 final float mMinDeviceWidthDp;
1220 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001221 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001222 final int mDefaultLayoutId;
1223 final int mDemoModeLayoutId;
1224
fbaronebc10c92024-09-03 12:51:41 -07001225
fbarond1cd8c22024-11-26 10:13:36 -08001226 GridSize(Context context, AttributeSet attrs) {
1227 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001228
fbarond1cd8c22024-11-26 10:13:36 -08001229 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1230 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1231 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1232 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1233 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001234 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001235 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001236 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001237 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001238
1239 a.recycle();
1240 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001241 }
1242
Sunny Goyal19ff7282021-04-22 10:12:54 -07001243 @VisibleForTesting
1244 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001245 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001246
Sunny Goyal415f1732018-11-29 10:33:47 -08001247 private final float minWidthDps;
1248 private final float minHeightDps;
1249 private final boolean canBeDefault;
1250
Thales Lima83bedbf2021-10-05 17:47:39 +01001251 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001252
Thales Lima78d00ad2021-09-30 11:29:06 +01001253 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001254 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001255 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1256 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001257
Thales Lima78d00ad2021-09-30 11:29:06 +01001258 private final float[] iconSizes = new float[COUNT_SIZES];
1259 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001260
Thales Limab7ef5692022-03-10 10:32:36 +00001261 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001262 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1263 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1264 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1265
Jon Miranda9c478b62023-03-23 21:38:49 -07001266 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1267
Jon Miranda04f05102023-04-04 12:16:31 -07001268 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1269
Thales Lima1de4d552021-10-13 16:13:25 +01001270 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001271 this.grid = grid;
1272
Jon Miranda9c478b62023-03-23 21:38:49 -07001273 Resources res = context.getResources();
1274
Thales Lima1de4d552021-10-13 16:13:25 +01001275 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001276
Sunny Goyal415f1732018-11-29 10:33:47 -08001277 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1278 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001279
Thales Lima1de4d552021-10-13 16:13:25 +01001280 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001281
Thales Lima83bedbf2021-10-05 17:47:39 +01001282 float x;
1283 float y;
1284
Thales Lima85c942f2021-12-31 13:04:20 +00001285 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1286 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001287 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001288
1289 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1290 minCellSize[INDEX_DEFAULT].x);
1291 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1292 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001293 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001294
Thales Lima85c942f2021-12-31 13:04:20 +00001295 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001296 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001297 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001298 minCellSize[INDEX_DEFAULT].y);
1299 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1300
Thales Lima85c942f2021-12-31 13:04:20 +00001301 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001302 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001303 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001304 minCellSize[INDEX_DEFAULT].y);
1305 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001306
Thales Lima85c942f2021-12-31 13:04:20 +00001307 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001308 float borderSpaceLandscape = a.getFloat(
1309 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001310 float borderSpaceTwoPanelPortrait = a.getFloat(
1311 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1312 float borderSpaceTwoPanelLandscape = a.getFloat(
1313 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001314
Thales Lima85c942f2021-12-31 13:04:20 +00001315 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1316 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001317 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001318
1319 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1320 borderSpaceLandscape);
1321 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1322 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001323 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1324
1325 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001326 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1327 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001328 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001329 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1330 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001331 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1332
1333 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001334 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1335 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001336 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001337 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1338 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001339 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1340
Thales Limab7ef5692022-03-10 10:32:36 +00001341 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1342 minCellSize[INDEX_DEFAULT].x);
1343 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1344 minCellSize[INDEX_DEFAULT].y);
1345 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1346
1347 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1348 allAppsCellSize[INDEX_DEFAULT].x);
1349 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1350 allAppsCellSize[INDEX_DEFAULT].y);
1351 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1352
1353 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1354 allAppsCellSize[INDEX_DEFAULT].x);
1355 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1356 allAppsCellSize[INDEX_DEFAULT].y);
1357 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1358
1359 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1360 allAppsCellSize[INDEX_DEFAULT].x);
1361 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1362 allAppsCellSize[INDEX_DEFAULT].y);
1363 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1364
Thales Lima080d8902022-03-28 15:30:29 +01001365 float allAppsBorderSpace = a.getFloat(
1366 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1367 float allAppsBorderSpaceLandscape = a.getFloat(
1368 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1369 allAppsBorderSpace);
1370 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001371 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001372 allAppsBorderSpace);
1373 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001374 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001375 allAppsBorderSpace);
1376
1377 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1378 allAppsBorderSpace);
1379 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1380 allAppsBorderSpace);
1381 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1382
1383 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1384 allAppsBorderSpaceLandscape);
1385 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1386 allAppsBorderSpaceLandscape);
1387 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1388
1389 x = a.getFloat(
1390 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1391 allAppsBorderSpaceTwoPanelPortrait);
1392 y = a.getFloat(
1393 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1394 allAppsBorderSpaceTwoPanelPortrait);
1395 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1396
1397 x = a.getFloat(
1398 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1399 allAppsBorderSpaceTwoPanelLandscape);
1400 y = a.getFloat(
1401 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1402 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001403 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001404
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001405 iconSizes[INDEX_DEFAULT] =
1406 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1407 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001408 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001409 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001410 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001411 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001412 iconSizes[INDEX_DEFAULT]);
1413 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001414 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001415 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001416
Thales Limabb7d3882021-12-22 12:56:29 +00001417 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1418 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001419 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1420 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001421 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001422 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1423 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1424 allAppsIconSizes[INDEX_DEFAULT]);
1425 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1426 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1427 allAppsIconSizes[INDEX_DEFAULT]);
1428
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001429 textSizes[INDEX_DEFAULT] =
1430 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1431 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001432 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001433 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001434 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001435 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001436 textSizes[INDEX_DEFAULT]);
1437 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001438 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001439 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001440
Thales Limabb7d3882021-12-22 12:56:29 +00001441 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1442 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1443 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1444 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1445 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1446 allAppsIconTextSizes[INDEX_DEFAULT]);
1447 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1448 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1449 allAppsIconTextSizes[INDEX_DEFAULT]);
1450
Thales Lima83bedbf2021-10-05 17:47:39 +01001451 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1452 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001453 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1454 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1455 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001456 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001457 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001458 horizontalMargin[INDEX_DEFAULT]);
1459 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001460 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001461 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001462
Thales Limab8c05952022-05-23 16:58:38 +01001463 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1464 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001465 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001466 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1467 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1468 hotseatBarBottomSpace[INDEX_DEFAULT]);
1469 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1470 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1471 hotseatBarBottomSpace[INDEX_DEFAULT]);
1472 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1473 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1474 hotseatBarBottomSpace[INDEX_DEFAULT]);
1475
1476 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1477 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001478 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001479 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1480 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1481 hotseatQsbSpace[INDEX_DEFAULT]);
1482 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1483 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1484 hotseatQsbSpace[INDEX_DEFAULT]);
1485 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1486 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1487 hotseatQsbSpace[INDEX_DEFAULT]);
1488
Jon Miranda9c478b62023-03-23 21:38:49 -07001489 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1490 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1491 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1492 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1493 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1494 transientTaskbarIconSize[INDEX_DEFAULT]);
1495 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1496 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1497 transientTaskbarIconSize[INDEX_DEFAULT]);
1498 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1499 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001500 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001501
Jon Miranda04f05102023-04-04 12:16:31 -07001502 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1503 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1504 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1505 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1506 startAlignTaskbar[INDEX_DEFAULT]);
1507 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1508 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1509 startAlignTaskbar[INDEX_LANDSCAPE]);
1510 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1511 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1512 startAlignTaskbar[INDEX_DEFAULT]);
1513
Sunny Goyal415f1732018-11-29 10:33:47 -08001514 a.recycle();
1515 }
1516
1517 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001518 this(null);
1519 }
1520
1521 DisplayOption(GridOption grid) {
1522 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001523 minWidthDps = 0;
1524 minHeightDps = 0;
1525 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001526 for (int i = 0; i < COUNT_SIZES; i++) {
1527 iconSizes[i] = 0;
1528 textSizes[i] = 0;
1529 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001530 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001531 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001532 allAppsIconSizes[i] = 0;
1533 allAppsIconTextSizes[i] = 0;
1534 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001535 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001536 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001537 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001538 }
1539
1540 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001541 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001542 iconSizes[i] *= w;
1543 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001544 borderSpaces[i].x *= w;
1545 borderSpaces[i].y *= w;
1546 minCellSize[i].x *= w;
1547 minCellSize[i].y *= w;
1548 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001549 hotseatBarBottomSpace[i] *= w;
1550 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001551 allAppsCellSize[i].x *= w;
1552 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001553 allAppsIconSizes[i] *= w;
1554 allAppsIconTextSizes[i] *= w;
1555 allAppsBorderSpaces[i].x *= w;
1556 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001557 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001558 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001559
Sunny Goyal415f1732018-11-29 10:33:47 -08001560 return this;
1561 }
1562
1563 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001564 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001565 iconSizes[i] += p.iconSizes[i];
1566 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001567 borderSpaces[i].x += p.borderSpaces[i].x;
1568 borderSpaces[i].y += p.borderSpaces[i].y;
1569 minCellSize[i].x += p.minCellSize[i].x;
1570 minCellSize[i].y += p.minCellSize[i].y;
1571 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001572 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1573 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001574 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1575 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001576 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1577 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1578 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1579 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001580 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001581 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001582 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001583
Sunny Goyal415f1732018-11-29 10:33:47 -08001584 return this;
1585 }
1586 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001587}