blob: db43b44f72e63284906c864e4f79a4128c6da712 [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;
49
Sunny Goyal68031ca2021-08-02 12:23:44 -070050import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010051import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalfd58da62020-08-11 12:06:49 -070052import com.android.launcher3.util.DisplayController;
53import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080054import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070055import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080056import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070057import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080058import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070059
Sunny Goyal819e1932016-07-07 16:43:58 -070060import org.xmlpull.v1.XmlPullParser;
61import org.xmlpull.v1.XmlPullParserException;
62
63import java.io.IOException;
Alex Chaud3e8cc42022-05-03 17:45:34 +010064import java.io.PrintWriter;
65import java.io.StringWriter;
Alex Chau1c883d82021-12-01 18:43:10 +000066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070068import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070069import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080070import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070071import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070072
73public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070074
Hyunyoung Songc55a3502018-12-04 15:43:16 -080075 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070076 // We do not need any synchronization for this variable as its only written on UI thread.
77 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070078 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Alex Chau1c883d82021-12-01 18:43:10 +000080 @Retention(RetentionPolicy.SOURCE)
81 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
82 public @interface DeviceType{}
83 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;
Thales Lima78d00ad2021-09-30 11:29:06 +0100130
Thales Lima83bedbf2021-10-05 17:47:39 +0100131 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500132
Thales Limab7ef5692022-03-10 10:32:36 +0000133 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000134 public float[] allAppsIconSize;
135 public float[] allAppsIconTextSize;
136 public PointF[] allAppsBorderSpaces;
137
Sunny Goyal5bc18462019-01-07 15:13:39 -0800138 private SparseArray<TypedValue> mExtraAttrs;
139
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700140 /**
141 * Number of icons inside the hotseat area.
142 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800143 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700144
145 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000146 * Number of icons inside the hotseat area when using 3 buttons navigation.
147 */
148 public int numShrunkenHotseatIcons;
149
150 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700151 * Number of icons inside the hotseat area that is stored in the database. This is greater than
152 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
153 * sizes that share the same DB.
154 */
155 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700156
Thales Lima425f6822022-05-10 13:44:58 -0300157 public int[] hotseatColumnSpan;
158
Jon Miranda6f7e9702019-09-16 14:44:14 -0700159 /**
160 * Number of columns in the all apps list.
161 */
162 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700163 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700164
Jon Mirandae126d722021-02-25 10:45:20 -0500165 /**
166 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
167 */
168 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400169 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500170
Tracy Zhou7df93d22020-01-27 13:44:06 -0800171 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800172 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700173 int demoModeLayoutId;
Thales Lima12d0eff2022-03-25 17:06:11 +0000174 boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700175
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000176 /**
177 * An immutable list of supported profiles.
178 */
179 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700180
sfufa@google.comde013292021-09-21 18:22:44 -0700181 @Nullable
182 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500183
Sunny Goyal6f866092016-03-17 17:04:15 -0700184 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700185 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700186
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700187 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700188
Sunny Goyalf633ef52018-03-13 09:57:05 -0700189 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800190 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700191
Sunny Goyalbbf01842015-10-08 07:41:15 -0700192 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700193 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700194 String gridName = getCurrentGridName(context);
195 String newGridName = initGrid(context, gridName);
196 if (!newGridName.equals(gridName)) {
197 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
198 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700199 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700200
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700201 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100202 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000203 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
204 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100205 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700206 }
207 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700208 }
209
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700210 /**
211 * This constructor should NOT have any monitors by design.
212 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800213 public InvariantDeviceProfile(Context context, String gridName) {
214 String newName = initGrid(context, gridName);
215 if (newName == null || !newName.equals(gridName)) {
216 throw new IllegalArgumentException("Unknown grid name");
217 }
218 }
219
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800221 * This constructor should NOT have any monitors by design.
222 */
223 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700224 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100225 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700226 String gridName = getCurrentGridName(context);
227
228 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000229 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
230 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700231 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000232 defaultInfo,
233 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
234 /*allowDisabledGrid=*/false),
235 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236
Alex Chau417bd722021-01-26 15:22:18 +0000237 Info myInfo = new Info(context, display);
Alex Chau1c883d82021-12-01 18:43:10 +0000238 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700239 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000240 myInfo,
241 getPredefinedDeviceProfiles(context, gridName, deviceType,
242 /*allowDisabledGrid=*/false),
243 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700244
245 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
246 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100247 result.iconSizes[INDEX_DEFAULT] =
248 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
249 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700250 result.iconSizes[i] = Math.min(
251 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000252 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700253
Thales Lima83bedbf2021-10-05 17:47:39 +0100254 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
255 COUNT_SIZES);
256 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
257 COUNT_SIZES);
Thales Lima12d0eff2022-03-25 17:06:11 +0000258 System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0,
259 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500260
Alex Chau1c883d82021-12-01 18:43:10 +0000261 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800262 }
263
Alex Chau238aaee2021-10-06 16:15:24 +0100264 /**
265 * Reinitialize the current grid after a restore, where some grids might now be disabled.
266 */
267 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000268 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100269 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000270 String newGridName = initGrid(context, currentGridName);
271 String newDbFile = dbFile;
272 if (!newDbFile.equals(currentDbFile)) {
273 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100274 + ", migrating to: " + newGridName
275 + ", removing all other grid db files");
276 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
277 if (gridDbFile.equals(currentDbFile)) {
278 continue;
279 }
280 if (context.getDatabasePath(gridDbFile).delete()) {
281 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
282 }
283 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000284 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100285 }
286 }
287
Alex Chau1c883d82021-12-01 18:43:10 +0000288 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800289 int flagPhone = 1 << 0;
290 int flagTablet = 1 << 1;
291
292 int type = displayInfo.supportedBounds.stream()
293 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
294 .reduce(0, (a, b) -> a | b);
295 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
296 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000297 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800298 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000299 return TYPE_TABLET;
300 } else {
301 return TYPE_PHONE;
302 }
303 }
304
Tracy Zhou42255d22020-03-13 00:38:11 -0700305 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700306 return Utilities.isGridOptionsEnabled(context)
307 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700308 }
309
Sunny Goyaleff44f32019-01-09 17:29:49 -0800310 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700311 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000312 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700313
314 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000315 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100316 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700317 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000318 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
319 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700320 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800321 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700322
Alex Chau1c883d82021-12-01 18:43:10 +0000323 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
324 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700325 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700326 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000327 numRows = closestProfile.numRows;
328 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000329 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000330 dbFile = closestProfile.dbFile;
331 defaultLayoutId = closestProfile.defaultLayoutId;
332 demoModeLayoutId = closestProfile.demoModeLayoutId;
333 numFolderRows = closestProfile.numFolderRows;
334 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500335 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400336 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000337 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000338
339 mExtraAttrs = closestProfile.extraAttrs;
340
Thales Lima83bedbf2021-10-05 17:47:39 +0100341 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100342 float maxIconSize = iconSize[0];
343 for (int i = 1; i < iconSize.length; i++) {
344 maxIconSize = Math.max(maxIconSize, iconSize[i]);
345 }
346 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000347 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
348
Thales Lima83bedbf2021-10-05 17:47:39 +0100349 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700350
Thales Lima83bedbf2021-10-05 17:47:39 +0100351 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100352
Thales Lima83bedbf2021-10-05 17:47:39 +0100353 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100354 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700355
Thales Limad90faab2021-09-21 17:18:47 +0100356 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100357
Sunny Goyal19ff7282021-04-22 10:12:54 -0700358 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000359 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000360 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700361 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300362 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000363 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700364
365 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000366 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700367 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500368
Thales Limab7ef5692022-03-10 10:32:36 +0000369 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000370 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
371 allAppsIconSize = displayOption.allAppsIconSizes;
372 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100373 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000374 allAppsIconSize = iconSize;
375 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000376 }
377
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400378 if (devicePaddingId != 0) {
379 devicePaddings = new DevicePaddings(context, devicePaddingId);
380 }
381
Thales Lima12d0eff2022-03-25 17:06:11 +0000382 inlineQsb = displayOption.inlineQsb;
383
Sunny Goyalae190ff2020-04-14 00:19:01 +0000384 // If the partner customization apk contains any grid overrides, apply them
385 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700386 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700387
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000388 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700389 defaultWallpaperSize = new Point(displayInfo.currentSize);
390 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000391 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000392 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000393 .setWindowBounds(bounds)
394 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700395
Sunny Goyal19ff7282021-04-22 10:12:54 -0700396 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
397 int displayWidth = bounds.bounds.width();
398 int displayHeight = bounds.bounds.height();
399 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700400
Sunny Goyal19ff7282021-04-22 10:12:54 -0700401 // We need to ensure that there is enough extra space in the wallpaper
402 // for the intended parallax effects
403 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300404 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
405 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700406 ? 2
407 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
408 defaultWallpaperSize.x =
409 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700410 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000411 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700412
413 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
414 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700415 }
416
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700417 public void addOnChangeListener(OnIDPChangeListener listener) {
418 mChangeListeners.add(listener);
419 }
420
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800421 public void removeOnChangeListener(OnIDPChangeListener listener) {
422 mChangeListeners.remove(listener);
423 }
424
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800425
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800426 public void setCurrentGrid(Context context, String gridName) {
427 Context appContext = context.getApplicationContext();
428 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700429 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800430 }
431
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700432 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700433 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000434 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
435 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700436 }
437
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700438 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700439 Object[] oldState = toModelState();
440
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700441 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700442 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700443 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700444
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700445 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700446 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700447 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700448 }
449 }
450
Alex Chau1c883d82021-12-01 18:43:10 +0000451 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
452 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800453 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100454
Alex Chau1c883d82021-12-01 18:43:10 +0000455 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700456 final int depth = parser.getDepth();
457 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700458 while (((type = parser.next()) != XmlPullParser.END_TAG ||
459 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800460 if ((type == XmlPullParser.START_TAG)
461 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800462
Alex Chau1c883d82021-12-01 18:43:10 +0000463 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
464 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100465 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100466 final int displayDepth = parser.getDepth();
467 while (((type = parser.next()) != XmlPullParser.END_TAG
468 || parser.getDepth() > displayDepth)
469 && type != XmlPullParser.END_DOCUMENT) {
470 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
471 parser.getName())) {
472 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100473 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100474 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800475 }
476 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700477 }
478 }
sfufa@google.comde013292021-09-21 18:22:44 -0700479 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700480 throw new RuntimeException(e);
481 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800482
Sunny Goyalae190ff2020-04-14 00:19:01 +0000483 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800484 if (!TextUtils.isEmpty(gridName)) {
485 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100486 if (gridName.equals(option.grid.name)
487 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000488 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800489 }
490 }
491 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000492 if (filteredProfiles.isEmpty()) {
493 // No grid found, use the default options
494 for (DisplayOption option : profiles) {
495 if (option.canBeDefault) {
496 filteredProfiles.add(option);
497 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800498 }
499 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000500 if (filteredProfiles.isEmpty()) {
501 throw new RuntimeException("No display option with canBeDefault=true");
502 }
503 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700504 }
505
Thales Lima7ec83822021-08-05 13:32:10 +0100506 /**
507 * @return all the grid options that can be shown on the device
508 */
509 public List<GridOption> parseAllGridOptions(Context context) {
510 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100511
Alex Chau1c883d82021-12-01 18:43:10 +0000512 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100513 final int depth = parser.getDepth();
514 int type;
515 while (((type = parser.next()) != XmlPullParser.END_TAG
516 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
517 if ((type == XmlPullParser.START_TAG)
518 && GridOption.TAG_NAME.equals(parser.getName())) {
519 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000520 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100521 if (option.isEnabled) {
522 result.add(option);
523 }
524 }
525 }
526 } catch (IOException | XmlPullParserException e) {
527 Log.e(TAG, "Error parsing device profile", e);
528 return Collections.emptyList();
529 }
530 return result;
531 }
532
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700533 private int getLauncherIconDensity(int requiredSize) {
534 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700535 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700536 DisplayMetrics.DENSITY_LOW,
537 DisplayMetrics.DENSITY_MEDIUM,
538 DisplayMetrics.DENSITY_TV,
539 DisplayMetrics.DENSITY_HIGH,
540 DisplayMetrics.DENSITY_XHIGH,
541 DisplayMetrics.DENSITY_XXHIGH,
542 DisplayMetrics.DENSITY_XXXHIGH
543 };
544
545 int density = DisplayMetrics.DENSITY_XXXHIGH;
546 for (int i = densityBuckets.length - 1; i >= 0; i--) {
547 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
548 / DisplayMetrics.DENSITY_DEFAULT;
549 if (expectedSize >= requiredSize) {
550 density = densityBuckets[i];
551 }
552 }
553
554 return density;
555 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700556
Adam Cohen2e6da152015-05-06 11:42:25 -0700557 /**
558 * Apply any Partner customization grid overrides.
559 *
560 * Currently we support: all apps row / column count.
561 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700562 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
563 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700564 if (p != null) {
565 p.applyInvariantDeviceProfileOverrides(this, dm);
566 }
567 }
568
Sunny Goyal415f1732018-11-29 10:33:47 -0800569 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700570 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700571 }
572
Sunny Goyal19ff7282021-04-22 10:12:54 -0700573 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000574 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700575 int minWidthPx = Integer.MAX_VALUE;
576 int minHeightPx = Integer.MAX_VALUE;
577 for (WindowBounds bounds : displayInfo.supportedBounds) {
578 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000579 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700580 // For split displays, take half width per page
581 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
582 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700583
Sunny Goyal19ff7282021-04-22 10:12:54 -0700584 } else if (!isTablet && bounds.isLandscape()) {
585 // We will use transposed layout in this case
586 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
587 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
588 } else {
589 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
590 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
591 }
592 }
593
Thales Lima425f6822022-05-10 13:44:58 -0300594 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
595 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700596
597 // Sort the profiles based on the closeness to the device size
598 Collections.sort(points, (a, b) ->
599 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
600 dist(width, height, b.minWidthDps, b.minHeightDps)));
601
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700602 DisplayOption closestPoint = points.get(0);
603 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700604 float weights = 0;
605
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700606 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
607 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700608 }
609
610 DisplayOption out = new DisplayOption(closestOption);
611 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700612 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700613 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
614 weights += w;
615 out.add(new DisplayOption().add(p).multiply(w));
616 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700617 out.multiply(1.0f / weights);
618
Thales Lima6e0005a2021-10-27 15:53:41 +0100619 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700620 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100621 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
622 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700623 }
624
625 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700626 }
627
Sunny Goyal27835952017-01-13 12:15:53 -0800628 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700629 Resources res = context.getResources();
630 Configuration config = context.getResources().getConfiguration();
631
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400632 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
633 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100634 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
635
636 if (Utilities.IS_DEBUG_DEVICE) {
637 StringWriter stringWriter = new StringWriter();
638 PrintWriter printWriter = new PrintWriter(stringWriter);
639 DisplayController.INSTANCE.get(context).dump(printWriter);
640 printWriter.flush();
641 Log.d("b/231312158", "getDeviceProfile -"
642 + "\nconfig: " + config
643 + "\ndisplayMetrics: " + res.getDisplayMetrics()
644 + "\nrotation: " + rotation
645 + "\n" + stringWriter.toString(),
646 new Exception());
647 }
648 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400649 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700650
Sunny Goyal187b16c2022-03-01 16:53:23 -0800651 /**
652 * Returns the device profile matching the provided screen configuration
653 */
654 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700655 DeviceProfile bestMatch = supportedProfiles.get(0);
656 float minDiff = Float.MAX_VALUE;
657
658 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400659 float diff = Math.abs(profile.widthPx - screenWidth)
660 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700661 if (diff < minDiff) {
662 minDiff = diff;
663 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800664 } else if (diff == minDiff && profile.rotationHint == rotation) {
665 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700666 }
667 }
668 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800669 }
670
Sunny Goyal415f1732018-11-29 10:33:47 -0800671 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700672 float d = dist(x0, y0, x1, y1);
673 if (Float.compare(d, 0f) == 0) {
674 return Float.POSITIVE_INFINITY;
675 }
676 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
677 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700678
679 /**
680 * As a ratio of screen height, the total distance we want the parallax effect to span
681 * horizontally
682 */
683 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
684 float aspectRatio = width / (float) height;
685
686 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
687 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
688 // We will use these two data points to extrapolate how much the wallpaper parallax effect
689 // to span (ie travel) at any aspect ratio:
690
sfufa@google.comde013292021-09-21 18:22:44 -0700691 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
692 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700693 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
694 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
695
696 // To find out the desired width at different aspect ratios, we use the following two
697 // formulas, where the coefficient on x is the aspect ratio (width/height):
698 // (16/10)x + y = 1.5
699 // (10/16)x + y = 1.2
700 // We solve for x and y and end up with a final formula:
701 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700702 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
703 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700704 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
705 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
706 return x * aspectRatio + y;
707 }
708
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700709 public interface OnIDPChangeListener {
710
Sunny Goyalb47172b2021-05-03 19:59:51 -0700711 /**
712 * Called when the device provide changes
713 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700714 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700715 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800716
717
Sunny Goyaleff44f32019-01-09 17:29:49 -0800718 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800719
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800720 public static final String TAG_NAME = "grid-option";
721
Alex Chau1c883d82021-12-01 18:43:10 +0000722 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
723 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
724 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
725 private static final int DEVICE_CATEGORY_ALL =
726 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
727
Sunny Goyaleff44f32019-01-09 17:29:49 -0800728 public final String name;
729 public final int numRows;
730 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000731 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100732 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800733
734 private final int numFolderRows;
735 private final int numFolderColumns;
736
Sunny Goyal19ff7282021-04-22 10:12:54 -0700737 private final int numAllAppsColumns;
738 private final int numDatabaseAllAppsColumns;
739 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000740 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700741 private final int numDatabaseHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300742 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800743
Tracy Zhou7df93d22020-01-27 13:44:06 -0800744 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000745
Sunny Goyal415f1732018-11-29 10:33:47 -0800746 private final int defaultLayoutId;
747 private final int demoModeLayoutId;
748
Jon Mirandae126d722021-02-25 10:45:20 -0500749 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400750 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500751
Sunny Goyal5bc18462019-01-07 15:13:39 -0800752 private final SparseArray<TypedValue> extraAttrs;
753
Alex Chau1c883d82021-12-01 18:43:10 +0000754 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800755 TypedArray a = context.obtainStyledAttributes(
756 attrs, R.styleable.GridDisplayOption);
757 name = a.getString(R.styleable.GridDisplayOption_name);
758 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
759 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000760 numSearchContainerColumns = a.getInt(
761 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800762
Tracy Zhou7df93d22020-01-27 13:44:06 -0800763 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000764 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100765 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
766 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
767 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800768 demoModeLayoutId = a.getResourceId(
769 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700770
771 numAllAppsColumns = a.getInt(
772 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
773 numDatabaseAllAppsColumns = a.getInt(
774 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
775
776 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800777 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000778 numShrunkenHotseatIcons = a.getInt(
779 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700780 numDatabaseHotseatIcons = a.getInt(
781 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Lima425f6822022-05-10 13:44:58 -0300782 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
783 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
784 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
785 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
786 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
787 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
788 numColumns);
789 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
790 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
791 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700792
Sunny Goyal415f1732018-11-29 10:33:47 -0800793 numFolderRows = a.getInt(
794 R.styleable.GridDisplayOption_numFolderRows, numRows);
795 numFolderColumns = a.getInt(
796 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700797
Jon Mirandae126d722021-02-25 10:45:20 -0500798 isScalable = a.getBoolean(
799 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400800 devicePaddingId = a.getResourceId(
801 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500802
Alex Chau1c883d82021-12-01 18:43:10 +0000803 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
804 DEVICE_CATEGORY_ALL);
805 isEnabled = (deviceType == TYPE_PHONE
806 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
807 || (deviceType == TYPE_TABLET
808 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
809 || (deviceType == TYPE_MULTI_DISPLAY
810 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
811 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100812
Sunny Goyal415f1732018-11-29 10:33:47 -0800813 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800814 extraAttrs = Themes.createValueMap(context, attrs,
815 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800816 }
817 }
818
Sunny Goyal19ff7282021-04-22 10:12:54 -0700819 @VisibleForTesting
820 static final class DisplayOption {
Thales Lima12d0eff2022-03-25 17:06:11 +0000821 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
822 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
823 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
824 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
825 private static final int DONT_INLINE_QSB = 0;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700826
827 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800828
Sunny Goyal415f1732018-11-29 10:33:47 -0800829 private final float minWidthDps;
830 private final float minHeightDps;
831 private final boolean canBeDefault;
Thales Lima12d0eff2022-03-25 17:06:11 +0000832 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800833
Thales Lima83bedbf2021-10-05 17:47:39 +0100834 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100835
836 private float folderBorderSpace;
837 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100838 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima425f6822022-05-10 13:44:58 -0300839 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
Thales Lima6e7f36c2022-01-04 12:14:11 +0000840 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100841
Thales Lima78d00ad2021-09-30 11:29:06 +0100842 private final float[] iconSizes = new float[COUNT_SIZES];
843 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800844
Thales Limab7ef5692022-03-10 10:32:36 +0000845 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000846 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
847 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
848 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
849
Thales Lima1de4d552021-10-13 16:13:25 +0100850 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800851 this.grid = grid;
852
Thales Lima1de4d552021-10-13 16:13:25 +0100853 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800854
Sunny Goyal415f1732018-11-29 10:33:47 -0800855 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
856 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700857
Thales Lima1de4d552021-10-13 16:13:25 +0100858 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800859
Thales Lima12d0eff2022-03-25 17:06:11 +0000860 int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb,
861 DONT_INLINE_QSB);
862 inlineQsb[INDEX_DEFAULT] =
863 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
864 inlineQsb[INDEX_LANDSCAPE] =
865 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
866 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
867 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
868 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
869 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
870 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
871 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
872
Thales Lima83bedbf2021-10-05 17:47:39 +0100873 float x;
874 float y;
875
Thales Lima85c942f2021-12-31 13:04:20 +0000876 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
877 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100878 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000879
880 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
881 minCellSize[INDEX_DEFAULT].x);
882 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
883 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100884 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100885
Thales Lima85c942f2021-12-31 13:04:20 +0000886 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100887 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000888 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100889 minCellSize[INDEX_DEFAULT].y);
890 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
891
Thales Lima85c942f2021-12-31 13:04:20 +0000892 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100893 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000894 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100895 minCellSize[INDEX_DEFAULT].y);
896 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100897
Thales Lima85c942f2021-12-31 13:04:20 +0000898 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000899 float borderSpaceLandscape = a.getFloat(
900 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000901 float borderSpaceTwoPanelPortrait = a.getFloat(
902 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
903 float borderSpaceTwoPanelLandscape = a.getFloat(
904 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100905
Thales Lima85c942f2021-12-31 13:04:20 +0000906 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
907 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100908 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000909
910 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
911 borderSpaceLandscape);
912 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
913 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100914 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
915
916 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000917 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
918 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100919 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000920 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
921 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100922 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
923
924 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000925 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
926 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100927 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000928 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
929 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100930 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
931
Thales Limabb7d3882021-12-22 12:56:29 +0000932 folderBorderSpace = borderSpace;
933
Thales Limab7ef5692022-03-10 10:32:36 +0000934 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
935 minCellSize[INDEX_DEFAULT].x);
936 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
937 minCellSize[INDEX_DEFAULT].y);
938 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
939
940 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
941 allAppsCellSize[INDEX_DEFAULT].x);
942 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
943 allAppsCellSize[INDEX_DEFAULT].y);
944 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
945
946 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
947 allAppsCellSize[INDEX_DEFAULT].x);
948 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
949 allAppsCellSize[INDEX_DEFAULT].y);
950 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
951
952 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
953 allAppsCellSize[INDEX_DEFAULT].x);
954 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
955 allAppsCellSize[INDEX_DEFAULT].y);
956 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
957
Thales Lima080d8902022-03-28 15:30:29 +0100958 float allAppsBorderSpace = a.getFloat(
959 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
960 float allAppsBorderSpaceLandscape = a.getFloat(
961 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
962 allAppsBorderSpace);
963 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000964 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +0100965 allAppsBorderSpace);
966 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000967 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +0100968 allAppsBorderSpace);
969
970 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
971 allAppsBorderSpace);
972 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
973 allAppsBorderSpace);
974 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
975
976 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
977 allAppsBorderSpaceLandscape);
978 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
979 allAppsBorderSpaceLandscape);
980 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
981
982 x = a.getFloat(
983 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
984 allAppsBorderSpaceTwoPanelPortrait);
985 y = a.getFloat(
986 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
987 allAppsBorderSpaceTwoPanelPortrait);
988 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
989
990 x = a.getFloat(
991 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
992 allAppsBorderSpaceTwoPanelLandscape);
993 y = a.getFloat(
994 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
995 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +0000996 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500997
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700998 iconSizes[INDEX_DEFAULT] =
999 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1000 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001001 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001002 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001003 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001004 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001005 iconSizes[INDEX_DEFAULT]);
1006 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001007 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001008 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001009
Thales Limabb7d3882021-12-22 12:56:29 +00001010 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1011 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
1012 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
1013 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1014 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1015 allAppsIconSizes[INDEX_DEFAULT]);
1016 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1017 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1018 allAppsIconSizes[INDEX_DEFAULT]);
1019
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001020 textSizes[INDEX_DEFAULT] =
1021 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1022 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001023 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001024 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001025 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001026 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001027 textSizes[INDEX_DEFAULT]);
1028 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001029 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001030 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001031
Thales Limabb7d3882021-12-22 12:56:29 +00001032 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1033 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1034 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1035 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1036 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1037 allAppsIconTextSizes[INDEX_DEFAULT]);
1038 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1039 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1040 allAppsIconTextSizes[INDEX_DEFAULT]);
1041
Thales Lima83bedbf2021-10-05 17:47:39 +01001042 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1043 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001044 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1045 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1046 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001047 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001048 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001049 horizontalMargin[INDEX_DEFAULT]);
1050 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001051 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001052 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001053
Thales Lima6e7f36c2022-01-04 12:14:11 +00001054 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
1055 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +00001056 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
1057 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
1058 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001059 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1060 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
1061 hotseatBorderSpaces[INDEX_DEFAULT]);
1062 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1063 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
1064 hotseatBorderSpaces[INDEX_DEFAULT]);
1065
Sunny Goyal415f1732018-11-29 10:33:47 -08001066 a.recycle();
1067 }
1068
1069 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001070 this(null);
1071 }
1072
1073 DisplayOption(GridOption grid) {
1074 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001075 minWidthDps = 0;
1076 minHeightDps = 0;
1077 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001078 for (int i = 0; i < COUNT_SIZES; i++) {
1079 iconSizes[i] = 0;
1080 textSizes[i] = 0;
1081 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001082 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001083 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001084 allAppsIconSizes[i] = 0;
1085 allAppsIconTextSizes[i] = 0;
1086 allAppsBorderSpaces[i] = new PointF();
Thales Lima12d0eff2022-03-25 17:06:11 +00001087 inlineQsb[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001088 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001089 }
1090
1091 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001092 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001093 iconSizes[i] *= w;
1094 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001095 borderSpaces[i].x *= w;
1096 borderSpaces[i].y *= w;
1097 minCellSize[i].x *= w;
1098 minCellSize[i].y *= w;
1099 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001100 hotseatBorderSpaces[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001101 allAppsCellSize[i].x *= w;
1102 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001103 allAppsIconSizes[i] *= w;
1104 allAppsIconTextSizes[i] *= w;
1105 allAppsBorderSpaces[i].x *= w;
1106 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001107 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001108
1109 folderBorderSpace *= w;
1110
Sunny Goyal415f1732018-11-29 10:33:47 -08001111 return this;
1112 }
1113
1114 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001115 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001116 iconSizes[i] += p.iconSizes[i];
1117 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001118 borderSpaces[i].x += p.borderSpaces[i].x;
1119 borderSpaces[i].y += p.borderSpaces[i].y;
1120 minCellSize[i].x += p.minCellSize[i].x;
1121 minCellSize[i].y += p.minCellSize[i].y;
1122 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001123 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001124 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1125 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001126 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1127 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1128 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1129 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Thales Lima12d0eff2022-03-25 17:06:11 +00001130 inlineQsb[i] |= p.inlineQsb[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001131 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001132
1133 folderBorderSpace += p.folderBorderSpace;
1134
Sunny Goyal415f1732018-11-29 10:33:47 -08001135 return this;
1136 }
1137 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001138}