blob: dddc43f913c47eb5e2f3df931f460796fcab9293 [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);
Charlie Andersonbad2be42024-12-06 16:32:03 -0500248 FileLog.d(TAG, "New InvariantDeviceProfile, before initGrid(): "
249 + "gridName:" + gridName
250 + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME)
251 + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE));
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800252 initGrid(context, gridName);
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700253 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100254 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000255 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700256 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
257 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100258 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700259 }
260 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700261 if (Flags.oneGridSpecs()) {
262 mLandscapeModePreferenceListener = (String s) -> {
fbarond1cd8c22024-11-26 10:13:36 -0800263 if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
264 MAIN_EXECUTOR.execute(() -> {
265 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
266 onConfigChanged(context.getApplicationContext());
267 Trace.endSection();
268 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700269 }
270 };
271 LauncherPrefs.INSTANCE.get(context).addListener(
272 mLandscapeModePreferenceListener,
273 FIXED_LANDSCAPE_MODE
274 );
275 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700276 }
277
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700278 /**
279 * This constructor should NOT have any monitors by design.
280 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800281 public InvariantDeviceProfile(Context context, String gridName) {
282 String newName = initGrid(context, gridName);
283 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000284 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800285 }
286 }
287
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700288 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800289 * This constructor should NOT have any monitors by design.
290 */
291 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700292 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100293 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700294 String gridName = getCurrentGridName(context);
295
296 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000297 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700298 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700299 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000300 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700301 getPredefinedDeviceProfiles(
302 context,
303 gridName,
304 defaultInfo,
305 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800306 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700307 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000308 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700309
Alex Chau661f02d2022-06-07 14:03:43 +0100310 Context displayContext = context.createDisplayContext(display);
311 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700312 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700313 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000314 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700315 getPredefinedDeviceProfiles(
316 context,
317 gridName,
318 myInfo,
319 /*allowDisabledGrid=*/false,
fbarond1cd8c22024-11-26 10:13:36 -0800320 FIXED_LANDSCAPE_MODE.get(context)
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700321 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000322 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700323
324 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
325 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100326 result.iconSizes[INDEX_DEFAULT] =
327 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
328 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700329 result.iconSizes[i] = Math.min(
330 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000331 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700332
Thales Lima83bedbf2021-10-05 17:47:39 +0100333 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
334 COUNT_SIZES);
335 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
336 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500337
Federico Baron56307d22024-11-06 18:48:48 +0000338 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800339 }
340
Sunny Goyal10fa0162024-04-21 00:13:35 -0700341 @Override
342 public void close() {
343 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700344 if (mLandscapeModePreferenceListener != null) {
345 LauncherPrefs.INSTANCE.executeIfCreated(
346 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
347 );
348 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700349 }
350
Tracy Zhou42255d22020-03-13 00:38:11 -0700351 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000352 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700353 }
354
Sunny Goyaleff44f32019-01-09 17:29:49 -0800355 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700356 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700357 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
358 context,
359 gridName,
360 displayInfo,
361 RestoreDbTask.isPending(context),
362 FIXED_LANDSCAPE_MODE.get(context)
363 );
fbaronebc10c92024-09-03 12:51:41 -0700364
365 // Filter out options that don't have the same number of columns as the grid
366 DeviceGridState deviceGridState = new DeviceGridState(context);
367 List<DisplayOption> allOptionsFilteredByColCount =
368 filterByColumnCount(allOptions, deviceGridState.getColumns());
369
Sunny Goyal19ff7282021-04-22 10:12:54 -0700370 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700371 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700372 ? new ArrayList<>(allOptions)
373 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000374 displayInfo.getDeviceType());
Sebastian Franco2b0cdbb2024-12-04 17:21:56 -0800375
376 if (!displayOption.grid.name.equals(gridName)) {
377 LauncherPrefs.get(context).put(GRID_NAME, displayOption.grid.name);
378 }
379
Federico Baron56307d22024-11-06 18:48:48 +0000380 initGrid(context, displayInfo, displayOption);
Charlie Andersonbad2be42024-12-06 16:32:03 -0500381 FileLog.d(TAG, "initGrid: "
382 + "gridName:" + gridName
383 + ", LauncherPrefs GRID_NAME:" + LauncherPrefs.get(context).get(GRID_NAME)
384 + ", LauncherPrefs DB_FILE:" + LauncherPrefs.get(context).get(DB_FILE));
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700385 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800386 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700387
fbaronebc10c92024-09-03 12:51:41 -0700388 private List<DisplayOption> filterByColumnCount(
389 List<DisplayOption> allOptions, int numColumns) {
390 return allOptions.stream().filter(
391 option -> option.grid.numColumns == numColumns).toList();
392 }
393
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700394 /**
395 * @deprecated This is a temporary solution because on the backup and restore case we modify the
396 * IDP, this resets it. b/332974074
397 */
398 @Deprecated
399 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700400 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700401 }
402
Thales Limab67bfa72022-11-02 15:30:11 +0000403 @VisibleForTesting
404 public static String getDefaultGridName(Context context) {
405 return new InvariantDeviceProfile().initGrid(context, null);
406 }
407
Federico Baron56307d22024-11-06 18:48:48 +0000408 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700409 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700410 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000411 numRows = closestProfile.numRows;
412 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000413 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000414 dbFile = closestProfile.dbFile;
415 defaultLayoutId = closestProfile.defaultLayoutId;
416 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300417
Sunny Goyalae190ff2020-04-14 00:19:01 +0000418 numFolderRows = closestProfile.numFolderRows;
419 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300420 folderStyle = closestProfile.folderStyle;
421
Thales Limad852d652023-01-17 14:01:13 +0000422 cellStyle = closestProfile.cellStyle;
423
Jon Mirandae126d722021-02-25 10:45:20 -0500424 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400425 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100426 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbarond1cd8c22024-11-26 10:13:36 -0800427 gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100428 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100429 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100430 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100431 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100432 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100433 hotseatSpecsId = closestProfile.mHotseatSpecsId;
434 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000435 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
436 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
437 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
438 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300439 numAllAppsRowsForCellHeightCalculation =
440 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000441 this.deviceType = displayInfo.getDeviceType();
442 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000443
Vinit Nayakc7293172022-07-18 16:41:50 -0700444 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
445
Thales Lima83bedbf2021-10-05 17:47:39 +0100446 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100447 float maxIconSize = iconSize[0];
448 for (int i = 1; i < iconSize.length; i++) {
449 maxIconSize = Math.max(maxIconSize, iconSize[i]);
450 }
451 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000452 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
453
Thales Lima83bedbf2021-10-05 17:47:39 +0100454 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700455
Thales Lima83bedbf2021-10-05 17:47:39 +0100456 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100457
Thales Lima83bedbf2021-10-05 17:47:39 +0100458 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100459
Thales Limad90faab2021-09-21 17:18:47 +0100460 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100461
Sunny Goyal19ff7282021-04-22 10:12:54 -0700462 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000463 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700464 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100465 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
466 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700467
Thales Limae9273ea2023-01-26 12:33:52 +0000468 allAppsStyle = closestProfile.allAppsStyle;
469
Sunny Goyal19ff7282021-04-22 10:12:54 -0700470 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300471
Alex Chau1c883d82021-12-01 18:43:10 +0000472 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700473 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500474
Thales Limab7ef5692022-03-10 10:32:36 +0000475 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000476 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
477 allAppsIconSize = displayOption.allAppsIconSizes;
478 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000479
Thales Lima11af7bc2022-08-12 15:24:54 +0100480 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000481
Jon Miranda9c478b62023-03-23 21:38:49 -0700482 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
483
Jon Miranda04f05102023-04-04 12:16:31 -0700484 startAlignTaskbar = displayOption.startAlignTaskbar;
485
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700486 // Fixed Landscape mode
fbarond1cd8c22024-11-26 10:13:36 -0800487 isFixedLandscape = closestProfile.mIsFixedLandscape;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700488
Sunny Goyalae190ff2020-04-14 00:19:01 +0000489 // If the partner customization apk contains any grid overrides, apply them
490 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700491 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700492
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000493 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700494 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700495 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700496 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000497 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000498 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000499 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700500 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000501 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700502
Sunny Goyal19ff7282021-04-22 10:12:54 -0700503 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
504 int displayWidth = bounds.bounds.width();
505 int displayHeight = bounds.bounds.height();
506 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700507
Sunny Goyal19ff7282021-04-22 10:12:54 -0700508 // We need to ensure that there is enough extra space in the wallpaper
509 // for the intended parallax effects
510 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300511 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
512 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700513 ? 2
514 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
515 defaultWallpaperSize.x =
516 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700517 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000518 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700519
Thales Lima6a590062022-11-22 15:52:49 +0000520 int numMinShownHotseatIconsForTablet = supportedProfiles
521 .stream()
522 .filter(deviceProfile -> deviceProfile.isTablet)
523 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
524 .min()
525 .orElse(0);
526
527 supportedProfiles
528 .stream()
529 .filter(deviceProfile -> deviceProfile.isTablet)
530 .forEach(deviceProfile -> {
531 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
532 deviceProfile.recalculateHotseatWidthAndBorderSpace();
533 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700534 }
535
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700536 public void addOnChangeListener(OnIDPChangeListener listener) {
537 mChangeListeners.add(listener);
538 }
539
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800540 public void removeOnChangeListener(OnIDPChangeListener listener) {
541 mChangeListeners.remove(listener);
542 }
543
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700544 /**
545 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
546 * migration.
547 */
548 public void setCurrentGrid(Context context, String newGridName) {
549 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700550 MAIN_EXECUTOR.execute(() -> {
551 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
552 onConfigChanged(context.getApplicationContext());
553 Trace.endSection();
554 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800555 }
556
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700557 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700558 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000559 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
560 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700561 }
562
Pat Manning24cec692023-10-13 10:36:57 +0000563 /** Updates IDP using the provided context. Notifies listeners of change. */
564 @VisibleForTesting
565 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700566 Object[] oldState = toModelState();
567
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700568 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700569 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700570 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700571
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700572 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700573 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700574 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700575 }
576 }
577
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700578 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
579 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
580 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaronc1b68f42024-11-08 18:10:46 -0800581 && gridOption.filterByFlag(deviceType, isFixedLandscapeMode);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700582 }
583
584 private static List<DisplayOption> getPredefinedDeviceProfiles(
585 Context context,
586 String gridName,
587 Info displayInfo,
588 boolean allowDisabledGrid,
589 boolean isFixedLandscapeMode
590 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800591 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100592
Alex Chau1c883d82021-12-01 18:43:10 +0000593 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700594 final int depth = parser.getDepth();
595 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700596 while (((type = parser.next()) != XmlPullParser.END_TAG ||
597 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800598 if ((type == XmlPullParser.START_TAG)
599 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000600 GridOption gridOption = new GridOption(
601 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700602 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
603 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100604 final int displayDepth = parser.getDepth();
605 while (((type = parser.next()) != XmlPullParser.END_TAG
606 || parser.getDepth() > displayDepth)
607 && type != XmlPullParser.END_DOCUMENT) {
608 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
609 parser.getName())) {
610 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100611 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100612 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800613 }
614 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700615 }
616 }
sfufa@google.comde013292021-09-21 18:22:44 -0700617 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700618 throw new RuntimeException(e);
619 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000620 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800621 if (!TextUtils.isEmpty(gridName)) {
622 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000623 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
624 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000625 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800626 }
627 }
628 }
fbaronebc10c92024-09-03 12:51:41 -0700629 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
630 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000631 for (DisplayOption option : profiles) {
632 if (option.canBeDefault) {
633 filteredProfiles.add(option);
634 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800635 }
fbaronebc10c92024-09-03 12:51:41 -0700636 } else if (filteredProfiles.isEmpty()) {
637 // In this case we had a grid selected but we couldn't find it.
638 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800639 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000640 if (filteredProfiles.isEmpty()) {
641 throw new RuntimeException("No display option with canBeDefault=true");
642 }
643 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700644 }
645
Thales Lima7ec83822021-08-05 13:32:10 +0100646 /**
fbarond1cd8c22024-11-26 10:13:36 -0800647 * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
648 * correct grid size for this GridOption.
fbaronebc10c92024-09-03 12:51:41 -0700649 *
fbarond1cd8c22024-11-26 10:13:36 -0800650 * @return the result of {@link #findBestGridSize(List, int, int)}.
fbaronebc10c92024-09-03 12:51:41 -0700651 */
fbarond1cd8c22024-11-26 10:13:36 -0800652 private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000653 Info displayInfo) {
fbarond1cd8c22024-11-26 10:13:36 -0800654 ArrayList<GridSize> gridSizes = new ArrayList<>();
fbaronebc10c92024-09-03 12:51:41 -0700655
656 try (XmlResourceParser parser = resourceHelper.getXml()) {
657 final int depth = parser.getDepth();
658 int type;
659 while (((type = parser.next()) != XmlPullParser.END_TAG
660 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
661 if ((type == XmlPullParser.START_TAG)
fbarond1cd8c22024-11-26 10:13:36 -0800662 && "GridSize".equals(parser.getName())) {
663 gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
fbaronebc10c92024-09-03 12:51:41 -0700664 }
665 }
666 } catch (IOException | XmlPullParserException e) {
667 throw new RuntimeException(e);
668 }
669
fbaron49358342024-11-22 17:38:56 -0800670 // Finds the min width and height in dp for all displays.
671 int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);
672
fbarond1cd8c22024-11-26 10:13:36 -0800673 return findBestGridSize(gridSizes, dimens[0], dimens[1]);
fbaronebc10c92024-09-03 12:51:41 -0700674 }
675
676 /**
fbarond1cd8c22024-11-26 10:13:36 -0800677 * @return the biggest grid size that fits the display dimensions.
678 * If no best grid size is found, return null.
fbaronebc10c92024-09-03 12:51:41 -0700679 */
fbarond1cd8c22024-11-26 10:13:36 -0800680 private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
fbaron49358342024-11-22 17:38:56 -0800681 int minHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800682 GridSize selectedGridSize = null;
683 for (GridSize item: list) {
fbaron49358342024-11-22 17:38:56 -0800684 if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
fbarond1cd8c22024-11-26 10:13:36 -0800685 if (selectedGridSize == null
686 || (selectedGridSize.mNumColumns <= item.mNumColumns
687 && selectedGridSize.mNumRows <= item.mNumRows)) {
688 selectedGridSize = item;
fbaron49358342024-11-22 17:38:56 -0800689 }
690 }
691 }
fbarond1cd8c22024-11-26 10:13:36 -0800692 return selectedGridSize;
fbaron49358342024-11-22 17:38:56 -0800693 }
694
695 private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
fbaron9ce45ba2024-12-03 02:17:00 -0800696 int minDisplayWidthDp = Integer.MAX_VALUE;
697 int minDisplayHeightDp = Integer.MAX_VALUE;
698 for (CachedDisplayInfo display: displayInfo.getAllDisplays()) {
699 minDisplayWidthDp = Math.min(minDisplayWidthDp,
700 (int) dpiFromPx(display.size.x, DisplayMetrics.DENSITY_DEVICE_STABLE));
701 minDisplayHeightDp = Math.min(minDisplayHeightDp,
702 (int) dpiFromPx(display.size.y, DisplayMetrics.DENSITY_DEVICE_STABLE));
fbaronebc10c92024-09-03 12:51:41 -0700703 }
fbaron9ce45ba2024-12-03 02:17:00 -0800704 return new int[]{minDisplayWidthDp, minDisplayHeightDp};
fbaronebc10c92024-09-03 12:51:41 -0700705 }
706
707 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000708 * Returns the GridOption associated to the given file name or null if the fileName is not
709 * supported.
710 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
711 */
712 public GridOption getGridOptionFromFileName(Context context, String fileName) {
713 return parseAllGridOptions(context).stream()
714 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
715 .findFirst()
716 .orElse(null);
717 }
718
719 /**
720 * Returns the name of the given size on the current device or empty string if the size is not
721 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
722 * (Note: the name of the grid can be different for the same grid size depending of
723 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000724 */
725 public String getGridNameFromSize(Context context, Point size) {
726 return parseAllGridOptions(context).stream()
727 .filter(gridOption -> gridOption.numColumns == size.x
728 && gridOption.numRows == size.y)
729 .map(gridOption -> gridOption.name)
730 .findFirst()
731 .orElse("");
732 }
733
734 /**
735 * Returns the grid option for the given gridName on the current device (Note: the gridOption
736 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
737 */
738 public GridOption getGridOptionFromName(Context context, String gridName) {
739 return parseAllGridOptions(context).stream()
740 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
741 .findFirst()
742 .orElse(null);
743 }
744
745 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100746 * @return all the grid options that can be shown on the device
747 */
748 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000749 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700750 .stream()
751 .filter(go -> go.isEnabled(deviceType))
fbarond1cd8c22024-11-26 10:13:36 -0800752 .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700753 .collect(Collectors.toList());
754 }
755
756 /**
757 * @return all the grid options that can be shown on the device
758 */
Federico Baron56307d22024-11-06 18:48:48 +0000759 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100760 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000761 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100762 final int depth = parser.getDepth();
763 int type;
764 while (((type = parser.next()) != XmlPullParser.END_TAG
765 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
766 if ((type == XmlPullParser.START_TAG)
767 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000768 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100769 }
770 }
771 } catch (IOException | XmlPullParserException e) {
772 Log.e(TAG, "Error parsing device profile", e);
773 return Collections.emptyList();
774 }
775 return result;
776 }
777
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700778 private int getLauncherIconDensity(int requiredSize) {
779 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700780 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700781 DisplayMetrics.DENSITY_LOW,
782 DisplayMetrics.DENSITY_MEDIUM,
783 DisplayMetrics.DENSITY_TV,
784 DisplayMetrics.DENSITY_HIGH,
785 DisplayMetrics.DENSITY_XHIGH,
786 DisplayMetrics.DENSITY_XXHIGH,
787 DisplayMetrics.DENSITY_XXXHIGH
788 };
789
790 int density = DisplayMetrics.DENSITY_XXXHIGH;
791 for (int i = densityBuckets.length - 1; i >= 0; i--) {
792 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
793 / DisplayMetrics.DENSITY_DEFAULT;
794 if (expectedSize >= requiredSize) {
795 density = densityBuckets[i];
796 }
797 }
798
799 return density;
800 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700801
Adam Cohen2e6da152015-05-06 11:42:25 -0700802 /**
803 * Apply any Partner customization grid overrides.
804 *
805 * Currently we support: all apps row / column count.
806 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700807 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
808 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800809 if (p == null) {
810 return;
811 }
812 try {
813 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
814 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
815 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
816
817 if (numRows > 0 && numColumns > 0) {
818 this.numRows = numRows;
819 this.numColumns = numColumns;
820 }
821 if (iconSizePx > 0) {
822 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
823 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
824 }
825 } catch (Resources.NotFoundException ex) {
826 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700827 }
828 }
829
Sunny Goyal415f1732018-11-29 10:33:47 -0800830 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700831 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700832 }
833
Sunny Goyal19ff7282021-04-22 10:12:54 -0700834 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700835 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700836 int minWidthPx = Integer.MAX_VALUE;
837 int minHeightPx = Integer.MAX_VALUE;
838 for (WindowBounds bounds : displayInfo.supportedBounds) {
839 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000840 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700841 // For split displays, take half width per page
842 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
843 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700844
Sunny Goyal19ff7282021-04-22 10:12:54 -0700845 } else if (!isTablet && bounds.isLandscape()) {
846 // We will use transposed layout in this case
847 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
848 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
849 } else {
850 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
851 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
852 }
853 }
854
Thales Lima425f6822022-05-10 13:44:58 -0300855 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
856 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700857
858 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700859 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700860 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
861 dist(width, height, b.minWidthDps, b.minHeightDps)));
862
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700863 DisplayOption closestPoint = points.get(0);
864 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700865 float weights = 0;
866
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700867 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
868 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700869 }
870
871 DisplayOption out = new DisplayOption(closestOption);
872 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700873 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700874 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
875 weights += w;
876 out.add(new DisplayOption().add(p).multiply(w));
877 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700878 out.multiply(1.0f / weights);
879
Thales Lima6e0005a2021-10-27 15:53:41 +0100880 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700881 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100882 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
883 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700884 }
885
886 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700887 }
888
Sunny Goyal27835952017-01-13 12:15:53 -0800889 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000890 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
891 Rect bounds = windowManagerProxy.getCurrentBounds(context);
892 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700893
Alex Chauc09a98a2023-11-14 12:51:42 +0000894 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400895 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700896
Sunny Goyal187b16c2022-03-01 16:53:23 -0800897 /**
898 * Returns the device profile matching the provided screen configuration
899 */
900 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700901 DeviceProfile bestMatch = supportedProfiles.get(0);
902 float minDiff = Float.MAX_VALUE;
903
904 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400905 float diff = Math.abs(profile.widthPx - screenWidth)
906 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700907 if (diff < minDiff) {
908 minDiff = diff;
909 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800910 } else if (diff == minDiff && profile.rotationHint == rotation) {
911 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700912 }
913 }
914 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800915 }
916
Sunny Goyal415f1732018-11-29 10:33:47 -0800917 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700918 float d = dist(x0, y0, x1, y1);
919 if (Float.compare(d, 0f) == 0) {
920 return Float.POSITIVE_INFINITY;
921 }
922 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
923 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700924
925 /**
926 * As a ratio of screen height, the total distance we want the parallax effect to span
927 * horizontally
928 */
929 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
930 float aspectRatio = width / (float) height;
931
932 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
933 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
934 // We will use these two data points to extrapolate how much the wallpaper parallax effect
935 // to span (ie travel) at any aspect ratio:
936
sfufa@google.comde013292021-09-21 18:22:44 -0700937 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
938 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700939 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
940 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
941
942 // To find out the desired width at different aspect ratios, we use the following two
943 // formulas, where the coefficient on x is the aspect ratio (width/height):
944 // (16/10)x + y = 1.5
945 // (10/16)x + y = 1.2
946 // We solve for x and y and end up with a final formula:
947 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700948 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
949 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700950 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
951 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
952 return x * aspectRatio + y;
953 }
954
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700955 public interface OnIDPChangeListener {
956
Sunny Goyalb47172b2021-05-03 19:59:51 -0700957 /**
958 * Called when the device provide changes
959 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700960 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700961 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800962
963
Sunny Goyaleff44f32019-01-09 17:29:49 -0800964 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800965
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800966 public static final String TAG_NAME = "grid-option";
967
Alex Chau1c883d82021-12-01 18:43:10 +0000968 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
969 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
970 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
971 private static final int DEVICE_CATEGORY_ALL =
972 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
973
Thales Lima11af7bc2022-08-12 15:24:54 +0100974 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
975 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
976 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
977 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
978 private static final int DONT_INLINE_QSB = 0;
979
Sunny Goyaleff44f32019-01-09 17:29:49 -0800980 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700981 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800982 public final int numRows;
983 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000984 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700985 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800986
Thales Lima1faa4ed2023-12-01 16:48:19 +0000987 private final int[] numFolderRows = new int[COUNT_SIZES];
988 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300989 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000990 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800991
Thales Limae9273ea2023-01-26 12:33:52 +0000992 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700993 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300994 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700995 private final int numDatabaseAllAppsColumns;
996 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700997 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100998
Thales Lima11af7bc2022-08-12 15:24:54 +0100999 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
1000
Thales Limab35faed2022-09-05 16:30:01 -03001001 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001002 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001003
Sunny Goyal415f1732018-11-29 10:33:47 -08001004 private final int defaultLayoutId;
1005 private final int demoModeLayoutId;
1006
Jon Mirandae126d722021-02-25 10:45:20 -05001007 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001008 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001009 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001010 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001011 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001012 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001013 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001014 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001015 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001016 private final int mHotseatSpecsId;
1017 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001018 private final int mWorkspaceCellSpecsId;
1019 private final int mWorkspaceCellSpecsTwoPanelId;
1020 private final int mAllAppsCellSpecsId;
1021 private final int mAllAppsCellSpecsTwoPanelId;
fbarond1cd8c22024-11-26 10:13:36 -08001022 private final int mGridSizeSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001023 private final boolean mIsFixedLandscape;
fbaron6c91ef92024-11-12 22:22:43 -08001024 private final boolean mIsOldGrid;
Jon Mirandae126d722021-02-25 10:45:20 -05001025
Federico Baron56307d22024-11-06 18:48:48 +00001026 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001027 TypedArray a = context.obtainStyledAttributes(
1028 attrs, R.styleable.GridDisplayOption);
1029 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001030 title = a.getString(R.styleable.GridDisplayOption_title);
1031 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1032 DEVICE_CATEGORY_ALL);
fbarond1cd8c22024-11-26 10:13:36 -08001033 mGridSizeSpecsId = a.getResourceId(
1034 R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001035 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbarond1cd8c22024-11-26 10:13:36 -08001036 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
1037 ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
1038 GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
1039 numColumns = gridSize.mNumColumns;
1040 numRows = gridSize.mNumRows;
1041 dbFile = gridSize.mDbFile;
1042 defaultLayoutId = gridSize.mDefaultLayoutId;
1043 demoModeLayoutId = gridSize.mDemoModeLayoutId;
fbaronebc10c92024-09-03 12:51:41 -07001044 } else {
1045 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
fbarond1cd8c22024-11-26 10:13:36 -08001046 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
fbaronebc10c92024-09-03 12:51:41 -07001047 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001048 defaultLayoutId = a.getResourceId(
1049 R.styleable.GridDisplayOption_defaultLayoutId, 0);
1050 demoModeLayoutId = a.getResourceId(
1051 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001052 }
1053
Alex Chau9fee3fd2021-12-01 18:43:10 +00001054 numSearchContainerColumns = a.getInt(
1055 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001056
Thales Limae9273ea2023-01-26 12:33:52 +00001057 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1058 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001059 numAllAppsColumns = a.getInt(
1060 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1061 numDatabaseAllAppsColumns = a.getInt(
1062 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1063
1064 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001065 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001066 numDatabaseHotseatIcons = a.getInt(
1067 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001068
Vinit Nayakc7293172022-07-18 16:41:50 -07001069 inlineNavButtonsEndSpacing =
1070 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001071 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001072
Thales Lima1faa4ed2023-12-01 16:48:19 +00001073 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001074 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001075 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001076 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001077
Thales Lima1faa4ed2023-12-01 16:48:19 +00001078 if (FeatureFlags.enableResponsiveWorkspace()) {
1079 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1080 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1081 numFolderRows[INDEX_DEFAULT]);
1082 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1083 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1084 numFolderColumns[INDEX_DEFAULT]);
1085 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1086 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1087 numFolderRows[INDEX_DEFAULT]);
1088 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1089 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1090 numFolderColumns[INDEX_DEFAULT]);
1091 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1092 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1093 numFolderRows[INDEX_DEFAULT]);
1094 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1095 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1096 numFolderColumns[INDEX_DEFAULT]);
1097 } else {
1098 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1099 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1100 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1101 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1102 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1103 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1104 }
1105
Thales Limab35faed2022-09-05 16:30:01 -03001106 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1107 INVALID_RESOURCE_HANDLE);
1108
Thales Limad852d652023-01-17 14:01:13 +00001109 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1110 R.style.CellStyleDefault);
1111
Jon Mirandae126d722021-02-25 10:45:20 -05001112 isScalable = a.getBoolean(
1113 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001114 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001115 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001116
Thales Limaca31b612023-09-14 14:25:26 +01001117 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001118 mWorkspaceSpecsId = a.getResourceId(
1119 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001120 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1121 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001122 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001123 mAllAppsSpecsId = a.getResourceId(
1124 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001125 mAllAppsSpecsTwoPanelId = a.getResourceId(
1126 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001127 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001128 mFolderSpecsId = a.getResourceId(
1129 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001130 mFolderSpecsTwoPanelId = a.getResourceId(
1131 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001132 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001133 mHotseatSpecsId = a.getResourceId(
1134 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1135 mHotseatSpecsTwoPanelId = a.getResourceId(
1136 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001137 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001138 mWorkspaceCellSpecsId = a.getResourceId(
1139 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1140 INVALID_RESOURCE_HANDLE);
1141 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1142 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001143 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001144 mAllAppsCellSpecsId = a.getResourceId(
1145 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1146 INVALID_RESOURCE_HANDLE);
1147 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1148 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001149 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001150 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1151 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1152 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001153 } else {
1154 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001155 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001156 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001157 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001158 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001159 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001160 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1161 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001162 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1163 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1164 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1165 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001166 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001167 }
1168
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001169 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
fbaron6c91ef92024-11-12 22:22:43 -08001170 mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001171
Thales Lima11af7bc2022-08-12 15:24:54 +01001172 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1173 DONT_INLINE_QSB);
1174 inlineQsb[INDEX_DEFAULT] =
1175 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1176 inlineQsb[INDEX_LANDSCAPE] =
1177 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1178 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1179 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1180 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1181 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1182 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1183 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1184
Sunny Goyal415f1732018-11-29 10:33:47 -08001185 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001186 }
1187
1188 public boolean isEnabled(@DeviceType int deviceType) {
1189 switch (deviceType) {
1190 case TYPE_PHONE:
1191 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1192 case TYPE_TABLET:
1193 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1194 case TYPE_MULTI_DISPLAY:
1195 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1196 == DEVICE_CATEGORY_MULTI_DISPLAY;
1197 default:
1198 return false;
1199 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001200 }
fbaronebc10c92024-09-03 12:51:41 -07001201
fbaron6c91ef92024-11-12 22:22:43 -08001202 /**
1203 * Returns true if the grid option should be used given the flags that are toggled on/off.
1204 */
fbaronc1b68f42024-11-08 18:10:46 -08001205 public boolean filterByFlag(int deviceType, boolean isFixedLandscape) {
fbaron49f7df02024-11-05 16:15:19 -08001206 if (deviceType == TYPE_TABLET) {
1207 return Flags.oneGridRotationHandling() == mIsDualGrid;
1208 }
fbaronc1b68f42024-11-08 18:10:46 -08001209
fbaron6c91ef92024-11-12 22:22:43 -08001210 // Here we return true if fixed landscape mode should be on.
1211 if (mIsFixedLandscape || isFixedLandscape) {
1212 return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs();
fbaronc1b68f42024-11-08 18:10:46 -08001213 }
1214
fbaron6c91ef92024-11-12 22:22:43 -08001215 // Here we return true if we want to show the new grids.
fbarond1cd8c22024-11-26 10:13:36 -08001216 if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
fbaron6c91ef92024-11-12 22:22:43 -08001217 return Flags.oneGridSpecs();
1218 }
1219
1220 // Here we return true if we want to show the old grids.
1221 if (mIsOldGrid) {
1222 return !Flags.oneGridSpecs();
1223 }
1224
1225 return true;
fbaron49f7df02024-11-05 16:15:19 -08001226 }
fbaronebc10c92024-09-03 12:51:41 -07001227 }
1228
fbarond1cd8c22024-11-26 10:13:36 -08001229 public static final class GridSize {
1230 final int mNumRows;
1231 final int mNumColumns;
1232 final float mMinDeviceWidthDp;
1233 final float mMinDeviceHeightDp;
fbaronebc10c92024-09-03 12:51:41 -07001234 final String mDbFile;
fbaronc1b68f42024-11-08 18:10:46 -08001235 final int mDefaultLayoutId;
1236 final int mDemoModeLayoutId;
1237
fbaronebc10c92024-09-03 12:51:41 -07001238
fbarond1cd8c22024-11-26 10:13:36 -08001239 GridSize(Context context, AttributeSet attrs) {
1240 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);
fbaronebc10c92024-09-03 12:51:41 -07001241
fbarond1cd8c22024-11-26 10:13:36 -08001242 mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
1243 mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
1244 mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
1245 mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
1246 mDbFile = a.getString(R.styleable.GridSize_dbFile);
fbaronc1b68f42024-11-08 18:10:46 -08001247 mDefaultLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001248 R.styleable.GridSize_defaultLayoutId, 0);
fbaronc1b68f42024-11-08 18:10:46 -08001249 mDemoModeLayoutId = a.getResourceId(
fbarond1cd8c22024-11-26 10:13:36 -08001250 R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);
fbaronebc10c92024-09-03 12:51:41 -07001251
1252 a.recycle();
1253 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001254 }
1255
Sunny Goyal19ff7282021-04-22 10:12:54 -07001256 @VisibleForTesting
1257 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001258 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001259
Sunny Goyal415f1732018-11-29 10:33:47 -08001260 private final float minWidthDps;
1261 private final float minHeightDps;
1262 private final boolean canBeDefault;
1263
Thales Lima83bedbf2021-10-05 17:47:39 +01001264 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001265
Thales Lima78d00ad2021-09-30 11:29:06 +01001266 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001267 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001268 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1269 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001270
Thales Lima78d00ad2021-09-30 11:29:06 +01001271 private final float[] iconSizes = new float[COUNT_SIZES];
1272 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001273
Thales Limab7ef5692022-03-10 10:32:36 +00001274 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001275 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1276 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1277 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1278
Jon Miranda9c478b62023-03-23 21:38:49 -07001279 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1280
Jon Miranda04f05102023-04-04 12:16:31 -07001281 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1282
Thales Lima1de4d552021-10-13 16:13:25 +01001283 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001284 this.grid = grid;
1285
Jon Miranda9c478b62023-03-23 21:38:49 -07001286 Resources res = context.getResources();
1287
Thales Lima1de4d552021-10-13 16:13:25 +01001288 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001289
Sunny Goyal415f1732018-11-29 10:33:47 -08001290 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1291 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001292
Thales Lima1de4d552021-10-13 16:13:25 +01001293 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001294
Thales Lima83bedbf2021-10-05 17:47:39 +01001295 float x;
1296 float y;
1297
Thales Lima85c942f2021-12-31 13:04:20 +00001298 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1299 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001300 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001301
1302 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1303 minCellSize[INDEX_DEFAULT].x);
1304 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1305 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001306 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001307
Thales Lima85c942f2021-12-31 13:04:20 +00001308 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001309 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001310 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001311 minCellSize[INDEX_DEFAULT].y);
1312 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1313
Thales Lima85c942f2021-12-31 13:04:20 +00001314 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001315 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001316 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001317 minCellSize[INDEX_DEFAULT].y);
1318 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001319
Thales Lima85c942f2021-12-31 13:04:20 +00001320 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001321 float borderSpaceLandscape = a.getFloat(
1322 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001323 float borderSpaceTwoPanelPortrait = a.getFloat(
1324 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1325 float borderSpaceTwoPanelLandscape = a.getFloat(
1326 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001327
Thales Lima85c942f2021-12-31 13:04:20 +00001328 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1329 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001330 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001331
1332 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1333 borderSpaceLandscape);
1334 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1335 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001336 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1337
1338 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001339 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1340 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001341 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001342 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1343 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001344 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1345
1346 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001347 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1348 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001349 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001350 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1351 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001352 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1353
Thales Limab7ef5692022-03-10 10:32:36 +00001354 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1355 minCellSize[INDEX_DEFAULT].x);
1356 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1357 minCellSize[INDEX_DEFAULT].y);
1358 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1359
1360 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1361 allAppsCellSize[INDEX_DEFAULT].x);
1362 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1363 allAppsCellSize[INDEX_DEFAULT].y);
1364 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1365
1366 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1367 allAppsCellSize[INDEX_DEFAULT].x);
1368 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1369 allAppsCellSize[INDEX_DEFAULT].y);
1370 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1371
1372 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1373 allAppsCellSize[INDEX_DEFAULT].x);
1374 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1375 allAppsCellSize[INDEX_DEFAULT].y);
1376 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1377
Thales Lima080d8902022-03-28 15:30:29 +01001378 float allAppsBorderSpace = a.getFloat(
1379 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1380 float allAppsBorderSpaceLandscape = a.getFloat(
1381 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1382 allAppsBorderSpace);
1383 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001384 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001385 allAppsBorderSpace);
1386 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001387 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001388 allAppsBorderSpace);
1389
1390 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1391 allAppsBorderSpace);
1392 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1393 allAppsBorderSpace);
1394 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1395
1396 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1397 allAppsBorderSpaceLandscape);
1398 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1399 allAppsBorderSpaceLandscape);
1400 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1401
1402 x = a.getFloat(
1403 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1404 allAppsBorderSpaceTwoPanelPortrait);
1405 y = a.getFloat(
1406 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1407 allAppsBorderSpaceTwoPanelPortrait);
1408 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1409
1410 x = a.getFloat(
1411 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1412 allAppsBorderSpaceTwoPanelLandscape);
1413 y = a.getFloat(
1414 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1415 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001416 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001417
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001418 iconSizes[INDEX_DEFAULT] =
1419 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1420 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001421 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001422 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001423 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001424 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001425 iconSizes[INDEX_DEFAULT]);
1426 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001427 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001428 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001429
Thales Limabb7d3882021-12-22 12:56:29 +00001430 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1431 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001432 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1433 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001434 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001435 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1436 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1437 allAppsIconSizes[INDEX_DEFAULT]);
1438 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1439 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1440 allAppsIconSizes[INDEX_DEFAULT]);
1441
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001442 textSizes[INDEX_DEFAULT] =
1443 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1444 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001445 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001446 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001447 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001448 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001449 textSizes[INDEX_DEFAULT]);
1450 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001451 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001452 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001453
Thales Limabb7d3882021-12-22 12:56:29 +00001454 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1455 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1456 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1457 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1458 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1459 allAppsIconTextSizes[INDEX_DEFAULT]);
1460 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1461 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1462 allAppsIconTextSizes[INDEX_DEFAULT]);
1463
Thales Lima83bedbf2021-10-05 17:47:39 +01001464 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1465 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001466 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1467 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1468 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001469 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001470 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001471 horizontalMargin[INDEX_DEFAULT]);
1472 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001473 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001474 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001475
Thales Limab8c05952022-05-23 16:58:38 +01001476 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1477 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001478 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001479 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1480 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1481 hotseatBarBottomSpace[INDEX_DEFAULT]);
1482 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1483 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1484 hotseatBarBottomSpace[INDEX_DEFAULT]);
1485 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1486 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1487 hotseatBarBottomSpace[INDEX_DEFAULT]);
1488
1489 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1490 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001491 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001492 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1493 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1494 hotseatQsbSpace[INDEX_DEFAULT]);
1495 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1496 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1497 hotseatQsbSpace[INDEX_DEFAULT]);
1498 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1499 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1500 hotseatQsbSpace[INDEX_DEFAULT]);
1501
Jon Miranda9c478b62023-03-23 21:38:49 -07001502 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1503 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1504 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1505 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1506 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1507 transientTaskbarIconSize[INDEX_DEFAULT]);
1508 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1509 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1510 transientTaskbarIconSize[INDEX_DEFAULT]);
1511 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1512 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001513 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001514
Jon Miranda04f05102023-04-04 12:16:31 -07001515 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1516 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1517 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1518 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1519 startAlignTaskbar[INDEX_DEFAULT]);
1520 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1521 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1522 startAlignTaskbar[INDEX_LANDSCAPE]);
1523 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1524 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1525 startAlignTaskbar[INDEX_DEFAULT]);
1526
Sunny Goyal415f1732018-11-29 10:33:47 -08001527 a.recycle();
1528 }
1529
1530 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001531 this(null);
1532 }
1533
1534 DisplayOption(GridOption grid) {
1535 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001536 minWidthDps = 0;
1537 minHeightDps = 0;
1538 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001539 for (int i = 0; i < COUNT_SIZES; i++) {
1540 iconSizes[i] = 0;
1541 textSizes[i] = 0;
1542 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001543 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001544 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001545 allAppsIconSizes[i] = 0;
1546 allAppsIconTextSizes[i] = 0;
1547 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001548 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001549 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001550 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001551 }
1552
1553 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001554 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001555 iconSizes[i] *= w;
1556 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001557 borderSpaces[i].x *= w;
1558 borderSpaces[i].y *= w;
1559 minCellSize[i].x *= w;
1560 minCellSize[i].y *= w;
1561 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001562 hotseatBarBottomSpace[i] *= w;
1563 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001564 allAppsCellSize[i].x *= w;
1565 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001566 allAppsIconSizes[i] *= w;
1567 allAppsIconTextSizes[i] *= w;
1568 allAppsBorderSpaces[i].x *= w;
1569 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001570 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001571 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001572
Sunny Goyal415f1732018-11-29 10:33:47 -08001573 return this;
1574 }
1575
1576 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001577 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001578 iconSizes[i] += p.iconSizes[i];
1579 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001580 borderSpaces[i].x += p.borderSpaces[i].x;
1581 borderSpaces[i].y += p.borderSpaces[i].y;
1582 minCellSize[i].x += p.minCellSize[i].x;
1583 minCellSize[i].y += p.minCellSize[i].y;
1584 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001585 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1586 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001587 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1588 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001589 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1590 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1591 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1592 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001593 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001594 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001595 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001596
Sunny Goyal415f1732018-11-29 10:33:47 -08001597 return this;
1598 }
1599 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001600}