blob: c0512925128308952d5f5682daf979b894b29277 [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
Thales Lima1de4d552021-10-13 16:13:25 +01002 * Copyright (C) 2021 The Android Open Source Project
Adam Cohen2e6da152015-05-06 11:42:25 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Sunny Goyal19ff7282021-04-22 10:12:54 -070019import static com.android.launcher3.Utilities.dpiFromPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010020import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070021import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Alex Chau6ed408f2022-03-04 12:58:05 +000022import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
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;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070036import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080037import android.text.TextUtils;
38import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070039import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010040import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080041import android.util.SparseArray;
42import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070043import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080044import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070045
Alex Chau1c883d82021-12-01 18:43:10 +000046import androidx.annotation.IntDef;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.Nullable;
48import androidx.annotation.VisibleForTesting;
Thales Limab8c05952022-05-23 16:58:38 +010049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070050
Sunny Goyal68031ca2021-08-02 12:23:44 -070051import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010052import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalfd58da62020-08-11 12:06:49 -070053import com.android.launcher3.util.DisplayController;
54import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080055import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070056import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080057import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070058import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080059import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070060
Sunny Goyal819e1932016-07-07 16:43:58 -070061import org.xmlpull.v1.XmlPullParser;
62import org.xmlpull.v1.XmlPullParserException;
63
64import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000065import java.lang.annotation.Retention;
66import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070067import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070068import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080069import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070070import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070071
72public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070073
Hyunyoung Songc55a3502018-12-04 15:43:16 -080074 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070075 // We do not need any synchronization for this variable as its only written on UI thread.
76 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070077 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070078
Alex Chau1c883d82021-12-01 18:43:10 +000079 @Retention(RetentionPolicy.SOURCE)
80 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010081 public @interface DeviceType {}
82
Alex Chau1c883d82021-12-01 18:43:10 +000083 public static final int TYPE_PHONE = 0;
84 public static final int TYPE_MULTI_DISPLAY = 1;
85 public static final int TYPE_TABLET = 2;
86
Hyunyoung Songc55a3502018-12-04 15:43:16 -080087 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080088
Sunny Goyal53d7ee42015-05-22 12:25:45 -070089 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
90
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070091 // Constants that affects the interpolation curve between statically defined device profile
92 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080093 private static final float KNEARESTNEIGHBOR = 3;
94 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070095
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070096 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080097 private static final float WEIGHT_EFFICIENT = 100000f;
98
Thales Lima83bedbf2021-10-05 17:47:39 +010099 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
100 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000101 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100102 static final int INDEX_DEFAULT = 0;
103 static final int INDEX_LANDSCAPE = 1;
104 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
105 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100106
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700107 /**
108 * Number of icons per row and column in the workspace.
109 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700110 public int numRows;
111 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000112 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700113
114 /**
115 * Number of icons per row and column in the folder.
116 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700117 public int numFolderRows;
118 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100119 public float[] iconSize;
120 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700121 public int iconBitmapSize;
122 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000123 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700124
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126
Thales Lima83bedbf2021-10-05 17:47:39 +0100127 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100128 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000129 public float[] hotseatBorderSpaces;
Vinit Nayakc7293172022-07-18 16:41:50 -0700130 public int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100131
Thales Lima83bedbf2021-10-05 17:47:39 +0100132 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500133
Thales Limab7ef5692022-03-10 10:32:36 +0000134 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000135 public float[] allAppsIconSize;
136 public float[] allAppsIconTextSize;
137 public PointF[] allAppsBorderSpaces;
138
Sunny Goyal5bc18462019-01-07 15:13:39 -0800139 private SparseArray<TypedValue> mExtraAttrs;
140
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700141 /**
142 * Number of icons inside the hotseat area.
143 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800144 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700145
146 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000147 * Number of icons inside the hotseat area when using 3 buttons navigation.
148 */
149 public int numShrunkenHotseatIcons;
150
151 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700152 * Number of icons inside the hotseat area that is stored in the database. This is greater than
153 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
154 * sizes that share the same DB.
155 */
156 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700157
Thales Lima425f6822022-05-10 13:44:58 -0300158 public int[] hotseatColumnSpan;
Thales Limab8c05952022-05-23 16:58:38 +0100159 public float[] hotseatBarBottomSpace;
160 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300161
Jon Miranda6f7e9702019-09-16 14:44:14 -0700162 /**
163 * Number of columns in the all apps list.
164 */
165 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700166 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700167
Jon Mirandae126d722021-02-25 10:45:20 -0500168 /**
169 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
170 */
171 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400172 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500173
Tracy Zhou7df93d22020-01-27 13:44:06 -0800174 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800175 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700176 int demoModeLayoutId;
Thales Lima12d0eff2022-03-25 17:06:11 +0000177 boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700178
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000179 /**
180 * An immutable list of supported profiles.
181 */
182 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700183
sfufa@google.comde013292021-09-21 18:22:44 -0700184 @Nullable
185 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500186
Sunny Goyal6f866092016-03-17 17:04:15 -0700187 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700188 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700189
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700190 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700191
Sunny Goyalf633ef52018-03-13 09:57:05 -0700192 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800193 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700194
Sunny Goyalbbf01842015-10-08 07:41:15 -0700195 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700196 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700197 String gridName = getCurrentGridName(context);
198 String newGridName = initGrid(context, gridName);
199 if (!newGridName.equals(gridName)) {
200 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
201 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700202 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700203
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700204 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100205 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000206 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
207 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100208 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700209 }
210 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700211 }
212
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700213 /**
214 * This constructor should NOT have any monitors by design.
215 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800216 public InvariantDeviceProfile(Context context, String gridName) {
217 String newName = initGrid(context, gridName);
218 if (newName == null || !newName.equals(gridName)) {
219 throw new IllegalArgumentException("Unknown grid name");
220 }
221 }
222
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800224 * This constructor should NOT have any monitors by design.
225 */
226 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700227 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100228 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700229 String gridName = getCurrentGridName(context);
230
231 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000232 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
233 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700234 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000235 defaultInfo,
236 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
237 /*allowDisabledGrid=*/false),
238 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700239
Alex Chau661f02d2022-06-07 14:03:43 +0100240 Context displayContext = context.createDisplayContext(display);
241 Info myInfo = new Info(displayContext);
Alex Chau1c883d82021-12-01 18:43:10 +0000242 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700243 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000244 myInfo,
245 getPredefinedDeviceProfiles(context, gridName, deviceType,
246 /*allowDisabledGrid=*/false),
247 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700248
249 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
250 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100251 result.iconSizes[INDEX_DEFAULT] =
252 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
253 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700254 result.iconSizes[i] = Math.min(
255 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000256 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700257
Thales Lima83bedbf2021-10-05 17:47:39 +0100258 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
259 COUNT_SIZES);
260 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
261 COUNT_SIZES);
Thales Lima12d0eff2022-03-25 17:06:11 +0000262 System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0,
263 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500264
Alex Chau1c883d82021-12-01 18:43:10 +0000265 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800266 }
267
Alex Chau238aaee2021-10-06 16:15:24 +0100268 /**
269 * Reinitialize the current grid after a restore, where some grids might now be disabled.
270 */
271 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000272 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100273 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000274 String newGridName = initGrid(context, currentGridName);
275 String newDbFile = dbFile;
276 if (!newDbFile.equals(currentDbFile)) {
277 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100278 + ", migrating to: " + newGridName
279 + ", removing all other grid db files");
280 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
281 if (gridDbFile.equals(currentDbFile)) {
282 continue;
283 }
284 if (context.getDatabasePath(gridDbFile).delete()) {
285 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
286 }
287 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000288 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100289 }
290 }
291
Alex Chau1c883d82021-12-01 18:43:10 +0000292 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800293 int flagPhone = 1 << 0;
294 int flagTablet = 1 << 1;
295
296 int type = displayInfo.supportedBounds.stream()
297 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
298 .reduce(0, (a, b) -> a | b);
299 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
300 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000301 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800302 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000303 return TYPE_TABLET;
304 } else {
305 return TYPE_PHONE;
306 }
307 }
308
Tracy Zhou42255d22020-03-13 00:38:11 -0700309 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700310 return Utilities.isGridOptionsEnabled(context)
311 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700312 }
313
Sunny Goyaleff44f32019-01-09 17:29:49 -0800314 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700315 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000316 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700317
318 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000319 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100320 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700321 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000322 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
323 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700324 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800325 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700326
Alex Chau1c883d82021-12-01 18:43:10 +0000327 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
328 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700329 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700330 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000331 numRows = closestProfile.numRows;
332 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000333 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000334 dbFile = closestProfile.dbFile;
335 defaultLayoutId = closestProfile.defaultLayoutId;
336 demoModeLayoutId = closestProfile.demoModeLayoutId;
337 numFolderRows = closestProfile.numFolderRows;
338 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500339 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400340 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000341 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000342
Vinit Nayakc7293172022-07-18 16:41:50 -0700343 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
344
Sunny Goyalae190ff2020-04-14 00:19:01 +0000345 mExtraAttrs = closestProfile.extraAttrs;
346
Thales Lima83bedbf2021-10-05 17:47:39 +0100347 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100348 float maxIconSize = iconSize[0];
349 for (int i = 1; i < iconSize.length; i++) {
350 maxIconSize = Math.max(maxIconSize, iconSize[i]);
351 }
352 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000353 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
354
Thales Lima83bedbf2021-10-05 17:47:39 +0100355 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700356
Thales Lima83bedbf2021-10-05 17:47:39 +0100357 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100358
Thales Lima83bedbf2021-10-05 17:47:39 +0100359 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100360 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700361
Thales Limad90faab2021-09-21 17:18:47 +0100362 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100363
Sunny Goyal19ff7282021-04-22 10:12:54 -0700364 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000365 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000366 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700367 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300368 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000369 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Thales Limab8c05952022-05-23 16:58:38 +0100370 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
371 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700372
373 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000374 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700375 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500376
Thales Limab7ef5692022-03-10 10:32:36 +0000377 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000378 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
379 allAppsIconSize = displayOption.allAppsIconSizes;
380 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100381 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000382 allAppsIconSize = iconSize;
383 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000384 }
385
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400386 if (devicePaddingId != 0) {
387 devicePaddings = new DevicePaddings(context, devicePaddingId);
388 }
389
Thales Lima12d0eff2022-03-25 17:06:11 +0000390 inlineQsb = displayOption.inlineQsb;
391
Sunny Goyalae190ff2020-04-14 00:19:01 +0000392 // If the partner customization apk contains any grid overrides, apply them
393 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700394 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700395
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000396 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700397 defaultWallpaperSize = new Point(displayInfo.currentSize);
398 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000399 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000400 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000401 .setWindowBounds(bounds)
402 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700403
Sunny Goyal19ff7282021-04-22 10:12:54 -0700404 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
405 int displayWidth = bounds.bounds.width();
406 int displayHeight = bounds.bounds.height();
407 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700408
Sunny Goyal19ff7282021-04-22 10:12:54 -0700409 // We need to ensure that there is enough extra space in the wallpaper
410 // for the intended parallax effects
411 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300412 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
413 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700414 ? 2
415 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
416 defaultWallpaperSize.x =
417 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700418 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000419 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700420
421 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
422 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700423 }
424
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700425 public void addOnChangeListener(OnIDPChangeListener listener) {
426 mChangeListeners.add(listener);
427 }
428
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800429 public void removeOnChangeListener(OnIDPChangeListener listener) {
430 mChangeListeners.remove(listener);
431 }
432
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800433
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800434 public void setCurrentGrid(Context context, String gridName) {
435 Context appContext = context.getApplicationContext();
436 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700437 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800438 }
439
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700440 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700441 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000442 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
443 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700444 }
445
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700446 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700447 Object[] oldState = toModelState();
448
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700449 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700450 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700451 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700452
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700453 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700454 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700455 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700456 }
457 }
458
Alex Chau1c883d82021-12-01 18:43:10 +0000459 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
460 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800461 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100462
Alex Chau1c883d82021-12-01 18:43:10 +0000463 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700464 final int depth = parser.getDepth();
465 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700466 while (((type = parser.next()) != XmlPullParser.END_TAG ||
467 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800468 if ((type == XmlPullParser.START_TAG)
469 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800470
Alex Chau1c883d82021-12-01 18:43:10 +0000471 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
472 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100473 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100474 final int displayDepth = parser.getDepth();
475 while (((type = parser.next()) != XmlPullParser.END_TAG
476 || parser.getDepth() > displayDepth)
477 && type != XmlPullParser.END_DOCUMENT) {
478 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
479 parser.getName())) {
480 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100481 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100482 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800483 }
484 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700485 }
486 }
sfufa@google.comde013292021-09-21 18:22:44 -0700487 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700488 throw new RuntimeException(e);
489 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800490
Sunny Goyalae190ff2020-04-14 00:19:01 +0000491 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800492 if (!TextUtils.isEmpty(gridName)) {
493 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100494 if (gridName.equals(option.grid.name)
495 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000496 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800497 }
498 }
499 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000500 if (filteredProfiles.isEmpty()) {
501 // No grid found, use the default options
502 for (DisplayOption option : profiles) {
503 if (option.canBeDefault) {
504 filteredProfiles.add(option);
505 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800506 }
507 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000508 if (filteredProfiles.isEmpty()) {
509 throw new RuntimeException("No display option with canBeDefault=true");
510 }
511 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700512 }
513
Thales Lima7ec83822021-08-05 13:32:10 +0100514 /**
515 * @return all the grid options that can be shown on the device
516 */
517 public List<GridOption> parseAllGridOptions(Context context) {
518 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100519
Alex Chau1c883d82021-12-01 18:43:10 +0000520 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100521 final int depth = parser.getDepth();
522 int type;
523 while (((type = parser.next()) != XmlPullParser.END_TAG
524 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
525 if ((type == XmlPullParser.START_TAG)
526 && GridOption.TAG_NAME.equals(parser.getName())) {
527 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000528 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100529 if (option.isEnabled) {
530 result.add(option);
531 }
532 }
533 }
534 } catch (IOException | XmlPullParserException e) {
535 Log.e(TAG, "Error parsing device profile", e);
536 return Collections.emptyList();
537 }
538 return result;
539 }
540
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700541 private int getLauncherIconDensity(int requiredSize) {
542 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700543 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700544 DisplayMetrics.DENSITY_LOW,
545 DisplayMetrics.DENSITY_MEDIUM,
546 DisplayMetrics.DENSITY_TV,
547 DisplayMetrics.DENSITY_HIGH,
548 DisplayMetrics.DENSITY_XHIGH,
549 DisplayMetrics.DENSITY_XXHIGH,
550 DisplayMetrics.DENSITY_XXXHIGH
551 };
552
553 int density = DisplayMetrics.DENSITY_XXXHIGH;
554 for (int i = densityBuckets.length - 1; i >= 0; i--) {
555 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
556 / DisplayMetrics.DENSITY_DEFAULT;
557 if (expectedSize >= requiredSize) {
558 density = densityBuckets[i];
559 }
560 }
561
562 return density;
563 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700564
Adam Cohen2e6da152015-05-06 11:42:25 -0700565 /**
566 * Apply any Partner customization grid overrides.
567 *
568 * Currently we support: all apps row / column count.
569 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700570 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
571 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700572 if (p != null) {
573 p.applyInvariantDeviceProfileOverrides(this, dm);
574 }
575 }
576
Sunny Goyal415f1732018-11-29 10:33:47 -0800577 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700578 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700579 }
580
Sunny Goyal19ff7282021-04-22 10:12:54 -0700581 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000582 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700583 int minWidthPx = Integer.MAX_VALUE;
584 int minHeightPx = Integer.MAX_VALUE;
585 for (WindowBounds bounds : displayInfo.supportedBounds) {
586 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000587 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700588 // For split displays, take half width per page
589 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
590 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700591
Sunny Goyal19ff7282021-04-22 10:12:54 -0700592 } else if (!isTablet && bounds.isLandscape()) {
593 // We will use transposed layout in this case
594 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
595 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
596 } else {
597 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
598 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
599 }
600 }
601
Thales Lima425f6822022-05-10 13:44:58 -0300602 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
603 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700604
605 // Sort the profiles based on the closeness to the device size
606 Collections.sort(points, (a, b) ->
607 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
608 dist(width, height, b.minWidthDps, b.minHeightDps)));
609
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700610 DisplayOption closestPoint = points.get(0);
611 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700612 float weights = 0;
613
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700614 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
615 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700616 }
617
618 DisplayOption out = new DisplayOption(closestOption);
619 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700620 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700621 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
622 weights += w;
623 out.add(new DisplayOption().add(p).multiply(w));
624 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700625 out.multiply(1.0f / weights);
626
Thales Lima6e0005a2021-10-27 15:53:41 +0100627 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700628 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100629 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
630 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700631 }
632
633 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700634 }
635
Sunny Goyal27835952017-01-13 12:15:53 -0800636 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700637 Resources res = context.getResources();
638 Configuration config = context.getResources().getConfiguration();
639
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400640 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
641 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100642 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
643
Alex Chaud3e8cc42022-05-03 17:45:34 +0100644 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400645 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700646
Sunny Goyal187b16c2022-03-01 16:53:23 -0800647 /**
648 * Returns the device profile matching the provided screen configuration
649 */
650 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700651 DeviceProfile bestMatch = supportedProfiles.get(0);
652 float minDiff = Float.MAX_VALUE;
653
654 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400655 float diff = Math.abs(profile.widthPx - screenWidth)
656 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700657 if (diff < minDiff) {
658 minDiff = diff;
659 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800660 } else if (diff == minDiff && profile.rotationHint == rotation) {
661 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700662 }
663 }
664 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800665 }
666
Sunny Goyal415f1732018-11-29 10:33:47 -0800667 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700668 float d = dist(x0, y0, x1, y1);
669 if (Float.compare(d, 0f) == 0) {
670 return Float.POSITIVE_INFINITY;
671 }
672 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
673 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700674
675 /**
676 * As a ratio of screen height, the total distance we want the parallax effect to span
677 * horizontally
678 */
679 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
680 float aspectRatio = width / (float) height;
681
682 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
683 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
684 // We will use these two data points to extrapolate how much the wallpaper parallax effect
685 // to span (ie travel) at any aspect ratio:
686
sfufa@google.comde013292021-09-21 18:22:44 -0700687 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
688 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700689 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
690 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
691
692 // To find out the desired width at different aspect ratios, we use the following two
693 // formulas, where the coefficient on x is the aspect ratio (width/height):
694 // (16/10)x + y = 1.5
695 // (10/16)x + y = 1.2
696 // We solve for x and y and end up with a final formula:
697 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700698 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
699 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700700 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
701 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
702 return x * aspectRatio + y;
703 }
704
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700705 public interface OnIDPChangeListener {
706
Sunny Goyalb47172b2021-05-03 19:59:51 -0700707 /**
708 * Called when the device provide changes
709 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700710 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700711 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800712
713
Sunny Goyaleff44f32019-01-09 17:29:49 -0800714 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800715
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800716 public static final String TAG_NAME = "grid-option";
717
Alex Chau1c883d82021-12-01 18:43:10 +0000718 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
719 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
720 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
721 private static final int DEVICE_CATEGORY_ALL =
722 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
723
Sunny Goyaleff44f32019-01-09 17:29:49 -0800724 public final String name;
725 public final int numRows;
726 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000727 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100728 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800729
730 private final int numFolderRows;
731 private final int numFolderColumns;
732
Sunny Goyal19ff7282021-04-22 10:12:54 -0700733 private final int numAllAppsColumns;
734 private final int numDatabaseAllAppsColumns;
735 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000736 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700737 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100738
Thales Lima425f6822022-05-10 13:44:58 -0300739 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800740
Vinit Nayakc7293172022-07-18 16:41:50 -0700741 private int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800742 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000743
Sunny Goyal415f1732018-11-29 10:33:47 -0800744 private final int defaultLayoutId;
745 private final int demoModeLayoutId;
746
Jon Mirandae126d722021-02-25 10:45:20 -0500747 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400748 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500749
Sunny Goyal5bc18462019-01-07 15:13:39 -0800750 private final SparseArray<TypedValue> extraAttrs;
751
Alex Chau1c883d82021-12-01 18:43:10 +0000752 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800753 TypedArray a = context.obtainStyledAttributes(
754 attrs, R.styleable.GridDisplayOption);
755 name = a.getString(R.styleable.GridDisplayOption_name);
756 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
757 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000758 numSearchContainerColumns = a.getInt(
759 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800760
Tracy Zhou7df93d22020-01-27 13:44:06 -0800761 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000762 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100763 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
764 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
765 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800766 demoModeLayoutId = a.getResourceId(
767 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768
769 numAllAppsColumns = a.getInt(
770 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
771 numDatabaseAllAppsColumns = a.getInt(
772 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
773
774 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800775 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000776 numShrunkenHotseatIcons = a.getInt(
777 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700778 numDatabaseHotseatIcons = a.getInt(
779 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100780
Thales Lima425f6822022-05-10 13:44:58 -0300781 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
782 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
783 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
784 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
785 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
786 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
787 numColumns);
788 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
789 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
790 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700791
Vinit Nayakc7293172022-07-18 16:41:50 -0700792 inlineNavButtonsEndSpacing =
793 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
794 R.dimen.taskbar_button_margin_default);
Sunny Goyal415f1732018-11-29 10:33:47 -0800795 numFolderRows = a.getInt(
796 R.styleable.GridDisplayOption_numFolderRows, numRows);
797 numFolderColumns = a.getInt(
798 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700799
Jon Mirandae126d722021-02-25 10:45:20 -0500800 isScalable = a.getBoolean(
801 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400802 devicePaddingId = a.getResourceId(
803 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500804
Alex Chau1c883d82021-12-01 18:43:10 +0000805 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
806 DEVICE_CATEGORY_ALL);
807 isEnabled = (deviceType == TYPE_PHONE
808 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
809 || (deviceType == TYPE_TABLET
810 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
811 || (deviceType == TYPE_MULTI_DISPLAY
812 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
813 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100814
Sunny Goyal415f1732018-11-29 10:33:47 -0800815 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800816 extraAttrs = Themes.createValueMap(context, attrs,
817 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800818 }
819 }
820
Sunny Goyal19ff7282021-04-22 10:12:54 -0700821 @VisibleForTesting
822 static final class DisplayOption {
Thales Lima12d0eff2022-03-25 17:06:11 +0000823 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
824 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
825 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
826 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
827 private static final int DONT_INLINE_QSB = 0;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700828
829 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800830
Sunny Goyal415f1732018-11-29 10:33:47 -0800831 private final float minWidthDps;
832 private final float minHeightDps;
833 private final boolean canBeDefault;
Thales Lima12d0eff2022-03-25 17:06:11 +0000834 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800835
Thales Lima83bedbf2021-10-05 17:47:39 +0100836 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100837
838 private float folderBorderSpace;
839 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100840 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima425f6822022-05-10 13:44:58 -0300841 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
Thales Lima6e7f36c2022-01-04 12:14:11 +0000842 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +0100843 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
844 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100845
Thales Lima78d00ad2021-09-30 11:29:06 +0100846 private final float[] iconSizes = new float[COUNT_SIZES];
847 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800848
Thales Limab7ef5692022-03-10 10:32:36 +0000849 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000850 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
851 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
852 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
853
Thales Lima1de4d552021-10-13 16:13:25 +0100854 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800855 this.grid = grid;
856
Thales Lima1de4d552021-10-13 16:13:25 +0100857 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800858
Sunny Goyal415f1732018-11-29 10:33:47 -0800859 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
860 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700861
Thales Lima1de4d552021-10-13 16:13:25 +0100862 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800863
Thales Lima12d0eff2022-03-25 17:06:11 +0000864 int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb,
865 DONT_INLINE_QSB);
866 inlineQsb[INDEX_DEFAULT] =
867 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
868 inlineQsb[INDEX_LANDSCAPE] =
869 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
870 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
871 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
872 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
873 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
874 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
875 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
876
Thales Lima83bedbf2021-10-05 17:47:39 +0100877 float x;
878 float y;
879
Thales Lima85c942f2021-12-31 13:04:20 +0000880 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
881 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100882 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000883
884 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
885 minCellSize[INDEX_DEFAULT].x);
886 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
887 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100888 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100889
Thales Lima85c942f2021-12-31 13:04:20 +0000890 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100891 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000892 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100893 minCellSize[INDEX_DEFAULT].y);
894 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
895
Thales Lima85c942f2021-12-31 13:04:20 +0000896 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100897 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000898 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100899 minCellSize[INDEX_DEFAULT].y);
900 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100901
Thales Lima85c942f2021-12-31 13:04:20 +0000902 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000903 float borderSpaceLandscape = a.getFloat(
904 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000905 float borderSpaceTwoPanelPortrait = a.getFloat(
906 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
907 float borderSpaceTwoPanelLandscape = a.getFloat(
908 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100909
Thales Lima85c942f2021-12-31 13:04:20 +0000910 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
911 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100912 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000913
914 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
915 borderSpaceLandscape);
916 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
917 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100918 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
919
920 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000921 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
922 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100923 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000924 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
925 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100926 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
927
928 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000929 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
930 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100931 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000932 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
933 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100934 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
935
Thales Limabb7d3882021-12-22 12:56:29 +0000936 folderBorderSpace = borderSpace;
937
Thales Limab7ef5692022-03-10 10:32:36 +0000938 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
939 minCellSize[INDEX_DEFAULT].x);
940 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
941 minCellSize[INDEX_DEFAULT].y);
942 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
943
944 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
945 allAppsCellSize[INDEX_DEFAULT].x);
946 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
947 allAppsCellSize[INDEX_DEFAULT].y);
948 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
949
950 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
951 allAppsCellSize[INDEX_DEFAULT].x);
952 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
953 allAppsCellSize[INDEX_DEFAULT].y);
954 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
955
956 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
957 allAppsCellSize[INDEX_DEFAULT].x);
958 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
959 allAppsCellSize[INDEX_DEFAULT].y);
960 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
961
Thales Lima080d8902022-03-28 15:30:29 +0100962 float allAppsBorderSpace = a.getFloat(
963 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
964 float allAppsBorderSpaceLandscape = a.getFloat(
965 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
966 allAppsBorderSpace);
967 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000968 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +0100969 allAppsBorderSpace);
970 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000971 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +0100972 allAppsBorderSpace);
973
974 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
975 allAppsBorderSpace);
976 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
977 allAppsBorderSpace);
978 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
979
980 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
981 allAppsBorderSpaceLandscape);
982 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
983 allAppsBorderSpaceLandscape);
984 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
985
986 x = a.getFloat(
987 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
988 allAppsBorderSpaceTwoPanelPortrait);
989 y = a.getFloat(
990 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
991 allAppsBorderSpaceTwoPanelPortrait);
992 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
993
994 x = a.getFloat(
995 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
996 allAppsBorderSpaceTwoPanelLandscape);
997 y = a.getFloat(
998 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
999 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001000 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001001
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001002 iconSizes[INDEX_DEFAULT] =
1003 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1004 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001005 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001006 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001007 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001008 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001009 iconSizes[INDEX_DEFAULT]);
1010 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001011 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001012 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001013
Thales Limabb7d3882021-12-22 12:56:29 +00001014 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1015 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
1016 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
1017 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1018 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1019 allAppsIconSizes[INDEX_DEFAULT]);
1020 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1021 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1022 allAppsIconSizes[INDEX_DEFAULT]);
1023
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001024 textSizes[INDEX_DEFAULT] =
1025 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1026 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001027 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001028 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001029 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001030 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001031 textSizes[INDEX_DEFAULT]);
1032 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001033 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001034 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001035
Thales Limabb7d3882021-12-22 12:56:29 +00001036 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1037 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1038 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1039 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1040 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1041 allAppsIconTextSizes[INDEX_DEFAULT]);
1042 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1043 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1044 allAppsIconTextSizes[INDEX_DEFAULT]);
1045
Thales Lima83bedbf2021-10-05 17:47:39 +01001046 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1047 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001048 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1049 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1050 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001051 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001052 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001053 horizontalMargin[INDEX_DEFAULT]);
1054 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001055 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001056 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001057
Thales Lima6e7f36c2022-01-04 12:14:11 +00001058 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
1059 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +00001060 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
1061 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
1062 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001063 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1064 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
1065 hotseatBorderSpaces[INDEX_DEFAULT]);
1066 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1067 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
1068 hotseatBorderSpaces[INDEX_DEFAULT]);
1069
Thales Limab8c05952022-05-23 16:58:38 +01001070 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1071 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
1072 ResourcesCompat.getFloat(context.getResources(),
1073 R.dimen.hotseat_bar_bottom_space_default));
1074 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1075 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1076 hotseatBarBottomSpace[INDEX_DEFAULT]);
1077 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1078 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1079 hotseatBarBottomSpace[INDEX_DEFAULT]);
1080 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1081 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1082 hotseatBarBottomSpace[INDEX_DEFAULT]);
1083
1084 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1085 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
1086 ResourcesCompat.getFloat(context.getResources(),
1087 R.dimen.hotseat_qsb_space_default));
1088 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1089 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1090 hotseatQsbSpace[INDEX_DEFAULT]);
1091 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1092 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1093 hotseatQsbSpace[INDEX_DEFAULT]);
1094 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1095 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1096 hotseatQsbSpace[INDEX_DEFAULT]);
1097
Sunny Goyal415f1732018-11-29 10:33:47 -08001098 a.recycle();
1099 }
1100
1101 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001102 this(null);
1103 }
1104
1105 DisplayOption(GridOption grid) {
1106 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001107 minWidthDps = 0;
1108 minHeightDps = 0;
1109 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001110 for (int i = 0; i < COUNT_SIZES; i++) {
1111 iconSizes[i] = 0;
1112 textSizes[i] = 0;
1113 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001114 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001115 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001116 allAppsIconSizes[i] = 0;
1117 allAppsIconTextSizes[i] = 0;
1118 allAppsBorderSpaces[i] = new PointF();
Thales Lima12d0eff2022-03-25 17:06:11 +00001119 inlineQsb[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001120 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001121 }
1122
1123 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001124 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001125 iconSizes[i] *= w;
1126 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001127 borderSpaces[i].x *= w;
1128 borderSpaces[i].y *= w;
1129 minCellSize[i].x *= w;
1130 minCellSize[i].y *= w;
1131 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001132 hotseatBorderSpaces[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001133 hotseatBarBottomSpace[i] *= w;
1134 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001135 allAppsCellSize[i].x *= w;
1136 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001137 allAppsIconSizes[i] *= w;
1138 allAppsIconTextSizes[i] *= w;
1139 allAppsBorderSpaces[i].x *= w;
1140 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001141 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001142
1143 folderBorderSpace *= w;
1144
Sunny Goyal415f1732018-11-29 10:33:47 -08001145 return this;
1146 }
1147
1148 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001149 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001150 iconSizes[i] += p.iconSizes[i];
1151 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001152 borderSpaces[i].x += p.borderSpaces[i].x;
1153 borderSpaces[i].y += p.borderSpaces[i].y;
1154 minCellSize[i].x += p.minCellSize[i].x;
1155 minCellSize[i].y += p.minCellSize[i].y;
1156 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001157 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limab8c05952022-05-23 16:58:38 +01001158 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1159 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001160 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1161 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001162 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1163 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1164 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1165 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Thales Lima12d0eff2022-03-25 17:06:11 +00001166 inlineQsb[i] |= p.inlineQsb[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001167 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001168
1169 folderBorderSpace += p.folderBorderSpace;
1170
Sunny Goyal415f1732018-11-29 10:33:47 -08001171 return this;
1172 }
1173 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001174}