blob: 54aea38ef3d537747dd291dd738d35480b3e1f5a [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;
Sunny Goyal415f1732018-11-29 10:33:47 -080037import android.text.TextUtils;
38import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070039import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010040import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080041import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070042import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080043import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070044
Thales Limab35faed2022-09-05 16:30:01 -030045import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000046import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030047import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070048import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000049import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010050import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070051
Thales Limaec5abba2023-04-05 16:33:50 +010052import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070053import com.android.launcher3.icons.DotRenderer;
Charlie Andersonc9d11e82023-08-02 11:41:55 -040054import com.android.launcher3.logging.FileLog;
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;
Stefan Andonian5bd9a222023-02-23 00:58:33 +000060import com.android.launcher3.util.LockedUserState;
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;
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
Jordan Silva575c3bd2023-07-21 12:00:43 +0100188 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
189 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100190 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100191 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100192 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
193 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100194 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100195 @XmlRes
196 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000197 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100198 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000199 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100200 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000201 @XmlRes
202 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
203 @XmlRes
204 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
205 @XmlRes
206 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
207 @XmlRes
208 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500209
Tracy Zhou7df93d22020-01-27 13:44:06 -0800210 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800211 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700212 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100213 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700214
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000215 /**
216 * An immutable list of supported profiles.
217 */
218 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700219
Sunny Goyal6f866092016-03-17 17:04:15 -0700220 public Point defaultWallpaperSize;
221
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700222 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700223
Sunny Goyalf633ef52018-03-13 09:57:05 -0700224 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800225 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700226
Sunny Goyalbbf01842015-10-08 07:41:15 -0700227 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700228 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700229 String gridName = getCurrentGridName(context);
230 String newGridName = initGrid(context, gridName);
231 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000232 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700233 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700234 LockedUserState.get(context).runOnUserUnlocked(() ->
235 new DeviceGridState(this).writeToPrefs(context));
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700237 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100238 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000239 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut 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
Alex Chau238aaee2021-10-06 16:15:24 +0100305 /**
306 * Reinitialize the current grid after a restore, where some grids might now be disabled.
307 */
308 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000309 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100310 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000311 String newGridName = initGrid(context, currentGridName);
312 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400313 FileLog.d(TAG, "Reinitializing grid after restore."
314 + " currentGridName=" + currentGridName
315 + ", currentDbFile=" + currentDbFile
316 + ", newGridName=" + newGridName
317 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000318 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400319 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100320 + ", migrating to: " + newGridName
321 + ", removing all other grid db files");
322 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
323 if (gridDbFile.equals(currentDbFile)) {
324 continue;
325 }
326 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400327 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100328 }
329 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000330 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100331 }
332 }
333
Tracy Zhou42255d22020-03-13 00:38:11 -0700334 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000335 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700336 }
337
Sunny Goyaleff44f32019-01-09 17:29:49 -0800338 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700339 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700340 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700341
342 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000343 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100344 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700345 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000346 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
347 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700348 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800349 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700350
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700351 /**
352 * @deprecated This is a temporary solution because on the backup and restore case we modify the
353 * IDP, this resets it. b/332974074
354 */
355 @Deprecated
356 public void reset(Context context) {
357 initGrid(context, getCurrentGridName(context));
358 }
359
Thales Limab67bfa72022-11-02 15:30:11 +0000360 @VisibleForTesting
361 public static String getDefaultGridName(Context context) {
362 return new InvariantDeviceProfile().initGrid(context, null);
363 }
364
Alex Chau1c883d82021-12-01 18:43:10 +0000365 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
366 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700367 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700368 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000369 numRows = closestProfile.numRows;
370 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000371 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000372 dbFile = closestProfile.dbFile;
373 defaultLayoutId = closestProfile.defaultLayoutId;
374 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300375
Sunny Goyalae190ff2020-04-14 00:19:01 +0000376 numFolderRows = closestProfile.numFolderRows;
377 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300378 folderStyle = closestProfile.folderStyle;
379
Thales Limad852d652023-01-17 14:01:13 +0000380 cellStyle = closestProfile.cellStyle;
381
Jon Mirandae126d722021-02-25 10:45:20 -0500382 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400383 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100384 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100385 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100386 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100387 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100388 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100389 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100390 hotseatSpecsId = closestProfile.mHotseatSpecsId;
391 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000392 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
393 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
394 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
395 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300396 numAllAppsRowsForCellHeightCalculation =
397 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000398 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000399
Vinit Nayakc7293172022-07-18 16:41:50 -0700400 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
401
Thales Lima83bedbf2021-10-05 17:47:39 +0100402 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100403 float maxIconSize = iconSize[0];
404 for (int i = 1; i < iconSize.length; i++) {
405 maxIconSize = Math.max(maxIconSize, iconSize[i]);
406 }
407 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000408 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
409
Thales Lima83bedbf2021-10-05 17:47:39 +0100410 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700411
Thales Lima83bedbf2021-10-05 17:47:39 +0100412 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100413
Thales Lima83bedbf2021-10-05 17:47:39 +0100414 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100415
Thales Limad90faab2021-09-21 17:18:47 +0100416 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100417
Sunny Goyal19ff7282021-04-22 10:12:54 -0700418 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000419 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700420 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100421 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
422 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700423
Thales Limae9273ea2023-01-26 12:33:52 +0000424 allAppsStyle = closestProfile.allAppsStyle;
425
Sunny Goyal19ff7282021-04-22 10:12:54 -0700426 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300427
Alex Chau1c883d82021-12-01 18:43:10 +0000428 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700429 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500430
Thales Limab7ef5692022-03-10 10:32:36 +0000431 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000432 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
433 allAppsIconSize = displayOption.allAppsIconSizes;
434 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000435
Thales Lima11af7bc2022-08-12 15:24:54 +0100436 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000437
Jon Miranda9c478b62023-03-23 21:38:49 -0700438 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
439
Jon Miranda04f05102023-04-04 12:16:31 -0700440 startAlignTaskbar = displayOption.startAlignTaskbar;
441
Sunny Goyalae190ff2020-04-14 00:19:01 +0000442 // If the partner customization apk contains any grid overrides, apply them
443 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700444 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700445
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000446 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700447 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700448 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700449 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000450 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000451 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000452 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700453 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000454 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700455
Sunny Goyal19ff7282021-04-22 10:12:54 -0700456 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
457 int displayWidth = bounds.bounds.width();
458 int displayHeight = bounds.bounds.height();
459 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700460
Sunny Goyal19ff7282021-04-22 10:12:54 -0700461 // We need to ensure that there is enough extra space in the wallpaper
462 // for the intended parallax effects
463 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300464 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
465 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700466 ? 2
467 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
468 defaultWallpaperSize.x =
469 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700470 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000471 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700472
Thales Lima6a590062022-11-22 15:52:49 +0000473 int numMinShownHotseatIconsForTablet = supportedProfiles
474 .stream()
475 .filter(deviceProfile -> deviceProfile.isTablet)
476 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
477 .min()
478 .orElse(0);
479
480 supportedProfiles
481 .stream()
482 .filter(deviceProfile -> deviceProfile.isTablet)
483 .forEach(deviceProfile -> {
484 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
485 deviceProfile.recalculateHotseatWidthAndBorderSpace();
486 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700487 }
488
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700489 public void addOnChangeListener(OnIDPChangeListener listener) {
490 mChangeListeners.add(listener);
491 }
492
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800493 public void removeOnChangeListener(OnIDPChangeListener listener) {
494 mChangeListeners.remove(listener);
495 }
496
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800497
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800498 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000499 LauncherPrefs.get(context).put(GRID_NAME, gridName);
500 MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext()));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800501 }
502
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700503 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700504 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000505 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
506 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700507 }
508
Pat Manning24cec692023-10-13 10:36:57 +0000509 /** Updates IDP using the provided context. Notifies listeners of change. */
510 @VisibleForTesting
511 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700512 Object[] oldState = toModelState();
513
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700514 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700515 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700516 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700517
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700518 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700519 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700520 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700521 }
522 }
523
Alex Chau1c883d82021-12-01 18:43:10 +0000524 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
525 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800526 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100527
Alex Chau1c883d82021-12-01 18:43:10 +0000528 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700529 final int depth = parser.getDepth();
530 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700531 while (((type = parser.next()) != XmlPullParser.END_TAG ||
532 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800533 if ((type == XmlPullParser.START_TAG)
534 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800535
Sunny Goyal076e04b2023-04-03 12:38:30 -0700536 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
537 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100538 final int displayDepth = parser.getDepth();
539 while (((type = parser.next()) != XmlPullParser.END_TAG
540 || parser.getDepth() > displayDepth)
541 && type != XmlPullParser.END_DOCUMENT) {
542 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
543 parser.getName())) {
544 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100545 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100546 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800547 }
548 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700549 }
550 }
sfufa@google.comde013292021-09-21 18:22:44 -0700551 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700552 throw new RuntimeException(e);
553 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800554
Sunny Goyalae190ff2020-04-14 00:19:01 +0000555 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800556 if (!TextUtils.isEmpty(gridName)) {
557 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100558 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700559 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000560 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800561 }
562 }
563 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000564 if (filteredProfiles.isEmpty()) {
565 // No grid found, use the default options
566 for (DisplayOption option : profiles) {
567 if (option.canBeDefault) {
568 filteredProfiles.add(option);
569 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800570 }
571 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000572 if (filteredProfiles.isEmpty()) {
573 throw new RuntimeException("No display option with canBeDefault=true");
574 }
575 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700576 }
577
Thales Lima7ec83822021-08-05 13:32:10 +0100578 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000579 * Returns the GridOption associated to the given file name or null if the fileName is not
580 * supported.
581 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
582 */
583 public GridOption getGridOptionFromFileName(Context context, String fileName) {
584 return parseAllGridOptions(context).stream()
585 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
586 .findFirst()
587 .orElse(null);
588 }
589
590 /**
591 * Returns the name of the given size on the current device or empty string if the size is not
592 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
593 * (Note: the name of the grid can be different for the same grid size depending of
594 * the values of the InvariantDeviceProfile)
595 *
596 */
597 public String getGridNameFromSize(Context context, Point size) {
598 return parseAllGridOptions(context).stream()
599 .filter(gridOption -> gridOption.numColumns == size.x
600 && gridOption.numRows == size.y)
601 .map(gridOption -> gridOption.name)
602 .findFirst()
603 .orElse("");
604 }
605
606 /**
607 * Returns the grid option for the given gridName on the current device (Note: the gridOption
608 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
609 */
610 public GridOption getGridOptionFromName(Context context, String gridName) {
611 return parseAllGridOptions(context).stream()
612 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
613 .findFirst()
614 .orElse(null);
615 }
616
617 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100618 * @return all the grid options that can be shown on the device
619 */
620 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700621 return parseAllDefinedGridOptions(context)
622 .stream()
623 .filter(go -> go.isEnabled(deviceType))
624 .collect(Collectors.toList());
625 }
626
627 /**
628 * @return all the grid options that can be shown on the device
629 */
630 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100631 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100632
Alex Chau1c883d82021-12-01 18:43:10 +0000633 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100634 final int depth = parser.getDepth();
635 int type;
636 while (((type = parser.next()) != XmlPullParser.END_TAG
637 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
638 if ((type == XmlPullParser.START_TAG)
639 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700640 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100641 }
642 }
643 } catch (IOException | XmlPullParserException e) {
644 Log.e(TAG, "Error parsing device profile", e);
645 return Collections.emptyList();
646 }
647 return result;
648 }
649
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700650 private int getLauncherIconDensity(int requiredSize) {
651 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700652 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700653 DisplayMetrics.DENSITY_LOW,
654 DisplayMetrics.DENSITY_MEDIUM,
655 DisplayMetrics.DENSITY_TV,
656 DisplayMetrics.DENSITY_HIGH,
657 DisplayMetrics.DENSITY_XHIGH,
658 DisplayMetrics.DENSITY_XXHIGH,
659 DisplayMetrics.DENSITY_XXXHIGH
660 };
661
662 int density = DisplayMetrics.DENSITY_XXXHIGH;
663 for (int i = densityBuckets.length - 1; i >= 0; i--) {
664 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
665 / DisplayMetrics.DENSITY_DEFAULT;
666 if (expectedSize >= requiredSize) {
667 density = densityBuckets[i];
668 }
669 }
670
671 return density;
672 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700673
Adam Cohen2e6da152015-05-06 11:42:25 -0700674 /**
675 * Apply any Partner customization grid overrides.
676 *
677 * Currently we support: all apps row / column count.
678 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700679 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
680 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800681 if (p == null) {
682 return;
683 }
684 try {
685 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
686 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
687 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
688
689 if (numRows > 0 && numColumns > 0) {
690 this.numRows = numRows;
691 this.numColumns = numColumns;
692 }
693 if (iconSizePx > 0) {
694 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
695 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
696 }
697 } catch (Resources.NotFoundException ex) {
698 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700699 }
700 }
701
Sunny Goyal415f1732018-11-29 10:33:47 -0800702 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700703 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700704 }
705
Sunny Goyal19ff7282021-04-22 10:12:54 -0700706 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000707 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700708 int minWidthPx = Integer.MAX_VALUE;
709 int minHeightPx = Integer.MAX_VALUE;
710 for (WindowBounds bounds : displayInfo.supportedBounds) {
711 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000712 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700713 // For split displays, take half width per page
714 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
715 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700716
Sunny Goyal19ff7282021-04-22 10:12:54 -0700717 } else if (!isTablet && bounds.isLandscape()) {
718 // We will use transposed layout in this case
719 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
720 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
721 } else {
722 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
723 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
724 }
725 }
726
Thales Lima425f6822022-05-10 13:44:58 -0300727 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
728 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700729
730 // Sort the profiles based on the closeness to the device size
731 Collections.sort(points, (a, b) ->
732 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
733 dist(width, height, b.minWidthDps, b.minHeightDps)));
734
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700735 DisplayOption closestPoint = points.get(0);
736 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700737 float weights = 0;
738
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700739 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
740 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700741 }
742
743 DisplayOption out = new DisplayOption(closestOption);
744 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700745 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700746 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
747 weights += w;
748 out.add(new DisplayOption().add(p).multiply(w));
749 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700750 out.multiply(1.0f / weights);
751
Thales Lima6e0005a2021-10-27 15:53:41 +0100752 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700753 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100754 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
755 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700756 }
757
758 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700759 }
760
Sunny Goyal27835952017-01-13 12:15:53 -0800761 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000762 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
763 Rect bounds = windowManagerProxy.getCurrentBounds(context);
764 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700765
Alex Chauc09a98a2023-11-14 12:51:42 +0000766 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400767 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768
Sunny Goyal187b16c2022-03-01 16:53:23 -0800769 /**
770 * Returns the device profile matching the provided screen configuration
771 */
772 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700773 DeviceProfile bestMatch = supportedProfiles.get(0);
774 float minDiff = Float.MAX_VALUE;
775
776 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400777 float diff = Math.abs(profile.widthPx - screenWidth)
778 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700779 if (diff < minDiff) {
780 minDiff = diff;
781 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800782 } else if (diff == minDiff && profile.rotationHint == rotation) {
783 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700784 }
785 }
786 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800787 }
788
Sunny Goyal415f1732018-11-29 10:33:47 -0800789 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700790 float d = dist(x0, y0, x1, y1);
791 if (Float.compare(d, 0f) == 0) {
792 return Float.POSITIVE_INFINITY;
793 }
794 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
795 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700796
797 /**
798 * As a ratio of screen height, the total distance we want the parallax effect to span
799 * horizontally
800 */
801 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
802 float aspectRatio = width / (float) height;
803
804 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
805 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
806 // We will use these two data points to extrapolate how much the wallpaper parallax effect
807 // to span (ie travel) at any aspect ratio:
808
sfufa@google.comde013292021-09-21 18:22:44 -0700809 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
810 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700811 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
812 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
813
814 // To find out the desired width at different aspect ratios, we use the following two
815 // formulas, where the coefficient on x is the aspect ratio (width/height):
816 // (16/10)x + y = 1.5
817 // (10/16)x + y = 1.2
818 // We solve for x and y and end up with a final formula:
819 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700820 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
821 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700822 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
823 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
824 return x * aspectRatio + y;
825 }
826
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700827 public interface OnIDPChangeListener {
828
Sunny Goyalb47172b2021-05-03 19:59:51 -0700829 /**
830 * Called when the device provide changes
831 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700832 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700833 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800834
835
Sunny Goyaleff44f32019-01-09 17:29:49 -0800836 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800837
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800838 public static final String TAG_NAME = "grid-option";
839
Alex Chau1c883d82021-12-01 18:43:10 +0000840 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
841 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
842 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
843 private static final int DEVICE_CATEGORY_ALL =
844 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
845
Thales Lima11af7bc2022-08-12 15:24:54 +0100846 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
847 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
848 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
849 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
850 private static final int DONT_INLINE_QSB = 0;
851
Sunny Goyaleff44f32019-01-09 17:29:49 -0800852 public final String name;
853 public final int numRows;
854 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000855 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700856 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800857
Thales Lima1faa4ed2023-12-01 16:48:19 +0000858 private final int[] numFolderRows = new int[COUNT_SIZES];
859 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300860 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000861 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800862
Thales Limae9273ea2023-01-26 12:33:52 +0000863 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700864 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300865 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700866 private final int numDatabaseAllAppsColumns;
867 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700868 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100869
Thales Lima11af7bc2022-08-12 15:24:54 +0100870 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
871
Thales Limab35faed2022-09-05 16:30:01 -0300872 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800873 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000874
Sunny Goyal415f1732018-11-29 10:33:47 -0800875 private final int defaultLayoutId;
876 private final int demoModeLayoutId;
877
Jon Mirandae126d722021-02-25 10:45:20 -0500878 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400879 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100880 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100881 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100882 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100883 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100884 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100885 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100886 private final int mHotseatSpecsId;
887 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000888 private final int mWorkspaceCellSpecsId;
889 private final int mWorkspaceCellSpecsTwoPanelId;
890 private final int mAllAppsCellSpecsId;
891 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500892
Sunny Goyal076e04b2023-04-03 12:38:30 -0700893 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800894 TypedArray a = context.obtainStyledAttributes(
895 attrs, R.styleable.GridDisplayOption);
896 name = a.getString(R.styleable.GridDisplayOption_name);
897 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
898 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000899 numSearchContainerColumns = a.getInt(
900 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800901
Tracy Zhou7df93d22020-01-27 13:44:06 -0800902 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100903 defaultLayoutId = a.getResourceId(
904 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800905 demoModeLayoutId = a.getResourceId(
906 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700907
Thales Limae9273ea2023-01-26 12:33:52 +0000908 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
909 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700910 numAllAppsColumns = a.getInt(
911 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
912 numDatabaseAllAppsColumns = a.getInt(
913 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
914
915 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800916 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700917 numDatabaseHotseatIcons = a.getInt(
918 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100919
Vinit Nayakc7293172022-07-18 16:41:50 -0700920 inlineNavButtonsEndSpacing =
921 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100922 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300923
Thales Lima1faa4ed2023-12-01 16:48:19 +0000924 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800925 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000926 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800927 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700928
Thales Lima1faa4ed2023-12-01 16:48:19 +0000929 if (FeatureFlags.enableResponsiveWorkspace()) {
930 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
931 R.styleable.GridDisplayOption_numFolderRowsLandscape,
932 numFolderRows[INDEX_DEFAULT]);
933 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
934 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
935 numFolderColumns[INDEX_DEFAULT]);
936 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
937 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
938 numFolderRows[INDEX_DEFAULT]);
939 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
940 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
941 numFolderColumns[INDEX_DEFAULT]);
942 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
943 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
944 numFolderRows[INDEX_DEFAULT]);
945 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
946 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
947 numFolderColumns[INDEX_DEFAULT]);
948 } else {
949 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
950 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
951 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
952 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
953 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
954 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
955 }
956
Thales Limab35faed2022-09-05 16:30:01 -0300957 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
958 INVALID_RESOURCE_HANDLE);
959
Thales Limad852d652023-01-17 14:01:13 +0000960 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
961 R.style.CellStyleDefault);
962
Jon Mirandae126d722021-02-25 10:45:20 -0500963 isScalable = a.getBoolean(
964 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400965 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000966 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700967 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000968 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100969
Thales Limaca31b612023-09-14 14:25:26 +0100970 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100971 mWorkspaceSpecsId = a.getResourceId(
972 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100973 mWorkspaceSpecsTwoPanelId = a.getResourceId(
974 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300975 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100976 mAllAppsSpecsId = a.getResourceId(
977 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100978 mAllAppsSpecsTwoPanelId = a.getResourceId(
979 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300980 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100981 mFolderSpecsId = a.getResourceId(
982 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100983 mFolderSpecsTwoPanelId = a.getResourceId(
984 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300985 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +0100986 mHotseatSpecsId = a.getResourceId(
987 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
988 mHotseatSpecsTwoPanelId = a.getResourceId(
989 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300990 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000991 mWorkspaceCellSpecsId = a.getResourceId(
992 R.styleable.GridDisplayOption_workspaceCellSpecsId,
993 INVALID_RESOURCE_HANDLE);
994 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
995 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300996 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000997 mAllAppsCellSpecsId = a.getResourceId(
998 R.styleable.GridDisplayOption_allAppsCellSpecsId,
999 INVALID_RESOURCE_HANDLE);
1000 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1001 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001002 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001003 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1004 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1005 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001006 } else {
1007 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001008 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001009 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001010 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001011 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001012 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001013 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1014 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001015 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1016 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1017 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1018 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001019 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001020 }
1021
Thales Lima11af7bc2022-08-12 15:24:54 +01001022 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1023 DONT_INLINE_QSB);
1024 inlineQsb[INDEX_DEFAULT] =
1025 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1026 inlineQsb[INDEX_LANDSCAPE] =
1027 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1028 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1029 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1030 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1031 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1032 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1033 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1034
Sunny Goyal415f1732018-11-29 10:33:47 -08001035 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001036 }
1037
1038 public boolean isEnabled(@DeviceType int deviceType) {
1039 switch (deviceType) {
1040 case TYPE_PHONE:
1041 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1042 case TYPE_TABLET:
1043 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1044 case TYPE_MULTI_DISPLAY:
1045 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1046 == DEVICE_CATEGORY_MULTI_DISPLAY;
1047 default:
1048 return false;
1049 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001050 }
1051 }
1052
Sunny Goyal19ff7282021-04-22 10:12:54 -07001053 @VisibleForTesting
1054 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001055 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001056
Sunny Goyal415f1732018-11-29 10:33:47 -08001057 private final float minWidthDps;
1058 private final float minHeightDps;
1059 private final boolean canBeDefault;
1060
Thales Lima83bedbf2021-10-05 17:47:39 +01001061 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001062
Thales Lima78d00ad2021-09-30 11:29:06 +01001063 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001064 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001065 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1066 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001067
Thales Lima78d00ad2021-09-30 11:29:06 +01001068 private final float[] iconSizes = new float[COUNT_SIZES];
1069 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001070
Thales Limab7ef5692022-03-10 10:32:36 +00001071 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001072 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1073 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1074 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1075
Jon Miranda9c478b62023-03-23 21:38:49 -07001076 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1077
Jon Miranda04f05102023-04-04 12:16:31 -07001078 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1079
Thales Lima1de4d552021-10-13 16:13:25 +01001080 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001081 this.grid = grid;
1082
Jon Miranda9c478b62023-03-23 21:38:49 -07001083 Resources res = context.getResources();
1084
Thales Lima1de4d552021-10-13 16:13:25 +01001085 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001086
Sunny Goyal415f1732018-11-29 10:33:47 -08001087 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1088 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001089
Thales Lima1de4d552021-10-13 16:13:25 +01001090 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001091
Thales Lima83bedbf2021-10-05 17:47:39 +01001092 float x;
1093 float y;
1094
Thales Lima85c942f2021-12-31 13:04:20 +00001095 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1096 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001097 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001098
1099 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1100 minCellSize[INDEX_DEFAULT].x);
1101 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1102 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001103 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001104
Thales Lima85c942f2021-12-31 13:04:20 +00001105 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001106 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001107 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001108 minCellSize[INDEX_DEFAULT].y);
1109 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1110
Thales Lima85c942f2021-12-31 13:04:20 +00001111 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001112 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001113 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001114 minCellSize[INDEX_DEFAULT].y);
1115 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001116
Thales Lima85c942f2021-12-31 13:04:20 +00001117 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001118 float borderSpaceLandscape = a.getFloat(
1119 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001120 float borderSpaceTwoPanelPortrait = a.getFloat(
1121 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1122 float borderSpaceTwoPanelLandscape = a.getFloat(
1123 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001124
Thales Lima85c942f2021-12-31 13:04:20 +00001125 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1126 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001127 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001128
1129 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1130 borderSpaceLandscape);
1131 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1132 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001133 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1134
1135 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001136 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1137 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001138 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001139 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1140 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001141 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1142
1143 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001144 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1145 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001146 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001147 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1148 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001149 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1150
Thales Limab7ef5692022-03-10 10:32:36 +00001151 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1152 minCellSize[INDEX_DEFAULT].x);
1153 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1154 minCellSize[INDEX_DEFAULT].y);
1155 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1156
1157 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1158 allAppsCellSize[INDEX_DEFAULT].x);
1159 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1160 allAppsCellSize[INDEX_DEFAULT].y);
1161 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1162
1163 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1164 allAppsCellSize[INDEX_DEFAULT].x);
1165 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1166 allAppsCellSize[INDEX_DEFAULT].y);
1167 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1168
1169 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1170 allAppsCellSize[INDEX_DEFAULT].x);
1171 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1172 allAppsCellSize[INDEX_DEFAULT].y);
1173 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1174
Thales Lima080d8902022-03-28 15:30:29 +01001175 float allAppsBorderSpace = a.getFloat(
1176 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1177 float allAppsBorderSpaceLandscape = a.getFloat(
1178 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1179 allAppsBorderSpace);
1180 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001181 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001182 allAppsBorderSpace);
1183 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001184 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001185 allAppsBorderSpace);
1186
1187 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1188 allAppsBorderSpace);
1189 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1190 allAppsBorderSpace);
1191 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1192
1193 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1194 allAppsBorderSpaceLandscape);
1195 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1196 allAppsBorderSpaceLandscape);
1197 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1198
1199 x = a.getFloat(
1200 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1201 allAppsBorderSpaceTwoPanelPortrait);
1202 y = a.getFloat(
1203 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1204 allAppsBorderSpaceTwoPanelPortrait);
1205 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1206
1207 x = a.getFloat(
1208 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1209 allAppsBorderSpaceTwoPanelLandscape);
1210 y = a.getFloat(
1211 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1212 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001213 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001214
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001215 iconSizes[INDEX_DEFAULT] =
1216 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1217 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001218 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001219 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001220 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001221 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001222 iconSizes[INDEX_DEFAULT]);
1223 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001224 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001225 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001226
Thales Limabb7d3882021-12-22 12:56:29 +00001227 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1228 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001229 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1230 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001231 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001232 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1233 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1234 allAppsIconSizes[INDEX_DEFAULT]);
1235 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1236 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1237 allAppsIconSizes[INDEX_DEFAULT]);
1238
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001239 textSizes[INDEX_DEFAULT] =
1240 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1241 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001242 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001243 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001244 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001245 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001246 textSizes[INDEX_DEFAULT]);
1247 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001248 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001249 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001250
Thales Limabb7d3882021-12-22 12:56:29 +00001251 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1252 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1253 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1254 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1255 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1256 allAppsIconTextSizes[INDEX_DEFAULT]);
1257 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1258 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1259 allAppsIconTextSizes[INDEX_DEFAULT]);
1260
Thales Lima83bedbf2021-10-05 17:47:39 +01001261 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1262 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001263 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1264 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1265 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001266 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001267 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001268 horizontalMargin[INDEX_DEFAULT]);
1269 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001270 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001271 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001272
Thales Limab8c05952022-05-23 16:58:38 +01001273 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1274 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001275 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001276 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1277 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1278 hotseatBarBottomSpace[INDEX_DEFAULT]);
1279 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1280 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1281 hotseatBarBottomSpace[INDEX_DEFAULT]);
1282 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1283 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1284 hotseatBarBottomSpace[INDEX_DEFAULT]);
1285
1286 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1287 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001288 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001289 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1290 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1291 hotseatQsbSpace[INDEX_DEFAULT]);
1292 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1293 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1294 hotseatQsbSpace[INDEX_DEFAULT]);
1295 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1296 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1297 hotseatQsbSpace[INDEX_DEFAULT]);
1298
Jon Miranda9c478b62023-03-23 21:38:49 -07001299 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1300 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1301 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1302 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1303 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1304 transientTaskbarIconSize[INDEX_DEFAULT]);
1305 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1306 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1307 transientTaskbarIconSize[INDEX_DEFAULT]);
1308 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1309 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001310 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001311
Jon Miranda04f05102023-04-04 12:16:31 -07001312 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1313 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1314 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1315 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1316 startAlignTaskbar[INDEX_DEFAULT]);
1317 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1318 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1319 startAlignTaskbar[INDEX_LANDSCAPE]);
1320 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1321 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1322 startAlignTaskbar[INDEX_DEFAULT]);
1323
Sunny Goyal415f1732018-11-29 10:33:47 -08001324 a.recycle();
1325 }
1326
1327 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001328 this(null);
1329 }
1330
1331 DisplayOption(GridOption grid) {
1332 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001333 minWidthDps = 0;
1334 minHeightDps = 0;
1335 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001336 for (int i = 0; i < COUNT_SIZES; i++) {
1337 iconSizes[i] = 0;
1338 textSizes[i] = 0;
1339 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001340 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001341 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001342 allAppsIconSizes[i] = 0;
1343 allAppsIconTextSizes[i] = 0;
1344 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001345 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001346 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001347 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001348 }
1349
1350 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001351 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001352 iconSizes[i] *= w;
1353 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001354 borderSpaces[i].x *= w;
1355 borderSpaces[i].y *= w;
1356 minCellSize[i].x *= w;
1357 minCellSize[i].y *= w;
1358 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001359 hotseatBarBottomSpace[i] *= w;
1360 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001361 allAppsCellSize[i].x *= w;
1362 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001363 allAppsIconSizes[i] *= w;
1364 allAppsIconTextSizes[i] *= w;
1365 allAppsBorderSpaces[i].x *= w;
1366 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001367 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001368 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001369
Sunny Goyal415f1732018-11-29 10:33:47 -08001370 return this;
1371 }
1372
1373 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001374 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001375 iconSizes[i] += p.iconSizes[i];
1376 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001377 borderSpaces[i].x += p.borderSpaces[i].x;
1378 borderSpaces[i].y += p.borderSpaces[i].y;
1379 minCellSize[i].x += p.minCellSize[i].x;
1380 minCellSize[i].y += p.minCellSize[i].y;
1381 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001382 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1383 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001384 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1385 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001386 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1387 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1388 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1389 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001390 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001391 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001392 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001393
Sunny Goyal415f1732018-11-29 10:33:47 -08001394 return this;
1395 }
1396 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001397}