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