blob: 115d3aeebb8cf82e74010429936cb0c01706b210 [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;
Tracy Zhoued5f3082020-04-20 01:13:26 -070020import static com.android.launcher3.Utilities.getPointString;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010021import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Sunny Goyal19ff7282021-04-22 10:12:54 -070023import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080024import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070025
Sunny Goyalc6205602015-05-21 20:46:33 -070026import android.annotation.TargetApi;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070027import android.appwidget.AppWidgetHostView;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070028import android.content.ComponentName;
Adam Cohen2e6da152015-05-06 11:42:25 -070029import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080030import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
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;
Sunny Goyal5bc18462019-01-07 15:13:39 -080039import android.util.SparseArray;
40import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070041import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080042import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070043
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070044import androidx.annotation.Nullable;
45import androidx.annotation.VisibleForTesting;
46
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
Tracy Zhoued5f3082020-04-20 01:13:26 -070069 public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
70 public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";
71
Sunny Goyal19ff7282021-04-22 10:12:54 -070072 private static final int DEFAULT_TRUE = -1;
73 private static final int DEFAULT_SPLIT_DISPLAY = 2;
74
Hyunyoung Songc55a3502018-12-04 15:43:16 -080075 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080076
Sunny Goyal53d7ee42015-05-22 12:25:45 -070077 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
78
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070079 // Constants that affects the interpolation curve between statically defined device profile
80 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080081 private static final float KNEARESTNEIGHBOR = 3;
82 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070083
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070084 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080085 private static final float WEIGHT_EFFICIENT = 100000f;
86
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070087 /**
88 * Number of icons per row and column in the workspace.
89 */
Adam Cohen2e6da152015-05-06 11:42:25 -070090 public int numRows;
91 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070092
93 /**
94 * Number of icons per row and column in the folder.
95 */
Adam Cohen2e6da152015-05-06 11:42:25 -070096 public int numFolderRows;
97 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -070098 public float iconSize;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070099 public float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200100 public float landscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700101 public int iconBitmapSize;
102 public int fillResIconDpi;
103 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000104 public float allAppsIconSize;
105 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700106
Jon Mirandae126d722021-02-25 10:45:20 -0500107 public float minCellHeight;
108 public float minCellWidth;
109 public float borderSpacing;
110
Sunny Goyal5bc18462019-01-07 15:13:39 -0800111 private SparseArray<TypedValue> mExtraAttrs;
112
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700113 /**
114 * Number of icons inside the hotseat area.
115 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700116 protected int numShownHotseatIcons;
117
118 /**
119 * Number of icons inside the hotseat area that is stored in the database. This is greater than
120 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
121 * sizes that share the same DB.
122 */
123 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700124
Jon Miranda6f7e9702019-09-16 14:44:14 -0700125 /**
126 * Number of columns in the all apps list.
127 */
128 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700129 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700130
Jon Mirandae126d722021-02-25 10:45:20 -0500131 /**
132 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
133 */
134 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400135 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500136
Tracy Zhou7df93d22020-01-27 13:44:06 -0800137 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800138 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700139 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700140
Sunny Goyal19ff7282021-04-22 10:12:54 -0700141 public final List<DeviceProfile> supportedProfiles = new ArrayList<>();
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 }
Tracy Zhoued5f3082020-04-20 01:13:26 -0700188 Utilities.getPrefs(context).edit()
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700189 .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numDatabaseHotseatIcons)
Tracy Zhoued5f3082020-04-20 01:13:26 -0700190 .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
191 .apply();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700192
Sunny Goyal35c7b192021-04-20 16:51:10 -0700193 DisplayController.INSTANCE.get(context).addChangeListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100194 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700195 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100196 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700197 }
198 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700199 }
200
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700201 /**
202 * This constructor should NOT have any monitors by design.
203 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800204 public InvariantDeviceProfile(Context context, String gridName) {
205 String newName = initGrid(context, gridName);
206 if (newName == null || !newName.equals(gridName)) {
207 throw new IllegalArgumentException("Unknown grid name");
208 }
209 }
210
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700211 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800212 * This constructor should NOT have any monitors by design.
213 */
214 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700215 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100216 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700217 String gridName = getCurrentGridName(context);
218
219 // Get the display info based on default display and interpolate it to existing display
220 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyal35c7b192021-04-20 16:51:10 -0700221 DisplayController.INSTANCE.get(context).getInfo(),
Sunny Goyal19ff7282021-04-22 10:12:54 -0700222 getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223
Alex Chau417bd722021-01-26 15:22:18 +0000224 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700225 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700226 myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700227
228 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
229 .add(myDisplayOption);
230 result.iconSize = defaultDisplayOption.iconSize;
231 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000232 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
233 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000234 } else {
235 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000236 }
Jon Mirandae126d722021-02-25 10:45:20 -0500237 result.minCellHeight = defaultDisplayOption.minCellHeight;
238 result.minCellWidth = defaultDisplayOption.minCellWidth;
239 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500240
Sunny Goyal19ff7282021-04-22 10:12:54 -0700241 initGrid(context, myInfo, result, false);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800242 }
243
Tracy Zhou42255d22020-03-13 00:38:11 -0700244 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700245 return Utilities.isGridOptionsEnabled(context)
246 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700247 }
248
Sunny Goyaleff44f32019-01-09 17:29:49 -0800249 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700250 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Pat Manning67094bf2021-05-26 12:38:13 +0000251 // Each screen has two profiles (portrait/landscape), so devices with four or more
252 // supported profiles implies two or more internal displays.
253 boolean isSplitDisplay =
254 displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700255
256 ArrayList<DisplayOption> allOptions =
257 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
258 DisplayOption displayOption =
259 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
260 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800262 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700263
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700264 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700265 Context context, Info displayInfo, DisplayOption displayOption,
266 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700267 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700268 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000269 numRows = closestProfile.numRows;
270 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000271 dbFile = closestProfile.dbFile;
272 defaultLayoutId = closestProfile.defaultLayoutId;
273 demoModeLayoutId = closestProfile.demoModeLayoutId;
274 numFolderRows = closestProfile.numFolderRows;
275 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500276 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400277 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000278
279 mExtraAttrs = closestProfile.extraAttrs;
280
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700282 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700283 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700284 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200285 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000286 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
287
Jon Mirandae126d722021-02-25 10:45:20 -0500288 minCellHeight = displayOption.minCellHeight;
289 minCellWidth = displayOption.minCellWidth;
290 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700291
292 numShownHotseatIcons = closestProfile.numHotseatIcons;
293 numDatabaseHotseatIcons = isSplitDisplay
294 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
295
296 numAllAppsColumns = closestProfile.numAllAppsColumns;
297 numDatabaseAllAppsColumns = isSplitDisplay
298 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500299
Tracy Zhouc6060e62020-04-27 13:05:34 -0700300 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700301 allAppsIconSize = displayOption.allAppsIconSize;
302 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000303 } else {
304 allAppsIconSize = iconSize;
305 allAppsIconTextSize = iconTextSize;
306 }
307
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400308 if (devicePaddingId != 0) {
309 devicePaddings = new DevicePaddings(context, devicePaddingId);
310 }
311
Sunny Goyalae190ff2020-04-14 00:19:01 +0000312 // If the partner customization apk contains any grid overrides, apply them
313 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700314 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700315
Sunny Goyal19ff7282021-04-22 10:12:54 -0700316 supportedProfiles.clear();
317 defaultWallpaperSize = new Point(displayInfo.currentSize);
318 for (WindowBounds bounds : displayInfo.supportedBounds) {
319 supportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
320 .setUseTwoPanels(isSplitDisplay)
321 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700322
Sunny Goyal19ff7282021-04-22 10:12:54 -0700323 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
324 int displayWidth = bounds.bounds.width();
325 int displayHeight = bounds.bounds.height();
326 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700327
Sunny Goyal19ff7282021-04-22 10:12:54 -0700328 // We need to ensure that there is enough extra space in the wallpaper
329 // for the intended parallax effects
330 float parallaxFactor =
331 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
332 ? 2
333 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
334 defaultWallpaperSize.x =
335 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700336 }
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700337
338 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
339 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700340 }
341
Sunny Goyal5bc18462019-01-07 15:13:39 -0800342 @Nullable
343 public TypedValue getAttrValue(int attr) {
344 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
345 }
346
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700347 public void addOnChangeListener(OnIDPChangeListener listener) {
348 mChangeListeners.add(listener);
349 }
350
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800351 public void removeOnChangeListener(OnIDPChangeListener listener) {
352 mChangeListeners.remove(listener);
353 }
354
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800355
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800356 public void setCurrentGrid(Context context, String gridName) {
357 Context appContext = context.getApplicationContext();
358 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700359 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800360 }
361
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700362 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700363 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700364 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700365 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700366
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700367 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700368 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700369 }
370 }
371
Sunny Goyal19ff7282021-04-22 10:12:54 -0700372 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
373 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800374 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700375 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
376 final int depth = parser.getDepth();
377 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700378 while (((type = parser.next()) != XmlPullParser.END_TAG ||
379 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800380 if ((type == XmlPullParser.START_TAG)
381 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800382
383 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
384 final int displayDepth = parser.getDepth();
385 while (((type = parser.next()) != XmlPullParser.END_TAG ||
386 parser.getDepth() > displayDepth)
387 && type != XmlPullParser.END_DOCUMENT) {
388 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
389 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700390 profiles.add(new DisplayOption(gridOption, context,
391 Xml.asAttributeSet(parser),
392 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800393 }
394 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700395 }
396 }
397 } catch (IOException|XmlPullParserException e) {
398 throw new RuntimeException(e);
399 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800400
Sunny Goyalae190ff2020-04-14 00:19:01 +0000401 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800402 if (!TextUtils.isEmpty(gridName)) {
403 for (DisplayOption option : profiles) {
404 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000405 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800406 }
407 }
408 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000409 if (filteredProfiles.isEmpty()) {
410 // No grid found, use the default options
411 for (DisplayOption option : profiles) {
412 if (option.canBeDefault) {
413 filteredProfiles.add(option);
414 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800415 }
416 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000417 if (filteredProfiles.isEmpty()) {
418 throw new RuntimeException("No display option with canBeDefault=true");
419 }
420 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700421 }
422
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700423 private int getLauncherIconDensity(int requiredSize) {
424 // Densities typically defined by an app.
425 int[] densityBuckets = new int[] {
426 DisplayMetrics.DENSITY_LOW,
427 DisplayMetrics.DENSITY_MEDIUM,
428 DisplayMetrics.DENSITY_TV,
429 DisplayMetrics.DENSITY_HIGH,
430 DisplayMetrics.DENSITY_XHIGH,
431 DisplayMetrics.DENSITY_XXHIGH,
432 DisplayMetrics.DENSITY_XXXHIGH
433 };
434
435 int density = DisplayMetrics.DENSITY_XXXHIGH;
436 for (int i = densityBuckets.length - 1; i >= 0; i--) {
437 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
438 / DisplayMetrics.DENSITY_DEFAULT;
439 if (expectedSize >= requiredSize) {
440 density = densityBuckets[i];
441 }
442 }
443
444 return density;
445 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700446
Adam Cohen2e6da152015-05-06 11:42:25 -0700447 /**
448 * Apply any Partner customization grid overrides.
449 *
450 * Currently we support: all apps row / column count.
451 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700452 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
453 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700454 if (p != null) {
455 p.applyInvariantDeviceProfileOverrides(this, dm);
456 }
457 }
458
Sunny Goyal415f1732018-11-29 10:33:47 -0800459 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700460 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700461 }
462
Sunny Goyal19ff7282021-04-22 10:12:54 -0700463 private static DisplayOption invDistWeightedInterpolate(
464 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
465 int minWidthPx = Integer.MAX_VALUE;
466 int minHeightPx = Integer.MAX_VALUE;
467 for (WindowBounds bounds : displayInfo.supportedBounds) {
468 boolean isTablet = displayInfo.isTablet(bounds);
469 if (isTablet && isSplitDisplay) {
470 // For split displays, take half width per page
471 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
472 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700473
Sunny Goyal19ff7282021-04-22 10:12:54 -0700474 } else if (!isTablet && bounds.isLandscape()) {
475 // We will use transposed layout in this case
476 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
477 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
478 } else {
479 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
480 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
481 }
482 }
483
484 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
485 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700486
487 // Sort the profiles based on the closeness to the device size
488 Collections.sort(points, (a, b) ->
489 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
490 dist(width, height, b.minWidthDps, b.minHeightDps)));
491
492 GridOption closestOption = points.get(0).grid;
493 float weights = 0;
494
495 DisplayOption p = points.get(0);
496 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
497 return p;
498 }
499
500 DisplayOption out = new DisplayOption(closestOption);
501 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
502 p = points.get(i);
503 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
504 weights += w;
505 out.add(new DisplayOption().add(p).multiply(w));
506 }
507 return out.multiply(1.0f / weights);
508 }
509
Sunny Goyal27835952017-01-13 12:15:53 -0800510 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700511 Resources res = context.getResources();
512 Configuration config = context.getResources().getConfiguration();
513
514 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
515 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
516
Sunny Goyal19ff7282021-04-22 10:12:54 -0700517 DeviceProfile bestMatch = supportedProfiles.get(0);
518 float minDiff = Float.MAX_VALUE;
519
520 for (DeviceProfile profile : supportedProfiles) {
521 float diff = Math.abs(profile.availableWidthPx - availableWidth)
522 + Math.abs(profile.availableHeightPx - availableHeight);
523 if (diff < minDiff) {
524 minDiff = diff;
525 bestMatch = profile;
526 }
527 }
528 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800529 }
530
Sunny Goyal415f1732018-11-29 10:33:47 -0800531 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700532 float d = dist(x0, y0, x1, y1);
533 if (Float.compare(d, 0f) == 0) {
534 return Float.POSITIVE_INFINITY;
535 }
536 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
537 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700538
539 /**
540 * As a ratio of screen height, the total distance we want the parallax effect to span
541 * horizontally
542 */
543 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
544 float aspectRatio = width / (float) height;
545
546 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
547 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
548 // We will use these two data points to extrapolate how much the wallpaper parallax effect
549 // to span (ie travel) at any aspect ratio:
550
551 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
552 final float ASPECT_RATIO_PORTRAIT = 10/16f;
553 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
554 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
555
556 // To find out the desired width at different aspect ratios, we use the following two
557 // formulas, where the coefficient on x is the aspect ratio (width/height):
558 // (16/10)x + y = 1.5
559 // (10/16)x + y = 1.2
560 // We solve for x and y and end up with a final formula:
561 final float x =
562 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
563 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
564 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
565 return x * aspectRatio + y;
566 }
567
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700568 public interface OnIDPChangeListener {
569
Sunny Goyalb47172b2021-05-03 19:59:51 -0700570 /**
571 * Called when the device provide changes
572 */
573 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700574 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800575
576
Sunny Goyaleff44f32019-01-09 17:29:49 -0800577 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800578
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800579 public static final String TAG_NAME = "grid-option";
580
Sunny Goyaleff44f32019-01-09 17:29:49 -0800581 public final String name;
582 public final int numRows;
583 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800584
585 private final int numFolderRows;
586 private final int numFolderColumns;
587
Sunny Goyal19ff7282021-04-22 10:12:54 -0700588 private final int numAllAppsColumns;
589 private final int numDatabaseAllAppsColumns;
590 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700591 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800592
Tracy Zhou7df93d22020-01-27 13:44:06 -0800593 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000594
Sunny Goyal415f1732018-11-29 10:33:47 -0800595 private final int defaultLayoutId;
596 private final int demoModeLayoutId;
597
Jon Mirandae126d722021-02-25 10:45:20 -0500598 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400599 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500600
Sunny Goyal5bc18462019-01-07 15:13:39 -0800601 private final SparseArray<TypedValue> extraAttrs;
602
Sunny Goyaleff44f32019-01-09 17:29:49 -0800603 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800604 TypedArray a = context.obtainStyledAttributes(
605 attrs, R.styleable.GridDisplayOption);
606 name = a.getString(R.styleable.GridDisplayOption_name);
607 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
608 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
609
Tracy Zhou7df93d22020-01-27 13:44:06 -0800610 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800611 defaultLayoutId = a.getResourceId(
612 R.styleable.GridDisplayOption_defaultLayoutId, 0);
613 demoModeLayoutId = a.getResourceId(
614 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700615
616 numAllAppsColumns = a.getInt(
617 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
618 numDatabaseAllAppsColumns = a.getInt(
619 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
620
621 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800622 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700623 numDatabaseHotseatIcons = a.getInt(
624 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
625
Sunny Goyal415f1732018-11-29 10:33:47 -0800626 numFolderRows = a.getInt(
627 R.styleable.GridDisplayOption_numFolderRows, numRows);
628 numFolderColumns = a.getInt(
629 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700630
Jon Mirandae126d722021-02-25 10:45:20 -0500631 isScalable = a.getBoolean(
632 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400633 devicePaddingId = a.getResourceId(
634 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500635
Sunny Goyal415f1732018-11-29 10:33:47 -0800636 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800637 extraAttrs = Themes.createValueMap(context, attrs,
638 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800639 }
640 }
641
Sunny Goyal19ff7282021-04-22 10:12:54 -0700642 @VisibleForTesting
643 static final class DisplayOption {
644
645 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800646
Sunny Goyal415f1732018-11-29 10:33:47 -0800647 private final float minWidthDps;
648 private final float minHeightDps;
649 private final boolean canBeDefault;
650
Jon Mirandae126d722021-02-25 10:45:20 -0500651 private float minCellHeight;
652 private float minCellWidth;
653 private float borderSpacing;
654
Sunny Goyal415f1732018-11-29 10:33:47 -0800655 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800656 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700657 private float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200658 private float landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000659 private float allAppsIconSize;
660 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800661
Sunny Goyal19ff7282021-04-22 10:12:54 -0700662 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800663 this.grid = grid;
664
665 TypedArray a = context.obtainStyledAttributes(
666 attrs, R.styleable.ProfileDisplayOption);
667
Sunny Goyal415f1732018-11-29 10:33:47 -0800668 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
669 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700670
671 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
672 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800673
Jon Mirandae126d722021-02-25 10:45:20 -0500674 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
675 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
676 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
677
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700678 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800679 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
680 iconSize);
681 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200682 landscapeIconTextSize = a.getFloat(
683 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700684
Sunny Goyalae190ff2020-04-14 00:19:01 +0000685 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
686 iconSize);
687 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
688 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800689 a.recycle();
690 }
691
692 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700693 this(null);
694 }
695
696 DisplayOption(GridOption grid) {
697 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800698 minWidthDps = 0;
699 minHeightDps = 0;
700 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500701 minCellHeight = 0;
702 minCellWidth = 0;
703 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800704 }
705
706 private DisplayOption multiply(float w) {
707 iconSize *= w;
708 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000709 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800710 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200711 landscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000712 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500713 minCellHeight *= w;
714 minCellWidth *= w;
715 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800716 return this;
717 }
718
719 private DisplayOption add(DisplayOption p) {
720 iconSize += p.iconSize;
721 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000722 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800723 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200724 landscapeIconTextSize += p.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000725 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500726 minCellHeight += p.minCellHeight;
727 minCellWidth += p.minCellWidth;
728 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800729 return this;
730 }
731 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000732}