Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.Utilities.dpiFromPx; |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 20 | import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 23 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 24 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 25 | import android.annotation.TargetApi; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 26 | import android.appwidget.AppWidgetHostView; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 30 | import android.content.res.Resources; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 31 | import android.content.res.TypedArray; |
| 32 | import android.content.res.XmlResourceParser; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 35 | import android.text.TextUtils; |
| 36 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 37 | import android.util.DisplayMetrics; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 38 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 39 | import android.util.SparseArray; |
| 40 | import android.util.TypedValue; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 41 | import android.util.Xml; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 42 | import android.view.Display; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 43 | |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 44 | import androidx.annotation.Nullable; |
| 45 | import androidx.annotation.VisibleForTesting; |
| 46 | |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 47 | import com.android.launcher3.model.DeviceGridState; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 48 | import com.android.launcher3.util.DisplayController; |
| 49 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 50 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 51 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 52 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 53 | import com.android.launcher3.util.WindowBounds; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 54 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 55 | import org.xmlpull.v1.XmlPullParser; |
| 56 | import org.xmlpull.v1.XmlPullParserException; |
| 57 | |
| 58 | import java.io.IOException; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 59 | import java.util.ArrayList; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 60 | import java.util.Arrays; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 61 | import java.util.Collections; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 62 | import java.util.List; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 63 | |
| 64 | public class InvariantDeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 65 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 66 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 67 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 68 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 69 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 70 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 71 | private static final int DEFAULT_TRUE = -1; |
| 72 | private static final int DEFAULT_SPLIT_DISPLAY = 2; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 73 | private static final int GRID_ENABLED_ALL_DISPLAYS = 0; |
| 74 | private static final int GRID_ENABLED_SINGLE_DISPLAY = 1; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 75 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 76 | private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 77 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 78 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 79 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 80 | // Constants that affects the interpolation curve between statically defined device profile |
| 81 | // buckets. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 82 | private static final float KNEARESTNEIGHBOR = 3; |
| 83 | private static final float WEIGHT_POWER = 5; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 84 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 85 | // used to offset float not being able to express extremely small weights in extreme cases. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 86 | private static final float WEIGHT_EFFICIENT = 100000f; |
| 87 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Number of icons per row and column in the workspace. |
| 90 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 91 | public int numRows; |
| 92 | public int numColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Number of icons per row and column in the folder. |
| 96 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 97 | public int numFolderRows; |
| 98 | public int numFolderColumns; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 99 | public float iconSize; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 100 | public float landscapeIconSize; |
Andras Kloczl | 30fe915 | 2021-08-05 18:02:29 +0200 | [diff] [blame] | 101 | public float twoPanelPortraitIconSize; |
| 102 | public float twoPanelLandscapeIconSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 103 | public float landscapeIconTextSize; |
Andras Kloczl | 30fe915 | 2021-08-05 18:02:29 +0200 | [diff] [blame] | 104 | public float twoPanelPortraitIconTextSize; |
| 105 | public float twoPanelLandscapeIconTextSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 106 | public int iconBitmapSize; |
| 107 | public int fillResIconDpi; |
| 108 | public float iconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 109 | public float allAppsIconSize; |
| 110 | public float allAppsIconTextSize; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 111 | public boolean isSplitDisplay; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 112 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 113 | public float minCellHeight; |
| 114 | public float minCellWidth; |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 115 | public float twoPanelPortraitMinCellHeightDps; |
| 116 | public float twoPanelPortraitMinCellWidthDps; |
| 117 | public float twoPanelLandscapeMinCellHeightDps; |
| 118 | public float twoPanelLandscapeMinCellWidthDps; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 119 | public float borderSpacing; |
| 120 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 121 | private SparseArray<TypedValue> mExtraAttrs; |
| 122 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 123 | /** |
| 124 | * Number of icons inside the hotseat area. |
| 125 | */ |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 126 | protected int numShownHotseatIcons; |
| 127 | |
| 128 | /** |
| 129 | * Number of icons inside the hotseat area that is stored in the database. This is greater than |
| 130 | * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat |
| 131 | * sizes that share the same DB. |
| 132 | */ |
| 133 | public int numDatabaseHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 134 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 135 | /** |
| 136 | * Number of columns in the all apps list. |
| 137 | */ |
| 138 | public int numAllAppsColumns; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 139 | public int numDatabaseAllAppsColumns; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 140 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 141 | /** |
| 142 | * Do not query directly. see {@link DeviceProfile#isScalableGrid}. |
| 143 | */ |
| 144 | protected boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 145 | public int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 146 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 147 | public String dbFile; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 148 | public int defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 149 | int demoModeLayoutId; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 150 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 151 | /** |
| 152 | * An immutable list of supported profiles. |
| 153 | */ |
| 154 | public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 155 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 156 | @Nullable public DevicePaddings devicePaddings; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 157 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 158 | public Point defaultWallpaperSize; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 159 | public Rect defaultWidgetPadding; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 160 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 161 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 162 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 163 | @VisibleForTesting |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 164 | public InvariantDeviceProfile() {} |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 165 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 166 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 167 | private InvariantDeviceProfile(Context context) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 168 | String gridName = getCurrentGridName(context); |
| 169 | String newGridName = initGrid(context, gridName); |
| 170 | if (!newGridName.equals(gridName)) { |
| 171 | Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); |
| 172 | } |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 173 | new DeviceGridState(this).writeToPrefs(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 174 | |
Tracy Zhou | c8beebf | 2021-09-23 10:18:11 -0700 | [diff] [blame^] | 175 | DisplayController.INSTANCE.get(context).setPriorityListener( |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 176 | (displayContext, info, flags) -> { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 177 | if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) { |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 178 | onConfigChanged(displayContext); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 179 | } |
| 180 | }); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 183 | /** |
| 184 | * This constructor should NOT have any monitors by design. |
| 185 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 186 | public InvariantDeviceProfile(Context context, String gridName) { |
| 187 | String newName = initGrid(context, gridName); |
| 188 | if (newName == null || !newName.equals(gridName)) { |
| 189 | throw new IllegalArgumentException("Unknown grid name"); |
| 190 | } |
| 191 | } |
| 192 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 193 | /** |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 194 | * This constructor should NOT have any monitors by design. |
| 195 | */ |
| 196 | public InvariantDeviceProfile(Context context, Display display) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 197 | // Ensure that the main device profile is initialized |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 198 | INSTANCE.get(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 199 | String gridName = getCurrentGridName(context); |
| 200 | |
| 201 | // Get the display info based on default display and interpolate it to existing display |
| 202 | DisplayOption defaultDisplayOption = invDistWeightedInterpolate( |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 203 | DisplayController.INSTANCE.get(context).getInfo(), |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 204 | getPredefinedDeviceProfiles(context, gridName, false), false); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 205 | |
Alex Chau | 417bd72 | 2021-01-26 15:22:18 +0000 | [diff] [blame] | 206 | Info myInfo = new Info(context, display); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 207 | DisplayOption myDisplayOption = invDistWeightedInterpolate( |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 208 | myInfo, getPredefinedDeviceProfiles(context, gridName, false), false); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 209 | |
| 210 | DisplayOption result = new DisplayOption(defaultDisplayOption.grid) |
| 211 | .add(myDisplayOption); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 212 | result.iconSizes[DisplayOption.INDEX_DEFAULT] = |
| 213 | defaultDisplayOption.iconSizes[DisplayOption.INDEX_DEFAULT]; |
| 214 | for (int i = 1; i < DisplayOption.COUNT_TOTAL; i++) { |
| 215 | result.iconSizes[i] = Math.min( |
| 216 | defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 217 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 218 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 219 | result.minCellHeight = defaultDisplayOption.minCellHeight; |
| 220 | result.minCellWidth = defaultDisplayOption.minCellWidth; |
| 221 | result.borderSpacing = defaultDisplayOption.borderSpacing; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 222 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 223 | initGrid(context, myInfo, result, false); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 226 | public static String getCurrentGridName(Context context) { |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 227 | return Utilities.isGridOptionsEnabled(context) |
| 228 | ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null; |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 231 | private String initGrid(Context context, String gridName) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 232 | Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); |
Pat Manning | 67094bf | 2021-05-26 12:38:13 +0000 | [diff] [blame] | 233 | // Each screen has two profiles (portrait/landscape), so devices with four or more |
| 234 | // supported profiles implies two or more internal displays. |
| 235 | boolean isSplitDisplay = |
| 236 | displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 237 | |
| 238 | ArrayList<DisplayOption> allOptions = |
| 239 | getPredefinedDeviceProfiles(context, gridName, isSplitDisplay); |
| 240 | DisplayOption displayOption = |
| 241 | invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay); |
| 242 | initGrid(context, displayInfo, displayOption, isSplitDisplay); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 243 | return displayOption.grid.name; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 244 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 245 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 246 | private void initGrid( |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 247 | Context context, Info displayInfo, DisplayOption displayOption, |
| 248 | boolean isSplitDisplay) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 249 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 250 | GridOption closestProfile = displayOption.grid; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 251 | numRows = closestProfile.numRows; |
| 252 | numColumns = closestProfile.numColumns; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 253 | dbFile = closestProfile.dbFile; |
| 254 | defaultLayoutId = closestProfile.defaultLayoutId; |
| 255 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
| 256 | numFolderRows = closestProfile.numFolderRows; |
| 257 | numFolderColumns = closestProfile.numFolderColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 258 | isScalable = closestProfile.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 259 | devicePaddingId = closestProfile.devicePaddingId; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 260 | this.isSplitDisplay = isSplitDisplay; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 261 | |
| 262 | mExtraAttrs = closestProfile.extraAttrs; |
| 263 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 264 | iconSize = displayOption.iconSizes[DisplayOption.INDEX_DEFAULT]; |
| 265 | landscapeIconSize = displayOption.iconSizes[DisplayOption.INDEX_LANDSCAPE]; |
| 266 | twoPanelPortraitIconSize = displayOption.iconSizes[DisplayOption.INDEX_TWO_PANEL_PORTRAIT]; |
| 267 | twoPanelLandscapeIconSize = |
| 268 | displayOption.iconSizes[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE]; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 269 | iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics); |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 270 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 271 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 272 | iconTextSize = displayOption.textSizes[DisplayOption.INDEX_DEFAULT]; |
| 273 | landscapeIconTextSize = displayOption.textSizes[DisplayOption.INDEX_LANDSCAPE]; |
| 274 | twoPanelPortraitIconTextSize = |
| 275 | displayOption.textSizes[DisplayOption.INDEX_TWO_PANEL_PORTRAIT]; |
| 276 | twoPanelLandscapeIconTextSize = |
| 277 | displayOption.textSizes[DisplayOption.INDEX_TWO_PANEL_LANDSCAPE]; |
| 278 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 279 | minCellHeight = displayOption.minCellHeight; |
| 280 | minCellWidth = displayOption.minCellWidth; |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 281 | twoPanelPortraitMinCellHeightDps = displayOption.twoPanelPortraitMinCellHeightDps; |
| 282 | twoPanelPortraitMinCellWidthDps = displayOption.twoPanelPortraitMinCellWidthDps; |
| 283 | twoPanelLandscapeMinCellHeightDps = displayOption.twoPanelLandscapeMinCellHeightDps; |
| 284 | twoPanelLandscapeMinCellWidthDps = displayOption.twoPanelLandscapeMinCellWidthDps; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 285 | borderSpacing = displayOption.borderSpacing; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 286 | |
| 287 | numShownHotseatIcons = closestProfile.numHotseatIcons; |
| 288 | numDatabaseHotseatIcons = isSplitDisplay |
| 289 | ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; |
| 290 | |
| 291 | numAllAppsColumns = closestProfile.numAllAppsColumns; |
| 292 | numDatabaseAllAppsColumns = isSplitDisplay |
| 293 | ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 294 | |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 295 | if (Utilities.isGridOptionsEnabled(context)) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 296 | allAppsIconSize = displayOption.iconSizes[DisplayOption.INDEX_ALL_APPS]; |
| 297 | allAppsIconTextSize = displayOption.textSizes[DisplayOption.INDEX_ALL_APPS]; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 298 | } else { |
| 299 | allAppsIconSize = iconSize; |
| 300 | allAppsIconTextSize = iconTextSize; |
| 301 | } |
| 302 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 303 | if (devicePaddingId != 0) { |
| 304 | devicePaddings = new DevicePaddings(context, devicePaddingId); |
| 305 | } |
| 306 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 307 | // If the partner customization apk contains any grid overrides, apply them |
| 308 | // Supported overrides: numRows, numColumns, iconSize |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 309 | applyPartnerDeviceProfileOverrides(context, metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 310 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 311 | final List<DeviceProfile> localSupportedProfiles = new ArrayList<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 312 | defaultWallpaperSize = new Point(displayInfo.currentSize); |
| 313 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 314 | localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 315 | .setUseTwoPanels(isSplitDisplay) |
| 316 | .setWindowBounds(bounds).build()); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 317 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 318 | // Wallpaper size should be the maximum of the all possible sizes Launcher expects |
| 319 | int displayWidth = bounds.bounds.width(); |
| 320 | int displayHeight = bounds.bounds.height(); |
| 321 | defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 322 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 323 | // We need to ensure that there is enough extra space in the wallpaper |
| 324 | // for the intended parallax effects |
| 325 | float parallaxFactor = |
| 326 | dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720 |
| 327 | ? 2 |
| 328 | : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight); |
| 329 | defaultWallpaperSize.x = |
| 330 | Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth)); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 331 | } |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 332 | supportedProfiles = Collections.unmodifiableList(localSupportedProfiles); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 333 | |
| 334 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 335 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 338 | @Nullable |
| 339 | public TypedValue getAttrValue(int attr) { |
| 340 | return mExtraAttrs == null ? null : mExtraAttrs.get(attr); |
| 341 | } |
| 342 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 343 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 344 | mChangeListeners.add(listener); |
| 345 | } |
| 346 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 347 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 348 | mChangeListeners.remove(listener); |
| 349 | } |
| 350 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 351 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 352 | public void setCurrentGrid(Context context, String gridName) { |
| 353 | Context appContext = context.getApplicationContext(); |
| 354 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 355 | MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 358 | private Object[] toModelState() { |
| 359 | return new Object[] { |
| 360 | numColumns, numRows, numDatabaseHotseatIcons, iconBitmapSize, fillResIconDpi, |
| 361 | numDatabaseAllAppsColumns, dbFile}; |
| 362 | } |
| 363 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 364 | private void onConfigChanged(Context context) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 365 | Object[] oldState = toModelState(); |
| 366 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 367 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 368 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 369 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 370 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 371 | boolean modelPropsChanged = !Arrays.equals(oldState, toModelState()); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 372 | for (OnIDPChangeListener listener : mChangeListeners) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 373 | listener.onIdpChanged(modelPropsChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 377 | private static ArrayList<DisplayOption> getPredefinedDeviceProfiles( |
| 378 | Context context, String gridName, boolean isSplitDisplay) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 379 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 380 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
| 381 | final int depth = parser.getDepth(); |
| 382 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 383 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 384 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 385 | if ((type == XmlPullParser.START_TAG) |
| 386 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 387 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 388 | GridOption gridOption = |
| 389 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
| 390 | if (gridOption.isEnabled) { |
| 391 | final int displayDepth = parser.getDepth(); |
| 392 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 393 | || parser.getDepth() > displayDepth) |
| 394 | && type != XmlPullParser.END_DOCUMENT) { |
| 395 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 396 | parser.getName())) { |
| 397 | profiles.add(new DisplayOption(gridOption, context, |
| 398 | Xml.asAttributeSet(parser), |
| 399 | isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE)); |
| 400 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 401 | } |
| 402 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } catch (IOException|XmlPullParserException e) { |
| 406 | throw new RuntimeException(e); |
| 407 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 408 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 409 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 410 | if (!TextUtils.isEmpty(gridName)) { |
| 411 | for (DisplayOption option : profiles) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 412 | if (gridName.equals(option.grid.name) && option.grid.isEnabled) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 413 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 417 | if (filteredProfiles.isEmpty()) { |
| 418 | // No grid found, use the default options |
| 419 | for (DisplayOption option : profiles) { |
| 420 | if (option.canBeDefault) { |
| 421 | filteredProfiles.add(option); |
| 422 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 425 | if (filteredProfiles.isEmpty()) { |
| 426 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 427 | } |
| 428 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 431 | /** |
| 432 | * @return all the grid options that can be shown on the device |
| 433 | */ |
| 434 | public List<GridOption> parseAllGridOptions(Context context) { |
| 435 | List<GridOption> result = new ArrayList<>(); |
| 436 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
| 437 | final int depth = parser.getDepth(); |
| 438 | int type; |
| 439 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 440 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 441 | if ((type == XmlPullParser.START_TAG) |
| 442 | && GridOption.TAG_NAME.equals(parser.getName())) { |
| 443 | GridOption option = |
| 444 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
| 445 | if (option.isEnabled) { |
| 446 | result.add(option); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } catch (IOException | XmlPullParserException e) { |
| 451 | Log.e(TAG, "Error parsing device profile", e); |
| 452 | return Collections.emptyList(); |
| 453 | } |
| 454 | return result; |
| 455 | } |
| 456 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 457 | private int getLauncherIconDensity(int requiredSize) { |
| 458 | // Densities typically defined by an app. |
| 459 | int[] densityBuckets = new int[] { |
| 460 | DisplayMetrics.DENSITY_LOW, |
| 461 | DisplayMetrics.DENSITY_MEDIUM, |
| 462 | DisplayMetrics.DENSITY_TV, |
| 463 | DisplayMetrics.DENSITY_HIGH, |
| 464 | DisplayMetrics.DENSITY_XHIGH, |
| 465 | DisplayMetrics.DENSITY_XXHIGH, |
| 466 | DisplayMetrics.DENSITY_XXXHIGH |
| 467 | }; |
| 468 | |
| 469 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 470 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 471 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 472 | / DisplayMetrics.DENSITY_DEFAULT; |
| 473 | if (expectedSize >= requiredSize) { |
| 474 | density = densityBuckets[i]; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | return density; |
| 479 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 480 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 481 | /** |
| 482 | * Apply any Partner customization grid overrides. |
| 483 | * |
| 484 | * Currently we support: all apps row / column count. |
| 485 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 486 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 487 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 488 | if (p != null) { |
| 489 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 490 | } |
| 491 | } |
| 492 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 493 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 494 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 497 | private static DisplayOption invDistWeightedInterpolate( |
| 498 | Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) { |
| 499 | int minWidthPx = Integer.MAX_VALUE; |
| 500 | int minHeightPx = Integer.MAX_VALUE; |
| 501 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 502 | boolean isTablet = displayInfo.isTablet(bounds); |
| 503 | if (isTablet && isSplitDisplay) { |
| 504 | // For split displays, take half width per page |
| 505 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 506 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 507 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 508 | } else if (!isTablet && bounds.isLandscape()) { |
| 509 | // We will use transposed layout in this case |
| 510 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 511 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 512 | } else { |
| 513 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 514 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | float width = dpiFromPx(minWidthPx, displayInfo.densityDpi); |
| 519 | float height = dpiFromPx(minHeightPx, displayInfo.densityDpi); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 520 | |
| 521 | // Sort the profiles based on the closeness to the device size |
| 522 | Collections.sort(points, (a, b) -> |
| 523 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 524 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 525 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 526 | DisplayOption closestPoint = points.get(0); |
| 527 | GridOption closestOption = closestPoint.grid; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 528 | float weights = 0; |
| 529 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 530 | if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) { |
| 531 | return closestPoint; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | DisplayOption out = new DisplayOption(closestOption); |
| 535 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 536 | DisplayOption p = points.get(i); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 537 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 538 | weights += w; |
| 539 | out.add(new DisplayOption().add(p).multiply(w)); |
| 540 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 541 | out.multiply(1.0f / weights); |
| 542 | |
| 543 | // Since the bitmaps are persisted, ensure that the default bitmap size is same as |
| 544 | // predefined size to avoid cache invalidation |
| 545 | out.iconSizes[DisplayOption.INDEX_DEFAULT] = |
| 546 | closestPoint.iconSizes[DisplayOption.INDEX_DEFAULT]; |
| 547 | for (int i = DisplayOption.INDEX_DEFAULT + 1; i < DisplayOption.COUNT_TOTAL; i++) { |
| 548 | out.iconSizes[i] = Math.min(out.iconSizes[i], |
| 549 | out.iconSizes[DisplayOption.INDEX_DEFAULT]); |
| 550 | } |
| 551 | |
| 552 | return out; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 555 | public DeviceProfile getDeviceProfile(Context context) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 556 | Resources res = context.getResources(); |
| 557 | Configuration config = context.getResources().getConfiguration(); |
| 558 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 559 | float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; |
| 560 | float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; |
| 561 | return getBestMatch(screenWidth, screenHeight); |
| 562 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 563 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 564 | public DeviceProfile getBestMatch(float screenWidth, float screenHeight) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 565 | DeviceProfile bestMatch = supportedProfiles.get(0); |
| 566 | float minDiff = Float.MAX_VALUE; |
| 567 | |
| 568 | for (DeviceProfile profile : supportedProfiles) { |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 569 | float diff = Math.abs(profile.widthPx - screenWidth) |
| 570 | + Math.abs(profile.heightPx - screenHeight); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 571 | if (diff < minDiff) { |
| 572 | minDiff = diff; |
| 573 | bestMatch = profile; |
| 574 | } |
| 575 | } |
| 576 | return bestMatch; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 579 | private static float weight(float x0, float y0, float x1, float y1, float pow) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 580 | float d = dist(x0, y0, x1, y1); |
| 581 | if (Float.compare(d, 0f) == 0) { |
| 582 | return Float.POSITIVE_INFINITY; |
| 583 | } |
| 584 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 585 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 586 | |
| 587 | /** |
| 588 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 589 | * horizontally |
| 590 | */ |
| 591 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 592 | float aspectRatio = width / (float) height; |
| 593 | |
| 594 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 595 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 596 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 597 | // to span (ie travel) at any aspect ratio: |
| 598 | |
| 599 | final float ASPECT_RATIO_LANDSCAPE = 16/10f; |
| 600 | final float ASPECT_RATIO_PORTRAIT = 10/16f; |
| 601 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 602 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 603 | |
| 604 | // To find out the desired width at different aspect ratios, we use the following two |
| 605 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 606 | // (16/10)x + y = 1.5 |
| 607 | // (10/16)x + y = 1.2 |
| 608 | // We solve for x and y and end up with a final formula: |
| 609 | final float x = |
| 610 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
| 611 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 612 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 613 | return x * aspectRatio + y; |
| 614 | } |
| 615 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 616 | public interface OnIDPChangeListener { |
| 617 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 618 | /** |
| 619 | * Called when the device provide changes |
| 620 | */ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 621 | void onIdpChanged(boolean modelPropertiesChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 622 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 623 | |
| 624 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 625 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 626 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 627 | public static final String TAG_NAME = "grid-option"; |
| 628 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 629 | public final String name; |
| 630 | public final int numRows; |
| 631 | public final int numColumns; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 632 | public final boolean isEnabled; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 633 | |
| 634 | private final int numFolderRows; |
| 635 | private final int numFolderColumns; |
| 636 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 637 | private final int numAllAppsColumns; |
| 638 | private final int numDatabaseAllAppsColumns; |
| 639 | private final int numHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 640 | private final int numDatabaseHotseatIcons; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 641 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 642 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 643 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 644 | private final int defaultLayoutId; |
| 645 | private final int demoModeLayoutId; |
| 646 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 647 | private final boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 648 | private final int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 649 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 650 | private final SparseArray<TypedValue> extraAttrs; |
| 651 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 652 | public GridOption(Context context, AttributeSet attrs, boolean isSplitDisplay) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 653 | TypedArray a = context.obtainStyledAttributes( |
| 654 | attrs, R.styleable.GridDisplayOption); |
| 655 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 656 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 657 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
| 658 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 659 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 660 | defaultLayoutId = a.getResourceId(isSplitDisplay && a.hasValue( |
| 661 | R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId) |
| 662 | ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId |
| 663 | : R.styleable.GridDisplayOption_defaultLayoutId, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 664 | demoModeLayoutId = a.getResourceId( |
| 665 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 666 | |
| 667 | numAllAppsColumns = a.getInt( |
| 668 | R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); |
| 669 | numDatabaseAllAppsColumns = a.getInt( |
| 670 | R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); |
| 671 | |
| 672 | numHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 673 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 674 | numDatabaseHotseatIcons = a.getInt( |
| 675 | R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); |
| 676 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 677 | numFolderRows = a.getInt( |
| 678 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 679 | numFolderColumns = a.getInt( |
| 680 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 681 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 682 | isScalable = a.getBoolean( |
| 683 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 684 | devicePaddingId = a.getResourceId( |
| 685 | R.styleable.GridDisplayOption_devicePaddingId, 0); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 686 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 687 | final int enabledInt = |
| 688 | a.getInteger(R.styleable.GridDisplayOption_gridEnabled, |
| 689 | GRID_ENABLED_ALL_DISPLAYS); |
| 690 | isEnabled = enabledInt == GRID_ENABLED_ALL_DISPLAYS |
| 691 | || enabledInt == GRID_ENABLED_SINGLE_DISPLAY && !isSplitDisplay; |
| 692 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 693 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 694 | extraAttrs = Themes.createValueMap(context, attrs, |
| 695 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 699 | @VisibleForTesting |
| 700 | static final class DisplayOption { |
| 701 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 702 | static final int INDEX_DEFAULT = 0; |
| 703 | static final int INDEX_LANDSCAPE = 1; |
| 704 | static final int INDEX_ALL_APPS = 2; |
| 705 | static final int INDEX_TWO_PANEL_PORTRAIT = 3; |
| 706 | static final int INDEX_TWO_PANEL_LANDSCAPE = 4; |
| 707 | |
| 708 | static final int COUNT_TOTAL = 5; |
| 709 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 710 | public final GridOption grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 711 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 712 | private final float minWidthDps; |
| 713 | private final float minHeightDps; |
| 714 | private final boolean canBeDefault; |
| 715 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 716 | private float minCellHeight; |
| 717 | private float minCellWidth; |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 718 | private float twoPanelPortraitMinCellHeightDps; |
| 719 | private float twoPanelPortraitMinCellWidthDps; |
| 720 | private float twoPanelLandscapeMinCellHeightDps; |
| 721 | private float twoPanelLandscapeMinCellWidthDps; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 722 | private float borderSpacing; |
| 723 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 724 | private final float[] iconSizes = new float[COUNT_TOTAL]; |
| 725 | private final float[] textSizes = new float[COUNT_TOTAL]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 726 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 727 | DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 728 | this.grid = grid; |
| 729 | |
| 730 | TypedArray a = context.obtainStyledAttributes( |
| 731 | attrs, R.styleable.ProfileDisplayOption); |
| 732 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 733 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 734 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 735 | |
| 736 | canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0) |
| 737 | == defaultFlagValue; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 738 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 739 | minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0); |
| 740 | minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0); |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 741 | twoPanelPortraitMinCellHeightDps = a.getFloat( |
| 742 | R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellHeightDps, |
| 743 | minCellHeight); |
| 744 | twoPanelPortraitMinCellWidthDps = a.getFloat( |
| 745 | R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellWidthDps, minCellWidth); |
| 746 | twoPanelLandscapeMinCellHeightDps = a.getFloat( |
| 747 | R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellHeightDps, |
| 748 | twoPanelPortraitMinCellHeightDps); |
| 749 | twoPanelLandscapeMinCellWidthDps = a.getFloat( |
| 750 | R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps, |
| 751 | twoPanelPortraitMinCellWidthDps); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 752 | borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0); |
| 753 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 754 | iconSizes[INDEX_DEFAULT] = |
| 755 | a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
| 756 | iconSizes[INDEX_LANDSCAPE] = |
| 757 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize, |
| 758 | iconSizes[INDEX_DEFAULT]); |
| 759 | iconSizes[INDEX_ALL_APPS] = |
| 760 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize, |
| 761 | iconSizes[INDEX_DEFAULT]); |
| 762 | iconSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 763 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconSize, |
| 764 | iconSizes[INDEX_DEFAULT]); |
| 765 | iconSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 766 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconSize, |
| 767 | iconSizes[INDEX_LANDSCAPE]); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 768 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 769 | textSizes[INDEX_DEFAULT] = |
| 770 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 771 | textSizes[INDEX_LANDSCAPE] = |
| 772 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconTextSize, |
| 773 | textSizes[INDEX_DEFAULT]); |
| 774 | textSizes[INDEX_ALL_APPS] = |
| 775 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize, |
| 776 | textSizes[INDEX_DEFAULT]); |
| 777 | textSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 778 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconTextSize, |
| 779 | textSizes[INDEX_DEFAULT]); |
| 780 | textSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 781 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize, |
| 782 | textSizes[INDEX_LANDSCAPE]); |
| 783 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 784 | a.recycle(); |
| 785 | } |
| 786 | |
| 787 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 788 | this(null); |
| 789 | } |
| 790 | |
| 791 | DisplayOption(GridOption grid) { |
| 792 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 793 | minWidthDps = 0; |
| 794 | minHeightDps = 0; |
| 795 | canBeDefault = false; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 796 | minCellHeight = 0; |
| 797 | minCellWidth = 0; |
| 798 | borderSpacing = 0; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | private DisplayOption multiply(float w) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 802 | for (int i = 0; i < COUNT_TOTAL; i++) { |
| 803 | iconSizes[i] *= w; |
| 804 | textSizes[i] *= w; |
| 805 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 806 | minCellHeight *= w; |
| 807 | minCellWidth *= w; |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 808 | twoPanelPortraitMinCellHeightDps *= w; |
| 809 | twoPanelPortraitMinCellWidthDps *= w; |
| 810 | twoPanelLandscapeMinCellHeightDps *= w; |
| 811 | twoPanelLandscapeMinCellWidthDps *= w; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 812 | borderSpacing *= w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 813 | return this; |
| 814 | } |
| 815 | |
| 816 | private DisplayOption add(DisplayOption p) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 817 | for (int i = 0; i < COUNT_TOTAL; i++) { |
| 818 | iconSizes[i] += p.iconSizes[i]; |
| 819 | textSizes[i] += p.textSizes[i]; |
| 820 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 821 | minCellHeight += p.minCellHeight; |
| 822 | minCellWidth += p.minCellWidth; |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 823 | twoPanelPortraitMinCellHeightDps += p.twoPanelPortraitMinCellHeightDps; |
| 824 | twoPanelPortraitMinCellWidthDps += p.twoPanelPortraitMinCellWidthDps; |
| 825 | twoPanelLandscapeMinCellHeightDps += p.twoPanelLandscapeMinCellHeightDps; |
| 826 | twoPanelLandscapeMinCellWidthDps += p.twoPanelLandscapeMinCellWidthDps; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 827 | borderSpacing += p.borderSpacing; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 828 | return this; |
| 829 | } |
| 830 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 831 | } |