blob: b93bfd6ef8d34c3bc0fd4f6212bf8c29034cf158 [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 Kloczl30fe9152021-08-05 18:02:29 +020097 public float twoPanelPortraitIconSize;
98 public float twoPanelLandscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +020099 public float landscapeIconTextSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200100 public float twoPanelPortraitIconTextSize;
101 public float twoPanelLandscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700102 public int iconBitmapSize;
103 public int fillResIconDpi;
104 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000105 public float allAppsIconSize;
106 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700107
Jon Mirandae126d722021-02-25 10:45:20 -0500108 public float minCellHeight;
109 public float minCellWidth;
110 public float borderSpacing;
111
Sunny Goyal5bc18462019-01-07 15:13:39 -0800112 private SparseArray<TypedValue> mExtraAttrs;
113
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700114 /**
115 * Number of icons inside the hotseat area.
116 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700117 protected int numShownHotseatIcons;
118
119 /**
120 * Number of icons inside the hotseat area that is stored in the database. This is greater than
121 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
122 * sizes that share the same DB.
123 */
124 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700125
Jon Miranda6f7e9702019-09-16 14:44:14 -0700126 /**
127 * Number of columns in the all apps list.
128 */
129 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700130 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700131
Jon Mirandae126d722021-02-25 10:45:20 -0500132 /**
133 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
134 */
135 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400136 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500137
Tracy Zhou7df93d22020-01-27 13:44:06 -0800138 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800139 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700140 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700141
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000142 /**
143 * An immutable list of supported profiles.
144 */
145 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700146
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400147 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500148
Sunny Goyal6f866092016-03-17 17:04:15 -0700149 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700150 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700151
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700152 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700153
Sunny Goyalf633ef52018-03-13 09:57:05 -0700154 @VisibleForTesting
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700155 public InvariantDeviceProfile() {}
Adam Cohen2e6da152015-05-06 11:42:25 -0700156
Sunny Goyalf633ef52018-03-13 09:57:05 -0700157 private InvariantDeviceProfile(InvariantDeviceProfile p) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800158 numRows = p.numRows;
159 numColumns = p.numColumns;
160 numFolderRows = p.numFolderRows;
161 numFolderColumns = p.numFolderColumns;
162 iconSize = p.iconSize;
163 landscapeIconSize = p.landscapeIconSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200164 twoPanelPortraitIconSize = p.twoPanelPortraitIconSize;
165 twoPanelLandscapeIconSize = p.twoPanelLandscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500166 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800167 iconTextSize = p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200168 landscapeIconTextSize = p.landscapeIconTextSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200169 twoPanelPortraitIconTextSize = p.twoPanelPortraitIconTextSize;
170 twoPanelLandscapeIconTextSize = p.twoPanelLandscapeIconTextSize;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700171 numShownHotseatIcons = p.numShownHotseatIcons;
172 numDatabaseHotseatIcons = p.numDatabaseHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700173 numAllAppsColumns = p.numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700174 numDatabaseAllAppsColumns = p.numDatabaseAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500175 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400176 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500177 minCellHeight = p.minCellHeight;
178 minCellWidth = p.minCellWidth;
179 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800180 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000181 allAppsIconSize = p.allAppsIconSize;
182 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800183 defaultLayoutId = p.defaultLayoutId;
184 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800185 mExtraAttrs = p.mExtraAttrs;
Jon Miranda228877d2021-02-09 11:05:00 -0500186 devicePaddings = p.devicePaddings;
Adam Cohen2e6da152015-05-06 11:42:25 -0700187 }
188
Sunny Goyalbbf01842015-10-08 07:41:15 -0700189 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700190 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700191 String gridName = getCurrentGridName(context);
192 String newGridName = initGrid(context, gridName);
193 if (!newGridName.equals(gridName)) {
194 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
195 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700196 new DeviceGridState(this).writeToPrefs(context);
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();
Pat Manning67094bf2021-05-26 12:38:13 +0000256 // Each screen has two profiles (portrait/landscape), so devices with four or more
257 // supported profiles implies two or more internal displays.
258 boolean isSplitDisplay =
259 displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700260
261 ArrayList<DisplayOption> allOptions =
262 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
263 DisplayOption displayOption =
264 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
265 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700266 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800267 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700268
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700269 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700270 Context context, Info displayInfo, DisplayOption displayOption,
271 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700272 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700273 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000274 numRows = closestProfile.numRows;
275 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000276 dbFile = closestProfile.dbFile;
277 defaultLayoutId = closestProfile.defaultLayoutId;
278 demoModeLayoutId = closestProfile.demoModeLayoutId;
279 numFolderRows = closestProfile.numFolderRows;
280 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500281 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400282 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000283
284 mExtraAttrs = closestProfile.extraAttrs;
285
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700286 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700287 landscapeIconSize = displayOption.landscapeIconSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200288 twoPanelPortraitIconSize = displayOption.twoPanelPortraitIconSize;
289 twoPanelLandscapeIconSize = displayOption.twoPanelLandscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700290 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200292 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200293 twoPanelPortraitIconTextSize = displayOption.twoPanelPortraitIconTextSize;
294 twoPanelLandscapeIconTextSize = displayOption.twoPanelLandscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000295 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
296
Jon Mirandae126d722021-02-25 10:45:20 -0500297 minCellHeight = displayOption.minCellHeight;
298 minCellWidth = displayOption.minCellWidth;
299 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700300
301 numShownHotseatIcons = closestProfile.numHotseatIcons;
302 numDatabaseHotseatIcons = isSplitDisplay
303 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
304
305 numAllAppsColumns = closestProfile.numAllAppsColumns;
306 numDatabaseAllAppsColumns = isSplitDisplay
307 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500308
Tracy Zhouc6060e62020-04-27 13:05:34 -0700309 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700310 allAppsIconSize = displayOption.allAppsIconSize;
311 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000312 } else {
313 allAppsIconSize = iconSize;
314 allAppsIconTextSize = iconTextSize;
315 }
316
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400317 if (devicePaddingId != 0) {
318 devicePaddings = new DevicePaddings(context, devicePaddingId);
319 }
320
Sunny Goyalae190ff2020-04-14 00:19:01 +0000321 // If the partner customization apk contains any grid overrides, apply them
322 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700323 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700324
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000325 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700326 defaultWallpaperSize = new Point(displayInfo.currentSize);
327 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000328 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700329 .setUseTwoPanels(isSplitDisplay)
330 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700331
Sunny Goyal19ff7282021-04-22 10:12:54 -0700332 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
333 int displayWidth = bounds.bounds.width();
334 int displayHeight = bounds.bounds.height();
335 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700336
Sunny Goyal19ff7282021-04-22 10:12:54 -0700337 // We need to ensure that there is enough extra space in the wallpaper
338 // for the intended parallax effects
339 float parallaxFactor =
340 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
341 ? 2
342 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
343 defaultWallpaperSize.x =
344 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700345 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000346 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700347
348 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
349 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700350 }
351
Sunny Goyal5bc18462019-01-07 15:13:39 -0800352 @Nullable
353 public TypedValue getAttrValue(int attr) {
354 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
355 }
356
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700357 public void addOnChangeListener(OnIDPChangeListener listener) {
358 mChangeListeners.add(listener);
359 }
360
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800361 public void removeOnChangeListener(OnIDPChangeListener listener) {
362 mChangeListeners.remove(listener);
363 }
364
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800365
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800366 public void setCurrentGrid(Context context, String gridName) {
367 Context appContext = context.getApplicationContext();
368 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700369 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800370 }
371
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700372 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700373 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700374 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700375 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700376
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700377 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700378 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700379 }
380 }
381
Sunny Goyal19ff7282021-04-22 10:12:54 -0700382 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
383 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800384 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700385 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
386 final int depth = parser.getDepth();
387 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700388 while (((type = parser.next()) != XmlPullParser.END_TAG ||
389 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800390 if ((type == XmlPullParser.START_TAG)
391 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800392
393 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
394 final int displayDepth = parser.getDepth();
395 while (((type = parser.next()) != XmlPullParser.END_TAG ||
396 parser.getDepth() > displayDepth)
397 && type != XmlPullParser.END_DOCUMENT) {
398 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
399 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700400 profiles.add(new DisplayOption(gridOption, context,
401 Xml.asAttributeSet(parser),
402 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800403 }
404 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700405 }
406 }
407 } catch (IOException|XmlPullParserException e) {
408 throw new RuntimeException(e);
409 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800410
Sunny Goyalae190ff2020-04-14 00:19:01 +0000411 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800412 if (!TextUtils.isEmpty(gridName)) {
413 for (DisplayOption option : profiles) {
414 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000415 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800416 }
417 }
418 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000419 if (filteredProfiles.isEmpty()) {
420 // No grid found, use the default options
421 for (DisplayOption option : profiles) {
422 if (option.canBeDefault) {
423 filteredProfiles.add(option);
424 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800425 }
426 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000427 if (filteredProfiles.isEmpty()) {
428 throw new RuntimeException("No display option with canBeDefault=true");
429 }
430 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700431 }
432
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700433 private int getLauncherIconDensity(int requiredSize) {
434 // Densities typically defined by an app.
435 int[] densityBuckets = new int[] {
436 DisplayMetrics.DENSITY_LOW,
437 DisplayMetrics.DENSITY_MEDIUM,
438 DisplayMetrics.DENSITY_TV,
439 DisplayMetrics.DENSITY_HIGH,
440 DisplayMetrics.DENSITY_XHIGH,
441 DisplayMetrics.DENSITY_XXHIGH,
442 DisplayMetrics.DENSITY_XXXHIGH
443 };
444
445 int density = DisplayMetrics.DENSITY_XXXHIGH;
446 for (int i = densityBuckets.length - 1; i >= 0; i--) {
447 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
448 / DisplayMetrics.DENSITY_DEFAULT;
449 if (expectedSize >= requiredSize) {
450 density = densityBuckets[i];
451 }
452 }
453
454 return density;
455 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700456
Adam Cohen2e6da152015-05-06 11:42:25 -0700457 /**
458 * Apply any Partner customization grid overrides.
459 *
460 * Currently we support: all apps row / column count.
461 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700462 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
463 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700464 if (p != null) {
465 p.applyInvariantDeviceProfileOverrides(this, dm);
466 }
467 }
468
Sunny Goyal415f1732018-11-29 10:33:47 -0800469 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700470 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700471 }
472
Sunny Goyal19ff7282021-04-22 10:12:54 -0700473 private static DisplayOption invDistWeightedInterpolate(
474 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
475 int minWidthPx = Integer.MAX_VALUE;
476 int minHeightPx = Integer.MAX_VALUE;
477 for (WindowBounds bounds : displayInfo.supportedBounds) {
478 boolean isTablet = displayInfo.isTablet(bounds);
479 if (isTablet && isSplitDisplay) {
480 // For split displays, take half width per page
481 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
482 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700483
Sunny Goyal19ff7282021-04-22 10:12:54 -0700484 } else if (!isTablet && bounds.isLandscape()) {
485 // We will use transposed layout in this case
486 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
487 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
488 } else {
489 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
490 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
491 }
492 }
493
494 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
495 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700496
497 // Sort the profiles based on the closeness to the device size
498 Collections.sort(points, (a, b) ->
499 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
500 dist(width, height, b.minWidthDps, b.minHeightDps)));
501
502 GridOption closestOption = points.get(0).grid;
503 float weights = 0;
504
505 DisplayOption p = points.get(0);
506 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
507 return p;
508 }
509
510 DisplayOption out = new DisplayOption(closestOption);
511 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
512 p = points.get(i);
513 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
514 weights += w;
515 out.add(new DisplayOption().add(p).multiply(w));
516 }
517 return out.multiply(1.0f / weights);
518 }
519
Sunny Goyal27835952017-01-13 12:15:53 -0800520 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700521 Resources res = context.getResources();
522 Configuration config = context.getResources().getConfiguration();
523
524 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
525 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
526
Sunny Goyal19ff7282021-04-22 10:12:54 -0700527 DeviceProfile bestMatch = supportedProfiles.get(0);
528 float minDiff = Float.MAX_VALUE;
529
530 for (DeviceProfile profile : supportedProfiles) {
531 float diff = Math.abs(profile.availableWidthPx - availableWidth)
532 + Math.abs(profile.availableHeightPx - availableHeight);
533 if (diff < minDiff) {
534 minDiff = diff;
535 bestMatch = profile;
536 }
537 }
538 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800539 }
540
Sunny Goyal415f1732018-11-29 10:33:47 -0800541 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700542 float d = dist(x0, y0, x1, y1);
543 if (Float.compare(d, 0f) == 0) {
544 return Float.POSITIVE_INFINITY;
545 }
546 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
547 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700548
549 /**
550 * As a ratio of screen height, the total distance we want the parallax effect to span
551 * horizontally
552 */
553 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
554 float aspectRatio = width / (float) height;
555
556 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
557 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
558 // We will use these two data points to extrapolate how much the wallpaper parallax effect
559 // to span (ie travel) at any aspect ratio:
560
561 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
562 final float ASPECT_RATIO_PORTRAIT = 10/16f;
563 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
564 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
565
566 // To find out the desired width at different aspect ratios, we use the following two
567 // formulas, where the coefficient on x is the aspect ratio (width/height):
568 // (16/10)x + y = 1.5
569 // (10/16)x + y = 1.2
570 // We solve for x and y and end up with a final formula:
571 final float x =
572 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
573 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
574 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
575 return x * aspectRatio + y;
576 }
577
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700578 public interface OnIDPChangeListener {
579
Sunny Goyalb47172b2021-05-03 19:59:51 -0700580 /**
581 * Called when the device provide changes
582 */
583 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700584 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800585
586
Sunny Goyaleff44f32019-01-09 17:29:49 -0800587 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800588
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800589 public static final String TAG_NAME = "grid-option";
590
Sunny Goyaleff44f32019-01-09 17:29:49 -0800591 public final String name;
592 public final int numRows;
593 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800594
595 private final int numFolderRows;
596 private final int numFolderColumns;
597
Sunny Goyal19ff7282021-04-22 10:12:54 -0700598 private final int numAllAppsColumns;
599 private final int numDatabaseAllAppsColumns;
600 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700601 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800602
Tracy Zhou7df93d22020-01-27 13:44:06 -0800603 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000604
Sunny Goyal415f1732018-11-29 10:33:47 -0800605 private final int defaultLayoutId;
606 private final int demoModeLayoutId;
607
Jon Mirandae126d722021-02-25 10:45:20 -0500608 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400609 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500610
Sunny Goyal5bc18462019-01-07 15:13:39 -0800611 private final SparseArray<TypedValue> extraAttrs;
612
Sunny Goyaleff44f32019-01-09 17:29:49 -0800613 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800614 TypedArray a = context.obtainStyledAttributes(
615 attrs, R.styleable.GridDisplayOption);
616 name = a.getString(R.styleable.GridDisplayOption_name);
617 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
618 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
619
Tracy Zhou7df93d22020-01-27 13:44:06 -0800620 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800621 defaultLayoutId = a.getResourceId(
622 R.styleable.GridDisplayOption_defaultLayoutId, 0);
623 demoModeLayoutId = a.getResourceId(
624 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700625
626 numAllAppsColumns = a.getInt(
627 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
628 numDatabaseAllAppsColumns = a.getInt(
629 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
630
631 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800632 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700633 numDatabaseHotseatIcons = a.getInt(
634 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
635
Sunny Goyal415f1732018-11-29 10:33:47 -0800636 numFolderRows = a.getInt(
637 R.styleable.GridDisplayOption_numFolderRows, numRows);
638 numFolderColumns = a.getInt(
639 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700640
Jon Mirandae126d722021-02-25 10:45:20 -0500641 isScalable = a.getBoolean(
642 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400643 devicePaddingId = a.getResourceId(
644 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500645
Sunny Goyal415f1732018-11-29 10:33:47 -0800646 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800647 extraAttrs = Themes.createValueMap(context, attrs,
648 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800649 }
650 }
651
Sunny Goyal19ff7282021-04-22 10:12:54 -0700652 @VisibleForTesting
653 static final class DisplayOption {
654
655 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800656
Sunny Goyal415f1732018-11-29 10:33:47 -0800657 private final float minWidthDps;
658 private final float minHeightDps;
659 private final boolean canBeDefault;
660
Jon Mirandae126d722021-02-25 10:45:20 -0500661 private float minCellHeight;
662 private float minCellWidth;
663 private float borderSpacing;
664
Sunny Goyal415f1732018-11-29 10:33:47 -0800665 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800666 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700667 private float landscapeIconSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200668 private float twoPanelPortraitIconSize;
669 private float twoPanelLandscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200670 private float landscapeIconTextSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200671 private float twoPanelPortraitIconTextSize;
672 private float twoPanelLandscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000673 private float allAppsIconSize;
674 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800675
Sunny Goyal19ff7282021-04-22 10:12:54 -0700676 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800677 this.grid = grid;
678
679 TypedArray a = context.obtainStyledAttributes(
680 attrs, R.styleable.ProfileDisplayOption);
681
Sunny Goyal415f1732018-11-29 10:33:47 -0800682 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
683 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700684
685 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
686 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800687
Jon Mirandae126d722021-02-25 10:45:20 -0500688 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
689 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
690 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
691
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700692 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800693 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
694 iconSize);
Andras Kloczl30fe9152021-08-05 18:02:29 +0200695 twoPanelPortraitIconSize = a.getFloat(
696 R.styleable.ProfileDisplayOption_twoPanelPortraitIconSize, iconSize);
697 twoPanelLandscapeIconSize = a.getFloat(
698 R.styleable.ProfileDisplayOption_twoPanelLandscapeIconSize,
699 landscapeIconSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800700 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200701 landscapeIconTextSize = a.getFloat(
702 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Andras Kloczl30fe9152021-08-05 18:02:29 +0200703 twoPanelPortraitIconTextSize = a.getFloat(
704 R.styleable.ProfileDisplayOption_twoPanelPortraitIconTextSize, iconTextSize);
705 twoPanelLandscapeIconTextSize = a.getFloat(
706 R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize,
707 landscapeIconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700708
Sunny Goyalae190ff2020-04-14 00:19:01 +0000709 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
710 iconSize);
711 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
712 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800713 a.recycle();
714 }
715
716 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700717 this(null);
718 }
719
720 DisplayOption(GridOption grid) {
721 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800722 minWidthDps = 0;
723 minHeightDps = 0;
724 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500725 minCellHeight = 0;
726 minCellWidth = 0;
727 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800728 }
729
730 private DisplayOption multiply(float w) {
731 iconSize *= w;
732 landscapeIconSize *= w;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200733 twoPanelPortraitIconSize *= w;
734 twoPanelLandscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000735 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800736 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200737 landscapeIconTextSize *= w;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200738 twoPanelPortraitIconTextSize *= w;
739 twoPanelLandscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000740 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500741 minCellHeight *= w;
742 minCellWidth *= w;
743 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800744 return this;
745 }
746
747 private DisplayOption add(DisplayOption p) {
748 iconSize += p.iconSize;
749 landscapeIconSize += p.landscapeIconSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200750 twoPanelPortraitIconSize += p.twoPanelPortraitIconSize;
751 twoPanelLandscapeIconSize += p.twoPanelLandscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000752 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800753 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200754 landscapeIconTextSize += p.landscapeIconTextSize;
Andras Kloczl30fe9152021-08-05 18:02:29 +0200755 twoPanelPortraitIconTextSize += p.twoPanelPortraitIconTextSize;
756 twoPanelLandscapeIconTextSize += p.twoPanelLandscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000757 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500758 minCellHeight += p.minCellHeight;
759 minCellWidth += p.minCellWidth;
760 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800761 return this;
762 }
763 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000764}