blob: 7112a1bfb1c29587a06cf66cf312bd073b12756a [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
Thales Lima1de4d552021-10-13 16:13:25 +01002 * Copyright (C) 2021 The Android Open Source Project
Adam Cohen2e6da152015-05-06 11:42:25 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Stefan Andonian4c9612b2023-02-22 00:00:03 +000019import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070020import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030021import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070023import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000024import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070025import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070026import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080027import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070028
Sunny Goyalc6205602015-05-21 20:46:33 -070029import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070030import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000036import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070037import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080038import android.text.TextUtils;
39import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070040import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010041import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080042import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070043import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080044import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070045
Thales Limab35faed2022-09-05 16:30:01 -030046import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000047import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030048import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070049import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000050import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010051import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070052
Thales Limaec5abba2023-04-05 16:33:50 +010053import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070054import com.android.launcher3.icons.DotRenderer;
Sunny Goyal68031ca2021-08-02 12:23:44 -070055import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010056import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070057import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070058import com.android.launcher3.util.DisplayController;
59import com.android.launcher3.util.DisplayController.Info;
Sunny Goyald0e360a2018-06-29 14:40:18 -070060import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080061import com.android.launcher3.util.Partner;
fbaronebc10c92024-09-03 12:51:41 -070062import com.android.launcher3.util.ResourceHelper;
Sunny Goyal10fa0162024-04-21 00:13:35 -070063import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070064import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080065import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070066
Sunny Goyal819e1932016-07-07 16:43:58 -070067import org.xmlpull.v1.XmlPullParser;
68import org.xmlpull.v1.XmlPullParserException;
69
70import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000071import java.lang.annotation.Retention;
72import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070073import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070074import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080075import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070076import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000077import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070078import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Sunny Goyal10fa0162024-04-21 00:13:35 -070080public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070081
Hyunyoung Songc55a3502018-12-04 15:43:16 -080082 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070083 // We do not need any synchronization for this variable as its only written on UI thread.
84 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070085 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070086
Alex Chau1c883d82021-12-01 18:43:10 +000087 @Retention(RetentionPolicy.SOURCE)
88 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010089 public @interface DeviceType {}
90
Alex Chau1c883d82021-12-01 18:43:10 +000091 public static final int TYPE_PHONE = 0;
92 public static final int TYPE_MULTI_DISPLAY = 1;
93 public static final int TYPE_TABLET = 2;
94
Sunny Goyal53d7ee42015-05-22 12:25:45 -070095 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
96
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070097 // Constants that affects the interpolation curve between statically defined device profile
98 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080099 private static final float KNEARESTNEIGHBOR = 3;
100 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700101
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700102 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800103 private static final float WEIGHT_EFFICIENT = 100000f;
104
Thales Lima83bedbf2021-10-05 17:47:39 +0100105 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
106 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000107 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100108 static final int INDEX_DEFAULT = 0;
109 static final int INDEX_LANDSCAPE = 1;
110 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
111 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100112
Thales Limaec5abba2023-04-05 16:33:50 +0100113 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800114 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
115 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
116 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
117
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700118 /**
119 * Number of icons per row and column in the workspace.
120 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700121 public int numRows;
122 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000123 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700124
125 /**
126 * Number of icons per row and column in the folder.
127 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000128 public int[] numFolderRows;
129 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100130 public float[] iconSize;
131 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700132 public int iconBitmapSize;
133 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000134 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700135
Thales Lima83bedbf2021-10-05 17:47:39 +0100136 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100137
Thales Lima83bedbf2021-10-05 17:47:39 +0100138 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300139 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100140
Thales Limab35faed2022-09-05 16:30:01 -0300141 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100142
Thales Limad852d652023-01-17 14:01:13 +0000143 public @StyleRes int cellStyle;
144
Thales Lima83bedbf2021-10-05 17:47:39 +0100145 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500146
Thales Limab7ef5692022-03-10 10:32:36 +0000147 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000148 public float[] allAppsIconSize;
149 public float[] allAppsIconTextSize;
150 public PointF[] allAppsBorderSpaces;
151
Jon Miranda9c478b62023-03-23 21:38:49 -0700152 public float[] transientTaskbarIconSize;
153
Jon Miranda04f05102023-04-04 12:16:31 -0700154 public boolean[] startAlignTaskbar;
155
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700156 /**
157 * Number of icons inside the hotseat area.
158 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800159 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700160
161 /**
162 * Number of icons inside the hotseat area that is stored in the database. This is greater than
163 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
164 * sizes that share the same DB.
165 */
166 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700167
Thales Limab8c05952022-05-23 16:58:38 +0100168 public float[] hotseatBarBottomSpace;
169 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300170
Jon Miranda6f7e9702019-09-16 14:44:14 -0700171 /**
172 * Number of columns in the all apps list.
173 */
174 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300175 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700176 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000177 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700178
Jon Mirandae126d722021-02-25 10:45:20 -0500179 /**
180 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
181 */
182 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000183 @XmlRes
184 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100185 @XmlRes
186 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100187 @XmlRes
fbaronebc10c92024-09-03 12:51:41 -0700188 public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
189 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100190 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
191 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100192 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100193 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100194 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
195 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100196 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100197 @XmlRes
198 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000199 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100200 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000201 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100202 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000203 @XmlRes
204 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
205 @XmlRes
206 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
207 @XmlRes
208 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
209 @XmlRes
210 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500211
Tracy Zhou7df93d22020-01-27 13:44:06 -0800212 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800213 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700214 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100215 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700216
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000217 /**
218 * An immutable list of supported profiles.
219 */
220 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700221
Sunny Goyal6f866092016-03-17 17:04:15 -0700222 public Point defaultWallpaperSize;
223
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700224 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700225
Sunny Goyalf633ef52018-03-13 09:57:05 -0700226 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800227 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700228
Sunny Goyalbbf01842015-10-08 07:41:15 -0700229 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700230 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700231 String gridName = getCurrentGridName(context);
232 String newGridName = initGrid(context, gridName);
233 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000234 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700235 }
236
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700237 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100238 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000239 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700240 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
241 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100242 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700243 }
244 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700245 }
246
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700247 /**
248 * This constructor should NOT have any monitors by design.
249 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800250 public InvariantDeviceProfile(Context context, String gridName) {
251 String newName = initGrid(context, gridName);
252 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000253 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800254 }
255 }
256
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700257 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800258 * This constructor should NOT have any monitors by design.
259 */
260 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100262 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700263 String gridName = getCurrentGridName(context);
264
265 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000266 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700267 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700268 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000269 defaultInfo,
270 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
271 /*allowDisabledGrid=*/false),
272 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700273
Alex Chau661f02d2022-06-07 14:03:43 +0100274 Context displayContext = context.createDisplayContext(display);
275 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700276 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700277 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000278 myInfo,
279 getPredefinedDeviceProfiles(context, gridName, deviceType,
280 /*allowDisabledGrid=*/false),
281 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700282
283 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
284 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100285 result.iconSizes[INDEX_DEFAULT] =
286 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
287 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700288 result.iconSizes[i] = Math.min(
289 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000290 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700291
Thales Lima83bedbf2021-10-05 17:47:39 +0100292 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
293 COUNT_SIZES);
294 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
295 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500296
Alex Chau1c883d82021-12-01 18:43:10 +0000297 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800298 }
299
Sunny Goyal10fa0162024-04-21 00:13:35 -0700300 @Override
301 public void close() {
302 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
303 }
304
Tracy Zhou42255d22020-03-13 00:38:11 -0700305 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000306 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700307 }
308
Sunny Goyaleff44f32019-01-09 17:29:49 -0800309 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700310 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700311 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700312
fbaronebc10c92024-09-03 12:51:41 -0700313 List<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000314 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100315 RestoreDbTask.isPending(context));
fbaronebc10c92024-09-03 12:51:41 -0700316
317 // Filter out options that don't have the same number of columns as the grid
318 DeviceGridState deviceGridState = new DeviceGridState(context);
319 List<DisplayOption> allOptionsFilteredByColCount =
320 filterByColumnCount(allOptions, deviceGridState.getColumns());
321
Sunny Goyal19ff7282021-04-22 10:12:54 -0700322 DisplayOption displayOption =
fbaronebc10c92024-09-03 12:51:41 -0700323 invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty()
324 ? new ArrayList<>(allOptions)
325 : new ArrayList<>(allOptionsFilteredByColCount), deviceType);
Alex Chau1c883d82021-12-01 18:43:10 +0000326 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700327 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800328 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700329
fbaronebc10c92024-09-03 12:51:41 -0700330 private List<DisplayOption> filterByColumnCount(
331 List<DisplayOption> allOptions, int numColumns) {
332 return allOptions.stream().filter(
333 option -> option.grid.numColumns == numColumns).toList();
334 }
335
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700336 /**
337 * @deprecated This is a temporary solution because on the backup and restore case we modify the
338 * IDP, this resets it. b/332974074
339 */
340 @Deprecated
341 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700342 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700343 }
344
Thales Limab67bfa72022-11-02 15:30:11 +0000345 @VisibleForTesting
346 public static String getDefaultGridName(Context context) {
347 return new InvariantDeviceProfile().initGrid(context, null);
348 }
349
Alex Chau1c883d82021-12-01 18:43:10 +0000350 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
351 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700352 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700353 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000354 numRows = closestProfile.numRows;
355 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000356 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000357 dbFile = closestProfile.dbFile;
358 defaultLayoutId = closestProfile.defaultLayoutId;
359 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300360
Sunny Goyalae190ff2020-04-14 00:19:01 +0000361 numFolderRows = closestProfile.numFolderRows;
362 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300363 folderStyle = closestProfile.folderStyle;
364
Thales Limad852d652023-01-17 14:01:13 +0000365 cellStyle = closestProfile.cellStyle;
366
Jon Mirandae126d722021-02-25 10:45:20 -0500367 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400368 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100369 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
fbaronebc10c92024-09-03 12:51:41 -0700370 rowCountSpecsId = closestProfile.mRowCountSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100371 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100372 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100373 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100374 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100375 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100376 hotseatSpecsId = closestProfile.mHotseatSpecsId;
377 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000378 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
379 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
380 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
381 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300382 numAllAppsRowsForCellHeightCalculation =
383 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000384 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000385
Vinit Nayakc7293172022-07-18 16:41:50 -0700386 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
387
Thales Lima83bedbf2021-10-05 17:47:39 +0100388 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100389 float maxIconSize = iconSize[0];
390 for (int i = 1; i < iconSize.length; i++) {
391 maxIconSize = Math.max(maxIconSize, iconSize[i]);
392 }
393 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000394 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
395
Thales Lima83bedbf2021-10-05 17:47:39 +0100396 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700397
Thales Lima83bedbf2021-10-05 17:47:39 +0100398 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100399
Thales Lima83bedbf2021-10-05 17:47:39 +0100400 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100401
Thales Limad90faab2021-09-21 17:18:47 +0100402 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100403
Sunny Goyal19ff7282021-04-22 10:12:54 -0700404 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000405 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700406 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100407 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
408 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700409
Thales Limae9273ea2023-01-26 12:33:52 +0000410 allAppsStyle = closestProfile.allAppsStyle;
411
Sunny Goyal19ff7282021-04-22 10:12:54 -0700412 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300413
Alex Chau1c883d82021-12-01 18:43:10 +0000414 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700415 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500416
Thales Limab7ef5692022-03-10 10:32:36 +0000417 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000418 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
419 allAppsIconSize = displayOption.allAppsIconSizes;
420 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000421
Thales Lima11af7bc2022-08-12 15:24:54 +0100422 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000423
Jon Miranda9c478b62023-03-23 21:38:49 -0700424 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
425
Jon Miranda04f05102023-04-04 12:16:31 -0700426 startAlignTaskbar = displayOption.startAlignTaskbar;
427
Sunny Goyalae190ff2020-04-14 00:19:01 +0000428 // If the partner customization apk contains any grid overrides, apply them
429 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700430 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700431
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000432 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700433 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700434 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700435 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000436 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000437 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000438 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700439 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000440 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700441
Sunny Goyal19ff7282021-04-22 10:12:54 -0700442 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
443 int displayWidth = bounds.bounds.width();
444 int displayHeight = bounds.bounds.height();
445 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700446
Sunny Goyal19ff7282021-04-22 10:12:54 -0700447 // We need to ensure that there is enough extra space in the wallpaper
448 // for the intended parallax effects
449 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300450 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
451 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700452 ? 2
453 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
454 defaultWallpaperSize.x =
455 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700456 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000457 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700458
Thales Lima6a590062022-11-22 15:52:49 +0000459 int numMinShownHotseatIconsForTablet = supportedProfiles
460 .stream()
461 .filter(deviceProfile -> deviceProfile.isTablet)
462 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
463 .min()
464 .orElse(0);
465
466 supportedProfiles
467 .stream()
468 .filter(deviceProfile -> deviceProfile.isTablet)
469 .forEach(deviceProfile -> {
470 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
471 deviceProfile.recalculateHotseatWidthAndBorderSpace();
472 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700473 }
474
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700475 public void addOnChangeListener(OnIDPChangeListener listener) {
476 mChangeListeners.add(listener);
477 }
478
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800479 public void removeOnChangeListener(OnIDPChangeListener listener) {
480 mChangeListeners.remove(listener);
481 }
482
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800483 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000484 LauncherPrefs.get(context).put(GRID_NAME, gridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700485 MAIN_EXECUTOR.execute(() -> {
486 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
487 onConfigChanged(context.getApplicationContext());
488 Trace.endSection();
489 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800490 }
491
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700492 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700493 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000494 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
495 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700496 }
497
Pat Manning24cec692023-10-13 10:36:57 +0000498 /** Updates IDP using the provided context. Notifies listeners of change. */
499 @VisibleForTesting
500 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700501 Object[] oldState = toModelState();
502
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700503 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700504 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700505 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700506
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700507 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700508 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700509 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700510 }
511 }
512
fbaron49f7df02024-11-05 16:15:19 -0800513 private static List<DisplayOption> getPredefinedDeviceProfiles(Context context,
Alex Chau1c883d82021-12-01 18:43:10 +0000514 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800515 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100516
Alex Chau1c883d82021-12-01 18:43:10 +0000517 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700518 final int depth = parser.getDepth();
519 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700520 while (((type = parser.next()) != XmlPullParser.END_TAG ||
521 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800522 if ((type == XmlPullParser.START_TAG)
523 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800524
Sunny Goyal076e04b2023-04-03 12:38:30 -0700525 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
fbaronebc10c92024-09-03 12:51:41 -0700526 if ((gridOption.isEnabled(deviceType) || allowDisabledGrid)
fbaron49f7df02024-11-05 16:15:19 -0800527 && gridOption.filterByFlag(deviceType)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100528 final int displayDepth = parser.getDepth();
529 while (((type = parser.next()) != XmlPullParser.END_TAG
530 || parser.getDepth() > displayDepth)
531 && type != XmlPullParser.END_DOCUMENT) {
532 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
533 parser.getName())) {
534 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100535 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100536 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800537 }
538 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700539 }
540 }
sfufa@google.comde013292021-09-21 18:22:44 -0700541 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700542 throw new RuntimeException(e);
543 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800544
Sunny Goyalae190ff2020-04-14 00:19:01 +0000545 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800546 if (!TextUtils.isEmpty(gridName)) {
547 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100548 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700549 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000550 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800551 }
552 }
553 }
fbaronebc10c92024-09-03 12:51:41 -0700554 if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) {
555 // Use the default options since gridName is empty and there's no valid grids.
Sunny Goyalae190ff2020-04-14 00:19:01 +0000556 for (DisplayOption option : profiles) {
557 if (option.canBeDefault) {
558 filteredProfiles.add(option);
559 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800560 }
fbaronebc10c92024-09-03 12:51:41 -0700561 } else if (filteredProfiles.isEmpty()) {
562 // In this case we had a grid selected but we couldn't find it.
563 filteredProfiles.addAll(profiles);
Sunny Goyal415f1732018-11-29 10:33:47 -0800564 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000565 if (filteredProfiles.isEmpty()) {
566 throw new RuntimeException("No display option with canBeDefault=true");
567 }
568 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700569 }
570
Thales Lima7ec83822021-08-05 13:32:10 +0100571 /**
fbaronebc10c92024-09-03 12:51:41 -0700572 * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct
573 * row count for this GridOption.
574 *
575 * @return the result of {@link #findBestRowCount(List, Context, int)}.
576 */
577 public static NumRows getRowCount(ResourceHelper resourceHelper, Context context,
578 int deviceType) {
579 ArrayList<NumRows> rowCounts = new ArrayList<>();
580
581 try (XmlResourceParser parser = resourceHelper.getXml()) {
582 final int depth = parser.getDepth();
583 int type;
584 while (((type = parser.next()) != XmlPullParser.END_TAG
585 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
586 if ((type == XmlPullParser.START_TAG)
587 && "NumRows".equals(parser.getName())) {
588 rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser)));
589 }
590 }
591 } catch (IOException | XmlPullParserException e) {
592 throw new RuntimeException(e);
593 }
594
595 return findBestRowCount(rowCounts, context, deviceType);
596 }
597
598 /**
599 * @return the biggest row count that fits the display dimensions spec using NumRows to
600 * determine that. If no best row count is found, return -1.
601 */
602 public static NumRows findBestRowCount(List<NumRows> list, Context context,
603 @DeviceType int deviceType) {
604 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
605 int minWidthPx = Integer.MAX_VALUE;
606 int minHeightPx = Integer.MAX_VALUE;
607 for (WindowBounds bounds : displayInfo.supportedBounds) {
608 boolean isTablet = displayInfo.isTablet(bounds);
609 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
610 // For split displays, take half width per page
611 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
612 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
613 } else if (!isTablet && bounds.isLandscape()) {
614 // We will use transposed layout in this case
615 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
616 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
617 } else {
618 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
619 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
620 }
621 }
622
623 NumRows selectedRow = null;
624 for (NumRows item: list) {
625 if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) {
626 if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) {
627 selectedRow = item;
628 }
629 }
630 }
631 if (selectedRow != null) {
632 return selectedRow;
633 }
634 return null;
635 }
636
637 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000638 * Returns the GridOption associated to the given file name or null if the fileName is not
639 * supported.
640 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
641 */
642 public GridOption getGridOptionFromFileName(Context context, String fileName) {
643 return parseAllGridOptions(context).stream()
644 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
645 .findFirst()
646 .orElse(null);
647 }
648
649 /**
650 * Returns the name of the given size on the current device or empty string if the size is not
651 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
652 * (Note: the name of the grid can be different for the same grid size depending of
653 * the values of the InvariantDeviceProfile)
654 *
655 */
656 public String getGridNameFromSize(Context context, Point size) {
657 return parseAllGridOptions(context).stream()
658 .filter(gridOption -> gridOption.numColumns == size.x
659 && gridOption.numRows == size.y)
660 .map(gridOption -> gridOption.name)
661 .findFirst()
662 .orElse("");
663 }
664
665 /**
666 * Returns the grid option for the given gridName on the current device (Note: the gridOption
667 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
668 */
669 public GridOption getGridOptionFromName(Context context, String gridName) {
670 return parseAllGridOptions(context).stream()
671 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
672 .findFirst()
673 .orElse(null);
674 }
675
676 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100677 * @return all the grid options that can be shown on the device
678 */
679 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700680 return parseAllDefinedGridOptions(context)
681 .stream()
682 .filter(go -> go.isEnabled(deviceType))
fbaron49f7df02024-11-05 16:15:19 -0800683 .filter(go -> go.filterByFlag(deviceType))
Sunny Goyal076e04b2023-04-03 12:38:30 -0700684 .collect(Collectors.toList());
685 }
686
687 /**
688 * @return all the grid options that can be shown on the device
689 */
690 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100691 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100692
Alex Chau1c883d82021-12-01 18:43:10 +0000693 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100694 final int depth = parser.getDepth();
695 int type;
696 while (((type = parser.next()) != XmlPullParser.END_TAG
697 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
698 if ((type == XmlPullParser.START_TAG)
699 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700700 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100701 }
702 }
703 } catch (IOException | XmlPullParserException e) {
704 Log.e(TAG, "Error parsing device profile", e);
705 return Collections.emptyList();
706 }
707 return result;
708 }
709
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700710 private int getLauncherIconDensity(int requiredSize) {
711 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700712 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700713 DisplayMetrics.DENSITY_LOW,
714 DisplayMetrics.DENSITY_MEDIUM,
715 DisplayMetrics.DENSITY_TV,
716 DisplayMetrics.DENSITY_HIGH,
717 DisplayMetrics.DENSITY_XHIGH,
718 DisplayMetrics.DENSITY_XXHIGH,
719 DisplayMetrics.DENSITY_XXXHIGH
720 };
721
722 int density = DisplayMetrics.DENSITY_XXXHIGH;
723 for (int i = densityBuckets.length - 1; i >= 0; i--) {
724 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
725 / DisplayMetrics.DENSITY_DEFAULT;
726 if (expectedSize >= requiredSize) {
727 density = densityBuckets[i];
728 }
729 }
730
731 return density;
732 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700733
Adam Cohen2e6da152015-05-06 11:42:25 -0700734 /**
735 * Apply any Partner customization grid overrides.
736 *
737 * Currently we support: all apps row / column count.
738 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700739 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
740 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800741 if (p == null) {
742 return;
743 }
744 try {
745 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
746 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
747 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
748
749 if (numRows > 0 && numColumns > 0) {
750 this.numRows = numRows;
751 this.numColumns = numColumns;
752 }
753 if (iconSizePx > 0) {
754 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
755 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
756 }
757 } catch (Resources.NotFoundException ex) {
758 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700759 }
760 }
761
Sunny Goyal415f1732018-11-29 10:33:47 -0800762 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700763 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700764 }
765
Sunny Goyal19ff7282021-04-22 10:12:54 -0700766 private static DisplayOption invDistWeightedInterpolate(
fbaronebc10c92024-09-03 12:51:41 -0700767 Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768 int minWidthPx = Integer.MAX_VALUE;
769 int minHeightPx = Integer.MAX_VALUE;
770 for (WindowBounds bounds : displayInfo.supportedBounds) {
771 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000772 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700773 // For split displays, take half width per page
774 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
775 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700776
Sunny Goyal19ff7282021-04-22 10:12:54 -0700777 } else if (!isTablet && bounds.isLandscape()) {
778 // We will use transposed layout in this case
779 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
780 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
781 } else {
782 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
783 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
784 }
785 }
786
Thales Lima425f6822022-05-10 13:44:58 -0300787 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
788 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700789
790 // Sort the profiles based on the closeness to the device size
fbaronebc10c92024-09-03 12:51:41 -0700791 points.sort((a, b) ->
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700792 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
793 dist(width, height, b.minWidthDps, b.minHeightDps)));
794
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700795 DisplayOption closestPoint = points.get(0);
796 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700797 float weights = 0;
798
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700799 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
800 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700801 }
802
803 DisplayOption out = new DisplayOption(closestOption);
804 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700805 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700806 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
807 weights += w;
808 out.add(new DisplayOption().add(p).multiply(w));
809 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700810 out.multiply(1.0f / weights);
811
Thales Lima6e0005a2021-10-27 15:53:41 +0100812 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700813 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100814 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
815 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700816 }
817
818 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700819 }
820
Sunny Goyal27835952017-01-13 12:15:53 -0800821 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000822 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
823 Rect bounds = windowManagerProxy.getCurrentBounds(context);
824 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700825
Alex Chauc09a98a2023-11-14 12:51:42 +0000826 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400827 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700828
Sunny Goyal187b16c2022-03-01 16:53:23 -0800829 /**
830 * Returns the device profile matching the provided screen configuration
831 */
832 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700833 DeviceProfile bestMatch = supportedProfiles.get(0);
834 float minDiff = Float.MAX_VALUE;
835
836 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400837 float diff = Math.abs(profile.widthPx - screenWidth)
838 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700839 if (diff < minDiff) {
840 minDiff = diff;
841 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800842 } else if (diff == minDiff && profile.rotationHint == rotation) {
843 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844 }
845 }
846 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800847 }
848
Sunny Goyal415f1732018-11-29 10:33:47 -0800849 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700850 float d = dist(x0, y0, x1, y1);
851 if (Float.compare(d, 0f) == 0) {
852 return Float.POSITIVE_INFINITY;
853 }
854 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
855 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700856
857 /**
858 * As a ratio of screen height, the total distance we want the parallax effect to span
859 * horizontally
860 */
861 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
862 float aspectRatio = width / (float) height;
863
864 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
865 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
866 // We will use these two data points to extrapolate how much the wallpaper parallax effect
867 // to span (ie travel) at any aspect ratio:
868
sfufa@google.comde013292021-09-21 18:22:44 -0700869 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
870 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700871 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
872 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
873
874 // To find out the desired width at different aspect ratios, we use the following two
875 // formulas, where the coefficient on x is the aspect ratio (width/height):
876 // (16/10)x + y = 1.5
877 // (10/16)x + y = 1.2
878 // We solve for x and y and end up with a final formula:
879 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700880 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
881 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700882 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
883 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
884 return x * aspectRatio + y;
885 }
886
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700887 public interface OnIDPChangeListener {
888
Sunny Goyalb47172b2021-05-03 19:59:51 -0700889 /**
890 * Called when the device provide changes
891 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700892 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700893 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800894
895
Sunny Goyaleff44f32019-01-09 17:29:49 -0800896 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800897
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800898 public static final String TAG_NAME = "grid-option";
899
Alex Chau1c883d82021-12-01 18:43:10 +0000900 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
901 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
902 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
903 private static final int DEVICE_CATEGORY_ALL =
904 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
905
Thales Lima11af7bc2022-08-12 15:24:54 +0100906 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
907 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
908 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
909 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
910 private static final int DONT_INLINE_QSB = 0;
911
Sunny Goyaleff44f32019-01-09 17:29:49 -0800912 public final String name;
fbaronebc10c92024-09-03 12:51:41 -0700913 public final String title;
Sunny Goyaleff44f32019-01-09 17:29:49 -0800914 public final int numRows;
915 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000916 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700917 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800918
Thales Lima1faa4ed2023-12-01 16:48:19 +0000919 private final int[] numFolderRows = new int[COUNT_SIZES];
920 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300921 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000922 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800923
Thales Limae9273ea2023-01-26 12:33:52 +0000924 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700925 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300926 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700927 private final int numDatabaseAllAppsColumns;
928 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700929 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100930
Thales Lima11af7bc2022-08-12 15:24:54 +0100931 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
932
Thales Limab35faed2022-09-05 16:30:01 -0300933 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800934 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000935
Sunny Goyal415f1732018-11-29 10:33:47 -0800936 private final int defaultLayoutId;
937 private final int demoModeLayoutId;
938
Jon Mirandae126d722021-02-25 10:45:20 -0500939 private final boolean isScalable;
fbaron49f7df02024-11-05 16:15:19 -0800940 private final boolean mIsDualGrid;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400941 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100942 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100943 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100944 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100945 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100946 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100947 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100948 private final int mHotseatSpecsId;
949 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000950 private final int mWorkspaceCellSpecsId;
951 private final int mWorkspaceCellSpecsTwoPanelId;
952 private final int mAllAppsCellSpecsId;
953 private final int mAllAppsCellSpecsTwoPanelId;
fbaronebc10c92024-09-03 12:51:41 -0700954 private final int mRowCountSpecsId;
Jon Mirandae126d722021-02-25 10:45:20 -0500955
Sunny Goyal076e04b2023-04-03 12:38:30 -0700956 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800957 TypedArray a = context.obtainStyledAttributes(
958 attrs, R.styleable.GridDisplayOption);
959 name = a.getString(R.styleable.GridDisplayOption_name);
fbaronebc10c92024-09-03 12:51:41 -0700960 title = a.getString(R.styleable.GridDisplayOption_title);
961 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
962 DEVICE_CATEGORY_ALL);
963 mRowCountSpecsId = a.getResourceId(
964 R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
fbaron49f7df02024-11-05 16:15:19 -0800965 mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
fbaronebc10c92024-09-03 12:51:41 -0700966 if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
967 ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
968 NumRows numR = getRowCount(resourceHelper, context, deviceCategory);
969 numRows = numR.mNumRowsNew;
970 dbFile = numR.mDbFile;
971 } else {
972 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
973 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
974 }
975
Sunny Goyal415f1732018-11-29 10:33:47 -0800976 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000977 numSearchContainerColumns = a.getInt(
978 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Alex Chau766cd2b2022-07-06 17:15:21 +0100979 defaultLayoutId = a.getResourceId(
980 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800981 demoModeLayoutId = a.getResourceId(
982 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700983
Thales Limae9273ea2023-01-26 12:33:52 +0000984 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
985 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700986 numAllAppsColumns = a.getInt(
987 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
988 numDatabaseAllAppsColumns = a.getInt(
989 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
990
991 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800992 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700993 numDatabaseHotseatIcons = a.getInt(
994 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100995
Vinit Nayakc7293172022-07-18 16:41:50 -0700996 inlineNavButtonsEndSpacing =
997 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100998 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300999
Thales Lima1faa4ed2023-12-01 16:48:19 +00001000 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001001 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +00001002 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -08001003 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001004
Thales Lima1faa4ed2023-12-01 16:48:19 +00001005 if (FeatureFlags.enableResponsiveWorkspace()) {
1006 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
1007 R.styleable.GridDisplayOption_numFolderRowsLandscape,
1008 numFolderRows[INDEX_DEFAULT]);
1009 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
1010 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
1011 numFolderColumns[INDEX_DEFAULT]);
1012 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1013 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
1014 numFolderRows[INDEX_DEFAULT]);
1015 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1016 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
1017 numFolderColumns[INDEX_DEFAULT]);
1018 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1019 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
1020 numFolderRows[INDEX_DEFAULT]);
1021 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1022 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
1023 numFolderColumns[INDEX_DEFAULT]);
1024 } else {
1025 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1026 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1027 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
1028 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
1029 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
1030 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
1031 }
1032
Thales Limab35faed2022-09-05 16:30:01 -03001033 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
1034 INVALID_RESOURCE_HANDLE);
1035
Thales Limad852d652023-01-17 14:01:13 +00001036 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
1037 R.style.CellStyleDefault);
1038
Jon Mirandae126d722021-02-25 10:45:20 -05001039 isScalable = a.getBoolean(
1040 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001041 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +00001042 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Thales Lima7ec83822021-08-05 13:32:10 +01001043
Thales Limaca31b612023-09-14 14:25:26 +01001044 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +01001045 mWorkspaceSpecsId = a.getResourceId(
1046 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001047 mWorkspaceSpecsTwoPanelId = a.getResourceId(
1048 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001049 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +01001050 mAllAppsSpecsId = a.getResourceId(
1051 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001052 mAllAppsSpecsTwoPanelId = a.getResourceId(
1053 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001054 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001055 mFolderSpecsId = a.getResourceId(
1056 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +01001057 mFolderSpecsTwoPanelId = a.getResourceId(
1058 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001059 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +01001060 mHotseatSpecsId = a.getResourceId(
1061 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
1062 mHotseatSpecsTwoPanelId = a.getResourceId(
1063 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001064 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001065 mWorkspaceCellSpecsId = a.getResourceId(
1066 R.styleable.GridDisplayOption_workspaceCellSpecsId,
1067 INVALID_RESOURCE_HANDLE);
1068 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1069 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001070 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001071 mAllAppsCellSpecsId = a.getResourceId(
1072 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1073 INVALID_RESOURCE_HANDLE);
1074 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1075 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001076 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001077 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1078 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1079 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001080 } else {
1081 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001082 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001083 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001084 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001085 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001086 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001087 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1088 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001089 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1090 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1091 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1092 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001093 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001094 }
1095
Thales Lima11af7bc2022-08-12 15:24:54 +01001096 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1097 DONT_INLINE_QSB);
1098 inlineQsb[INDEX_DEFAULT] =
1099 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1100 inlineQsb[INDEX_LANDSCAPE] =
1101 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1102 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1103 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1104 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1105 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1106 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1107 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1108
Sunny Goyal415f1732018-11-29 10:33:47 -08001109 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001110 }
1111
1112 public boolean isEnabled(@DeviceType int deviceType) {
1113 switch (deviceType) {
1114 case TYPE_PHONE:
1115 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1116 case TYPE_TABLET:
1117 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1118 case TYPE_MULTI_DISPLAY:
1119 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1120 == DEVICE_CATEGORY_MULTI_DISPLAY;
1121 default:
1122 return false;
1123 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001124 }
fbaronebc10c92024-09-03 12:51:41 -07001125
1126 public boolean isNewGridOption() {
1127 return mRowCountSpecsId != INVALID_RESOURCE_HANDLE;
1128 }
fbaron49f7df02024-11-05 16:15:19 -08001129
1130 public boolean filterByFlag(int deviceType) {
1131 if (deviceType == TYPE_TABLET) {
1132 return Flags.oneGridRotationHandling() == mIsDualGrid;
1133 }
1134 return Flags.oneGridSpecs() == isNewGridOption();
1135 }
fbaronebc10c92024-09-03 12:51:41 -07001136 }
1137
1138 public static final class NumRows {
1139 final int mNumRowsNew;
1140 final float mMinDeviceWidthPx;
1141 final float mMinDeviceHeightPx;
1142 final String mDbFile;
1143
1144 NumRows(Context context, AttributeSet attrs) {
1145 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows);
1146
1147 mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0);
1148 mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0);
1149 mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0);
1150 mDbFile = a.getString(R.styleable.NumRows_dbFile);
1151
1152 a.recycle();
1153 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001154 }
1155
Sunny Goyal19ff7282021-04-22 10:12:54 -07001156 @VisibleForTesting
1157 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001158 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001159
Sunny Goyal415f1732018-11-29 10:33:47 -08001160 private final float minWidthDps;
1161 private final float minHeightDps;
1162 private final boolean canBeDefault;
1163
Thales Lima83bedbf2021-10-05 17:47:39 +01001164 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001165
Thales Lima78d00ad2021-09-30 11:29:06 +01001166 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001167 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001168 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1169 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001170
Thales Lima78d00ad2021-09-30 11:29:06 +01001171 private final float[] iconSizes = new float[COUNT_SIZES];
1172 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001173
Thales Limab7ef5692022-03-10 10:32:36 +00001174 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001175 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1176 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1177 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1178
Jon Miranda9c478b62023-03-23 21:38:49 -07001179 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1180
Jon Miranda04f05102023-04-04 12:16:31 -07001181 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1182
Thales Lima1de4d552021-10-13 16:13:25 +01001183 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001184 this.grid = grid;
1185
Jon Miranda9c478b62023-03-23 21:38:49 -07001186 Resources res = context.getResources();
1187
Thales Lima1de4d552021-10-13 16:13:25 +01001188 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001189
Sunny Goyal415f1732018-11-29 10:33:47 -08001190 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1191 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001192
Thales Lima1de4d552021-10-13 16:13:25 +01001193 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001194
Thales Lima83bedbf2021-10-05 17:47:39 +01001195 float x;
1196 float y;
1197
Thales Lima85c942f2021-12-31 13:04:20 +00001198 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1199 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001200 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001201
1202 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1203 minCellSize[INDEX_DEFAULT].x);
1204 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1205 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001206 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001207
Thales Lima85c942f2021-12-31 13:04:20 +00001208 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001209 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001210 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001211 minCellSize[INDEX_DEFAULT].y);
1212 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1213
Thales Lima85c942f2021-12-31 13:04:20 +00001214 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001215 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001216 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001217 minCellSize[INDEX_DEFAULT].y);
1218 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001219
Thales Lima85c942f2021-12-31 13:04:20 +00001220 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001221 float borderSpaceLandscape = a.getFloat(
1222 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001223 float borderSpaceTwoPanelPortrait = a.getFloat(
1224 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1225 float borderSpaceTwoPanelLandscape = a.getFloat(
1226 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001227
Thales Lima85c942f2021-12-31 13:04:20 +00001228 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1229 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001230 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001231
1232 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1233 borderSpaceLandscape);
1234 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1235 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001236 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1237
1238 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001239 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1240 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001241 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001242 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1243 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001244 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1245
1246 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001247 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1248 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001249 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001250 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1251 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001252 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1253
Thales Limab7ef5692022-03-10 10:32:36 +00001254 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1255 minCellSize[INDEX_DEFAULT].x);
1256 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1257 minCellSize[INDEX_DEFAULT].y);
1258 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1259
1260 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1261 allAppsCellSize[INDEX_DEFAULT].x);
1262 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1263 allAppsCellSize[INDEX_DEFAULT].y);
1264 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1265
1266 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1267 allAppsCellSize[INDEX_DEFAULT].x);
1268 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1269 allAppsCellSize[INDEX_DEFAULT].y);
1270 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1271
1272 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1273 allAppsCellSize[INDEX_DEFAULT].x);
1274 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1275 allAppsCellSize[INDEX_DEFAULT].y);
1276 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1277
Thales Lima080d8902022-03-28 15:30:29 +01001278 float allAppsBorderSpace = a.getFloat(
1279 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1280 float allAppsBorderSpaceLandscape = a.getFloat(
1281 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1282 allAppsBorderSpace);
1283 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001284 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001285 allAppsBorderSpace);
1286 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001287 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001288 allAppsBorderSpace);
1289
1290 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1291 allAppsBorderSpace);
1292 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1293 allAppsBorderSpace);
1294 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1295
1296 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1297 allAppsBorderSpaceLandscape);
1298 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1299 allAppsBorderSpaceLandscape);
1300 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1301
1302 x = a.getFloat(
1303 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1304 allAppsBorderSpaceTwoPanelPortrait);
1305 y = a.getFloat(
1306 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1307 allAppsBorderSpaceTwoPanelPortrait);
1308 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1309
1310 x = a.getFloat(
1311 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1312 allAppsBorderSpaceTwoPanelLandscape);
1313 y = a.getFloat(
1314 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1315 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001316 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001317
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001318 iconSizes[INDEX_DEFAULT] =
1319 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1320 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001321 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001322 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001323 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001324 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001325 iconSizes[INDEX_DEFAULT]);
1326 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001327 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001328 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001329
Thales Limabb7d3882021-12-22 12:56:29 +00001330 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1331 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001332 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1333 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001334 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001335 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1336 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1337 allAppsIconSizes[INDEX_DEFAULT]);
1338 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1339 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1340 allAppsIconSizes[INDEX_DEFAULT]);
1341
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001342 textSizes[INDEX_DEFAULT] =
1343 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1344 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001345 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001346 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001347 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001348 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001349 textSizes[INDEX_DEFAULT]);
1350 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001351 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001352 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001353
Thales Limabb7d3882021-12-22 12:56:29 +00001354 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1355 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1356 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1357 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1358 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1359 allAppsIconTextSizes[INDEX_DEFAULT]);
1360 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1361 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1362 allAppsIconTextSizes[INDEX_DEFAULT]);
1363
Thales Lima83bedbf2021-10-05 17:47:39 +01001364 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1365 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001366 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1367 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1368 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001369 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001370 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001371 horizontalMargin[INDEX_DEFAULT]);
1372 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001373 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001374 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001375
Thales Limab8c05952022-05-23 16:58:38 +01001376 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1377 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001378 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001379 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1380 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1381 hotseatBarBottomSpace[INDEX_DEFAULT]);
1382 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1383 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1384 hotseatBarBottomSpace[INDEX_DEFAULT]);
1385 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1386 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1387 hotseatBarBottomSpace[INDEX_DEFAULT]);
1388
1389 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1390 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001391 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001392 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1393 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1394 hotseatQsbSpace[INDEX_DEFAULT]);
1395 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1396 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1397 hotseatQsbSpace[INDEX_DEFAULT]);
1398 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1399 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1400 hotseatQsbSpace[INDEX_DEFAULT]);
1401
Jon Miranda9c478b62023-03-23 21:38:49 -07001402 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1403 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1404 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1405 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1406 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1407 transientTaskbarIconSize[INDEX_DEFAULT]);
1408 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1409 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1410 transientTaskbarIconSize[INDEX_DEFAULT]);
1411 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1412 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001413 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001414
Jon Miranda04f05102023-04-04 12:16:31 -07001415 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1416 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1417 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1418 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1419 startAlignTaskbar[INDEX_DEFAULT]);
1420 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1421 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1422 startAlignTaskbar[INDEX_LANDSCAPE]);
1423 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1424 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1425 startAlignTaskbar[INDEX_DEFAULT]);
1426
Sunny Goyal415f1732018-11-29 10:33:47 -08001427 a.recycle();
1428 }
1429
1430 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001431 this(null);
1432 }
1433
1434 DisplayOption(GridOption grid) {
1435 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001436 minWidthDps = 0;
1437 minHeightDps = 0;
1438 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001439 for (int i = 0; i < COUNT_SIZES; i++) {
1440 iconSizes[i] = 0;
1441 textSizes[i] = 0;
1442 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001443 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001444 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001445 allAppsIconSizes[i] = 0;
1446 allAppsIconTextSizes[i] = 0;
1447 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001448 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001449 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001450 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001451 }
1452
1453 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001454 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001455 iconSizes[i] *= w;
1456 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001457 borderSpaces[i].x *= w;
1458 borderSpaces[i].y *= w;
1459 minCellSize[i].x *= w;
1460 minCellSize[i].y *= w;
1461 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001462 hotseatBarBottomSpace[i] *= w;
1463 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001464 allAppsCellSize[i].x *= w;
1465 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001466 allAppsIconSizes[i] *= w;
1467 allAppsIconTextSizes[i] *= w;
1468 allAppsBorderSpaces[i].x *= w;
1469 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001470 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001471 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001472
Sunny Goyal415f1732018-11-29 10:33:47 -08001473 return this;
1474 }
1475
1476 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001477 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001478 iconSizes[i] += p.iconSizes[i];
1479 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001480 borderSpaces[i].x += p.borderSpaces[i].x;
1481 borderSpaces[i].y += p.borderSpaces[i].y;
1482 minCellSize[i].x += p.minCellSize[i].x;
1483 minCellSize[i].y += p.minCellSize[i].y;
1484 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001485 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1486 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001487 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1488 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001489 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1490 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1491 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1492 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001493 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001494 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001495 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001496
Sunny Goyal415f1732018-11-29 10:33:47 -08001497 return this;
1498 }
1499 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001500}