blob: dfe4bb0204c07b285800ff049bb5608c72f1289c [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
Sunny Goyal19ff7282021-04-22 10:12:54 -070019import static com.android.launcher3.Utilities.dpiFromPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010020import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070021import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Sunny Goyal19ff7282021-04-22 10:12:54 -070022import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080023import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070024
Sunny Goyalc6205602015-05-21 20:46:33 -070025import android.annotation.TargetApi;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070026import android.appwidget.AppWidgetHostView;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070027import android.content.ComponentName;
Adam Cohen2e6da152015-05-06 11:42:25 -070028import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080029import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080030import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070031import android.content.res.TypedArray;
32import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070033import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010034import android.graphics.PointF;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070035import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080036import android.text.TextUtils;
37import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070038import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010039import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080040import android.util.SparseArray;
41import android.util.TypedValue;
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
Alex Chau1c883d82021-12-01 18:43:10 +000045import androidx.annotation.IntDef;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070046import androidx.annotation.Nullable;
47import androidx.annotation.VisibleForTesting;
48
Sunny Goyal68031ca2021-08-02 12:23:44 -070049import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010050import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalfd58da62020-08-11 12:06:49 -070051import com.android.launcher3.util.DisplayController;
52import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080053import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070054import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080055import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070056import com.android.launcher3.util.WindowBounds;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070057
Sunny Goyal819e1932016-07-07 16:43:58 -070058import org.xmlpull.v1.XmlPullParser;
59import org.xmlpull.v1.XmlPullParserException;
60
61import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000062import java.lang.annotation.Retention;
63import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070064import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070065import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080066import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070067import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070068
69public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070070
Hyunyoung Songc55a3502018-12-04 15:43:16 -080071 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070072 // We do not need any synchronization for this variable as its only written on UI thread.
73 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070074 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070075
Alex Chau1c883d82021-12-01 18:43:10 +000076 @Retention(RetentionPolicy.SOURCE)
77 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
78 public @interface DeviceType{}
79 public static final int TYPE_PHONE = 0;
80 public static final int TYPE_MULTI_DISPLAY = 1;
81 public static final int TYPE_TABLET = 2;
82
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080084
Sunny Goyal53d7ee42015-05-22 12:25:45 -070085 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
86
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070087 // Constants that affects the interpolation curve between statically defined device profile
88 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080089 private static final float KNEARESTNEIGHBOR = 3;
90 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070091
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070092 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080093 private static final float WEIGHT_EFFICIENT = 100000f;
94
Thales Lima83bedbf2021-10-05 17:47:39 +010095 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
96 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +000097 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +010098 static final int INDEX_DEFAULT = 0;
99 static final int INDEX_LANDSCAPE = 1;
100 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
101 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100102
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700103 /**
104 * Number of icons per row and column in the workspace.
105 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700106 public int numRows;
107 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000108 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700109
110 /**
111 * Number of icons per row and column in the folder.
112 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700113 public int numFolderRows;
114 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100115 public float[] iconSize;
116 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700117 public int iconBitmapSize;
118 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000119 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700120
Thales Lima83bedbf2021-10-05 17:47:39 +0100121 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100122
Thales Lima83bedbf2021-10-05 17:47:39 +0100123 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000125 public float[] hotseatBorderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126
Thales Lima83bedbf2021-10-05 17:47:39 +0100127 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500128
Thales Limabb7d3882021-12-22 12:56:29 +0000129 public float[] allAppsIconSize;
130 public float[] allAppsIconTextSize;
131 public PointF[] allAppsBorderSpaces;
132
Sunny Goyal5bc18462019-01-07 15:13:39 -0800133 private SparseArray<TypedValue> mExtraAttrs;
134
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700135 /**
136 * Number of icons inside the hotseat area.
137 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800138 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700139
140 /**
141 * Number of icons inside the hotseat area that is stored in the database. This is greater than
142 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
143 * sizes that share the same DB.
144 */
145 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700146
Jon Miranda6f7e9702019-09-16 14:44:14 -0700147 /**
148 * Number of columns in the all apps list.
149 */
150 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700151 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700152
Jon Mirandae126d722021-02-25 10:45:20 -0500153 /**
154 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
155 */
156 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400157 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500158
Tracy Zhou7df93d22020-01-27 13:44:06 -0800159 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800160 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700161 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700162
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000163 /**
164 * An immutable list of supported profiles.
165 */
166 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700167
sfufa@google.comde013292021-09-21 18:22:44 -0700168 @Nullable
169 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500170
Sunny Goyal6f866092016-03-17 17:04:15 -0700171 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700172 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700173
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700174 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700175
Sunny Goyalf633ef52018-03-13 09:57:05 -0700176 @VisibleForTesting
sfufa@google.comde013292021-09-21 18:22:44 -0700177 public InvariantDeviceProfile() {
178 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700179
Sunny Goyalbbf01842015-10-08 07:41:15 -0700180 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700181 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700182 String gridName = getCurrentGridName(context);
183 String newGridName = initGrid(context, gridName);
184 if (!newGridName.equals(gridName)) {
185 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
186 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700187 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700188
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700189 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100190 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700191 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100192 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700193 }
194 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700195 }
196
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700197 /**
198 * This constructor should NOT have any monitors by design.
199 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800200 public InvariantDeviceProfile(Context context, String gridName) {
201 String newName = initGrid(context, gridName);
202 if (newName == null || !newName.equals(gridName)) {
203 throw new IllegalArgumentException("Unknown grid name");
204 }
205 }
206
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700207 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800208 * This constructor should NOT have any monitors by design.
209 */
210 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700211 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100212 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700213 String gridName = getCurrentGridName(context);
214
215 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000216 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
217 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700218 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000219 defaultInfo,
220 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
221 /*allowDisabledGrid=*/false),
222 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223
Alex Chau417bd722021-01-26 15:22:18 +0000224 Info myInfo = new Info(context, display);
Alex Chau1c883d82021-12-01 18:43:10 +0000225 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700226 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000227 myInfo,
228 getPredefinedDeviceProfiles(context, gridName, deviceType,
229 /*allowDisabledGrid=*/false),
230 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700231
232 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
233 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100234 result.iconSizes[INDEX_DEFAULT] =
235 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
236 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700237 result.iconSizes[i] = Math.min(
238 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000239 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700240
Thales Lima83bedbf2021-10-05 17:47:39 +0100241 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
242 COUNT_SIZES);
243 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
244 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500245
Alex Chau1c883d82021-12-01 18:43:10 +0000246 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800247 }
248
Alex Chau238aaee2021-10-06 16:15:24 +0100249 /**
250 * Reinitialize the current grid after a restore, where some grids might now be disabled.
251 */
252 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000253 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100254 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000255 String newGridName = initGrid(context, currentGridName);
256 String newDbFile = dbFile;
257 if (!newDbFile.equals(currentDbFile)) {
258 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100259 + ", migrating to: " + newGridName
260 + ", removing all other grid db files");
261 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
262 if (gridDbFile.equals(currentDbFile)) {
263 continue;
264 }
265 if (context.getDatabasePath(gridDbFile).delete()) {
266 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
267 }
268 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000269 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100270 }
271 }
272
Alex Chau1c883d82021-12-01 18:43:10 +0000273 private static @DeviceType int getDeviceType(Info displayInfo) {
274 // Each screen has two profiles (portrait/landscape), so devices with four or more
275 // supported profiles implies two or more internal displays.
276 if (displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get()) {
277 return TYPE_MULTI_DISPLAY;
278 } else if (displayInfo.supportedBounds.stream().allMatch(displayInfo::isTablet)) {
279 return TYPE_TABLET;
280 } else {
281 return TYPE_PHONE;
282 }
283 }
284
Tracy Zhou42255d22020-03-13 00:38:11 -0700285 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700286 return Utilities.isGridOptionsEnabled(context)
287 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700288 }
289
Sunny Goyaleff44f32019-01-09 17:29:49 -0800290 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700291 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000292 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700293
294 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000295 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100296 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700297 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000298 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
299 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700300 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800301 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700302
Alex Chau1c883d82021-12-01 18:43:10 +0000303 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
304 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700305 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700306 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000307 numRows = closestProfile.numRows;
308 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000309 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000310 dbFile = closestProfile.dbFile;
311 defaultLayoutId = closestProfile.defaultLayoutId;
312 demoModeLayoutId = closestProfile.demoModeLayoutId;
313 numFolderRows = closestProfile.numFolderRows;
314 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500315 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400316 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000317 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000318
319 mExtraAttrs = closestProfile.extraAttrs;
320
Thales Lima83bedbf2021-10-05 17:47:39 +0100321 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100322 float maxIconSize = iconSize[0];
323 for (int i = 1; i < iconSize.length; i++) {
324 maxIconSize = Math.max(maxIconSize, iconSize[i]);
325 }
326 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000327 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
328
Thales Lima83bedbf2021-10-05 17:47:39 +0100329 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700330
Thales Lima83bedbf2021-10-05 17:47:39 +0100331 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100332
Thales Lima83bedbf2021-10-05 17:47:39 +0100333 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100334 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700335
Thales Limad90faab2021-09-21 17:18:47 +0100336 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100337
Sunny Goyal19ff7282021-04-22 10:12:54 -0700338 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000339 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700340 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000341 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700342
343 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000344 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700345 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500346
Thales Limabb7d3882021-12-22 12:56:29 +0000347 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
348 allAppsIconSize = displayOption.allAppsIconSizes;
349 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100350 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000351 allAppsIconSize = iconSize;
352 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000353 }
354
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400355 if (devicePaddingId != 0) {
356 devicePaddings = new DevicePaddings(context, devicePaddingId);
357 }
358
Sunny Goyalae190ff2020-04-14 00:19:01 +0000359 // If the partner customization apk contains any grid overrides, apply them
360 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700361 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700362
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000363 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700364 defaultWallpaperSize = new Point(displayInfo.currentSize);
365 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000366 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000367 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700368 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700369
Sunny Goyal19ff7282021-04-22 10:12:54 -0700370 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
371 int displayWidth = bounds.bounds.width();
372 int displayHeight = bounds.bounds.height();
373 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700374
Sunny Goyal19ff7282021-04-22 10:12:54 -0700375 // We need to ensure that there is enough extra space in the wallpaper
376 // for the intended parallax effects
377 float parallaxFactor =
378 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
379 ? 2
380 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
381 defaultWallpaperSize.x =
382 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700383 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000384 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700385
386 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
387 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700388 }
389
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700390 public void addOnChangeListener(OnIDPChangeListener listener) {
391 mChangeListeners.add(listener);
392 }
393
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800394 public void removeOnChangeListener(OnIDPChangeListener listener) {
395 mChangeListeners.remove(listener);
396 }
397
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800398
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800399 public void setCurrentGrid(Context context, String gridName) {
400 Context appContext = context.getApplicationContext();
401 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700402 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800403 }
404
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700405 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700406 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000407 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
408 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700409 }
410
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700411 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700412 Object[] oldState = toModelState();
413
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700414 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700415 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700416 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700417
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700418 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700419 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700420 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700421 }
422 }
423
Alex Chau1c883d82021-12-01 18:43:10 +0000424 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
425 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800426 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100427
Alex Chau1c883d82021-12-01 18:43:10 +0000428 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700429 final int depth = parser.getDepth();
430 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700431 while (((type = parser.next()) != XmlPullParser.END_TAG ||
432 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800433 if ((type == XmlPullParser.START_TAG)
434 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800435
Alex Chau1c883d82021-12-01 18:43:10 +0000436 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
437 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100438 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100439 final int displayDepth = parser.getDepth();
440 while (((type = parser.next()) != XmlPullParser.END_TAG
441 || parser.getDepth() > displayDepth)
442 && type != XmlPullParser.END_DOCUMENT) {
443 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
444 parser.getName())) {
445 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100446 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100447 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800448 }
449 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700450 }
451 }
sfufa@google.comde013292021-09-21 18:22:44 -0700452 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700453 throw new RuntimeException(e);
454 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800455
Sunny Goyalae190ff2020-04-14 00:19:01 +0000456 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800457 if (!TextUtils.isEmpty(gridName)) {
458 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100459 if (gridName.equals(option.grid.name)
460 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000461 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800462 }
463 }
464 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000465 if (filteredProfiles.isEmpty()) {
466 // No grid found, use the default options
467 for (DisplayOption option : profiles) {
468 if (option.canBeDefault) {
469 filteredProfiles.add(option);
470 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800471 }
472 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000473 if (filteredProfiles.isEmpty()) {
474 throw new RuntimeException("No display option with canBeDefault=true");
475 }
476 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700477 }
478
Thales Lima7ec83822021-08-05 13:32:10 +0100479 /**
480 * @return all the grid options that can be shown on the device
481 */
482 public List<GridOption> parseAllGridOptions(Context context) {
483 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100484
Alex Chau1c883d82021-12-01 18:43:10 +0000485 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100486 final int depth = parser.getDepth();
487 int type;
488 while (((type = parser.next()) != XmlPullParser.END_TAG
489 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
490 if ((type == XmlPullParser.START_TAG)
491 && GridOption.TAG_NAME.equals(parser.getName())) {
492 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000493 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100494 if (option.isEnabled) {
495 result.add(option);
496 }
497 }
498 }
499 } catch (IOException | XmlPullParserException e) {
500 Log.e(TAG, "Error parsing device profile", e);
501 return Collections.emptyList();
502 }
503 return result;
504 }
505
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700506 private int getLauncherIconDensity(int requiredSize) {
507 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700508 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700509 DisplayMetrics.DENSITY_LOW,
510 DisplayMetrics.DENSITY_MEDIUM,
511 DisplayMetrics.DENSITY_TV,
512 DisplayMetrics.DENSITY_HIGH,
513 DisplayMetrics.DENSITY_XHIGH,
514 DisplayMetrics.DENSITY_XXHIGH,
515 DisplayMetrics.DENSITY_XXXHIGH
516 };
517
518 int density = DisplayMetrics.DENSITY_XXXHIGH;
519 for (int i = densityBuckets.length - 1; i >= 0; i--) {
520 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
521 / DisplayMetrics.DENSITY_DEFAULT;
522 if (expectedSize >= requiredSize) {
523 density = densityBuckets[i];
524 }
525 }
526
527 return density;
528 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700529
Adam Cohen2e6da152015-05-06 11:42:25 -0700530 /**
531 * Apply any Partner customization grid overrides.
532 *
533 * Currently we support: all apps row / column count.
534 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700535 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
536 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700537 if (p != null) {
538 p.applyInvariantDeviceProfileOverrides(this, dm);
539 }
540 }
541
Sunny Goyal415f1732018-11-29 10:33:47 -0800542 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700543 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700544 }
545
Sunny Goyal19ff7282021-04-22 10:12:54 -0700546 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000547 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700548 int minWidthPx = Integer.MAX_VALUE;
549 int minHeightPx = Integer.MAX_VALUE;
550 for (WindowBounds bounds : displayInfo.supportedBounds) {
551 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000552 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700553 // For split displays, take half width per page
554 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
555 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700556
Sunny Goyal19ff7282021-04-22 10:12:54 -0700557 } else if (!isTablet && bounds.isLandscape()) {
558 // We will use transposed layout in this case
559 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
560 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
561 } else {
562 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
563 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
564 }
565 }
566
567 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
568 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700569
570 // Sort the profiles based on the closeness to the device size
571 Collections.sort(points, (a, b) ->
572 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
573 dist(width, height, b.minWidthDps, b.minHeightDps)));
574
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700575 DisplayOption closestPoint = points.get(0);
576 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700577 float weights = 0;
578
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700579 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
580 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700581 }
582
583 DisplayOption out = new DisplayOption(closestOption);
584 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700585 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700586 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
587 weights += w;
588 out.add(new DisplayOption().add(p).multiply(w));
589 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700590 out.multiply(1.0f / weights);
591
Thales Lima6e0005a2021-10-27 15:53:41 +0100592 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700593 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100594 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
595 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700596 }
597
598 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700599 }
600
Sunny Goyal27835952017-01-13 12:15:53 -0800601 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700602 Resources res = context.getResources();
603 Configuration config = context.getResources().getConfiguration();
604
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400605 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
606 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
607 return getBestMatch(screenWidth, screenHeight);
608 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700609
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400610 public DeviceProfile getBestMatch(float screenWidth, float screenHeight) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700611 DeviceProfile bestMatch = supportedProfiles.get(0);
612 float minDiff = Float.MAX_VALUE;
613
614 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400615 float diff = Math.abs(profile.widthPx - screenWidth)
616 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700617 if (diff < minDiff) {
618 minDiff = diff;
619 bestMatch = profile;
620 }
621 }
622 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800623 }
624
Sunny Goyal415f1732018-11-29 10:33:47 -0800625 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700626 float d = dist(x0, y0, x1, y1);
627 if (Float.compare(d, 0f) == 0) {
628 return Float.POSITIVE_INFINITY;
629 }
630 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
631 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700632
633 /**
634 * As a ratio of screen height, the total distance we want the parallax effect to span
635 * horizontally
636 */
637 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
638 float aspectRatio = width / (float) height;
639
640 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
641 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
642 // We will use these two data points to extrapolate how much the wallpaper parallax effect
643 // to span (ie travel) at any aspect ratio:
644
sfufa@google.comde013292021-09-21 18:22:44 -0700645 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
646 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700647 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
648 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
649
650 // To find out the desired width at different aspect ratios, we use the following two
651 // formulas, where the coefficient on x is the aspect ratio (width/height):
652 // (16/10)x + y = 1.5
653 // (10/16)x + y = 1.2
654 // We solve for x and y and end up with a final formula:
655 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700656 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
657 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700658 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
659 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
660 return x * aspectRatio + y;
661 }
662
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700663 public interface OnIDPChangeListener {
664
Sunny Goyalb47172b2021-05-03 19:59:51 -0700665 /**
666 * Called when the device provide changes
667 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700668 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700669 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800670
671
Sunny Goyaleff44f32019-01-09 17:29:49 -0800672 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800673
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800674 public static final String TAG_NAME = "grid-option";
675
Alex Chau1c883d82021-12-01 18:43:10 +0000676 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
677 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
678 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
679 private static final int DEVICE_CATEGORY_ALL =
680 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
681
Sunny Goyaleff44f32019-01-09 17:29:49 -0800682 public final String name;
683 public final int numRows;
684 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000685 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100686 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800687
688 private final int numFolderRows;
689 private final int numFolderColumns;
690
Sunny Goyal19ff7282021-04-22 10:12:54 -0700691 private final int numAllAppsColumns;
692 private final int numDatabaseAllAppsColumns;
693 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700694 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800695
Tracy Zhou7df93d22020-01-27 13:44:06 -0800696 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000697
Sunny Goyal415f1732018-11-29 10:33:47 -0800698 private final int defaultLayoutId;
699 private final int demoModeLayoutId;
700
Jon Mirandae126d722021-02-25 10:45:20 -0500701 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400702 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500703
Sunny Goyal5bc18462019-01-07 15:13:39 -0800704 private final SparseArray<TypedValue> extraAttrs;
705
Alex Chau1c883d82021-12-01 18:43:10 +0000706 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800707 TypedArray a = context.obtainStyledAttributes(
708 attrs, R.styleable.GridDisplayOption);
709 name = a.getString(R.styleable.GridDisplayOption_name);
710 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
711 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000712 numSearchContainerColumns = a.getInt(
713 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800714
Tracy Zhou7df93d22020-01-27 13:44:06 -0800715 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000716 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100717 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
718 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
719 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800720 demoModeLayoutId = a.getResourceId(
721 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700722
723 numAllAppsColumns = a.getInt(
724 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
725 numDatabaseAllAppsColumns = a.getInt(
726 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
727
728 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800729 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700730 numDatabaseHotseatIcons = a.getInt(
731 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
732
Sunny Goyal415f1732018-11-29 10:33:47 -0800733 numFolderRows = a.getInt(
734 R.styleable.GridDisplayOption_numFolderRows, numRows);
735 numFolderColumns = a.getInt(
736 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700737
Jon Mirandae126d722021-02-25 10:45:20 -0500738 isScalable = a.getBoolean(
739 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400740 devicePaddingId = a.getResourceId(
741 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500742
Alex Chau1c883d82021-12-01 18:43:10 +0000743 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
744 DEVICE_CATEGORY_ALL);
745 isEnabled = (deviceType == TYPE_PHONE
746 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
747 || (deviceType == TYPE_TABLET
748 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
749 || (deviceType == TYPE_MULTI_DISPLAY
750 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
751 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100752
Sunny Goyal415f1732018-11-29 10:33:47 -0800753 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800754 extraAttrs = Themes.createValueMap(context, attrs,
755 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800756 }
757 }
758
Sunny Goyal19ff7282021-04-22 10:12:54 -0700759 @VisibleForTesting
760 static final class DisplayOption {
761
762 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800763
Sunny Goyal415f1732018-11-29 10:33:47 -0800764 private final float minWidthDps;
765 private final float minHeightDps;
766 private final boolean canBeDefault;
767
Thales Lima83bedbf2021-10-05 17:47:39 +0100768 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100769
770 private float folderBorderSpace;
771 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100772 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000773 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100774
Thales Lima78d00ad2021-09-30 11:29:06 +0100775 private final float[] iconSizes = new float[COUNT_SIZES];
776 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800777
Thales Limabb7d3882021-12-22 12:56:29 +0000778 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
779 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
780 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
781
Thales Lima1de4d552021-10-13 16:13:25 +0100782 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800783 this.grid = grid;
784
Thales Lima1de4d552021-10-13 16:13:25 +0100785 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800786
Sunny Goyal415f1732018-11-29 10:33:47 -0800787 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
788 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700789
Thales Lima1de4d552021-10-13 16:13:25 +0100790 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800791
Thales Lima83bedbf2021-10-05 17:47:39 +0100792 float x;
793 float y;
794
Thales Lima85c942f2021-12-31 13:04:20 +0000795 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
796 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100797 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000798
799 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
800 minCellSize[INDEX_DEFAULT].x);
801 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
802 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100803 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100804
Thales Lima85c942f2021-12-31 13:04:20 +0000805 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100806 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000807 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100808 minCellSize[INDEX_DEFAULT].y);
809 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
810
Thales Lima85c942f2021-12-31 13:04:20 +0000811 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100812 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000813 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100814 minCellSize[INDEX_DEFAULT].y);
815 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100816
Thales Lima85c942f2021-12-31 13:04:20 +0000817 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
818 float borderSpaceTwoPanelPortrait = a.getFloat(
819 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
820 float borderSpaceTwoPanelLandscape = a.getFloat(
821 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100822
Thales Lima85c942f2021-12-31 13:04:20 +0000823 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
824 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100825 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
826 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
827
828 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000829 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
830 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100831 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000832 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
833 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100834 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
835
836 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000837 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
838 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100839 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000840 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
841 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100842 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
843
Thales Limabb7d3882021-12-22 12:56:29 +0000844 folderBorderSpace = borderSpace;
845
Thales Lima85c942f2021-12-31 13:04:20 +0000846 x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpace,
Thales Lima78d00ad2021-09-30 11:29:06 +0100847 borderSpace);
Thales Limabb7d3882021-12-22 12:56:29 +0000848 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
849 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
850 x = y = a.getFloat(
851 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
852 allAppsBorderSpaces[INDEX_DEFAULT].x);
853 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
854 x = y = a.getFloat(
855 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
856 allAppsBorderSpaces[INDEX_DEFAULT].x);
857 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500858
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700859 iconSizes[INDEX_DEFAULT] =
860 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
861 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000862 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700863 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700864 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000865 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700866 iconSizes[INDEX_DEFAULT]);
867 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000868 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100869 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700870
Thales Limabb7d3882021-12-22 12:56:29 +0000871 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
872 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
873 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
874 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
875 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
876 allAppsIconSizes[INDEX_DEFAULT]);
877 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
878 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
879 allAppsIconSizes[INDEX_DEFAULT]);
880
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700881 textSizes[INDEX_DEFAULT] =
882 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
883 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000884 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700885 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700886 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000887 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700888 textSizes[INDEX_DEFAULT]);
889 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000890 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100891 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700892
Thales Limabb7d3882021-12-22 12:56:29 +0000893 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
894 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
895 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
896 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
897 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
898 allAppsIconTextSizes[INDEX_DEFAULT]);
899 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
900 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
901 allAppsIconTextSizes[INDEX_DEFAULT]);
902
Thales Lima83bedbf2021-10-05 17:47:39 +0100903 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
904 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +0000905 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
906 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
907 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +0100908 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000909 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100910 horizontalMargin[INDEX_DEFAULT]);
911 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000912 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100913 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +0100914
Thales Lima6e7f36c2022-01-04 12:14:11 +0000915 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
916 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +0000917 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
918 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
919 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000920 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
921 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
922 hotseatBorderSpaces[INDEX_DEFAULT]);
923 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
924 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
925 hotseatBorderSpaces[INDEX_DEFAULT]);
926
Sunny Goyal415f1732018-11-29 10:33:47 -0800927 a.recycle();
928 }
929
930 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700931 this(null);
932 }
933
934 DisplayOption(GridOption grid) {
935 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800936 minWidthDps = 0;
937 minHeightDps = 0;
938 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +0100939 for (int i = 0; i < COUNT_SIZES; i++) {
940 iconSizes[i] = 0;
941 textSizes[i] = 0;
942 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +0100943 minCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +0000944 allAppsIconSizes[i] = 0;
945 allAppsIconTextSizes[i] = 0;
946 allAppsBorderSpaces[i] = new PointF();
Thales Lima78d00ad2021-09-30 11:29:06 +0100947 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800948 }
949
950 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100951 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700952 iconSizes[i] *= w;
953 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +0100954 borderSpaces[i].x *= w;
955 borderSpaces[i].y *= w;
956 minCellSize[i].x *= w;
957 minCellSize[i].y *= w;
958 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000959 hotseatBorderSpaces[i] *= w;
Thales Limabb7d3882021-12-22 12:56:29 +0000960 allAppsIconSizes[i] *= w;
961 allAppsIconTextSizes[i] *= w;
962 allAppsBorderSpaces[i].x *= w;
963 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700964 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100965
966 folderBorderSpace *= w;
967
Sunny Goyal415f1732018-11-29 10:33:47 -0800968 return this;
969 }
970
971 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100972 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700973 iconSizes[i] += p.iconSizes[i];
974 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +0100975 borderSpaces[i].x += p.borderSpaces[i].x;
976 borderSpaces[i].y += p.borderSpaces[i].y;
977 minCellSize[i].x += p.minCellSize[i].x;
978 minCellSize[i].y += p.minCellSize[i].y;
979 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000980 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limabb7d3882021-12-22 12:56:29 +0000981 allAppsIconSizes[i] += p.allAppsIconSizes[i];
982 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
983 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
984 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700985 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100986
987 folderBorderSpace += p.folderBorderSpace;
988
Sunny Goyal415f1732018-11-29 10:33:47 -0800989 return this;
990 }
991 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000992}