blob: 2e0f6762b4014fb21cdc69b571c98065903c360b [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;
Alex Chau6ed408f2022-03-04 12:58:05 +000023import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070024import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070025import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080026import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070027
Sunny Goyalc6205602015-05-21 20:46:33 -070028import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070029import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080030import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070031import android.content.res.TypedArray;
32import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070033import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010034import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000035import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080036import android.text.TextUtils;
37import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070038import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010039import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080040import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070041import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080042import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070043
Thales Limab35faed2022-09-05 16:30:01 -030044import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000045import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030046import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000048import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070050
Thales Limaec5abba2023-04-05 16:33:50 +010051import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070052import com.android.launcher3.icons.DotRenderer;
Charlie Andersonc9d11e82023-08-02 11:41:55 -040053import com.android.launcher3.logging.FileLog;
Sunny Goyal68031ca2021-08-02 12:23:44 -070054import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010055import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070056import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070057import com.android.launcher3.util.DisplayController;
58import com.android.launcher3.util.DisplayController.Info;
Stefan Andonian5bd9a222023-02-23 00:58:33 +000059import com.android.launcher3.util.LockedUserState;
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;
Sunny Goyal19ff7282021-04-22 10:12:54 -070062import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080063import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070064
Sunny Goyal819e1932016-07-07 16:43:58 -070065import org.xmlpull.v1.XmlPullParser;
66import org.xmlpull.v1.XmlPullParserException;
67
68import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000069import java.lang.annotation.Retention;
70import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070071import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070072import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080073import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070074import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000075import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070076import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070077
78public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Hyunyoung Songc55a3502018-12-04 15:43:16 -080080 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070081 // We do not need any synchronization for this variable as its only written on UI thread.
82 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070083 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070084
Alex Chau1c883d82021-12-01 18:43:10 +000085 @Retention(RetentionPolicy.SOURCE)
86 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010087 public @interface DeviceType {}
88
Alex Chau1c883d82021-12-01 18:43:10 +000089 public static final int TYPE_PHONE = 0;
90 public static final int TYPE_MULTI_DISPLAY = 1;
91 public static final int TYPE_TABLET = 2;
92
Sunny Goyal53d7ee42015-05-22 12:25:45 -070093 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
94
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070095 // Constants that affects the interpolation curve between statically defined device profile
96 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080097 private static final float KNEARESTNEIGHBOR = 3;
98 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070099
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700100 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800101 private static final float WEIGHT_EFFICIENT = 100000f;
102
Thales Lima83bedbf2021-10-05 17:47:39 +0100103 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
104 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000105 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100106 static final int INDEX_DEFAULT = 0;
107 static final int INDEX_LANDSCAPE = 1;
108 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
109 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100110
Thales Limaec5abba2023-04-05 16:33:50 +0100111 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800112 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
113 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
114 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
115
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700116 /**
117 * Number of icons per row and column in the workspace.
118 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700119 public int numRows;
120 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000121 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700122
123 /**
124 * Number of icons per row and column in the folder.
125 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000126 public int[] numFolderRows;
127 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100128 public float[] iconSize;
129 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700130 public int iconBitmapSize;
131 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000132 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700133
Thales Lima83bedbf2021-10-05 17:47:39 +0100134 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100135
Thales Lima83bedbf2021-10-05 17:47:39 +0100136 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300137 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100138
Thales Limab35faed2022-09-05 16:30:01 -0300139 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100140
Thales Limad852d652023-01-17 14:01:13 +0000141 public @StyleRes int cellStyle;
142
Thales Lima83bedbf2021-10-05 17:47:39 +0100143 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500144
Thales Limab7ef5692022-03-10 10:32:36 +0000145 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000146 public float[] allAppsIconSize;
147 public float[] allAppsIconTextSize;
148 public PointF[] allAppsBorderSpaces;
149
Jon Miranda9c478b62023-03-23 21:38:49 -0700150 public float[] transientTaskbarIconSize;
151
Jon Miranda04f05102023-04-04 12:16:31 -0700152 public boolean[] startAlignTaskbar;
153
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700154 /**
155 * Number of icons inside the hotseat area.
156 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800157 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700158
159 /**
160 * Number of icons inside the hotseat area that is stored in the database. This is greater than
161 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
162 * sizes that share the same DB.
163 */
164 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700165
Thales Lima425f6822022-05-10 13:44:58 -0300166 public int[] hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100167 public float[] hotseatBarBottomSpace;
168 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300169
Jon Miranda6f7e9702019-09-16 14:44:14 -0700170 /**
171 * Number of columns in the all apps list.
172 */
173 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300174 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700175 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000176 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700177
Jon Mirandae126d722021-02-25 10:45:20 -0500178 /**
179 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
180 */
181 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000182 @XmlRes
183 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100184 @XmlRes
185 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100186 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100187 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
188 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100189 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100190 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100191 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
192 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100193 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100194 @XmlRes
195 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000196 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100197 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000198 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100199 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000200 @XmlRes
201 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
202 @XmlRes
203 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
204 @XmlRes
205 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
206 @XmlRes
207 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500208
Tracy Zhou7df93d22020-01-27 13:44:06 -0800209 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800210 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700211 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100212 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700213
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000214 /**
215 * An immutable list of supported profiles.
216 */
217 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700218
Sunny Goyal6f866092016-03-17 17:04:15 -0700219 public Point defaultWallpaperSize;
220
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700221 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700222
Sunny Goyalf633ef52018-03-13 09:57:05 -0700223 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800224 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700225
Sunny Goyalbbf01842015-10-08 07:41:15 -0700226 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700227 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700228 String gridName = getCurrentGridName(context);
229 String newGridName = initGrid(context, gridName);
230 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000231 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700232 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000233 LockedUserState.get(context).runOnUserUnlocked(() -> {
234 new DeviceGridState(this).writeToPrefs(context);
235 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700237 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100238 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000239 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700240 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100241 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700242 }
243 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700244 }
245
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700246 /**
247 * This constructor should NOT have any monitors by design.
248 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800249 public InvariantDeviceProfile(Context context, String gridName) {
250 String newName = initGrid(context, gridName);
251 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000252 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800253 }
254 }
255
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700256 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800257 * This constructor should NOT have any monitors by design.
258 */
259 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700260 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100261 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 String gridName = getCurrentGridName(context);
263
264 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000265 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
266 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700267 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000268 defaultInfo,
269 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
270 /*allowDisabledGrid=*/false),
271 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700272
Alex Chau661f02d2022-06-07 14:03:43 +0100273 Context displayContext = context.createDisplayContext(display);
274 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000275 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700276 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000277 myInfo,
278 getPredefinedDeviceProfiles(context, gridName, deviceType,
279 /*allowDisabledGrid=*/false),
280 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281
282 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
283 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100284 result.iconSizes[INDEX_DEFAULT] =
285 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
286 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700287 result.iconSizes[i] = Math.min(
288 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000289 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700290
Thales Lima83bedbf2021-10-05 17:47:39 +0100291 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
292 COUNT_SIZES);
293 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
294 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500295
Alex Chau1c883d82021-12-01 18:43:10 +0000296 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800297 }
298
Alex Chau238aaee2021-10-06 16:15:24 +0100299 /**
300 * Reinitialize the current grid after a restore, where some grids might now be disabled.
301 */
302 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000303 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100304 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000305 String newGridName = initGrid(context, currentGridName);
306 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400307 FileLog.d(TAG, "Reinitializing grid after restore."
308 + " currentGridName=" + currentGridName
309 + ", currentDbFile=" + currentDbFile
310 + ", newGridName=" + newGridName
311 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000312 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400313 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100314 + ", migrating to: " + newGridName
315 + ", removing all other grid db files");
316 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
317 if (gridDbFile.equals(currentDbFile)) {
318 continue;
319 }
320 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400321 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100322 }
323 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000324 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100325 }
326 }
327
Alex Chau1c883d82021-12-01 18:43:10 +0000328 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800329 int flagPhone = 1 << 0;
330 int flagTablet = 1 << 1;
331
332 int type = displayInfo.supportedBounds.stream()
333 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
334 .reduce(0, (a, b) -> a | b);
Sebastian Francof3766132023-09-07 14:50:07 -0700335 if (type == (flagPhone | flagTablet)) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800336 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000337 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800338 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000339 return TYPE_TABLET;
340 } else {
341 return TYPE_PHONE;
342 }
343 }
344
Tracy Zhou42255d22020-03-13 00:38:11 -0700345 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000346 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700347 }
348
Sunny Goyaleff44f32019-01-09 17:29:49 -0800349 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700350 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000351 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700352
353 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000354 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100355 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700356 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000357 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
358 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700359 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800360 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700361
Thales Limab67bfa72022-11-02 15:30:11 +0000362 @VisibleForTesting
363 public static String getDefaultGridName(Context context) {
364 return new InvariantDeviceProfile().initGrid(context, null);
365 }
366
Alex Chau1c883d82021-12-01 18:43:10 +0000367 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
368 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700369 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700370 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000371 numRows = closestProfile.numRows;
372 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000373 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000374 dbFile = closestProfile.dbFile;
375 defaultLayoutId = closestProfile.defaultLayoutId;
376 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300377
Sunny Goyalae190ff2020-04-14 00:19:01 +0000378 numFolderRows = closestProfile.numFolderRows;
379 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300380 folderStyle = closestProfile.folderStyle;
381
Thales Limad852d652023-01-17 14:01:13 +0000382 cellStyle = closestProfile.cellStyle;
383
Jon Mirandae126d722021-02-25 10:45:20 -0500384 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400385 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100386 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100387 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100388 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100389 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100390 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100391 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100392 hotseatSpecsId = closestProfile.mHotseatSpecsId;
393 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000394 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
395 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
396 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
397 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300398 numAllAppsRowsForCellHeightCalculation =
399 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000400 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000401
Vinit Nayakc7293172022-07-18 16:41:50 -0700402 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
403
Thales Lima83bedbf2021-10-05 17:47:39 +0100404 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100405 float maxIconSize = iconSize[0];
406 for (int i = 1; i < iconSize.length; i++) {
407 maxIconSize = Math.max(maxIconSize, iconSize[i]);
408 }
409 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000410 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
411
Thales Lima83bedbf2021-10-05 17:47:39 +0100412 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700413
Thales Lima83bedbf2021-10-05 17:47:39 +0100414 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100415
Thales Lima83bedbf2021-10-05 17:47:39 +0100416 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100417
Thales Limad90faab2021-09-21 17:18:47 +0100418 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100419
Sunny Goyal19ff7282021-04-22 10:12:54 -0700420 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000421 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700422 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300423 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100424 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
425 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700426
Thales Limae9273ea2023-01-26 12:33:52 +0000427 allAppsStyle = closestProfile.allAppsStyle;
428
Sunny Goyal19ff7282021-04-22 10:12:54 -0700429 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300430
Alex Chau1c883d82021-12-01 18:43:10 +0000431 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700432 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500433
Thales Limab7ef5692022-03-10 10:32:36 +0000434 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000435 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
436 allAppsIconSize = displayOption.allAppsIconSizes;
437 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000438
Thales Lima11af7bc2022-08-12 15:24:54 +0100439 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000440
Jon Miranda9c478b62023-03-23 21:38:49 -0700441 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
442
Jon Miranda04f05102023-04-04 12:16:31 -0700443 startAlignTaskbar = displayOption.startAlignTaskbar;
444
Sunny Goyalae190ff2020-04-14 00:19:01 +0000445 // If the partner customization apk contains any grid overrides, apply them
446 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700447 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700448
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000449 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700450 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700451 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700452 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000453 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000454 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000455 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700456 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000457 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700458
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
460 int displayWidth = bounds.bounds.width();
461 int displayHeight = bounds.bounds.height();
462 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700463
Sunny Goyal19ff7282021-04-22 10:12:54 -0700464 // We need to ensure that there is enough extra space in the wallpaper
465 // for the intended parallax effects
466 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300467 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
468 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700469 ? 2
470 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
471 defaultWallpaperSize.x =
472 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700473 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000474 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700475
Thales Lima6a590062022-11-22 15:52:49 +0000476 int numMinShownHotseatIconsForTablet = supportedProfiles
477 .stream()
478 .filter(deviceProfile -> deviceProfile.isTablet)
479 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
480 .min()
481 .orElse(0);
482
483 supportedProfiles
484 .stream()
485 .filter(deviceProfile -> deviceProfile.isTablet)
486 .forEach(deviceProfile -> {
487 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
488 deviceProfile.recalculateHotseatWidthAndBorderSpace();
489 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700490 }
491
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700492 public void addOnChangeListener(OnIDPChangeListener listener) {
493 mChangeListeners.add(listener);
494 }
495
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800496 public void removeOnChangeListener(OnIDPChangeListener listener) {
497 mChangeListeners.remove(listener);
498 }
499
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800500
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800501 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000502 LauncherPrefs.get(context).put(GRID_NAME, gridName);
503 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800504 }
505
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700506 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700507 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000508 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
509 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700510 }
511
Pat Manning24cec692023-10-13 10:36:57 +0000512 /** Updates IDP using the provided context. Notifies listeners of change. */
513 @VisibleForTesting
514 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700515 Object[] oldState = toModelState();
516
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700517 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700518 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700519 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700520
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700521 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700522 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700523 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700524 }
525 }
526
Alex Chau1c883d82021-12-01 18:43:10 +0000527 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
528 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800529 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100530
Alex Chau1c883d82021-12-01 18:43:10 +0000531 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700532 final int depth = parser.getDepth();
533 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700534 while (((type = parser.next()) != XmlPullParser.END_TAG ||
535 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800536 if ((type == XmlPullParser.START_TAG)
537 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800538
Sunny Goyal076e04b2023-04-03 12:38:30 -0700539 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
540 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100541 final int displayDepth = parser.getDepth();
542 while (((type = parser.next()) != XmlPullParser.END_TAG
543 || parser.getDepth() > displayDepth)
544 && type != XmlPullParser.END_DOCUMENT) {
545 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
546 parser.getName())) {
547 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100548 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100549 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800550 }
551 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700552 }
553 }
sfufa@google.comde013292021-09-21 18:22:44 -0700554 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700555 throw new RuntimeException(e);
556 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800557
Sunny Goyalae190ff2020-04-14 00:19:01 +0000558 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800559 if (!TextUtils.isEmpty(gridName)) {
560 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100561 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700562 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000563 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800564 }
565 }
566 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000567 if (filteredProfiles.isEmpty()) {
568 // No grid found, use the default options
569 for (DisplayOption option : profiles) {
570 if (option.canBeDefault) {
571 filteredProfiles.add(option);
572 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800573 }
574 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000575 if (filteredProfiles.isEmpty()) {
576 throw new RuntimeException("No display option with canBeDefault=true");
577 }
578 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700579 }
580
Thales Lima7ec83822021-08-05 13:32:10 +0100581 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000582 * Returns the GridOption associated to the given file name or null if the fileName is not
583 * supported.
584 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
585 */
586 public GridOption getGridOptionFromFileName(Context context, String fileName) {
587 return parseAllGridOptions(context).stream()
588 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
589 .findFirst()
590 .orElse(null);
591 }
592
593 /**
594 * Returns the name of the given size on the current device or empty string if the size is not
595 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
596 * (Note: the name of the grid can be different for the same grid size depending of
597 * the values of the InvariantDeviceProfile)
598 *
599 */
600 public String getGridNameFromSize(Context context, Point size) {
601 return parseAllGridOptions(context).stream()
602 .filter(gridOption -> gridOption.numColumns == size.x
603 && gridOption.numRows == size.y)
604 .map(gridOption -> gridOption.name)
605 .findFirst()
606 .orElse("");
607 }
608
609 /**
610 * Returns the grid option for the given gridName on the current device (Note: the gridOption
611 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
612 */
613 public GridOption getGridOptionFromName(Context context, String gridName) {
614 return parseAllGridOptions(context).stream()
615 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
616 .findFirst()
617 .orElse(null);
618 }
619
620 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100621 * @return all the grid options that can be shown on the device
622 */
623 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700624 return parseAllDefinedGridOptions(context)
625 .stream()
626 .filter(go -> go.isEnabled(deviceType))
627 .collect(Collectors.toList());
628 }
629
630 /**
631 * @return all the grid options that can be shown on the device
632 */
633 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100634 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100635
Alex Chau1c883d82021-12-01 18:43:10 +0000636 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100637 final int depth = parser.getDepth();
638 int type;
639 while (((type = parser.next()) != XmlPullParser.END_TAG
640 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
641 if ((type == XmlPullParser.START_TAG)
642 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700643 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100644 }
645 }
646 } catch (IOException | XmlPullParserException e) {
647 Log.e(TAG, "Error parsing device profile", e);
648 return Collections.emptyList();
649 }
650 return result;
651 }
652
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700653 private int getLauncherIconDensity(int requiredSize) {
654 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700655 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700656 DisplayMetrics.DENSITY_LOW,
657 DisplayMetrics.DENSITY_MEDIUM,
658 DisplayMetrics.DENSITY_TV,
659 DisplayMetrics.DENSITY_HIGH,
660 DisplayMetrics.DENSITY_XHIGH,
661 DisplayMetrics.DENSITY_XXHIGH,
662 DisplayMetrics.DENSITY_XXXHIGH
663 };
664
665 int density = DisplayMetrics.DENSITY_XXXHIGH;
666 for (int i = densityBuckets.length - 1; i >= 0; i--) {
667 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
668 / DisplayMetrics.DENSITY_DEFAULT;
669 if (expectedSize >= requiredSize) {
670 density = densityBuckets[i];
671 }
672 }
673
674 return density;
675 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700676
Adam Cohen2e6da152015-05-06 11:42:25 -0700677 /**
678 * Apply any Partner customization grid overrides.
679 *
680 * Currently we support: all apps row / column count.
681 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700682 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
683 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800684 if (p == null) {
685 return;
686 }
687 try {
688 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
689 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
690 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
691
692 if (numRows > 0 && numColumns > 0) {
693 this.numRows = numRows;
694 this.numColumns = numColumns;
695 }
696 if (iconSizePx > 0) {
697 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
698 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
699 }
700 } catch (Resources.NotFoundException ex) {
701 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700702 }
703 }
704
Sunny Goyal415f1732018-11-29 10:33:47 -0800705 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700706 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700707 }
708
Sunny Goyal19ff7282021-04-22 10:12:54 -0700709 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000710 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700711 int minWidthPx = Integer.MAX_VALUE;
712 int minHeightPx = Integer.MAX_VALUE;
713 for (WindowBounds bounds : displayInfo.supportedBounds) {
714 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000715 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700716 // For split displays, take half width per page
717 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
718 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700719
Sunny Goyal19ff7282021-04-22 10:12:54 -0700720 } else if (!isTablet && bounds.isLandscape()) {
721 // We will use transposed layout in this case
722 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
723 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
724 } else {
725 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
726 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
727 }
728 }
729
Thales Lima425f6822022-05-10 13:44:58 -0300730 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
731 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700732
733 // Sort the profiles based on the closeness to the device size
734 Collections.sort(points, (a, b) ->
735 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
736 dist(width, height, b.minWidthDps, b.minHeightDps)));
737
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700738 DisplayOption closestPoint = points.get(0);
739 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700740 float weights = 0;
741
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700742 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
743 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700744 }
745
746 DisplayOption out = new DisplayOption(closestOption);
747 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700748 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700749 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
750 weights += w;
751 out.add(new DisplayOption().add(p).multiply(w));
752 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700753 out.multiply(1.0f / weights);
754
Thales Lima6e0005a2021-10-27 15:53:41 +0100755 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700756 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100757 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
758 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700759 }
760
761 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700762 }
763
Sunny Goyal27835952017-01-13 12:15:53 -0800764 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000765 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
766 Rect bounds = windowManagerProxy.getCurrentBounds(context);
767 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768
Alex Chauc09a98a2023-11-14 12:51:42 +0000769 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400770 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700771
Sunny Goyal187b16c2022-03-01 16:53:23 -0800772 /**
773 * Returns the device profile matching the provided screen configuration
774 */
775 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700776 DeviceProfile bestMatch = supportedProfiles.get(0);
777 float minDiff = Float.MAX_VALUE;
778
779 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400780 float diff = Math.abs(profile.widthPx - screenWidth)
781 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700782 if (diff < minDiff) {
783 minDiff = diff;
784 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800785 } else if (diff == minDiff && profile.rotationHint == rotation) {
786 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700787 }
788 }
789 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800790 }
791
Sunny Goyal415f1732018-11-29 10:33:47 -0800792 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700793 float d = dist(x0, y0, x1, y1);
794 if (Float.compare(d, 0f) == 0) {
795 return Float.POSITIVE_INFINITY;
796 }
797 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
798 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700799
800 /**
801 * As a ratio of screen height, the total distance we want the parallax effect to span
802 * horizontally
803 */
804 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
805 float aspectRatio = width / (float) height;
806
807 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
808 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
809 // We will use these two data points to extrapolate how much the wallpaper parallax effect
810 // to span (ie travel) at any aspect ratio:
811
sfufa@google.comde013292021-09-21 18:22:44 -0700812 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
813 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700814 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
815 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
816
817 // To find out the desired width at different aspect ratios, we use the following two
818 // formulas, where the coefficient on x is the aspect ratio (width/height):
819 // (16/10)x + y = 1.5
820 // (10/16)x + y = 1.2
821 // We solve for x and y and end up with a final formula:
822 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700823 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
824 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700825 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
826 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
827 return x * aspectRatio + y;
828 }
829
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700830 public interface OnIDPChangeListener {
831
Sunny Goyalb47172b2021-05-03 19:59:51 -0700832 /**
833 * Called when the device provide changes
834 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700835 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700836 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800837
838
Sunny Goyaleff44f32019-01-09 17:29:49 -0800839 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800840
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800841 public static final String TAG_NAME = "grid-option";
842
Alex Chau1c883d82021-12-01 18:43:10 +0000843 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
844 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
845 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
846 private static final int DEVICE_CATEGORY_ALL =
847 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
848
Thales Lima11af7bc2022-08-12 15:24:54 +0100849 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
850 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
851 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
852 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
853 private static final int DONT_INLINE_QSB = 0;
854
Sunny Goyaleff44f32019-01-09 17:29:49 -0800855 public final String name;
856 public final int numRows;
857 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000858 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700859 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800860
Thales Lima1faa4ed2023-12-01 16:48:19 +0000861 private final int[] numFolderRows = new int[COUNT_SIZES];
862 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300863 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000864 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800865
Thales Limae9273ea2023-01-26 12:33:52 +0000866 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700867 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300868 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700869 private final int numDatabaseAllAppsColumns;
870 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700871 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100872
Thales Lima425f6822022-05-10 13:44:58 -0300873 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800874
Thales Lima11af7bc2022-08-12 15:24:54 +0100875 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
876
Thales Limab35faed2022-09-05 16:30:01 -0300877 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800878 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000879
Sunny Goyal415f1732018-11-29 10:33:47 -0800880 private final int defaultLayoutId;
881 private final int demoModeLayoutId;
882
Jon Mirandae126d722021-02-25 10:45:20 -0500883 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400884 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100885 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100886 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100887 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100888 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100889 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100890 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100891 private final int mHotseatSpecsId;
892 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000893 private final int mWorkspaceCellSpecsId;
894 private final int mWorkspaceCellSpecsTwoPanelId;
895 private final int mAllAppsCellSpecsId;
896 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500897
Sunny Goyal076e04b2023-04-03 12:38:30 -0700898 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800899 TypedArray a = context.obtainStyledAttributes(
900 attrs, R.styleable.GridDisplayOption);
901 name = a.getString(R.styleable.GridDisplayOption_name);
902 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
903 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000904 numSearchContainerColumns = a.getInt(
905 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800906
Tracy Zhou7df93d22020-01-27 13:44:06 -0800907 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100908 defaultLayoutId = a.getResourceId(
909 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800910 demoModeLayoutId = a.getResourceId(
911 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700912
Thales Limae9273ea2023-01-26 12:33:52 +0000913 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
914 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700915 numAllAppsColumns = a.getInt(
916 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
917 numDatabaseAllAppsColumns = a.getInt(
918 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
919
920 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800921 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700922 numDatabaseHotseatIcons = a.getInt(
923 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100924
Thales Lima425f6822022-05-10 13:44:58 -0300925 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
926 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
927 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
928 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
929 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
930 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
931 numColumns);
932 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
933 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
934 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700935
Vinit Nayakc7293172022-07-18 16:41:50 -0700936 inlineNavButtonsEndSpacing =
937 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100938 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300939
Thales Lima1faa4ed2023-12-01 16:48:19 +0000940 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800941 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000942 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800943 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700944
Thales Lima1faa4ed2023-12-01 16:48:19 +0000945 if (FeatureFlags.enableResponsiveWorkspace()) {
946 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
947 R.styleable.GridDisplayOption_numFolderRowsLandscape,
948 numFolderRows[INDEX_DEFAULT]);
949 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
950 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
951 numFolderColumns[INDEX_DEFAULT]);
952 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
953 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
954 numFolderRows[INDEX_DEFAULT]);
955 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
956 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
957 numFolderColumns[INDEX_DEFAULT]);
958 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
959 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
960 numFolderRows[INDEX_DEFAULT]);
961 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
962 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
963 numFolderColumns[INDEX_DEFAULT]);
964 } else {
965 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
966 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
967 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
968 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
969 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
970 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
971 }
972
Thales Limab35faed2022-09-05 16:30:01 -0300973 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
974 INVALID_RESOURCE_HANDLE);
975
Thales Limad852d652023-01-17 14:01:13 +0000976 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
977 R.style.CellStyleDefault);
978
Jon Mirandae126d722021-02-25 10:45:20 -0500979 isScalable = a.getBoolean(
980 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400981 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000982 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700983 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000984 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100985
Thales Limaca31b612023-09-14 14:25:26 +0100986 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100987 mWorkspaceSpecsId = a.getResourceId(
988 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100989 mWorkspaceSpecsTwoPanelId = a.getResourceId(
990 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300991 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100992 mAllAppsSpecsId = a.getResourceId(
993 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100994 mAllAppsSpecsTwoPanelId = a.getResourceId(
995 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300996 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100997 mFolderSpecsId = a.getResourceId(
998 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100999 mFolderSpecsTwoPanelId = a.getResourceId(
1000 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001001 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001002 mHotseatSpecsId = a.getResourceId(
1003 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1004 mHotseatSpecsTwoPanelId = a.getResourceId(
1005 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001006 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001007 mWorkspaceCellSpecsId = a.getResourceId(
1008 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1009 INVALID_RESOURCE_HANDLE);
1010 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1011 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001012 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001013 mAllAppsCellSpecsId = a.getResourceId(
1014 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1015 INVALID_RESOURCE_HANDLE);
1016 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1017 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001018 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001019 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1020 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1021 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001022 } else {
1023 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001024 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001025 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001026 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001027 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001028 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001029 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1030 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001031 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1032 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1033 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1034 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001035 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001036 }
1037
Thales Lima11af7bc2022-08-12 15:24:54 +01001038 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1039 DONT_INLINE_QSB);
1040 inlineQsb[INDEX_DEFAULT] =
1041 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1042 inlineQsb[INDEX_LANDSCAPE] =
1043 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1044 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1045 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1046 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1047 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1048 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1049 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1050
Sunny Goyal415f1732018-11-29 10:33:47 -08001051 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001052 }
1053
1054 public boolean isEnabled(@DeviceType int deviceType) {
1055 switch (deviceType) {
1056 case TYPE_PHONE:
1057 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1058 case TYPE_TABLET:
1059 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1060 case TYPE_MULTI_DISPLAY:
1061 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1062 == DEVICE_CATEGORY_MULTI_DISPLAY;
1063 default:
1064 return false;
1065 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001066 }
1067 }
1068
Sunny Goyal19ff7282021-04-22 10:12:54 -07001069 @VisibleForTesting
1070 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001071 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001072
Sunny Goyal415f1732018-11-29 10:33:47 -08001073 private final float minWidthDps;
1074 private final float minHeightDps;
1075 private final boolean canBeDefault;
1076
Thales Lima83bedbf2021-10-05 17:47:39 +01001077 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001078
Thales Lima78d00ad2021-09-30 11:29:06 +01001079 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001080 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001081 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1082 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001083
Thales Lima78d00ad2021-09-30 11:29:06 +01001084 private final float[] iconSizes = new float[COUNT_SIZES];
1085 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001086
Thales Limab7ef5692022-03-10 10:32:36 +00001087 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001088 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1089 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1090 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1091
Jon Miranda9c478b62023-03-23 21:38:49 -07001092 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1093
Jon Miranda04f05102023-04-04 12:16:31 -07001094 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1095
Thales Lima1de4d552021-10-13 16:13:25 +01001096 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001097 this.grid = grid;
1098
Jon Miranda9c478b62023-03-23 21:38:49 -07001099 Resources res = context.getResources();
1100
Thales Lima1de4d552021-10-13 16:13:25 +01001101 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001102
Sunny Goyal415f1732018-11-29 10:33:47 -08001103 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1104 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001105
Thales Lima1de4d552021-10-13 16:13:25 +01001106 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001107
Thales Lima83bedbf2021-10-05 17:47:39 +01001108 float x;
1109 float y;
1110
Thales Lima85c942f2021-12-31 13:04:20 +00001111 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1112 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001113 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001114
1115 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1116 minCellSize[INDEX_DEFAULT].x);
1117 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1118 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001119 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001120
Thales Lima85c942f2021-12-31 13:04:20 +00001121 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001122 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001123 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001124 minCellSize[INDEX_DEFAULT].y);
1125 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1126
Thales Lima85c942f2021-12-31 13:04:20 +00001127 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001128 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001129 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001130 minCellSize[INDEX_DEFAULT].y);
1131 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001132
Thales Lima85c942f2021-12-31 13:04:20 +00001133 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001134 float borderSpaceLandscape = a.getFloat(
1135 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001136 float borderSpaceTwoPanelPortrait = a.getFloat(
1137 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1138 float borderSpaceTwoPanelLandscape = a.getFloat(
1139 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001140
Thales Lima85c942f2021-12-31 13:04:20 +00001141 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1142 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001143 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001144
1145 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1146 borderSpaceLandscape);
1147 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1148 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001149 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1150
1151 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001152 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1153 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001154 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001155 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1156 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001157 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1158
1159 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001160 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1161 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001162 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001163 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1164 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001165 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1166
Thales Limab7ef5692022-03-10 10:32:36 +00001167 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1168 minCellSize[INDEX_DEFAULT].x);
1169 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1170 minCellSize[INDEX_DEFAULT].y);
1171 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1172
1173 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1174 allAppsCellSize[INDEX_DEFAULT].x);
1175 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1176 allAppsCellSize[INDEX_DEFAULT].y);
1177 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1178
1179 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1180 allAppsCellSize[INDEX_DEFAULT].x);
1181 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1182 allAppsCellSize[INDEX_DEFAULT].y);
1183 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1184
1185 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1186 allAppsCellSize[INDEX_DEFAULT].x);
1187 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1188 allAppsCellSize[INDEX_DEFAULT].y);
1189 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1190
Thales Lima080d8902022-03-28 15:30:29 +01001191 float allAppsBorderSpace = a.getFloat(
1192 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1193 float allAppsBorderSpaceLandscape = a.getFloat(
1194 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1195 allAppsBorderSpace);
1196 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001197 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001198 allAppsBorderSpace);
1199 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001200 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001201 allAppsBorderSpace);
1202
1203 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1204 allAppsBorderSpace);
1205 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1206 allAppsBorderSpace);
1207 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1208
1209 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1210 allAppsBorderSpaceLandscape);
1211 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1212 allAppsBorderSpaceLandscape);
1213 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1214
1215 x = a.getFloat(
1216 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1217 allAppsBorderSpaceTwoPanelPortrait);
1218 y = a.getFloat(
1219 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1220 allAppsBorderSpaceTwoPanelPortrait);
1221 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1222
1223 x = a.getFloat(
1224 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1225 allAppsBorderSpaceTwoPanelLandscape);
1226 y = a.getFloat(
1227 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1228 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001229 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001230
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001231 iconSizes[INDEX_DEFAULT] =
1232 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1233 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001234 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001235 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001236 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001237 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001238 iconSizes[INDEX_DEFAULT]);
1239 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001240 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001241 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001242
Thales Limabb7d3882021-12-22 12:56:29 +00001243 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1244 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001245 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1246 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001247 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001248 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1249 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1250 allAppsIconSizes[INDEX_DEFAULT]);
1251 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1252 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1253 allAppsIconSizes[INDEX_DEFAULT]);
1254
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001255 textSizes[INDEX_DEFAULT] =
1256 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1257 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001258 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001259 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001260 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001261 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001262 textSizes[INDEX_DEFAULT]);
1263 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001264 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001265 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001266
Thales Limabb7d3882021-12-22 12:56:29 +00001267 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1268 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1269 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1270 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1271 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1272 allAppsIconTextSizes[INDEX_DEFAULT]);
1273 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1274 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1275 allAppsIconTextSizes[INDEX_DEFAULT]);
1276
Thales Lima83bedbf2021-10-05 17:47:39 +01001277 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1278 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001279 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1280 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1281 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001282 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001283 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001284 horizontalMargin[INDEX_DEFAULT]);
1285 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001286 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001287 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001288
Thales Limab8c05952022-05-23 16:58:38 +01001289 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1290 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001291 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001292 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1293 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1294 hotseatBarBottomSpace[INDEX_DEFAULT]);
1295 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1296 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1297 hotseatBarBottomSpace[INDEX_DEFAULT]);
1298 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1299 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1300 hotseatBarBottomSpace[INDEX_DEFAULT]);
1301
1302 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1303 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001304 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001305 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1306 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1307 hotseatQsbSpace[INDEX_DEFAULT]);
1308 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1309 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1310 hotseatQsbSpace[INDEX_DEFAULT]);
1311 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1312 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1313 hotseatQsbSpace[INDEX_DEFAULT]);
1314
Jon Miranda9c478b62023-03-23 21:38:49 -07001315 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1316 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1317 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1318 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1319 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1320 transientTaskbarIconSize[INDEX_DEFAULT]);
1321 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1322 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1323 transientTaskbarIconSize[INDEX_DEFAULT]);
1324 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1325 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001326 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001327
Jon Miranda04f05102023-04-04 12:16:31 -07001328 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1329 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1330 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1331 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1332 startAlignTaskbar[INDEX_DEFAULT]);
1333 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1334 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1335 startAlignTaskbar[INDEX_LANDSCAPE]);
1336 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1337 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1338 startAlignTaskbar[INDEX_DEFAULT]);
1339
Sunny Goyal415f1732018-11-29 10:33:47 -08001340 a.recycle();
1341 }
1342
1343 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001344 this(null);
1345 }
1346
1347 DisplayOption(GridOption grid) {
1348 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001349 minWidthDps = 0;
1350 minHeightDps = 0;
1351 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001352 for (int i = 0; i < COUNT_SIZES; i++) {
1353 iconSizes[i] = 0;
1354 textSizes[i] = 0;
1355 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001356 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001357 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001358 allAppsIconSizes[i] = 0;
1359 allAppsIconTextSizes[i] = 0;
1360 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001361 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001362 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001363 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001364 }
1365
1366 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001367 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001368 iconSizes[i] *= w;
1369 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001370 borderSpaces[i].x *= w;
1371 borderSpaces[i].y *= w;
1372 minCellSize[i].x *= w;
1373 minCellSize[i].y *= w;
1374 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001375 hotseatBarBottomSpace[i] *= w;
1376 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001377 allAppsCellSize[i].x *= w;
1378 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001379 allAppsIconSizes[i] *= w;
1380 allAppsIconTextSizes[i] *= w;
1381 allAppsBorderSpaces[i].x *= w;
1382 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001383 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001384 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001385
Sunny Goyal415f1732018-11-29 10:33:47 -08001386 return this;
1387 }
1388
1389 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001390 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001391 iconSizes[i] += p.iconSizes[i];
1392 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001393 borderSpaces[i].x += p.borderSpaces[i].x;
1394 borderSpaces[i].y += p.borderSpaces[i].y;
1395 minCellSize[i].x += p.minCellSize[i].x;
1396 minCellSize[i].y += p.minCellSize[i].y;
1397 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001398 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1399 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001400 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1401 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001402 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1403 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1404 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1405 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001406 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001407 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001408 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001409
Sunny Goyal415f1732018-11-29 10:33:47 -08001410 return this;
1411 }
1412 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001413}