blob: f405b93c6851b828d85ff952aace4343352f8e16 [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 Goyal10fa0162024-04-21 00:13:35 -070062import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070063import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080064import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070065
Sunny Goyal819e1932016-07-07 16:43:58 -070066import org.xmlpull.v1.XmlPullParser;
67import org.xmlpull.v1.XmlPullParserException;
68
69import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000070import java.lang.annotation.Retention;
71import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070072import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070073import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080074import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070075import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000076import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070077import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070078
Sunny Goyal10fa0162024-04-21 00:13:35 -070079public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Hyunyoung Songc55a3502018-12-04 15:43:16 -080081 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070082 // We do not need any synchronization for this variable as its only written on UI thread.
83 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070084 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070085
Alex Chau1c883d82021-12-01 18:43:10 +000086 @Retention(RetentionPolicy.SOURCE)
87 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010088 public @interface DeviceType {}
89
Alex Chau1c883d82021-12-01 18:43:10 +000090 public static final int TYPE_PHONE = 0;
91 public static final int TYPE_MULTI_DISPLAY = 1;
92 public static final int TYPE_TABLET = 2;
93
Sunny Goyal53d7ee42015-05-22 12:25:45 -070094 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
95
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070096 // Constants that affects the interpolation curve between statically defined device profile
97 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080098 private static final float KNEARESTNEIGHBOR = 3;
99 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700100
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700101 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800102 private static final float WEIGHT_EFFICIENT = 100000f;
103
Thales Lima83bedbf2021-10-05 17:47:39 +0100104 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
105 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000106 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100107 static final int INDEX_DEFAULT = 0;
108 static final int INDEX_LANDSCAPE = 1;
109 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
110 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100111
Thales Limaec5abba2023-04-05 16:33:50 +0100112 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800113 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
114 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
115 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
116
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700117 /**
118 * Number of icons per row and column in the workspace.
119 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700120 public int numRows;
121 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000122 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700123
124 /**
125 * Number of icons per row and column in the folder.
126 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000127 public int[] numFolderRows;
128 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100129 public float[] iconSize;
130 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700131 public int iconBitmapSize;
132 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000133 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700134
Thales Lima83bedbf2021-10-05 17:47:39 +0100135 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100136
Thales Lima83bedbf2021-10-05 17:47:39 +0100137 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300138 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100139
Thales Limab35faed2022-09-05 16:30:01 -0300140 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100141
Thales Limad852d652023-01-17 14:01:13 +0000142 public @StyleRes int cellStyle;
143
Thales Lima83bedbf2021-10-05 17:47:39 +0100144 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500145
Thales Limab7ef5692022-03-10 10:32:36 +0000146 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000147 public float[] allAppsIconSize;
148 public float[] allAppsIconTextSize;
149 public PointF[] allAppsBorderSpaces;
150
Jon Miranda9c478b62023-03-23 21:38:49 -0700151 public float[] transientTaskbarIconSize;
152
Jon Miranda04f05102023-04-04 12:16:31 -0700153 public boolean[] startAlignTaskbar;
154
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700155 /**
156 * Number of icons inside the hotseat area.
157 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800158 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700159
160 /**
161 * Number of icons inside the hotseat area that is stored in the database. This is greater than
162 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
163 * sizes that share the same DB.
164 */
165 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700166
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 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700233 LockedUserState.get(context).runOnUserUnlocked(() ->
234 new DeviceGridState(this).writeToPrefs(context));
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700235
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700236 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100237 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000238 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700239 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100240 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700241 }
242 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700243 }
244
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700245 /**
246 * This constructor should NOT have any monitors by design.
247 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800248 public InvariantDeviceProfile(Context context, String gridName) {
249 String newName = initGrid(context, gridName);
250 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000251 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800252 }
253 }
254
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700255 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800256 * This constructor should NOT have any monitors by design.
257 */
258 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700259 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100260 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 String gridName = getCurrentGridName(context);
262
263 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000264 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700265 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700266 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000267 defaultInfo,
268 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
269 /*allowDisabledGrid=*/false),
270 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700271
Alex Chau661f02d2022-06-07 14:03:43 +0100272 Context displayContext = context.createDisplayContext(display);
273 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700274 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700275 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000276 myInfo,
277 getPredefinedDeviceProfiles(context, gridName, deviceType,
278 /*allowDisabledGrid=*/false),
279 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280
281 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
282 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100283 result.iconSizes[INDEX_DEFAULT] =
284 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
285 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700286 result.iconSizes[i] = Math.min(
287 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000288 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700289
Thales Lima83bedbf2021-10-05 17:47:39 +0100290 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
291 COUNT_SIZES);
292 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
293 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500294
Alex Chau1c883d82021-12-01 18:43:10 +0000295 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800296 }
297
Sunny Goyal10fa0162024-04-21 00:13:35 -0700298 @Override
299 public void close() {
300 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
301 }
302
Alex Chau238aaee2021-10-06 16:15:24 +0100303 /**
304 * Reinitialize the current grid after a restore, where some grids might now be disabled.
305 */
306 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000307 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100308 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000309 String newGridName = initGrid(context, currentGridName);
310 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400311 FileLog.d(TAG, "Reinitializing grid after restore."
312 + " currentGridName=" + currentGridName
313 + ", currentDbFile=" + currentDbFile
314 + ", newGridName=" + newGridName
315 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000316 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400317 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100318 + ", migrating to: " + newGridName
319 + ", removing all other grid db files");
320 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
321 if (gridDbFile.equals(currentDbFile)) {
322 continue;
323 }
324 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400325 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100326 }
327 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000328 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100329 }
330 }
331
Tracy Zhou42255d22020-03-13 00:38:11 -0700332 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000333 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700334 }
335
Sunny Goyaleff44f32019-01-09 17:29:49 -0800336 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700337 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700338 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700339
340 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000341 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100342 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700343 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000344 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
345 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700346 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800347 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700348
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700349 /**
350 * @deprecated This is a temporary solution because on the backup and restore case we modify the
351 * IDP, this resets it. b/332974074
352 */
353 @Deprecated
354 public void reset(Context context) {
355 initGrid(context, getCurrentGridName(context));
356 }
357
Thales Limab67bfa72022-11-02 15:30:11 +0000358 @VisibleForTesting
359 public static String getDefaultGridName(Context context) {
360 return new InvariantDeviceProfile().initGrid(context, null);
361 }
362
Alex Chau1c883d82021-12-01 18:43:10 +0000363 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
364 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700365 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700366 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000367 numRows = closestProfile.numRows;
368 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000369 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000370 dbFile = closestProfile.dbFile;
371 defaultLayoutId = closestProfile.defaultLayoutId;
372 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300373
Sunny Goyalae190ff2020-04-14 00:19:01 +0000374 numFolderRows = closestProfile.numFolderRows;
375 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300376 folderStyle = closestProfile.folderStyle;
377
Thales Limad852d652023-01-17 14:01:13 +0000378 cellStyle = closestProfile.cellStyle;
379
Jon Mirandae126d722021-02-25 10:45:20 -0500380 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400381 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100382 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100383 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100384 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100385 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100386 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100387 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100388 hotseatSpecsId = closestProfile.mHotseatSpecsId;
389 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000390 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
391 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
392 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
393 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300394 numAllAppsRowsForCellHeightCalculation =
395 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000396 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000397
Vinit Nayakc7293172022-07-18 16:41:50 -0700398 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
399
Thales Lima83bedbf2021-10-05 17:47:39 +0100400 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100401 float maxIconSize = iconSize[0];
402 for (int i = 1; i < iconSize.length; i++) {
403 maxIconSize = Math.max(maxIconSize, iconSize[i]);
404 }
405 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000406 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
407
Thales Lima83bedbf2021-10-05 17:47:39 +0100408 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700409
Thales Lima83bedbf2021-10-05 17:47:39 +0100410 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100411
Thales Lima83bedbf2021-10-05 17:47:39 +0100412 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100413
Thales Limad90faab2021-09-21 17:18:47 +0100414 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100415
Sunny Goyal19ff7282021-04-22 10:12:54 -0700416 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000417 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700418 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100419 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
420 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700421
Thales Limae9273ea2023-01-26 12:33:52 +0000422 allAppsStyle = closestProfile.allAppsStyle;
423
Sunny Goyal19ff7282021-04-22 10:12:54 -0700424 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300425
Alex Chau1c883d82021-12-01 18:43:10 +0000426 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700427 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500428
Thales Limab7ef5692022-03-10 10:32:36 +0000429 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000430 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
431 allAppsIconSize = displayOption.allAppsIconSizes;
432 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000433
Thales Lima11af7bc2022-08-12 15:24:54 +0100434 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000435
Jon Miranda9c478b62023-03-23 21:38:49 -0700436 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
437
Jon Miranda04f05102023-04-04 12:16:31 -0700438 startAlignTaskbar = displayOption.startAlignTaskbar;
439
Sunny Goyalae190ff2020-04-14 00:19:01 +0000440 // If the partner customization apk contains any grid overrides, apply them
441 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700442 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700443
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000444 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700445 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700446 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700447 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000448 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000449 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000450 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700451 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000452 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700453
Sunny Goyal19ff7282021-04-22 10:12:54 -0700454 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
455 int displayWidth = bounds.bounds.width();
456 int displayHeight = bounds.bounds.height();
457 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700458
Sunny Goyal19ff7282021-04-22 10:12:54 -0700459 // We need to ensure that there is enough extra space in the wallpaper
460 // for the intended parallax effects
461 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300462 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
463 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700464 ? 2
465 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
466 defaultWallpaperSize.x =
467 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700468 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000469 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700470
Thales Lima6a590062022-11-22 15:52:49 +0000471 int numMinShownHotseatIconsForTablet = supportedProfiles
472 .stream()
473 .filter(deviceProfile -> deviceProfile.isTablet)
474 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
475 .min()
476 .orElse(0);
477
478 supportedProfiles
479 .stream()
480 .filter(deviceProfile -> deviceProfile.isTablet)
481 .forEach(deviceProfile -> {
482 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
483 deviceProfile.recalculateHotseatWidthAndBorderSpace();
484 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700485 }
486
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700487 public void addOnChangeListener(OnIDPChangeListener listener) {
488 mChangeListeners.add(listener);
489 }
490
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800491 public void removeOnChangeListener(OnIDPChangeListener listener) {
492 mChangeListeners.remove(listener);
493 }
494
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800495
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800496 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000497 LauncherPrefs.get(context).put(GRID_NAME, gridName);
498 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800499 }
500
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700501 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700502 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000503 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
504 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700505 }
506
Pat Manning24cec692023-10-13 10:36:57 +0000507 /** Updates IDP using the provided context. Notifies listeners of change. */
508 @VisibleForTesting
509 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700510 Object[] oldState = toModelState();
511
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700512 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700513 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700514 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700515
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700516 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700517 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700518 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700519 }
520 }
521
Alex Chau1c883d82021-12-01 18:43:10 +0000522 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
523 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800524 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100525
Alex Chau1c883d82021-12-01 18:43:10 +0000526 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700527 final int depth = parser.getDepth();
528 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700529 while (((type = parser.next()) != XmlPullParser.END_TAG ||
530 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800531 if ((type == XmlPullParser.START_TAG)
532 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800533
Sunny Goyal076e04b2023-04-03 12:38:30 -0700534 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
535 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100536 final int displayDepth = parser.getDepth();
537 while (((type = parser.next()) != XmlPullParser.END_TAG
538 || parser.getDepth() > displayDepth)
539 && type != XmlPullParser.END_DOCUMENT) {
540 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
541 parser.getName())) {
542 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100543 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100544 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800545 }
546 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700547 }
548 }
sfufa@google.comde013292021-09-21 18:22:44 -0700549 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700550 throw new RuntimeException(e);
551 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800552
Sunny Goyalae190ff2020-04-14 00:19:01 +0000553 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800554 if (!TextUtils.isEmpty(gridName)) {
555 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100556 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700557 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000558 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800559 }
560 }
561 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000562 if (filteredProfiles.isEmpty()) {
563 // No grid found, use the default options
564 for (DisplayOption option : profiles) {
565 if (option.canBeDefault) {
566 filteredProfiles.add(option);
567 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800568 }
569 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000570 if (filteredProfiles.isEmpty()) {
571 throw new RuntimeException("No display option with canBeDefault=true");
572 }
573 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700574 }
575
Thales Lima7ec83822021-08-05 13:32:10 +0100576 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000577 * Returns the GridOption associated to the given file name or null if the fileName is not
578 * supported.
579 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
580 */
581 public GridOption getGridOptionFromFileName(Context context, String fileName) {
582 return parseAllGridOptions(context).stream()
583 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
584 .findFirst()
585 .orElse(null);
586 }
587
588 /**
589 * Returns the name of the given size on the current device or empty string if the size is not
590 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
591 * (Note: the name of the grid can be different for the same grid size depending of
592 * the values of the InvariantDeviceProfile)
593 *
594 */
595 public String getGridNameFromSize(Context context, Point size) {
596 return parseAllGridOptions(context).stream()
597 .filter(gridOption -> gridOption.numColumns == size.x
598 && gridOption.numRows == size.y)
599 .map(gridOption -> gridOption.name)
600 .findFirst()
601 .orElse("");
602 }
603
604 /**
605 * Returns the grid option for the given gridName on the current device (Note: the gridOption
606 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
607 */
608 public GridOption getGridOptionFromName(Context context, String gridName) {
609 return parseAllGridOptions(context).stream()
610 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
611 .findFirst()
612 .orElse(null);
613 }
614
615 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100616 * @return all the grid options that can be shown on the device
617 */
618 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700619 return parseAllDefinedGridOptions(context)
620 .stream()
621 .filter(go -> go.isEnabled(deviceType))
622 .collect(Collectors.toList());
623 }
624
625 /**
626 * @return all the grid options that can be shown on the device
627 */
628 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100629 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100630
Alex Chau1c883d82021-12-01 18:43:10 +0000631 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100632 final int depth = parser.getDepth();
633 int type;
634 while (((type = parser.next()) != XmlPullParser.END_TAG
635 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
636 if ((type == XmlPullParser.START_TAG)
637 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700638 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100639 }
640 }
641 } catch (IOException | XmlPullParserException e) {
642 Log.e(TAG, "Error parsing device profile", e);
643 return Collections.emptyList();
644 }
645 return result;
646 }
647
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700648 private int getLauncherIconDensity(int requiredSize) {
649 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700650 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700651 DisplayMetrics.DENSITY_LOW,
652 DisplayMetrics.DENSITY_MEDIUM,
653 DisplayMetrics.DENSITY_TV,
654 DisplayMetrics.DENSITY_HIGH,
655 DisplayMetrics.DENSITY_XHIGH,
656 DisplayMetrics.DENSITY_XXHIGH,
657 DisplayMetrics.DENSITY_XXXHIGH
658 };
659
660 int density = DisplayMetrics.DENSITY_XXXHIGH;
661 for (int i = densityBuckets.length - 1; i >= 0; i--) {
662 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
663 / DisplayMetrics.DENSITY_DEFAULT;
664 if (expectedSize >= requiredSize) {
665 density = densityBuckets[i];
666 }
667 }
668
669 return density;
670 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700671
Adam Cohen2e6da152015-05-06 11:42:25 -0700672 /**
673 * Apply any Partner customization grid overrides.
674 *
675 * Currently we support: all apps row / column count.
676 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700677 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
678 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800679 if (p == null) {
680 return;
681 }
682 try {
683 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
684 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
685 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
686
687 if (numRows > 0 && numColumns > 0) {
688 this.numRows = numRows;
689 this.numColumns = numColumns;
690 }
691 if (iconSizePx > 0) {
692 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
693 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
694 }
695 } catch (Resources.NotFoundException ex) {
696 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700697 }
698 }
699
Sunny Goyal415f1732018-11-29 10:33:47 -0800700 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700701 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700702 }
703
Sunny Goyal19ff7282021-04-22 10:12:54 -0700704 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000705 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700706 int minWidthPx = Integer.MAX_VALUE;
707 int minHeightPx = Integer.MAX_VALUE;
708 for (WindowBounds bounds : displayInfo.supportedBounds) {
709 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000710 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700711 // For split displays, take half width per page
712 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
713 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700714
Sunny Goyal19ff7282021-04-22 10:12:54 -0700715 } else if (!isTablet && bounds.isLandscape()) {
716 // We will use transposed layout in this case
717 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
718 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
719 } else {
720 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
721 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
722 }
723 }
724
Thales Lima425f6822022-05-10 13:44:58 -0300725 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
726 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700727
728 // Sort the profiles based on the closeness to the device size
729 Collections.sort(points, (a, b) ->
730 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
731 dist(width, height, b.minWidthDps, b.minHeightDps)));
732
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700733 DisplayOption closestPoint = points.get(0);
734 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700735 float weights = 0;
736
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700737 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
738 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700739 }
740
741 DisplayOption out = new DisplayOption(closestOption);
742 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700743 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700744 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
745 weights += w;
746 out.add(new DisplayOption().add(p).multiply(w));
747 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700748 out.multiply(1.0f / weights);
749
Thales Lima6e0005a2021-10-27 15:53:41 +0100750 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700751 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100752 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
753 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700754 }
755
756 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700757 }
758
Sunny Goyal27835952017-01-13 12:15:53 -0800759 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000760 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
761 Rect bounds = windowManagerProxy.getCurrentBounds(context);
762 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700763
Alex Chauc09a98a2023-11-14 12:51:42 +0000764 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400765 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700766
Sunny Goyal187b16c2022-03-01 16:53:23 -0800767 /**
768 * Returns the device profile matching the provided screen configuration
769 */
770 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700771 DeviceProfile bestMatch = supportedProfiles.get(0);
772 float minDiff = Float.MAX_VALUE;
773
774 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400775 float diff = Math.abs(profile.widthPx - screenWidth)
776 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700777 if (diff < minDiff) {
778 minDiff = diff;
779 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800780 } else if (diff == minDiff && profile.rotationHint == rotation) {
781 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700782 }
783 }
784 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800785 }
786
Sunny Goyal415f1732018-11-29 10:33:47 -0800787 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700788 float d = dist(x0, y0, x1, y1);
789 if (Float.compare(d, 0f) == 0) {
790 return Float.POSITIVE_INFINITY;
791 }
792 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
793 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700794
795 /**
796 * As a ratio of screen height, the total distance we want the parallax effect to span
797 * horizontally
798 */
799 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
800 float aspectRatio = width / (float) height;
801
802 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
803 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
804 // We will use these two data points to extrapolate how much the wallpaper parallax effect
805 // to span (ie travel) at any aspect ratio:
806
sfufa@google.comde013292021-09-21 18:22:44 -0700807 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
808 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700809 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
810 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
811
812 // To find out the desired width at different aspect ratios, we use the following two
813 // formulas, where the coefficient on x is the aspect ratio (width/height):
814 // (16/10)x + y = 1.5
815 // (10/16)x + y = 1.2
816 // We solve for x and y and end up with a final formula:
817 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700818 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
819 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700820 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
821 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
822 return x * aspectRatio + y;
823 }
824
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700825 public interface OnIDPChangeListener {
826
Sunny Goyalb47172b2021-05-03 19:59:51 -0700827 /**
828 * Called when the device provide changes
829 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700830 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700831 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800832
833
Sunny Goyaleff44f32019-01-09 17:29:49 -0800834 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800835
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800836 public static final String TAG_NAME = "grid-option";
837
Alex Chau1c883d82021-12-01 18:43:10 +0000838 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
839 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
840 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
841 private static final int DEVICE_CATEGORY_ALL =
842 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
843
Thales Lima11af7bc2022-08-12 15:24:54 +0100844 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
845 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
846 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
847 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
848 private static final int DONT_INLINE_QSB = 0;
849
Sunny Goyaleff44f32019-01-09 17:29:49 -0800850 public final String name;
851 public final int numRows;
852 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000853 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700854 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800855
Thales Lima1faa4ed2023-12-01 16:48:19 +0000856 private final int[] numFolderRows = new int[COUNT_SIZES];
857 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300858 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000859 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800860
Thales Limae9273ea2023-01-26 12:33:52 +0000861 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700862 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300863 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700864 private final int numDatabaseAllAppsColumns;
865 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700866 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100867
Thales Lima11af7bc2022-08-12 15:24:54 +0100868 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
869
Thales Limab35faed2022-09-05 16:30:01 -0300870 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800871 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000872
Sunny Goyal415f1732018-11-29 10:33:47 -0800873 private final int defaultLayoutId;
874 private final int demoModeLayoutId;
875
Jon Mirandae126d722021-02-25 10:45:20 -0500876 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400877 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100878 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100879 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100880 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100881 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100882 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100883 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100884 private final int mHotseatSpecsId;
885 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000886 private final int mWorkspaceCellSpecsId;
887 private final int mWorkspaceCellSpecsTwoPanelId;
888 private final int mAllAppsCellSpecsId;
889 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500890
Sunny Goyal076e04b2023-04-03 12:38:30 -0700891 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800892 TypedArray a = context.obtainStyledAttributes(
893 attrs, R.styleable.GridDisplayOption);
894 name = a.getString(R.styleable.GridDisplayOption_name);
895 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
896 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000897 numSearchContainerColumns = a.getInt(
898 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800899
Tracy Zhou7df93d22020-01-27 13:44:06 -0800900 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100901 defaultLayoutId = a.getResourceId(
902 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800903 demoModeLayoutId = a.getResourceId(
904 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700905
Thales Limae9273ea2023-01-26 12:33:52 +0000906 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
907 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700908 numAllAppsColumns = a.getInt(
909 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
910 numDatabaseAllAppsColumns = a.getInt(
911 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
912
913 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800914 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700915 numDatabaseHotseatIcons = a.getInt(
916 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100917
Vinit Nayakc7293172022-07-18 16:41:50 -0700918 inlineNavButtonsEndSpacing =
919 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100920 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300921
Thales Lima1faa4ed2023-12-01 16:48:19 +0000922 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800923 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000924 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800925 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700926
Thales Lima1faa4ed2023-12-01 16:48:19 +0000927 if (FeatureFlags.enableResponsiveWorkspace()) {
928 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
929 R.styleable.GridDisplayOption_numFolderRowsLandscape,
930 numFolderRows[INDEX_DEFAULT]);
931 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
932 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
933 numFolderColumns[INDEX_DEFAULT]);
934 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
935 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
936 numFolderRows[INDEX_DEFAULT]);
937 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
938 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
939 numFolderColumns[INDEX_DEFAULT]);
940 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
941 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
942 numFolderRows[INDEX_DEFAULT]);
943 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
944 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
945 numFolderColumns[INDEX_DEFAULT]);
946 } else {
947 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
948 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
949 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
950 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
951 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
952 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
953 }
954
Thales Limab35faed2022-09-05 16:30:01 -0300955 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
956 INVALID_RESOURCE_HANDLE);
957
Thales Limad852d652023-01-17 14:01:13 +0000958 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
959 R.style.CellStyleDefault);
960
Jon Mirandae126d722021-02-25 10:45:20 -0500961 isScalable = a.getBoolean(
962 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400963 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000964 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700965 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000966 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100967
Thales Limaca31b612023-09-14 14:25:26 +0100968 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100969 mWorkspaceSpecsId = a.getResourceId(
970 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100971 mWorkspaceSpecsTwoPanelId = a.getResourceId(
972 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300973 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100974 mAllAppsSpecsId = a.getResourceId(
975 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100976 mAllAppsSpecsTwoPanelId = a.getResourceId(
977 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300978 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100979 mFolderSpecsId = a.getResourceId(
980 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100981 mFolderSpecsTwoPanelId = a.getResourceId(
982 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300983 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +0100984 mHotseatSpecsId = a.getResourceId(
985 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
986 mHotseatSpecsTwoPanelId = a.getResourceId(
987 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300988 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000989 mWorkspaceCellSpecsId = a.getResourceId(
990 R.styleable.GridDisplayOption_workspaceCellSpecsId,
991 INVALID_RESOURCE_HANDLE);
992 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
993 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300994 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000995 mAllAppsCellSpecsId = a.getResourceId(
996 R.styleable.GridDisplayOption_allAppsCellSpecsId,
997 INVALID_RESOURCE_HANDLE);
998 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
999 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001000 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001001 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1002 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1003 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001004 } else {
1005 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001006 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001007 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001008 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001009 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001010 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001011 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1012 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001013 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1014 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1015 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1016 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001017 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001018 }
1019
Thales Lima11af7bc2022-08-12 15:24:54 +01001020 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1021 DONT_INLINE_QSB);
1022 inlineQsb[INDEX_DEFAULT] =
1023 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1024 inlineQsb[INDEX_LANDSCAPE] =
1025 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1026 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1027 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1028 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1029 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1030 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1031 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1032
Sunny Goyal415f1732018-11-29 10:33:47 -08001033 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001034 }
1035
1036 public boolean isEnabled(@DeviceType int deviceType) {
1037 switch (deviceType) {
1038 case TYPE_PHONE:
1039 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1040 case TYPE_TABLET:
1041 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1042 case TYPE_MULTI_DISPLAY:
1043 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1044 == DEVICE_CATEGORY_MULTI_DISPLAY;
1045 default:
1046 return false;
1047 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001048 }
1049 }
1050
Sunny Goyal19ff7282021-04-22 10:12:54 -07001051 @VisibleForTesting
1052 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001053 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001054
Sunny Goyal415f1732018-11-29 10:33:47 -08001055 private final float minWidthDps;
1056 private final float minHeightDps;
1057 private final boolean canBeDefault;
1058
Thales Lima83bedbf2021-10-05 17:47:39 +01001059 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001060
Thales Lima78d00ad2021-09-30 11:29:06 +01001061 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001062 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001063 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1064 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001065
Thales Lima78d00ad2021-09-30 11:29:06 +01001066 private final float[] iconSizes = new float[COUNT_SIZES];
1067 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001068
Thales Limab7ef5692022-03-10 10:32:36 +00001069 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001070 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1071 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1072 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1073
Jon Miranda9c478b62023-03-23 21:38:49 -07001074 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1075
Jon Miranda04f05102023-04-04 12:16:31 -07001076 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1077
Thales Lima1de4d552021-10-13 16:13:25 +01001078 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001079 this.grid = grid;
1080
Jon Miranda9c478b62023-03-23 21:38:49 -07001081 Resources res = context.getResources();
1082
Thales Lima1de4d552021-10-13 16:13:25 +01001083 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001084
Sunny Goyal415f1732018-11-29 10:33:47 -08001085 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1086 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001087
Thales Lima1de4d552021-10-13 16:13:25 +01001088 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001089
Thales Lima83bedbf2021-10-05 17:47:39 +01001090 float x;
1091 float y;
1092
Thales Lima85c942f2021-12-31 13:04:20 +00001093 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1094 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001095 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001096
1097 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1098 minCellSize[INDEX_DEFAULT].x);
1099 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1100 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001101 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001102
Thales Lima85c942f2021-12-31 13:04:20 +00001103 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001104 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001105 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001106 minCellSize[INDEX_DEFAULT].y);
1107 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1108
Thales Lima85c942f2021-12-31 13:04:20 +00001109 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001110 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001111 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001112 minCellSize[INDEX_DEFAULT].y);
1113 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001114
Thales Lima85c942f2021-12-31 13:04:20 +00001115 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001116 float borderSpaceLandscape = a.getFloat(
1117 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001118 float borderSpaceTwoPanelPortrait = a.getFloat(
1119 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1120 float borderSpaceTwoPanelLandscape = a.getFloat(
1121 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001122
Thales Lima85c942f2021-12-31 13:04:20 +00001123 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1124 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001125 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001126
1127 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1128 borderSpaceLandscape);
1129 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1130 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001131 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1132
1133 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001134 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1135 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001136 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001137 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1138 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001139 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1140
1141 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001142 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1143 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001144 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001145 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1146 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001147 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1148
Thales Limab7ef5692022-03-10 10:32:36 +00001149 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1150 minCellSize[INDEX_DEFAULT].x);
1151 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1152 minCellSize[INDEX_DEFAULT].y);
1153 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1154
1155 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1156 allAppsCellSize[INDEX_DEFAULT].x);
1157 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1158 allAppsCellSize[INDEX_DEFAULT].y);
1159 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1160
1161 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1162 allAppsCellSize[INDEX_DEFAULT].x);
1163 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1164 allAppsCellSize[INDEX_DEFAULT].y);
1165 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1166
1167 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1168 allAppsCellSize[INDEX_DEFAULT].x);
1169 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1170 allAppsCellSize[INDEX_DEFAULT].y);
1171 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1172
Thales Lima080d8902022-03-28 15:30:29 +01001173 float allAppsBorderSpace = a.getFloat(
1174 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1175 float allAppsBorderSpaceLandscape = a.getFloat(
1176 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1177 allAppsBorderSpace);
1178 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001179 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001180 allAppsBorderSpace);
1181 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001182 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001183 allAppsBorderSpace);
1184
1185 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1186 allAppsBorderSpace);
1187 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1188 allAppsBorderSpace);
1189 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1190
1191 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1192 allAppsBorderSpaceLandscape);
1193 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1194 allAppsBorderSpaceLandscape);
1195 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1196
1197 x = a.getFloat(
1198 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1199 allAppsBorderSpaceTwoPanelPortrait);
1200 y = a.getFloat(
1201 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1202 allAppsBorderSpaceTwoPanelPortrait);
1203 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1204
1205 x = a.getFloat(
1206 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1207 allAppsBorderSpaceTwoPanelLandscape);
1208 y = a.getFloat(
1209 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1210 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001211 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001212
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001213 iconSizes[INDEX_DEFAULT] =
1214 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1215 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001216 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001217 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001218 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001219 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001220 iconSizes[INDEX_DEFAULT]);
1221 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001222 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001223 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001224
Thales Limabb7d3882021-12-22 12:56:29 +00001225 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1226 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001227 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1228 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001229 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001230 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1231 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1232 allAppsIconSizes[INDEX_DEFAULT]);
1233 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1234 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1235 allAppsIconSizes[INDEX_DEFAULT]);
1236
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001237 textSizes[INDEX_DEFAULT] =
1238 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1239 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001240 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001241 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001242 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001243 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001244 textSizes[INDEX_DEFAULT]);
1245 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001246 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001247 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001248
Thales Limabb7d3882021-12-22 12:56:29 +00001249 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1250 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1251 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1252 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1253 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1254 allAppsIconTextSizes[INDEX_DEFAULT]);
1255 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1256 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1257 allAppsIconTextSizes[INDEX_DEFAULT]);
1258
Thales Lima83bedbf2021-10-05 17:47:39 +01001259 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1260 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001261 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1262 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1263 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001264 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001265 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001266 horizontalMargin[INDEX_DEFAULT]);
1267 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001268 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001269 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001270
Thales Limab8c05952022-05-23 16:58:38 +01001271 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1272 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001273 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001274 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1275 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1276 hotseatBarBottomSpace[INDEX_DEFAULT]);
1277 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1278 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1279 hotseatBarBottomSpace[INDEX_DEFAULT]);
1280 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1281 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1282 hotseatBarBottomSpace[INDEX_DEFAULT]);
1283
1284 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1285 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001286 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001287 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1288 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1289 hotseatQsbSpace[INDEX_DEFAULT]);
1290 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1291 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1292 hotseatQsbSpace[INDEX_DEFAULT]);
1293 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1294 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1295 hotseatQsbSpace[INDEX_DEFAULT]);
1296
Jon Miranda9c478b62023-03-23 21:38:49 -07001297 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1298 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1299 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1300 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1301 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1302 transientTaskbarIconSize[INDEX_DEFAULT]);
1303 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1304 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1305 transientTaskbarIconSize[INDEX_DEFAULT]);
1306 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1307 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001308 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001309
Jon Miranda04f05102023-04-04 12:16:31 -07001310 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1311 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1312 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1313 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1314 startAlignTaskbar[INDEX_DEFAULT]);
1315 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1316 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1317 startAlignTaskbar[INDEX_LANDSCAPE]);
1318 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1319 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1320 startAlignTaskbar[INDEX_DEFAULT]);
1321
Sunny Goyal415f1732018-11-29 10:33:47 -08001322 a.recycle();
1323 }
1324
1325 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001326 this(null);
1327 }
1328
1329 DisplayOption(GridOption grid) {
1330 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001331 minWidthDps = 0;
1332 minHeightDps = 0;
1333 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001334 for (int i = 0; i < COUNT_SIZES; i++) {
1335 iconSizes[i] = 0;
1336 textSizes[i] = 0;
1337 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001338 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001339 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001340 allAppsIconSizes[i] = 0;
1341 allAppsIconTextSizes[i] = 0;
1342 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001343 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001344 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001345 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001346 }
1347
1348 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001349 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001350 iconSizes[i] *= w;
1351 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001352 borderSpaces[i].x *= w;
1353 borderSpaces[i].y *= w;
1354 minCellSize[i].x *= w;
1355 minCellSize[i].y *= w;
1356 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001357 hotseatBarBottomSpace[i] *= w;
1358 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001359 allAppsCellSize[i].x *= w;
1360 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001361 allAppsIconSizes[i] *= w;
1362 allAppsIconTextSizes[i] *= w;
1363 allAppsBorderSpaces[i].x *= w;
1364 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001365 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001366 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001367
Sunny Goyal415f1732018-11-29 10:33:47 -08001368 return this;
1369 }
1370
1371 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001372 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001373 iconSizes[i] += p.iconSizes[i];
1374 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001375 borderSpaces[i].x += p.borderSpaces[i].x;
1376 borderSpaces[i].y += p.borderSpaces[i].y;
1377 minCellSize[i].x += p.minCellSize[i].x;
1378 minCellSize[i].y += p.minCellSize[i].y;
1379 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001380 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1381 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001382 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1383 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001384 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1385 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1386 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1387 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001388 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001389 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001390 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001391
Sunny Goyal415f1732018-11-29 10:33:47 -08001392 return this;
1393 }
1394 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001395}