blob: 29a02236123c8a33c6799e6daf7a560dea7949b2 [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 Goyal87dc48b2018-10-12 11:42:33 -070039import 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
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070045import androidx.annotation.Nullable;
46import androidx.annotation.VisibleForTesting;
47
Winson Chung8e64bba2021-04-20 13:26:26 -070048import com.android.launcher3.testing.TestProtocol;
Sunny Goyalfd58da62020-08-11 12:06:49 -070049import com.android.launcher3.util.DisplayController;
50import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080051import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070052import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080053import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070054import com.android.launcher3.util.WindowBounds;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070055
Sunny Goyal819e1932016-07-07 16:43:58 -070056import org.xmlpull.v1.XmlPullParser;
57import org.xmlpull.v1.XmlPullParserException;
58
59import java.io.IOException;
Adam Cohen2e6da152015-05-06 11:42:25 -070060import java.util.ArrayList;
Sunny Goyal6d55f662019-01-02 12:13:43 -080061import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070062import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070063
64public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070065
Hyunyoung Songc55a3502018-12-04 15:43:16 -080066 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070067 // We do not need any synchronization for this variable as its only written on UI thread.
68 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070069 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070070
Tracy Zhoued5f3082020-04-20 01:13:26 -070071 public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
72 public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";
73
Sunny Goyal19ff7282021-04-22 10:12:54 -070074 private static final int DEFAULT_TRUE = -1;
75 private static final int DEFAULT_SPLIT_DISPLAY = 2;
76
Hyunyoung Songc55a3502018-12-04 15:43:16 -080077 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080078
Sunny Goyal53d7ee42015-05-22 12:25:45 -070079 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
80
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070081 // Constants that affects the interpolation curve between statically defined device profile
82 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 private static final float KNEARESTNEIGHBOR = 3;
84 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070085
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070086 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080087 private static final float WEIGHT_EFFICIENT = 100000f;
88
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 /**
90 * Number of icons per row and column in the workspace.
91 */
Adam Cohen2e6da152015-05-06 11:42:25 -070092 public int numRows;
93 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094
95 /**
96 * Number of icons per row and column in the folder.
97 */
Adam Cohen2e6da152015-05-06 11:42:25 -070098 public int numFolderRows;
99 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -0700100 public float iconSize;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700101 public float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200102 public float landscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700103 public int iconBitmapSize;
104 public int fillResIconDpi;
105 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000106 public float allAppsIconSize;
107 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700108
Jon Mirandae126d722021-02-25 10:45:20 -0500109 public float minCellHeight;
110 public float minCellWidth;
111 public float borderSpacing;
112
Sunny Goyal5bc18462019-01-07 15:13:39 -0800113 private SparseArray<TypedValue> mExtraAttrs;
114
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700115 /**
116 * Number of icons inside the hotseat area.
117 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700118 protected int numShownHotseatIcons;
119
120 /**
121 * Number of icons inside the hotseat area that is stored in the database. This is greater than
122 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
123 * sizes that share the same DB.
124 */
125 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700126
Jon Miranda6f7e9702019-09-16 14:44:14 -0700127 /**
128 * Number of columns in the all apps list.
129 */
130 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700131 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700132
Jon Mirandae126d722021-02-25 10:45:20 -0500133 /**
134 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
135 */
136 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400137 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500138
Tracy Zhou7df93d22020-01-27 13:44:06 -0800139 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800140 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700141 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700142
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000143 /**
144 * An immutable list of supported profiles.
145 */
146 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700147
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400148 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500149
Sunny Goyal6f866092016-03-17 17:04:15 -0700150 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700151 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700152
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700153 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700154
Sunny Goyalf633ef52018-03-13 09:57:05 -0700155 @VisibleForTesting
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700156 public InvariantDeviceProfile() {}
Adam Cohen2e6da152015-05-06 11:42:25 -0700157
Sunny Goyalf633ef52018-03-13 09:57:05 -0700158 private InvariantDeviceProfile(InvariantDeviceProfile p) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800159 numRows = p.numRows;
160 numColumns = p.numColumns;
161 numFolderRows = p.numFolderRows;
162 numFolderColumns = p.numFolderColumns;
163 iconSize = p.iconSize;
164 landscapeIconSize = p.landscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500165 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800166 iconTextSize = p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200167 landscapeIconTextSize = p.landscapeIconTextSize;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700168 numShownHotseatIcons = p.numShownHotseatIcons;
169 numDatabaseHotseatIcons = p.numDatabaseHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700170 numAllAppsColumns = p.numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700171 numDatabaseAllAppsColumns = p.numDatabaseAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500172 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400173 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500174 minCellHeight = p.minCellHeight;
175 minCellWidth = p.minCellWidth;
176 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800177 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000178 allAppsIconSize = p.allAppsIconSize;
179 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800180 defaultLayoutId = p.defaultLayoutId;
181 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800182 mExtraAttrs = p.mExtraAttrs;
Jon Miranda228877d2021-02-09 11:05:00 -0500183 devicePaddings = p.devicePaddings;
Adam Cohen2e6da152015-05-06 11:42:25 -0700184 }
185
Sunny Goyalbbf01842015-10-08 07:41:15 -0700186 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700187 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700188 String gridName = getCurrentGridName(context);
189 String newGridName = initGrid(context, gridName);
190 if (!newGridName.equals(gridName)) {
191 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
192 }
Tracy Zhoued5f3082020-04-20 01:13:26 -0700193 Utilities.getPrefs(context).edit()
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700194 .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numDatabaseHotseatIcons)
Tracy Zhoued5f3082020-04-20 01:13:26 -0700195 .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
196 .apply();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700197
Sunny Goyal35c7b192021-04-20 16:51:10 -0700198 DisplayController.INSTANCE.get(context).addChangeListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100199 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700200 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100201 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700202 }
203 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700204 }
205
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700206 /**
207 * This constructor should NOT have any monitors by design.
208 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800209 public InvariantDeviceProfile(Context context, String gridName) {
210 String newName = initGrid(context, gridName);
211 if (newName == null || !newName.equals(gridName)) {
212 throw new IllegalArgumentException("Unknown grid name");
213 }
214 }
215
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700216 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800217 * This constructor should NOT have any monitors by design.
218 */
219 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100221 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700222 String gridName = getCurrentGridName(context);
223
224 // Get the display info based on default display and interpolate it to existing display
225 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyal35c7b192021-04-20 16:51:10 -0700226 DisplayController.INSTANCE.get(context).getInfo(),
Sunny Goyal19ff7282021-04-22 10:12:54 -0700227 getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700228
Alex Chau417bd722021-01-26 15:22:18 +0000229 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700231 myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700232
233 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
234 .add(myDisplayOption);
235 result.iconSize = defaultDisplayOption.iconSize;
236 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000237 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
238 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000239 } else {
240 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000241 }
Jon Mirandae126d722021-02-25 10:45:20 -0500242 result.minCellHeight = defaultDisplayOption.minCellHeight;
243 result.minCellWidth = defaultDisplayOption.minCellWidth;
244 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500245
Sunny Goyal19ff7282021-04-22 10:12:54 -0700246 initGrid(context, myInfo, result, false);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800247 }
248
Tracy Zhou42255d22020-03-13 00:38:11 -0700249 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700250 return Utilities.isGridOptionsEnabled(context)
251 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700252 }
253
Sunny Goyaleff44f32019-01-09 17:29:49 -0800254 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700255 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700256 // Determine if we have split display
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700257
Sunny Goyal19ff7282021-04-22 10:12:54 -0700258 boolean isTablet = false, isPhone = false;
259 for (WindowBounds bounds : displayInfo.supportedBounds) {
260 if (displayInfo.isTablet(bounds)) {
261 isTablet = true;
262 } else {
263 isPhone = true;
264 }
265 }
266 boolean isSplitDisplay = isPhone && isTablet && ENABLE_TWO_PANEL_HOME.get();
267
268 ArrayList<DisplayOption> allOptions =
269 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
270 DisplayOption displayOption =
271 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
272 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700273 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800274 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700275
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700276 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700277 Context context, Info displayInfo, DisplayOption displayOption,
278 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700279 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000281 numRows = closestProfile.numRows;
282 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000283 dbFile = closestProfile.dbFile;
284 defaultLayoutId = closestProfile.defaultLayoutId;
285 demoModeLayoutId = closestProfile.demoModeLayoutId;
286 numFolderRows = closestProfile.numFolderRows;
287 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500288 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400289 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000290
291 mExtraAttrs = closestProfile.extraAttrs;
292
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700293 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700294 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700295 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700296 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200297 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000298 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
299
Jon Mirandae126d722021-02-25 10:45:20 -0500300 minCellHeight = displayOption.minCellHeight;
301 minCellWidth = displayOption.minCellWidth;
302 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700303
304 numShownHotseatIcons = closestProfile.numHotseatIcons;
305 numDatabaseHotseatIcons = isSplitDisplay
306 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
307
308 numAllAppsColumns = closestProfile.numAllAppsColumns;
309 numDatabaseAllAppsColumns = isSplitDisplay
310 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500311
Tracy Zhouc6060e62020-04-27 13:05:34 -0700312 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700313 allAppsIconSize = displayOption.allAppsIconSize;
314 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000315 } else {
316 allAppsIconSize = iconSize;
317 allAppsIconTextSize = iconTextSize;
318 }
319
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400320 if (devicePaddingId != 0) {
321 devicePaddings = new DevicePaddings(context, devicePaddingId);
322 }
323
Sunny Goyalae190ff2020-04-14 00:19:01 +0000324 // If the partner customization apk contains any grid overrides, apply them
325 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700326 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700327
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000328 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700329 defaultWallpaperSize = new Point(displayInfo.currentSize);
330 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000331 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700332 .setUseTwoPanels(isSplitDisplay)
333 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700334
Sunny Goyal19ff7282021-04-22 10:12:54 -0700335 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
336 int displayWidth = bounds.bounds.width();
337 int displayHeight = bounds.bounds.height();
338 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700339
Sunny Goyal19ff7282021-04-22 10:12:54 -0700340 // We need to ensure that there is enough extra space in the wallpaper
341 // for the intended parallax effects
342 float parallaxFactor =
343 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
344 ? 2
345 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
346 defaultWallpaperSize.x =
347 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700348 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000349 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700350
351 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
352 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700353 }
354
Sunny Goyal5bc18462019-01-07 15:13:39 -0800355 @Nullable
356 public TypedValue getAttrValue(int attr) {
357 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
358 }
359
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700360 public void addOnChangeListener(OnIDPChangeListener listener) {
361 mChangeListeners.add(listener);
362 }
363
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800364 public void removeOnChangeListener(OnIDPChangeListener listener) {
365 mChangeListeners.remove(listener);
366 }
367
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800368
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800369 public void setCurrentGrid(Context context, String gridName) {
370 Context appContext = context.getApplicationContext();
371 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700372 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800373 }
374
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700375 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700376 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700377 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700378 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700379
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700380 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700381 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700382 }
383 }
384
Sunny Goyal19ff7282021-04-22 10:12:54 -0700385 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
386 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800387 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700388 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
389 final int depth = parser.getDepth();
390 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700391 while (((type = parser.next()) != XmlPullParser.END_TAG ||
392 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800393 if ((type == XmlPullParser.START_TAG)
394 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800395
396 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
397 final int displayDepth = parser.getDepth();
398 while (((type = parser.next()) != XmlPullParser.END_TAG ||
399 parser.getDepth() > displayDepth)
400 && type != XmlPullParser.END_DOCUMENT) {
401 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
402 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700403 profiles.add(new DisplayOption(gridOption, context,
404 Xml.asAttributeSet(parser),
405 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800406 }
407 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700408 }
409 }
410 } catch (IOException|XmlPullParserException e) {
411 throw new RuntimeException(e);
412 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800413
Sunny Goyalae190ff2020-04-14 00:19:01 +0000414 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800415 if (!TextUtils.isEmpty(gridName)) {
416 for (DisplayOption option : profiles) {
417 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000418 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800419 }
420 }
421 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000422 if (filteredProfiles.isEmpty()) {
423 // No grid found, use the default options
424 for (DisplayOption option : profiles) {
425 if (option.canBeDefault) {
426 filteredProfiles.add(option);
427 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800428 }
429 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000430 if (filteredProfiles.isEmpty()) {
431 throw new RuntimeException("No display option with canBeDefault=true");
432 }
433 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700434 }
435
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700436 private int getLauncherIconDensity(int requiredSize) {
437 // Densities typically defined by an app.
438 int[] densityBuckets = new int[] {
439 DisplayMetrics.DENSITY_LOW,
440 DisplayMetrics.DENSITY_MEDIUM,
441 DisplayMetrics.DENSITY_TV,
442 DisplayMetrics.DENSITY_HIGH,
443 DisplayMetrics.DENSITY_XHIGH,
444 DisplayMetrics.DENSITY_XXHIGH,
445 DisplayMetrics.DENSITY_XXXHIGH
446 };
447
448 int density = DisplayMetrics.DENSITY_XXXHIGH;
449 for (int i = densityBuckets.length - 1; i >= 0; i--) {
450 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
451 / DisplayMetrics.DENSITY_DEFAULT;
452 if (expectedSize >= requiredSize) {
453 density = densityBuckets[i];
454 }
455 }
456
457 return density;
458 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700459
Adam Cohen2e6da152015-05-06 11:42:25 -0700460 /**
461 * Apply any Partner customization grid overrides.
462 *
463 * Currently we support: all apps row / column count.
464 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700465 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
466 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700467 if (p != null) {
468 p.applyInvariantDeviceProfileOverrides(this, dm);
469 }
470 }
471
Sunny Goyal415f1732018-11-29 10:33:47 -0800472 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700473 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700474 }
475
Sunny Goyal19ff7282021-04-22 10:12:54 -0700476 private static DisplayOption invDistWeightedInterpolate(
477 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
478 int minWidthPx = Integer.MAX_VALUE;
479 int minHeightPx = Integer.MAX_VALUE;
480 for (WindowBounds bounds : displayInfo.supportedBounds) {
481 boolean isTablet = displayInfo.isTablet(bounds);
482 if (isTablet && isSplitDisplay) {
483 // For split displays, take half width per page
484 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
485 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700486
Sunny Goyal19ff7282021-04-22 10:12:54 -0700487 } else if (!isTablet && bounds.isLandscape()) {
488 // We will use transposed layout in this case
489 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
490 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
491 } else {
492 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
493 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
494 }
495 }
496
497 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
498 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700499
500 // Sort the profiles based on the closeness to the device size
501 Collections.sort(points, (a, b) ->
502 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
503 dist(width, height, b.minWidthDps, b.minHeightDps)));
504
505 GridOption closestOption = points.get(0).grid;
506 float weights = 0;
507
508 DisplayOption p = points.get(0);
509 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
510 return p;
511 }
512
513 DisplayOption out = new DisplayOption(closestOption);
514 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
515 p = points.get(i);
516 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
517 weights += w;
518 out.add(new DisplayOption().add(p).multiply(w));
519 }
520 return out.multiply(1.0f / weights);
521 }
522
Sunny Goyal27835952017-01-13 12:15:53 -0800523 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700524 Resources res = context.getResources();
525 Configuration config = context.getResources().getConfiguration();
526
527 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
528 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
529
Sunny Goyal19ff7282021-04-22 10:12:54 -0700530 DeviceProfile bestMatch = supportedProfiles.get(0);
531 float minDiff = Float.MAX_VALUE;
532
533 for (DeviceProfile profile : supportedProfiles) {
534 float diff = Math.abs(profile.availableWidthPx - availableWidth)
535 + Math.abs(profile.availableHeightPx - availableHeight);
536 if (diff < minDiff) {
537 minDiff = diff;
538 bestMatch = profile;
539 }
540 }
541 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800542 }
543
Sunny Goyal415f1732018-11-29 10:33:47 -0800544 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700545 float d = dist(x0, y0, x1, y1);
546 if (Float.compare(d, 0f) == 0) {
547 return Float.POSITIVE_INFINITY;
548 }
549 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
550 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700551
552 /**
553 * As a ratio of screen height, the total distance we want the parallax effect to span
554 * horizontally
555 */
556 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
557 float aspectRatio = width / (float) height;
558
559 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
560 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
561 // We will use these two data points to extrapolate how much the wallpaper parallax effect
562 // to span (ie travel) at any aspect ratio:
563
564 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
565 final float ASPECT_RATIO_PORTRAIT = 10/16f;
566 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
567 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
568
569 // To find out the desired width at different aspect ratios, we use the following two
570 // formulas, where the coefficient on x is the aspect ratio (width/height):
571 // (16/10)x + y = 1.5
572 // (10/16)x + y = 1.2
573 // We solve for x and y and end up with a final formula:
574 final float x =
575 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
576 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
577 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
578 return x * aspectRatio + y;
579 }
580
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700581 public interface OnIDPChangeListener {
582
Sunny Goyalb47172b2021-05-03 19:59:51 -0700583 /**
584 * Called when the device provide changes
585 */
586 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700587 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800588
589
Sunny Goyaleff44f32019-01-09 17:29:49 -0800590 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800591
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800592 public static final String TAG_NAME = "grid-option";
593
Sunny Goyaleff44f32019-01-09 17:29:49 -0800594 public final String name;
595 public final int numRows;
596 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800597
598 private final int numFolderRows;
599 private final int numFolderColumns;
600
Sunny Goyal19ff7282021-04-22 10:12:54 -0700601 private final int numAllAppsColumns;
602 private final int numDatabaseAllAppsColumns;
603 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700604 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800605
Tracy Zhou7df93d22020-01-27 13:44:06 -0800606 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000607
Sunny Goyal415f1732018-11-29 10:33:47 -0800608 private final int defaultLayoutId;
609 private final int demoModeLayoutId;
610
Jon Mirandae126d722021-02-25 10:45:20 -0500611 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400612 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500613
Sunny Goyal5bc18462019-01-07 15:13:39 -0800614 private final SparseArray<TypedValue> extraAttrs;
615
Sunny Goyaleff44f32019-01-09 17:29:49 -0800616 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800617 TypedArray a = context.obtainStyledAttributes(
618 attrs, R.styleable.GridDisplayOption);
619 name = a.getString(R.styleable.GridDisplayOption_name);
620 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
621 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
622
Tracy Zhou7df93d22020-01-27 13:44:06 -0800623 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800624 defaultLayoutId = a.getResourceId(
625 R.styleable.GridDisplayOption_defaultLayoutId, 0);
626 demoModeLayoutId = a.getResourceId(
627 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700628
629 numAllAppsColumns = a.getInt(
630 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
631 numDatabaseAllAppsColumns = a.getInt(
632 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
633
634 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800635 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700636 numDatabaseHotseatIcons = a.getInt(
637 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
638
Sunny Goyal415f1732018-11-29 10:33:47 -0800639 numFolderRows = a.getInt(
640 R.styleable.GridDisplayOption_numFolderRows, numRows);
641 numFolderColumns = a.getInt(
642 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700643
Jon Mirandae126d722021-02-25 10:45:20 -0500644 isScalable = a.getBoolean(
645 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400646 devicePaddingId = a.getResourceId(
647 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500648
Sunny Goyal415f1732018-11-29 10:33:47 -0800649 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800650 extraAttrs = Themes.createValueMap(context, attrs,
651 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800652 }
653 }
654
Sunny Goyal19ff7282021-04-22 10:12:54 -0700655 @VisibleForTesting
656 static final class DisplayOption {
657
658 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800659
Sunny Goyal415f1732018-11-29 10:33:47 -0800660 private final float minWidthDps;
661 private final float minHeightDps;
662 private final boolean canBeDefault;
663
Jon Mirandae126d722021-02-25 10:45:20 -0500664 private float minCellHeight;
665 private float minCellWidth;
666 private float borderSpacing;
667
Sunny Goyal415f1732018-11-29 10:33:47 -0800668 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800669 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700670 private float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200671 private float landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000672 private float allAppsIconSize;
673 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800674
Sunny Goyal19ff7282021-04-22 10:12:54 -0700675 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800676 this.grid = grid;
677
678 TypedArray a = context.obtainStyledAttributes(
679 attrs, R.styleable.ProfileDisplayOption);
680
Sunny Goyal415f1732018-11-29 10:33:47 -0800681 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
682 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700683
684 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
685 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800686
Jon Mirandae126d722021-02-25 10:45:20 -0500687 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
688 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
689 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
690
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700691 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800692 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
693 iconSize);
694 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200695 landscapeIconTextSize = a.getFloat(
696 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700697
Sunny Goyalae190ff2020-04-14 00:19:01 +0000698 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
699 iconSize);
700 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
701 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800702 a.recycle();
703 }
704
705 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700706 this(null);
707 }
708
709 DisplayOption(GridOption grid) {
710 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800711 minWidthDps = 0;
712 minHeightDps = 0;
713 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500714 minCellHeight = 0;
715 minCellWidth = 0;
716 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800717 }
718
719 private DisplayOption multiply(float w) {
720 iconSize *= w;
721 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000722 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800723 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200724 landscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000725 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500726 minCellHeight *= w;
727 minCellWidth *= w;
728 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800729 return this;
730 }
731
732 private DisplayOption add(DisplayOption p) {
733 iconSize += p.iconSize;
734 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000735 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800736 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200737 landscapeIconTextSize += p.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000738 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500739 minCellHeight += p.minCellHeight;
740 minCellWidth += p.minCellWidth;
741 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800742 return this;
743 }
744 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000745}