blob: 42d4d50218f031f5b8e2685c820dae0be0cb520b [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;
Sunny Goyal076e04b2023-04-03 12:38:30 -070075import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070076
77public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070078
Hyunyoung Songc55a3502018-12-04 15:43:16 -080079 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070080 // We do not need any synchronization for this variable as its only written on UI thread.
81 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070082 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070083
Alex Chau1c883d82021-12-01 18:43:10 +000084 @Retention(RetentionPolicy.SOURCE)
85 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010086 public @interface DeviceType {}
87
Alex Chau1c883d82021-12-01 18:43:10 +000088 public static final int TYPE_PHONE = 0;
89 public static final int TYPE_MULTI_DISPLAY = 1;
90 public static final int TYPE_TABLET = 2;
91
Sunny Goyal53d7ee42015-05-22 12:25:45 -070092 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
93
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094 // Constants that affects the interpolation curve between statically defined device profile
95 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080096 private static final float KNEARESTNEIGHBOR = 3;
97 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070098
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070099 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800100 private static final float WEIGHT_EFFICIENT = 100000f;
101
Thales Lima83bedbf2021-10-05 17:47:39 +0100102 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
103 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000104 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100105 static final int INDEX_DEFAULT = 0;
106 static final int INDEX_LANDSCAPE = 1;
107 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
108 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100109
Thales Limaec5abba2023-04-05 16:33:50 +0100110 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800111 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
112 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
113 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
114
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700115 /**
116 * Number of icons per row and column in the workspace.
117 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700118 public int numRows;
119 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000120 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700121
122 /**
123 * Number of icons per row and column in the folder.
124 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000125 public int[] numFolderRows;
126 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100127 public float[] iconSize;
128 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700129 public int iconBitmapSize;
130 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000131 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700132
Thales Lima83bedbf2021-10-05 17:47:39 +0100133 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100134
Thales Lima83bedbf2021-10-05 17:47:39 +0100135 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300136 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100137
Thales Limab35faed2022-09-05 16:30:01 -0300138 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100139
Thales Limad852d652023-01-17 14:01:13 +0000140 public @StyleRes int cellStyle;
141
Thales Lima83bedbf2021-10-05 17:47:39 +0100142 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500143
Thales Limab7ef5692022-03-10 10:32:36 +0000144 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000145 public float[] allAppsIconSize;
146 public float[] allAppsIconTextSize;
147 public PointF[] allAppsBorderSpaces;
148
Jon Miranda9c478b62023-03-23 21:38:49 -0700149 public float[] transientTaskbarIconSize;
150
Jon Miranda04f05102023-04-04 12:16:31 -0700151 public boolean[] startAlignTaskbar;
152
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700153 /**
154 * Number of icons inside the hotseat area.
155 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800156 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700157
158 /**
159 * Number of icons inside the hotseat area that is stored in the database. This is greater than
160 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
161 * sizes that share the same DB.
162 */
163 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700164
Thales Lima425f6822022-05-10 13:44:58 -0300165 public int[] hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100166 public float[] hotseatBarBottomSpace;
167 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300168
Jon Miranda6f7e9702019-09-16 14:44:14 -0700169 /**
170 * Number of columns in the all apps list.
171 */
172 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300173 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700174 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000175 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700176
Jon Mirandae126d722021-02-25 10:45:20 -0500177 /**
178 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
179 */
180 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000181 @XmlRes
182 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100183 @XmlRes
184 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100185 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100186 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
187 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100188 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100189 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100190 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
191 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100192 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100193 @XmlRes
194 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000195 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100196 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000197 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100198 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000199 @XmlRes
200 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
201 @XmlRes
202 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
203 @XmlRes
204 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
205 @XmlRes
206 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500207
Tracy Zhou7df93d22020-01-27 13:44:06 -0800208 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800209 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700210 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100211 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700212
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000213 /**
214 * An immutable list of supported profiles.
215 */
216 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700217
Sunny Goyal6f866092016-03-17 17:04:15 -0700218 public Point defaultWallpaperSize;
219
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700220 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700221
Sunny Goyalf633ef52018-03-13 09:57:05 -0700222 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800223 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700224
Sunny Goyalbbf01842015-10-08 07:41:15 -0700225 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700226 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700227 String gridName = getCurrentGridName(context);
228 String newGridName = initGrid(context, gridName);
229 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000230 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700231 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000232 LockedUserState.get(context).runOnUserUnlocked(() -> {
233 new DeviceGridState(this).writeToPrefs(context);
234 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700235
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700236 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100237 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000238 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700239 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100240 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700241 }
242 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700243 }
244
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700245 /**
246 * This constructor should NOT have any monitors by design.
247 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800248 public InvariantDeviceProfile(Context context, String gridName) {
249 String newName = initGrid(context, gridName);
250 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000251 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800252 }
253 }
254
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700255 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800256 * This constructor should NOT have any monitors by design.
257 */
258 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700259 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100260 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 String gridName = getCurrentGridName(context);
262
263 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000264 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
265 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700266 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000267 defaultInfo,
268 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
269 /*allowDisabledGrid=*/false),
270 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700271
Alex Chau661f02d2022-06-07 14:03:43 +0100272 Context displayContext = context.createDisplayContext(display);
273 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000274 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700275 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000276 myInfo,
277 getPredefinedDeviceProfiles(context, gridName, deviceType,
278 /*allowDisabledGrid=*/false),
279 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280
281 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
282 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100283 result.iconSizes[INDEX_DEFAULT] =
284 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
285 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700286 result.iconSizes[i] = Math.min(
287 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000288 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700289
Thales Lima83bedbf2021-10-05 17:47:39 +0100290 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
291 COUNT_SIZES);
292 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
293 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500294
Alex Chau1c883d82021-12-01 18:43:10 +0000295 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800296 }
297
Alex Chau238aaee2021-10-06 16:15:24 +0100298 /**
299 * Reinitialize the current grid after a restore, where some grids might now be disabled.
300 */
301 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000302 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100303 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000304 String newGridName = initGrid(context, currentGridName);
305 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400306 FileLog.d(TAG, "Reinitializing grid after restore."
307 + " currentGridName=" + currentGridName
308 + ", currentDbFile=" + currentDbFile
309 + ", newGridName=" + newGridName
310 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000311 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400312 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100313 + ", migrating to: " + newGridName
314 + ", removing all other grid db files");
315 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
316 if (gridDbFile.equals(currentDbFile)) {
317 continue;
318 }
319 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400320 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100321 }
322 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000323 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100324 }
325 }
326
Alex Chau1c883d82021-12-01 18:43:10 +0000327 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800328 int flagPhone = 1 << 0;
329 int flagTablet = 1 << 1;
330
331 int type = displayInfo.supportedBounds.stream()
332 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
333 .reduce(0, (a, b) -> a | b);
Sebastian Francof3766132023-09-07 14:50:07 -0700334 if (type == (flagPhone | flagTablet)) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800335 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000336 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800337 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000338 return TYPE_TABLET;
339 } else {
340 return TYPE_PHONE;
341 }
342 }
343
Tracy Zhou42255d22020-03-13 00:38:11 -0700344 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000345 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700346 }
347
Sunny Goyaleff44f32019-01-09 17:29:49 -0800348 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700349 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000350 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700351
352 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000353 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100354 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700355 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000356 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
357 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700358 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800359 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700360
Thales Limab67bfa72022-11-02 15:30:11 +0000361 @VisibleForTesting
362 public static String getDefaultGridName(Context context) {
363 return new InvariantDeviceProfile().initGrid(context, null);
364 }
365
Alex Chau1c883d82021-12-01 18:43:10 +0000366 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
367 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700368 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700369 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000370 numRows = closestProfile.numRows;
371 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000372 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000373 dbFile = closestProfile.dbFile;
374 defaultLayoutId = closestProfile.defaultLayoutId;
375 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300376
Sunny Goyalae190ff2020-04-14 00:19:01 +0000377 numFolderRows = closestProfile.numFolderRows;
378 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300379 folderStyle = closestProfile.folderStyle;
380
Thales Limad852d652023-01-17 14:01:13 +0000381 cellStyle = closestProfile.cellStyle;
382
Jon Mirandae126d722021-02-25 10:45:20 -0500383 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400384 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100385 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100386 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100387 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100388 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100389 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100390 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100391 hotseatSpecsId = closestProfile.mHotseatSpecsId;
392 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000393 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
394 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
395 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
396 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300397 numAllAppsRowsForCellHeightCalculation =
398 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000399 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000400
Vinit Nayakc7293172022-07-18 16:41:50 -0700401 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
402
Thales Lima83bedbf2021-10-05 17:47:39 +0100403 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100404 float maxIconSize = iconSize[0];
405 for (int i = 1; i < iconSize.length; i++) {
406 maxIconSize = Math.max(maxIconSize, iconSize[i]);
407 }
408 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000409 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
410
Thales Lima83bedbf2021-10-05 17:47:39 +0100411 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700412
Thales Lima83bedbf2021-10-05 17:47:39 +0100413 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100414
Thales Lima83bedbf2021-10-05 17:47:39 +0100415 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100416
Thales Limad90faab2021-09-21 17:18:47 +0100417 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100418
Sunny Goyal19ff7282021-04-22 10:12:54 -0700419 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000420 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700421 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300422 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100423 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
424 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700425
Thales Limae9273ea2023-01-26 12:33:52 +0000426 allAppsStyle = closestProfile.allAppsStyle;
427
Sunny Goyal19ff7282021-04-22 10:12:54 -0700428 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300429
Alex Chau1c883d82021-12-01 18:43:10 +0000430 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700431 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500432
Thales Limab7ef5692022-03-10 10:32:36 +0000433 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000434 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
435 allAppsIconSize = displayOption.allAppsIconSizes;
436 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000437
Thales Lima11af7bc2022-08-12 15:24:54 +0100438 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000439
Jon Miranda9c478b62023-03-23 21:38:49 -0700440 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
441
Jon Miranda04f05102023-04-04 12:16:31 -0700442 startAlignTaskbar = displayOption.startAlignTaskbar;
443
Sunny Goyalae190ff2020-04-14 00:19:01 +0000444 // If the partner customization apk contains any grid overrides, apply them
445 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700446 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700447
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000448 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700449 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700450 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000452 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000453 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000454 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700455 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000456 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700457
Sunny Goyal19ff7282021-04-22 10:12:54 -0700458 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
459 int displayWidth = bounds.bounds.width();
460 int displayHeight = bounds.bounds.height();
461 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700462
Sunny Goyal19ff7282021-04-22 10:12:54 -0700463 // We need to ensure that there is enough extra space in the wallpaper
464 // for the intended parallax effects
465 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300466 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
467 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700468 ? 2
469 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
470 defaultWallpaperSize.x =
471 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700472 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000473 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700474
Thales Lima6a590062022-11-22 15:52:49 +0000475 int numMinShownHotseatIconsForTablet = supportedProfiles
476 .stream()
477 .filter(deviceProfile -> deviceProfile.isTablet)
478 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
479 .min()
480 .orElse(0);
481
482 supportedProfiles
483 .stream()
484 .filter(deviceProfile -> deviceProfile.isTablet)
485 .forEach(deviceProfile -> {
486 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
487 deviceProfile.recalculateHotseatWidthAndBorderSpace();
488 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700489 }
490
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700491 public void addOnChangeListener(OnIDPChangeListener listener) {
492 mChangeListeners.add(listener);
493 }
494
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800495 public void removeOnChangeListener(OnIDPChangeListener listener) {
496 mChangeListeners.remove(listener);
497 }
498
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800499
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800500 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000501 LauncherPrefs.get(context).put(GRID_NAME, gridName);
502 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800503 }
504
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700505 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700506 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000507 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
508 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700509 }
510
Pat Manning24cec692023-10-13 10:36:57 +0000511 /** Updates IDP using the provided context. Notifies listeners of change. */
512 @VisibleForTesting
513 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700514 Object[] oldState = toModelState();
515
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700516 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700517 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700518 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700519
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700520 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700521 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700522 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700523 }
524 }
525
Alex Chau1c883d82021-12-01 18:43:10 +0000526 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
527 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800528 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100529
Alex Chau1c883d82021-12-01 18:43:10 +0000530 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700531 final int depth = parser.getDepth();
532 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700533 while (((type = parser.next()) != XmlPullParser.END_TAG ||
534 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800535 if ((type == XmlPullParser.START_TAG)
536 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800537
Sunny Goyal076e04b2023-04-03 12:38:30 -0700538 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
539 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100540 final int displayDepth = parser.getDepth();
541 while (((type = parser.next()) != XmlPullParser.END_TAG
542 || parser.getDepth() > displayDepth)
543 && type != XmlPullParser.END_DOCUMENT) {
544 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
545 parser.getName())) {
546 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100547 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100548 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800549 }
550 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700551 }
552 }
sfufa@google.comde013292021-09-21 18:22:44 -0700553 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700554 throw new RuntimeException(e);
555 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800556
Sunny Goyalae190ff2020-04-14 00:19:01 +0000557 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800558 if (!TextUtils.isEmpty(gridName)) {
559 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100560 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700561 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000562 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800563 }
564 }
565 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000566 if (filteredProfiles.isEmpty()) {
567 // No grid found, use the default options
568 for (DisplayOption option : profiles) {
569 if (option.canBeDefault) {
570 filteredProfiles.add(option);
571 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800572 }
573 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000574 if (filteredProfiles.isEmpty()) {
575 throw new RuntimeException("No display option with canBeDefault=true");
576 }
577 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700578 }
579
Thales Lima7ec83822021-08-05 13:32:10 +0100580 /**
581 * @return all the grid options that can be shown on the device
582 */
583 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700584 return parseAllDefinedGridOptions(context)
585 .stream()
586 .filter(go -> go.isEnabled(deviceType))
587 .collect(Collectors.toList());
588 }
589
590 /**
591 * @return all the grid options that can be shown on the device
592 */
593 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100594 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100595
Alex Chau1c883d82021-12-01 18:43:10 +0000596 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100597 final int depth = parser.getDepth();
598 int type;
599 while (((type = parser.next()) != XmlPullParser.END_TAG
600 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
601 if ((type == XmlPullParser.START_TAG)
602 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700603 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100604 }
605 }
606 } catch (IOException | XmlPullParserException e) {
607 Log.e(TAG, "Error parsing device profile", e);
608 return Collections.emptyList();
609 }
610 return result;
611 }
612
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700613 private int getLauncherIconDensity(int requiredSize) {
614 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700615 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700616 DisplayMetrics.DENSITY_LOW,
617 DisplayMetrics.DENSITY_MEDIUM,
618 DisplayMetrics.DENSITY_TV,
619 DisplayMetrics.DENSITY_HIGH,
620 DisplayMetrics.DENSITY_XHIGH,
621 DisplayMetrics.DENSITY_XXHIGH,
622 DisplayMetrics.DENSITY_XXXHIGH
623 };
624
625 int density = DisplayMetrics.DENSITY_XXXHIGH;
626 for (int i = densityBuckets.length - 1; i >= 0; i--) {
627 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
628 / DisplayMetrics.DENSITY_DEFAULT;
629 if (expectedSize >= requiredSize) {
630 density = densityBuckets[i];
631 }
632 }
633
634 return density;
635 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700636
Adam Cohen2e6da152015-05-06 11:42:25 -0700637 /**
638 * Apply any Partner customization grid overrides.
639 *
640 * Currently we support: all apps row / column count.
641 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700642 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
643 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800644 if (p == null) {
645 return;
646 }
647 try {
648 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
649 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
650 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
651
652 if (numRows > 0 && numColumns > 0) {
653 this.numRows = numRows;
654 this.numColumns = numColumns;
655 }
656 if (iconSizePx > 0) {
657 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
658 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
659 }
660 } catch (Resources.NotFoundException ex) {
661 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700662 }
663 }
664
Sunny Goyal415f1732018-11-29 10:33:47 -0800665 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700666 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700667 }
668
Sunny Goyal19ff7282021-04-22 10:12:54 -0700669 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000670 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700671 int minWidthPx = Integer.MAX_VALUE;
672 int minHeightPx = Integer.MAX_VALUE;
673 for (WindowBounds bounds : displayInfo.supportedBounds) {
674 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000675 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700676 // For split displays, take half width per page
677 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
678 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700679
Sunny Goyal19ff7282021-04-22 10:12:54 -0700680 } else if (!isTablet && bounds.isLandscape()) {
681 // We will use transposed layout in this case
682 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
683 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
684 } else {
685 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
686 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
687 }
688 }
689
Thales Lima425f6822022-05-10 13:44:58 -0300690 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
691 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700692
693 // Sort the profiles based on the closeness to the device size
694 Collections.sort(points, (a, b) ->
695 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
696 dist(width, height, b.minWidthDps, b.minHeightDps)));
697
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700698 DisplayOption closestPoint = points.get(0);
699 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700700 float weights = 0;
701
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700702 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
703 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700704 }
705
706 DisplayOption out = new DisplayOption(closestOption);
707 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700708 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700709 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
710 weights += w;
711 out.add(new DisplayOption().add(p).multiply(w));
712 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700713 out.multiply(1.0f / weights);
714
Thales Lima6e0005a2021-10-27 15:53:41 +0100715 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700716 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100717 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
718 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700719 }
720
721 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700722 }
723
Sunny Goyal27835952017-01-13 12:15:53 -0800724 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000725 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
726 Rect bounds = windowManagerProxy.getCurrentBounds(context);
727 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700728
Alex Chauc09a98a2023-11-14 12:51:42 +0000729 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400730 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700731
Sunny Goyal187b16c2022-03-01 16:53:23 -0800732 /**
733 * Returns the device profile matching the provided screen configuration
734 */
735 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700736 DeviceProfile bestMatch = supportedProfiles.get(0);
737 float minDiff = Float.MAX_VALUE;
738
739 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400740 float diff = Math.abs(profile.widthPx - screenWidth)
741 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700742 if (diff < minDiff) {
743 minDiff = diff;
744 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800745 } else if (diff == minDiff && profile.rotationHint == rotation) {
746 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700747 }
748 }
749 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800750 }
751
Sunny Goyal415f1732018-11-29 10:33:47 -0800752 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700753 float d = dist(x0, y0, x1, y1);
754 if (Float.compare(d, 0f) == 0) {
755 return Float.POSITIVE_INFINITY;
756 }
757 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
758 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700759
760 /**
761 * As a ratio of screen height, the total distance we want the parallax effect to span
762 * horizontally
763 */
764 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
765 float aspectRatio = width / (float) height;
766
767 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
768 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
769 // We will use these two data points to extrapolate how much the wallpaper parallax effect
770 // to span (ie travel) at any aspect ratio:
771
sfufa@google.comde013292021-09-21 18:22:44 -0700772 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
773 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700774 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
775 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
776
777 // To find out the desired width at different aspect ratios, we use the following two
778 // formulas, where the coefficient on x is the aspect ratio (width/height):
779 // (16/10)x + y = 1.5
780 // (10/16)x + y = 1.2
781 // We solve for x and y and end up with a final formula:
782 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700783 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
784 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700785 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
786 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
787 return x * aspectRatio + y;
788 }
789
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700790 public interface OnIDPChangeListener {
791
Sunny Goyalb47172b2021-05-03 19:59:51 -0700792 /**
793 * Called when the device provide changes
794 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700795 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700796 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800797
798
Sunny Goyaleff44f32019-01-09 17:29:49 -0800799 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800800
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800801 public static final String TAG_NAME = "grid-option";
802
Alex Chau1c883d82021-12-01 18:43:10 +0000803 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
804 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
805 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
806 private static final int DEVICE_CATEGORY_ALL =
807 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
808
Thales Lima11af7bc2022-08-12 15:24:54 +0100809 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
810 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
811 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
812 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
813 private static final int DONT_INLINE_QSB = 0;
814
Sunny Goyaleff44f32019-01-09 17:29:49 -0800815 public final String name;
816 public final int numRows;
817 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000818 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700819 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800820
Thales Lima1faa4ed2023-12-01 16:48:19 +0000821 private final int[] numFolderRows = new int[COUNT_SIZES];
822 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300823 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000824 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800825
Thales Limae9273ea2023-01-26 12:33:52 +0000826 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700827 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300828 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700829 private final int numDatabaseAllAppsColumns;
830 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700831 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100832
Thales Lima425f6822022-05-10 13:44:58 -0300833 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800834
Thales Lima11af7bc2022-08-12 15:24:54 +0100835 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
836
Thales Limab35faed2022-09-05 16:30:01 -0300837 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800838 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000839
Sunny Goyal415f1732018-11-29 10:33:47 -0800840 private final int defaultLayoutId;
841 private final int demoModeLayoutId;
842
Jon Mirandae126d722021-02-25 10:45:20 -0500843 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400844 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100845 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100846 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100847 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100848 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100849 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100850 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100851 private final int mHotseatSpecsId;
852 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000853 private final int mWorkspaceCellSpecsId;
854 private final int mWorkspaceCellSpecsTwoPanelId;
855 private final int mAllAppsCellSpecsId;
856 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500857
Sunny Goyal076e04b2023-04-03 12:38:30 -0700858 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800859 TypedArray a = context.obtainStyledAttributes(
860 attrs, R.styleable.GridDisplayOption);
861 name = a.getString(R.styleable.GridDisplayOption_name);
862 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
863 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000864 numSearchContainerColumns = a.getInt(
865 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800866
Tracy Zhou7df93d22020-01-27 13:44:06 -0800867 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100868 defaultLayoutId = a.getResourceId(
869 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800870 demoModeLayoutId = a.getResourceId(
871 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700872
Thales Limae9273ea2023-01-26 12:33:52 +0000873 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
874 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700875 numAllAppsColumns = a.getInt(
876 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
877 numDatabaseAllAppsColumns = a.getInt(
878 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
879
880 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800881 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700882 numDatabaseHotseatIcons = a.getInt(
883 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100884
Thales Lima425f6822022-05-10 13:44:58 -0300885 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
886 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
887 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
888 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
889 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
890 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
891 numColumns);
892 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
893 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
894 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700895
Vinit Nayakc7293172022-07-18 16:41:50 -0700896 inlineNavButtonsEndSpacing =
897 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100898 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300899
Thales Lima1faa4ed2023-12-01 16:48:19 +0000900 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800901 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000902 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800903 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700904
Thales Lima1faa4ed2023-12-01 16:48:19 +0000905 if (FeatureFlags.enableResponsiveWorkspace()) {
906 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
907 R.styleable.GridDisplayOption_numFolderRowsLandscape,
908 numFolderRows[INDEX_DEFAULT]);
909 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
910 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
911 numFolderColumns[INDEX_DEFAULT]);
912 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
913 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
914 numFolderRows[INDEX_DEFAULT]);
915 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
916 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
917 numFolderColumns[INDEX_DEFAULT]);
918 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
919 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
920 numFolderRows[INDEX_DEFAULT]);
921 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
922 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
923 numFolderColumns[INDEX_DEFAULT]);
924 } else {
925 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
926 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
927 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
928 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
929 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
930 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
931 }
932
Thales Limab35faed2022-09-05 16:30:01 -0300933 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
934 INVALID_RESOURCE_HANDLE);
935
Thales Limad852d652023-01-17 14:01:13 +0000936 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
937 R.style.CellStyleDefault);
938
Jon Mirandae126d722021-02-25 10:45:20 -0500939 isScalable = a.getBoolean(
940 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400941 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000942 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700943 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000944 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100945
Thales Limaca31b612023-09-14 14:25:26 +0100946 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100947 mWorkspaceSpecsId = a.getResourceId(
948 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100949 mWorkspaceSpecsTwoPanelId = a.getResourceId(
950 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300951 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100952 mAllAppsSpecsId = a.getResourceId(
953 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100954 mAllAppsSpecsTwoPanelId = a.getResourceId(
955 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300956 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100957 mFolderSpecsId = a.getResourceId(
958 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100959 mFolderSpecsTwoPanelId = a.getResourceId(
960 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300961 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +0100962 mHotseatSpecsId = a.getResourceId(
963 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
964 mHotseatSpecsTwoPanelId = a.getResourceId(
965 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300966 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000967 mWorkspaceCellSpecsId = a.getResourceId(
968 R.styleable.GridDisplayOption_workspaceCellSpecsId,
969 INVALID_RESOURCE_HANDLE);
970 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
971 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300972 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000973 mAllAppsCellSpecsId = a.getResourceId(
974 R.styleable.GridDisplayOption_allAppsCellSpecsId,
975 INVALID_RESOURCE_HANDLE);
976 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
977 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300978 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -0300979 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
980 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
981 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +0100982 } else {
983 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100984 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100985 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100986 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100987 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100988 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100989 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
990 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000991 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
992 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
993 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
994 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -0300995 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +0100996 }
997
Thales Lima11af7bc2022-08-12 15:24:54 +0100998 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
999 DONT_INLINE_QSB);
1000 inlineQsb[INDEX_DEFAULT] =
1001 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1002 inlineQsb[INDEX_LANDSCAPE] =
1003 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1004 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1005 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1006 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1007 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1008 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1009 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1010
Sunny Goyal415f1732018-11-29 10:33:47 -08001011 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001012 }
1013
1014 public boolean isEnabled(@DeviceType int deviceType) {
1015 switch (deviceType) {
1016 case TYPE_PHONE:
1017 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1018 case TYPE_TABLET:
1019 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1020 case TYPE_MULTI_DISPLAY:
1021 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1022 == DEVICE_CATEGORY_MULTI_DISPLAY;
1023 default:
1024 return false;
1025 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001026 }
1027 }
1028
Sunny Goyal19ff7282021-04-22 10:12:54 -07001029 @VisibleForTesting
1030 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001031 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001032
Sunny Goyal415f1732018-11-29 10:33:47 -08001033 private final float minWidthDps;
1034 private final float minHeightDps;
1035 private final boolean canBeDefault;
1036
Thales Lima83bedbf2021-10-05 17:47:39 +01001037 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001038
Thales Lima78d00ad2021-09-30 11:29:06 +01001039 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001040 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001041 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1042 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001043
Thales Lima78d00ad2021-09-30 11:29:06 +01001044 private final float[] iconSizes = new float[COUNT_SIZES];
1045 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001046
Thales Limab7ef5692022-03-10 10:32:36 +00001047 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001048 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1049 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1050 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1051
Jon Miranda9c478b62023-03-23 21:38:49 -07001052 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1053
Jon Miranda04f05102023-04-04 12:16:31 -07001054 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1055
Thales Lima1de4d552021-10-13 16:13:25 +01001056 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001057 this.grid = grid;
1058
Jon Miranda9c478b62023-03-23 21:38:49 -07001059 Resources res = context.getResources();
1060
Thales Lima1de4d552021-10-13 16:13:25 +01001061 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001062
Sunny Goyal415f1732018-11-29 10:33:47 -08001063 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1064 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001065
Thales Lima1de4d552021-10-13 16:13:25 +01001066 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001067
Thales Lima83bedbf2021-10-05 17:47:39 +01001068 float x;
1069 float y;
1070
Thales Lima85c942f2021-12-31 13:04:20 +00001071 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1072 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001073 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001074
1075 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1076 minCellSize[INDEX_DEFAULT].x);
1077 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1078 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001079 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001080
Thales Lima85c942f2021-12-31 13:04:20 +00001081 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001082 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001083 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001084 minCellSize[INDEX_DEFAULT].y);
1085 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1086
Thales Lima85c942f2021-12-31 13:04:20 +00001087 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001088 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001089 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001090 minCellSize[INDEX_DEFAULT].y);
1091 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001092
Thales Lima85c942f2021-12-31 13:04:20 +00001093 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001094 float borderSpaceLandscape = a.getFloat(
1095 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001096 float borderSpaceTwoPanelPortrait = a.getFloat(
1097 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1098 float borderSpaceTwoPanelLandscape = a.getFloat(
1099 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001100
Thales Lima85c942f2021-12-31 13:04:20 +00001101 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1102 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001103 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001104
1105 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1106 borderSpaceLandscape);
1107 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1108 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001109 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1110
1111 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001112 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1113 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001114 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001115 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1116 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001117 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1118
1119 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001120 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1121 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001122 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001123 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1124 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001125 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1126
Thales Limab7ef5692022-03-10 10:32:36 +00001127 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1128 minCellSize[INDEX_DEFAULT].x);
1129 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1130 minCellSize[INDEX_DEFAULT].y);
1131 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1132
1133 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1134 allAppsCellSize[INDEX_DEFAULT].x);
1135 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1136 allAppsCellSize[INDEX_DEFAULT].y);
1137 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1138
1139 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1140 allAppsCellSize[INDEX_DEFAULT].x);
1141 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1142 allAppsCellSize[INDEX_DEFAULT].y);
1143 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1144
1145 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1146 allAppsCellSize[INDEX_DEFAULT].x);
1147 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1148 allAppsCellSize[INDEX_DEFAULT].y);
1149 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1150
Thales Lima080d8902022-03-28 15:30:29 +01001151 float allAppsBorderSpace = a.getFloat(
1152 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1153 float allAppsBorderSpaceLandscape = a.getFloat(
1154 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1155 allAppsBorderSpace);
1156 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001157 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001158 allAppsBorderSpace);
1159 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001160 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001161 allAppsBorderSpace);
1162
1163 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1164 allAppsBorderSpace);
1165 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1166 allAppsBorderSpace);
1167 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1168
1169 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1170 allAppsBorderSpaceLandscape);
1171 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1172 allAppsBorderSpaceLandscape);
1173 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1174
1175 x = a.getFloat(
1176 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1177 allAppsBorderSpaceTwoPanelPortrait);
1178 y = a.getFloat(
1179 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1180 allAppsBorderSpaceTwoPanelPortrait);
1181 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1182
1183 x = a.getFloat(
1184 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1185 allAppsBorderSpaceTwoPanelLandscape);
1186 y = a.getFloat(
1187 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1188 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001189 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001190
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001191 iconSizes[INDEX_DEFAULT] =
1192 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1193 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001194 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001195 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001196 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001197 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001198 iconSizes[INDEX_DEFAULT]);
1199 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001200 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001201 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001202
Thales Limabb7d3882021-12-22 12:56:29 +00001203 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1204 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001205 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1206 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001207 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001208 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1209 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1210 allAppsIconSizes[INDEX_DEFAULT]);
1211 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1212 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1213 allAppsIconSizes[INDEX_DEFAULT]);
1214
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001215 textSizes[INDEX_DEFAULT] =
1216 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1217 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001218 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001219 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001220 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001221 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001222 textSizes[INDEX_DEFAULT]);
1223 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001224 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001225 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001226
Thales Limabb7d3882021-12-22 12:56:29 +00001227 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1228 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1229 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1230 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1231 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1232 allAppsIconTextSizes[INDEX_DEFAULT]);
1233 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1234 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1235 allAppsIconTextSizes[INDEX_DEFAULT]);
1236
Thales Lima83bedbf2021-10-05 17:47:39 +01001237 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1238 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001239 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1240 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1241 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001242 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001243 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001244 horizontalMargin[INDEX_DEFAULT]);
1245 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001246 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001247 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001248
Thales Limab8c05952022-05-23 16:58:38 +01001249 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1250 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001251 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001252 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1253 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1254 hotseatBarBottomSpace[INDEX_DEFAULT]);
1255 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1256 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1257 hotseatBarBottomSpace[INDEX_DEFAULT]);
1258 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1259 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1260 hotseatBarBottomSpace[INDEX_DEFAULT]);
1261
1262 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1263 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001264 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001265 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1266 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1267 hotseatQsbSpace[INDEX_DEFAULT]);
1268 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1269 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1270 hotseatQsbSpace[INDEX_DEFAULT]);
1271 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1272 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1273 hotseatQsbSpace[INDEX_DEFAULT]);
1274
Jon Miranda9c478b62023-03-23 21:38:49 -07001275 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1276 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1277 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1278 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1279 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1280 transientTaskbarIconSize[INDEX_DEFAULT]);
1281 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1282 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1283 transientTaskbarIconSize[INDEX_DEFAULT]);
1284 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1285 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001286 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001287
Jon Miranda04f05102023-04-04 12:16:31 -07001288 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1289 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1290 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1291 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1292 startAlignTaskbar[INDEX_DEFAULT]);
1293 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1294 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1295 startAlignTaskbar[INDEX_LANDSCAPE]);
1296 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1297 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1298 startAlignTaskbar[INDEX_DEFAULT]);
1299
Sunny Goyal415f1732018-11-29 10:33:47 -08001300 a.recycle();
1301 }
1302
1303 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001304 this(null);
1305 }
1306
1307 DisplayOption(GridOption grid) {
1308 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001309 minWidthDps = 0;
1310 minHeightDps = 0;
1311 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001312 for (int i = 0; i < COUNT_SIZES; i++) {
1313 iconSizes[i] = 0;
1314 textSizes[i] = 0;
1315 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001316 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001317 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001318 allAppsIconSizes[i] = 0;
1319 allAppsIconTextSizes[i] = 0;
1320 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001321 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001322 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001323 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001324 }
1325
1326 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001327 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001328 iconSizes[i] *= w;
1329 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001330 borderSpaces[i].x *= w;
1331 borderSpaces[i].y *= w;
1332 minCellSize[i].x *= w;
1333 minCellSize[i].y *= w;
1334 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001335 hotseatBarBottomSpace[i] *= w;
1336 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001337 allAppsCellSize[i].x *= w;
1338 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001339 allAppsIconSizes[i] *= w;
1340 allAppsIconTextSizes[i] *= w;
1341 allAppsBorderSpaces[i].x *= w;
1342 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001343 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001344 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001345
Sunny Goyal415f1732018-11-29 10:33:47 -08001346 return this;
1347 }
1348
1349 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001350 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001351 iconSizes[i] += p.iconSizes[i];
1352 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001353 borderSpaces[i].x += p.borderSpaces[i].x;
1354 borderSpaces[i].y += p.borderSpaces[i].y;
1355 minCellSize[i].x += p.minCellSize[i].x;
1356 minCellSize[i].y += p.minCellSize[i].y;
1357 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001358 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1359 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001360 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1361 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001362 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1363 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1364 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1365 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001366 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001367 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001368 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001369
Sunny Goyal415f1732018-11-29 10:33:47 -08001370 return this;
1371 }
1372 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001373}