blob: 3a29727785c6f9f59628fd060403335e3e7e0c4c [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
Stefan Andonian4c9612b2023-02-22 00:00:03 +000019import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070020import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030021import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070023import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000024import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070025import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070026import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080027import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070028
Sunny Goyalc6205602015-05-21 20:46:33 -070029import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070030import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000036import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070037import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080038import android.text.TextUtils;
39import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070040import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010041import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080042import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070043import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080044import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070045
Thales Limab35faed2022-09-05 16:30:01 -030046import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000047import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030048import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070049import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000050import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010051import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070052
Thales Limaec5abba2023-04-05 16:33:50 +010053import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070054import com.android.launcher3.icons.DotRenderer;
Charlie Andersonc9d11e82023-08-02 11:41:55 -040055import com.android.launcher3.logging.FileLog;
Sunny Goyal68031ca2021-08-02 12:23:44 -070056import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010057import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070058import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070059import com.android.launcher3.util.DisplayController;
60import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070061import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080062import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070063import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070064import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070065import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080066import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070067
Sunny Goyal819e1932016-07-07 16:43:58 -070068import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70
71import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000072import java.lang.annotation.Retention;
73import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070074import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070075import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080076import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070077import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000078import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070079import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Sunny Goyal10fa0162024-04-21 00:13:35 -070081public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070084 // We do not need any synchronization for this variable as its only written on UI thread.
85 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070086 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070087
Alex Chau1c883d82021-12-01 18:43:10 +000088 @Retention(RetentionPolicy.SOURCE)
89 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010090 public @interface DeviceType {}
91
Alex Chau1c883d82021-12-01 18:43:10 +000092 public static final int TYPE_PHONE = 0;
93 public static final int TYPE_MULTI_DISPLAY = 1;
94 public static final int TYPE_TABLET = 2;
95
Sunny Goyal53d7ee42015-05-22 12:25:45 -070096 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
97
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070098 // Constants that affects the interpolation curve between statically defined device profile
99 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800100 private static final float KNEARESTNEIGHBOR = 3;
101 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700102
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700103 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800104 private static final float WEIGHT_EFFICIENT = 100000f;
105
Thales Lima83bedbf2021-10-05 17:47:39 +0100106 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
107 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000108 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100109 static final int INDEX_DEFAULT = 0;
110 static final int INDEX_LANDSCAPE = 1;
111 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
112 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100113
Thales Limaec5abba2023-04-05 16:33:50 +0100114 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800115 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
116 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
117 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
118
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700119 /**
120 * Number of icons per row and column in the workspace.
121 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700122 public int numRows;
123 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000124 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700125
126 /**
127 * Number of icons per row and column in the folder.
128 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000129 public int[] numFolderRows;
130 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100131 public float[] iconSize;
132 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700133 public int iconBitmapSize;
134 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000135 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700136
Thales Lima83bedbf2021-10-05 17:47:39 +0100137 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100138
Thales Lima83bedbf2021-10-05 17:47:39 +0100139 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300140 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100141
Thales Limab35faed2022-09-05 16:30:01 -0300142 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100143
Thales Limad852d652023-01-17 14:01:13 +0000144 public @StyleRes int cellStyle;
145
Thales Lima83bedbf2021-10-05 17:47:39 +0100146 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500147
Thales Limab7ef5692022-03-10 10:32:36 +0000148 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000149 public float[] allAppsIconSize;
150 public float[] allAppsIconTextSize;
151 public PointF[] allAppsBorderSpaces;
152
Jon Miranda9c478b62023-03-23 21:38:49 -0700153 public float[] transientTaskbarIconSize;
154
Jon Miranda04f05102023-04-04 12:16:31 -0700155 public boolean[] startAlignTaskbar;
156
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700157 /**
158 * Number of icons inside the hotseat area.
159 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800160 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700161
162 /**
163 * Number of icons inside the hotseat area that is stored in the database. This is greater than
164 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
165 * sizes that share the same DB.
166 */
167 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700168
Thales Limab8c05952022-05-23 16:58:38 +0100169 public float[] hotseatBarBottomSpace;
170 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300171
Jon Miranda6f7e9702019-09-16 14:44:14 -0700172 /**
173 * Number of columns in the all apps list.
174 */
175 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300176 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700177 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000178 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700179
Jon Mirandae126d722021-02-25 10:45:20 -0500180 /**
181 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
182 */
183 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000184 @XmlRes
185 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100186 @XmlRes
187 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100188 @XmlRes
fbaronebc10c92024-09-03 12:51:41 -0700189 public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
190 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100191 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
192 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100193 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100194 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100195 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
196 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100197 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100198 @XmlRes
199 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000200 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100201 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000202 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100203 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000204 @XmlRes
205 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
206 @XmlRes
207 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
208 @XmlRes
209 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
210 @XmlRes
211 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500212
Tracy Zhou7df93d22020-01-27 13:44:06 -0800213 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800214 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700215 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100216 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700217
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000218 /**
219 * An immutable list of supported profiles.
220 */
221 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700222
Sunny Goyal6f866092016-03-17 17:04:15 -0700223 public Point defaultWallpaperSize;
224
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700225 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700226
Sunny Goyalf633ef52018-03-13 09:57:05 -0700227 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800228 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700229
Sunny Goyalbbf01842015-10-08 07:41:15 -0700230 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700231 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700232 String gridName = getCurrentGridName(context);
233 String newGridName = initGrid(context, gridName);
234 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000235 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236 }
237
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700238 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100239 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000240 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700241 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
242 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100243 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700244 }
245 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700246 }
247
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700248 /**
249 * This constructor should NOT have any monitors by design.
250 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800251 public InvariantDeviceProfile(Context context, String gridName) {
252 String newName = initGrid(context, gridName);
253 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000254 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800255 }
256 }
257
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800259 * This constructor should NOT have any monitors by design.
260 */
261 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100263 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700264 String gridName = getCurrentGridName(context);
265
266 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000267 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700268 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700269 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000270 defaultInfo,
271 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
272 /*allowDisabledGrid=*/false),
273 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700274
Alex Chau661f02d2022-06-07 14:03:43 +0100275 Context displayContext = context.createDisplayContext(display);
276 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700277 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700278 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000279 myInfo,
280 getPredefinedDeviceProfiles(context, gridName, deviceType,
281 /*allowDisabledGrid=*/false),
282 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700283
284 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
285 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100286 result.iconSizes[INDEX_DEFAULT] =
287 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
288 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700289 result.iconSizes[i] = Math.min(
290 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000291 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700292
Thales Lima83bedbf2021-10-05 17:47:39 +0100293 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
294 COUNT_SIZES);
295 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
296 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500297
Alex Chau1c883d82021-12-01 18:43:10 +0000298 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800299 }
300
Sunny Goyal10fa0162024-04-21 00:13:35 -0700301 @Override
302 public void close() {
303 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
304 }
305
Alex Chau238aaee2021-10-06 16:15:24 +0100306 /**
307 * Reinitialize the current grid after a restore, where some grids might now be disabled.
308 */
309 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000310 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100311 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000312 String newGridName = initGrid(context, currentGridName);
313 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400314 FileLog.d(TAG, "Reinitializing grid after restore."
315 + " currentGridName=" + currentGridName
316 + ", currentDbFile=" + currentDbFile
317 + ", newGridName=" + newGridName
318 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000319 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400320 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100321 + ", migrating to: " + newGridName
322 + ", removing all other grid db files");
323 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
324 if (gridDbFile.equals(currentDbFile)) {
325 continue;
326 }
327 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400328 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100329 }
330 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000331 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100332 }
333 }
334
Tracy Zhou42255d22020-03-13 00:38:11 -0700335 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000336 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700337 }
338
Sunny Goyaleff44f32019-01-09 17:29:49 -0800339 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700340 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700341 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700342
fbaronebc10c92024-09-03 12:51:41 -0700343 List<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000344 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100345 RestoreDbTask.isPending(context));
fbaronebc10c92024-09-03 12:51:41 -0700346
347 // Filter out options that don't have the same number of columns as the grid
348 DeviceGridState deviceGridState = new DeviceGridState(context);
349 List<DisplayOption> allOptionsFilteredByColCount =
350 filterByColumnCount(allOptions, deviceGridState.getColumns());
351
Sunny Goyal19ff7282021-04-22 10:12:54 -0700352 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700353 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
354 ? new ArrayList<>(allOptions)
355 : new ArrayList<>(allOptionsFilteredByColCount), deviceType);
Alex Chau1c883d82021-12-01 18:43:10 +0000356 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700357 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800358 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700359
fbaronebc10c92024-09-03 12:51:41 -0700360 private List<DisplayOption> filterByColumnCount(
361 List<DisplayOption> allOptions, int numColumns) {
362 return allOptions.stream().filter(
363 option -> option.grid.numColumns == numColumns).toList();
364 }
365
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700366 /**
367 * @deprecated This is a temporary solution because on the backup and restore case we modify the
368 * IDP, this resets it. b/332974074
369 */
370 @Deprecated
371 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700372 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700373 }
374
Thales Limab67bfa72022-11-02 15:30:11 +0000375 @VisibleForTesting
376 public static String getDefaultGridName(Context context) {
377 return new InvariantDeviceProfile().initGrid(context, null);
378 }
379
Alex Chau1c883d82021-12-01 18:43:10 +0000380 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
381 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700382 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700383 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000384 numRows = closestProfile.numRows;
385 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000386 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000387 dbFile = closestProfile.dbFile;
388 defaultLayoutId = closestProfile.defaultLayoutId;
389 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300390
Sunny Goyalae190ff2020-04-14 00:19:01 +0000391 numFolderRows = closestProfile.numFolderRows;
392 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300393 folderStyle = closestProfile.folderStyle;
394
Thales Limad852d652023-01-17 14:01:13 +0000395 cellStyle = closestProfile.cellStyle;
396
Jon Mirandae126d722021-02-25 10:45:20 -0500397 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400398 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100399 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbaronebc10c92024-09-03 12:51:41 -0700400 rowCountSpecsId = closestProfile.mRowCountSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100401 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100402 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100403 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100404 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100405 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100406 hotseatSpecsId = closestProfile.mHotseatSpecsId;
407 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000408 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
409 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
410 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
411 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300412 numAllAppsRowsForCellHeightCalculation =
413 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000414 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000415
Vinit Nayakc7293172022-07-18 16:41:50 -0700416 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
417
Thales Lima83bedbf2021-10-05 17:47:39 +0100418 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100419 float maxIconSize = iconSize[0];
420 for (int i = 1; i < iconSize.length; i++) {
421 maxIconSize = Math.max(maxIconSize, iconSize[i]);
422 }
423 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000424 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
425
Thales Lima83bedbf2021-10-05 17:47:39 +0100426 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700427
Thales Lima83bedbf2021-10-05 17:47:39 +0100428 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100429
Thales Lima83bedbf2021-10-05 17:47:39 +0100430 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100431
Thales Limad90faab2021-09-21 17:18:47 +0100432 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100433
Sunny Goyal19ff7282021-04-22 10:12:54 -0700434 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000435 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700436 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100437 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
438 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700439
Thales Limae9273ea2023-01-26 12:33:52 +0000440 allAppsStyle = closestProfile.allAppsStyle;
441
Sunny Goyal19ff7282021-04-22 10:12:54 -0700442 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300443
Alex Chau1c883d82021-12-01 18:43:10 +0000444 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700445 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500446
Thales Limab7ef5692022-03-10 10:32:36 +0000447 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000448 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
449 allAppsIconSize = displayOption.allAppsIconSizes;
450 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000451
Thales Lima11af7bc2022-08-12 15:24:54 +0100452 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000453
Jon Miranda9c478b62023-03-23 21:38:49 -0700454 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
455
Jon Miranda04f05102023-04-04 12:16:31 -0700456 startAlignTaskbar = displayOption.startAlignTaskbar;
457
Sunny Goyalae190ff2020-04-14 00:19:01 +0000458 // If the partner customization apk contains any grid overrides, apply them
459 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700460 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700461
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000462 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700463 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700464 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700465 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000466 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000467 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000468 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700469 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000470 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700471
Sunny Goyal19ff7282021-04-22 10:12:54 -0700472 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
473 int displayWidth = bounds.bounds.width();
474 int displayHeight = bounds.bounds.height();
475 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700476
Sunny Goyal19ff7282021-04-22 10:12:54 -0700477 // We need to ensure that there is enough extra space in the wallpaper
478 // for the intended parallax effects
479 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300480 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
481 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700482 ? 2
483 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
484 defaultWallpaperSize.x =
485 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700486 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000487 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700488
Thales Lima6a590062022-11-22 15:52:49 +0000489 int numMinShownHotseatIconsForTablet = supportedProfiles
490 .stream()
491 .filter(deviceProfile -> deviceProfile.isTablet)
492 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
493 .min()
494 .orElse(0);
495
496 supportedProfiles
497 .stream()
498 .filter(deviceProfile -> deviceProfile.isTablet)
499 .forEach(deviceProfile -> {
500 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
501 deviceProfile.recalculateHotseatWidthAndBorderSpace();
502 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700503 }
504
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700505 public void addOnChangeListener(OnIDPChangeListener listener) {
506 mChangeListeners.add(listener);
507 }
508
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800509 public void removeOnChangeListener(OnIDPChangeListener listener) {
510 mChangeListeners.remove(listener);
511 }
512
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800513 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000514 LauncherPrefs.get(context).put(GRID_NAME, gridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700515 MAIN_EXECUTOR.execute(() -> {
516 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
517 onConfigChanged(context.getApplicationContext());
518 Trace.endSection();
519 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800520 }
521
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700522 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700523 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000524 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
525 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700526 }
527
Pat Manning24cec692023-10-13 10:36:57 +0000528 /** Updates IDP using the provided context. Notifies listeners of change. */
529 @VisibleForTesting
530 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700531 Object[] oldState = toModelState();
532
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700533 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700534 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700535 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700536
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700537 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700538 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700539 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700540 }
541 }
542
fbaron49f7df02024-11-05 16:15:19 -0800543 private static List<DisplayOption> getPredefinedDeviceProfiles(Context context,
Alex Chau1c883d82021-12-01 18:43:10 +0000544 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800545 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100546
Alex Chau1c883d82021-12-01 18:43:10 +0000547 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700548 final int depth = parser.getDepth();
549 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700550 while (((type = parser.next()) != XmlPullParser.END_TAG ||
551 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800552 if ((type == XmlPullParser.START_TAG)
553 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800554
Sunny Goyal076e04b2023-04-03 12:38:30 -0700555 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
fbaronebc10c92024-09-03 12:51:41 -0700556 if ((gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaron49f7df02024-11-05 16:15:19 -0800557 && gridOption.filterByFlag(deviceType)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100558 final int displayDepth = parser.getDepth();
559 while (((type = parser.next()) != XmlPullParser.END_TAG
560 || parser.getDepth() > displayDepth)
561 && type != XmlPullParser.END_DOCUMENT) {
562 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
563 parser.getName())) {
564 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100565 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100566 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800567 }
568 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700569 }
570 }
sfufa@google.comde013292021-09-21 18:22:44 -0700571 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700572 throw new RuntimeException(e);
573 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800574
Sunny Goyalae190ff2020-04-14 00:19:01 +0000575 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800576 if (!TextUtils.isEmpty(gridName)) {
577 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100578 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700579 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000580 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800581 }
582 }
583 }
fbaronebc10c92024-09-03 12:51:41 -0700584 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
585 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000586 for (DisplayOption option : profiles) {
587 if (option.canBeDefault) {
588 filteredProfiles.add(option);
589 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800590 }
fbaronebc10c92024-09-03 12:51:41 -0700591 } else if (filteredProfiles.isEmpty()) {
592 // In this case we had a grid selected but we couldn't find it.
593 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800594 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000595 if (filteredProfiles.isEmpty()) {
596 throw new RuntimeException("No display option with canBeDefault=true");
597 }
598 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700599 }
600
Thales Lima7ec83822021-08-05 13:32:10 +0100601 /**
fbaronebc10c92024-09-03 12:51:41 -0700602 * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct
603 * row count for this GridOption.
604 *
605 * @return the result of {@link #findBestRowCount(List, Context, int)}.
606 */
607 public static NumRows getRowCount(ResourceHelper resourceHelper, Context context,
608 int deviceType) {
609 ArrayList<NumRows> rowCounts = new ArrayList<>();
610
611 try (XmlResourceParser parser = resourceHelper.getXml()) {
612 final int depth = parser.getDepth();
613 int type;
614 while (((type = parser.next()) != XmlPullParser.END_TAG
615 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
616 if ((type == XmlPullParser.START_TAG)
617 && "NumRows".equals(parser.getName())) {
618 rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser)));
619 }
620 }
621 } catch (IOException | XmlPullParserException e) {
622 throw new RuntimeException(e);
623 }
624
625 return findBestRowCount(rowCounts, context, deviceType);
626 }
627
628 /**
629 * @return the biggest row count that fits the display dimensions spec using NumRows to
630 * determine that. If no best row count is found, return -1.
631 */
632 public static NumRows findBestRowCount(List<NumRows> list, Context context,
633 @DeviceType int deviceType) {
634 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
635 int minWidthPx = Integer.MAX_VALUE;
636 int minHeightPx = Integer.MAX_VALUE;
637 for (WindowBounds bounds : displayInfo.supportedBounds) {
638 boolean isTablet = displayInfo.isTablet(bounds);
639 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
640 // For split displays, take half width per page
641 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
642 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
643 } else if (!isTablet && bounds.isLandscape()) {
644 // We will use transposed layout in this case
645 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
646 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
647 } else {
648 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
649 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
650 }
651 }
652
653 NumRows selectedRow = null;
654 for (NumRows item: list) {
655 if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) {
656 if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) {
657 selectedRow = item;
658 }
659 }
660 }
661 if (selectedRow != null) {
662 return selectedRow;
663 }
664 return null;
665 }
666
667 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000668 * Returns the GridOption associated to the given file name or null if the fileName is not
669 * supported.
670 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
671 */
672 public GridOption getGridOptionFromFileName(Context context, String fileName) {
673 return parseAllGridOptions(context).stream()
674 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
675 .findFirst()
676 .orElse(null);
677 }
678
679 /**
680 * Returns the name of the given size on the current device or empty string if the size is not
681 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
682 * (Note: the name of the grid can be different for the same grid size depending of
683 * the values of the InvariantDeviceProfile)
684 *
685 */
686 public String getGridNameFromSize(Context context, Point size) {
687 return parseAllGridOptions(context).stream()
688 .filter(gridOption -> gridOption.numColumns == size.x
689 && gridOption.numRows == size.y)
690 .map(gridOption -> gridOption.name)
691 .findFirst()
692 .orElse("");
693 }
694
695 /**
696 * Returns the grid option for the given gridName on the current device (Note: the gridOption
697 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
698 */
699 public GridOption getGridOptionFromName(Context context, String gridName) {
700 return parseAllGridOptions(context).stream()
701 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
702 .findFirst()
703 .orElse(null);
704 }
705
706 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100707 * @return all the grid options that can be shown on the device
708 */
709 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700710 return parseAllDefinedGridOptions(context)
711 .stream()
712 .filter(go -> go.isEnabled(deviceType))
fbaron49f7df02024-11-05 16:15:19 -0800713 .filter(go -> go.filterByFlag(deviceType))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700714 .collect(Collectors.toList());
715 }
716
717 /**
718 * @return all the grid options that can be shown on the device
719 */
720 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100721 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100722
Alex Chau1c883d82021-12-01 18:43:10 +0000723 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100724 final int depth = parser.getDepth();
725 int type;
726 while (((type = parser.next()) != XmlPullParser.END_TAG
727 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
728 if ((type == XmlPullParser.START_TAG)
729 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700730 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100731 }
732 }
733 } catch (IOException | XmlPullParserException e) {
734 Log.e(TAG, "Error parsing device profile", e);
735 return Collections.emptyList();
736 }
737 return result;
738 }
739
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700740 private int getLauncherIconDensity(int requiredSize) {
741 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700742 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700743 DisplayMetrics.DENSITY_LOW,
744 DisplayMetrics.DENSITY_MEDIUM,
745 DisplayMetrics.DENSITY_TV,
746 DisplayMetrics.DENSITY_HIGH,
747 DisplayMetrics.DENSITY_XHIGH,
748 DisplayMetrics.DENSITY_XXHIGH,
749 DisplayMetrics.DENSITY_XXXHIGH
750 };
751
752 int density = DisplayMetrics.DENSITY_XXXHIGH;
753 for (int i = densityBuckets.length - 1; i >= 0; i--) {
754 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
755 / DisplayMetrics.DENSITY_DEFAULT;
756 if (expectedSize >= requiredSize) {
757 density = densityBuckets[i];
758 }
759 }
760
761 return density;
762 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700763
Adam Cohen2e6da152015-05-06 11:42:25 -0700764 /**
765 * Apply any Partner customization grid overrides.
766 *
767 * Currently we support: all apps row / column count.
768 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700769 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
770 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800771 if (p == null) {
772 return;
773 }
774 try {
775 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
776 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
777 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
778
779 if (numRows > 0 && numColumns > 0) {
780 this.numRows = numRows;
781 this.numColumns = numColumns;
782 }
783 if (iconSizePx > 0) {
784 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
785 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
786 }
787 } catch (Resources.NotFoundException ex) {
788 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700789 }
790 }
791
Sunny Goyal415f1732018-11-29 10:33:47 -0800792 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700793 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700794 }
795
Sunny Goyal19ff7282021-04-22 10:12:54 -0700796 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700797 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700798 int minWidthPx = Integer.MAX_VALUE;
799 int minHeightPx = Integer.MAX_VALUE;
800 for (WindowBounds bounds : displayInfo.supportedBounds) {
801 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000802 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700803 // For split displays, take half width per page
804 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
805 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700806
Sunny Goyal19ff7282021-04-22 10:12:54 -0700807 } else if (!isTablet && bounds.isLandscape()) {
808 // We will use transposed layout in this case
809 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
810 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
811 } else {
812 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
813 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
814 }
815 }
816
Thales Lima425f6822022-05-10 13:44:58 -0300817 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
818 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700819
820 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700821 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700822 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
823 dist(width, height, b.minWidthDps, b.minHeightDps)));
824
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700825 DisplayOption closestPoint = points.get(0);
826 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700827 float weights = 0;
828
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700829 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
830 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700831 }
832
833 DisplayOption out = new DisplayOption(closestOption);
834 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700835 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700836 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
837 weights += w;
838 out.add(new DisplayOption().add(p).multiply(w));
839 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700840 out.multiply(1.0f / weights);
841
Thales Lima6e0005a2021-10-27 15:53:41 +0100842 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700843 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100844 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
845 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700846 }
847
848 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700849 }
850
Sunny Goyal27835952017-01-13 12:15:53 -0800851 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000852 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
853 Rect bounds = windowManagerProxy.getCurrentBounds(context);
854 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700855
Alex Chauc09a98a2023-11-14 12:51:42 +0000856 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400857 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700858
Sunny Goyal187b16c2022-03-01 16:53:23 -0800859 /**
860 * Returns the device profile matching the provided screen configuration
861 */
862 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700863 DeviceProfile bestMatch = supportedProfiles.get(0);
864 float minDiff = Float.MAX_VALUE;
865
866 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400867 float diff = Math.abs(profile.widthPx - screenWidth)
868 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700869 if (diff < minDiff) {
870 minDiff = diff;
871 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800872 } else if (diff == minDiff && profile.rotationHint == rotation) {
873 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700874 }
875 }
876 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800877 }
878
Sunny Goyal415f1732018-11-29 10:33:47 -0800879 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700880 float d = dist(x0, y0, x1, y1);
881 if (Float.compare(d, 0f) == 0) {
882 return Float.POSITIVE_INFINITY;
883 }
884 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
885 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700886
887 /**
888 * As a ratio of screen height, the total distance we want the parallax effect to span
889 * horizontally
890 */
891 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
892 float aspectRatio = width / (float) height;
893
894 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
895 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
896 // We will use these two data points to extrapolate how much the wallpaper parallax effect
897 // to span (ie travel) at any aspect ratio:
898
sfufa@google.comde013292021-09-21 18:22:44 -0700899 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
900 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700901 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
902 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
903
904 // To find out the desired width at different aspect ratios, we use the following two
905 // formulas, where the coefficient on x is the aspect ratio (width/height):
906 // (16/10)x + y = 1.5
907 // (10/16)x + y = 1.2
908 // We solve for x and y and end up with a final formula:
909 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700910 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
911 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700912 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
913 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
914 return x * aspectRatio + y;
915 }
916
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700917 public interface OnIDPChangeListener {
918
Sunny Goyalb47172b2021-05-03 19:59:51 -0700919 /**
920 * Called when the device provide changes
921 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700922 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700923 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800924
925
Sunny Goyaleff44f32019-01-09 17:29:49 -0800926 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800927
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800928 public static final String TAG_NAME = "grid-option";
929
Alex Chau1c883d82021-12-01 18:43:10 +0000930 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
931 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
932 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
933 private static final int DEVICE_CATEGORY_ALL =
934 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
935
Thales Lima11af7bc2022-08-12 15:24:54 +0100936 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
937 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
938 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
939 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
940 private static final int DONT_INLINE_QSB = 0;
941
Sunny Goyaleff44f32019-01-09 17:29:49 -0800942 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700943 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800944 public final int numRows;
945 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000946 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700947 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800948
Thales Lima1faa4ed2023-12-01 16:48:19 +0000949 private final int[] numFolderRows = new int[COUNT_SIZES];
950 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300951 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000952 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800953
Thales Limae9273ea2023-01-26 12:33:52 +0000954 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700955 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300956 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700957 private final int numDatabaseAllAppsColumns;
958 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700959 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100960
Thales Lima11af7bc2022-08-12 15:24:54 +0100961 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
962
Thales Limab35faed2022-09-05 16:30:01 -0300963 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800964 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000965
Sunny Goyal415f1732018-11-29 10:33:47 -0800966 private final int defaultLayoutId;
967 private final int demoModeLayoutId;
968
Jon Mirandae126d722021-02-25 10:45:20 -0500969 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -0800970 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400971 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100972 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100973 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100974 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100975 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100976 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100977 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100978 private final int mHotseatSpecsId;
979 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000980 private final int mWorkspaceCellSpecsId;
981 private final int mWorkspaceCellSpecsTwoPanelId;
982 private final int mAllAppsCellSpecsId;
983 private final int mAllAppsCellSpecsTwoPanelId;
fbaronebc10c92024-09-03 12:51:41 -0700984 private final int mRowCountSpecsId;
Jon Mirandae126d722021-02-25 10:45:20 -0500985
Sunny Goyal076e04b2023-04-03 12:38:30 -0700986 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800987 TypedArray a = context.obtainStyledAttributes(
988 attrs, R.styleable.GridDisplayOption);
989 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -0700990 title = a.getString(R.styleable.GridDisplayOption_title);
991 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
992 DEVICE_CATEGORY_ALL);
993 mRowCountSpecsId = a.getResourceId(
994 R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -0800995 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbaronebc10c92024-09-03 12:51:41 -0700996 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
997 ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
998 NumRows numR = getRowCount(resourceHelper, context, deviceCategory);
999 numRows = numR.mNumRowsNew;
1000 dbFile = numR.mDbFile;
1001 } else {
1002 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
1003 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
1004 }
1005
Sunny Goyal415f1732018-11-29 10:33:47 -08001006 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001007 numSearchContainerColumns = a.getInt(
1008 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Alex Chau766cd2b2022-07-06 17:15:21 +01001009 defaultLayoutId = a.getResourceId(
1010 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -08001011 demoModeLayoutId = a.getResourceId(
1012 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001013
Thales Limae9273ea2023-01-26 12:33:52 +00001014 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1015 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001016 numAllAppsColumns = a.getInt(
1017 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1018 numDatabaseAllAppsColumns = a.getInt(
1019 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1020
1021 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001022 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001023 numDatabaseHotseatIcons = a.getInt(
1024 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001025
Vinit Nayakc7293172022-07-18 16:41:50 -07001026 inlineNavButtonsEndSpacing =
1027 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001028 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001029
Thales Lima1faa4ed2023-12-01 16:48:19 +00001030 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001031 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001032 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001033 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001034
Thales Lima1faa4ed2023-12-01 16:48:19 +00001035 if (FeatureFlags.enableResponsiveWorkspace()) {
1036 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1037 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1038 numFolderRows[INDEX_DEFAULT]);
1039 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1040 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1041 numFolderColumns[INDEX_DEFAULT]);
1042 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1043 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1044 numFolderRows[INDEX_DEFAULT]);
1045 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1046 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1047 numFolderColumns[INDEX_DEFAULT]);
1048 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1049 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1050 numFolderRows[INDEX_DEFAULT]);
1051 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1052 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1053 numFolderColumns[INDEX_DEFAULT]);
1054 } else {
1055 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1056 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1057 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1058 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1059 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1060 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1061 }
1062
Thales Limab35faed2022-09-05 16:30:01 -03001063 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1064 INVALID_RESOURCE_HANDLE);
1065
Thales Limad852d652023-01-17 14:01:13 +00001066 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1067 R.style.CellStyleDefault);
1068
Jon Mirandae126d722021-02-25 10:45:20 -05001069 isScalable = a.getBoolean(
1070 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001071 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001072 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001073
Thales Limaca31b612023-09-14 14:25:26 +01001074 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001075 mWorkspaceSpecsId = a.getResourceId(
1076 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001077 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1078 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001079 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001080 mAllAppsSpecsId = a.getResourceId(
1081 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001082 mAllAppsSpecsTwoPanelId = a.getResourceId(
1083 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001084 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001085 mFolderSpecsId = a.getResourceId(
1086 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001087 mFolderSpecsTwoPanelId = a.getResourceId(
1088 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001089 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001090 mHotseatSpecsId = a.getResourceId(
1091 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1092 mHotseatSpecsTwoPanelId = a.getResourceId(
1093 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001094 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001095 mWorkspaceCellSpecsId = a.getResourceId(
1096 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1097 INVALID_RESOURCE_HANDLE);
1098 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1099 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001100 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001101 mAllAppsCellSpecsId = a.getResourceId(
1102 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1103 INVALID_RESOURCE_HANDLE);
1104 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1105 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001106 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001107 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1108 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1109 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001110 } else {
1111 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001112 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001113 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001114 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001115 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001116 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001117 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1118 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001119 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1120 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1121 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1122 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001123 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001124 }
1125
Thales Lima11af7bc2022-08-12 15:24:54 +01001126 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1127 DONT_INLINE_QSB);
1128 inlineQsb[INDEX_DEFAULT] =
1129 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1130 inlineQsb[INDEX_LANDSCAPE] =
1131 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1132 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1133 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1134 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1135 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1136 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1137 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1138
Sunny Goyal415f1732018-11-29 10:33:47 -08001139 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001140 }
1141
1142 public boolean isEnabled(@DeviceType int deviceType) {
1143 switch (deviceType) {
1144 case TYPE_PHONE:
1145 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1146 case TYPE_TABLET:
1147 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1148 case TYPE_MULTI_DISPLAY:
1149 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1150 == DEVICE_CATEGORY_MULTI_DISPLAY;
1151 default:
1152 return false;
1153 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001154 }
fbaronebc10c92024-09-03 12:51:41 -07001155
1156 public boolean isNewGridOption() {
1157 return mRowCountSpecsId != INVALID_RESOURCE_HANDLE;
1158 }
fbaron49f7df02024-11-05 16:15:19 -08001159
1160 public boolean filterByFlag(int deviceType) {
1161 if (deviceType == TYPE_TABLET) {
1162 return Flags.oneGridRotationHandling() == mIsDualGrid;
1163 }
1164 return Flags.oneGridSpecs() == isNewGridOption();
1165 }
fbaronebc10c92024-09-03 12:51:41 -07001166 }
1167
1168 public static final class NumRows {
1169 final int mNumRowsNew;
1170 final float mMinDeviceWidthPx;
1171 final float mMinDeviceHeightPx;
1172 final String mDbFile;
1173
1174 NumRows(Context context, AttributeSet attrs) {
1175 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows);
1176
1177 mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0);
1178 mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0);
1179 mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0);
1180 mDbFile = a.getString(R.styleable.NumRows_dbFile);
1181
1182 a.recycle();
1183 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001184 }
1185
Sunny Goyal19ff7282021-04-22 10:12:54 -07001186 @VisibleForTesting
1187 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001188 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001189
Sunny Goyal415f1732018-11-29 10:33:47 -08001190 private final float minWidthDps;
1191 private final float minHeightDps;
1192 private final boolean canBeDefault;
1193
Thales Lima83bedbf2021-10-05 17:47:39 +01001194 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001195
Thales Lima78d00ad2021-09-30 11:29:06 +01001196 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001197 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001198 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1199 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001200
Thales Lima78d00ad2021-09-30 11:29:06 +01001201 private final float[] iconSizes = new float[COUNT_SIZES];
1202 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001203
Thales Limab7ef5692022-03-10 10:32:36 +00001204 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001205 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1206 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1207 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1208
Jon Miranda9c478b62023-03-23 21:38:49 -07001209 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1210
Jon Miranda04f05102023-04-04 12:16:31 -07001211 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1212
Thales Lima1de4d552021-10-13 16:13:25 +01001213 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001214 this.grid = grid;
1215
Jon Miranda9c478b62023-03-23 21:38:49 -07001216 Resources res = context.getResources();
1217
Thales Lima1de4d552021-10-13 16:13:25 +01001218 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001219
Sunny Goyal415f1732018-11-29 10:33:47 -08001220 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1221 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001222
Thales Lima1de4d552021-10-13 16:13:25 +01001223 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001224
Thales Lima83bedbf2021-10-05 17:47:39 +01001225 float x;
1226 float y;
1227
Thales Lima85c942f2021-12-31 13:04:20 +00001228 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1229 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001230 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001231
1232 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1233 minCellSize[INDEX_DEFAULT].x);
1234 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1235 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001236 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001237
Thales Lima85c942f2021-12-31 13:04:20 +00001238 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001239 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001240 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001241 minCellSize[INDEX_DEFAULT].y);
1242 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1243
Thales Lima85c942f2021-12-31 13:04:20 +00001244 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001245 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001246 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001247 minCellSize[INDEX_DEFAULT].y);
1248 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001249
Thales Lima85c942f2021-12-31 13:04:20 +00001250 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001251 float borderSpaceLandscape = a.getFloat(
1252 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001253 float borderSpaceTwoPanelPortrait = a.getFloat(
1254 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1255 float borderSpaceTwoPanelLandscape = a.getFloat(
1256 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001257
Thales Lima85c942f2021-12-31 13:04:20 +00001258 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1259 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001260 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001261
1262 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1263 borderSpaceLandscape);
1264 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1265 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001266 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1267
1268 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001269 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1270 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001271 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001272 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1273 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001274 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1275
1276 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001277 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1278 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001279 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001280 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1281 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001282 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1283
Thales Limab7ef5692022-03-10 10:32:36 +00001284 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1285 minCellSize[INDEX_DEFAULT].x);
1286 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1287 minCellSize[INDEX_DEFAULT].y);
1288 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1289
1290 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1291 allAppsCellSize[INDEX_DEFAULT].x);
1292 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1293 allAppsCellSize[INDEX_DEFAULT].y);
1294 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1295
1296 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1297 allAppsCellSize[INDEX_DEFAULT].x);
1298 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1299 allAppsCellSize[INDEX_DEFAULT].y);
1300 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1301
1302 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1303 allAppsCellSize[INDEX_DEFAULT].x);
1304 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1305 allAppsCellSize[INDEX_DEFAULT].y);
1306 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1307
Thales Lima080d8902022-03-28 15:30:29 +01001308 float allAppsBorderSpace = a.getFloat(
1309 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1310 float allAppsBorderSpaceLandscape = a.getFloat(
1311 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1312 allAppsBorderSpace);
1313 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001314 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001315 allAppsBorderSpace);
1316 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001317 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001318 allAppsBorderSpace);
1319
1320 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1321 allAppsBorderSpace);
1322 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1323 allAppsBorderSpace);
1324 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1325
1326 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1327 allAppsBorderSpaceLandscape);
1328 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1329 allAppsBorderSpaceLandscape);
1330 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1331
1332 x = a.getFloat(
1333 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1334 allAppsBorderSpaceTwoPanelPortrait);
1335 y = a.getFloat(
1336 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1337 allAppsBorderSpaceTwoPanelPortrait);
1338 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1339
1340 x = a.getFloat(
1341 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1342 allAppsBorderSpaceTwoPanelLandscape);
1343 y = a.getFloat(
1344 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1345 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001346 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001347
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001348 iconSizes[INDEX_DEFAULT] =
1349 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1350 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001351 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001352 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001353 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001354 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001355 iconSizes[INDEX_DEFAULT]);
1356 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001357 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001358 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001359
Thales Limabb7d3882021-12-22 12:56:29 +00001360 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1361 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001362 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1363 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001364 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001365 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1366 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1367 allAppsIconSizes[INDEX_DEFAULT]);
1368 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1369 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1370 allAppsIconSizes[INDEX_DEFAULT]);
1371
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001372 textSizes[INDEX_DEFAULT] =
1373 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1374 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001375 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001376 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001377 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001378 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001379 textSizes[INDEX_DEFAULT]);
1380 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001381 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001382 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001383
Thales Limabb7d3882021-12-22 12:56:29 +00001384 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1385 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1386 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1387 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1388 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1389 allAppsIconTextSizes[INDEX_DEFAULT]);
1390 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1391 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1392 allAppsIconTextSizes[INDEX_DEFAULT]);
1393
Thales Lima83bedbf2021-10-05 17:47:39 +01001394 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1395 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001396 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1397 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1398 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001399 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001400 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001401 horizontalMargin[INDEX_DEFAULT]);
1402 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001403 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001404 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001405
Thales Limab8c05952022-05-23 16:58:38 +01001406 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1407 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001408 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001409 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1410 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1411 hotseatBarBottomSpace[INDEX_DEFAULT]);
1412 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1413 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1414 hotseatBarBottomSpace[INDEX_DEFAULT]);
1415 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1416 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1417 hotseatBarBottomSpace[INDEX_DEFAULT]);
1418
1419 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1420 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001421 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001422 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1423 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1424 hotseatQsbSpace[INDEX_DEFAULT]);
1425 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1426 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1427 hotseatQsbSpace[INDEX_DEFAULT]);
1428 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1429 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1430 hotseatQsbSpace[INDEX_DEFAULT]);
1431
Jon Miranda9c478b62023-03-23 21:38:49 -07001432 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1433 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1434 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1435 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1436 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1437 transientTaskbarIconSize[INDEX_DEFAULT]);
1438 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1439 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1440 transientTaskbarIconSize[INDEX_DEFAULT]);
1441 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1442 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001443 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001444
Jon Miranda04f05102023-04-04 12:16:31 -07001445 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1446 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1447 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1448 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1449 startAlignTaskbar[INDEX_DEFAULT]);
1450 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1451 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1452 startAlignTaskbar[INDEX_LANDSCAPE]);
1453 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1454 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1455 startAlignTaskbar[INDEX_DEFAULT]);
1456
Sunny Goyal415f1732018-11-29 10:33:47 -08001457 a.recycle();
1458 }
1459
1460 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001461 this(null);
1462 }
1463
1464 DisplayOption(GridOption grid) {
1465 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001466 minWidthDps = 0;
1467 minHeightDps = 0;
1468 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001469 for (int i = 0; i < COUNT_SIZES; i++) {
1470 iconSizes[i] = 0;
1471 textSizes[i] = 0;
1472 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001473 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001474 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001475 allAppsIconSizes[i] = 0;
1476 allAppsIconTextSizes[i] = 0;
1477 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001478 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001479 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001480 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001481 }
1482
1483 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001484 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001485 iconSizes[i] *= w;
1486 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001487 borderSpaces[i].x *= w;
1488 borderSpaces[i].y *= w;
1489 minCellSize[i].x *= w;
1490 minCellSize[i].y *= w;
1491 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001492 hotseatBarBottomSpace[i] *= w;
1493 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001494 allAppsCellSize[i].x *= w;
1495 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001496 allAppsIconSizes[i] *= w;
1497 allAppsIconTextSizes[i] *= w;
1498 allAppsBorderSpaces[i].x *= w;
1499 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001500 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001501 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001502
Sunny Goyal415f1732018-11-29 10:33:47 -08001503 return this;
1504 }
1505
1506 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001507 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001508 iconSizes[i] += p.iconSizes[i];
1509 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001510 borderSpaces[i].x += p.borderSpaces[i].x;
1511 borderSpaces[i].y += p.borderSpaces[i].y;
1512 minCellSize[i].x += p.minCellSize[i].x;
1513 minCellSize[i].y += p.minCellSize[i].y;
1514 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001515 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1516 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001517 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1518 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001519 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1520 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1521 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1522 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001523 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001524 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001525 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001526
Sunny Goyal415f1732018-11-29 10:33:47 -08001527 return this;
1528 }
1529 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001530}