blob: 75f4bb2d119ad79aebd777e368f131722f34683d [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;
Sunny Goyal27835952017-01-13 12:15:53 -080030import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
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 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700125 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;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700173 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000174 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700175
Jon Mirandae126d722021-02-25 10:45:20 -0500176 /**
177 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
178 */
179 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000180 @XmlRes
181 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100182 @XmlRes
183 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100184 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100185 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
186 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100187 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100188 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100189 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
190 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100191 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100192 @XmlRes
193 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100194 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
195 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500196
Tracy Zhou7df93d22020-01-27 13:44:06 -0800197 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800198 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700199 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100200 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700201
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000202 /**
203 * An immutable list of supported profiles.
204 */
205 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700206
Sunny Goyal6f866092016-03-17 17:04:15 -0700207 public Point defaultWallpaperSize;
208
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700209 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700210
Sunny Goyalf633ef52018-03-13 09:57:05 -0700211 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800212 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700213
Sunny Goyalbbf01842015-10-08 07:41:15 -0700214 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700215 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700216 String gridName = getCurrentGridName(context);
217 String newGridName = initGrid(context, gridName);
218 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000219 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 }
Stefan Andonian5bd9a222023-02-23 00:58:33 +0000221 LockedUserState.get(context).runOnUserUnlocked(() -> {
222 new DeviceGridState(this).writeToPrefs(context);
223 });
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700224
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700225 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100226 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000227 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700228 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100229 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700230 }
231 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700232 }
233
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700234 /**
235 * This constructor should NOT have any monitors by design.
236 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800237 public InvariantDeviceProfile(Context context, String gridName) {
238 String newName = initGrid(context, gridName);
239 if (newName == null || !newName.equals(gridName)) {
240 throw new IllegalArgumentException("Unknown grid name");
241 }
242 }
243
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700244 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800245 * This constructor should NOT have any monitors by design.
246 */
247 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700248 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100249 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700250 String gridName = getCurrentGridName(context);
251
252 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000253 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
254 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700255 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000256 defaultInfo,
257 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
258 /*allowDisabledGrid=*/false),
259 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700260
Alex Chau661f02d2022-06-07 14:03:43 +0100261 Context displayContext = context.createDisplayContext(display);
262 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000263 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700264 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000265 myInfo,
266 getPredefinedDeviceProfiles(context, gridName, deviceType,
267 /*allowDisabledGrid=*/false),
268 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700269
270 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
271 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100272 result.iconSizes[INDEX_DEFAULT] =
273 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
274 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700275 result.iconSizes[i] = Math.min(
276 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000277 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700278
Thales Lima83bedbf2021-10-05 17:47:39 +0100279 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
280 COUNT_SIZES);
281 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
282 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500283
Alex Chau1c883d82021-12-01 18:43:10 +0000284 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800285 }
286
Alex Chau238aaee2021-10-06 16:15:24 +0100287 /**
288 * Reinitialize the current grid after a restore, where some grids might now be disabled.
289 */
290 public void reinitializeAfterRestore(Context context) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400291 FileLog.d(TAG, "Reinitializing grid after restore");
Alex Chau29a96ad2022-02-10 13:12:20 +0000292 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100293 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000294 String newGridName = initGrid(context, currentGridName);
295 String newDbFile = dbFile;
296 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400297 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100298 + ", migrating to: " + newGridName
299 + ", removing all other grid db files");
300 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
301 if (gridDbFile.equals(currentDbFile)) {
302 continue;
303 }
304 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400305 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100306 }
307 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000308 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100309 }
310 }
311
Alex Chau1c883d82021-12-01 18:43:10 +0000312 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800313 int flagPhone = 1 << 0;
314 int flagTablet = 1 << 1;
315
316 int type = displayInfo.supportedBounds.stream()
317 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
318 .reduce(0, (a, b) -> a | b);
Sebastian Francof3766132023-09-07 14:50:07 -0700319 if (type == (flagPhone | flagTablet)) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800320 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000321 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800322 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000323 return TYPE_TABLET;
324 } else {
325 return TYPE_PHONE;
326 }
327 }
328
Tracy Zhou42255d22020-03-13 00:38:11 -0700329 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000330 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700331 }
332
Sunny Goyaleff44f32019-01-09 17:29:49 -0800333 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700334 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000335 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700336
337 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000338 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100339 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700340 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000341 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
342 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700343 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800344 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700345
Thales Limab67bfa72022-11-02 15:30:11 +0000346 @VisibleForTesting
347 public static String getDefaultGridName(Context context) {
348 return new InvariantDeviceProfile().initGrid(context, null);
349 }
350
Alex Chau1c883d82021-12-01 18:43:10 +0000351 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
352 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700353 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700354 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000355 numRows = closestProfile.numRows;
356 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000357 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000358 dbFile = closestProfile.dbFile;
359 defaultLayoutId = closestProfile.defaultLayoutId;
360 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300361
Sunny Goyalae190ff2020-04-14 00:19:01 +0000362 numFolderRows = closestProfile.numFolderRows;
363 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300364 folderStyle = closestProfile.folderStyle;
365
Thales Limad852d652023-01-17 14:01:13 +0000366 cellStyle = closestProfile.cellStyle;
367
Jon Mirandae126d722021-02-25 10:45:20 -0500368 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400369 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100370 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100371 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100372 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100373 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100374 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100375 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100376 hotseatSpecsId = closestProfile.mHotseatSpecsId;
377 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Alex Chau1c883d82021-12-01 18:43:10 +0000378 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000379
Vinit Nayakc7293172022-07-18 16:41:50 -0700380 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
381
Thales Lima83bedbf2021-10-05 17:47:39 +0100382 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100383 float maxIconSize = iconSize[0];
384 for (int i = 1; i < iconSize.length; i++) {
385 maxIconSize = Math.max(maxIconSize, iconSize[i]);
386 }
387 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000388 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
389
Thales Lima83bedbf2021-10-05 17:47:39 +0100390 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700391
Thales Lima83bedbf2021-10-05 17:47:39 +0100392 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100393
Thales Lima83bedbf2021-10-05 17:47:39 +0100394 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100395
Thales Limad90faab2021-09-21 17:18:47 +0100396 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100397
Sunny Goyal19ff7282021-04-22 10:12:54 -0700398 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000399 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700400 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300401 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100402 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
403 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700404
Thales Limae9273ea2023-01-26 12:33:52 +0000405 allAppsStyle = closestProfile.allAppsStyle;
406
Sunny Goyal19ff7282021-04-22 10:12:54 -0700407 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000408 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700409 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500410
Thales Limab7ef5692022-03-10 10:32:36 +0000411 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000412 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
413 allAppsIconSize = displayOption.allAppsIconSizes;
414 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000415
Thales Lima11af7bc2022-08-12 15:24:54 +0100416 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000417
Jon Miranda9c478b62023-03-23 21:38:49 -0700418 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
419
Jon Miranda04f05102023-04-04 12:16:31 -0700420 startAlignTaskbar = displayOption.startAlignTaskbar;
421
Sunny Goyalae190ff2020-04-14 00:19:01 +0000422 // If the partner customization apk contains any grid overrides, apply them
423 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700424 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700425
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000426 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700427 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700428 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700429 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000430 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000431 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000432 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700433 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000434 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700435
Sunny Goyal19ff7282021-04-22 10:12:54 -0700436 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
437 int displayWidth = bounds.bounds.width();
438 int displayHeight = bounds.bounds.height();
439 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700440
Sunny Goyal19ff7282021-04-22 10:12:54 -0700441 // We need to ensure that there is enough extra space in the wallpaper
442 // for the intended parallax effects
443 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300444 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
445 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700446 ? 2
447 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
448 defaultWallpaperSize.x =
449 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700450 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000451 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700452
Thales Lima6a590062022-11-22 15:52:49 +0000453 int numMinShownHotseatIconsForTablet = supportedProfiles
454 .stream()
455 .filter(deviceProfile -> deviceProfile.isTablet)
456 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
457 .min()
458 .orElse(0);
459
460 supportedProfiles
461 .stream()
462 .filter(deviceProfile -> deviceProfile.isTablet)
463 .forEach(deviceProfile -> {
464 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
465 deviceProfile.recalculateHotseatWidthAndBorderSpace();
466 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700467 }
468
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700469 public void addOnChangeListener(OnIDPChangeListener listener) {
470 mChangeListeners.add(listener);
471 }
472
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800473 public void removeOnChangeListener(OnIDPChangeListener listener) {
474 mChangeListeners.remove(listener);
475 }
476
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800477
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800478 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000479 LauncherPrefs.get(context).put(GRID_NAME, gridName);
480 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800481 }
482
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700483 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700484 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000485 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
486 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700487 }
488
Pat Manning24cec692023-10-13 10:36:57 +0000489 /** Updates IDP using the provided context. Notifies listeners of change. */
490 @VisibleForTesting
491 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700492 Object[] oldState = toModelState();
493
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700494 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700495 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700496 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700497
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700498 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700499 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700500 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700501 }
502 }
503
Alex Chau1c883d82021-12-01 18:43:10 +0000504 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
505 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800506 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100507
Alex Chau1c883d82021-12-01 18:43:10 +0000508 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700509 final int depth = parser.getDepth();
510 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700511 while (((type = parser.next()) != XmlPullParser.END_TAG ||
512 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800513 if ((type == XmlPullParser.START_TAG)
514 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800515
Sunny Goyal076e04b2023-04-03 12:38:30 -0700516 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
517 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100518 final int displayDepth = parser.getDepth();
519 while (((type = parser.next()) != XmlPullParser.END_TAG
520 || parser.getDepth() > displayDepth)
521 && type != XmlPullParser.END_DOCUMENT) {
522 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
523 parser.getName())) {
524 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100525 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100526 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800527 }
528 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700529 }
530 }
sfufa@google.comde013292021-09-21 18:22:44 -0700531 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700532 throw new RuntimeException(e);
533 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800534
Sunny Goyalae190ff2020-04-14 00:19:01 +0000535 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800536 if (!TextUtils.isEmpty(gridName)) {
537 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100538 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700539 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000540 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800541 }
542 }
543 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000544 if (filteredProfiles.isEmpty()) {
545 // No grid found, use the default options
546 for (DisplayOption option : profiles) {
547 if (option.canBeDefault) {
548 filteredProfiles.add(option);
549 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800550 }
551 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000552 if (filteredProfiles.isEmpty()) {
553 throw new RuntimeException("No display option with canBeDefault=true");
554 }
555 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700556 }
557
Thales Lima7ec83822021-08-05 13:32:10 +0100558 /**
559 * @return all the grid options that can be shown on the device
560 */
561 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700562 return parseAllDefinedGridOptions(context)
563 .stream()
564 .filter(go -> go.isEnabled(deviceType))
565 .collect(Collectors.toList());
566 }
567
568 /**
569 * @return all the grid options that can be shown on the device
570 */
571 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100572 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100573
Alex Chau1c883d82021-12-01 18:43:10 +0000574 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100575 final int depth = parser.getDepth();
576 int type;
577 while (((type = parser.next()) != XmlPullParser.END_TAG
578 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
579 if ((type == XmlPullParser.START_TAG)
580 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700581 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100582 }
583 }
584 } catch (IOException | XmlPullParserException e) {
585 Log.e(TAG, "Error parsing device profile", e);
586 return Collections.emptyList();
587 }
588 return result;
589 }
590
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700591 private int getLauncherIconDensity(int requiredSize) {
592 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700593 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700594 DisplayMetrics.DENSITY_LOW,
595 DisplayMetrics.DENSITY_MEDIUM,
596 DisplayMetrics.DENSITY_TV,
597 DisplayMetrics.DENSITY_HIGH,
598 DisplayMetrics.DENSITY_XHIGH,
599 DisplayMetrics.DENSITY_XXHIGH,
600 DisplayMetrics.DENSITY_XXXHIGH
601 };
602
603 int density = DisplayMetrics.DENSITY_XXXHIGH;
604 for (int i = densityBuckets.length - 1; i >= 0; i--) {
605 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
606 / DisplayMetrics.DENSITY_DEFAULT;
607 if (expectedSize >= requiredSize) {
608 density = densityBuckets[i];
609 }
610 }
611
612 return density;
613 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700614
Adam Cohen2e6da152015-05-06 11:42:25 -0700615 /**
616 * Apply any Partner customization grid overrides.
617 *
618 * Currently we support: all apps row / column count.
619 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700620 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
621 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800622 if (p == null) {
623 return;
624 }
625 try {
626 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
627 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
628 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
629
630 if (numRows > 0 && numColumns > 0) {
631 this.numRows = numRows;
632 this.numColumns = numColumns;
633 }
634 if (iconSizePx > 0) {
635 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
636 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
637 }
638 } catch (Resources.NotFoundException ex) {
639 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700640 }
641 }
642
Sunny Goyal415f1732018-11-29 10:33:47 -0800643 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700644 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700645 }
646
Sunny Goyal19ff7282021-04-22 10:12:54 -0700647 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000648 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700649 int minWidthPx = Integer.MAX_VALUE;
650 int minHeightPx = Integer.MAX_VALUE;
651 for (WindowBounds bounds : displayInfo.supportedBounds) {
652 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000653 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700654 // For split displays, take half width per page
655 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
656 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700657
Sunny Goyal19ff7282021-04-22 10:12:54 -0700658 } else if (!isTablet && bounds.isLandscape()) {
659 // We will use transposed layout in this case
660 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
661 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
662 } else {
663 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
664 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
665 }
666 }
667
Thales Lima425f6822022-05-10 13:44:58 -0300668 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
669 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700670
671 // Sort the profiles based on the closeness to the device size
672 Collections.sort(points, (a, b) ->
673 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
674 dist(width, height, b.minWidthDps, b.minHeightDps)));
675
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700676 DisplayOption closestPoint = points.get(0);
677 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700678 float weights = 0;
679
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700680 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
681 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700682 }
683
684 DisplayOption out = new DisplayOption(closestOption);
685 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700686 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700687 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
688 weights += w;
689 out.add(new DisplayOption().add(p).multiply(w));
690 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700691 out.multiply(1.0f / weights);
692
Thales Lima6e0005a2021-10-27 15:53:41 +0100693 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700694 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100695 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
696 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700697 }
698
699 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700700 }
701
Sunny Goyal27835952017-01-13 12:15:53 -0800702 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700703 Resources res = context.getResources();
704 Configuration config = context.getResources().getConfiguration();
705
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400706 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
707 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100708 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
709
Alex Chaud3e8cc42022-05-03 17:45:34 +0100710 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400711 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700712
Sunny Goyal187b16c2022-03-01 16:53:23 -0800713 /**
714 * Returns the device profile matching the provided screen configuration
715 */
716 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700717 DeviceProfile bestMatch = supportedProfiles.get(0);
718 float minDiff = Float.MAX_VALUE;
719
720 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400721 float diff = Math.abs(profile.widthPx - screenWidth)
722 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700723 if (diff < minDiff) {
724 minDiff = diff;
725 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800726 } else if (diff == minDiff && profile.rotationHint == rotation) {
727 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700728 }
729 }
730 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800731 }
732
Sunny Goyal415f1732018-11-29 10:33:47 -0800733 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700734 float d = dist(x0, y0, x1, y1);
735 if (Float.compare(d, 0f) == 0) {
736 return Float.POSITIVE_INFINITY;
737 }
738 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
739 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700740
741 /**
742 * As a ratio of screen height, the total distance we want the parallax effect to span
743 * horizontally
744 */
745 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
746 float aspectRatio = width / (float) height;
747
748 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
749 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
750 // We will use these two data points to extrapolate how much the wallpaper parallax effect
751 // to span (ie travel) at any aspect ratio:
752
sfufa@google.comde013292021-09-21 18:22:44 -0700753 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
754 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700755 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
756 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
757
758 // To find out the desired width at different aspect ratios, we use the following two
759 // formulas, where the coefficient on x is the aspect ratio (width/height):
760 // (16/10)x + y = 1.5
761 // (10/16)x + y = 1.2
762 // We solve for x and y and end up with a final formula:
763 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700764 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
765 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700766 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
767 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
768 return x * aspectRatio + y;
769 }
770
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700771 public interface OnIDPChangeListener {
772
Sunny Goyalb47172b2021-05-03 19:59:51 -0700773 /**
774 * Called when the device provide changes
775 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700776 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700777 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800778
779
Sunny Goyaleff44f32019-01-09 17:29:49 -0800780 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800781
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800782 public static final String TAG_NAME = "grid-option";
783
Alex Chau1c883d82021-12-01 18:43:10 +0000784 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
785 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
786 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
787 private static final int DEVICE_CATEGORY_ALL =
788 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
789
Thales Lima11af7bc2022-08-12 15:24:54 +0100790 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
791 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
792 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
793 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
794 private static final int DONT_INLINE_QSB = 0;
795
Sunny Goyaleff44f32019-01-09 17:29:49 -0800796 public final String name;
797 public final int numRows;
798 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000799 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700800 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800801
802 private final int numFolderRows;
803 private final int numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300804 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000805 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800806
Thales Limae9273ea2023-01-26 12:33:52 +0000807 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700808 private final int numAllAppsColumns;
809 private final int numDatabaseAllAppsColumns;
810 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700811 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100812
Thales Lima425f6822022-05-10 13:44:58 -0300813 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800814
Thales Lima11af7bc2022-08-12 15:24:54 +0100815 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
816
Thales Limab35faed2022-09-05 16:30:01 -0300817 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800818 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000819
Sunny Goyal415f1732018-11-29 10:33:47 -0800820 private final int defaultLayoutId;
821 private final int demoModeLayoutId;
822
Jon Mirandae126d722021-02-25 10:45:20 -0500823 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400824 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100825 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100826 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100827 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100828 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100829 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100830 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100831 private final int mHotseatSpecsId;
832 private final int mHotseatSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500833
Sunny Goyal076e04b2023-04-03 12:38:30 -0700834 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800835 TypedArray a = context.obtainStyledAttributes(
836 attrs, R.styleable.GridDisplayOption);
837 name = a.getString(R.styleable.GridDisplayOption_name);
838 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
839 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000840 numSearchContainerColumns = a.getInt(
841 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800842
Tracy Zhou7df93d22020-01-27 13:44:06 -0800843 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100844 defaultLayoutId = a.getResourceId(
845 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800846 demoModeLayoutId = a.getResourceId(
847 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700848
Thales Limae9273ea2023-01-26 12:33:52 +0000849 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
850 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700851 numAllAppsColumns = a.getInt(
852 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
853 numDatabaseAllAppsColumns = a.getInt(
854 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
855
856 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800857 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700858 numDatabaseHotseatIcons = a.getInt(
859 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100860
Thales Lima425f6822022-05-10 13:44:58 -0300861 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
862 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
863 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
864 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
865 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
866 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
867 numColumns);
868 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
869 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
870 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700871
Vinit Nayakc7293172022-07-18 16:41:50 -0700872 inlineNavButtonsEndSpacing =
873 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100874 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300875
Sunny Goyal415f1732018-11-29 10:33:47 -0800876 numFolderRows = a.getInt(
877 R.styleable.GridDisplayOption_numFolderRows, numRows);
878 numFolderColumns = a.getInt(
879 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700880
Thales Limab35faed2022-09-05 16:30:01 -0300881 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
882 INVALID_RESOURCE_HANDLE);
883
Thales Limad852d652023-01-17 14:01:13 +0000884 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
885 R.style.CellStyleDefault);
886
Jon Mirandae126d722021-02-25 10:45:20 -0500887 isScalable = a.getBoolean(
888 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400889 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000890 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700891 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000892 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100893
Thales Limaca31b612023-09-14 14:25:26 +0100894 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100895 mWorkspaceSpecsId = a.getResourceId(
896 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100897 mWorkspaceSpecsTwoPanelId = a.getResourceId(
898 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
899 INVALID_RESOURCE_HANDLE);
Thales Limaabfe3642023-05-24 18:08:53 +0100900 mAllAppsSpecsId = a.getResourceId(
901 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100902 mAllAppsSpecsTwoPanelId = a.getResourceId(
903 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
904 INVALID_RESOURCE_HANDLE);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100905 mFolderSpecsId = a.getResourceId(
906 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100907 mFolderSpecsTwoPanelId = a.getResourceId(
908 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
909 INVALID_RESOURCE_HANDLE);
Thales Limaf8bfb032023-07-24 15:08:05 +0100910 mHotseatSpecsId = a.getResourceId(
911 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
912 mHotseatSpecsTwoPanelId = a.getResourceId(
913 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
914 INVALID_RESOURCE_HANDLE);
Thales Limaec5abba2023-04-05 16:33:50 +0100915 } else {
916 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100917 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100918 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100919 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100920 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100921 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +0100922 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
923 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100924 }
925
Thales Lima11af7bc2022-08-12 15:24:54 +0100926 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
927 DONT_INLINE_QSB);
928 inlineQsb[INDEX_DEFAULT] =
929 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
930 inlineQsb[INDEX_LANDSCAPE] =
931 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
932 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
933 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
934 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
935 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
936 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
937 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
938
Sunny Goyal415f1732018-11-29 10:33:47 -0800939 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -0700940 }
941
942 public boolean isEnabled(@DeviceType int deviceType) {
943 switch (deviceType) {
944 case TYPE_PHONE:
945 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
946 case TYPE_TABLET:
947 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
948 case TYPE_MULTI_DISPLAY:
949 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
950 == DEVICE_CATEGORY_MULTI_DISPLAY;
951 default:
952 return false;
953 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800954 }
955 }
956
Sunny Goyal19ff7282021-04-22 10:12:54 -0700957 @VisibleForTesting
958 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700959 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800960
Sunny Goyal415f1732018-11-29 10:33:47 -0800961 private final float minWidthDps;
962 private final float minHeightDps;
963 private final boolean canBeDefault;
964
Thales Lima83bedbf2021-10-05 17:47:39 +0100965 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100966
Thales Lima78d00ad2021-09-30 11:29:06 +0100967 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100968 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100969 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
970 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100971
Thales Lima78d00ad2021-09-30 11:29:06 +0100972 private final float[] iconSizes = new float[COUNT_SIZES];
973 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800974
Thales Limab7ef5692022-03-10 10:32:36 +0000975 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000976 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
977 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
978 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
979
Jon Miranda9c478b62023-03-23 21:38:49 -0700980 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
981
Jon Miranda04f05102023-04-04 12:16:31 -0700982 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
983
Thales Lima1de4d552021-10-13 16:13:25 +0100984 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800985 this.grid = grid;
986
Jon Miranda9c478b62023-03-23 21:38:49 -0700987 Resources res = context.getResources();
988
Thales Lima1de4d552021-10-13 16:13:25 +0100989 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800990
Sunny Goyal415f1732018-11-29 10:33:47 -0800991 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
992 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700993
Thales Lima1de4d552021-10-13 16:13:25 +0100994 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800995
Thales Lima83bedbf2021-10-05 17:47:39 +0100996 float x;
997 float y;
998
Thales Lima85c942f2021-12-31 13:04:20 +0000999 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1000 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001001 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001002
1003 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1004 minCellSize[INDEX_DEFAULT].x);
1005 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1006 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001007 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001008
Thales Lima85c942f2021-12-31 13:04:20 +00001009 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001010 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001011 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001012 minCellSize[INDEX_DEFAULT].y);
1013 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1014
Thales Lima85c942f2021-12-31 13:04:20 +00001015 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001016 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001017 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001018 minCellSize[INDEX_DEFAULT].y);
1019 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001020
Thales Lima85c942f2021-12-31 13:04:20 +00001021 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001022 float borderSpaceLandscape = a.getFloat(
1023 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001024 float borderSpaceTwoPanelPortrait = a.getFloat(
1025 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1026 float borderSpaceTwoPanelLandscape = a.getFloat(
1027 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001028
Thales Lima85c942f2021-12-31 13:04:20 +00001029 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1030 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001031 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001032
1033 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1034 borderSpaceLandscape);
1035 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1036 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001037 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1038
1039 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001040 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1041 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001042 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001043 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1044 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001045 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1046
1047 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001048 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1049 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001050 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001051 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1052 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001053 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1054
Thales Limab7ef5692022-03-10 10:32:36 +00001055 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1056 minCellSize[INDEX_DEFAULT].x);
1057 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1058 minCellSize[INDEX_DEFAULT].y);
1059 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1060
1061 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1062 allAppsCellSize[INDEX_DEFAULT].x);
1063 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1064 allAppsCellSize[INDEX_DEFAULT].y);
1065 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1066
1067 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1068 allAppsCellSize[INDEX_DEFAULT].x);
1069 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1070 allAppsCellSize[INDEX_DEFAULT].y);
1071 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1072
1073 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1074 allAppsCellSize[INDEX_DEFAULT].x);
1075 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1076 allAppsCellSize[INDEX_DEFAULT].y);
1077 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1078
Thales Lima080d8902022-03-28 15:30:29 +01001079 float allAppsBorderSpace = a.getFloat(
1080 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1081 float allAppsBorderSpaceLandscape = a.getFloat(
1082 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1083 allAppsBorderSpace);
1084 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001085 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001086 allAppsBorderSpace);
1087 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001088 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001089 allAppsBorderSpace);
1090
1091 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1092 allAppsBorderSpace);
1093 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1094 allAppsBorderSpace);
1095 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1096
1097 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1098 allAppsBorderSpaceLandscape);
1099 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1100 allAppsBorderSpaceLandscape);
1101 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1102
1103 x = a.getFloat(
1104 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1105 allAppsBorderSpaceTwoPanelPortrait);
1106 y = a.getFloat(
1107 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1108 allAppsBorderSpaceTwoPanelPortrait);
1109 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1110
1111 x = a.getFloat(
1112 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1113 allAppsBorderSpaceTwoPanelLandscape);
1114 y = a.getFloat(
1115 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1116 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001117 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001118
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001119 iconSizes[INDEX_DEFAULT] =
1120 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1121 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001122 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001123 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001124 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001125 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001126 iconSizes[INDEX_DEFAULT]);
1127 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001128 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001129 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001130
Thales Limabb7d3882021-12-22 12:56:29 +00001131 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1132 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001133 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1134 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001135 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001136 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1137 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1138 allAppsIconSizes[INDEX_DEFAULT]);
1139 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1140 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1141 allAppsIconSizes[INDEX_DEFAULT]);
1142
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001143 textSizes[INDEX_DEFAULT] =
1144 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1145 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001146 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001147 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001148 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001149 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001150 textSizes[INDEX_DEFAULT]);
1151 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001152 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001153 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001154
Thales Limabb7d3882021-12-22 12:56:29 +00001155 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1156 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1157 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1158 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1159 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1160 allAppsIconTextSizes[INDEX_DEFAULT]);
1161 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1162 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1163 allAppsIconTextSizes[INDEX_DEFAULT]);
1164
Thales Lima83bedbf2021-10-05 17:47:39 +01001165 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1166 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001167 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1168 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1169 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001170 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001171 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001172 horizontalMargin[INDEX_DEFAULT]);
1173 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001174 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001175 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001176
Thales Limab8c05952022-05-23 16:58:38 +01001177 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1178 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001179 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001180 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1181 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1182 hotseatBarBottomSpace[INDEX_DEFAULT]);
1183 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1184 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1185 hotseatBarBottomSpace[INDEX_DEFAULT]);
1186 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1187 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1188 hotseatBarBottomSpace[INDEX_DEFAULT]);
1189
1190 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1191 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001192 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001193 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1194 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1195 hotseatQsbSpace[INDEX_DEFAULT]);
1196 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1197 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1198 hotseatQsbSpace[INDEX_DEFAULT]);
1199 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1200 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1201 hotseatQsbSpace[INDEX_DEFAULT]);
1202
Jon Miranda9c478b62023-03-23 21:38:49 -07001203 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1204 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1205 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1206 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1207 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1208 transientTaskbarIconSize[INDEX_DEFAULT]);
1209 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1210 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1211 transientTaskbarIconSize[INDEX_DEFAULT]);
1212 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1213 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001214 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001215
Jon Miranda04f05102023-04-04 12:16:31 -07001216 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1217 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1218 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1219 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1220 startAlignTaskbar[INDEX_DEFAULT]);
1221 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1222 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1223 startAlignTaskbar[INDEX_LANDSCAPE]);
1224 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1225 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1226 startAlignTaskbar[INDEX_DEFAULT]);
1227
Sunny Goyal415f1732018-11-29 10:33:47 -08001228 a.recycle();
1229 }
1230
1231 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001232 this(null);
1233 }
1234
1235 DisplayOption(GridOption grid) {
1236 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001237 minWidthDps = 0;
1238 minHeightDps = 0;
1239 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001240 for (int i = 0; i < COUNT_SIZES; i++) {
1241 iconSizes[i] = 0;
1242 textSizes[i] = 0;
1243 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001244 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001245 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001246 allAppsIconSizes[i] = 0;
1247 allAppsIconTextSizes[i] = 0;
1248 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001249 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001250 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001251 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001252 }
1253
1254 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001255 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001256 iconSizes[i] *= w;
1257 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001258 borderSpaces[i].x *= w;
1259 borderSpaces[i].y *= w;
1260 minCellSize[i].x *= w;
1261 minCellSize[i].y *= w;
1262 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001263 hotseatBarBottomSpace[i] *= w;
1264 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001265 allAppsCellSize[i].x *= w;
1266 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001267 allAppsIconSizes[i] *= w;
1268 allAppsIconTextSizes[i] *= w;
1269 allAppsBorderSpaces[i].x *= w;
1270 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001271 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001272 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001273
Sunny Goyal415f1732018-11-29 10:33:47 -08001274 return this;
1275 }
1276
1277 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001278 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001279 iconSizes[i] += p.iconSizes[i];
1280 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001281 borderSpaces[i].x += p.borderSpaces[i].x;
1282 borderSpaces[i].y += p.borderSpaces[i].y;
1283 minCellSize[i].x += p.minCellSize[i].x;
1284 minCellSize[i].y += p.minCellSize[i].y;
1285 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001286 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1287 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001288 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1289 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001290 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1291 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1292 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1293 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001294 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001295 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001296 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001297
Sunny Goyal415f1732018-11-29 10:33:47 -08001298 return this;
1299 }
1300 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001301}