blob: a3817878044b22ad89ecc791764c5dc0848d9d2a [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) {
253 String currentDbFile = dbFile;
254 String gridName = getCurrentGridName(context);
255 String newGridName = initGrid(context, gridName);
256 if (!newGridName.equals(gridName)) {
257 Log.d(TAG, "Restored grid is disabled : " + gridName
258 + ", migrating to: " + newGridName
259 + ", removing all other grid db files");
260 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
261 if (gridDbFile.equals(currentDbFile)) {
262 continue;
263 }
264 if (context.getDatabasePath(gridDbFile).delete()) {
265 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
266 }
267 }
268 setCurrentGrid(context, gridName);
269 }
270 }
271
Alex Chau1c883d82021-12-01 18:43:10 +0000272 private static @DeviceType int getDeviceType(Info displayInfo) {
273 // Each screen has two profiles (portrait/landscape), so devices with four or more
274 // supported profiles implies two or more internal displays.
275 if (displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get()) {
276 return TYPE_MULTI_DISPLAY;
277 } else if (displayInfo.supportedBounds.stream().allMatch(displayInfo::isTablet)) {
278 return TYPE_TABLET;
279 } else {
280 return TYPE_PHONE;
281 }
282 }
283
Tracy Zhou42255d22020-03-13 00:38:11 -0700284 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700285 return Utilities.isGridOptionsEnabled(context)
286 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700287 }
288
Sunny Goyaleff44f32019-01-09 17:29:49 -0800289 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700290 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000291 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700292
293 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000294 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100295 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700296 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000297 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
298 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700299 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800300 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700301
Alex Chau1c883d82021-12-01 18:43:10 +0000302 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
303 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700304 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700305 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000306 numRows = closestProfile.numRows;
307 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000308 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000309 dbFile = closestProfile.dbFile;
310 defaultLayoutId = closestProfile.defaultLayoutId;
311 demoModeLayoutId = closestProfile.demoModeLayoutId;
312 numFolderRows = closestProfile.numFolderRows;
313 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500314 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400315 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000316 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000317
318 mExtraAttrs = closestProfile.extraAttrs;
319
Thales Lima83bedbf2021-10-05 17:47:39 +0100320 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100321 float maxIconSize = iconSize[0];
322 for (int i = 1; i < iconSize.length; i++) {
323 maxIconSize = Math.max(maxIconSize, iconSize[i]);
324 }
325 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000326 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
327
Thales Lima83bedbf2021-10-05 17:47:39 +0100328 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700329
Thales Lima83bedbf2021-10-05 17:47:39 +0100330 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100331
Thales Lima83bedbf2021-10-05 17:47:39 +0100332 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100333 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700334
Thales Limad90faab2021-09-21 17:18:47 +0100335 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100336
Sunny Goyal19ff7282021-04-22 10:12:54 -0700337 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000338 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700339 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000340 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700341
342 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000343 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700344 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500345
Thales Limabb7d3882021-12-22 12:56:29 +0000346 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
347 allAppsIconSize = displayOption.allAppsIconSizes;
348 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100349 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000350 allAppsIconSize = iconSize;
351 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000352 }
353
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400354 if (devicePaddingId != 0) {
355 devicePaddings = new DevicePaddings(context, devicePaddingId);
356 }
357
Sunny Goyalae190ff2020-04-14 00:19:01 +0000358 // If the partner customization apk contains any grid overrides, apply them
359 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700360 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700361
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000362 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700363 defaultWallpaperSize = new Point(displayInfo.currentSize);
364 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000365 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000366 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700367 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700368
Sunny Goyal19ff7282021-04-22 10:12:54 -0700369 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
370 int displayWidth = bounds.bounds.width();
371 int displayHeight = bounds.bounds.height();
372 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700373
Sunny Goyal19ff7282021-04-22 10:12:54 -0700374 // We need to ensure that there is enough extra space in the wallpaper
375 // for the intended parallax effects
376 float parallaxFactor =
377 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
378 ? 2
379 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
380 defaultWallpaperSize.x =
381 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700382 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000383 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700384
385 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
386 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700387 }
388
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700389 public void addOnChangeListener(OnIDPChangeListener listener) {
390 mChangeListeners.add(listener);
391 }
392
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800393 public void removeOnChangeListener(OnIDPChangeListener listener) {
394 mChangeListeners.remove(listener);
395 }
396
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800397
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800398 public void setCurrentGrid(Context context, String gridName) {
399 Context appContext = context.getApplicationContext();
400 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700401 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800402 }
403
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700404 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700405 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000406 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
407 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700408 }
409
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700410 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700411 Object[] oldState = toModelState();
412
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700413 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700414 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700415 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700416
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700417 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700418 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700419 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700420 }
421 }
422
Alex Chau1c883d82021-12-01 18:43:10 +0000423 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
424 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800425 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100426
Alex Chau1c883d82021-12-01 18:43:10 +0000427 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700428 final int depth = parser.getDepth();
429 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700430 while (((type = parser.next()) != XmlPullParser.END_TAG ||
431 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800432 if ((type == XmlPullParser.START_TAG)
433 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800434
Alex Chau1c883d82021-12-01 18:43:10 +0000435 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
436 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100437 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100438 final int displayDepth = parser.getDepth();
439 while (((type = parser.next()) != XmlPullParser.END_TAG
440 || parser.getDepth() > displayDepth)
441 && type != XmlPullParser.END_DOCUMENT) {
442 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
443 parser.getName())) {
444 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100445 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100446 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800447 }
448 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700449 }
450 }
sfufa@google.comde013292021-09-21 18:22:44 -0700451 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700452 throw new RuntimeException(e);
453 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800454
Sunny Goyalae190ff2020-04-14 00:19:01 +0000455 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800456 if (!TextUtils.isEmpty(gridName)) {
457 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100458 if (gridName.equals(option.grid.name)
459 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000460 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800461 }
462 }
463 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000464 if (filteredProfiles.isEmpty()) {
465 // No grid found, use the default options
466 for (DisplayOption option : profiles) {
467 if (option.canBeDefault) {
468 filteredProfiles.add(option);
469 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800470 }
471 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000472 if (filteredProfiles.isEmpty()) {
473 throw new RuntimeException("No display option with canBeDefault=true");
474 }
475 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700476 }
477
Thales Lima7ec83822021-08-05 13:32:10 +0100478 /**
479 * @return all the grid options that can be shown on the device
480 */
481 public List<GridOption> parseAllGridOptions(Context context) {
482 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100483
Alex Chau1c883d82021-12-01 18:43:10 +0000484 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100485 final int depth = parser.getDepth();
486 int type;
487 while (((type = parser.next()) != XmlPullParser.END_TAG
488 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
489 if ((type == XmlPullParser.START_TAG)
490 && GridOption.TAG_NAME.equals(parser.getName())) {
491 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000492 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100493 if (option.isEnabled) {
494 result.add(option);
495 }
496 }
497 }
498 } catch (IOException | XmlPullParserException e) {
499 Log.e(TAG, "Error parsing device profile", e);
500 return Collections.emptyList();
501 }
502 return result;
503 }
504
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700505 private int getLauncherIconDensity(int requiredSize) {
506 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700507 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700508 DisplayMetrics.DENSITY_LOW,
509 DisplayMetrics.DENSITY_MEDIUM,
510 DisplayMetrics.DENSITY_TV,
511 DisplayMetrics.DENSITY_HIGH,
512 DisplayMetrics.DENSITY_XHIGH,
513 DisplayMetrics.DENSITY_XXHIGH,
514 DisplayMetrics.DENSITY_XXXHIGH
515 };
516
517 int density = DisplayMetrics.DENSITY_XXXHIGH;
518 for (int i = densityBuckets.length - 1; i >= 0; i--) {
519 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
520 / DisplayMetrics.DENSITY_DEFAULT;
521 if (expectedSize >= requiredSize) {
522 density = densityBuckets[i];
523 }
524 }
525
526 return density;
527 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700528
Adam Cohen2e6da152015-05-06 11:42:25 -0700529 /**
530 * Apply any Partner customization grid overrides.
531 *
532 * Currently we support: all apps row / column count.
533 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700534 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
535 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700536 if (p != null) {
537 p.applyInvariantDeviceProfileOverrides(this, dm);
538 }
539 }
540
Sunny Goyal415f1732018-11-29 10:33:47 -0800541 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700542 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700543 }
544
Sunny Goyal19ff7282021-04-22 10:12:54 -0700545 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000546 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700547 int minWidthPx = Integer.MAX_VALUE;
548 int minHeightPx = Integer.MAX_VALUE;
549 for (WindowBounds bounds : displayInfo.supportedBounds) {
550 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000551 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700552 // For split displays, take half width per page
553 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
554 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700555
Sunny Goyal19ff7282021-04-22 10:12:54 -0700556 } else if (!isTablet && bounds.isLandscape()) {
557 // We will use transposed layout in this case
558 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
559 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
560 } else {
561 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
562 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
563 }
564 }
565
566 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
567 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700568
569 // Sort the profiles based on the closeness to the device size
570 Collections.sort(points, (a, b) ->
571 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
572 dist(width, height, b.minWidthDps, b.minHeightDps)));
573
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700574 DisplayOption closestPoint = points.get(0);
575 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700576 float weights = 0;
577
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700578 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
579 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700580 }
581
582 DisplayOption out = new DisplayOption(closestOption);
583 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700584 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700585 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
586 weights += w;
587 out.add(new DisplayOption().add(p).multiply(w));
588 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700589 out.multiply(1.0f / weights);
590
Thales Lima6e0005a2021-10-27 15:53:41 +0100591 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700592 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100593 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
594 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700595 }
596
597 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700598 }
599
Sunny Goyal27835952017-01-13 12:15:53 -0800600 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700601 Resources res = context.getResources();
602 Configuration config = context.getResources().getConfiguration();
603
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400604 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
605 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
606 return getBestMatch(screenWidth, screenHeight);
607 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700608
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400609 public DeviceProfile getBestMatch(float screenWidth, float screenHeight) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700610 DeviceProfile bestMatch = supportedProfiles.get(0);
611 float minDiff = Float.MAX_VALUE;
612
613 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400614 float diff = Math.abs(profile.widthPx - screenWidth)
615 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700616 if (diff < minDiff) {
617 minDiff = diff;
618 bestMatch = profile;
619 }
620 }
621 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800622 }
623
Sunny Goyal415f1732018-11-29 10:33:47 -0800624 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700625 float d = dist(x0, y0, x1, y1);
626 if (Float.compare(d, 0f) == 0) {
627 return Float.POSITIVE_INFINITY;
628 }
629 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
630 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700631
632 /**
633 * As a ratio of screen height, the total distance we want the parallax effect to span
634 * horizontally
635 */
636 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
637 float aspectRatio = width / (float) height;
638
639 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
640 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
641 // We will use these two data points to extrapolate how much the wallpaper parallax effect
642 // to span (ie travel) at any aspect ratio:
643
sfufa@google.comde013292021-09-21 18:22:44 -0700644 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
645 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700646 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
647 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
648
649 // To find out the desired width at different aspect ratios, we use the following two
650 // formulas, where the coefficient on x is the aspect ratio (width/height):
651 // (16/10)x + y = 1.5
652 // (10/16)x + y = 1.2
653 // We solve for x and y and end up with a final formula:
654 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700655 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
656 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700657 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
658 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
659 return x * aspectRatio + y;
660 }
661
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700662 public interface OnIDPChangeListener {
663
Sunny Goyalb47172b2021-05-03 19:59:51 -0700664 /**
665 * Called when the device provide changes
666 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700667 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700668 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800669
670
Sunny Goyaleff44f32019-01-09 17:29:49 -0800671 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800672
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800673 public static final String TAG_NAME = "grid-option";
674
Alex Chau1c883d82021-12-01 18:43:10 +0000675 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
676 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
677 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
678 private static final int DEVICE_CATEGORY_ALL =
679 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
680
Sunny Goyaleff44f32019-01-09 17:29:49 -0800681 public final String name;
682 public final int numRows;
683 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000684 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100685 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800686
687 private final int numFolderRows;
688 private final int numFolderColumns;
689
Sunny Goyal19ff7282021-04-22 10:12:54 -0700690 private final int numAllAppsColumns;
691 private final int numDatabaseAllAppsColumns;
692 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700693 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800694
Tracy Zhou7df93d22020-01-27 13:44:06 -0800695 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000696
Sunny Goyal415f1732018-11-29 10:33:47 -0800697 private final int defaultLayoutId;
698 private final int demoModeLayoutId;
699
Jon Mirandae126d722021-02-25 10:45:20 -0500700 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400701 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500702
Sunny Goyal5bc18462019-01-07 15:13:39 -0800703 private final SparseArray<TypedValue> extraAttrs;
704
Alex Chau1c883d82021-12-01 18:43:10 +0000705 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800706 TypedArray a = context.obtainStyledAttributes(
707 attrs, R.styleable.GridDisplayOption);
708 name = a.getString(R.styleable.GridDisplayOption_name);
709 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
710 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000711 numSearchContainerColumns = a.getInt(
712 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800713
Tracy Zhou7df93d22020-01-27 13:44:06 -0800714 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000715 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100716 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
717 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
718 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800719 demoModeLayoutId = a.getResourceId(
720 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700721
722 numAllAppsColumns = a.getInt(
723 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
724 numDatabaseAllAppsColumns = a.getInt(
725 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
726
727 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800728 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700729 numDatabaseHotseatIcons = a.getInt(
730 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
731
Sunny Goyal415f1732018-11-29 10:33:47 -0800732 numFolderRows = a.getInt(
733 R.styleable.GridDisplayOption_numFolderRows, numRows);
734 numFolderColumns = a.getInt(
735 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700736
Jon Mirandae126d722021-02-25 10:45:20 -0500737 isScalable = a.getBoolean(
738 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400739 devicePaddingId = a.getResourceId(
740 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500741
Alex Chau1c883d82021-12-01 18:43:10 +0000742 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
743 DEVICE_CATEGORY_ALL);
744 isEnabled = (deviceType == TYPE_PHONE
745 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
746 || (deviceType == TYPE_TABLET
747 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
748 || (deviceType == TYPE_MULTI_DISPLAY
749 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
750 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100751
Sunny Goyal415f1732018-11-29 10:33:47 -0800752 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800753 extraAttrs = Themes.createValueMap(context, attrs,
754 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800755 }
756 }
757
Sunny Goyal19ff7282021-04-22 10:12:54 -0700758 @VisibleForTesting
759 static final class DisplayOption {
760
761 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800762
Sunny Goyal415f1732018-11-29 10:33:47 -0800763 private final float minWidthDps;
764 private final float minHeightDps;
765 private final boolean canBeDefault;
766
Thales Lima83bedbf2021-10-05 17:47:39 +0100767 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100768
769 private float folderBorderSpace;
770 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100771 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000772 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100773
Thales Lima78d00ad2021-09-30 11:29:06 +0100774 private final float[] iconSizes = new float[COUNT_SIZES];
775 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800776
Thales Limabb7d3882021-12-22 12:56:29 +0000777 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
778 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
779 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
780
Thales Lima1de4d552021-10-13 16:13:25 +0100781 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800782 this.grid = grid;
783
Thales Lima1de4d552021-10-13 16:13:25 +0100784 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800785
Sunny Goyal415f1732018-11-29 10:33:47 -0800786 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
787 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700788
Thales Lima1de4d552021-10-13 16:13:25 +0100789 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800790
Thales Lima83bedbf2021-10-05 17:47:39 +0100791 float x;
792 float y;
793
Thales Lima85c942f2021-12-31 13:04:20 +0000794 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
795 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100796 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000797
798 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
799 minCellSize[INDEX_DEFAULT].x);
800 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
801 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100802 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100803
Thales Lima85c942f2021-12-31 13:04:20 +0000804 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100805 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000806 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100807 minCellSize[INDEX_DEFAULT].y);
808 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
809
Thales Lima85c942f2021-12-31 13:04:20 +0000810 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100811 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000812 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100813 minCellSize[INDEX_DEFAULT].y);
814 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100815
Thales Lima85c942f2021-12-31 13:04:20 +0000816 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
817 float borderSpaceTwoPanelPortrait = a.getFloat(
818 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
819 float borderSpaceTwoPanelLandscape = a.getFloat(
820 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100821
Thales Lima85c942f2021-12-31 13:04:20 +0000822 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
823 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100824 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
825 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
826
827 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000828 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
829 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100830 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000831 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
832 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100833 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
834
835 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000836 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
837 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100838 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000839 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
840 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100841 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
842
Thales Limabb7d3882021-12-22 12:56:29 +0000843 folderBorderSpace = borderSpace;
844
Thales Lima85c942f2021-12-31 13:04:20 +0000845 x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpace,
Thales Lima78d00ad2021-09-30 11:29:06 +0100846 borderSpace);
Thales Limabb7d3882021-12-22 12:56:29 +0000847 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
848 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
849 x = y = a.getFloat(
850 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
851 allAppsBorderSpaces[INDEX_DEFAULT].x);
852 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
853 x = y = a.getFloat(
854 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
855 allAppsBorderSpaces[INDEX_DEFAULT].x);
856 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500857
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700858 iconSizes[INDEX_DEFAULT] =
859 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
860 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000861 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700862 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700863 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000864 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700865 iconSizes[INDEX_DEFAULT]);
866 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000867 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100868 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700869
Thales Limabb7d3882021-12-22 12:56:29 +0000870 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
871 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
872 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
873 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
874 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
875 allAppsIconSizes[INDEX_DEFAULT]);
876 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
877 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
878 allAppsIconSizes[INDEX_DEFAULT]);
879
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700880 textSizes[INDEX_DEFAULT] =
881 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
882 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000883 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700884 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700885 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000886 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700887 textSizes[INDEX_DEFAULT]);
888 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000889 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100890 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700891
Thales Limabb7d3882021-12-22 12:56:29 +0000892 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
893 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
894 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
895 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
896 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
897 allAppsIconTextSizes[INDEX_DEFAULT]);
898 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
899 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
900 allAppsIconTextSizes[INDEX_DEFAULT]);
901
Thales Lima83bedbf2021-10-05 17:47:39 +0100902 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
903 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +0000904 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
905 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
906 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +0100907 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000908 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100909 horizontalMargin[INDEX_DEFAULT]);
910 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000911 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100912 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +0100913
Thales Lima6e7f36c2022-01-04 12:14:11 +0000914 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
915 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +0000916 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
917 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
918 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000919 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
920 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
921 hotseatBorderSpaces[INDEX_DEFAULT]);
922 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
923 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
924 hotseatBorderSpaces[INDEX_DEFAULT]);
925
Sunny Goyal415f1732018-11-29 10:33:47 -0800926 a.recycle();
927 }
928
929 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700930 this(null);
931 }
932
933 DisplayOption(GridOption grid) {
934 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800935 minWidthDps = 0;
936 minHeightDps = 0;
937 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +0100938 for (int i = 0; i < COUNT_SIZES; i++) {
939 iconSizes[i] = 0;
940 textSizes[i] = 0;
941 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +0100942 minCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +0000943 allAppsIconSizes[i] = 0;
944 allAppsIconTextSizes[i] = 0;
945 allAppsBorderSpaces[i] = new PointF();
Thales Lima78d00ad2021-09-30 11:29:06 +0100946 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800947 }
948
949 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100950 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700951 iconSizes[i] *= w;
952 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +0100953 borderSpaces[i].x *= w;
954 borderSpaces[i].y *= w;
955 minCellSize[i].x *= w;
956 minCellSize[i].y *= w;
957 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000958 hotseatBorderSpaces[i] *= w;
Thales Limabb7d3882021-12-22 12:56:29 +0000959 allAppsIconSizes[i] *= w;
960 allAppsIconTextSizes[i] *= w;
961 allAppsBorderSpaces[i].x *= w;
962 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700963 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100964
965 folderBorderSpace *= w;
966
Sunny Goyal415f1732018-11-29 10:33:47 -0800967 return this;
968 }
969
970 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100971 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700972 iconSizes[i] += p.iconSizes[i];
973 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +0100974 borderSpaces[i].x += p.borderSpaces[i].x;
975 borderSpaces[i].y += p.borderSpaces[i].y;
976 minCellSize[i].x += p.minCellSize[i].x;
977 minCellSize[i].y += p.minCellSize[i].y;
978 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000979 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limabb7d3882021-12-22 12:56:29 +0000980 allAppsIconSizes[i] += p.allAppsIconSizes[i];
981 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
982 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
983 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700984 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100985
986 folderBorderSpace += p.folderBorderSpace;
987
Sunny Goyal415f1732018-11-29 10:33:47 -0800988 return this;
989 }
990 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000991}