blob: 10b3f98d222fae4cb2afd70e1d982e61d21a3f4d [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
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;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070034import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080035import android.text.TextUtils;
36import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070037import android.util.DisplayMetrics;
Sunny Goyal5bc18462019-01-07 15:13:39 -080038import android.util.SparseArray;
39import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070040import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080041import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070042
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070043import androidx.annotation.Nullable;
44import androidx.annotation.VisibleForTesting;
45
Sunny Goyal68031ca2021-08-02 12:23:44 -070046import com.android.launcher3.model.DeviceGridState;
Sunny Goyalfd58da62020-08-11 12:06:49 -070047import com.android.launcher3.util.DisplayController;
48import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080049import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070050import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080051import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070052import com.android.launcher3.util.WindowBounds;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070053
Sunny Goyal819e1932016-07-07 16:43:58 -070054import org.xmlpull.v1.XmlPullParser;
55import org.xmlpull.v1.XmlPullParserException;
56
57import java.io.IOException;
Adam Cohen2e6da152015-05-06 11:42:25 -070058import java.util.ArrayList;
Sunny Goyal6d55f662019-01-02 12:13:43 -080059import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070060import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070061
62public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070063
Hyunyoung Songc55a3502018-12-04 15:43:16 -080064 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070065 // We do not need any synchronization for this variable as its only written on UI thread.
66 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070067 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070068
Sunny Goyal19ff7282021-04-22 10:12:54 -070069 private static final int DEFAULT_TRUE = -1;
70 private static final int DEFAULT_SPLIT_DISPLAY = 2;
71
Hyunyoung Songc55a3502018-12-04 15:43:16 -080072 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080073
Sunny Goyal53d7ee42015-05-22 12:25:45 -070074 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
75
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070076 // Constants that affects the interpolation curve between statically defined device profile
77 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080078 private static final float KNEARESTNEIGHBOR = 3;
79 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070081 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080082 private static final float WEIGHT_EFFICIENT = 100000f;
83
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070084 /**
85 * Number of icons per row and column in the workspace.
86 */
Adam Cohen2e6da152015-05-06 11:42:25 -070087 public int numRows;
88 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089
90 /**
91 * Number of icons per row and column in the folder.
92 */
Adam Cohen2e6da152015-05-06 11:42:25 -070093 public int numFolderRows;
94 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -070095 public float iconSize;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070096 public float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +020097 public float landscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -070098 public int iconBitmapSize;
99 public int fillResIconDpi;
100 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000101 public float allAppsIconSize;
102 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700103
Jon Mirandae126d722021-02-25 10:45:20 -0500104 public float minCellHeight;
105 public float minCellWidth;
106 public float borderSpacing;
107
Sunny Goyal5bc18462019-01-07 15:13:39 -0800108 private SparseArray<TypedValue> mExtraAttrs;
109
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700110 /**
111 * Number of icons inside the hotseat area.
112 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700113 protected int numShownHotseatIcons;
114
115 /**
116 * Number of icons inside the hotseat area that is stored in the database. This is greater than
117 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
118 * sizes that share the same DB.
119 */
120 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700121
Jon Miranda6f7e9702019-09-16 14:44:14 -0700122 /**
123 * Number of columns in the all apps list.
124 */
125 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700126 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700127
Jon Mirandae126d722021-02-25 10:45:20 -0500128 /**
129 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
130 */
131 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400132 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500133
Tracy Zhou7df93d22020-01-27 13:44:06 -0800134 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800135 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700136 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700137
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000138 /**
139 * An immutable list of supported profiles.
140 */
141 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700142
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400143 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500144
Sunny Goyal6f866092016-03-17 17:04:15 -0700145 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700146 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700147
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700148 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700149
Sunny Goyalf633ef52018-03-13 09:57:05 -0700150 @VisibleForTesting
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700151 public InvariantDeviceProfile() {}
Adam Cohen2e6da152015-05-06 11:42:25 -0700152
Sunny Goyalf633ef52018-03-13 09:57:05 -0700153 private InvariantDeviceProfile(InvariantDeviceProfile p) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800154 numRows = p.numRows;
155 numColumns = p.numColumns;
156 numFolderRows = p.numFolderRows;
157 numFolderColumns = p.numFolderColumns;
158 iconSize = p.iconSize;
159 landscapeIconSize = p.landscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500160 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800161 iconTextSize = p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200162 landscapeIconTextSize = p.landscapeIconTextSize;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700163 numShownHotseatIcons = p.numShownHotseatIcons;
164 numDatabaseHotseatIcons = p.numDatabaseHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700165 numAllAppsColumns = p.numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700166 numDatabaseAllAppsColumns = p.numDatabaseAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500167 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400168 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500169 minCellHeight = p.minCellHeight;
170 minCellWidth = p.minCellWidth;
171 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800172 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000173 allAppsIconSize = p.allAppsIconSize;
174 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800175 defaultLayoutId = p.defaultLayoutId;
176 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800177 mExtraAttrs = p.mExtraAttrs;
Jon Miranda228877d2021-02-09 11:05:00 -0500178 devicePaddings = p.devicePaddings;
Adam Cohen2e6da152015-05-06 11:42:25 -0700179 }
180
Sunny Goyalbbf01842015-10-08 07:41:15 -0700181 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700182 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700183 String gridName = getCurrentGridName(context);
184 String newGridName = initGrid(context, gridName);
185 if (!newGridName.equals(gridName)) {
186 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
187 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700188 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700189
Sunny Goyal35c7b192021-04-20 16:51:10 -0700190 DisplayController.INSTANCE.get(context).addChangeListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100191 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700192 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100193 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700194 }
195 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700196 }
197
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700198 /**
199 * This constructor should NOT have any monitors by design.
200 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800201 public InvariantDeviceProfile(Context context, String gridName) {
202 String newName = initGrid(context, gridName);
203 if (newName == null || !newName.equals(gridName)) {
204 throw new IllegalArgumentException("Unknown grid name");
205 }
206 }
207
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700208 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800209 * This constructor should NOT have any monitors by design.
210 */
211 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700212 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100213 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700214 String gridName = getCurrentGridName(context);
215
216 // Get the display info based on default display and interpolate it to existing display
217 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyal35c7b192021-04-20 16:51:10 -0700218 DisplayController.INSTANCE.get(context).getInfo(),
Sunny Goyal19ff7282021-04-22 10:12:54 -0700219 getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220
Alex Chau417bd722021-01-26 15:22:18 +0000221 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700222 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700223 myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700224
225 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
226 .add(myDisplayOption);
227 result.iconSize = defaultDisplayOption.iconSize;
228 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000229 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
230 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000231 } else {
232 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000233 }
Jon Mirandae126d722021-02-25 10:45:20 -0500234 result.minCellHeight = defaultDisplayOption.minCellHeight;
235 result.minCellWidth = defaultDisplayOption.minCellWidth;
236 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500237
Sunny Goyal19ff7282021-04-22 10:12:54 -0700238 initGrid(context, myInfo, result, false);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800239 }
240
Tracy Zhou42255d22020-03-13 00:38:11 -0700241 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700242 return Utilities.isGridOptionsEnabled(context)
243 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700244 }
245
Sunny Goyaleff44f32019-01-09 17:29:49 -0800246 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700247 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Pat Manning67094bf2021-05-26 12:38:13 +0000248 // Each screen has two profiles (portrait/landscape), so devices with four or more
249 // supported profiles implies two or more internal displays.
250 boolean isSplitDisplay =
251 displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700252
253 ArrayList<DisplayOption> allOptions =
254 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
255 DisplayOption displayOption =
256 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
257 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800259 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700260
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700262 Context context, Info displayInfo, DisplayOption displayOption,
263 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700264 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700265 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000266 numRows = closestProfile.numRows;
267 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000268 dbFile = closestProfile.dbFile;
269 defaultLayoutId = closestProfile.defaultLayoutId;
270 demoModeLayoutId = closestProfile.demoModeLayoutId;
271 numFolderRows = closestProfile.numFolderRows;
272 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500273 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400274 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000275
276 mExtraAttrs = closestProfile.extraAttrs;
277
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700278 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700279 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700280 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200282 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000283 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
284
Jon Mirandae126d722021-02-25 10:45:20 -0500285 minCellHeight = displayOption.minCellHeight;
286 minCellWidth = displayOption.minCellWidth;
287 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700288
289 numShownHotseatIcons = closestProfile.numHotseatIcons;
290 numDatabaseHotseatIcons = isSplitDisplay
291 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
292
293 numAllAppsColumns = closestProfile.numAllAppsColumns;
294 numDatabaseAllAppsColumns = isSplitDisplay
295 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500296
Tracy Zhouc6060e62020-04-27 13:05:34 -0700297 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700298 allAppsIconSize = displayOption.allAppsIconSize;
299 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000300 } else {
301 allAppsIconSize = iconSize;
302 allAppsIconTextSize = iconTextSize;
303 }
304
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400305 if (devicePaddingId != 0) {
306 devicePaddings = new DevicePaddings(context, devicePaddingId);
307 }
308
Sunny Goyalae190ff2020-04-14 00:19:01 +0000309 // If the partner customization apk contains any grid overrides, apply them
310 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700311 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700312
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000313 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700314 defaultWallpaperSize = new Point(displayInfo.currentSize);
315 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000316 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700317 .setUseTwoPanels(isSplitDisplay)
318 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700319
Sunny Goyal19ff7282021-04-22 10:12:54 -0700320 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
321 int displayWidth = bounds.bounds.width();
322 int displayHeight = bounds.bounds.height();
323 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700324
Sunny Goyal19ff7282021-04-22 10:12:54 -0700325 // We need to ensure that there is enough extra space in the wallpaper
326 // for the intended parallax effects
327 float parallaxFactor =
328 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
329 ? 2
330 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
331 defaultWallpaperSize.x =
332 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700333 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000334 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700335
336 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
337 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700338 }
339
Sunny Goyal5bc18462019-01-07 15:13:39 -0800340 @Nullable
341 public TypedValue getAttrValue(int attr) {
342 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
343 }
344
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700345 public void addOnChangeListener(OnIDPChangeListener listener) {
346 mChangeListeners.add(listener);
347 }
348
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800349 public void removeOnChangeListener(OnIDPChangeListener listener) {
350 mChangeListeners.remove(listener);
351 }
352
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800353
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800354 public void setCurrentGrid(Context context, String gridName) {
355 Context appContext = context.getApplicationContext();
356 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700357 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800358 }
359
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700360 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700361 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700362 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700363 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700364
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700365 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700366 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700367 }
368 }
369
Sunny Goyal19ff7282021-04-22 10:12:54 -0700370 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
371 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800372 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700373 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
374 final int depth = parser.getDepth();
375 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700376 while (((type = parser.next()) != XmlPullParser.END_TAG ||
377 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800378 if ((type == XmlPullParser.START_TAG)
379 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800380
381 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
382 final int displayDepth = parser.getDepth();
383 while (((type = parser.next()) != XmlPullParser.END_TAG ||
384 parser.getDepth() > displayDepth)
385 && type != XmlPullParser.END_DOCUMENT) {
386 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
387 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700388 profiles.add(new DisplayOption(gridOption, context,
389 Xml.asAttributeSet(parser),
390 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800391 }
392 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700393 }
394 }
395 } catch (IOException|XmlPullParserException e) {
396 throw new RuntimeException(e);
397 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800398
Sunny Goyalae190ff2020-04-14 00:19:01 +0000399 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800400 if (!TextUtils.isEmpty(gridName)) {
401 for (DisplayOption option : profiles) {
402 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000403 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800404 }
405 }
406 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000407 if (filteredProfiles.isEmpty()) {
408 // No grid found, use the default options
409 for (DisplayOption option : profiles) {
410 if (option.canBeDefault) {
411 filteredProfiles.add(option);
412 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800413 }
414 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000415 if (filteredProfiles.isEmpty()) {
416 throw new RuntimeException("No display option with canBeDefault=true");
417 }
418 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700419 }
420
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700421 private int getLauncherIconDensity(int requiredSize) {
422 // Densities typically defined by an app.
423 int[] densityBuckets = new int[] {
424 DisplayMetrics.DENSITY_LOW,
425 DisplayMetrics.DENSITY_MEDIUM,
426 DisplayMetrics.DENSITY_TV,
427 DisplayMetrics.DENSITY_HIGH,
428 DisplayMetrics.DENSITY_XHIGH,
429 DisplayMetrics.DENSITY_XXHIGH,
430 DisplayMetrics.DENSITY_XXXHIGH
431 };
432
433 int density = DisplayMetrics.DENSITY_XXXHIGH;
434 for (int i = densityBuckets.length - 1; i >= 0; i--) {
435 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
436 / DisplayMetrics.DENSITY_DEFAULT;
437 if (expectedSize >= requiredSize) {
438 density = densityBuckets[i];
439 }
440 }
441
442 return density;
443 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700444
Adam Cohen2e6da152015-05-06 11:42:25 -0700445 /**
446 * Apply any Partner customization grid overrides.
447 *
448 * Currently we support: all apps row / column count.
449 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700450 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
451 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700452 if (p != null) {
453 p.applyInvariantDeviceProfileOverrides(this, dm);
454 }
455 }
456
Sunny Goyal415f1732018-11-29 10:33:47 -0800457 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700458 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700459 }
460
Sunny Goyal19ff7282021-04-22 10:12:54 -0700461 private static DisplayOption invDistWeightedInterpolate(
462 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
463 int minWidthPx = Integer.MAX_VALUE;
464 int minHeightPx = Integer.MAX_VALUE;
465 for (WindowBounds bounds : displayInfo.supportedBounds) {
466 boolean isTablet = displayInfo.isTablet(bounds);
467 if (isTablet && isSplitDisplay) {
468 // For split displays, take half width per page
469 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
470 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700471
Sunny Goyal19ff7282021-04-22 10:12:54 -0700472 } else if (!isTablet && bounds.isLandscape()) {
473 // We will use transposed layout in this case
474 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
475 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
476 } else {
477 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
478 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
479 }
480 }
481
482 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
483 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700484
485 // Sort the profiles based on the closeness to the device size
486 Collections.sort(points, (a, b) ->
487 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
488 dist(width, height, b.minWidthDps, b.minHeightDps)));
489
490 GridOption closestOption = points.get(0).grid;
491 float weights = 0;
492
493 DisplayOption p = points.get(0);
494 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
495 return p;
496 }
497
498 DisplayOption out = new DisplayOption(closestOption);
499 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
500 p = points.get(i);
501 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
502 weights += w;
503 out.add(new DisplayOption().add(p).multiply(w));
504 }
505 return out.multiply(1.0f / weights);
506 }
507
Sunny Goyal27835952017-01-13 12:15:53 -0800508 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700509 Resources res = context.getResources();
510 Configuration config = context.getResources().getConfiguration();
511
512 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
513 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
514
Sunny Goyal19ff7282021-04-22 10:12:54 -0700515 DeviceProfile bestMatch = supportedProfiles.get(0);
516 float minDiff = Float.MAX_VALUE;
517
518 for (DeviceProfile profile : supportedProfiles) {
519 float diff = Math.abs(profile.availableWidthPx - availableWidth)
520 + Math.abs(profile.availableHeightPx - availableHeight);
521 if (diff < minDiff) {
522 minDiff = diff;
523 bestMatch = profile;
524 }
525 }
526 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800527 }
528
Sunny Goyal415f1732018-11-29 10:33:47 -0800529 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700530 float d = dist(x0, y0, x1, y1);
531 if (Float.compare(d, 0f) == 0) {
532 return Float.POSITIVE_INFINITY;
533 }
534 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
535 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700536
537 /**
538 * As a ratio of screen height, the total distance we want the parallax effect to span
539 * horizontally
540 */
541 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
542 float aspectRatio = width / (float) height;
543
544 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
545 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
546 // We will use these two data points to extrapolate how much the wallpaper parallax effect
547 // to span (ie travel) at any aspect ratio:
548
549 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
550 final float ASPECT_RATIO_PORTRAIT = 10/16f;
551 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
552 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
553
554 // To find out the desired width at different aspect ratios, we use the following two
555 // formulas, where the coefficient on x is the aspect ratio (width/height):
556 // (16/10)x + y = 1.5
557 // (10/16)x + y = 1.2
558 // We solve for x and y and end up with a final formula:
559 final float x =
560 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
561 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
562 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
563 return x * aspectRatio + y;
564 }
565
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700566 public interface OnIDPChangeListener {
567
Sunny Goyalb47172b2021-05-03 19:59:51 -0700568 /**
569 * Called when the device provide changes
570 */
571 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700572 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800573
574
Sunny Goyaleff44f32019-01-09 17:29:49 -0800575 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800576
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800577 public static final String TAG_NAME = "grid-option";
578
Sunny Goyaleff44f32019-01-09 17:29:49 -0800579 public final String name;
580 public final int numRows;
581 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800582
583 private final int numFolderRows;
584 private final int numFolderColumns;
585
Sunny Goyal19ff7282021-04-22 10:12:54 -0700586 private final int numAllAppsColumns;
587 private final int numDatabaseAllAppsColumns;
588 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700589 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800590
Tracy Zhou7df93d22020-01-27 13:44:06 -0800591 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000592
Sunny Goyal415f1732018-11-29 10:33:47 -0800593 private final int defaultLayoutId;
594 private final int demoModeLayoutId;
595
Jon Mirandae126d722021-02-25 10:45:20 -0500596 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400597 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500598
Sunny Goyal5bc18462019-01-07 15:13:39 -0800599 private final SparseArray<TypedValue> extraAttrs;
600
Sunny Goyaleff44f32019-01-09 17:29:49 -0800601 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800602 TypedArray a = context.obtainStyledAttributes(
603 attrs, R.styleable.GridDisplayOption);
604 name = a.getString(R.styleable.GridDisplayOption_name);
605 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
606 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
607
Tracy Zhou7df93d22020-01-27 13:44:06 -0800608 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800609 defaultLayoutId = a.getResourceId(
610 R.styleable.GridDisplayOption_defaultLayoutId, 0);
611 demoModeLayoutId = a.getResourceId(
612 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700613
614 numAllAppsColumns = a.getInt(
615 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
616 numDatabaseAllAppsColumns = a.getInt(
617 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
618
619 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800620 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700621 numDatabaseHotseatIcons = a.getInt(
622 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
623
Sunny Goyal415f1732018-11-29 10:33:47 -0800624 numFolderRows = a.getInt(
625 R.styleable.GridDisplayOption_numFolderRows, numRows);
626 numFolderColumns = a.getInt(
627 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700628
Jon Mirandae126d722021-02-25 10:45:20 -0500629 isScalable = a.getBoolean(
630 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400631 devicePaddingId = a.getResourceId(
632 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500633
Sunny Goyal415f1732018-11-29 10:33:47 -0800634 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800635 extraAttrs = Themes.createValueMap(context, attrs,
636 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800637 }
638 }
639
Sunny Goyal19ff7282021-04-22 10:12:54 -0700640 @VisibleForTesting
641 static final class DisplayOption {
642
643 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800644
Sunny Goyal415f1732018-11-29 10:33:47 -0800645 private final float minWidthDps;
646 private final float minHeightDps;
647 private final boolean canBeDefault;
648
Jon Mirandae126d722021-02-25 10:45:20 -0500649 private float minCellHeight;
650 private float minCellWidth;
651 private float borderSpacing;
652
Sunny Goyal415f1732018-11-29 10:33:47 -0800653 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800654 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700655 private float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200656 private float landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000657 private float allAppsIconSize;
658 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800659
Sunny Goyal19ff7282021-04-22 10:12:54 -0700660 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800661 this.grid = grid;
662
663 TypedArray a = context.obtainStyledAttributes(
664 attrs, R.styleable.ProfileDisplayOption);
665
Sunny Goyal415f1732018-11-29 10:33:47 -0800666 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
667 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700668
669 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
670 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800671
Jon Mirandae126d722021-02-25 10:45:20 -0500672 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
673 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
674 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
675
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700676 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800677 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
678 iconSize);
679 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200680 landscapeIconTextSize = a.getFloat(
681 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700682
Sunny Goyalae190ff2020-04-14 00:19:01 +0000683 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
684 iconSize);
685 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
686 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800687 a.recycle();
688 }
689
690 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700691 this(null);
692 }
693
694 DisplayOption(GridOption grid) {
695 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800696 minWidthDps = 0;
697 minHeightDps = 0;
698 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500699 minCellHeight = 0;
700 minCellWidth = 0;
701 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800702 }
703
704 private DisplayOption multiply(float w) {
705 iconSize *= w;
706 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000707 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800708 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200709 landscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000710 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500711 minCellHeight *= w;
712 minCellWidth *= w;
713 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800714 return this;
715 }
716
717 private DisplayOption add(DisplayOption p) {
718 iconSize += p.iconSize;
719 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000720 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800721 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200722 landscapeIconTextSize += p.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000723 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500724 minCellHeight += p.minCellHeight;
725 minCellWidth += p.minCellWidth;
726 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800727 return this;
728 }
729 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000730}