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