blob: 89b177165f8feb717ad48d1b6f7c57e0715e788b [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 Chau1c883d82021-12-01 18:43:10 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070066import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070067import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080068import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070069import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070070
71public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070072
Hyunyoung Songc55a3502018-12-04 15:43:16 -080073 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070074 // We do not need any synchronization for this variable as its only written on UI thread.
75 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070076 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070077
Alex Chau1c883d82021-12-01 18:43:10 +000078 @Retention(RetentionPolicy.SOURCE)
79 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
80 public @interface DeviceType{}
81 public static final int TYPE_PHONE = 0;
82 public static final int TYPE_MULTI_DISPLAY = 1;
83 public static final int TYPE_TABLET = 2;
84
Hyunyoung Songc55a3502018-12-04 15:43:16 -080085 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080086
Sunny Goyal53d7ee42015-05-22 12:25:45 -070087 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
88
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 // Constants that affects the interpolation curve between statically defined device profile
90 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080091 private static final float KNEARESTNEIGHBOR = 3;
92 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070093
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080095 private static final float WEIGHT_EFFICIENT = 100000f;
96
Thales Lima83bedbf2021-10-05 17:47:39 +010097 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
98 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +000099 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100100 static final int INDEX_DEFAULT = 0;
101 static final int INDEX_LANDSCAPE = 1;
102 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
103 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700105 /**
106 * Number of icons per row and column in the workspace.
107 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700108 public int numRows;
109 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000110 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700111
112 /**
113 * Number of icons per row and column in the folder.
114 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700115 public int numFolderRows;
116 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 public float[] iconSize;
118 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700119 public int iconBitmapSize;
120 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000121 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700122
Thales Lima83bedbf2021-10-05 17:47:39 +0100123 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000127 public float[] hotseatBorderSpaces;
Thales Lima828875c2022-04-26 20:29:30 +0100128 public int[] hotseatColumnSpan;
Thales Lima78d00ad2021-09-30 11:29:06 +0100129
Thales Lima83bedbf2021-10-05 17:47:39 +0100130 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500131
Thales Limab7ef5692022-03-10 10:32:36 +0000132 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000133 public float[] allAppsIconSize;
134 public float[] allAppsIconTextSize;
135 public PointF[] allAppsBorderSpaces;
136
Sunny Goyal5bc18462019-01-07 15:13:39 -0800137 private SparseArray<TypedValue> mExtraAttrs;
138
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700139 /**
140 * Number of icons inside the hotseat area.
141 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800142 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700143
144 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000145 * Number of icons inside the hotseat area when using 3 buttons navigation.
146 */
147 public int numShrunkenHotseatIcons;
148
149 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700150 * Number of icons inside the hotseat area that is stored in the database. This is greater than
151 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
152 * sizes that share the same DB.
153 */
154 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700155
Jon Miranda6f7e9702019-09-16 14:44:14 -0700156 /**
157 * Number of columns in the all apps list.
158 */
159 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700160 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700161
Jon Mirandae126d722021-02-25 10:45:20 -0500162 /**
163 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
164 */
165 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400166 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500167
Tracy Zhou7df93d22020-01-27 13:44:06 -0800168 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800169 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700170 int demoModeLayoutId;
Thales Lima12d0eff2022-03-25 17:06:11 +0000171 boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700172
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000173 /**
174 * An immutable list of supported profiles.
175 */
176 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700177
sfufa@google.comde013292021-09-21 18:22:44 -0700178 @Nullable
179 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500180
Sunny Goyal6f866092016-03-17 17:04:15 -0700181 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700182 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700183
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700184 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700185
Sunny Goyalf633ef52018-03-13 09:57:05 -0700186 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800187 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700188
Sunny Goyalbbf01842015-10-08 07:41:15 -0700189 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700190 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700191 String gridName = getCurrentGridName(context);
192 String newGridName = initGrid(context, gridName);
193 if (!newGridName.equals(gridName)) {
194 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
195 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700196 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700197
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700198 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100199 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000200 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
201 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100202 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700203 }
204 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700205 }
206
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700207 /**
208 * This constructor should NOT have any monitors by design.
209 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800210 public InvariantDeviceProfile(Context context, String gridName) {
211 String newName = initGrid(context, gridName);
212 if (newName == null || !newName.equals(gridName)) {
213 throw new IllegalArgumentException("Unknown grid name");
214 }
215 }
216
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700217 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800218 * This constructor should NOT have any monitors by design.
219 */
220 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700221 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100222 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 String gridName = getCurrentGridName(context);
224
225 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000226 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
227 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700228 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000229 defaultInfo,
230 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
231 /*allowDisabledGrid=*/false),
232 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700233
Alex Chau417bd722021-01-26 15:22:18 +0000234 Info myInfo = new Info(context, display);
Alex Chau1c883d82021-12-01 18:43:10 +0000235 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000237 myInfo,
238 getPredefinedDeviceProfiles(context, gridName, deviceType,
239 /*allowDisabledGrid=*/false),
240 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700241
242 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
243 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100244 result.iconSizes[INDEX_DEFAULT] =
245 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
246 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700247 result.iconSizes[i] = Math.min(
248 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000249 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700250
Thales Lima83bedbf2021-10-05 17:47:39 +0100251 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
252 COUNT_SIZES);
253 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
254 COUNT_SIZES);
Thales Lima12d0eff2022-03-25 17:06:11 +0000255 System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0,
256 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500257
Alex Chau1c883d82021-12-01 18:43:10 +0000258 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800259 }
260
Alex Chau238aaee2021-10-06 16:15:24 +0100261 /**
262 * Reinitialize the current grid after a restore, where some grids might now be disabled.
263 */
264 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000265 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100266 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000267 String newGridName = initGrid(context, currentGridName);
268 String newDbFile = dbFile;
269 if (!newDbFile.equals(currentDbFile)) {
270 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100271 + ", migrating to: " + newGridName
272 + ", removing all other grid db files");
273 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
274 if (gridDbFile.equals(currentDbFile)) {
275 continue;
276 }
277 if (context.getDatabasePath(gridDbFile).delete()) {
278 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
279 }
280 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000281 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100282 }
283 }
284
Alex Chau1c883d82021-12-01 18:43:10 +0000285 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800286 int flagPhone = 1 << 0;
287 int flagTablet = 1 << 1;
288
289 int type = displayInfo.supportedBounds.stream()
290 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
291 .reduce(0, (a, b) -> a | b);
292 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
293 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000294 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800295 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000296 return TYPE_TABLET;
297 } else {
298 return TYPE_PHONE;
299 }
300 }
301
Tracy Zhou42255d22020-03-13 00:38:11 -0700302 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700303 return Utilities.isGridOptionsEnabled(context)
304 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700305 }
306
Sunny Goyaleff44f32019-01-09 17:29:49 -0800307 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700308 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000309 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700310
311 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000312 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100313 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700314 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000315 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
316 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700317 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800318 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700319
Alex Chau1c883d82021-12-01 18:43:10 +0000320 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
321 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700322 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700323 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000324 numRows = closestProfile.numRows;
325 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000326 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000327 dbFile = closestProfile.dbFile;
328 defaultLayoutId = closestProfile.defaultLayoutId;
329 demoModeLayoutId = closestProfile.demoModeLayoutId;
330 numFolderRows = closestProfile.numFolderRows;
331 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500332 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400333 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000334 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000335
336 mExtraAttrs = closestProfile.extraAttrs;
337
Thales Lima83bedbf2021-10-05 17:47:39 +0100338 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100339 float maxIconSize = iconSize[0];
340 for (int i = 1; i < iconSize.length; i++) {
341 maxIconSize = Math.max(maxIconSize, iconSize[i]);
342 }
343 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000344 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
345
Thales Lima83bedbf2021-10-05 17:47:39 +0100346 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700347
Thales Lima83bedbf2021-10-05 17:47:39 +0100348 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100349
Thales Lima83bedbf2021-10-05 17:47:39 +0100350 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100351 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700352
Thales Limad90faab2021-09-21 17:18:47 +0100353 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100354
Sunny Goyal19ff7282021-04-22 10:12:54 -0700355 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000356 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000357 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700358 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000359 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Thales Lima828875c2022-04-26 20:29:30 +0100360 hotseatColumnSpan = displayOption.hotseatColumnSpan;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700361
362 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000363 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700364 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500365
Thales Limab7ef5692022-03-10 10:32:36 +0000366 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000367 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
368 allAppsIconSize = displayOption.allAppsIconSizes;
369 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100370 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000371 allAppsIconSize = iconSize;
372 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000373 }
374
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400375 if (devicePaddingId != 0) {
376 devicePaddings = new DevicePaddings(context, devicePaddingId);
377 }
378
Thales Lima12d0eff2022-03-25 17:06:11 +0000379 inlineQsb = displayOption.inlineQsb;
380
Sunny Goyalae190ff2020-04-14 00:19:01 +0000381 // If the partner customization apk contains any grid overrides, apply them
382 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700383 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700384
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000385 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700386 defaultWallpaperSize = new Point(displayInfo.currentSize);
387 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000388 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000389 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000390 .setWindowBounds(bounds)
391 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700392
Sunny Goyal19ff7282021-04-22 10:12:54 -0700393 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
394 int displayWidth = bounds.bounds.width();
395 int displayHeight = bounds.bounds.height();
396 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700397
Sunny Goyal19ff7282021-04-22 10:12:54 -0700398 // We need to ensure that there is enough extra space in the wallpaper
399 // for the intended parallax effects
400 float parallaxFactor =
Thales Lima828875c2022-04-26 20:29:30 +0100401 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
402 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700403 ? 2
404 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
405 defaultWallpaperSize.x =
406 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700407 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000408 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700409
410 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
411 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700412 }
413
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700414 public void addOnChangeListener(OnIDPChangeListener listener) {
415 mChangeListeners.add(listener);
416 }
417
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800418 public void removeOnChangeListener(OnIDPChangeListener listener) {
419 mChangeListeners.remove(listener);
420 }
421
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800422
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800423 public void setCurrentGrid(Context context, String gridName) {
424 Context appContext = context.getApplicationContext();
425 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700426 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800427 }
428
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700429 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700430 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000431 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
432 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700433 }
434
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700435 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700436 Object[] oldState = toModelState();
437
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700438 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700439 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700440 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700441
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700442 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700443 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700444 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700445 }
446 }
447
Alex Chau1c883d82021-12-01 18:43:10 +0000448 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
449 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800450 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100451
Alex Chau1c883d82021-12-01 18:43:10 +0000452 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700453 final int depth = parser.getDepth();
454 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700455 while (((type = parser.next()) != XmlPullParser.END_TAG ||
456 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800457 if ((type == XmlPullParser.START_TAG)
458 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800459
Alex Chau1c883d82021-12-01 18:43:10 +0000460 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
461 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100462 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100463 final int displayDepth = parser.getDepth();
464 while (((type = parser.next()) != XmlPullParser.END_TAG
465 || parser.getDepth() > displayDepth)
466 && type != XmlPullParser.END_DOCUMENT) {
467 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
468 parser.getName())) {
469 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100470 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100471 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800472 }
473 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700474 }
475 }
sfufa@google.comde013292021-09-21 18:22:44 -0700476 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700477 throw new RuntimeException(e);
478 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800479
Sunny Goyalae190ff2020-04-14 00:19:01 +0000480 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800481 if (!TextUtils.isEmpty(gridName)) {
482 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100483 if (gridName.equals(option.grid.name)
484 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000485 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800486 }
487 }
488 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000489 if (filteredProfiles.isEmpty()) {
490 // No grid found, use the default options
491 for (DisplayOption option : profiles) {
492 if (option.canBeDefault) {
493 filteredProfiles.add(option);
494 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800495 }
496 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000497 if (filteredProfiles.isEmpty()) {
498 throw new RuntimeException("No display option with canBeDefault=true");
499 }
500 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700501 }
502
Thales Lima7ec83822021-08-05 13:32:10 +0100503 /**
504 * @return all the grid options that can be shown on the device
505 */
506 public List<GridOption> parseAllGridOptions(Context context) {
507 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100508
Alex Chau1c883d82021-12-01 18:43:10 +0000509 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100510 final int depth = parser.getDepth();
511 int type;
512 while (((type = parser.next()) != XmlPullParser.END_TAG
513 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
514 if ((type == XmlPullParser.START_TAG)
515 && GridOption.TAG_NAME.equals(parser.getName())) {
516 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000517 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100518 if (option.isEnabled) {
519 result.add(option);
520 }
521 }
522 }
523 } catch (IOException | XmlPullParserException e) {
524 Log.e(TAG, "Error parsing device profile", e);
525 return Collections.emptyList();
526 }
527 return result;
528 }
529
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700530 private int getLauncherIconDensity(int requiredSize) {
531 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700532 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700533 DisplayMetrics.DENSITY_LOW,
534 DisplayMetrics.DENSITY_MEDIUM,
535 DisplayMetrics.DENSITY_TV,
536 DisplayMetrics.DENSITY_HIGH,
537 DisplayMetrics.DENSITY_XHIGH,
538 DisplayMetrics.DENSITY_XXHIGH,
539 DisplayMetrics.DENSITY_XXXHIGH
540 };
541
542 int density = DisplayMetrics.DENSITY_XXXHIGH;
543 for (int i = densityBuckets.length - 1; i >= 0; i--) {
544 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
545 / DisplayMetrics.DENSITY_DEFAULT;
546 if (expectedSize >= requiredSize) {
547 density = densityBuckets[i];
548 }
549 }
550
551 return density;
552 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700553
Adam Cohen2e6da152015-05-06 11:42:25 -0700554 /**
555 * Apply any Partner customization grid overrides.
556 *
557 * Currently we support: all apps row / column count.
558 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700559 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
560 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700561 if (p != null) {
562 p.applyInvariantDeviceProfileOverrides(this, dm);
563 }
564 }
565
Sunny Goyal415f1732018-11-29 10:33:47 -0800566 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700567 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700568 }
569
Sunny Goyal19ff7282021-04-22 10:12:54 -0700570 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000571 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700572 int minWidthPx = Integer.MAX_VALUE;
573 int minHeightPx = Integer.MAX_VALUE;
574 for (WindowBounds bounds : displayInfo.supportedBounds) {
575 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000576 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700577 // For split displays, take half width per page
578 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
579 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700580
Sunny Goyal19ff7282021-04-22 10:12:54 -0700581 } else if (!isTablet && bounds.isLandscape()) {
582 // We will use transposed layout in this case
583 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
584 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
585 } else {
586 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
587 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
588 }
589 }
590
Thales Lima828875c2022-04-26 20:29:30 +0100591 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
592 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700593
594 // Sort the profiles based on the closeness to the device size
595 Collections.sort(points, (a, b) ->
596 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
597 dist(width, height, b.minWidthDps, b.minHeightDps)));
598
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700599 DisplayOption closestPoint = points.get(0);
600 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700601 float weights = 0;
602
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700603 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
604 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700605 }
606
607 DisplayOption out = new DisplayOption(closestOption);
608 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700609 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700610 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
611 weights += w;
612 out.add(new DisplayOption().add(p).multiply(w));
613 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700614 out.multiply(1.0f / weights);
615
Thales Lima6e0005a2021-10-27 15:53:41 +0100616 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700617 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100618 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
619 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700620 }
621
622 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700623 }
624
Sunny Goyal27835952017-01-13 12:15:53 -0800625 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700626 Resources res = context.getResources();
627 Configuration config = context.getResources().getConfiguration();
628
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400629 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
630 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800631 return getBestMatch(screenWidth, screenHeight,
632 WindowManagerProxy.INSTANCE.get(context).getRotation(context));
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400633 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700634
Sunny Goyal187b16c2022-03-01 16:53:23 -0800635 /**
636 * Returns the device profile matching the provided screen configuration
637 */
638 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700639 DeviceProfile bestMatch = supportedProfiles.get(0);
640 float minDiff = Float.MAX_VALUE;
641
642 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400643 float diff = Math.abs(profile.widthPx - screenWidth)
644 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700645 if (diff < minDiff) {
646 minDiff = diff;
647 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800648 } else if (diff == minDiff && profile.rotationHint == rotation) {
649 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700650 }
651 }
652 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800653 }
654
Sunny Goyal415f1732018-11-29 10:33:47 -0800655 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700656 float d = dist(x0, y0, x1, y1);
657 if (Float.compare(d, 0f) == 0) {
658 return Float.POSITIVE_INFINITY;
659 }
660 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
661 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700662
663 /**
664 * As a ratio of screen height, the total distance we want the parallax effect to span
665 * horizontally
666 */
667 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
668 float aspectRatio = width / (float) height;
669
670 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
671 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
672 // We will use these two data points to extrapolate how much the wallpaper parallax effect
673 // to span (ie travel) at any aspect ratio:
674
sfufa@google.comde013292021-09-21 18:22:44 -0700675 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
676 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700677 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
678 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
679
680 // To find out the desired width at different aspect ratios, we use the following two
681 // formulas, where the coefficient on x is the aspect ratio (width/height):
682 // (16/10)x + y = 1.5
683 // (10/16)x + y = 1.2
684 // We solve for x and y and end up with a final formula:
685 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700686 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
687 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700688 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
689 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
690 return x * aspectRatio + y;
691 }
692
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700693 public interface OnIDPChangeListener {
694
Sunny Goyalb47172b2021-05-03 19:59:51 -0700695 /**
696 * Called when the device provide changes
697 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700698 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700699 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800700
701
Sunny Goyaleff44f32019-01-09 17:29:49 -0800702 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800703
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800704 public static final String TAG_NAME = "grid-option";
705
Alex Chau1c883d82021-12-01 18:43:10 +0000706 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
707 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
708 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
709 private static final int DEVICE_CATEGORY_ALL =
710 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
711
Sunny Goyaleff44f32019-01-09 17:29:49 -0800712 public final String name;
713 public final int numRows;
714 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000715 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100716 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800717
718 private final int numFolderRows;
719 private final int numFolderColumns;
720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700721 private final int numAllAppsColumns;
722 private final int numDatabaseAllAppsColumns;
723 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000724 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700725 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800726
Tracy Zhou7df93d22020-01-27 13:44:06 -0800727 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000728
Sunny Goyal415f1732018-11-29 10:33:47 -0800729 private final int defaultLayoutId;
730 private final int demoModeLayoutId;
731
Jon Mirandae126d722021-02-25 10:45:20 -0500732 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400733 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500734
Sunny Goyal5bc18462019-01-07 15:13:39 -0800735 private final SparseArray<TypedValue> extraAttrs;
736
Alex Chau1c883d82021-12-01 18:43:10 +0000737 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800738 TypedArray a = context.obtainStyledAttributes(
739 attrs, R.styleable.GridDisplayOption);
740 name = a.getString(R.styleable.GridDisplayOption_name);
741 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
742 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000743 numSearchContainerColumns = a.getInt(
744 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800745
Tracy Zhou7df93d22020-01-27 13:44:06 -0800746 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000747 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100748 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
749 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
750 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800751 demoModeLayoutId = a.getResourceId(
752 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700753
754 numAllAppsColumns = a.getInt(
755 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
756 numDatabaseAllAppsColumns = a.getInt(
757 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
758
759 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800760 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000761 numShrunkenHotseatIcons = a.getInt(
762 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700763 numDatabaseHotseatIcons = a.getInt(
764 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
765
Sunny Goyal415f1732018-11-29 10:33:47 -0800766 numFolderRows = a.getInt(
767 R.styleable.GridDisplayOption_numFolderRows, numRows);
768 numFolderColumns = a.getInt(
769 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700770
Jon Mirandae126d722021-02-25 10:45:20 -0500771 isScalable = a.getBoolean(
772 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400773 devicePaddingId = a.getResourceId(
774 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500775
Alex Chau1c883d82021-12-01 18:43:10 +0000776 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
777 DEVICE_CATEGORY_ALL);
778 isEnabled = (deviceType == TYPE_PHONE
779 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
780 || (deviceType == TYPE_TABLET
781 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
782 || (deviceType == TYPE_MULTI_DISPLAY
783 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
784 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100785
Sunny Goyal415f1732018-11-29 10:33:47 -0800786 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800787 extraAttrs = Themes.createValueMap(context, attrs,
788 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800789 }
790 }
791
Sunny Goyal19ff7282021-04-22 10:12:54 -0700792 @VisibleForTesting
793 static final class DisplayOption {
Thales Lima12d0eff2022-03-25 17:06:11 +0000794 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
795 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
796 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
797 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
798 private static final int DONT_INLINE_QSB = 0;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700799
800 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800801
Sunny Goyal415f1732018-11-29 10:33:47 -0800802 private final float minWidthDps;
803 private final float minHeightDps;
804 private final boolean canBeDefault;
Thales Lima12d0eff2022-03-25 17:06:11 +0000805 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800806
Thales Lima83bedbf2021-10-05 17:47:39 +0100807 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100808
809 private float folderBorderSpace;
810 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100811 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima828875c2022-04-26 20:29:30 +0100812 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
Thales Lima6e7f36c2022-01-04 12:14:11 +0000813 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Lima828875c2022-04-26 20:29:30 +0100814 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100815
Thales Lima78d00ad2021-09-30 11:29:06 +0100816 private final float[] iconSizes = new float[COUNT_SIZES];
817 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800818
Thales Limab7ef5692022-03-10 10:32:36 +0000819 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000820 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
821 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
822 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
823
Thales Lima1de4d552021-10-13 16:13:25 +0100824 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800825 this.grid = grid;
826
Thales Lima1de4d552021-10-13 16:13:25 +0100827 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800828
Sunny Goyal415f1732018-11-29 10:33:47 -0800829 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
830 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700831
Thales Lima1de4d552021-10-13 16:13:25 +0100832 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800833
Thales Lima12d0eff2022-03-25 17:06:11 +0000834 int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb,
835 DONT_INLINE_QSB);
836 inlineQsb[INDEX_DEFAULT] =
837 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
838 inlineQsb[INDEX_LANDSCAPE] =
839 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
840 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
841 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
842 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
843 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
844 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
845 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
846
Thales Lima83bedbf2021-10-05 17:47:39 +0100847 float x;
848 float y;
849
Thales Lima85c942f2021-12-31 13:04:20 +0000850 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
851 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100852 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000853
854 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
855 minCellSize[INDEX_DEFAULT].x);
856 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
857 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100858 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100859
Thales Lima85c942f2021-12-31 13:04:20 +0000860 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100861 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000862 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100863 minCellSize[INDEX_DEFAULT].y);
864 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
865
Thales Lima85c942f2021-12-31 13:04:20 +0000866 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100867 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000868 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100869 minCellSize[INDEX_DEFAULT].y);
870 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100871
Thales Lima85c942f2021-12-31 13:04:20 +0000872 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000873 float borderSpaceLandscape = a.getFloat(
874 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000875 float borderSpaceTwoPanelPortrait = a.getFloat(
876 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
877 float borderSpaceTwoPanelLandscape = a.getFloat(
878 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100879
Thales Lima85c942f2021-12-31 13:04:20 +0000880 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
881 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100882 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000883
884 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
885 borderSpaceLandscape);
886 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
887 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100888 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
889
890 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000891 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
892 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100893 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000894 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
895 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100896 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
897
898 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000899 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
900 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100901 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000902 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
903 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100904 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
905
Thales Limabb7d3882021-12-22 12:56:29 +0000906 folderBorderSpace = borderSpace;
907
Thales Limab7ef5692022-03-10 10:32:36 +0000908 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
909 minCellSize[INDEX_DEFAULT].x);
910 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
911 minCellSize[INDEX_DEFAULT].y);
912 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
913
914 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
915 allAppsCellSize[INDEX_DEFAULT].x);
916 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
917 allAppsCellSize[INDEX_DEFAULT].y);
918 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
919
920 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
921 allAppsCellSize[INDEX_DEFAULT].x);
922 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
923 allAppsCellSize[INDEX_DEFAULT].y);
924 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
925
926 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
927 allAppsCellSize[INDEX_DEFAULT].x);
928 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
929 allAppsCellSize[INDEX_DEFAULT].y);
930 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
931
Thales Lima080d8902022-03-28 15:30:29 +0100932 float allAppsBorderSpace = a.getFloat(
933 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
934 float allAppsBorderSpaceLandscape = a.getFloat(
935 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
936 allAppsBorderSpace);
937 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000938 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +0100939 allAppsBorderSpace);
940 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000941 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +0100942 allAppsBorderSpace);
943
944 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
945 allAppsBorderSpace);
946 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
947 allAppsBorderSpace);
948 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
949
950 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
951 allAppsBorderSpaceLandscape);
952 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
953 allAppsBorderSpaceLandscape);
954 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
955
956 x = a.getFloat(
957 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
958 allAppsBorderSpaceTwoPanelPortrait);
959 y = a.getFloat(
960 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
961 allAppsBorderSpaceTwoPanelPortrait);
962 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
963
964 x = a.getFloat(
965 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
966 allAppsBorderSpaceTwoPanelLandscape);
967 y = a.getFloat(
968 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
969 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +0000970 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500971
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700972 iconSizes[INDEX_DEFAULT] =
973 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
974 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000975 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700976 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700977 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000978 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700979 iconSizes[INDEX_DEFAULT]);
980 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000981 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100982 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700983
Thales Limabb7d3882021-12-22 12:56:29 +0000984 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
985 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
986 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
987 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
988 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
989 allAppsIconSizes[INDEX_DEFAULT]);
990 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
991 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
992 allAppsIconSizes[INDEX_DEFAULT]);
993
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700994 textSizes[INDEX_DEFAULT] =
995 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
996 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000997 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700998 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700999 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001000 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001001 textSizes[INDEX_DEFAULT]);
1002 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001003 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001004 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001005
Thales Limabb7d3882021-12-22 12:56:29 +00001006 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1007 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1008 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1009 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1010 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1011 allAppsIconTextSizes[INDEX_DEFAULT]);
1012 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1013 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1014 allAppsIconTextSizes[INDEX_DEFAULT]);
1015
Thales Lima83bedbf2021-10-05 17:47:39 +01001016 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1017 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001018 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1019 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1020 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001021 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001022 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001023 horizontalMargin[INDEX_DEFAULT]);
1024 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001025 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001026 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001027
Thales Lima6e7f36c2022-01-04 12:14:11 +00001028 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
1029 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +00001030 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
1031 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
1032 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001033 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1034 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
1035 hotseatBorderSpaces[INDEX_DEFAULT]);
1036 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1037 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
1038 hotseatBorderSpaces[INDEX_DEFAULT]);
1039
Thales Lima828875c2022-04-26 20:29:30 +01001040 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
1041 R.styleable.ProfileDisplayOption_hotseatColumnSpan, grid.numColumns);
1042 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
1043 R.styleable.ProfileDisplayOption_hotseatColumnSpanLandscape, grid.numColumns);
1044 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1045 R.styleable.ProfileDisplayOption_hotseatColumnSpanTwoPanelLandscape,
1046 grid.numColumns);
1047 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1048 R.styleable.ProfileDisplayOption_hotseatColumnSpanTwoPanelPortrait,
1049 grid.numColumns);
1050
Sunny Goyal415f1732018-11-29 10:33:47 -08001051 a.recycle();
1052 }
1053
1054 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001055 this(null);
1056 }
1057
1058 DisplayOption(GridOption grid) {
1059 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001060 minWidthDps = 0;
1061 minHeightDps = 0;
1062 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001063 for (int i = 0; i < COUNT_SIZES; i++) {
1064 iconSizes[i] = 0;
1065 textSizes[i] = 0;
1066 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001067 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001068 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001069 allAppsIconSizes[i] = 0;
1070 allAppsIconTextSizes[i] = 0;
1071 allAppsBorderSpaces[i] = new PointF();
Thales Lima12d0eff2022-03-25 17:06:11 +00001072 inlineQsb[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001073 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001074 }
1075
1076 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001077 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001078 iconSizes[i] *= w;
1079 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001080 borderSpaces[i].x *= w;
1081 borderSpaces[i].y *= w;
1082 minCellSize[i].x *= w;
1083 minCellSize[i].y *= w;
1084 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001085 hotseatBorderSpaces[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001086 allAppsCellSize[i].x *= w;
1087 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001088 allAppsIconSizes[i] *= w;
1089 allAppsIconTextSizes[i] *= w;
1090 allAppsBorderSpaces[i].x *= w;
1091 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001092 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001093
1094 folderBorderSpace *= w;
1095
Sunny Goyal415f1732018-11-29 10:33:47 -08001096 return this;
1097 }
1098
1099 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001100 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001101 iconSizes[i] += p.iconSizes[i];
1102 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001103 borderSpaces[i].x += p.borderSpaces[i].x;
1104 borderSpaces[i].y += p.borderSpaces[i].y;
1105 minCellSize[i].x += p.minCellSize[i].x;
1106 minCellSize[i].y += p.minCellSize[i].y;
1107 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001108 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Lima828875c2022-04-26 20:29:30 +01001109 hotseatColumnSpan[i] = p.hotseatColumnSpan[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001110 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1111 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001112 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1113 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1114 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1115 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Thales Lima12d0eff2022-03-25 17:06:11 +00001116 inlineQsb[i] |= p.inlineQsb[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001117 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001118
1119 folderBorderSpace += p.folderBorderSpace;
1120
Sunny Goyal415f1732018-11-29 10:33:47 -08001121 return this;
1122 }
1123 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001124}