blob: bc3633660d152b24f89ffe6a6836830b892ed3ae [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
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700362 /**
363 * @deprecated This is a temporary solution because on the backup and restore case we modify the
364 * IDP, this resets it. b/332974074
365 */
366 @Deprecated
367 public void reset(Context context) {
368 initGrid(context, getCurrentGridName(context));
369 }
370
Thales Limab67bfa72022-11-02 15:30:11 +0000371 @VisibleForTesting
372 public static String getDefaultGridName(Context context) {
373 return new InvariantDeviceProfile().initGrid(context, null);
374 }
375
Alex Chau1c883d82021-12-01 18:43:10 +0000376 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
377 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700378 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700379 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000380 numRows = closestProfile.numRows;
381 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000382 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000383 dbFile = closestProfile.dbFile;
384 defaultLayoutId = closestProfile.defaultLayoutId;
385 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300386
Sunny Goyalae190ff2020-04-14 00:19:01 +0000387 numFolderRows = closestProfile.numFolderRows;
388 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300389 folderStyle = closestProfile.folderStyle;
390
Thales Limad852d652023-01-17 14:01:13 +0000391 cellStyle = closestProfile.cellStyle;
392
Jon Mirandae126d722021-02-25 10:45:20 -0500393 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400394 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100395 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100396 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100397 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100398 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100399 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100400 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100401 hotseatSpecsId = closestProfile.mHotseatSpecsId;
402 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000403 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
404 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
405 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
406 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300407 numAllAppsRowsForCellHeightCalculation =
408 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000409 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000410
Vinit Nayakc7293172022-07-18 16:41:50 -0700411 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
412
Thales Lima83bedbf2021-10-05 17:47:39 +0100413 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100414 float maxIconSize = iconSize[0];
415 for (int i = 1; i < iconSize.length; i++) {
416 maxIconSize = Math.max(maxIconSize, iconSize[i]);
417 }
418 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000419 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
420
Thales Lima83bedbf2021-10-05 17:47:39 +0100421 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700422
Thales Lima83bedbf2021-10-05 17:47:39 +0100423 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100424
Thales Lima83bedbf2021-10-05 17:47:39 +0100425 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100426
Thales Limad90faab2021-09-21 17:18:47 +0100427 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100428
Sunny Goyal19ff7282021-04-22 10:12:54 -0700429 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000430 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700431 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300432 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100433 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
434 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700435
Thales Limae9273ea2023-01-26 12:33:52 +0000436 allAppsStyle = closestProfile.allAppsStyle;
437
Sunny Goyal19ff7282021-04-22 10:12:54 -0700438 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300439
Alex Chau1c883d82021-12-01 18:43:10 +0000440 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700441 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500442
Thales Limab7ef5692022-03-10 10:32:36 +0000443 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000444 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
445 allAppsIconSize = displayOption.allAppsIconSizes;
446 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000447
Thales Lima11af7bc2022-08-12 15:24:54 +0100448 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000449
Jon Miranda9c478b62023-03-23 21:38:49 -0700450 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
451
Jon Miranda04f05102023-04-04 12:16:31 -0700452 startAlignTaskbar = displayOption.startAlignTaskbar;
453
Sunny Goyalae190ff2020-04-14 00:19:01 +0000454 // If the partner customization apk contains any grid overrides, apply them
455 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700456 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700457
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000458 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700460 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700461 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000462 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000463 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000464 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700465 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000466 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700467
Sunny Goyal19ff7282021-04-22 10:12:54 -0700468 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
469 int displayWidth = bounds.bounds.width();
470 int displayHeight = bounds.bounds.height();
471 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700472
Sunny Goyal19ff7282021-04-22 10:12:54 -0700473 // We need to ensure that there is enough extra space in the wallpaper
474 // for the intended parallax effects
475 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300476 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
477 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700478 ? 2
479 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
480 defaultWallpaperSize.x =
481 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700482 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000483 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700484
Thales Lima6a590062022-11-22 15:52:49 +0000485 int numMinShownHotseatIconsForTablet = supportedProfiles
486 .stream()
487 .filter(deviceProfile -> deviceProfile.isTablet)
488 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
489 .min()
490 .orElse(0);
491
492 supportedProfiles
493 .stream()
494 .filter(deviceProfile -> deviceProfile.isTablet)
495 .forEach(deviceProfile -> {
496 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
497 deviceProfile.recalculateHotseatWidthAndBorderSpace();
498 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700499 }
500
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700501 public void addOnChangeListener(OnIDPChangeListener listener) {
502 mChangeListeners.add(listener);
503 }
504
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800505 public void removeOnChangeListener(OnIDPChangeListener listener) {
506 mChangeListeners.remove(listener);
507 }
508
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800509
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800510 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000511 LauncherPrefs.get(context).put(GRID_NAME, gridName);
512 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800513 }
514
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700515 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700516 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000517 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
518 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700519 }
520
Pat Manning24cec692023-10-13 10:36:57 +0000521 /** Updates IDP using the provided context. Notifies listeners of change. */
522 @VisibleForTesting
523 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700524 Object[] oldState = toModelState();
525
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700526 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700527 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700528 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700529
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700530 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700531 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700532 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700533 }
534 }
535
Alex Chau1c883d82021-12-01 18:43:10 +0000536 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
537 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800538 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100539
Alex Chau1c883d82021-12-01 18:43:10 +0000540 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700541 final int depth = parser.getDepth();
542 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700543 while (((type = parser.next()) != XmlPullParser.END_TAG ||
544 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800545 if ((type == XmlPullParser.START_TAG)
546 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800547
Sunny Goyal076e04b2023-04-03 12:38:30 -0700548 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
549 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100550 final int displayDepth = parser.getDepth();
551 while (((type = parser.next()) != XmlPullParser.END_TAG
552 || parser.getDepth() > displayDepth)
553 && type != XmlPullParser.END_DOCUMENT) {
554 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
555 parser.getName())) {
556 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100557 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100558 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800559 }
560 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700561 }
562 }
sfufa@google.comde013292021-09-21 18:22:44 -0700563 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700564 throw new RuntimeException(e);
565 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800566
Sunny Goyalae190ff2020-04-14 00:19:01 +0000567 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800568 if (!TextUtils.isEmpty(gridName)) {
569 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100570 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700571 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000572 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800573 }
574 }
575 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000576 if (filteredProfiles.isEmpty()) {
577 // No grid found, use the default options
578 for (DisplayOption option : profiles) {
579 if (option.canBeDefault) {
580 filteredProfiles.add(option);
581 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800582 }
583 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000584 if (filteredProfiles.isEmpty()) {
585 throw new RuntimeException("No display option with canBeDefault=true");
586 }
587 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700588 }
589
Thales Lima7ec83822021-08-05 13:32:10 +0100590 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000591 * Returns the GridOption associated to the given file name or null if the fileName is not
592 * supported.
593 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
594 */
595 public GridOption getGridOptionFromFileName(Context context, String fileName) {
596 return parseAllGridOptions(context).stream()
597 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
598 .findFirst()
599 .orElse(null);
600 }
601
602 /**
603 * Returns the name of the given size on the current device or empty string if the size is not
604 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
605 * (Note: the name of the grid can be different for the same grid size depending of
606 * the values of the InvariantDeviceProfile)
607 *
608 */
609 public String getGridNameFromSize(Context context, Point size) {
610 return parseAllGridOptions(context).stream()
611 .filter(gridOption -> gridOption.numColumns == size.x
612 && gridOption.numRows == size.y)
613 .map(gridOption -> gridOption.name)
614 .findFirst()
615 .orElse("");
616 }
617
618 /**
619 * Returns the grid option for the given gridName on the current device (Note: the gridOption
620 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
621 */
622 public GridOption getGridOptionFromName(Context context, String gridName) {
623 return parseAllGridOptions(context).stream()
624 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
625 .findFirst()
626 .orElse(null);
627 }
628
629 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100630 * @return all the grid options that can be shown on the device
631 */
632 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700633 return parseAllDefinedGridOptions(context)
634 .stream()
635 .filter(go -> go.isEnabled(deviceType))
636 .collect(Collectors.toList());
637 }
638
639 /**
640 * @return all the grid options that can be shown on the device
641 */
642 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100643 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100644
Alex Chau1c883d82021-12-01 18:43:10 +0000645 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100646 final int depth = parser.getDepth();
647 int type;
648 while (((type = parser.next()) != XmlPullParser.END_TAG
649 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
650 if ((type == XmlPullParser.START_TAG)
651 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700652 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100653 }
654 }
655 } catch (IOException | XmlPullParserException e) {
656 Log.e(TAG, "Error parsing device profile", e);
657 return Collections.emptyList();
658 }
659 return result;
660 }
661
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700662 private int getLauncherIconDensity(int requiredSize) {
663 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700664 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700665 DisplayMetrics.DENSITY_LOW,
666 DisplayMetrics.DENSITY_MEDIUM,
667 DisplayMetrics.DENSITY_TV,
668 DisplayMetrics.DENSITY_HIGH,
669 DisplayMetrics.DENSITY_XHIGH,
670 DisplayMetrics.DENSITY_XXHIGH,
671 DisplayMetrics.DENSITY_XXXHIGH
672 };
673
674 int density = DisplayMetrics.DENSITY_XXXHIGH;
675 for (int i = densityBuckets.length - 1; i >= 0; i--) {
676 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
677 / DisplayMetrics.DENSITY_DEFAULT;
678 if (expectedSize >= requiredSize) {
679 density = densityBuckets[i];
680 }
681 }
682
683 return density;
684 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700685
Adam Cohen2e6da152015-05-06 11:42:25 -0700686 /**
687 * Apply any Partner customization grid overrides.
688 *
689 * Currently we support: all apps row / column count.
690 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700691 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
692 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800693 if (p == null) {
694 return;
695 }
696 try {
697 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
698 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
699 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
700
701 if (numRows > 0 && numColumns > 0) {
702 this.numRows = numRows;
703 this.numColumns = numColumns;
704 }
705 if (iconSizePx > 0) {
706 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
707 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
708 }
709 } catch (Resources.NotFoundException ex) {
710 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700711 }
712 }
713
Sunny Goyal415f1732018-11-29 10:33:47 -0800714 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700715 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700716 }
717
Sunny Goyal19ff7282021-04-22 10:12:54 -0700718 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000719 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700720 int minWidthPx = Integer.MAX_VALUE;
721 int minHeightPx = Integer.MAX_VALUE;
722 for (WindowBounds bounds : displayInfo.supportedBounds) {
723 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000724 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700725 // For split displays, take half width per page
726 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
727 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700728
Sunny Goyal19ff7282021-04-22 10:12:54 -0700729 } else if (!isTablet && bounds.isLandscape()) {
730 // We will use transposed layout in this case
731 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
732 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
733 } else {
734 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
735 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
736 }
737 }
738
Thales Lima425f6822022-05-10 13:44:58 -0300739 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
740 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700741
742 // Sort the profiles based on the closeness to the device size
743 Collections.sort(points, (a, b) ->
744 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
745 dist(width, height, b.minWidthDps, b.minHeightDps)));
746
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700747 DisplayOption closestPoint = points.get(0);
748 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700749 float weights = 0;
750
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700751 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
752 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700753 }
754
755 DisplayOption out = new DisplayOption(closestOption);
756 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700757 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700758 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
759 weights += w;
760 out.add(new DisplayOption().add(p).multiply(w));
761 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700762 out.multiply(1.0f / weights);
763
Thales Lima6e0005a2021-10-27 15:53:41 +0100764 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700765 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100766 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
767 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700768 }
769
770 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700771 }
772
Sunny Goyal27835952017-01-13 12:15:53 -0800773 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000774 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
775 Rect bounds = windowManagerProxy.getCurrentBounds(context);
776 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700777
Alex Chauc09a98a2023-11-14 12:51:42 +0000778 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400779 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700780
Sunny Goyal187b16c2022-03-01 16:53:23 -0800781 /**
782 * Returns the device profile matching the provided screen configuration
783 */
784 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700785 DeviceProfile bestMatch = supportedProfiles.get(0);
786 float minDiff = Float.MAX_VALUE;
787
788 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400789 float diff = Math.abs(profile.widthPx - screenWidth)
790 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700791 if (diff < minDiff) {
792 minDiff = diff;
793 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800794 } else if (diff == minDiff && profile.rotationHint == rotation) {
795 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700796 }
797 }
798 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800799 }
800
Sunny Goyal415f1732018-11-29 10:33:47 -0800801 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700802 float d = dist(x0, y0, x1, y1);
803 if (Float.compare(d, 0f) == 0) {
804 return Float.POSITIVE_INFINITY;
805 }
806 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
807 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700808
809 /**
810 * As a ratio of screen height, the total distance we want the parallax effect to span
811 * horizontally
812 */
813 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
814 float aspectRatio = width / (float) height;
815
816 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
817 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
818 // We will use these two data points to extrapolate how much the wallpaper parallax effect
819 // to span (ie travel) at any aspect ratio:
820
sfufa@google.comde013292021-09-21 18:22:44 -0700821 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
822 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700823 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
824 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
825
826 // To find out the desired width at different aspect ratios, we use the following two
827 // formulas, where the coefficient on x is the aspect ratio (width/height):
828 // (16/10)x + y = 1.5
829 // (10/16)x + y = 1.2
830 // We solve for x and y and end up with a final formula:
831 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700832 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
833 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700834 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
835 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
836 return x * aspectRatio + y;
837 }
838
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700839 public interface OnIDPChangeListener {
840
Sunny Goyalb47172b2021-05-03 19:59:51 -0700841 /**
842 * Called when the device provide changes
843 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700844 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700845 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800846
847
Sunny Goyaleff44f32019-01-09 17:29:49 -0800848 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800849
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800850 public static final String TAG_NAME = "grid-option";
851
Alex Chau1c883d82021-12-01 18:43:10 +0000852 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
853 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
854 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
855 private static final int DEVICE_CATEGORY_ALL =
856 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
857
Thales Lima11af7bc2022-08-12 15:24:54 +0100858 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
859 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
860 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
861 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
862 private static final int DONT_INLINE_QSB = 0;
863
Sunny Goyaleff44f32019-01-09 17:29:49 -0800864 public final String name;
865 public final int numRows;
866 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000867 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700868 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800869
Thales Lima1faa4ed2023-12-01 16:48:19 +0000870 private final int[] numFolderRows = new int[COUNT_SIZES];
871 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300872 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000873 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800874
Thales Limae9273ea2023-01-26 12:33:52 +0000875 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700876 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300877 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700878 private final int numDatabaseAllAppsColumns;
879 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700880 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100881
Thales Lima425f6822022-05-10 13:44:58 -0300882 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800883
Thales Lima11af7bc2022-08-12 15:24:54 +0100884 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
885
Thales Limab35faed2022-09-05 16:30:01 -0300886 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800887 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000888
Sunny Goyal415f1732018-11-29 10:33:47 -0800889 private final int defaultLayoutId;
890 private final int demoModeLayoutId;
891
Jon Mirandae126d722021-02-25 10:45:20 -0500892 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400893 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100894 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100895 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100896 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100897 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100898 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100899 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100900 private final int mHotseatSpecsId;
901 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000902 private final int mWorkspaceCellSpecsId;
903 private final int mWorkspaceCellSpecsTwoPanelId;
904 private final int mAllAppsCellSpecsId;
905 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500906
Sunny Goyal076e04b2023-04-03 12:38:30 -0700907 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800908 TypedArray a = context.obtainStyledAttributes(
909 attrs, R.styleable.GridDisplayOption);
910 name = a.getString(R.styleable.GridDisplayOption_name);
911 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
912 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000913 numSearchContainerColumns = a.getInt(
914 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800915
Tracy Zhou7df93d22020-01-27 13:44:06 -0800916 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100917 defaultLayoutId = a.getResourceId(
918 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800919 demoModeLayoutId = a.getResourceId(
920 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700921
Thales Limae9273ea2023-01-26 12:33:52 +0000922 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
923 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700924 numAllAppsColumns = a.getInt(
925 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
926 numDatabaseAllAppsColumns = a.getInt(
927 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
928
929 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800930 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700931 numDatabaseHotseatIcons = a.getInt(
932 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100933
Thales Lima425f6822022-05-10 13:44:58 -0300934 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
935 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
936 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
937 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
938 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
939 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
940 numColumns);
941 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
942 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
943 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700944
Vinit Nayakc7293172022-07-18 16:41:50 -0700945 inlineNavButtonsEndSpacing =
946 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100947 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300948
Thales Lima1faa4ed2023-12-01 16:48:19 +0000949 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800950 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000951 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800952 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700953
Thales Lima1faa4ed2023-12-01 16:48:19 +0000954 if (FeatureFlags.enableResponsiveWorkspace()) {
955 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
956 R.styleable.GridDisplayOption_numFolderRowsLandscape,
957 numFolderRows[INDEX_DEFAULT]);
958 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
959 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
960 numFolderColumns[INDEX_DEFAULT]);
961 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
962 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
963 numFolderRows[INDEX_DEFAULT]);
964 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
965 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
966 numFolderColumns[INDEX_DEFAULT]);
967 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
968 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
969 numFolderRows[INDEX_DEFAULT]);
970 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
971 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
972 numFolderColumns[INDEX_DEFAULT]);
973 } else {
974 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
975 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
976 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
977 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
978 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
979 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
980 }
981
Thales Limab35faed2022-09-05 16:30:01 -0300982 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
983 INVALID_RESOURCE_HANDLE);
984
Thales Limad852d652023-01-17 14:01:13 +0000985 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
986 R.style.CellStyleDefault);
987
Jon Mirandae126d722021-02-25 10:45:20 -0500988 isScalable = a.getBoolean(
989 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400990 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000991 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700992 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000993 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100994
Thales Limaca31b612023-09-14 14:25:26 +0100995 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100996 mWorkspaceSpecsId = a.getResourceId(
997 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100998 mWorkspaceSpecsTwoPanelId = a.getResourceId(
999 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001000 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001001 mAllAppsSpecsId = a.getResourceId(
1002 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001003 mAllAppsSpecsTwoPanelId = a.getResourceId(
1004 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001005 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001006 mFolderSpecsId = a.getResourceId(
1007 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001008 mFolderSpecsTwoPanelId = a.getResourceId(
1009 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001010 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001011 mHotseatSpecsId = a.getResourceId(
1012 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1013 mHotseatSpecsTwoPanelId = a.getResourceId(
1014 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001015 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001016 mWorkspaceCellSpecsId = a.getResourceId(
1017 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1018 INVALID_RESOURCE_HANDLE);
1019 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1020 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001021 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001022 mAllAppsCellSpecsId = a.getResourceId(
1023 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1024 INVALID_RESOURCE_HANDLE);
1025 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1026 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001027 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001028 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1029 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1030 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001031 } else {
1032 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001033 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001034 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001035 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001036 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001037 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001038 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1039 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001040 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1041 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1042 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1043 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001044 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001045 }
1046
Thales Lima11af7bc2022-08-12 15:24:54 +01001047 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1048 DONT_INLINE_QSB);
1049 inlineQsb[INDEX_DEFAULT] =
1050 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1051 inlineQsb[INDEX_LANDSCAPE] =
1052 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1053 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1054 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1055 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1056 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1057 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1058 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1059
Sunny Goyal415f1732018-11-29 10:33:47 -08001060 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001061 }
1062
1063 public boolean isEnabled(@DeviceType int deviceType) {
1064 switch (deviceType) {
1065 case TYPE_PHONE:
1066 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1067 case TYPE_TABLET:
1068 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1069 case TYPE_MULTI_DISPLAY:
1070 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1071 == DEVICE_CATEGORY_MULTI_DISPLAY;
1072 default:
1073 return false;
1074 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001075 }
1076 }
1077
Sunny Goyal19ff7282021-04-22 10:12:54 -07001078 @VisibleForTesting
1079 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001080 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001081
Sunny Goyal415f1732018-11-29 10:33:47 -08001082 private final float minWidthDps;
1083 private final float minHeightDps;
1084 private final boolean canBeDefault;
1085
Thales Lima83bedbf2021-10-05 17:47:39 +01001086 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001087
Thales Lima78d00ad2021-09-30 11:29:06 +01001088 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001089 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001090 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1091 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001092
Thales Lima78d00ad2021-09-30 11:29:06 +01001093 private final float[] iconSizes = new float[COUNT_SIZES];
1094 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001095
Thales Limab7ef5692022-03-10 10:32:36 +00001096 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001097 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1098 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1099 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1100
Jon Miranda9c478b62023-03-23 21:38:49 -07001101 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1102
Jon Miranda04f05102023-04-04 12:16:31 -07001103 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1104
Thales Lima1de4d552021-10-13 16:13:25 +01001105 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001106 this.grid = grid;
1107
Jon Miranda9c478b62023-03-23 21:38:49 -07001108 Resources res = context.getResources();
1109
Thales Lima1de4d552021-10-13 16:13:25 +01001110 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001111
Sunny Goyal415f1732018-11-29 10:33:47 -08001112 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1113 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001114
Thales Lima1de4d552021-10-13 16:13:25 +01001115 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001116
Thales Lima83bedbf2021-10-05 17:47:39 +01001117 float x;
1118 float y;
1119
Thales Lima85c942f2021-12-31 13:04:20 +00001120 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1121 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001122 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001123
1124 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1125 minCellSize[INDEX_DEFAULT].x);
1126 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1127 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001128 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001129
Thales Lima85c942f2021-12-31 13:04:20 +00001130 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001131 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001132 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001133 minCellSize[INDEX_DEFAULT].y);
1134 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1135
Thales Lima85c942f2021-12-31 13:04:20 +00001136 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001137 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001138 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001139 minCellSize[INDEX_DEFAULT].y);
1140 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001141
Thales Lima85c942f2021-12-31 13:04:20 +00001142 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001143 float borderSpaceLandscape = a.getFloat(
1144 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001145 float borderSpaceTwoPanelPortrait = a.getFloat(
1146 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1147 float borderSpaceTwoPanelLandscape = a.getFloat(
1148 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001149
Thales Lima85c942f2021-12-31 13:04:20 +00001150 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1151 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001152 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001153
1154 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1155 borderSpaceLandscape);
1156 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1157 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001158 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1159
1160 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001161 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1162 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001163 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001164 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1165 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001166 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1167
1168 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001169 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1170 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001171 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001172 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1173 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001174 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1175
Thales Limab7ef5692022-03-10 10:32:36 +00001176 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1177 minCellSize[INDEX_DEFAULT].x);
1178 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1179 minCellSize[INDEX_DEFAULT].y);
1180 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1181
1182 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1183 allAppsCellSize[INDEX_DEFAULT].x);
1184 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1185 allAppsCellSize[INDEX_DEFAULT].y);
1186 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1187
1188 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1189 allAppsCellSize[INDEX_DEFAULT].x);
1190 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1191 allAppsCellSize[INDEX_DEFAULT].y);
1192 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1193
1194 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1195 allAppsCellSize[INDEX_DEFAULT].x);
1196 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1197 allAppsCellSize[INDEX_DEFAULT].y);
1198 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1199
Thales Lima080d8902022-03-28 15:30:29 +01001200 float allAppsBorderSpace = a.getFloat(
1201 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1202 float allAppsBorderSpaceLandscape = a.getFloat(
1203 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1204 allAppsBorderSpace);
1205 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001206 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001207 allAppsBorderSpace);
1208 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001209 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001210 allAppsBorderSpace);
1211
1212 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1213 allAppsBorderSpace);
1214 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1215 allAppsBorderSpace);
1216 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1217
1218 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1219 allAppsBorderSpaceLandscape);
1220 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1221 allAppsBorderSpaceLandscape);
1222 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1223
1224 x = a.getFloat(
1225 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1226 allAppsBorderSpaceTwoPanelPortrait);
1227 y = a.getFloat(
1228 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1229 allAppsBorderSpaceTwoPanelPortrait);
1230 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1231
1232 x = a.getFloat(
1233 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1234 allAppsBorderSpaceTwoPanelLandscape);
1235 y = a.getFloat(
1236 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1237 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001238 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001239
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001240 iconSizes[INDEX_DEFAULT] =
1241 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1242 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001243 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001244 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001245 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001246 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001247 iconSizes[INDEX_DEFAULT]);
1248 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001249 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001250 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001251
Thales Limabb7d3882021-12-22 12:56:29 +00001252 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1253 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001254 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1255 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001256 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001257 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1258 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1259 allAppsIconSizes[INDEX_DEFAULT]);
1260 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1261 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1262 allAppsIconSizes[INDEX_DEFAULT]);
1263
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001264 textSizes[INDEX_DEFAULT] =
1265 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1266 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001267 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001268 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001269 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001270 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001271 textSizes[INDEX_DEFAULT]);
1272 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001273 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001274 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001275
Thales Limabb7d3882021-12-22 12:56:29 +00001276 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1277 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1278 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1279 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1280 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1281 allAppsIconTextSizes[INDEX_DEFAULT]);
1282 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1283 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1284 allAppsIconTextSizes[INDEX_DEFAULT]);
1285
Thales Lima83bedbf2021-10-05 17:47:39 +01001286 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1287 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001288 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1289 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1290 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001291 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001292 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001293 horizontalMargin[INDEX_DEFAULT]);
1294 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001295 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001296 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001297
Thales Limab8c05952022-05-23 16:58:38 +01001298 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1299 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001300 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001301 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1302 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1303 hotseatBarBottomSpace[INDEX_DEFAULT]);
1304 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1305 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1306 hotseatBarBottomSpace[INDEX_DEFAULT]);
1307 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1308 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1309 hotseatBarBottomSpace[INDEX_DEFAULT]);
1310
1311 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1312 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001313 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001314 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1315 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1316 hotseatQsbSpace[INDEX_DEFAULT]);
1317 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1318 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1319 hotseatQsbSpace[INDEX_DEFAULT]);
1320 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1321 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1322 hotseatQsbSpace[INDEX_DEFAULT]);
1323
Jon Miranda9c478b62023-03-23 21:38:49 -07001324 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1325 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1326 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1327 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1328 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1329 transientTaskbarIconSize[INDEX_DEFAULT]);
1330 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1331 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1332 transientTaskbarIconSize[INDEX_DEFAULT]);
1333 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1334 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001335 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001336
Jon Miranda04f05102023-04-04 12:16:31 -07001337 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1338 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1339 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1340 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1341 startAlignTaskbar[INDEX_DEFAULT]);
1342 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1343 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1344 startAlignTaskbar[INDEX_LANDSCAPE]);
1345 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1346 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1347 startAlignTaskbar[INDEX_DEFAULT]);
1348
Sunny Goyal415f1732018-11-29 10:33:47 -08001349 a.recycle();
1350 }
1351
1352 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001353 this(null);
1354 }
1355
1356 DisplayOption(GridOption grid) {
1357 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001358 minWidthDps = 0;
1359 minHeightDps = 0;
1360 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001361 for (int i = 0; i < COUNT_SIZES; i++) {
1362 iconSizes[i] = 0;
1363 textSizes[i] = 0;
1364 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001365 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001366 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001367 allAppsIconSizes[i] = 0;
1368 allAppsIconTextSizes[i] = 0;
1369 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001370 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001371 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001372 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001373 }
1374
1375 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001376 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001377 iconSizes[i] *= w;
1378 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001379 borderSpaces[i].x *= w;
1380 borderSpaces[i].y *= w;
1381 minCellSize[i].x *= w;
1382 minCellSize[i].y *= w;
1383 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001384 hotseatBarBottomSpace[i] *= w;
1385 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001386 allAppsCellSize[i].x *= w;
1387 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001388 allAppsIconSizes[i] *= w;
1389 allAppsIconTextSizes[i] *= w;
1390 allAppsBorderSpaces[i].x *= w;
1391 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001392 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001393 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001394
Sunny Goyal415f1732018-11-29 10:33:47 -08001395 return this;
1396 }
1397
1398 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001399 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001400 iconSizes[i] += p.iconSizes[i];
1401 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001402 borderSpaces[i].x += p.borderSpaces[i].x;
1403 borderSpaces[i].y += p.borderSpaces[i].y;
1404 minCellSize[i].x += p.minCellSize[i].x;
1405 minCellSize[i].y += p.minCellSize[i].y;
1406 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001407 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1408 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001409 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1410 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001411 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1412 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1413 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1414 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001415 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001416 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001417 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001418
Sunny Goyal415f1732018-11-29 10:33:47 -08001419 return this;
1420 }
1421 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001422}