blob: aefb2b15943db57da44f490ca1a4267f1b591277 [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
Charlie Andersonbad2be42024-12-06 16:32:03 -050019import static com.android.launcher3.LauncherPrefs.DB_FILE;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070020import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE;
Stefan Andonian4c9612b2023-02-22 00:00:03 +000021import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070022import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030023import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070024import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070025import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000026import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070027import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070028import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080029import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070030
Sunny Goyalc6205602015-05-21 20:46:33 -070031import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070032import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080033import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070034import android.content.res.TypedArray;
35import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070036import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010037import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000038import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070039import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080040import android.text.TextUtils;
41import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070042import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010043import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080044import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070045import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080046import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070047
Thales Limab35faed2022-09-05 16:30:01 -030048import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000049import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030050import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070051import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000052import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010053import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070054
Thales Limaec5abba2023-04-05 16:33:50 +010055import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070056import com.android.launcher3.icons.DotRenderer;
Charlie Andersonbad2be42024-12-06 16:32:03 -050057import com.android.launcher3.logging.FileLog;
Sunny Goyal68031ca2021-08-02 12:23:44 -070058import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010059import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070060import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070061import com.android.launcher3.util.DisplayController;
62import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070063import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080064import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070065import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070066import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070067import com.android.launcher3.util.WindowBounds;
fbaron9ce45ba2024-12-03 02:17:00 -080068import com.android.launcher3.util.window.CachedDisplayInfo;
Sunny Goyal187b16c2022-03-01 16:53:23 -080069import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070070
Sunny Goyal819e1932016-07-07 16:43:58 -070071import org.xmlpull.v1.XmlPullParser;
72import org.xmlpull.v1.XmlPullParserException;
73
74import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000075import java.lang.annotation.Retention;
76import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070077import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070078import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080079import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070080import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000081import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070082import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070083
Sunny Goyal10fa0162024-04-21 00:13:35 -070084public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070085
Hyunyoung Songc55a3502018-12-04 15:43:16 -080086 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070087 // We do not need any synchronization for this variable as its only written on UI thread.
88 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070089 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070090
Charlie Andersonbad2be42024-12-06 16:32:03 -050091 public static final String GRID_NAME_PREFS_KEY = "idp_grid_name";
92
Alex Chau1c883d82021-12-01 18:43:10 +000093 @Retention(RetentionPolicy.SOURCE)
94 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070095 public @interface DeviceType {
96 }
Thales Limab8c05952022-05-23 16:58:38 +010097
Alex Chau1c883d82021-12-01 18:43:10 +000098 public static final int TYPE_PHONE = 0;
99 public static final int TYPE_MULTI_DISPLAY = 1;
100 public static final int TYPE_TABLET = 2;
101
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700102 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
103
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700104 // Constants that affects the interpolation curve between statically defined device profile
105 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800106 private static final float KNEARESTNEIGHBOR = 3;
107 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700108
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700109 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800110 private static final float WEIGHT_EFFICIENT = 100000f;
111
Thales Lima83bedbf2021-10-05 17:47:39 +0100112 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
113 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000114 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100115 static final int INDEX_DEFAULT = 0;
116 static final int INDEX_LANDSCAPE = 1;
117 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
118 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100119
Thales Limaec5abba2023-04-05 16:33:50 +0100120 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800121 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
122 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
123 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
124
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700125 /**
126 * Number of icons per row and column in the workspace.
127 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700128 public int numRows;
129 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000130 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700131
132 /**
133 * Number of icons per row and column in the folder.
134 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000135 public int[] numFolderRows;
136 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100137 public float[] iconSize;
138 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700139 public int iconBitmapSize;
140 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000141 public @DeviceType int deviceType;
Federico Baron56307d22024-11-06 18:48:48 +0000142 public Info displayInfo;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700143
Thales Lima83bedbf2021-10-05 17:47:39 +0100144 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100145
Thales Lima83bedbf2021-10-05 17:47:39 +0100146 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300147 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100148
Thales Limab35faed2022-09-05 16:30:01 -0300149 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100150
Thales Limad852d652023-01-17 14:01:13 +0000151 public @StyleRes int cellStyle;
152
Thales Lima83bedbf2021-10-05 17:47:39 +0100153 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500154
Thales Limab7ef5692022-03-10 10:32:36 +0000155 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000156 public float[] allAppsIconSize;
157 public float[] allAppsIconTextSize;
158 public PointF[] allAppsBorderSpaces;
159
Jon Miranda9c478b62023-03-23 21:38:49 -0700160 public float[] transientTaskbarIconSize;
161
Jon Miranda04f05102023-04-04 12:16:31 -0700162 public boolean[] startAlignTaskbar;
163
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700164 /**
165 * Number of icons inside the hotseat area.
166 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800167 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700168
169 /**
170 * Number of icons inside the hotseat area that is stored in the database. This is greater than
171 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
172 * sizes that share the same DB.
173 */
174 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700175
Thales Limab8c05952022-05-23 16:58:38 +0100176 public float[] hotseatBarBottomSpace;
177 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300178
Jon Miranda6f7e9702019-09-16 14:44:14 -0700179 /**
180 * Number of columns in the all apps list.
181 */
182 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300183 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700184 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000185 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700186
Jon Mirandae126d722021-02-25 10:45:20 -0500187 /**
188 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
189 */
190 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000191 @XmlRes
192 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100193 @XmlRes
194 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100195 @XmlRes
fbarond1cd8c22024-11-26 10:13:36 -0800196 public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;;
fbaronebc10c92024-09-03 12:51:41 -0700197 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100198 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
199 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100200 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100201 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100202 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
203 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100204 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100205 @XmlRes
206 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000207 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100208 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000209 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100210 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000211 @XmlRes
212 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
213 @XmlRes
214 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
215 @XmlRes
216 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
217 @XmlRes
218 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500219
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700220
221 /**
222 * Fixed landscape mode is the landscape on the phones.
223 */
fbarond1cd8c22024-11-26 10:13:36 -0800224 public boolean isFixedLandscape = false;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700225 private LauncherPrefChangeListener mLandscapeModePreferenceListener;
226
Tracy Zhou7df93d22020-01-27 13:44:06 -0800227 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800228 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700229 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100230 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700231
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000232 /**
233 * An immutable list of supported profiles.
234 */
235 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700236
Sunny Goyal6f866092016-03-17 17:04:15 -0700237 public Point defaultWallpaperSize;
238
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700239 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700240
Sunny Goyalf633ef52018-03-13 09:57:05 -0700241 @VisibleForTesting
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700242 public InvariantDeviceProfile() {
243 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700244
Sunny Goyalbbf01842015-10-08 07:41:15 -0700245 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700246 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700247 String gridName = getCurrentGridName(context);
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800248 initGrid(context, gridName);
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) {
Charlie Andersonbe55d962024-12-11 22:11:09 +0000352 FileLog.d(TAG, "Before initGrid:"
353 + "gridName:" + gridName
354 + ", dbFile:" + dbFile
355 + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME)
356 + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE));
Sunny Goyal35c7b192021-04-20 16:51:10 -0700357 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700358 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
359 context,
360 gridName,
361 displayInfo,
362 RestoreDbTask.isPending(context),
363 FIXED_LANDSCAPE_MODE.get(context)
364 );
fbaronebc10c92024-09-03 12:51:41 -0700365
366 // Filter out options that don't have the same number of columns as the grid
367 DeviceGridState deviceGridState = new DeviceGridState(context);
368 List<DisplayOption> allOptionsFilteredByColCount =
369 filterByColumnCount(allOptions, deviceGridState.getColumns());
370
Sunny Goyal19ff7282021-04-22 10:12:54 -0700371 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700372 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700373 ? new ArrayList<>(allOptions)
374 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000375 displayInfo.getDeviceType());
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800376
377 if (!displayOption.grid.name.equals(gridName)) {
378 LauncherPrefs.get(context).put(GRID_NAME, displayOption.grid.name);
379 }
380
Federico Baron56307d22024-11-06 18:48:48 +0000381 initGrid(context, displayInfo, displayOption);
Charlie Andersonbe55d962024-12-11 22:11:09 +0000382 FileLog.d(TAG, "After initGrid:"
Charlie Andersonbad2be42024-12-06 16:32:03 -0500383 + "gridName:" + gridName
Charlie Andersonbe55d962024-12-11 22:11:09 +0000384 + ", dbFile:" + dbFile
Charlie Andersonbad2be42024-12-06 16:32:03 -0500385 + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME)
386 + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE));
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700387 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800388 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700389
fbaronebc10c92024-09-03 12:51:41 -0700390 private List<DisplayOption> filterByColumnCount(
391 List<DisplayOption> allOptions, int numColumns) {
392 return allOptions.stream().filter(
393 option -> option.grid.numColumns == numColumns).toList();
394 }
395
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700396 /**
397 * @deprecated This is a temporary solution because on the backup and restore case we modify the
398 * IDP, this resets it. b/332974074
399 */
400 @Deprecated
401 public void reset(Context context) {
Charlie Andersonbe55d962024-12-11 22:11:09 +0000402 initGrid(context, getCurrentGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700403 }
404
Thales Limab67bfa72022-11-02 15:30:11 +0000405 @VisibleForTesting
406 public static String getDefaultGridName(Context context) {
407 return new InvariantDeviceProfile().initGrid(context, null);
408 }
409
Federico Baron56307d22024-11-06 18:48:48 +0000410 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700411 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700412 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000413 numRows = closestProfile.numRows;
414 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000415 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000416 dbFile = closestProfile.dbFile;
417 defaultLayoutId = closestProfile.defaultLayoutId;
418 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300419
Sunny Goyalae190ff2020-04-14 00:19:01 +0000420 numFolderRows = closestProfile.numFolderRows;
421 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300422 folderStyle = closestProfile.folderStyle;
423
Thales Limad852d652023-01-17 14:01:13 +0000424 cellStyle = closestProfile.cellStyle;
425
Jon Mirandae126d722021-02-25 10:45:20 -0500426 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400427 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100428 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800429 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100430 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100431 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100432 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100433 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100434 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100435 hotseatSpecsId = closestProfile.mHotseatSpecsId;
436 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000437 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
438 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
439 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
440 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300441 numAllAppsRowsForCellHeightCalculation =
442 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000443 this.deviceType = displayInfo.getDeviceType();
444 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000445
Vinit Nayakc7293172022-07-18 16:41:50 -0700446 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
447
Thales Lima83bedbf2021-10-05 17:47:39 +0100448 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100449 float maxIconSize = iconSize[0];
450 for (int i = 1; i < iconSize.length; i++) {
451 maxIconSize = Math.max(maxIconSize, iconSize[i]);
452 }
453 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000454 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
455
Thales Lima83bedbf2021-10-05 17:47:39 +0100456 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700457
Thales Lima83bedbf2021-10-05 17:47:39 +0100458 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100459
Thales Lima83bedbf2021-10-05 17:47:39 +0100460 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100461
Thales Limad90faab2021-09-21 17:18:47 +0100462 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100463
Sunny Goyal19ff7282021-04-22 10:12:54 -0700464 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000465 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700466 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100467 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
468 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700469
Thales Limae9273ea2023-01-26 12:33:52 +0000470 allAppsStyle = closestProfile.allAppsStyle;
471
Sunny Goyal19ff7282021-04-22 10:12:54 -0700472 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300473
Alex Chau1c883d82021-12-01 18:43:10 +0000474 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700475 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500476
Thales Limab7ef5692022-03-10 10:32:36 +0000477 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000478 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
479 allAppsIconSize = displayOption.allAppsIconSizes;
480 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000481
Thales Lima11af7bc2022-08-12 15:24:54 +0100482 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000483
Jon Miranda9c478b62023-03-23 21:38:49 -0700484 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
485
Jon Miranda04f05102023-04-04 12:16:31 -0700486 startAlignTaskbar = displayOption.startAlignTaskbar;
487
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700488 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800489 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700490
Sunny Goyalae190ff2020-04-14 00:19:01 +0000491 // If the partner customization apk contains any grid overrides, apply them
492 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700493 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700494
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000495 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700496 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700497 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700498 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000499 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000500 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000501 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700502 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000503 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700504
Sunny Goyal19ff7282021-04-22 10:12:54 -0700505 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
506 int displayWidth = bounds.bounds.width();
507 int displayHeight = bounds.bounds.height();
508 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700509
Sunny Goyal19ff7282021-04-22 10:12:54 -0700510 // We need to ensure that there is enough extra space in the wallpaper
511 // for the intended parallax effects
512 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300513 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
514 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700515 ? 2
516 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
517 defaultWallpaperSize.x =
518 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700519 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000520 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700521
Thales Lima6a590062022-11-22 15:52:49 +0000522 int numMinShownHotseatIconsForTablet = supportedProfiles
523 .stream()
524 .filter(deviceProfile -> deviceProfile.isTablet)
525 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
526 .min()
527 .orElse(0);
528
529 supportedProfiles
530 .stream()
531 .filter(deviceProfile -> deviceProfile.isTablet)
532 .forEach(deviceProfile -> {
533 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
534 deviceProfile.recalculateHotseatWidthAndBorderSpace();
535 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700536 }
537
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700538 public void addOnChangeListener(OnIDPChangeListener listener) {
539 mChangeListeners.add(listener);
540 }
541
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800542 public void removeOnChangeListener(OnIDPChangeListener listener) {
543 mChangeListeners.remove(listener);
544 }
545
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700546 /**
547 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
548 * migration.
549 */
550 public void setCurrentGrid(Context context, String newGridName) {
551 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700552 MAIN_EXECUTOR.execute(() -> {
553 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
554 onConfigChanged(context.getApplicationContext());
555 Trace.endSection();
556 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800557 }
558
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700559 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700560 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000561 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
562 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700563 }
564
Pat Manning24cec692023-10-13 10:36:57 +0000565 /** Updates IDP using the provided context. Notifies listeners of change. */
566 @VisibleForTesting
567 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700568 Object[] oldState = toModelState();
569
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700570 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700571 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700572 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700573
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700574 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700575 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700576 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700577 }
578 }
579
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700580 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
581 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
582 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800583 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700584 }
585
586 private static List<DisplayOption> getPredefinedDeviceProfiles(
587 Context context,
588 String gridName,
589 Info displayInfo,
590 boolean allowDisabledGrid,
591 boolean isFixedLandscapeMode
592 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800593 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100594
Alex Chau1c883d82021-12-01 18:43:10 +0000595 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700596 final int depth = parser.getDepth();
597 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700598 while (((type = parser.next()) != XmlPullParser.END_TAG ||
599 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800600 if ((type == XmlPullParser.START_TAG)
601 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000602 GridOption gridOption = new GridOption(
603 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700604 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
605 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100606 final int displayDepth = parser.getDepth();
607 while (((type = parser.next()) != XmlPullParser.END_TAG
608 || parser.getDepth() > displayDepth)
609 && type != XmlPullParser.END_DOCUMENT) {
610 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
611 parser.getName())) {
612 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100613 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100614 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800615 }
616 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700617 }
618 }
sfufa@google.comde013292021-09-21 18:22:44 -0700619 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700620 throw new RuntimeException(e);
621 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000622 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800623 if (!TextUtils.isEmpty(gridName)) {
624 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000625 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
626 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000627 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800628 }
629 }
630 }
fbaronebc10c92024-09-03 12:51:41 -0700631 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
632 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000633 for (DisplayOption option : profiles) {
634 if (option.canBeDefault) {
635 filteredProfiles.add(option);
636 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800637 }
fbaronebc10c92024-09-03 12:51:41 -0700638 } else if (filteredProfiles.isEmpty()) {
639 // In this case we had a grid selected but we couldn't find it.
640 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800641 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000642 if (filteredProfiles.isEmpty()) {
643 throw new RuntimeException("No display option with canBeDefault=true");
644 }
645 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700646 }
647
Thales Lima7ec83822021-08-05 13:32:10 +0100648 /**
fbarond1cd8c22024-11-26 10:13:36 -0800649 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
650 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700651 *
fbarond1cd8c22024-11-26 10:13:36 -0800652 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700653 */
fbarond1cd8c22024-11-26 10:13:36 -0800654 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000655 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800656 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700657
658 try (XmlResourceParser parser = resourceHelper.getXml()) {
659 final int depth = parser.getDepth();
660 int type;
661 while (((type = parser.next()) != XmlPullParser.END_TAG
662 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
663 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800664 && "GridSize".equals(parser.getName())) {
665 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700666 }
667 }
668 } catch (IOException | XmlPullParserException e) {
669 throw new RuntimeException(e);
670 }
671
fbaron49358342024-11-22 17:38:56 -0800672 // Finds the min width and height in dp for all displays.
673 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
674
fbarond1cd8c22024-11-26 10:13:36 -0800675 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700676 }
677
678 /**
fbarond1cd8c22024-11-26 10:13:36 -0800679 * @return the biggest grid size that fits the display dimensions.
680 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700681 */
fbarond1cd8c22024-11-26 10:13:36 -0800682 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800683 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800684 GridSize selectedGridSize = null;
685 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800686 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800687 if (selectedGridSize == null
688 || (selectedGridSize.mNumColumns <= item.mNumColumns
689 && selectedGridSize.mNumRows <= item.mNumRows)) {
690 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800691 }
692 }
693 }
fbarond1cd8c22024-11-26 10:13:36 -0800694 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800695 }
696
697 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaron9ce45ba2024-12-03 02:17:00 -0800698 int minDisplayWidthDp = Integer.MAX_VALUE;
699 int minDisplayHeightDp = Integer.MAX_VALUE;
700 for (CachedDisplayInfo display: displayInfo.getAllDisplays()) {
701 minDisplayWidthDp = Math.min(minDisplayWidthDp,
702 (int) dpiFromPx(display.size.x, DisplayMetrics.DENSITY_DEVICE_STABLE));
703 minDisplayHeightDp = Math.min(minDisplayHeightDp,
704 (int) dpiFromPx(display.size.y, DisplayMetrics.DENSITY_DEVICE_STABLE));
fbaronebc10c92024-09-03 12:51:41 -0700705 }
fbaron9ce45ba2024-12-03 02:17:00 -0800706 return new int[]{minDisplayWidthDp, minDisplayHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700707 }
708
709 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000710 * Returns the GridOption associated to the given file name or null if the fileName is not
711 * supported.
712 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
713 */
714 public GridOption getGridOptionFromFileName(Context context, String fileName) {
715 return parseAllGridOptions(context).stream()
716 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
717 .findFirst()
718 .orElse(null);
719 }
720
721 /**
722 * Returns the name of the given size on the current device or empty string if the size is not
723 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
724 * (Note: the name of the grid can be different for the same grid size depending of
725 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000726 */
727 public String getGridNameFromSize(Context context, Point size) {
728 return parseAllGridOptions(context).stream()
729 .filter(gridOption -> gridOption.numColumns == size.x
730 && gridOption.numRows == size.y)
731 .map(gridOption -> gridOption.name)
732 .findFirst()
733 .orElse("");
734 }
735
736 /**
737 * Returns the grid option for the given gridName on the current device (Note: the gridOption
738 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
739 */
740 public GridOption getGridOptionFromName(Context context, String gridName) {
741 return parseAllGridOptions(context).stream()
742 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
743 .findFirst()
744 .orElse(null);
745 }
746
747 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100748 * @return all the grid options that can be shown on the device
749 */
750 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000751 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700752 .stream()
753 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800754 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700755 .collect(Collectors.toList());
756 }
757
758 /**
759 * @return all the grid options that can be shown on the device
760 */
Federico Baron56307d22024-11-06 18:48:48 +0000761 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100762 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000763 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100764 final int depth = parser.getDepth();
765 int type;
766 while (((type = parser.next()) != XmlPullParser.END_TAG
767 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
768 if ((type == XmlPullParser.START_TAG)
769 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000770 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100771 }
772 }
773 } catch (IOException | XmlPullParserException e) {
774 Log.e(TAG, "Error parsing device profile", e);
775 return Collections.emptyList();
776 }
777 return result;
778 }
779
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700780 private int getLauncherIconDensity(int requiredSize) {
781 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700782 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700783 DisplayMetrics.DENSITY_LOW,
784 DisplayMetrics.DENSITY_MEDIUM,
785 DisplayMetrics.DENSITY_TV,
786 DisplayMetrics.DENSITY_HIGH,
787 DisplayMetrics.DENSITY_XHIGH,
788 DisplayMetrics.DENSITY_XXHIGH,
789 DisplayMetrics.DENSITY_XXXHIGH
790 };
791
792 int density = DisplayMetrics.DENSITY_XXXHIGH;
793 for (int i = densityBuckets.length - 1; i >= 0; i--) {
794 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
795 / DisplayMetrics.DENSITY_DEFAULT;
796 if (expectedSize >= requiredSize) {
797 density = densityBuckets[i];
798 }
799 }
800
801 return density;
802 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700803
Adam Cohen2e6da152015-05-06 11:42:25 -0700804 /**
805 * Apply any Partner customization grid overrides.
806 *
807 * Currently we support: all apps row / column count.
808 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700809 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
810 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800811 if (p == null) {
812 return;
813 }
814 try {
815 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
816 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
817 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
818
819 if (numRows > 0 && numColumns > 0) {
820 this.numRows = numRows;
821 this.numColumns = numColumns;
822 }
823 if (iconSizePx > 0) {
824 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
825 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
826 }
827 } catch (Resources.NotFoundException ex) {
828 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700829 }
830 }
831
Sunny Goyal415f1732018-11-29 10:33:47 -0800832 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700833 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700834 }
835
Sunny Goyal19ff7282021-04-22 10:12:54 -0700836 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700837 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700838 int minWidthPx = Integer.MAX_VALUE;
839 int minHeightPx = Integer.MAX_VALUE;
840 for (WindowBounds bounds : displayInfo.supportedBounds) {
841 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000842 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700843 // For split displays, take half width per page
844 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
845 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700846
Sunny Goyal19ff7282021-04-22 10:12:54 -0700847 } else if (!isTablet && bounds.isLandscape()) {
848 // We will use transposed layout in this case
849 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
850 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
851 } else {
852 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
853 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
854 }
855 }
856
Thales Lima425f6822022-05-10 13:44:58 -0300857 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
858 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700859
860 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700861 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700862 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
863 dist(width, height, b.minWidthDps, b.minHeightDps)));
864
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700865 DisplayOption closestPoint = points.get(0);
866 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700867 float weights = 0;
868
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700869 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
870 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700871 }
872
873 DisplayOption out = new DisplayOption(closestOption);
874 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700875 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700876 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
877 weights += w;
878 out.add(new DisplayOption().add(p).multiply(w));
879 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700880 out.multiply(1.0f / weights);
881
Thales Lima6e0005a2021-10-27 15:53:41 +0100882 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700883 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100884 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
885 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700886 }
887
888 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700889 }
890
Sunny Goyal27835952017-01-13 12:15:53 -0800891 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000892 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
893 Rect bounds = windowManagerProxy.getCurrentBounds(context);
894 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700895
Alex Chauc09a98a2023-11-14 12:51:42 +0000896 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400897 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700898
Sunny Goyal187b16c2022-03-01 16:53:23 -0800899 /**
900 * Returns the device profile matching the provided screen configuration
901 */
902 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700903 DeviceProfile bestMatch = supportedProfiles.get(0);
904 float minDiff = Float.MAX_VALUE;
905
906 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400907 float diff = Math.abs(profile.widthPx - screenWidth)
908 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700909 if (diff < minDiff) {
910 minDiff = diff;
911 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800912 } else if (diff == minDiff && profile.rotationHint == rotation) {
913 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700914 }
915 }
916 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800917 }
918
Sunny Goyal415f1732018-11-29 10:33:47 -0800919 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700920 float d = dist(x0, y0, x1, y1);
921 if (Float.compare(d, 0f) == 0) {
922 return Float.POSITIVE_INFINITY;
923 }
924 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
925 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700926
927 /**
928 * As a ratio of screen height, the total distance we want the parallax effect to span
929 * horizontally
930 */
931 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
932 float aspectRatio = width / (float) height;
933
934 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
935 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
936 // We will use these two data points to extrapolate how much the wallpaper parallax effect
937 // to span (ie travel) at any aspect ratio:
938
sfufa@google.comde013292021-09-21 18:22:44 -0700939 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
940 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700941 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
942 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
943
944 // To find out the desired width at different aspect ratios, we use the following two
945 // formulas, where the coefficient on x is the aspect ratio (width/height):
946 // (16/10)x + y = 1.5
947 // (10/16)x + y = 1.2
948 // We solve for x and y and end up with a final formula:
949 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700950 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
951 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700952 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
953 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
954 return x * aspectRatio + y;
955 }
956
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700957 public interface OnIDPChangeListener {
958
Sunny Goyalb47172b2021-05-03 19:59:51 -0700959 /**
960 * Called when the device provide changes
961 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700962 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700963 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800964
965
Sunny Goyaleff44f32019-01-09 17:29:49 -0800966 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800967
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800968 public static final String TAG_NAME = "grid-option";
969
Alex Chau1c883d82021-12-01 18:43:10 +0000970 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
971 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
972 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
973 private static final int DEVICE_CATEGORY_ALL =
974 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
975
Thales Lima11af7bc2022-08-12 15:24:54 +0100976 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
977 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
978 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
979 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
980 private static final int DONT_INLINE_QSB = 0;
981
Sunny Goyaleff44f32019-01-09 17:29:49 -0800982 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700983 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800984 public final int numRows;
985 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000986 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700987 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800988
Thales Lima1faa4ed2023-12-01 16:48:19 +0000989 private final int[] numFolderRows = new int[COUNT_SIZES];
990 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300991 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000992 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800993
Thales Limae9273ea2023-01-26 12:33:52 +0000994 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700995 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300996 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700997 private final int numDatabaseAllAppsColumns;
998 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700999 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +01001000
Thales Lima11af7bc2022-08-12 15:24:54 +01001001 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
1002
Thales Limab35faed2022-09-05 16:30:01 -03001003 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001004 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001005
Sunny Goyal415f1732018-11-29 10:33:47 -08001006 private final int defaultLayoutId;
1007 private final int demoModeLayoutId;
1008
Jon Mirandae126d722021-02-25 10:45:20 -05001009 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001010 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001011 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001012 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001013 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001014 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001015 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001016 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001017 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001018 private final int mHotseatSpecsId;
1019 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001020 private final int mWorkspaceCellSpecsId;
1021 private final int mWorkspaceCellSpecsTwoPanelId;
1022 private final int mAllAppsCellSpecsId;
1023 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001024 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001025 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001026 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001027
Federico Baron56307d22024-11-06 18:48:48 +00001028 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001029 TypedArray a = context.obtainStyledAttributes(
1030 attrs, R.styleable.GridDisplayOption);
1031 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001032 title = a.getString(R.styleable.GridDisplayOption_title);
1033 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1034 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001035 mGridSizeSpecsId = a.getResourceId(
1036 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001037 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001038 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1039 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1040 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1041 numColumns = gridSize.mNumColumns;
1042 numRows = gridSize.mNumRows;
1043 dbFile = gridSize.mDbFile;
1044 defaultLayoutId = gridSize.mDefaultLayoutId;
1045 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001046 } else {
1047 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001048 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001049 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001050 defaultLayoutId = a.getResourceId(
1051 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1052 demoModeLayoutId = a.getResourceId(
1053 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001054 }
1055
Alex Chau9fee3fd2021-12-01 18:43:10 +00001056 numSearchContainerColumns = a.getInt(
1057 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001058
Thales Limae9273ea2023-01-26 12:33:52 +00001059 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1060 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001061 numAllAppsColumns = a.getInt(
1062 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1063 numDatabaseAllAppsColumns = a.getInt(
1064 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1065
1066 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001067 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001068 numDatabaseHotseatIcons = a.getInt(
1069 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001070
Vinit Nayakc7293172022-07-18 16:41:50 -07001071 inlineNavButtonsEndSpacing =
1072 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001073 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001074
Thales Lima1faa4ed2023-12-01 16:48:19 +00001075 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001076 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001077 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001078 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001079
Thales Lima1faa4ed2023-12-01 16:48:19 +00001080 if (FeatureFlags.enableResponsiveWorkspace()) {
1081 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1082 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1083 numFolderRows[INDEX_DEFAULT]);
1084 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1085 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1086 numFolderColumns[INDEX_DEFAULT]);
1087 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1088 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1089 numFolderRows[INDEX_DEFAULT]);
1090 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1091 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1092 numFolderColumns[INDEX_DEFAULT]);
1093 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1094 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1095 numFolderRows[INDEX_DEFAULT]);
1096 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1097 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1098 numFolderColumns[INDEX_DEFAULT]);
1099 } else {
1100 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1101 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1102 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1103 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1104 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1105 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1106 }
1107
Thales Limab35faed2022-09-05 16:30:01 -03001108 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1109 INVALID_RESOURCE_HANDLE);
1110
Thales Limad852d652023-01-17 14:01:13 +00001111 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1112 R.style.CellStyleDefault);
1113
Jon Mirandae126d722021-02-25 10:45:20 -05001114 isScalable = a.getBoolean(
1115 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001116 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001117 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001118
Thales Limaca31b612023-09-14 14:25:26 +01001119 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001120 mWorkspaceSpecsId = a.getResourceId(
1121 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001122 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1123 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001124 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001125 mAllAppsSpecsId = a.getResourceId(
1126 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001127 mAllAppsSpecsTwoPanelId = a.getResourceId(
1128 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001129 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001130 mFolderSpecsId = a.getResourceId(
1131 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001132 mFolderSpecsTwoPanelId = a.getResourceId(
1133 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001134 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001135 mHotseatSpecsId = a.getResourceId(
1136 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1137 mHotseatSpecsTwoPanelId = a.getResourceId(
1138 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001139 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001140 mWorkspaceCellSpecsId = a.getResourceId(
1141 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1142 INVALID_RESOURCE_HANDLE);
1143 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1144 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001145 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001146 mAllAppsCellSpecsId = a.getResourceId(
1147 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1148 INVALID_RESOURCE_HANDLE);
1149 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1150 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001151 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001152 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1153 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1154 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001155 } else {
1156 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001157 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001158 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001159 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001160 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001161 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001162 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1163 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001164 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1165 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1166 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1167 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001168 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001169 }
1170
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001171 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001172 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001173
Thales Lima11af7bc2022-08-12 15:24:54 +01001174 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1175 DONT_INLINE_QSB);
1176 inlineQsb[INDEX_DEFAULT] =
1177 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1178 inlineQsb[INDEX_LANDSCAPE] =
1179 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1180 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1181 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1182 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1183 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1184 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1185 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1186
Sunny Goyal415f1732018-11-29 10:33:47 -08001187 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001188 }
1189
1190 public boolean isEnabled(@DeviceType int deviceType) {
1191 switch (deviceType) {
1192 case TYPE_PHONE:
1193 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1194 case TYPE_TABLET:
1195 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1196 case TYPE_MULTI_DISPLAY:
1197 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1198 == DEVICE_CATEGORY_MULTI_DISPLAY;
1199 default:
1200 return false;
1201 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001202 }
fbaronebc10c92024-09-03 12:51:41 -07001203
fbaron6c91ef92024-11-12 22:22:43 -08001204 /**
1205 * Returns true if the grid option should be used given the flags that are toggled on/off.
1206 */
fbaronc1b68f42024-11-08 18:10:46 -08001207 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001208 if (deviceType == TYPE_TABLET) {
1209 return Flags.oneGridRotationHandling() == mIsDualGrid;
1210 }
fbaronc1b68f42024-11-08 18:10:46 -08001211
fbaron6c91ef92024-11-12 22:22:43 -08001212 // Here we return true if fixed landscape mode should be on.
1213 if (mIsFixedLandscape || isFixedLandscape) {
1214 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001215 }
1216
fbaron6c91ef92024-11-12 22:22:43 -08001217 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001218 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001219 return Flags.oneGridSpecs();
1220 }
1221
1222 // Here we return true if we want to show the old grids.
1223 if (mIsOldGrid) {
1224 return !Flags.oneGridSpecs();
1225 }
1226
1227 return true;
fbaron49f7df02024-11-05 16:15:19 -08001228 }
fbaronebc10c92024-09-03 12:51:41 -07001229 }
1230
fbarond1cd8c22024-11-26 10:13:36 -08001231 public static final class GridSize {
1232 final int mNumRows;
1233 final int mNumColumns;
1234 final float mMinDeviceWidthDp;
1235 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001236 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001237 final int mDefaultLayoutId;
1238 final int mDemoModeLayoutId;
1239
fbaronebc10c92024-09-03 12:51:41 -07001240
fbarond1cd8c22024-11-26 10:13:36 -08001241 GridSize(Context context, AttributeSet attrs) {
1242 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001243
fbarond1cd8c22024-11-26 10:13:36 -08001244 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1245 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1246 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1247 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1248 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001249 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001250 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001251 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001252 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001253
1254 a.recycle();
1255 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001256 }
1257
Sunny Goyal19ff7282021-04-22 10:12:54 -07001258 @VisibleForTesting
1259 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001260 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001261
Sunny Goyal415f1732018-11-29 10:33:47 -08001262 private final float minWidthDps;
1263 private final float minHeightDps;
1264 private final boolean canBeDefault;
1265
Thales Lima83bedbf2021-10-05 17:47:39 +01001266 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001267
Thales Lima78d00ad2021-09-30 11:29:06 +01001268 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001269 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001270 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1271 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001272
Thales Lima78d00ad2021-09-30 11:29:06 +01001273 private final float[] iconSizes = new float[COUNT_SIZES];
1274 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001275
Thales Limab7ef5692022-03-10 10:32:36 +00001276 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001277 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1278 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1279 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1280
Jon Miranda9c478b62023-03-23 21:38:49 -07001281 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1282
Jon Miranda04f05102023-04-04 12:16:31 -07001283 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1284
Thales Lima1de4d552021-10-13 16:13:25 +01001285 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001286 this.grid = grid;
1287
Jon Miranda9c478b62023-03-23 21:38:49 -07001288 Resources res = context.getResources();
1289
Thales Lima1de4d552021-10-13 16:13:25 +01001290 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001291
Sunny Goyal415f1732018-11-29 10:33:47 -08001292 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1293 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001294
Thales Lima1de4d552021-10-13 16:13:25 +01001295 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001296
Thales Lima83bedbf2021-10-05 17:47:39 +01001297 float x;
1298 float y;
1299
Thales Lima85c942f2021-12-31 13:04:20 +00001300 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1301 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001302 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001303
1304 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1305 minCellSize[INDEX_DEFAULT].x);
1306 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1307 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001308 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001309
Thales Lima85c942f2021-12-31 13:04:20 +00001310 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001311 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001312 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001313 minCellSize[INDEX_DEFAULT].y);
1314 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1315
Thales Lima85c942f2021-12-31 13:04:20 +00001316 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001317 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001318 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001319 minCellSize[INDEX_DEFAULT].y);
1320 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001321
Thales Lima85c942f2021-12-31 13:04:20 +00001322 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001323 float borderSpaceLandscape = a.getFloat(
1324 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001325 float borderSpaceTwoPanelPortrait = a.getFloat(
1326 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1327 float borderSpaceTwoPanelLandscape = a.getFloat(
1328 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001329
Thales Lima85c942f2021-12-31 13:04:20 +00001330 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1331 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001332 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001333
1334 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1335 borderSpaceLandscape);
1336 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1337 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001338 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1339
1340 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001341 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1342 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001343 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001344 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1345 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001346 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1347
1348 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001349 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1350 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001351 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001352 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1353 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001354 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1355
Thales Limab7ef5692022-03-10 10:32:36 +00001356 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1357 minCellSize[INDEX_DEFAULT].x);
1358 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1359 minCellSize[INDEX_DEFAULT].y);
1360 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1361
1362 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1363 allAppsCellSize[INDEX_DEFAULT].x);
1364 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1365 allAppsCellSize[INDEX_DEFAULT].y);
1366 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1367
1368 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1369 allAppsCellSize[INDEX_DEFAULT].x);
1370 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1371 allAppsCellSize[INDEX_DEFAULT].y);
1372 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1373
1374 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1375 allAppsCellSize[INDEX_DEFAULT].x);
1376 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1377 allAppsCellSize[INDEX_DEFAULT].y);
1378 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1379
Thales Lima080d8902022-03-28 15:30:29 +01001380 float allAppsBorderSpace = a.getFloat(
1381 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1382 float allAppsBorderSpaceLandscape = a.getFloat(
1383 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1384 allAppsBorderSpace);
1385 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001386 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001387 allAppsBorderSpace);
1388 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001389 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001390 allAppsBorderSpace);
1391
1392 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1393 allAppsBorderSpace);
1394 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1395 allAppsBorderSpace);
1396 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1397
1398 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1399 allAppsBorderSpaceLandscape);
1400 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1401 allAppsBorderSpaceLandscape);
1402 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1403
1404 x = a.getFloat(
1405 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1406 allAppsBorderSpaceTwoPanelPortrait);
1407 y = a.getFloat(
1408 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1409 allAppsBorderSpaceTwoPanelPortrait);
1410 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1411
1412 x = a.getFloat(
1413 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1414 allAppsBorderSpaceTwoPanelLandscape);
1415 y = a.getFloat(
1416 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1417 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001418 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001419
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001420 iconSizes[INDEX_DEFAULT] =
1421 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1422 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001423 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001424 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001425 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001426 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001427 iconSizes[INDEX_DEFAULT]);
1428 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001429 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001430 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001431
Thales Limabb7d3882021-12-22 12:56:29 +00001432 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1433 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001434 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1435 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001436 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001437 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1438 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1439 allAppsIconSizes[INDEX_DEFAULT]);
1440 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1441 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1442 allAppsIconSizes[INDEX_DEFAULT]);
1443
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001444 textSizes[INDEX_DEFAULT] =
1445 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1446 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001447 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001448 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001449 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001450 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001451 textSizes[INDEX_DEFAULT]);
1452 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001453 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001454 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001455
Thales Limabb7d3882021-12-22 12:56:29 +00001456 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1457 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1458 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1459 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1460 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1461 allAppsIconTextSizes[INDEX_DEFAULT]);
1462 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1463 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1464 allAppsIconTextSizes[INDEX_DEFAULT]);
1465
Thales Lima83bedbf2021-10-05 17:47:39 +01001466 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1467 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001468 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1469 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1470 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001471 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001472 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001473 horizontalMargin[INDEX_DEFAULT]);
1474 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001475 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001476 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001477
Thales Limab8c05952022-05-23 16:58:38 +01001478 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1479 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001480 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001481 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1482 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1483 hotseatBarBottomSpace[INDEX_DEFAULT]);
1484 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1485 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1486 hotseatBarBottomSpace[INDEX_DEFAULT]);
1487 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1488 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1489 hotseatBarBottomSpace[INDEX_DEFAULT]);
1490
1491 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1492 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001493 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001494 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1495 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1496 hotseatQsbSpace[INDEX_DEFAULT]);
1497 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1498 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1499 hotseatQsbSpace[INDEX_DEFAULT]);
1500 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1501 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1502 hotseatQsbSpace[INDEX_DEFAULT]);
1503
Jon Miranda9c478b62023-03-23 21:38:49 -07001504 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1505 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1506 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1507 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1508 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1509 transientTaskbarIconSize[INDEX_DEFAULT]);
1510 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1511 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1512 transientTaskbarIconSize[INDEX_DEFAULT]);
1513 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1514 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001515 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001516
Jon Miranda04f05102023-04-04 12:16:31 -07001517 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1518 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1519 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1520 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1521 startAlignTaskbar[INDEX_DEFAULT]);
1522 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1523 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1524 startAlignTaskbar[INDEX_LANDSCAPE]);
1525 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1526 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1527 startAlignTaskbar[INDEX_DEFAULT]);
1528
Sunny Goyal415f1732018-11-29 10:33:47 -08001529 a.recycle();
1530 }
1531
1532 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001533 this(null);
1534 }
1535
1536 DisplayOption(GridOption grid) {
1537 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001538 minWidthDps = 0;
1539 minHeightDps = 0;
1540 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001541 for (int i = 0; i < COUNT_SIZES; i++) {
1542 iconSizes[i] = 0;
1543 textSizes[i] = 0;
1544 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001545 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001546 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001547 allAppsIconSizes[i] = 0;
1548 allAppsIconTextSizes[i] = 0;
1549 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001550 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001551 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001552 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001553 }
1554
1555 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001556 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001557 iconSizes[i] *= w;
1558 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001559 borderSpaces[i].x *= w;
1560 borderSpaces[i].y *= w;
1561 minCellSize[i].x *= w;
1562 minCellSize[i].y *= w;
1563 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001564 hotseatBarBottomSpace[i] *= w;
1565 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001566 allAppsCellSize[i].x *= w;
1567 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001568 allAppsIconSizes[i] *= w;
1569 allAppsIconTextSizes[i] *= w;
1570 allAppsBorderSpaces[i].x *= w;
1571 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001572 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001573 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001574
Sunny Goyal415f1732018-11-29 10:33:47 -08001575 return this;
1576 }
1577
1578 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001579 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001580 iconSizes[i] += p.iconSizes[i];
1581 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001582 borderSpaces[i].x += p.borderSpaces[i].x;
1583 borderSpaces[i].y += p.borderSpaces[i].y;
1584 minCellSize[i].x += p.minCellSize[i].x;
1585 minCellSize[i].y += p.minCellSize[i].y;
1586 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001587 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1588 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001589 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1590 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001591 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1592 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1593 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1594 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001595 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001596 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001597 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001598
Sunny Goyal415f1732018-11-29 10:33:47 -08001599 return this;
1600 }
1601 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001602}