blob: 090fe515f597d3e2d5eff3be8aa7aab567fdd437 [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
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070019import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE;
Stefan Andonian4c9612b2023-02-22 00:00:03 +000020import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070021import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030022import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070023import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070024import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000025import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070026import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070027import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080028import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070029
Sunny Goyalc6205602015-05-21 20:46:33 -070030import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070031import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080032import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070033import android.content.res.TypedArray;
34import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070035import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010036import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000037import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070038import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080039import android.text.TextUtils;
40import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070041import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010042import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080043import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070044import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080045import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070046
Thales Limab35faed2022-09-05 16:30:01 -030047import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000048import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030049import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070050import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000051import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010052import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070053
Thales Limaec5abba2023-04-05 16:33:50 +010054import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070055import com.android.launcher3.icons.DotRenderer;
Sunny Goyal68031ca2021-08-02 12:23:44 -070056import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010057import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070058import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070059import com.android.launcher3.util.DisplayController;
60import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070061import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080062import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070063import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070064import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070065import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080066import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070067
Sunny Goyal819e1932016-07-07 16:43:58 -070068import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70
71import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000072import java.lang.annotation.Retention;
73import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070074import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070075import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080076import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070077import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000078import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070079import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Sunny Goyal10fa0162024-04-21 00:13:35 -070081public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070084 // We do not need any synchronization for this variable as its only written on UI thread.
85 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070086 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070087
Alex Chau1c883d82021-12-01 18:43:10 +000088 @Retention(RetentionPolicy.SOURCE)
89 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Sebastian Franco9e4c99b2024-10-02 15:16:37 -070090 public @interface DeviceType {
91 }
Thales Limab8c05952022-05-23 16:58:38 +010092
Alex Chau1c883d82021-12-01 18:43:10 +000093 public static final int TYPE_PHONE = 0;
94 public static final int TYPE_MULTI_DISPLAY = 1;
95 public static final int TYPE_TABLET = 2;
96
Sunny Goyal53d7ee42015-05-22 12:25:45 -070097 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
98
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070099 // Constants that affects the interpolation curve between statically defined device profile
100 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800101 private static final float KNEARESTNEIGHBOR = 3;
102 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700103
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700104 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800105 private static final float WEIGHT_EFFICIENT = 100000f;
106
Thales Lima83bedbf2021-10-05 17:47:39 +0100107 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
108 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000109 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100110 static final int INDEX_DEFAULT = 0;
111 static final int INDEX_LANDSCAPE = 1;
112 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
113 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100114
Thales Limaec5abba2023-04-05 16:33:50 +0100115 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800116 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
117 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
118 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
119
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700120 /**
121 * Number of icons per row and column in the workspace.
122 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700123 public int numRows;
124 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000125 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700126
127 /**
128 * Number of icons per row and column in the folder.
129 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000130 public int[] numFolderRows;
131 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100132 public float[] iconSize;
133 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700134 public int iconBitmapSize;
135 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000136 public @DeviceType int deviceType;
Federico Baron56307d22024-11-06 18:48:48 +0000137 public Info displayInfo;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700138
Thales Lima83bedbf2021-10-05 17:47:39 +0100139 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100140
Thales Lima83bedbf2021-10-05 17:47:39 +0100141 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300142 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100143
Thales Limab35faed2022-09-05 16:30:01 -0300144 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100145
Thales Limad852d652023-01-17 14:01:13 +0000146 public @StyleRes int cellStyle;
147
Thales Lima83bedbf2021-10-05 17:47:39 +0100148 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500149
Thales Limab7ef5692022-03-10 10:32:36 +0000150 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000151 public float[] allAppsIconSize;
152 public float[] allAppsIconTextSize;
153 public PointF[] allAppsBorderSpaces;
154
Jon Miranda9c478b62023-03-23 21:38:49 -0700155 public float[] transientTaskbarIconSize;
156
Jon Miranda04f05102023-04-04 12:16:31 -0700157 public boolean[] startAlignTaskbar;
158
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700159 /**
160 * Number of icons inside the hotseat area.
161 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800162 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700163
164 /**
165 * Number of icons inside the hotseat area that is stored in the database. This is greater than
166 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
167 * sizes that share the same DB.
168 */
169 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700170
Thales Limab8c05952022-05-23 16:58:38 +0100171 public float[] hotseatBarBottomSpace;
172 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300173
Jon Miranda6f7e9702019-09-16 14:44:14 -0700174 /**
175 * Number of columns in the all apps list.
176 */
177 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300178 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700179 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000180 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700181
Jon Mirandae126d722021-02-25 10:45:20 -0500182 /**
183 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
184 */
185 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000186 @XmlRes
187 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100188 @XmlRes
189 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100190 @XmlRes
fbaronebc10c92024-09-03 12:51:41 -0700191 public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
192 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100193 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
194 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100195 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100196 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100197 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
198 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100199 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100200 @XmlRes
201 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000202 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100203 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000204 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100205 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000206 @XmlRes
207 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
208 @XmlRes
209 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
210 @XmlRes
211 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
212 @XmlRes
213 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500214
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700215
216 /**
217 * Fixed landscape mode is the landscape on the phones.
218 */
219 public boolean isFixedLandscapeMode = false;
220 private LauncherPrefChangeListener mLandscapeModePreferenceListener;
221
Tracy Zhou7df93d22020-01-27 13:44:06 -0800222 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800223 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700224 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100225 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700226
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000227 /**
228 * An immutable list of supported profiles.
229 */
230 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700231
Sunny Goyal6f866092016-03-17 17:04:15 -0700232 public Point defaultWallpaperSize;
233
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700234 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700235
Sunny Goyalf633ef52018-03-13 09:57:05 -0700236 @VisibleForTesting
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700237 public InvariantDeviceProfile() {
238 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700239
Sunny Goyalbbf01842015-10-08 07:41:15 -0700240 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700241 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700242 String gridName = getCurrentGridName(context);
243 String newGridName = initGrid(context, gridName);
244 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000245 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700246 }
247
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700248 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100249 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000250 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700251 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
252 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100253 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700254 }
255 });
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700256 if (Flags.oneGridSpecs()) {
257 mLandscapeModePreferenceListener = (String s) -> {
258 boolean newFixedLandscapeValue = FIXED_LANDSCAPE_MODE.get(context);
259 if (isFixedLandscapeMode != newFixedLandscapeValue) {
260 setFixedLandscape(context, newFixedLandscapeValue);
261 }
262 };
263 LauncherPrefs.INSTANCE.get(context).addListener(
264 mLandscapeModePreferenceListener,
265 FIXED_LANDSCAPE_MODE
266 );
267 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700268 }
269
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700270 /**
271 * This constructor should NOT have any monitors by design.
272 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800273 public InvariantDeviceProfile(Context context, String gridName) {
274 String newName = initGrid(context, gridName);
275 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000276 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800277 }
278 }
279
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800281 * This constructor should NOT have any monitors by design.
282 */
283 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700284 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100285 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700286 String gridName = getCurrentGridName(context);
287
288 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000289 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700290 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000292 defaultInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700293 getPredefinedDeviceProfiles(
294 context,
295 gridName,
296 defaultInfo,
297 /*allowDisabledGrid=*/false,
298 isFixedLandscapeMode
299 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000300 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700301
Alex Chau661f02d2022-06-07 14:03:43 +0100302 Context displayContext = context.createDisplayContext(display);
303 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700304 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700305 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000306 myInfo,
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700307 getPredefinedDeviceProfiles(
308 context,
309 gridName,
310 myInfo,
311 /*allowDisabledGrid=*/false,
312 isFixedLandscapeMode
313 ),
Alex Chau1c883d82021-12-01 18:43:10 +0000314 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700315
316 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
317 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100318 result.iconSizes[INDEX_DEFAULT] =
319 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
320 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700321 result.iconSizes[i] = Math.min(
322 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000323 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700324
Thales Lima83bedbf2021-10-05 17:47:39 +0100325 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
326 COUNT_SIZES);
327 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
328 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500329
Federico Baron56307d22024-11-06 18:48:48 +0000330 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800331 }
332
Sunny Goyal10fa0162024-04-21 00:13:35 -0700333 @Override
334 public void close() {
335 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700336 if (mLandscapeModePreferenceListener != null) {
337 LauncherPrefs.INSTANCE.executeIfCreated(
338 lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE)
339 );
340 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700341 }
342
Tracy Zhou42255d22020-03-13 00:38:11 -0700343 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000344 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700345 }
346
Sunny Goyaleff44f32019-01-09 17:29:49 -0800347 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700348 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700349
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700350 List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
351 context,
352 gridName,
353 displayInfo,
354 RestoreDbTask.isPending(context),
355 FIXED_LANDSCAPE_MODE.get(context)
356 );
fbaronebc10c92024-09-03 12:51:41 -0700357
358 // Filter out options that don't have the same number of columns as the grid
359 DeviceGridState deviceGridState = new DeviceGridState(context);
360 List<DisplayOption> allOptionsFilteredByColCount =
361 filterByColumnCount(allOptions, deviceGridState.getColumns());
362
Sunny Goyal19ff7282021-04-22 10:12:54 -0700363 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700364 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700365 ? new ArrayList<>(allOptions)
366 : new ArrayList<>(allOptionsFilteredByColCount),
Federico Baron56307d22024-11-06 18:48:48 +0000367 displayInfo.getDeviceType());
368 initGrid(context, displayInfo, displayOption);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700369 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800370 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700371
fbaronebc10c92024-09-03 12:51:41 -0700372 private List<DisplayOption> filterByColumnCount(
373 List<DisplayOption> allOptions, int numColumns) {
374 return allOptions.stream().filter(
375 option -> option.grid.numColumns == numColumns).toList();
376 }
377
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700378 /**
379 * @deprecated This is a temporary solution because on the backup and restore case we modify the
380 * IDP, this resets it. b/332974074
381 */
382 @Deprecated
383 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700384 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700385 }
386
Thales Limab67bfa72022-11-02 15:30:11 +0000387 @VisibleForTesting
388 public static String getDefaultGridName(Context context) {
389 return new InvariantDeviceProfile().initGrid(context, null);
390 }
391
Federico Baron56307d22024-11-06 18:48:48 +0000392 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700393 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700394 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000395 numRows = closestProfile.numRows;
396 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000397 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000398 dbFile = closestProfile.dbFile;
399 defaultLayoutId = closestProfile.defaultLayoutId;
400 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300401
Sunny Goyalae190ff2020-04-14 00:19:01 +0000402 numFolderRows = closestProfile.numFolderRows;
403 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300404 folderStyle = closestProfile.folderStyle;
405
Thales Limad852d652023-01-17 14:01:13 +0000406 cellStyle = closestProfile.cellStyle;
407
Jon Mirandae126d722021-02-25 10:45:20 -0500408 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400409 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100410 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbaronebc10c92024-09-03 12:51:41 -0700411 rowCountSpecsId = closestProfile.mRowCountSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100412 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100413 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100414 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100415 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100416 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100417 hotseatSpecsId = closestProfile.mHotseatSpecsId;
418 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000419 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
420 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
421 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
422 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300423 numAllAppsRowsForCellHeightCalculation =
424 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Federico Baron56307d22024-11-06 18:48:48 +0000425 this.deviceType = displayInfo.getDeviceType();
426 this.displayInfo = displayInfo;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000427
Vinit Nayakc7293172022-07-18 16:41:50 -0700428 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
429
Thales Lima83bedbf2021-10-05 17:47:39 +0100430 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100431 float maxIconSize = iconSize[0];
432 for (int i = 1; i < iconSize.length; i++) {
433 maxIconSize = Math.max(maxIconSize, iconSize[i]);
434 }
435 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000436 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
437
Thales Lima83bedbf2021-10-05 17:47:39 +0100438 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700439
Thales Lima83bedbf2021-10-05 17:47:39 +0100440 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100441
Thales Lima83bedbf2021-10-05 17:47:39 +0100442 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100443
Thales Limad90faab2021-09-21 17:18:47 +0100444 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100445
Sunny Goyal19ff7282021-04-22 10:12:54 -0700446 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000447 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700448 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100449 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
450 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700451
Thales Limae9273ea2023-01-26 12:33:52 +0000452 allAppsStyle = closestProfile.allAppsStyle;
453
Sunny Goyal19ff7282021-04-22 10:12:54 -0700454 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300455
Alex Chau1c883d82021-12-01 18:43:10 +0000456 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700457 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500458
Thales Limab7ef5692022-03-10 10:32:36 +0000459 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000460 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
461 allAppsIconSize = displayOption.allAppsIconSizes;
462 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000463
Thales Lima11af7bc2022-08-12 15:24:54 +0100464 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000465
Jon Miranda9c478b62023-03-23 21:38:49 -0700466 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
467
Jon Miranda04f05102023-04-04 12:16:31 -0700468 startAlignTaskbar = displayOption.startAlignTaskbar;
469
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700470 // Fixed Landscape mode
471 isFixedLandscapeMode = FIXED_LANDSCAPE_MODE.get(context) && Flags.oneGridSpecs();
472
Sunny Goyalae190ff2020-04-14 00:19:01 +0000473 // If the partner customization apk contains any grid overrides, apply them
474 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700475 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700476
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000477 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700478 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700479 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700480 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000481 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000482 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000483 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700484 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000485 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700486
Sunny Goyal19ff7282021-04-22 10:12:54 -0700487 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
488 int displayWidth = bounds.bounds.width();
489 int displayHeight = bounds.bounds.height();
490 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700491
Sunny Goyal19ff7282021-04-22 10:12:54 -0700492 // We need to ensure that there is enough extra space in the wallpaper
493 // for the intended parallax effects
494 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300495 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
496 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700497 ? 2
498 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
499 defaultWallpaperSize.x =
500 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700501 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000502 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700503
Thales Lima6a590062022-11-22 15:52:49 +0000504 int numMinShownHotseatIconsForTablet = supportedProfiles
505 .stream()
506 .filter(deviceProfile -> deviceProfile.isTablet)
507 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
508 .min()
509 .orElse(0);
510
511 supportedProfiles
512 .stream()
513 .filter(deviceProfile -> deviceProfile.isTablet)
514 .forEach(deviceProfile -> {
515 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
516 deviceProfile.recalculateHotseatWidthAndBorderSpace();
517 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700518 }
519
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700520 public void addOnChangeListener(OnIDPChangeListener listener) {
521 mChangeListeners.add(listener);
522 }
523
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800524 public void removeOnChangeListener(OnIDPChangeListener listener) {
525 mChangeListeners.remove(listener);
526 }
527
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700528 /**
529 * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid
530 * migration.
531 */
532 public void setCurrentGrid(Context context, String newGridName) {
533 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700534 MAIN_EXECUTOR.execute(() -> {
535 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
536 onConfigChanged(context.getApplicationContext());
537 Trace.endSection();
538 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800539 }
540
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700541 /**
542 * Updates the mounted mode, this triggers a new IDP, reloads the database and triggers a grid
543 * migration.
544 */
545 public void setFixedLandscape(Context context, boolean isFixedLandscape) {
546 this.isFixedLandscapeMode = isFixedLandscape;
547 if (isFixedLandscape) {
548 // When in isFixedLandscape there should only be one default grid to choose from
549 MAIN_EXECUTOR.execute(() -> {
550 Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
551 onConfigChanged(context.getApplicationContext());
552 Trace.endSection();
553 });
554 } else {
555 setCurrentGrid(context, LauncherPrefs.get(context).get(GRID_NAME));
556 }
557 }
558
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700559 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700560 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000561 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
562 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700563 }
564
Pat Manning24cec692023-10-13 10:36:57 +0000565 /** Updates IDP using the provided context. Notifies listeners of change. */
566 @VisibleForTesting
567 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700568 Object[] oldState = toModelState();
569
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700570 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700571 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700572 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700573
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700574 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700575 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700576 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700577 }
578 }
579
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700580 private static boolean firstGridFilter(GridOption gridOption, int deviceType,
581 boolean allowDisabledGrid, boolean isFixedLandscapeMode) {
582 return (gridOption.isEnabled(deviceType) || allowDisabledGrid)
583 && ((gridOption.mIsFixedLandscape == isFixedLandscapeMode)
584 && gridOption.filterByFlag(deviceType));
585 }
586
587 private static List<DisplayOption> getPredefinedDeviceProfiles(
588 Context context,
589 String gridName,
590 Info displayInfo,
591 boolean allowDisabledGrid,
592 boolean isFixedLandscapeMode
593 ) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800594 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100595
Alex Chau1c883d82021-12-01 18:43:10 +0000596 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700597 final int depth = parser.getDepth();
598 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700599 while (((type = parser.next()) != XmlPullParser.END_TAG ||
600 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800601 if ((type == XmlPullParser.START_TAG)
602 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000603 GridOption gridOption = new GridOption(
604 context, Xml.asAttributeSet(parser), displayInfo);
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700605 if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid,
606 isFixedLandscapeMode)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100607 final int displayDepth = parser.getDepth();
608 while (((type = parser.next()) != XmlPullParser.END_TAG
609 || parser.getDepth() > displayDepth)
610 && type != XmlPullParser.END_DOCUMENT) {
611 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
612 parser.getName())) {
613 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100614 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100615 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800616 }
617 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700618 }
619 }
sfufa@google.comde013292021-09-21 18:22:44 -0700620 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700621 throw new RuntimeException(e);
622 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000623 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800624 if (!TextUtils.isEmpty(gridName)) {
625 for (DisplayOption option : profiles) {
Federico Baron56307d22024-11-06 18:48:48 +0000626 if (gridName.equals(option.grid.name) && (option.grid.isEnabled(
627 displayInfo.getDeviceType()) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000628 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800629 }
630 }
631 }
fbaronebc10c92024-09-03 12:51:41 -0700632 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
633 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000634 for (DisplayOption option : profiles) {
635 if (option.canBeDefault) {
636 filteredProfiles.add(option);
637 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800638 }
fbaronebc10c92024-09-03 12:51:41 -0700639 } else if (filteredProfiles.isEmpty()) {
640 // In this case we had a grid selected but we couldn't find it.
641 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800642 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000643 if (filteredProfiles.isEmpty()) {
644 throw new RuntimeException("No display option with canBeDefault=true");
645 }
646 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700647 }
648
Thales Lima7ec83822021-08-05 13:32:10 +0100649 /**
fbaronebc10c92024-09-03 12:51:41 -0700650 * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct
651 * row count for this GridOption.
652 *
Federico Baron56307d22024-11-06 18:48:48 +0000653 * @return the result of {@link #findBestRowCount(List, Info)}.
fbaronebc10c92024-09-03 12:51:41 -0700654 */
655 public static NumRows getRowCount(ResourceHelper resourceHelper, Context context,
Federico Baron56307d22024-11-06 18:48:48 +0000656 Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700657 ArrayList<NumRows> rowCounts = new ArrayList<>();
658
659 try (XmlResourceParser parser = resourceHelper.getXml()) {
660 final int depth = parser.getDepth();
661 int type;
662 while (((type = parser.next()) != XmlPullParser.END_TAG
663 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
664 if ((type == XmlPullParser.START_TAG)
665 && "NumRows".equals(parser.getName())) {
666 rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser)));
667 }
668 }
669 } catch (IOException | XmlPullParserException e) {
670 throw new RuntimeException(e);
671 }
672
Federico Baron56307d22024-11-06 18:48:48 +0000673 return findBestRowCount(rowCounts, displayInfo);
fbaronebc10c92024-09-03 12:51:41 -0700674 }
675
676 /**
677 * @return the biggest row count that fits the display dimensions spec using NumRows to
678 * determine that. If no best row count is found, return -1.
679 */
Federico Baron56307d22024-11-06 18:48:48 +0000680 public static NumRows findBestRowCount(List<NumRows> list, Info displayInfo) {
fbaronebc10c92024-09-03 12:51:41 -0700681 int minWidthPx = Integer.MAX_VALUE;
682 int minHeightPx = Integer.MAX_VALUE;
683 for (WindowBounds bounds : displayInfo.supportedBounds) {
684 boolean isTablet = displayInfo.isTablet(bounds);
Federico Baron56307d22024-11-06 18:48:48 +0000685 if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) {
fbaronebc10c92024-09-03 12:51:41 -0700686 // For split displays, take half width per page
687 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
688 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
689 } else if (!isTablet && bounds.isLandscape()) {
690 // We will use transposed layout in this case
691 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
692 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
693 } else {
694 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
695 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
696 }
697 }
698
699 NumRows selectedRow = null;
700 for (NumRows item: list) {
701 if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) {
702 if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) {
703 selectedRow = item;
704 }
705 }
706 }
707 if (selectedRow != null) {
708 return selectedRow;
709 }
710 return null;
711 }
712
713 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000714 * Returns the GridOption associated to the given file name or null if the fileName is not
715 * supported.
716 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
717 */
718 public GridOption getGridOptionFromFileName(Context context, String fileName) {
719 return parseAllGridOptions(context).stream()
720 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
721 .findFirst()
722 .orElse(null);
723 }
724
725 /**
726 * Returns the name of the given size on the current device or empty string if the size is not
727 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
728 * (Note: the name of the grid can be different for the same grid size depending of
729 * the values of the InvariantDeviceProfile)
Sebastián Francoad46eb72024-03-11 20:56:57 +0000730 */
731 public String getGridNameFromSize(Context context, Point size) {
732 return parseAllGridOptions(context).stream()
733 .filter(gridOption -> gridOption.numColumns == size.x
734 && gridOption.numRows == size.y)
735 .map(gridOption -> gridOption.name)
736 .findFirst()
737 .orElse("");
738 }
739
740 /**
741 * Returns the grid option for the given gridName on the current device (Note: the gridOption
742 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
743 */
744 public GridOption getGridOptionFromName(Context context, String gridName) {
745 return parseAllGridOptions(context).stream()
746 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
747 .findFirst()
748 .orElse(null);
749 }
750
751 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100752 * @return all the grid options that can be shown on the device
753 */
754 public List<GridOption> parseAllGridOptions(Context context) {
Federico Baron56307d22024-11-06 18:48:48 +0000755 return parseAllDefinedGridOptions(context, displayInfo)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700756 .stream()
757 .filter(go -> go.isEnabled(deviceType))
Sebastian Franco9e4c99b2024-10-02 15:16:37 -0700758 // if in fixedLandscape, then only show fixed landscape grids
759 .filter(go -> go.mIsFixedLandscape == isFixedLandscapeMode)
fbaron49f7df02024-11-05 16:15:19 -0800760 .filter(go -> go.filterByFlag(deviceType))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700761 .collect(Collectors.toList());
762 }
763
764 /**
765 * @return all the grid options that can be shown on the device
766 */
Federico Baron56307d22024-11-06 18:48:48 +0000767 public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) {
Thales Lima7ec83822021-08-05 13:32:10 +0100768 List<GridOption> result = new ArrayList<>();
Alex Chau1c883d82021-12-01 18:43:10 +0000769 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100770 final int depth = parser.getDepth();
771 int type;
772 while (((type = parser.next()) != XmlPullParser.END_TAG
773 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
774 if ((type == XmlPullParser.START_TAG)
775 && GridOption.TAG_NAME.equals(parser.getName())) {
Federico Baron56307d22024-11-06 18:48:48 +0000776 result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo));
Thales Lima7ec83822021-08-05 13:32:10 +0100777 }
778 }
779 } catch (IOException | XmlPullParserException e) {
780 Log.e(TAG, "Error parsing device profile", e);
781 return Collections.emptyList();
782 }
783 return result;
784 }
785
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700786 private int getLauncherIconDensity(int requiredSize) {
787 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700788 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700789 DisplayMetrics.DENSITY_LOW,
790 DisplayMetrics.DENSITY_MEDIUM,
791 DisplayMetrics.DENSITY_TV,
792 DisplayMetrics.DENSITY_HIGH,
793 DisplayMetrics.DENSITY_XHIGH,
794 DisplayMetrics.DENSITY_XXHIGH,
795 DisplayMetrics.DENSITY_XXXHIGH
796 };
797
798 int density = DisplayMetrics.DENSITY_XXXHIGH;
799 for (int i = densityBuckets.length - 1; i >= 0; i--) {
800 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
801 / DisplayMetrics.DENSITY_DEFAULT;
802 if (expectedSize >= requiredSize) {
803 density = densityBuckets[i];
804 }
805 }
806
807 return density;
808 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700809
Adam Cohen2e6da152015-05-06 11:42:25 -0700810 /**
811 * Apply any Partner customization grid overrides.
812 *
813 * Currently we support: all apps row / column count.
814 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700815 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
816 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800817 if (p == null) {
818 return;
819 }
820 try {
821 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
822 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
823 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
824
825 if (numRows > 0 && numColumns > 0) {
826 this.numRows = numRows;
827 this.numColumns = numColumns;
828 }
829 if (iconSizePx > 0) {
830 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
831 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
832 }
833 } catch (Resources.NotFoundException ex) {
834 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700835 }
836 }
837
Sunny Goyal415f1732018-11-29 10:33:47 -0800838 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700839 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700840 }
841
Sunny Goyal19ff7282021-04-22 10:12:54 -0700842 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700843 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844 int minWidthPx = Integer.MAX_VALUE;
845 int minHeightPx = Integer.MAX_VALUE;
846 for (WindowBounds bounds : displayInfo.supportedBounds) {
847 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000848 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700849 // For split displays, take half width per page
850 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
851 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700852
Sunny Goyal19ff7282021-04-22 10:12:54 -0700853 } else if (!isTablet && bounds.isLandscape()) {
854 // We will use transposed layout in this case
855 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
856 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
857 } else {
858 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
859 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
860 }
861 }
862
Thales Lima425f6822022-05-10 13:44:58 -0300863 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
864 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700865
866 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700867 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700868 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
869 dist(width, height, b.minWidthDps, b.minHeightDps)));
870
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700871 DisplayOption closestPoint = points.get(0);
872 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700873 float weights = 0;
874
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700875 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
876 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700877 }
878
879 DisplayOption out = new DisplayOption(closestOption);
880 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700881 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700882 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
883 weights += w;
884 out.add(new DisplayOption().add(p).multiply(w));
885 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700886 out.multiply(1.0f / weights);
887
Thales Lima6e0005a2021-10-27 15:53:41 +0100888 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700889 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100890 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
891 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700892 }
893
894 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700895 }
896
Sunny Goyal27835952017-01-13 12:15:53 -0800897 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000898 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
899 Rect bounds = windowManagerProxy.getCurrentBounds(context);
900 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700901
Alex Chauc09a98a2023-11-14 12:51:42 +0000902 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400903 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700904
Sunny Goyal187b16c2022-03-01 16:53:23 -0800905 /**
906 * Returns the device profile matching the provided screen configuration
907 */
908 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700909 DeviceProfile bestMatch = supportedProfiles.get(0);
910 float minDiff = Float.MAX_VALUE;
911
912 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400913 float diff = Math.abs(profile.widthPx - screenWidth)
914 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700915 if (diff < minDiff) {
916 minDiff = diff;
917 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800918 } else if (diff == minDiff && profile.rotationHint == rotation) {
919 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700920 }
921 }
922 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800923 }
924
Sunny Goyal415f1732018-11-29 10:33:47 -0800925 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700926 float d = dist(x0, y0, x1, y1);
927 if (Float.compare(d, 0f) == 0) {
928 return Float.POSITIVE_INFINITY;
929 }
930 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
931 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700932
933 /**
934 * As a ratio of screen height, the total distance we want the parallax effect to span
935 * horizontally
936 */
937 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
938 float aspectRatio = width / (float) height;
939
940 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
941 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
942 // We will use these two data points to extrapolate how much the wallpaper parallax effect
943 // to span (ie travel) at any aspect ratio:
944
sfufa@google.comde013292021-09-21 18:22:44 -0700945 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
946 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700947 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
948 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
949
950 // To find out the desired width at different aspect ratios, we use the following two
951 // formulas, where the coefficient on x is the aspect ratio (width/height):
952 // (16/10)x + y = 1.5
953 // (10/16)x + y = 1.2
954 // We solve for x and y and end up with a final formula:
955 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700956 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
957 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700958 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
959 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
960 return x * aspectRatio + y;
961 }
962
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700963 public interface OnIDPChangeListener {
964
Sunny Goyalb47172b2021-05-03 19:59:51 -0700965 /**
966 * Called when the device provide changes
967 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700968 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700969 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800970
971
Sunny Goyaleff44f32019-01-09 17:29:49 -0800972 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800973
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800974 public static final String TAG_NAME = "grid-option";
975
Alex Chau1c883d82021-12-01 18:43:10 +0000976 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
977 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
978 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
979 private static final int DEVICE_CATEGORY_ALL =
980 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
981
Thales Lima11af7bc2022-08-12 15:24:54 +0100982 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
983 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
984 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
985 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
986 private static final int DONT_INLINE_QSB = 0;
987
Sunny Goyaleff44f32019-01-09 17:29:49 -0800988 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700989 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800990 public final int numRows;
991 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000992 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700993 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800994
Thales Lima1faa4ed2023-12-01 16:48:19 +0000995 private final int[] numFolderRows = new int[COUNT_SIZES];
996 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300997 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000998 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800999
Thales Limae9273ea2023-01-26 12:33:52 +00001000 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001001 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -03001002 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001003 private final int numDatabaseAllAppsColumns;
1004 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -07001005 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +01001006
Thales Lima11af7bc2022-08-12 15:24:54 +01001007 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
1008
Thales Limab35faed2022-09-05 16:30:01 -03001009 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -08001010 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +00001011
Sunny Goyal415f1732018-11-29 10:33:47 -08001012 private final int defaultLayoutId;
1013 private final int demoModeLayoutId;
1014
Jon Mirandae126d722021-02-25 10:45:20 -05001015 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -08001016 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001017 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +01001018 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001019 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +01001020 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001021 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001022 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001023 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +01001024 private final int mHotseatSpecsId;
1025 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001026 private final int mWorkspaceCellSpecsId;
1027 private final int mWorkspaceCellSpecsTwoPanelId;
1028 private final int mAllAppsCellSpecsId;
1029 private final int mAllAppsCellSpecsTwoPanelId;
fbaronebc10c92024-09-03 12:51:41 -07001030 private final int mRowCountSpecsId;
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001031 private final boolean mIsFixedLandscape;
Jon Mirandae126d722021-02-25 10:45:20 -05001032
Federico Baron56307d22024-11-06 18:48:48 +00001033 public GridOption(Context context, AttributeSet attrs, Info displayInfo) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001034 TypedArray a = context.obtainStyledAttributes(
1035 attrs, R.styleable.GridDisplayOption);
1036 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -07001037 title = a.getString(R.styleable.GridDisplayOption_title);
1038 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
1039 DEVICE_CATEGORY_ALL);
1040 mRowCountSpecsId = a.getResourceId(
1041 R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -08001042 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbaronebc10c92024-09-03 12:51:41 -07001043 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
1044 ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
Federico Baron56307d22024-11-06 18:48:48 +00001045 NumRows numR = getRowCount(resourceHelper, context, displayInfo);
fbaronebc10c92024-09-03 12:51:41 -07001046 numRows = numR.mNumRowsNew;
1047 dbFile = numR.mDbFile;
1048 } else {
1049 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
1050 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
1051 }
1052
Sunny Goyal415f1732018-11-29 10:33:47 -08001053 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001054 numSearchContainerColumns = a.getInt(
1055 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Alex Chau766cd2b2022-07-06 17:15:21 +01001056 defaultLayoutId = a.getResourceId(
1057 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -08001058 demoModeLayoutId = a.getResourceId(
1059 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001060
Thales Limae9273ea2023-01-26 12:33:52 +00001061 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
1062 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001063 numAllAppsColumns = a.getInt(
1064 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
1065 numDatabaseAllAppsColumns = a.getInt(
1066 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
1067
1068 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001069 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001070 numDatabaseHotseatIcons = a.getInt(
1071 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +01001072
Vinit Nayakc7293172022-07-18 16:41:50 -07001073 inlineNavButtonsEndSpacing =
1074 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +01001075 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -03001076
Thales Lima1faa4ed2023-12-01 16:48:19 +00001077 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001078 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001079 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001080 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001081
Thales Lima1faa4ed2023-12-01 16:48:19 +00001082 if (FeatureFlags.enableResponsiveWorkspace()) {
1083 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1084 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1085 numFolderRows[INDEX_DEFAULT]);
1086 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1087 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1088 numFolderColumns[INDEX_DEFAULT]);
1089 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1090 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1091 numFolderRows[INDEX_DEFAULT]);
1092 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1093 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1094 numFolderColumns[INDEX_DEFAULT]);
1095 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1096 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1097 numFolderRows[INDEX_DEFAULT]);
1098 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1099 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1100 numFolderColumns[INDEX_DEFAULT]);
1101 } else {
1102 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1103 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1104 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1105 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1106 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1107 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1108 }
1109
Thales Limab35faed2022-09-05 16:30:01 -03001110 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1111 INVALID_RESOURCE_HANDLE);
1112
Thales Limad852d652023-01-17 14:01:13 +00001113 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1114 R.style.CellStyleDefault);
1115
Jon Mirandae126d722021-02-25 10:45:20 -05001116 isScalable = a.getBoolean(
1117 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001118 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001119 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001120
Thales Limaca31b612023-09-14 14:25:26 +01001121 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001122 mWorkspaceSpecsId = a.getResourceId(
1123 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001124 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1125 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001126 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001127 mAllAppsSpecsId = a.getResourceId(
1128 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001129 mAllAppsSpecsTwoPanelId = a.getResourceId(
1130 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001131 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001132 mFolderSpecsId = a.getResourceId(
1133 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001134 mFolderSpecsTwoPanelId = a.getResourceId(
1135 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001136 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001137 mHotseatSpecsId = a.getResourceId(
1138 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1139 mHotseatSpecsTwoPanelId = a.getResourceId(
1140 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001141 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001142 mWorkspaceCellSpecsId = a.getResourceId(
1143 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1144 INVALID_RESOURCE_HANDLE);
1145 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1146 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001147 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001148 mAllAppsCellSpecsId = a.getResourceId(
1149 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1150 INVALID_RESOURCE_HANDLE);
1151 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1152 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001153 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001154 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1155 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1156 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001157 } else {
1158 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001159 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001160 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001161 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001162 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001163 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001164 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1165 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001166 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1167 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1168 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1169 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001170 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001171 }
1172
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001173 mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false);
1174
Thales Lima11af7bc2022-08-12 15:24:54 +01001175 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1176 DONT_INLINE_QSB);
1177 inlineQsb[INDEX_DEFAULT] =
1178 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1179 inlineQsb[INDEX_LANDSCAPE] =
1180 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1181 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1182 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1183 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1184 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1185 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1186 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1187
Sunny Goyal415f1732018-11-29 10:33:47 -08001188 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001189 }
1190
1191 public boolean isEnabled(@DeviceType int deviceType) {
1192 switch (deviceType) {
1193 case TYPE_PHONE:
1194 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1195 case TYPE_TABLET:
1196 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1197 case TYPE_MULTI_DISPLAY:
1198 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1199 == DEVICE_CATEGORY_MULTI_DISPLAY;
1200 default:
1201 return false;
1202 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001203 }
fbaronebc10c92024-09-03 12:51:41 -07001204
1205 public boolean isNewGridOption() {
Sebastian Franco9e4c99b2024-10-02 15:16:37 -07001206 Log.d("HHHH", "GRID = " + mIsFixedLandscape);
1207 return mRowCountSpecsId != INVALID_RESOURCE_HANDLE || mIsFixedLandscape;
fbaronebc10c92024-09-03 12:51:41 -07001208 }
fbaron49f7df02024-11-05 16:15:19 -08001209
1210 public boolean filterByFlag(int deviceType) {
1211 if (deviceType == TYPE_TABLET) {
1212 return Flags.oneGridRotationHandling() == mIsDualGrid;
1213 }
1214 return Flags.oneGridSpecs() == isNewGridOption();
1215 }
fbaronebc10c92024-09-03 12:51:41 -07001216 }
1217
1218 public static final class NumRows {
1219 final int mNumRowsNew;
1220 final float mMinDeviceWidthPx;
1221 final float mMinDeviceHeightPx;
1222 final String mDbFile;
1223
1224 NumRows(Context context, AttributeSet attrs) {
1225 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows);
1226
1227 mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0);
1228 mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0);
1229 mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0);
1230 mDbFile = a.getString(R.styleable.NumRows_dbFile);
1231
1232 a.recycle();
1233 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001234 }
1235
Sunny Goyal19ff7282021-04-22 10:12:54 -07001236 @VisibleForTesting
1237 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001238 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001239
Sunny Goyal415f1732018-11-29 10:33:47 -08001240 private final float minWidthDps;
1241 private final float minHeightDps;
1242 private final boolean canBeDefault;
1243
Thales Lima83bedbf2021-10-05 17:47:39 +01001244 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001245
Thales Lima78d00ad2021-09-30 11:29:06 +01001246 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001247 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001248 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1249 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001250
Thales Lima78d00ad2021-09-30 11:29:06 +01001251 private final float[] iconSizes = new float[COUNT_SIZES];
1252 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001253
Thales Limab7ef5692022-03-10 10:32:36 +00001254 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001255 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1256 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1257 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1258
Jon Miranda9c478b62023-03-23 21:38:49 -07001259 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1260
Jon Miranda04f05102023-04-04 12:16:31 -07001261 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1262
Thales Lima1de4d552021-10-13 16:13:25 +01001263 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001264 this.grid = grid;
1265
Jon Miranda9c478b62023-03-23 21:38:49 -07001266 Resources res = context.getResources();
1267
Thales Lima1de4d552021-10-13 16:13:25 +01001268 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001269
Sunny Goyal415f1732018-11-29 10:33:47 -08001270 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1271 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001272
Thales Lima1de4d552021-10-13 16:13:25 +01001273 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001274
Thales Lima83bedbf2021-10-05 17:47:39 +01001275 float x;
1276 float y;
1277
Thales Lima85c942f2021-12-31 13:04:20 +00001278 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1279 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001280 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001281
1282 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1283 minCellSize[INDEX_DEFAULT].x);
1284 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1285 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001286 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001287
Thales Lima85c942f2021-12-31 13:04:20 +00001288 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001289 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001290 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001291 minCellSize[INDEX_DEFAULT].y);
1292 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1293
Thales Lima85c942f2021-12-31 13:04:20 +00001294 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001295 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001296 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001297 minCellSize[INDEX_DEFAULT].y);
1298 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001299
Thales Lima85c942f2021-12-31 13:04:20 +00001300 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001301 float borderSpaceLandscape = a.getFloat(
1302 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001303 float borderSpaceTwoPanelPortrait = a.getFloat(
1304 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1305 float borderSpaceTwoPanelLandscape = a.getFloat(
1306 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001307
Thales Lima85c942f2021-12-31 13:04:20 +00001308 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1309 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001310 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001311
1312 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1313 borderSpaceLandscape);
1314 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1315 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001316 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1317
1318 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001319 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1320 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001321 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001322 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1323 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001324 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1325
1326 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001327 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1328 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001329 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001330 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1331 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001332 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1333
Thales Limab7ef5692022-03-10 10:32:36 +00001334 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1335 minCellSize[INDEX_DEFAULT].x);
1336 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1337 minCellSize[INDEX_DEFAULT].y);
1338 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1339
1340 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1341 allAppsCellSize[INDEX_DEFAULT].x);
1342 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1343 allAppsCellSize[INDEX_DEFAULT].y);
1344 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1345
1346 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1347 allAppsCellSize[INDEX_DEFAULT].x);
1348 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1349 allAppsCellSize[INDEX_DEFAULT].y);
1350 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1351
1352 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1353 allAppsCellSize[INDEX_DEFAULT].x);
1354 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1355 allAppsCellSize[INDEX_DEFAULT].y);
1356 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1357
Thales Lima080d8902022-03-28 15:30:29 +01001358 float allAppsBorderSpace = a.getFloat(
1359 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1360 float allAppsBorderSpaceLandscape = a.getFloat(
1361 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1362 allAppsBorderSpace);
1363 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001364 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001365 allAppsBorderSpace);
1366 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001367 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001368 allAppsBorderSpace);
1369
1370 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1371 allAppsBorderSpace);
1372 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1373 allAppsBorderSpace);
1374 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1375
1376 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1377 allAppsBorderSpaceLandscape);
1378 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1379 allAppsBorderSpaceLandscape);
1380 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1381
1382 x = a.getFloat(
1383 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1384 allAppsBorderSpaceTwoPanelPortrait);
1385 y = a.getFloat(
1386 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1387 allAppsBorderSpaceTwoPanelPortrait);
1388 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1389
1390 x = a.getFloat(
1391 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1392 allAppsBorderSpaceTwoPanelLandscape);
1393 y = a.getFloat(
1394 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1395 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001396 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001397
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001398 iconSizes[INDEX_DEFAULT] =
1399 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1400 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001401 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001402 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001403 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001404 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001405 iconSizes[INDEX_DEFAULT]);
1406 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001407 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001408 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001409
Thales Limabb7d3882021-12-22 12:56:29 +00001410 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1411 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001412 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1413 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001414 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001415 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1416 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1417 allAppsIconSizes[INDEX_DEFAULT]);
1418 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1419 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1420 allAppsIconSizes[INDEX_DEFAULT]);
1421
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001422 textSizes[INDEX_DEFAULT] =
1423 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1424 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001425 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001426 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001427 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001428 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001429 textSizes[INDEX_DEFAULT]);
1430 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001431 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001432 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001433
Thales Limabb7d3882021-12-22 12:56:29 +00001434 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1435 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1436 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1437 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1438 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1439 allAppsIconTextSizes[INDEX_DEFAULT]);
1440 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1441 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1442 allAppsIconTextSizes[INDEX_DEFAULT]);
1443
Thales Lima83bedbf2021-10-05 17:47:39 +01001444 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1445 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001446 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1447 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1448 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001449 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001450 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001451 horizontalMargin[INDEX_DEFAULT]);
1452 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001453 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001454 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001455
Thales Limab8c05952022-05-23 16:58:38 +01001456 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1457 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001458 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001459 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1460 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1461 hotseatBarBottomSpace[INDEX_DEFAULT]);
1462 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1463 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1464 hotseatBarBottomSpace[INDEX_DEFAULT]);
1465 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1466 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1467 hotseatBarBottomSpace[INDEX_DEFAULT]);
1468
1469 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1470 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001471 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001472 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1473 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1474 hotseatQsbSpace[INDEX_DEFAULT]);
1475 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1476 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1477 hotseatQsbSpace[INDEX_DEFAULT]);
1478 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1479 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1480 hotseatQsbSpace[INDEX_DEFAULT]);
1481
Jon Miranda9c478b62023-03-23 21:38:49 -07001482 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1483 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1484 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1485 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1486 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1487 transientTaskbarIconSize[INDEX_DEFAULT]);
1488 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1489 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1490 transientTaskbarIconSize[INDEX_DEFAULT]);
1491 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1492 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001493 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001494
Jon Miranda04f05102023-04-04 12:16:31 -07001495 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1496 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1497 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1498 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1499 startAlignTaskbar[INDEX_DEFAULT]);
1500 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1501 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1502 startAlignTaskbar[INDEX_LANDSCAPE]);
1503 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1504 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1505 startAlignTaskbar[INDEX_DEFAULT]);
1506
Sunny Goyal415f1732018-11-29 10:33:47 -08001507 a.recycle();
1508 }
1509
1510 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001511 this(null);
1512 }
1513
1514 DisplayOption(GridOption grid) {
1515 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001516 minWidthDps = 0;
1517 minHeightDps = 0;
1518 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001519 for (int i = 0; i < COUNT_SIZES; i++) {
1520 iconSizes[i] = 0;
1521 textSizes[i] = 0;
1522 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001523 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001524 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001525 allAppsIconSizes[i] = 0;
1526 allAppsIconTextSizes[i] = 0;
1527 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001528 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001529 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001530 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001531 }
1532
1533 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001534 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001535 iconSizes[i] *= w;
1536 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001537 borderSpaces[i].x *= w;
1538 borderSpaces[i].y *= w;
1539 minCellSize[i].x *= w;
1540 minCellSize[i].y *= w;
1541 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001542 hotseatBarBottomSpace[i] *= w;
1543 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001544 allAppsCellSize[i].x *= w;
1545 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001546 allAppsIconSizes[i] *= w;
1547 allAppsIconTextSizes[i] *= w;
1548 allAppsBorderSpaces[i].x *= w;
1549 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001550 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001551 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001552
Sunny Goyal415f1732018-11-29 10:33:47 -08001553 return this;
1554 }
1555
1556 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001557 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001558 iconSizes[i] += p.iconSizes[i];
1559 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001560 borderSpaces[i].x += p.borderSpaces[i].x;
1561 borderSpaces[i].y += p.borderSpaces[i].y;
1562 minCellSize[i].x += p.minCellSize[i].x;
1563 minCellSize[i].y += p.minCellSize[i].y;
1564 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001565 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1566 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001567 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1568 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001569 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1570 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1571 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1572 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001573 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001574 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001575 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001576
Sunny Goyal415f1732018-11-29 10:33:47 -08001577 return this;
1578 }
1579 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001580}