blob: 7087d3b1babc0edfba3c07c12cdfc4fcdcfbf342 [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();
Sunny Goyal25c42762024-04-16 19:31:31 -0700266 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
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);
Sunny Goyal25c42762024-04-16 19:31:31 -0700275 @DeviceType int deviceType = myInfo.getDeviceType();
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
Tracy Zhou42255d22020-03-13 00:38:11 -0700328 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000329 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700330 }
331
Sunny Goyaleff44f32019-01-09 17:29:49 -0800332 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700333 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700334 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700335
336 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000337 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100338 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700339 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000340 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
341 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700342 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800343 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700344
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700345 /**
346 * @deprecated This is a temporary solution because on the backup and restore case we modify the
347 * IDP, this resets it. b/332974074
348 */
349 @Deprecated
350 public void reset(Context context) {
351 initGrid(context, getCurrentGridName(context));
352 }
353
Thales Limab67bfa72022-11-02 15:30:11 +0000354 @VisibleForTesting
355 public static String getDefaultGridName(Context context) {
356 return new InvariantDeviceProfile().initGrid(context, null);
357 }
358
Alex Chau1c883d82021-12-01 18:43:10 +0000359 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
360 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700361 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700362 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000363 numRows = closestProfile.numRows;
364 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000365 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000366 dbFile = closestProfile.dbFile;
367 defaultLayoutId = closestProfile.defaultLayoutId;
368 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300369
Sunny Goyalae190ff2020-04-14 00:19:01 +0000370 numFolderRows = closestProfile.numFolderRows;
371 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300372 folderStyle = closestProfile.folderStyle;
373
Thales Limad852d652023-01-17 14:01:13 +0000374 cellStyle = closestProfile.cellStyle;
375
Jon Mirandae126d722021-02-25 10:45:20 -0500376 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400377 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100378 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100379 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100380 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100381 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100382 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100383 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100384 hotseatSpecsId = closestProfile.mHotseatSpecsId;
385 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000386 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
387 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
388 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
389 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300390 numAllAppsRowsForCellHeightCalculation =
391 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000392 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000393
Vinit Nayakc7293172022-07-18 16:41:50 -0700394 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
395
Thales Lima83bedbf2021-10-05 17:47:39 +0100396 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100397 float maxIconSize = iconSize[0];
398 for (int i = 1; i < iconSize.length; i++) {
399 maxIconSize = Math.max(maxIconSize, iconSize[i]);
400 }
401 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000402 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
403
Thales Lima83bedbf2021-10-05 17:47:39 +0100404 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700405
Thales Lima83bedbf2021-10-05 17:47:39 +0100406 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100407
Thales Lima83bedbf2021-10-05 17:47:39 +0100408 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100409
Thales Limad90faab2021-09-21 17:18:47 +0100410 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100411
Sunny Goyal19ff7282021-04-22 10:12:54 -0700412 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000413 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700414 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300415 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100416 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
417 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700418
Thales Limae9273ea2023-01-26 12:33:52 +0000419 allAppsStyle = closestProfile.allAppsStyle;
420
Sunny Goyal19ff7282021-04-22 10:12:54 -0700421 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300422
Alex Chau1c883d82021-12-01 18:43:10 +0000423 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700424 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500425
Thales Limab7ef5692022-03-10 10:32:36 +0000426 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000427 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
428 allAppsIconSize = displayOption.allAppsIconSizes;
429 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000430
Thales Lima11af7bc2022-08-12 15:24:54 +0100431 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000432
Jon Miranda9c478b62023-03-23 21:38:49 -0700433 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
434
Jon Miranda04f05102023-04-04 12:16:31 -0700435 startAlignTaskbar = displayOption.startAlignTaskbar;
436
Sunny Goyalae190ff2020-04-14 00:19:01 +0000437 // If the partner customization apk contains any grid overrides, apply them
438 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700439 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700440
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000441 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700442 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700443 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700444 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000445 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000446 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000447 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700448 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000449 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700450
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
452 int displayWidth = bounds.bounds.width();
453 int displayHeight = bounds.bounds.height();
454 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700455
Sunny Goyal19ff7282021-04-22 10:12:54 -0700456 // We need to ensure that there is enough extra space in the wallpaper
457 // for the intended parallax effects
458 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300459 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
460 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700461 ? 2
462 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
463 defaultWallpaperSize.x =
464 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700465 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000466 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700467
Thales Lima6a590062022-11-22 15:52:49 +0000468 int numMinShownHotseatIconsForTablet = supportedProfiles
469 .stream()
470 .filter(deviceProfile -> deviceProfile.isTablet)
471 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
472 .min()
473 .orElse(0);
474
475 supportedProfiles
476 .stream()
477 .filter(deviceProfile -> deviceProfile.isTablet)
478 .forEach(deviceProfile -> {
479 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
480 deviceProfile.recalculateHotseatWidthAndBorderSpace();
481 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700482 }
483
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700484 public void addOnChangeListener(OnIDPChangeListener listener) {
485 mChangeListeners.add(listener);
486 }
487
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800488 public void removeOnChangeListener(OnIDPChangeListener listener) {
489 mChangeListeners.remove(listener);
490 }
491
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800492
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800493 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000494 LauncherPrefs.get(context).put(GRID_NAME, gridName);
495 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800496 }
497
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700498 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700499 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000500 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
501 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700502 }
503
Pat Manning24cec692023-10-13 10:36:57 +0000504 /** Updates IDP using the provided context. Notifies listeners of change. */
505 @VisibleForTesting
506 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700507 Object[] oldState = toModelState();
508
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700509 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700510 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700511 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700512
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700513 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700514 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700515 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700516 }
517 }
518
Alex Chau1c883d82021-12-01 18:43:10 +0000519 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
520 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800521 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100522
Alex Chau1c883d82021-12-01 18:43:10 +0000523 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700524 final int depth = parser.getDepth();
525 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700526 while (((type = parser.next()) != XmlPullParser.END_TAG ||
527 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800528 if ((type == XmlPullParser.START_TAG)
529 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800530
Sunny Goyal076e04b2023-04-03 12:38:30 -0700531 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
532 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100533 final int displayDepth = parser.getDepth();
534 while (((type = parser.next()) != XmlPullParser.END_TAG
535 || parser.getDepth() > displayDepth)
536 && type != XmlPullParser.END_DOCUMENT) {
537 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
538 parser.getName())) {
539 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100540 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100541 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800542 }
543 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700544 }
545 }
sfufa@google.comde013292021-09-21 18:22:44 -0700546 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700547 throw new RuntimeException(e);
548 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800549
Sunny Goyalae190ff2020-04-14 00:19:01 +0000550 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800551 if (!TextUtils.isEmpty(gridName)) {
552 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100553 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700554 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000555 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800556 }
557 }
558 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000559 if (filteredProfiles.isEmpty()) {
560 // No grid found, use the default options
561 for (DisplayOption option : profiles) {
562 if (option.canBeDefault) {
563 filteredProfiles.add(option);
564 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800565 }
566 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000567 if (filteredProfiles.isEmpty()) {
568 throw new RuntimeException("No display option with canBeDefault=true");
569 }
570 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700571 }
572
Thales Lima7ec83822021-08-05 13:32:10 +0100573 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000574 * Returns the GridOption associated to the given file name or null if the fileName is not
575 * supported.
576 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
577 */
578 public GridOption getGridOptionFromFileName(Context context, String fileName) {
579 return parseAllGridOptions(context).stream()
580 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
581 .findFirst()
582 .orElse(null);
583 }
584
585 /**
586 * Returns the name of the given size on the current device or empty string if the size is not
587 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
588 * (Note: the name of the grid can be different for the same grid size depending of
589 * the values of the InvariantDeviceProfile)
590 *
591 */
592 public String getGridNameFromSize(Context context, Point size) {
593 return parseAllGridOptions(context).stream()
594 .filter(gridOption -> gridOption.numColumns == size.x
595 && gridOption.numRows == size.y)
596 .map(gridOption -> gridOption.name)
597 .findFirst()
598 .orElse("");
599 }
600
601 /**
602 * Returns the grid option for the given gridName on the current device (Note: the gridOption
603 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
604 */
605 public GridOption getGridOptionFromName(Context context, String gridName) {
606 return parseAllGridOptions(context).stream()
607 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
608 .findFirst()
609 .orElse(null);
610 }
611
612 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100613 * @return all the grid options that can be shown on the device
614 */
615 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700616 return parseAllDefinedGridOptions(context)
617 .stream()
618 .filter(go -> go.isEnabled(deviceType))
619 .collect(Collectors.toList());
620 }
621
622 /**
623 * @return all the grid options that can be shown on the device
624 */
625 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100626 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100627
Alex Chau1c883d82021-12-01 18:43:10 +0000628 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100629 final int depth = parser.getDepth();
630 int type;
631 while (((type = parser.next()) != XmlPullParser.END_TAG
632 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
633 if ((type == XmlPullParser.START_TAG)
634 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700635 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100636 }
637 }
638 } catch (IOException | XmlPullParserException e) {
639 Log.e(TAG, "Error parsing device profile", e);
640 return Collections.emptyList();
641 }
642 return result;
643 }
644
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700645 private int getLauncherIconDensity(int requiredSize) {
646 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700647 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700648 DisplayMetrics.DENSITY_LOW,
649 DisplayMetrics.DENSITY_MEDIUM,
650 DisplayMetrics.DENSITY_TV,
651 DisplayMetrics.DENSITY_HIGH,
652 DisplayMetrics.DENSITY_XHIGH,
653 DisplayMetrics.DENSITY_XXHIGH,
654 DisplayMetrics.DENSITY_XXXHIGH
655 };
656
657 int density = DisplayMetrics.DENSITY_XXXHIGH;
658 for (int i = densityBuckets.length - 1; i >= 0; i--) {
659 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
660 / DisplayMetrics.DENSITY_DEFAULT;
661 if (expectedSize >= requiredSize) {
662 density = densityBuckets[i];
663 }
664 }
665
666 return density;
667 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700668
Adam Cohen2e6da152015-05-06 11:42:25 -0700669 /**
670 * Apply any Partner customization grid overrides.
671 *
672 * Currently we support: all apps row / column count.
673 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700674 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
675 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800676 if (p == null) {
677 return;
678 }
679 try {
680 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
681 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
682 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
683
684 if (numRows > 0 && numColumns > 0) {
685 this.numRows = numRows;
686 this.numColumns = numColumns;
687 }
688 if (iconSizePx > 0) {
689 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
690 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
691 }
692 } catch (Resources.NotFoundException ex) {
693 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700694 }
695 }
696
Sunny Goyal415f1732018-11-29 10:33:47 -0800697 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700698 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700699 }
700
Sunny Goyal19ff7282021-04-22 10:12:54 -0700701 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000702 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700703 int minWidthPx = Integer.MAX_VALUE;
704 int minHeightPx = Integer.MAX_VALUE;
705 for (WindowBounds bounds : displayInfo.supportedBounds) {
706 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000707 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700708 // For split displays, take half width per page
709 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
710 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700711
Sunny Goyal19ff7282021-04-22 10:12:54 -0700712 } else if (!isTablet && bounds.isLandscape()) {
713 // We will use transposed layout in this case
714 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
715 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
716 } else {
717 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
718 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
719 }
720 }
721
Thales Lima425f6822022-05-10 13:44:58 -0300722 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
723 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700724
725 // Sort the profiles based on the closeness to the device size
726 Collections.sort(points, (a, b) ->
727 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
728 dist(width, height, b.minWidthDps, b.minHeightDps)));
729
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700730 DisplayOption closestPoint = points.get(0);
731 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700732 float weights = 0;
733
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700734 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
735 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700736 }
737
738 DisplayOption out = new DisplayOption(closestOption);
739 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700740 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700741 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
742 weights += w;
743 out.add(new DisplayOption().add(p).multiply(w));
744 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700745 out.multiply(1.0f / weights);
746
Thales Lima6e0005a2021-10-27 15:53:41 +0100747 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700748 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100749 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
750 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700751 }
752
753 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700754 }
755
Sunny Goyal27835952017-01-13 12:15:53 -0800756 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000757 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
758 Rect bounds = windowManagerProxy.getCurrentBounds(context);
759 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700760
Alex Chauc09a98a2023-11-14 12:51:42 +0000761 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400762 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700763
Sunny Goyal187b16c2022-03-01 16:53:23 -0800764 /**
765 * Returns the device profile matching the provided screen configuration
766 */
767 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768 DeviceProfile bestMatch = supportedProfiles.get(0);
769 float minDiff = Float.MAX_VALUE;
770
771 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400772 float diff = Math.abs(profile.widthPx - screenWidth)
773 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700774 if (diff < minDiff) {
775 minDiff = diff;
776 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800777 } else if (diff == minDiff && profile.rotationHint == rotation) {
778 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700779 }
780 }
781 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800782 }
783
Sunny Goyal415f1732018-11-29 10:33:47 -0800784 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700785 float d = dist(x0, y0, x1, y1);
786 if (Float.compare(d, 0f) == 0) {
787 return Float.POSITIVE_INFINITY;
788 }
789 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
790 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700791
792 /**
793 * As a ratio of screen height, the total distance we want the parallax effect to span
794 * horizontally
795 */
796 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
797 float aspectRatio = width / (float) height;
798
799 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
800 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
801 // We will use these two data points to extrapolate how much the wallpaper parallax effect
802 // to span (ie travel) at any aspect ratio:
803
sfufa@google.comde013292021-09-21 18:22:44 -0700804 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
805 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700806 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
807 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
808
809 // To find out the desired width at different aspect ratios, we use the following two
810 // formulas, where the coefficient on x is the aspect ratio (width/height):
811 // (16/10)x + y = 1.5
812 // (10/16)x + y = 1.2
813 // We solve for x and y and end up with a final formula:
814 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700815 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
816 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700817 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
818 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
819 return x * aspectRatio + y;
820 }
821
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700822 public interface OnIDPChangeListener {
823
Sunny Goyalb47172b2021-05-03 19:59:51 -0700824 /**
825 * Called when the device provide changes
826 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700827 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700828 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800829
830
Sunny Goyaleff44f32019-01-09 17:29:49 -0800831 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800832
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800833 public static final String TAG_NAME = "grid-option";
834
Alex Chau1c883d82021-12-01 18:43:10 +0000835 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
836 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
837 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
838 private static final int DEVICE_CATEGORY_ALL =
839 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
840
Thales Lima11af7bc2022-08-12 15:24:54 +0100841 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
842 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
843 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
844 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
845 private static final int DONT_INLINE_QSB = 0;
846
Sunny Goyaleff44f32019-01-09 17:29:49 -0800847 public final String name;
848 public final int numRows;
849 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000850 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700851 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800852
Thales Lima1faa4ed2023-12-01 16:48:19 +0000853 private final int[] numFolderRows = new int[COUNT_SIZES];
854 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300855 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000856 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800857
Thales Limae9273ea2023-01-26 12:33:52 +0000858 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700859 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300860 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700861 private final int numDatabaseAllAppsColumns;
862 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700863 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100864
Thales Lima425f6822022-05-10 13:44:58 -0300865 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800866
Thales Lima11af7bc2022-08-12 15:24:54 +0100867 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
868
Thales Limab35faed2022-09-05 16:30:01 -0300869 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800870 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000871
Sunny Goyal415f1732018-11-29 10:33:47 -0800872 private final int defaultLayoutId;
873 private final int demoModeLayoutId;
874
Jon Mirandae126d722021-02-25 10:45:20 -0500875 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400876 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100877 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100878 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100879 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100880 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100881 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100882 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100883 private final int mHotseatSpecsId;
884 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000885 private final int mWorkspaceCellSpecsId;
886 private final int mWorkspaceCellSpecsTwoPanelId;
887 private final int mAllAppsCellSpecsId;
888 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500889
Sunny Goyal076e04b2023-04-03 12:38:30 -0700890 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800891 TypedArray a = context.obtainStyledAttributes(
892 attrs, R.styleable.GridDisplayOption);
893 name = a.getString(R.styleable.GridDisplayOption_name);
894 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
895 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000896 numSearchContainerColumns = a.getInt(
897 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800898
Tracy Zhou7df93d22020-01-27 13:44:06 -0800899 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100900 defaultLayoutId = a.getResourceId(
901 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800902 demoModeLayoutId = a.getResourceId(
903 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700904
Thales Limae9273ea2023-01-26 12:33:52 +0000905 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
906 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700907 numAllAppsColumns = a.getInt(
908 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
909 numDatabaseAllAppsColumns = a.getInt(
910 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
911
912 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800913 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700914 numDatabaseHotseatIcons = a.getInt(
915 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100916
Thales Lima425f6822022-05-10 13:44:58 -0300917 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
918 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
919 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
920 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
921 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
922 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
923 numColumns);
924 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
925 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
926 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700927
Vinit Nayakc7293172022-07-18 16:41:50 -0700928 inlineNavButtonsEndSpacing =
929 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100930 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300931
Thales Lima1faa4ed2023-12-01 16:48:19 +0000932 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800933 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000934 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800935 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700936
Thales Lima1faa4ed2023-12-01 16:48:19 +0000937 if (FeatureFlags.enableResponsiveWorkspace()) {
938 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
939 R.styleable.GridDisplayOption_numFolderRowsLandscape,
940 numFolderRows[INDEX_DEFAULT]);
941 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
942 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
943 numFolderColumns[INDEX_DEFAULT]);
944 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
945 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
946 numFolderRows[INDEX_DEFAULT]);
947 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
948 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
949 numFolderColumns[INDEX_DEFAULT]);
950 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
951 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
952 numFolderRows[INDEX_DEFAULT]);
953 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
954 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
955 numFolderColumns[INDEX_DEFAULT]);
956 } else {
957 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
958 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
959 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
960 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
961 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
962 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
963 }
964
Thales Limab35faed2022-09-05 16:30:01 -0300965 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
966 INVALID_RESOURCE_HANDLE);
967
Thales Limad852d652023-01-17 14:01:13 +0000968 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
969 R.style.CellStyleDefault);
970
Jon Mirandae126d722021-02-25 10:45:20 -0500971 isScalable = a.getBoolean(
972 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400973 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000974 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700975 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000976 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100977
Thales Limaca31b612023-09-14 14:25:26 +0100978 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100979 mWorkspaceSpecsId = a.getResourceId(
980 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100981 mWorkspaceSpecsTwoPanelId = a.getResourceId(
982 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300983 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100984 mAllAppsSpecsId = a.getResourceId(
985 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100986 mAllAppsSpecsTwoPanelId = a.getResourceId(
987 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300988 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100989 mFolderSpecsId = a.getResourceId(
990 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100991 mFolderSpecsTwoPanelId = a.getResourceId(
992 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300993 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +0100994 mHotseatSpecsId = a.getResourceId(
995 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
996 mHotseatSpecsTwoPanelId = a.getResourceId(
997 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300998 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000999 mWorkspaceCellSpecsId = a.getResourceId(
1000 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1001 INVALID_RESOURCE_HANDLE);
1002 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1003 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001004 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001005 mAllAppsCellSpecsId = a.getResourceId(
1006 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1007 INVALID_RESOURCE_HANDLE);
1008 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1009 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001010 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001011 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1012 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1013 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001014 } else {
1015 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001016 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001017 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001018 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001019 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001020 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001021 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1022 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001023 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1024 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1025 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1026 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001027 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001028 }
1029
Thales Lima11af7bc2022-08-12 15:24:54 +01001030 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1031 DONT_INLINE_QSB);
1032 inlineQsb[INDEX_DEFAULT] =
1033 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1034 inlineQsb[INDEX_LANDSCAPE] =
1035 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1036 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1037 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1038 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1039 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1040 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1041 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1042
Sunny Goyal415f1732018-11-29 10:33:47 -08001043 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001044 }
1045
1046 public boolean isEnabled(@DeviceType int deviceType) {
1047 switch (deviceType) {
1048 case TYPE_PHONE:
1049 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1050 case TYPE_TABLET:
1051 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1052 case TYPE_MULTI_DISPLAY:
1053 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1054 == DEVICE_CATEGORY_MULTI_DISPLAY;
1055 default:
1056 return false;
1057 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001058 }
1059 }
1060
Sunny Goyal19ff7282021-04-22 10:12:54 -07001061 @VisibleForTesting
1062 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001063 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001064
Sunny Goyal415f1732018-11-29 10:33:47 -08001065 private final float minWidthDps;
1066 private final float minHeightDps;
1067 private final boolean canBeDefault;
1068
Thales Lima83bedbf2021-10-05 17:47:39 +01001069 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001070
Thales Lima78d00ad2021-09-30 11:29:06 +01001071 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001072 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001073 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1074 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001075
Thales Lima78d00ad2021-09-30 11:29:06 +01001076 private final float[] iconSizes = new float[COUNT_SIZES];
1077 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001078
Thales Limab7ef5692022-03-10 10:32:36 +00001079 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001080 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1081 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1082 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1083
Jon Miranda9c478b62023-03-23 21:38:49 -07001084 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1085
Jon Miranda04f05102023-04-04 12:16:31 -07001086 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1087
Thales Lima1de4d552021-10-13 16:13:25 +01001088 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001089 this.grid = grid;
1090
Jon Miranda9c478b62023-03-23 21:38:49 -07001091 Resources res = context.getResources();
1092
Thales Lima1de4d552021-10-13 16:13:25 +01001093 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001094
Sunny Goyal415f1732018-11-29 10:33:47 -08001095 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1096 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001097
Thales Lima1de4d552021-10-13 16:13:25 +01001098 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001099
Thales Lima83bedbf2021-10-05 17:47:39 +01001100 float x;
1101 float y;
1102
Thales Lima85c942f2021-12-31 13:04:20 +00001103 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1104 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001105 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001106
1107 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1108 minCellSize[INDEX_DEFAULT].x);
1109 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1110 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001111 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001112
Thales Lima85c942f2021-12-31 13:04:20 +00001113 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001114 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001115 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001116 minCellSize[INDEX_DEFAULT].y);
1117 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1118
Thales Lima85c942f2021-12-31 13:04:20 +00001119 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001120 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001121 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001122 minCellSize[INDEX_DEFAULT].y);
1123 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001124
Thales Lima85c942f2021-12-31 13:04:20 +00001125 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001126 float borderSpaceLandscape = a.getFloat(
1127 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001128 float borderSpaceTwoPanelPortrait = a.getFloat(
1129 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1130 float borderSpaceTwoPanelLandscape = a.getFloat(
1131 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001132
Thales Lima85c942f2021-12-31 13:04:20 +00001133 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1134 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001135 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001136
1137 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1138 borderSpaceLandscape);
1139 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1140 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001141 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1142
1143 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001144 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1145 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001146 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001147 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1148 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001149 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1150
1151 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001152 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1153 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001154 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001155 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1156 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001157 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1158
Thales Limab7ef5692022-03-10 10:32:36 +00001159 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1160 minCellSize[INDEX_DEFAULT].x);
1161 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1162 minCellSize[INDEX_DEFAULT].y);
1163 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1164
1165 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1166 allAppsCellSize[INDEX_DEFAULT].x);
1167 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1168 allAppsCellSize[INDEX_DEFAULT].y);
1169 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1170
1171 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1172 allAppsCellSize[INDEX_DEFAULT].x);
1173 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1174 allAppsCellSize[INDEX_DEFAULT].y);
1175 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1176
1177 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1178 allAppsCellSize[INDEX_DEFAULT].x);
1179 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1180 allAppsCellSize[INDEX_DEFAULT].y);
1181 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1182
Thales Lima080d8902022-03-28 15:30:29 +01001183 float allAppsBorderSpace = a.getFloat(
1184 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1185 float allAppsBorderSpaceLandscape = a.getFloat(
1186 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1187 allAppsBorderSpace);
1188 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001189 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001190 allAppsBorderSpace);
1191 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001192 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001193 allAppsBorderSpace);
1194
1195 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1196 allAppsBorderSpace);
1197 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1198 allAppsBorderSpace);
1199 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1200
1201 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1202 allAppsBorderSpaceLandscape);
1203 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1204 allAppsBorderSpaceLandscape);
1205 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1206
1207 x = a.getFloat(
1208 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1209 allAppsBorderSpaceTwoPanelPortrait);
1210 y = a.getFloat(
1211 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1212 allAppsBorderSpaceTwoPanelPortrait);
1213 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1214
1215 x = a.getFloat(
1216 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1217 allAppsBorderSpaceTwoPanelLandscape);
1218 y = a.getFloat(
1219 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1220 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001221 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001222
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001223 iconSizes[INDEX_DEFAULT] =
1224 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1225 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001226 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001227 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001228 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001229 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001230 iconSizes[INDEX_DEFAULT]);
1231 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001232 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001233 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001234
Thales Limabb7d3882021-12-22 12:56:29 +00001235 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1236 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001237 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1238 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001239 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001240 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1241 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1242 allAppsIconSizes[INDEX_DEFAULT]);
1243 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1244 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1245 allAppsIconSizes[INDEX_DEFAULT]);
1246
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001247 textSizes[INDEX_DEFAULT] =
1248 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1249 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001250 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001251 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001252 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001253 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001254 textSizes[INDEX_DEFAULT]);
1255 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001256 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001257 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001258
Thales Limabb7d3882021-12-22 12:56:29 +00001259 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1260 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1261 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1262 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1263 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1264 allAppsIconTextSizes[INDEX_DEFAULT]);
1265 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1266 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1267 allAppsIconTextSizes[INDEX_DEFAULT]);
1268
Thales Lima83bedbf2021-10-05 17:47:39 +01001269 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1270 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001271 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1272 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1273 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001274 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001275 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001276 horizontalMargin[INDEX_DEFAULT]);
1277 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001278 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001279 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001280
Thales Limab8c05952022-05-23 16:58:38 +01001281 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1282 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001283 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001284 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1285 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1286 hotseatBarBottomSpace[INDEX_DEFAULT]);
1287 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1288 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1289 hotseatBarBottomSpace[INDEX_DEFAULT]);
1290 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1291 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1292 hotseatBarBottomSpace[INDEX_DEFAULT]);
1293
1294 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1295 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001296 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001297 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1298 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1299 hotseatQsbSpace[INDEX_DEFAULT]);
1300 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1301 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1302 hotseatQsbSpace[INDEX_DEFAULT]);
1303 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1304 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1305 hotseatQsbSpace[INDEX_DEFAULT]);
1306
Jon Miranda9c478b62023-03-23 21:38:49 -07001307 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1308 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1309 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1310 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1311 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1312 transientTaskbarIconSize[INDEX_DEFAULT]);
1313 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1314 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1315 transientTaskbarIconSize[INDEX_DEFAULT]);
1316 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1317 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001318 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001319
Jon Miranda04f05102023-04-04 12:16:31 -07001320 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1321 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1322 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1323 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1324 startAlignTaskbar[INDEX_DEFAULT]);
1325 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1326 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1327 startAlignTaskbar[INDEX_LANDSCAPE]);
1328 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1329 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1330 startAlignTaskbar[INDEX_DEFAULT]);
1331
Sunny Goyal415f1732018-11-29 10:33:47 -08001332 a.recycle();
1333 }
1334
1335 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001336 this(null);
1337 }
1338
1339 DisplayOption(GridOption grid) {
1340 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001341 minWidthDps = 0;
1342 minHeightDps = 0;
1343 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001344 for (int i = 0; i < COUNT_SIZES; i++) {
1345 iconSizes[i] = 0;
1346 textSizes[i] = 0;
1347 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001348 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001349 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001350 allAppsIconSizes[i] = 0;
1351 allAppsIconTextSizes[i] = 0;
1352 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001353 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001354 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001355 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001356 }
1357
1358 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001359 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001360 iconSizes[i] *= w;
1361 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001362 borderSpaces[i].x *= w;
1363 borderSpaces[i].y *= w;
1364 minCellSize[i].x *= w;
1365 minCellSize[i].y *= w;
1366 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001367 hotseatBarBottomSpace[i] *= w;
1368 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001369 allAppsCellSize[i].x *= w;
1370 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001371 allAppsIconSizes[i] *= w;
1372 allAppsIconTextSizes[i] *= w;
1373 allAppsBorderSpaces[i].x *= w;
1374 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001375 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001376 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001377
Sunny Goyal415f1732018-11-29 10:33:47 -08001378 return this;
1379 }
1380
1381 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001382 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001383 iconSizes[i] += p.iconSizes[i];
1384 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001385 borderSpaces[i].x += p.borderSpaces[i].x;
1386 borderSpaces[i].y += p.borderSpaces[i].y;
1387 minCellSize[i].x += p.minCellSize[i].x;
1388 minCellSize[i].y += p.minCellSize[i].y;
1389 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001390 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1391 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001392 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1393 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001394 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1395 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1396 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1397 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001398 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001399 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001400 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001401
Sunny Goyal415f1732018-11-29 10:33:47 -08001402 return this;
1403 }
1404 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001405}