blob: d8a898df91cc2c41da3b69002e2f13720b4a5127 [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;
Sunny Goyal68031ca2021-08-02 12:23:44 -070055import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010056import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070057import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070058import com.android.launcher3.util.DisplayController;
59import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070060import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080061import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070062import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070063import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070064import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080065import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070066
Sunny Goyal819e1932016-07-07 16:43:58 -070067import org.xmlpull.v1.XmlPullParser;
68import org.xmlpull.v1.XmlPullParserException;
69
70import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000071import java.lang.annotation.Retention;
72import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070073import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070074import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080075import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070076import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000077import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070078import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Sunny Goyal10fa0162024-04-21 00:13:35 -070080public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070081
Hyunyoung Songc55a3502018-12-04 15:43:16 -080082 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070083 // We do not need any synchronization for this variable as its only written on UI thread.
84 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070085 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070086
Alex Chau1c883d82021-12-01 18:43:10 +000087 @Retention(RetentionPolicy.SOURCE)
88 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010089 public @interface DeviceType {}
90
Alex Chau1c883d82021-12-01 18:43:10 +000091 public static final int TYPE_PHONE = 0;
92 public static final int TYPE_MULTI_DISPLAY = 1;
93 public static final int TYPE_TABLET = 2;
94
Sunny Goyal53d7ee42015-05-22 12:25:45 -070095 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
96
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070097 // Constants that affects the interpolation curve between statically defined device profile
98 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080099 private static final float KNEARESTNEIGHBOR = 3;
100 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700101
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700102 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800103 private static final float WEIGHT_EFFICIENT = 100000f;
104
Thales Lima83bedbf2021-10-05 17:47:39 +0100105 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
106 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000107 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100108 static final int INDEX_DEFAULT = 0;
109 static final int INDEX_LANDSCAPE = 1;
110 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
111 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100112
Thales Limaec5abba2023-04-05 16:33:50 +0100113 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800114 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
115 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
116 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
117
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700118 /**
119 * Number of icons per row and column in the workspace.
120 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700121 public int numRows;
122 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000123 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700124
125 /**
126 * Number of icons per row and column in the folder.
127 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000128 public int[] numFolderRows;
129 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100130 public float[] iconSize;
131 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700132 public int iconBitmapSize;
133 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000134 public @DeviceType int deviceType;
Federico Baron56307d22024-11-06 18:48:48 +0000135 public Info displayInfo;
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,
Federico Baron56307d22024-11-06 18:48:48 +0000271 getPredefinedDeviceProfiles(context, gridName, defaultInfo,
Alex Chau1c883d82021-12-01 18:43:10 +0000272 /*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,
Federico Baron56307d22024-11-06 18:48:48 +0000280 getPredefinedDeviceProfiles(context, gridName, myInfo,
Alex Chau1c883d82021-12-01 18:43:10 +0000281 /*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
Federico Baron56307d22024-11-06 18:48:48 +0000298 initGrid(context, myInfo, result);
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
Tracy Zhou42255d22020-03-13 00:38:11 -0700306 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000307 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700308 }
309
Sunny Goyaleff44f32019-01-09 17:29:49 -0800310 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700311 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700312
Federico Baron56307d22024-11-06 18:48:48 +0000313 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName,
314 displayInfo, RestoreDbTask.isPending(context));
fbaronebc10c92024-09-03 12:51:41 -0700315
316 // Filter out options that don't have the same number of columns as the grid
317 DeviceGridState deviceGridState = new DeviceGridState(context);
318 List<DisplayOption> allOptionsFilteredByColCount =
319 filterByColumnCount(allOptions, deviceGridState.getColumns());
320
Sunny Goyal19ff7282021-04-22 10:12:54 -0700321 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700322 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
323 ? new ArrayList<>(allOptions)
Federico Baron56307d22024-11-06 18:48:48 +0000324 : new ArrayList<>(allOptionsFilteredByColCount),
325 displayInfo.getDeviceType());
326 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700327 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800328 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700329
fbaronebc10c92024-09-03 12:51:41 -0700330 private List<DisplayOption> filterByColumnCount(
331 List<DisplayOption> allOptions, int numColumns) {
332 return allOptions.stream().filter(
333 option -> option.grid.numColumns == numColumns).toList();
334 }
335
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700336 /**
337 * @deprecated This is a temporary solution because on the backup and restore case we modify the
338 * IDP, this resets it. b/332974074
339 */
340 @Deprecated
341 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700342 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700343 }
344
Thales Limab67bfa72022-11-02 15:30:11 +0000345 @VisibleForTesting
346 public static String getDefaultGridName(Context context) {
347 return new InvariantDeviceProfile().initGrid(context, null);
348 }
349
Federico Baron56307d22024-11-06 18:48:48 +0000350 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700351 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700352 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000353 numRows = closestProfile.numRows;
354 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000355 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000356 dbFile = closestProfile.dbFile;
357 defaultLayoutId = closestProfile.defaultLayoutId;
358 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300359
Sunny Goyalae190ff2020-04-14 00:19:01 +0000360 numFolderRows = closestProfile.numFolderRows;
361 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300362 folderStyle = closestProfile.folderStyle;
363
Thales Limad852d652023-01-17 14:01:13 +0000364 cellStyle = closestProfile.cellStyle;
365
Jon Mirandae126d722021-02-25 10:45:20 -0500366 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400367 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100368 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbaronebc10c92024-09-03 12:51:41 -0700369 rowCountSpecsId = closestProfile.mRowCountSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100370 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100371 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100372 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100373 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100374 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100375 hotseatSpecsId = closestProfile.mHotseatSpecsId;
376 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000377 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
378 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
379 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
380 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300381 numAllAppsRowsForCellHeightCalculation =
382 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000383 this.deviceType = displayInfo.getDeviceType();
384 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000385
Vinit Nayakc7293172022-07-18 16:41:50 -0700386 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
387
Thales Lima83bedbf2021-10-05 17:47:39 +0100388 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100389 float maxIconSize = iconSize[0];
390 for (int i = 1; i < iconSize.length; i++) {
391 maxIconSize = Math.max(maxIconSize, iconSize[i]);
392 }
393 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000394 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
395
Thales Lima83bedbf2021-10-05 17:47:39 +0100396 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700397
Thales Lima83bedbf2021-10-05 17:47:39 +0100398 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100399
Thales Lima83bedbf2021-10-05 17:47:39 +0100400 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100401
Thales Limad90faab2021-09-21 17:18:47 +0100402 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100403
Sunny Goyal19ff7282021-04-22 10:12:54 -0700404 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000405 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700406 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100407 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
408 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700409
Thales Limae9273ea2023-01-26 12:33:52 +0000410 allAppsStyle = closestProfile.allAppsStyle;
411
Sunny Goyal19ff7282021-04-22 10:12:54 -0700412 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300413
Alex Chau1c883d82021-12-01 18:43:10 +0000414 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700415 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500416
Thales Limab7ef5692022-03-10 10:32:36 +0000417 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000418 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
419 allAppsIconSize = displayOption.allAppsIconSizes;
420 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000421
Thales Lima11af7bc2022-08-12 15:24:54 +0100422 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000423
Jon Miranda9c478b62023-03-23 21:38:49 -0700424 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
425
Jon Miranda04f05102023-04-04 12:16:31 -0700426 startAlignTaskbar = displayOption.startAlignTaskbar;
427
Sunny Goyalae190ff2020-04-14 00:19:01 +0000428 // If the partner customization apk contains any grid overrides, apply them
429 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700430 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700431
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000432 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700433 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700434 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700435 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000436 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000437 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000438 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700439 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000440 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700441
Sunny Goyal19ff7282021-04-22 10:12:54 -0700442 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
443 int displayWidth = bounds.bounds.width();
444 int displayHeight = bounds.bounds.height();
445 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700446
Sunny Goyal19ff7282021-04-22 10:12:54 -0700447 // We need to ensure that there is enough extra space in the wallpaper
448 // for the intended parallax effects
449 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300450 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
451 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700452 ? 2
453 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
454 defaultWallpaperSize.x =
455 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700456 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000457 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700458
Thales Lima6a590062022-11-22 15:52:49 +0000459 int numMinShownHotseatIconsForTablet = supportedProfiles
460 .stream()
461 .filter(deviceProfile -> deviceProfile.isTablet)
462 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
463 .min()
464 .orElse(0);
465
466 supportedProfiles
467 .stream()
468 .filter(deviceProfile -> deviceProfile.isTablet)
469 .forEach(deviceProfile -> {
470 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
471 deviceProfile.recalculateHotseatWidthAndBorderSpace();
472 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700473 }
474
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700475 public void addOnChangeListener(OnIDPChangeListener listener) {
476 mChangeListeners.add(listener);
477 }
478
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800479 public void removeOnChangeListener(OnIDPChangeListener listener) {
480 mChangeListeners.remove(listener);
481 }
482
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800483 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000484 LauncherPrefs.get(context).put(GRID_NAME, gridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700485 MAIN_EXECUTOR.execute(() -> {
486 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
487 onConfigChanged(context.getApplicationContext());
488 Trace.endSection();
489 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800490 }
491
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700492 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700493 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000494 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
495 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700496 }
497
Pat Manning24cec692023-10-13 10:36:57 +0000498 /** Updates IDP using the provided context. Notifies listeners of change. */
499 @VisibleForTesting
500 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700501 Object[] oldState = toModelState();
502
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700503 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700504 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700505 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700506
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700507 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700508 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700509 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700510 }
511 }
512
Federico Baron56307d22024-11-06 18:48:48 +0000513 private static List<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName,
514 Info displayInfo, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800515 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100516
Alex Chau1c883d82021-12-01 18:43:10 +0000517 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700518 final int depth = parser.getDepth();
519 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700520 while (((type = parser.next()) != XmlPullParser.END_TAG ||
521 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800522 if ((type == XmlPullParser.START_TAG)
523 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800524
Federico Baron56307d22024-11-06 18:48:48 +0000525 GridOption gridOption = new GridOption(
526 context, Xml.asAttributeSet(parser), displayInfo);
527 if ((gridOption.isEnabled(displayInfo.getDeviceType()) || allowDisabledGrid)
528 && gridOption.filterByFlag(displayInfo.getDeviceType())) {
Thales Lima7ec83822021-08-05 13:32:10 +0100529 final int displayDepth = parser.getDepth();
530 while (((type = parser.next()) != XmlPullParser.END_TAG
531 || parser.getDepth() > displayDepth)
532 && type != XmlPullParser.END_DOCUMENT) {
533 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
534 parser.getName())) {
535 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100536 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100537 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800538 }
539 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700540 }
541 }
sfufa@google.comde013292021-09-21 18:22:44 -0700542 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700543 throw new RuntimeException(e);
544 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800545
Sunny Goyalae190ff2020-04-14 00:19:01 +0000546 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800547 if (!TextUtils.isEmpty(gridName)) {
548 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000549 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
550 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000551 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800552 }
553 }
554 }
fbaronebc10c92024-09-03 12:51:41 -0700555 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
556 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000557 for (DisplayOption option : profiles) {
558 if (option.canBeDefault) {
559 filteredProfiles.add(option);
560 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800561 }
fbaronebc10c92024-09-03 12:51:41 -0700562 } else if (filteredProfiles.isEmpty()) {
563 // In this case we had a grid selected but we couldn't find it.
564 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800565 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000566 if (filteredProfiles.isEmpty()) {
567 throw new RuntimeException("No display option with canBeDefault=true");
568 }
569 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700570 }
571
Thales Lima7ec83822021-08-05 13:32:10 +0100572 /**
fbaronebc10c92024-09-03 12:51:41 -0700573 * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct
574 * row count for this GridOption.
575 *
Federico Baron56307d22024-11-06 18:48:48 +0000576 * @return the result of {@link #findBestRowCount(List, Info)}.
fbaronebc10c92024-09-03 12:51:41 -0700577 */
578 public static NumRows getRowCount(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000579 Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700580 ArrayList<NumRows> rowCounts = new ArrayList<>();
581
582 try (XmlResourceParser parser = resourceHelper.getXml()) {
583 final int depth = parser.getDepth();
584 int type;
585 while (((type = parser.next()) != XmlPullParser.END_TAG
586 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
587 if ((type == XmlPullParser.START_TAG)
588 && "NumRows".equals(parser.getName())) {
589 rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser)));
590 }
591 }
592 } catch (IOException | XmlPullParserException e) {
593 throw new RuntimeException(e);
594 }
595
Federico Baron56307d22024-11-06 18:48:48 +0000596 return findBestRowCount(rowCounts, displayInfo);
fbaronebc10c92024-09-03 12:51:41 -0700597 }
598
599 /**
600 * @return the biggest row count that fits the display dimensions spec using NumRows to
601 * determine that. If no best row count is found, return -1.
602 */
Federico Baron56307d22024-11-06 18:48:48 +0000603 public static NumRows findBestRowCount(List<NumRows> list, Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700604 int minWidthPx = Integer.MAX_VALUE;
605 int minHeightPx = Integer.MAX_VALUE;
606 for (WindowBounds bounds : displayInfo.supportedBounds) {
607 boolean isTablet = displayInfo.isTablet(bounds);
Federico Baron56307d22024-11-06 18:48:48 +0000608 if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) {
fbaronebc10c92024-09-03 12:51:41 -0700609 // For split displays, take half width per page
610 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
611 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
612 } else if (!isTablet && bounds.isLandscape()) {
613 // We will use transposed layout in this case
614 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
615 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
616 } else {
617 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
618 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
619 }
620 }
621
622 NumRows selectedRow = null;
623 for (NumRows item: list) {
624 if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) {
625 if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) {
626 selectedRow = item;
627 }
628 }
629 }
630 if (selectedRow != null) {
631 return selectedRow;
632 }
633 return null;
634 }
635
636 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000637 * Returns the GridOption associated to the given file name or null if the fileName is not
638 * supported.
639 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
640 */
641 public GridOption getGridOptionFromFileName(Context context, String fileName) {
642 return parseAllGridOptions(context).stream()
643 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
644 .findFirst()
645 .orElse(null);
646 }
647
648 /**
649 * Returns the name of the given size on the current device or empty string if the size is not
650 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
651 * (Note: the name of the grid can be different for the same grid size depending of
652 * the values of the InvariantDeviceProfile)
653 *
654 */
655 public String getGridNameFromSize(Context context, Point size) {
656 return parseAllGridOptions(context).stream()
657 .filter(gridOption -> gridOption.numColumns == size.x
658 && gridOption.numRows == size.y)
659 .map(gridOption -> gridOption.name)
660 .findFirst()
661 .orElse("");
662 }
663
664 /**
665 * Returns the grid option for the given gridName on the current device (Note: the gridOption
666 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
667 */
668 public GridOption getGridOptionFromName(Context context, String gridName) {
669 return parseAllGridOptions(context).stream()
670 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
671 .findFirst()
672 .orElse(null);
673 }
674
675 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100676 * @return all the grid options that can be shown on the device
677 */
678 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000679 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700680 .stream()
681 .filter(go -> go.isEnabled(deviceType))
fbaron49f7df02024-11-05 16:15:19 -0800682 .filter(go -> go.filterByFlag(deviceType))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700683 .collect(Collectors.toList());
684 }
685
686 /**
687 * @return all the grid options that can be shown on the device
688 */
Federico Baron56307d22024-11-06 18:48:48 +0000689 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100690 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000691 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100692 final int depth = parser.getDepth();
693 int type;
694 while (((type = parser.next()) != XmlPullParser.END_TAG
695 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
696 if ((type == XmlPullParser.START_TAG)
697 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000698 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100699 }
700 }
701 } catch (IOException | XmlPullParserException e) {
702 Log.e(TAG, "Error parsing device profile", e);
703 return Collections.emptyList();
704 }
705 return result;
706 }
707
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700708 private int getLauncherIconDensity(int requiredSize) {
709 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700710 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700711 DisplayMetrics.DENSITY_LOW,
712 DisplayMetrics.DENSITY_MEDIUM,
713 DisplayMetrics.DENSITY_TV,
714 DisplayMetrics.DENSITY_HIGH,
715 DisplayMetrics.DENSITY_XHIGH,
716 DisplayMetrics.DENSITY_XXHIGH,
717 DisplayMetrics.DENSITY_XXXHIGH
718 };
719
720 int density = DisplayMetrics.DENSITY_XXXHIGH;
721 for (int i = densityBuckets.length - 1; i >= 0; i--) {
722 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
723 / DisplayMetrics.DENSITY_DEFAULT;
724 if (expectedSize >= requiredSize) {
725 density = densityBuckets[i];
726 }
727 }
728
729 return density;
730 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700731
Adam Cohen2e6da152015-05-06 11:42:25 -0700732 /**
733 * Apply any Partner customization grid overrides.
734 *
735 * Currently we support: all apps row / column count.
736 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700737 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
738 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800739 if (p == null) {
740 return;
741 }
742 try {
743 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
744 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
745 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
746
747 if (numRows > 0 && numColumns > 0) {
748 this.numRows = numRows;
749 this.numColumns = numColumns;
750 }
751 if (iconSizePx > 0) {
752 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
753 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
754 }
755 } catch (Resources.NotFoundException ex) {
756 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700757 }
758 }
759
Sunny Goyal415f1732018-11-29 10:33:47 -0800760 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700761 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700762 }
763
Sunny Goyal19ff7282021-04-22 10:12:54 -0700764 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700765 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700766 int minWidthPx = Integer.MAX_VALUE;
767 int minHeightPx = Integer.MAX_VALUE;
768 for (WindowBounds bounds : displayInfo.supportedBounds) {
769 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000770 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700771 // For split displays, take half width per page
772 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
773 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700774
Sunny Goyal19ff7282021-04-22 10:12:54 -0700775 } else if (!isTablet && bounds.isLandscape()) {
776 // We will use transposed layout in this case
777 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
778 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
779 } else {
780 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
781 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
782 }
783 }
784
Thales Lima425f6822022-05-10 13:44:58 -0300785 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
786 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700787
788 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700789 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700790 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
791 dist(width, height, b.minWidthDps, b.minHeightDps)));
792
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700793 DisplayOption closestPoint = points.get(0);
794 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700795 float weights = 0;
796
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700797 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
798 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700799 }
800
801 DisplayOption out = new DisplayOption(closestOption);
802 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700803 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700804 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
805 weights += w;
806 out.add(new DisplayOption().add(p).multiply(w));
807 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700808 out.multiply(1.0f / weights);
809
Thales Lima6e0005a2021-10-27 15:53:41 +0100810 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700811 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100812 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
813 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700814 }
815
816 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700817 }
818
Sunny Goyal27835952017-01-13 12:15:53 -0800819 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000820 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
821 Rect bounds = windowManagerProxy.getCurrentBounds(context);
822 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700823
Alex Chauc09a98a2023-11-14 12:51:42 +0000824 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400825 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700826
Sunny Goyal187b16c2022-03-01 16:53:23 -0800827 /**
828 * Returns the device profile matching the provided screen configuration
829 */
830 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700831 DeviceProfile bestMatch = supportedProfiles.get(0);
832 float minDiff = Float.MAX_VALUE;
833
834 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400835 float diff = Math.abs(profile.widthPx - screenWidth)
836 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700837 if (diff < minDiff) {
838 minDiff = diff;
839 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800840 } else if (diff == minDiff && profile.rotationHint == rotation) {
841 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700842 }
843 }
844 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800845 }
846
Sunny Goyal415f1732018-11-29 10:33:47 -0800847 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700848 float d = dist(x0, y0, x1, y1);
849 if (Float.compare(d, 0f) == 0) {
850 return Float.POSITIVE_INFINITY;
851 }
852 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
853 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700854
855 /**
856 * As a ratio of screen height, the total distance we want the parallax effect to span
857 * horizontally
858 */
859 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
860 float aspectRatio = width / (float) height;
861
862 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
863 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
864 // We will use these two data points to extrapolate how much the wallpaper parallax effect
865 // to span (ie travel) at any aspect ratio:
866
sfufa@google.comde013292021-09-21 18:22:44 -0700867 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
868 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700869 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
870 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
871
872 // To find out the desired width at different aspect ratios, we use the following two
873 // formulas, where the coefficient on x is the aspect ratio (width/height):
874 // (16/10)x + y = 1.5
875 // (10/16)x + y = 1.2
876 // We solve for x and y and end up with a final formula:
877 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700878 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
879 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700880 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
881 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
882 return x * aspectRatio + y;
883 }
884
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700885 public interface OnIDPChangeListener {
886
Sunny Goyalb47172b2021-05-03 19:59:51 -0700887 /**
888 * Called when the device provide changes
889 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700890 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700891 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800892
893
Sunny Goyaleff44f32019-01-09 17:29:49 -0800894 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800895
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800896 public static final String TAG_NAME = "grid-option";
897
Alex Chau1c883d82021-12-01 18:43:10 +0000898 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
899 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
900 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
901 private static final int DEVICE_CATEGORY_ALL =
902 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
903
Thales Lima11af7bc2022-08-12 15:24:54 +0100904 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
905 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
906 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
907 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
908 private static final int DONT_INLINE_QSB = 0;
909
Sunny Goyaleff44f32019-01-09 17:29:49 -0800910 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700911 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800912 public final int numRows;
913 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000914 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700915 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800916
Thales Lima1faa4ed2023-12-01 16:48:19 +0000917 private final int[] numFolderRows = new int[COUNT_SIZES];
918 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300919 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000920 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800921
Thales Limae9273ea2023-01-26 12:33:52 +0000922 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700923 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300924 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700925 private final int numDatabaseAllAppsColumns;
926 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700927 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100928
Thales Lima11af7bc2022-08-12 15:24:54 +0100929 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
930
Thales Limab35faed2022-09-05 16:30:01 -0300931 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800932 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000933
Sunny Goyal415f1732018-11-29 10:33:47 -0800934 private final int defaultLayoutId;
935 private final int demoModeLayoutId;
936
Jon Mirandae126d722021-02-25 10:45:20 -0500937 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -0800938 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400939 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100940 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100941 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100942 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100943 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100944 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100945 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100946 private final int mHotseatSpecsId;
947 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000948 private final int mWorkspaceCellSpecsId;
949 private final int mWorkspaceCellSpecsTwoPanelId;
950 private final int mAllAppsCellSpecsId;
951 private final int mAllAppsCellSpecsTwoPanelId;
fbaronebc10c92024-09-03 12:51:41 -0700952 private final int mRowCountSpecsId;
Jon Mirandae126d722021-02-25 10:45:20 -0500953
Federico Baron56307d22024-11-06 18:48:48 +0000954 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800955 TypedArray a = context.obtainStyledAttributes(
956 attrs, R.styleable.GridDisplayOption);
957 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -0700958 title = a.getString(R.styleable.GridDisplayOption_title);
959 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
960 DEVICE_CATEGORY_ALL);
961 mRowCountSpecsId = a.getResourceId(
962 R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -0800963 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbaronebc10c92024-09-03 12:51:41 -0700964 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
965 ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
Federico Baron56307d22024-11-06 18:48:48 +0000966 NumRows numR = getRowCount(resourceHelper, context, displayInfo);
fbaronebc10c92024-09-03 12:51:41 -0700967 numRows = numR.mNumRowsNew;
968 dbFile = numR.mDbFile;
969 } else {
970 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
971 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
972 }
973
Sunny Goyal415f1732018-11-29 10:33:47 -0800974 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000975 numSearchContainerColumns = a.getInt(
976 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Alex Chau766cd2b2022-07-06 17:15:21 +0100977 defaultLayoutId = a.getResourceId(
978 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800979 demoModeLayoutId = a.getResourceId(
980 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700981
Thales Limae9273ea2023-01-26 12:33:52 +0000982 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
983 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700984 numAllAppsColumns = a.getInt(
985 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
986 numDatabaseAllAppsColumns = a.getInt(
987 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
988
989 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800990 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700991 numDatabaseHotseatIcons = a.getInt(
992 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100993
Vinit Nayakc7293172022-07-18 16:41:50 -0700994 inlineNavButtonsEndSpacing =
995 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100996 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300997
Thales Lima1faa4ed2023-12-01 16:48:19 +0000998 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800999 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001000 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001001 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001002
Thales Lima1faa4ed2023-12-01 16:48:19 +00001003 if (FeatureFlags.enableResponsiveWorkspace()) {
1004 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1005 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1006 numFolderRows[INDEX_DEFAULT]);
1007 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1008 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1009 numFolderColumns[INDEX_DEFAULT]);
1010 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1011 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1012 numFolderRows[INDEX_DEFAULT]);
1013 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1014 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1015 numFolderColumns[INDEX_DEFAULT]);
1016 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1017 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1018 numFolderRows[INDEX_DEFAULT]);
1019 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1020 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1021 numFolderColumns[INDEX_DEFAULT]);
1022 } else {
1023 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1024 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1025 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1026 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1027 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1028 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1029 }
1030
Thales Limab35faed2022-09-05 16:30:01 -03001031 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1032 INVALID_RESOURCE_HANDLE);
1033
Thales Limad852d652023-01-17 14:01:13 +00001034 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1035 R.style.CellStyleDefault);
1036
Jon Mirandae126d722021-02-25 10:45:20 -05001037 isScalable = a.getBoolean(
1038 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001039 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001040 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001041
Thales Limaca31b612023-09-14 14:25:26 +01001042 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001043 mWorkspaceSpecsId = a.getResourceId(
1044 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001045 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1046 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001047 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001048 mAllAppsSpecsId = a.getResourceId(
1049 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001050 mAllAppsSpecsTwoPanelId = a.getResourceId(
1051 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001052 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001053 mFolderSpecsId = a.getResourceId(
1054 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001055 mFolderSpecsTwoPanelId = a.getResourceId(
1056 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001057 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001058 mHotseatSpecsId = a.getResourceId(
1059 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1060 mHotseatSpecsTwoPanelId = a.getResourceId(
1061 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001062 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001063 mWorkspaceCellSpecsId = a.getResourceId(
1064 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1065 INVALID_RESOURCE_HANDLE);
1066 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1067 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001068 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001069 mAllAppsCellSpecsId = a.getResourceId(
1070 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1071 INVALID_RESOURCE_HANDLE);
1072 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1073 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001074 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001075 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1076 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1077 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001078 } else {
1079 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001080 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001081 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001082 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001083 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001084 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001085 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1086 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001087 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1088 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1089 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1090 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001091 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001092 }
1093
Thales Lima11af7bc2022-08-12 15:24:54 +01001094 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1095 DONT_INLINE_QSB);
1096 inlineQsb[INDEX_DEFAULT] =
1097 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1098 inlineQsb[INDEX_LANDSCAPE] =
1099 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1100 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1101 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1102 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1103 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1104 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1105 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1106
Sunny Goyal415f1732018-11-29 10:33:47 -08001107 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001108 }
1109
1110 public boolean isEnabled(@DeviceType int deviceType) {
1111 switch (deviceType) {
1112 case TYPE_PHONE:
1113 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1114 case TYPE_TABLET:
1115 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1116 case TYPE_MULTI_DISPLAY:
1117 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1118 == DEVICE_CATEGORY_MULTI_DISPLAY;
1119 default:
1120 return false;
1121 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001122 }
fbaronebc10c92024-09-03 12:51:41 -07001123
1124 public boolean isNewGridOption() {
1125 return mRowCountSpecsId != INVALID_RESOURCE_HANDLE;
1126 }
fbaron49f7df02024-11-05 16:15:19 -08001127
1128 public boolean filterByFlag(int deviceType) {
1129 if (deviceType == TYPE_TABLET) {
1130 return Flags.oneGridRotationHandling() == mIsDualGrid;
1131 }
1132 return Flags.oneGridSpecs() == isNewGridOption();
1133 }
fbaronebc10c92024-09-03 12:51:41 -07001134 }
1135
1136 public static final class NumRows {
1137 final int mNumRowsNew;
1138 final float mMinDeviceWidthPx;
1139 final float mMinDeviceHeightPx;
1140 final String mDbFile;
1141
1142 NumRows(Context context, AttributeSet attrs) {
1143 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows);
1144
1145 mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0);
1146 mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0);
1147 mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0);
1148 mDbFile = a.getString(R.styleable.NumRows_dbFile);
1149
1150 a.recycle();
1151 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001152 }
1153
Sunny Goyal19ff7282021-04-22 10:12:54 -07001154 @VisibleForTesting
1155 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001156 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001157
Sunny Goyal415f1732018-11-29 10:33:47 -08001158 private final float minWidthDps;
1159 private final float minHeightDps;
1160 private final boolean canBeDefault;
1161
Thales Lima83bedbf2021-10-05 17:47:39 +01001162 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001163
Thales Lima78d00ad2021-09-30 11:29:06 +01001164 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001165 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001166 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1167 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001168
Thales Lima78d00ad2021-09-30 11:29:06 +01001169 private final float[] iconSizes = new float[COUNT_SIZES];
1170 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001171
Thales Limab7ef5692022-03-10 10:32:36 +00001172 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001173 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1174 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1175 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1176
Jon Miranda9c478b62023-03-23 21:38:49 -07001177 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1178
Jon Miranda04f05102023-04-04 12:16:31 -07001179 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1180
Thales Lima1de4d552021-10-13 16:13:25 +01001181 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001182 this.grid = grid;
1183
Jon Miranda9c478b62023-03-23 21:38:49 -07001184 Resources res = context.getResources();
1185
Thales Lima1de4d552021-10-13 16:13:25 +01001186 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001187
Sunny Goyal415f1732018-11-29 10:33:47 -08001188 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1189 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001190
Thales Lima1de4d552021-10-13 16:13:25 +01001191 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001192
Thales Lima83bedbf2021-10-05 17:47:39 +01001193 float x;
1194 float y;
1195
Thales Lima85c942f2021-12-31 13:04:20 +00001196 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1197 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001198 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001199
1200 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1201 minCellSize[INDEX_DEFAULT].x);
1202 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1203 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001204 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001205
Thales Lima85c942f2021-12-31 13:04:20 +00001206 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001207 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001208 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001209 minCellSize[INDEX_DEFAULT].y);
1210 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1211
Thales Lima85c942f2021-12-31 13:04:20 +00001212 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001213 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001214 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001215 minCellSize[INDEX_DEFAULT].y);
1216 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001217
Thales Lima85c942f2021-12-31 13:04:20 +00001218 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001219 float borderSpaceLandscape = a.getFloat(
1220 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001221 float borderSpaceTwoPanelPortrait = a.getFloat(
1222 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1223 float borderSpaceTwoPanelLandscape = a.getFloat(
1224 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001225
Thales Lima85c942f2021-12-31 13:04:20 +00001226 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1227 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001228 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001229
1230 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1231 borderSpaceLandscape);
1232 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1233 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001234 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1235
1236 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001237 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1238 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001239 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001240 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1241 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001242 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1243
1244 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001245 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1246 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001247 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001248 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1249 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001250 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1251
Thales Limab7ef5692022-03-10 10:32:36 +00001252 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1253 minCellSize[INDEX_DEFAULT].x);
1254 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1255 minCellSize[INDEX_DEFAULT].y);
1256 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1257
1258 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1259 allAppsCellSize[INDEX_DEFAULT].x);
1260 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1261 allAppsCellSize[INDEX_DEFAULT].y);
1262 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1263
1264 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1265 allAppsCellSize[INDEX_DEFAULT].x);
1266 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1267 allAppsCellSize[INDEX_DEFAULT].y);
1268 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1269
1270 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1271 allAppsCellSize[INDEX_DEFAULT].x);
1272 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1273 allAppsCellSize[INDEX_DEFAULT].y);
1274 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1275
Thales Lima080d8902022-03-28 15:30:29 +01001276 float allAppsBorderSpace = a.getFloat(
1277 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1278 float allAppsBorderSpaceLandscape = a.getFloat(
1279 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1280 allAppsBorderSpace);
1281 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001282 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001283 allAppsBorderSpace);
1284 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001285 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001286 allAppsBorderSpace);
1287
1288 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1289 allAppsBorderSpace);
1290 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1291 allAppsBorderSpace);
1292 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1293
1294 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1295 allAppsBorderSpaceLandscape);
1296 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1297 allAppsBorderSpaceLandscape);
1298 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1299
1300 x = a.getFloat(
1301 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1302 allAppsBorderSpaceTwoPanelPortrait);
1303 y = a.getFloat(
1304 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1305 allAppsBorderSpaceTwoPanelPortrait);
1306 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1307
1308 x = a.getFloat(
1309 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1310 allAppsBorderSpaceTwoPanelLandscape);
1311 y = a.getFloat(
1312 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1313 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001314 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001315
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001316 iconSizes[INDEX_DEFAULT] =
1317 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1318 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001319 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001320 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001321 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001322 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001323 iconSizes[INDEX_DEFAULT]);
1324 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001325 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001326 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001327
Thales Limabb7d3882021-12-22 12:56:29 +00001328 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1329 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001330 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1331 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001332 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001333 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1334 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1335 allAppsIconSizes[INDEX_DEFAULT]);
1336 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1337 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1338 allAppsIconSizes[INDEX_DEFAULT]);
1339
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001340 textSizes[INDEX_DEFAULT] =
1341 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1342 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001343 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001344 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001345 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001346 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001347 textSizes[INDEX_DEFAULT]);
1348 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001349 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001350 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001351
Thales Limabb7d3882021-12-22 12:56:29 +00001352 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1353 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1354 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1355 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1356 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1357 allAppsIconTextSizes[INDEX_DEFAULT]);
1358 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1359 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1360 allAppsIconTextSizes[INDEX_DEFAULT]);
1361
Thales Lima83bedbf2021-10-05 17:47:39 +01001362 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1363 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001364 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1365 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1366 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001367 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001368 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001369 horizontalMargin[INDEX_DEFAULT]);
1370 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001371 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001372 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001373
Thales Limab8c05952022-05-23 16:58:38 +01001374 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1375 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001376 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001377 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1378 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1379 hotseatBarBottomSpace[INDEX_DEFAULT]);
1380 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1381 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1382 hotseatBarBottomSpace[INDEX_DEFAULT]);
1383 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1384 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1385 hotseatBarBottomSpace[INDEX_DEFAULT]);
1386
1387 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1388 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001389 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001390 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1391 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1392 hotseatQsbSpace[INDEX_DEFAULT]);
1393 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1394 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1395 hotseatQsbSpace[INDEX_DEFAULT]);
1396 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1397 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1398 hotseatQsbSpace[INDEX_DEFAULT]);
1399
Jon Miranda9c478b62023-03-23 21:38:49 -07001400 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1401 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1402 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1403 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1404 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1405 transientTaskbarIconSize[INDEX_DEFAULT]);
1406 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1407 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1408 transientTaskbarIconSize[INDEX_DEFAULT]);
1409 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1410 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001411 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001412
Jon Miranda04f05102023-04-04 12:16:31 -07001413 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1414 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1415 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1416 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1417 startAlignTaskbar[INDEX_DEFAULT]);
1418 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1419 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1420 startAlignTaskbar[INDEX_LANDSCAPE]);
1421 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1422 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1423 startAlignTaskbar[INDEX_DEFAULT]);
1424
Sunny Goyal415f1732018-11-29 10:33:47 -08001425 a.recycle();
1426 }
1427
1428 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001429 this(null);
1430 }
1431
1432 DisplayOption(GridOption grid) {
1433 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001434 minWidthDps = 0;
1435 minHeightDps = 0;
1436 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001437 for (int i = 0; i < COUNT_SIZES; i++) {
1438 iconSizes[i] = 0;
1439 textSizes[i] = 0;
1440 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001441 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001442 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001443 allAppsIconSizes[i] = 0;
1444 allAppsIconTextSizes[i] = 0;
1445 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001446 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001447 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001448 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001449 }
1450
1451 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001452 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001453 iconSizes[i] *= w;
1454 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001455 borderSpaces[i].x *= w;
1456 borderSpaces[i].y *= w;
1457 minCellSize[i].x *= w;
1458 minCellSize[i].y *= w;
1459 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001460 hotseatBarBottomSpace[i] *= w;
1461 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001462 allAppsCellSize[i].x *= w;
1463 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001464 allAppsIconSizes[i] *= w;
1465 allAppsIconTextSizes[i] *= w;
1466 allAppsBorderSpaces[i].x *= w;
1467 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001468 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001469 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001470
Sunny Goyal415f1732018-11-29 10:33:47 -08001471 return this;
1472 }
1473
1474 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001475 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001476 iconSizes[i] += p.iconSizes[i];
1477 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001478 borderSpaces[i].x += p.borderSpaces[i].x;
1479 borderSpaces[i].y += p.borderSpaces[i].y;
1480 minCellSize[i].x += p.minCellSize[i].x;
1481 minCellSize[i].y += p.minCellSize[i].y;
1482 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001483 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1484 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001485 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1486 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001487 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1488 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1489 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1490 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001491 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001492 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001493 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001494
Sunny Goyal415f1732018-11-29 10:33:47 -08001495 return this;
1496 }
1497 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001498}