diff --git a/protos/view_capture.proto b/protos/view_capture.proto index 98574dd172..349ff36d15 100644 --- a/protos/view_capture.proto +++ b/protos/view_capture.proto @@ -51,4 +51,6 @@ message ViewNode { optional int32 visibility = 16; repeated ViewNode children = 17; + + optional float elevation = 18; } diff --git a/quickstep/src/com/android/quickstep/TaskViewUtils.java b/quickstep/src/com/android/quickstep/TaskViewUtils.java index 3bd72fe41d..a809c9c09b 100644 --- a/quickstep/src/com/android/quickstep/TaskViewUtils.java +++ b/quickstep/src/com/android/quickstep/TaskViewUtils.java @@ -593,6 +593,15 @@ public final class TaskViewUtils { Animator launcherAnim; final AnimatorListenerAdapter windowAnimEndListener; if (launcherClosing) { + // Since Overview is in launcher, just opening overview sets willFinishToHome to true. + // Now that we are closing the launcher, we need to (re)set willFinishToHome back to + // false. Otherwise, RecentsAnimationController can't differentiate between closing + // overview to 3p home vs closing overview to app. + final RecentsAnimationController raController = + recentsView.getRecentsAnimationController(); + if (raController != null) { + raController.setWillFinishToHome(false); + } Context context = v.getContext(); DeviceProfile dp = BaseActivity.fromContext(context).getDeviceProfile(); launcherAnim = dp.isTablet diff --git a/quickstep/tests/src/com/android/quickstep/DeviceProfileTest.kt b/quickstep/tests/src/com/android/quickstep/DeviceProfileTest.kt index 45a342ae32..9977207e86 100644 --- a/quickstep/tests/src/com/android/quickstep/DeviceProfileTest.kt +++ b/quickstep/tests/src/com/android/quickstep/DeviceProfileTest.kt @@ -73,13 +73,14 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonTextSizePx: 36.0px (13.714286dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + - "\tfolderCellHeightPx: 272.0px (103.61905dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 21.0px (8.0dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 146.0px (55.61905dp)\n" + "\tallAppsShiftRange: 788.0px (300.1905dp)\n" + "\tallAppsTopPadding: 0.0px (0.0dp)\n" + @@ -192,13 +193,14 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonTextSizePx: 36.0px (13.714286dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + - "\tfolderCellHeightPx: 272.0px (103.61905dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 21.0px (8.0dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 146.0px (55.61905dp)\n" + "\tallAppsShiftRange: 788.0px (300.1905dp)\n" + "\tallAppsTopPadding: 0.0px (0.0dp)\n" + @@ -316,9 +318,10 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\tfolderChildIconSizePx: 120.0px (60.0dp)\n" + "\tfolderChildTextSizePx: 28.0px (14.0dp)\n" + "\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Horizontal: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Vertical: 0.0px (0.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Horizontal: 32.0px (16.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Vertical: 32.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 32.0px (16.0dp)\n" + + "\tfolderTopPadding: 48.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 104.0px (52.0dp)\n" + "\tallAppsShiftRange: 1496.0px (748.0dp)\n" + "\tallAppsTopPadding: 104.0px (52.0dp)\n" + @@ -436,9 +439,10 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\tfolderChildIconSizePx: 120.0px (60.0dp)\n" + "\tfolderChildTextSizePx: 28.0px (14.0dp)\n" + "\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Horizontal: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Vertical: 0.0px (0.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Horizontal: 32.0px (16.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Vertical: 32.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 32.0px (16.0dp)\n" + + "\tfolderTopPadding: 48.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 104.0px (52.0dp)\n" + "\tallAppsShiftRange: 1496.0px (748.0dp)\n" + "\tallAppsTopPadding: 104.0px (52.0dp)\n" + @@ -551,14 +555,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 120.0px (60.0dp)\n" + "\ticonTextSizePx: 28.0px (14.0dp)\n" + "\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" + - "\tfolderCellWidthPx: 204.0px (102.0dp)\n" + - "\tfolderCellHeightPx: 240.0px (120.0dp)\n" + + "\tfolderCellWidthPx: 240.0px (120.0dp)\n" + + "\tfolderCellHeightPx: 208.0px (104.0dp)\n" + "\tfolderChildIconSizePx: 120.0px (60.0dp)\n" + "\tfolderChildTextSizePx: 28.0px (14.0dp)\n" + - "\tfolderChildDrawablePaddingPx: 27.0px (13.5dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Horizontal: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Vertical: 0.0px (0.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Horizontal: 32.0px (16.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Vertical: 32.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 32.0px (16.0dp)\n" + + "\tfolderTopPadding: 48.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 704.0px (352.0dp)\n" + "\tallAppsShiftRange: 1936.0px (968.0dp)\n" + "\tallAppsTopPadding: 624.0px (312.0dp)\n" + @@ -671,14 +676,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 120.0px (60.0dp)\n" + "\ticonTextSizePx: 28.0px (14.0dp)\n" + "\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" + - "\tfolderCellWidthPx: 204.0px (102.0dp)\n" + - "\tfolderCellHeightPx: 240.0px (120.0dp)\n" + + "\tfolderCellWidthPx: 240.0px (120.0dp)\n" + + "\tfolderCellHeightPx: 208.0px (104.0dp)\n" + "\tfolderChildIconSizePx: 120.0px (60.0dp)\n" + "\tfolderChildTextSizePx: 28.0px (14.0dp)\n" + - "\tfolderChildDrawablePaddingPx: 27.0px (13.5dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Horizontal: 0.0px (0.0dp)\n" + - "\tfolderCellLayoutBorderSpacePx Vertical: 0.0px (0.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Horizontal: 32.0px (16.0dp)\n" + + "\tfolderCellLayoutBorderSpacePx Vertical: 32.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 32.0px (16.0dp)\n" + + "\tfolderTopPadding: 48.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 704.0px (352.0dp)\n" + "\tallAppsShiftRange: 1936.0px (968.0dp)\n" + "\tallAppsTopPadding: 624.0px (312.0dp)\n" + @@ -792,13 +798,14 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonTextSizePx: 36.0px (13.714286dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + - "\tfolderCellHeightPx: 267.0px (101.71429dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 19.0px (7.2380953dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 110.0px (41.904762dp)\n" + "\tallAppsShiftRange: 1730.0px (659.0476dp)\n" + "\tallAppsTopPadding: 110.0px (41.904762dp)\n" + @@ -912,13 +919,14 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonTextSizePx: 36.0px (13.714286dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + - "\tfolderCellHeightPx: 267.0px (101.71429dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 19.0px (7.2380953dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 110.0px (41.904762dp)\n" + "\tallAppsShiftRange: 1730.0px (659.0476dp)\n" + "\tallAppsTopPadding: 110.0px (41.904762dp)\n" + @@ -1031,14 +1039,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 136.0px (51.809525dp)\n" + "\ticonTextSizePx: 31.0px (11.809524dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + - "\tfolderCellWidthPx: 192.0px (73.14286dp)\n" + - "\tfolderCellHeightPx: 304.0px (115.809525dp)\n" + + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 32.0px (12.190476dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 110.0px (41.904762dp)\n" + "\tallAppsShiftRange: 2098.0px (799.2381dp)\n" + "\tallAppsTopPadding: 110.0px (41.904762dp)\n" + @@ -1151,14 +1160,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 136.0px (51.809525dp)\n" + "\ticonTextSizePx: 31.0px (11.809524dp)\n" + "\ticonDrawablePaddingPx: 17.0px (6.4761906dp)\n" + - "\tfolderCellWidthPx: 192.0px (73.14286dp)\n" + - "\tfolderCellHeightPx: 304.0px (115.809525dp)\n" + + "\tfolderCellWidthPx: 210.0px (80.0dp)\n" + + "\tfolderCellHeightPx: 247.0px (94.09524dp)\n" + "\tfolderChildIconSizePx: 158.0px (60.190475dp)\n" + "\tfolderChildTextSizePx: 37.0px (14.095238dp)\n" + - "\tfolderChildDrawablePaddingPx: 32.0px (12.190476dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderChildDrawablePaddingPx: 13.0px (4.952381dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 42.0px (16.0dp)\n" + + "\tfolderTopPadding: 63.0px (24.0dp)\n" + "\tbottomSheetTopPadding: 110.0px (41.904762dp)\n" + "\tallAppsShiftRange: 2098.0px (799.2381dp)\n" + "\tallAppsTopPadding: 110.0px (41.904762dp)\n" + @@ -1270,14 +1280,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 142.0px (54.095238dp)\n" + "\ticonTextSizePx: 0.0px (0.0dp)\n" + "\ticonDrawablePaddingPx: 0.0px (0.0dp)\n" + - "\tfolderCellWidthPx: 179.0px (68.190475dp)\n" + - "\tfolderCellHeightPx: 212.0px (80.7619dp)\n" + - "\tfolderChildIconSizePx: 135.0px (51.42857dp)\n" + - "\tfolderChildTextSizePx: 35.0px (13.333333dp)\n" + - "\tfolderChildDrawablePaddingPx: 10.0px (3.8095238dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + + "\tfolderCellWidthPx: 175.0px (66.666664dp)\n" + + "\tfolderCellHeightPx: 205.0px (78.09524dp)\n" + + "\tfolderChildIconSizePx: 131.0px (49.904762dp)\n" + + "\tfolderChildTextSizePx: 34.0px (12.952381dp)\n" + + "\tfolderChildDrawablePaddingPx: 9.0px (3.4285715dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 21.0px (8.0dp)\n" + + "\tfolderTopPadding: 42.0px (16.0dp)\n" + "\tbottomSheetTopPadding: 114.0px (43.42857dp)\n" + "\tallAppsShiftRange: 788.0px (300.1905dp)\n" + "\tallAppsTopPadding: 0.0px (0.0dp)\n" + @@ -1389,14 +1400,15 @@ class DeviceProfileTest : DeviceProfileBaseTest() { "\ticonSizePx: 142.0px (54.095238dp)\n" + "\ticonTextSizePx: 0.0px (0.0dp)\n" + "\ticonDrawablePaddingPx: 0.0px (0.0dp)\n" + - "\tfolderCellWidthPx: 163.0px (62.095238dp)\n" + - "\tfolderCellHeightPx: 192.0px (73.14286dp)\n" + - "\tfolderChildIconSizePx: 123.0px (46.857143dp)\n" + - "\tfolderChildTextSizePx: 32.0px (12.190476dp)\n" + + "\tfolderCellWidthPx: 159.0px (60.57143dp)\n" + + "\tfolderCellHeightPx: 187.0px (71.2381dp)\n" + + "\tfolderChildIconSizePx: 119.0px (45.333332dp)\n" + + "\tfolderChildTextSizePx: 31.0px (11.809524dp)\n" + "\tfolderChildDrawablePaddingPx: 8.0px (3.047619dp)\n" + - "\tfolderCellLayoutBorderSpaceOriginalPx: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Horizontal: 42.0px (16.0dp)\n" + "\tfolderCellLayoutBorderSpacePx Vertical: 42.0px (16.0dp)\n" + + "\tfolderContentPaddingLeftRight: 21.0px (8.0dp)\n" + + "\tfolderTopPadding: 42.0px (16.0dp)\n" + "\tbottomSheetTopPadding: 114.0px (43.42857dp)\n" + "\tallAppsShiftRange: 788.0px (300.1905dp)\n" + "\tallAppsTopPadding: 0.0px (0.0dp)\n" + diff --git a/res/layout/user_folder_icon_normalized.xml b/res/layout/user_folder_icon_normalized.xml index 11eea6072c..337014ace8 100644 --- a/res/layout/user_folder_icon_normalized.xml +++ b/res/layout/user_folder_icon_normalized.xml @@ -30,7 +30,7 @@ - + @@ -193,6 +193,18 @@ + + + + + + + + + + + + @@ -327,6 +339,19 @@ if not specified --> + + + + + + + + + + + + @@ -373,17 +398,6 @@ - - - - - - - - - - - diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 546ee35c17..a9d1127184 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -251,7 +251,7 @@ 6dp 1.14 - 48dp + 56dp 8dp 16dp diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 418df37c29..14a467ad65 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -38,11 +38,13 @@ import android.util.SparseArray; import android.view.Surface; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.DevicePaddings.DevicePadding; import com.android.launcher3.icons.DotRenderer; import com.android.launcher3.icons.IconNormalizer; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.uioverrides.ApiWrapper; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController.Info; @@ -57,6 +59,9 @@ public class DeviceProfile { private static final int DEFAULT_DOT_SIZE = 100; private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f; + public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f); + public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE; + // Ratio of empty space, qsb should take up to appear visually centered. private final float mQsbCenterFactor; @@ -144,7 +149,6 @@ public class DeviceProfile { // Folder content public Point folderCellLayoutBorderSpacePx; - public int folderCellLayoutBorderSpaceOriginalPx; public int folderContentPaddingLeftRight; public int folderContentPaddingTop; @@ -204,7 +208,7 @@ public class DeviceProfile { public int overviewGridSideMargin; // Widgets - public final PointF appWidgetScale = new PointF(1.0f, 1.0f); + private final ViewScaleProvider mViewScaleProvider; // Drop Target public int dropTargetBarSizePx; @@ -240,7 +244,8 @@ public class DeviceProfile { /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */ DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds, SparseArray dotRendererCache, boolean isMultiWindowMode, - boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode) { + boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode, + @NonNull final ViewScaleProvider viewScaleProvider) { this.inv = inv; this.isLandscape = windowBounds.isLandscape(); @@ -321,9 +326,8 @@ public class DeviceProfile { pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics), pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics)); cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx); - folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics); - folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx, - folderCellLayoutBorderSpaceOriginalPx); + folderCellLayoutBorderSpacePx = new Point(pxFromDp(inv.folderBorderSpaces.x, mMetrics), + pxFromDp(inv.folderBorderSpaces.y, mMetrics)); workspacePageIndicatorHeight = res.getDimensionPixelSize( R.dimen.workspace_page_indicator_height); @@ -473,6 +477,8 @@ public class DeviceProfile { flingToDeleteThresholdVelocity = res.getDimensionPixelSize( R.dimen.drag_flingToDeleteMinVelocity); + mViewScaleProvider = viewScaleProvider; + // This is done last, after iconSizePx is calculated above. mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache); mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache); @@ -669,13 +675,18 @@ public class DeviceProfile { .setMultiWindowMode(true) .build(); - profile.hideWorkspaceLabelsIfNotEnoughSpace(); - // We use these scales to measure and layout the widgets using their full invariant profile // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x; float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y; - profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY); + if (appWidgetScaleX != 1 || appWidgetScaleY != 1) { + final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY); + profile = profile.toBuilder(context) + .setViewScaleProvider(i -> p) + .build(); + } + + profile.hideWorkspaceLabelsIfNotEnoughSpace(); return profile; } @@ -919,16 +930,14 @@ public class DeviceProfile { int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); if (isScalableGrid) { - int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2; - int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight; + folderCellWidthPx = pxFromDp(inv.folderCellSize.x, mMetrics, scale); + folderCellHeightPx = pxFromDp(inv.folderCellSize.y, mMetrics, scale); - folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale); - folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale); - - int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale); - folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace); - folderContentPaddingLeftRight = scaledSpace; - folderContentPaddingTop = scaledSpace; + folderCellLayoutBorderSpacePx = new Point( + pxFromDp(inv.folderBorderSpaces.x, mMetrics, scale), + pxFromDp(inv.folderBorderSpaces.y, mMetrics, scale)); + folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x; + folderContentPaddingTop = pxFromDp(inv.folderTopPadding, mMetrics, scale); } else { int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); @@ -1242,6 +1251,19 @@ public class DeviceProfile { + getOverviewActionsClaimedSpaceBelow(); } + /** + * Takes the View and return the scales of width and height depending on the DeviceProfile + * specifications + * + * @param itemInfo The tag of the widget view + * @return A PointF instance with the x set to be the scale of width, and y being the scale of + * height + */ + @NonNull + public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) { + return mViewScaleProvider.getScaleFromItemInfo(itemInfo); + } + /** * @return the bounds for which the open folders should be contained within */ @@ -1391,12 +1413,13 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx)); writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx", folderChildDrawablePaddingPx)); - writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx", - folderCellLayoutBorderSpaceOriginalPx)); writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal", folderCellLayoutBorderSpacePx.x)); writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical", folderCellLayoutBorderSpacePx.y)); + writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight", + folderContentPaddingLeftRight)); + writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop)); writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding)); @@ -1551,6 +1574,22 @@ public class DeviceProfile { } } + /** + * Handler that deals with ItemInfo of the views for the DeviceProfile + */ + @FunctionalInterface + public interface ViewScaleProvider { + /** + * Get the scales from the view + * + * @param itemInfo The tag of the widget view + * @return PointF instance containing the scale information, or null if using the default + * app widget scale of this device profile. + */ + @NonNull + PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo); + } + public static class Builder { private Context mContext; private InvariantDeviceProfile mInv; @@ -1562,6 +1601,7 @@ public class DeviceProfile { private boolean mIsMultiWindowMode = false; private Boolean mTransposeLayoutWithOrientation; private Boolean mIsGestureMode; + private ViewScaleProvider mViewScaleProvider = null; private SparseArray mDotRendererCache; @@ -1601,6 +1641,19 @@ public class DeviceProfile { return this; } + /** + * Set the viewScaleProvider for the builder + * + * @param viewScaleProvider The viewScaleProvider to be set for the + * DeviceProfile + * @return This builder + */ + @NonNull + public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) { + mViewScaleProvider = viewScaleProvider; + return this; + } + public DeviceProfile build() { if (mWindowBounds == null) { throw new IllegalArgumentException("Window bounds not set"); @@ -1614,9 +1667,12 @@ public class DeviceProfile { if (mDotRendererCache == null) { mDotRendererCache = new SparseArray<>(); } + if (mViewScaleProvider == null) { + mViewScaleProvider = DEFAULT_PROVIDER; + } return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache, mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels, - mIsGestureMode); + mIsGestureMode, mViewScaleProvider); } } diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index cf2a3f8474..6a262c3f91 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -127,9 +127,12 @@ public class InvariantDeviceProfile { public PointF[] minCellSize; public PointF[] borderSpaces; - public float folderBorderSpace; public int inlineNavButtonsEndSpacing; + public PointF folderBorderSpaces; + public PointF folderCellSize; + public float folderTopPadding; + public float[] horizontalMargin; public PointF[] allAppsCellSize; @@ -255,8 +258,6 @@ public class InvariantDeviceProfile { COUNT_SIZES); System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0, COUNT_SIZES); - System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0, - COUNT_SIZES); initGrid(context, myInfo, result, deviceType); } @@ -353,7 +354,10 @@ public class InvariantDeviceProfile { minCellSize = displayOption.minCellSize; borderSpaces = displayOption.borderSpaces; - folderBorderSpace = displayOption.folderBorderSpace; + + folderBorderSpaces = displayOption.folderBorderSpaces; + folderCellSize = displayOption.folderCellSize; + folderTopPadding = displayOption.folderTopPadding; horizontalMargin = displayOption.horizontalMargin; @@ -381,7 +385,7 @@ public class InvariantDeviceProfile { devicePaddings = new DevicePaddings(context, devicePaddingId); } - inlineQsb = displayOption.inlineQsb; + inlineQsb = closestProfile.inlineQsb; // If the partner customization apk contains any grid overrides, apply them // Supported overrides: numRows, numColumns, iconSize @@ -717,6 +721,12 @@ public class InvariantDeviceProfile { private static final int DEVICE_CATEGORY_ALL = DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY; + private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0; + private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1; + private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2; + private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3; + private static final int DONT_INLINE_QSB = 0; + public final String name; public final int numRows; public final int numColumns; @@ -733,6 +743,8 @@ public class InvariantDeviceProfile { private final int[] hotseatColumnSpan = new int[COUNT_SIZES]; + private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; + private int inlineNavButtonsEndSpacing; private final String dbFile; @@ -805,6 +817,19 @@ public class InvariantDeviceProfile { && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY) == DEVICE_CATEGORY_MULTI_DISPLAY)); + int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb, + DONT_INLINE_QSB); + inlineQsb[INDEX_DEFAULT] = + (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT; + inlineQsb[INDEX_LANDSCAPE] = + (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE; + inlineQsb[INDEX_TWO_PANEL_PORTRAIT] = + (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT) + == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT; + inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = + (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) + == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; + a.recycle(); extraAttrs = Themes.createValueMap(context, attrs, IntArray.wrap(R.styleable.GridDisplayOption)); @@ -813,22 +838,18 @@ public class InvariantDeviceProfile { @VisibleForTesting static final class DisplayOption { - private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0; - private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1; - private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2; - private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3; - private static final int DONT_INLINE_QSB = 0; - public final GridOption grid; private final float minWidthDps; private final float minHeightDps; private final boolean canBeDefault; - private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; private final PointF[] minCellSize = new PointF[COUNT_SIZES]; - private float folderBorderSpace; + private final PointF folderCellSize; + private final PointF folderBorderSpaces; + private float folderTopPadding; + private final PointF[] borderSpaces = new PointF[COUNT_SIZES]; private final float[] horizontalMargin = new float[COUNT_SIZES]; private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES]; @@ -852,19 +873,6 @@ public class InvariantDeviceProfile { canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false); - int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb, - DONT_INLINE_QSB); - inlineQsb[INDEX_DEFAULT] = - (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT; - inlineQsb[INDEX_LANDSCAPE] = - (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE; - inlineQsb[INDEX_TWO_PANEL_PORTRAIT] = - (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT) - == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT; - inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = - (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) - == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; - float x; float y; @@ -924,7 +932,20 @@ public class InvariantDeviceProfile { borderSpaceTwoPanelLandscape); borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); - folderBorderSpace = borderSpace; + x = a.getFloat(R.styleable.ProfileDisplayOption_folderCellWidth, + minCellSize[INDEX_DEFAULT].x); + y = a.getFloat(R.styleable.ProfileDisplayOption_folderCellHeight, + minCellSize[INDEX_DEFAULT].y); + folderCellSize = new PointF(x, y); + + float folderBorderSpace = a.getFloat(R.styleable.ProfileDisplayOption_folderBorderSpace, + borderSpace); + + x = y = folderBorderSpace; + folderBorderSpaces = new PointF(x, y); + + folderTopPadding = a.getFloat(R.styleable.ProfileDisplayOption_folderTopPadding, + folderBorderSpaces.y); x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth, minCellSize[INDEX_DEFAULT].x); @@ -1097,8 +1118,10 @@ public class InvariantDeviceProfile { allAppsIconSizes[i] = 0; allAppsIconTextSizes[i] = 0; allAppsBorderSpaces[i] = new PointF(); - inlineQsb[i] = false; } + folderBorderSpaces = new PointF(); + folderCellSize = new PointF(); + folderTopPadding = 0f; } private DisplayOption multiply(float w) { @@ -1119,8 +1142,11 @@ public class InvariantDeviceProfile { allAppsBorderSpaces[i].x *= w; allAppsBorderSpaces[i].y *= w; } - - folderBorderSpace *= w; + folderBorderSpaces.x *= w; + folderBorderSpaces.y *= w; + folderCellSize.x *= w; + folderCellSize.y *= w; + folderTopPadding *= w; return this; } @@ -1142,10 +1168,12 @@ public class InvariantDeviceProfile { allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i]; allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x; allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y; - inlineQsb[i] |= p.inlineQsb[i]; } - - folderBorderSpace += p.folderBorderSpace; + folderBorderSpaces.x += p.folderBorderSpaces.x; + folderBorderSpaces.y += p.folderBorderSpaces.y; + folderCellSize.x += p.folderCellSize.x; + folderCellSize.y += p.folderCellSize.y; + folderTopPadding += p.folderTopPadding; return this; } diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index 5583eaeba9..486a68f691 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -25,6 +25,7 @@ import static com.android.launcher3.CellLayout.WORKSPACE; import android.app.WallpaperManager; import android.content.Context; import android.graphics.Point; +import android.graphics.PointF; import android.graphics.Rect; import android.view.MotionEvent; import android.view.View; @@ -32,6 +33,7 @@ import android.view.ViewGroup; import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.folder.FolderIcon; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.NavigableAppWidgetHostView; @@ -109,8 +111,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. if (child instanceof NavigableAppWidgetHostView) { DeviceProfile profile = mActivity.getDeviceProfile(); ((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect); + final PointF appWidgetScale = profile.getAppWidgetScale((ItemInfo) child.getTag()); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, - profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpace, mTempRect); + appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpace, null); @@ -133,8 +136,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. if (child instanceof NavigableAppWidgetHostView) { ((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect); + final PointF appWidgetScale = dp.getAppWidgetScale((ItemInfo) child.getTag()); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, - dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpace, mTempRect); + appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpace, null); @@ -187,8 +191,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. // Scale and center the widget to fit within its cells. DeviceProfile profile = mActivity.getDeviceProfile(); - float scaleX = profile.appWidgetScale.x; - float scaleY = profile.appWidgetScale.y; + final PointF appWidgetScale = profile.getAppWidgetScale((ItemInfo) child.getTag()); + float scaleX = appWidgetScale.x; + float scaleY = appWidgetScale.y; nahv.setScaleToFit(Math.min(scaleX, scaleY)); nahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f, diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 4c9542d5c9..f4a8ce5ff7 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -44,6 +44,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Point; +import android.graphics.PointF; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Handler; @@ -369,7 +370,8 @@ public class Workspace extends PagedView float scale = 1; if (isWidget) { DeviceProfile profile = mLauncher.getDeviceProfile(); - scale = Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y); + final PointF appWidgetScale = profile.getAppWidgetScale(null); + scale = Utilities.shrinkRect(r, appWidgetScale.x, appWidgetScale.y); } size[0] = r.width(); size[1] = r.height(); @@ -2061,20 +2063,11 @@ public class Workspace extends PagedView if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && cell instanceof LauncherAppWidgetHostView) { - final CellLayout cellLayout = dropTargetLayout; + // We post this call so that the widget has a chance to be placed // in its final location - - final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell; - AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo(); - if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE - && !options.isAccessibleDrag) { - onCompleteRunnable = () -> { - if (!isPageInTransition()) { - AppWidgetResizeFrame.showForWidget(hostView, cellLayout); - } - }; - } + onCompleteRunnable = getWidgetResizeFrameRunnable(options, + (LauncherAppWidgetHostView) cell, dropTargetLayout); } mLauncher.getModelWriter().modifyItemInDatabase(info, container, screenId, lp.cellX, lp.cellY, item.spanX, item.spanY); @@ -2095,8 +2088,16 @@ public class Workspace extends PagedView } } else { // When drag is cancelled, reattach content view back to its original parent. - if (mDragInfo.cell instanceof LauncherAppWidgetHostView) { + if (cell instanceof LauncherAppWidgetHostView) { d.dragView.detachContentView(/* reattachToPreviousParent= */ true); + + final CellLayout cellLayout = getParentCellLayoutForView(cell); + boolean pageIsVisible = isVisible(cellLayout); + + if (pageIsVisible) { + onCompleteRunnable = getWidgetResizeFrameRunnable(options, + (LauncherAppWidgetHostView) cell, cellLayout); + } } } @@ -2149,6 +2150,21 @@ public class Workspace extends PagedView } } + @Nullable + private Runnable getWidgetResizeFrameRunnable(DragOptions options, + LauncherAppWidgetHostView hostView, CellLayout cellLayout) { + AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo(); + if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE + && !options.isAccessibleDrag) { + return () -> { + if (!isPageInTransition()) { + AppWidgetResizeFrame.showForWidget(hostView, cellLayout); + } + }; + } + return null; + } + public void onNoCellFound( View dropTargetLayout, ItemInfo itemInfo, @Nullable InstanceId logInstanceId) { int strId = mLauncher.isHotseatLayout(dropTargetLayout) @@ -2884,7 +2900,8 @@ public class Workspace extends PagedView r.top -= widgetPadding.top; r.bottom += widgetPadding.bottom; } - Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y); + PointF appWidgetScale = profile.getAppWidgetScale(null); + Utilities.shrinkRect(r, appWidgetScale.x, appWidgetScale.y); } mTempFXY[0] = r.left; diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index a8546e8448..c1bab544cb 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -20,6 +20,7 @@ import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.makeMeasureSpec; import static android.view.View.VISIBLE; +import static com.android.launcher3.DeviceProfile.DEFAULT_SCALE; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION; import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems; import static com.android.launcher3.model.ModelUtils.getMissingHotseatRanks; @@ -36,6 +37,7 @@ import android.content.ContextWrapper; import android.content.Intent; import android.content.res.TypedArray; import android.graphics.Color; +import android.graphics.PointF; import android.graphics.Rect; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; @@ -55,6 +57,7 @@ import android.view.WindowInsets; import android.view.WindowManager; import android.widget.TextClock; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.launcher3.BubbleTextView; @@ -100,6 +103,7 @@ import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; import com.android.launcher3.widget.LocalColorExtractor; import com.android.launcher3.widget.NavigableAppWidgetHostView; import com.android.launcher3.widget.custom.CustomWidgetManager; +import com.android.launcher3.widget.util.WidgetSizes; import java.util.ArrayList; import java.util.Collections; @@ -173,6 +177,7 @@ public class LauncherPreviewRenderer extends ContextWrapper private final Context mContext; private final InvariantDeviceProfile mIdp; private final DeviceProfile mDp; + private final DeviceProfile mDpOrig; private final Rect mInsets; private final WorkspaceItemInfo mWorkspaceItemInfo; private final LayoutInflater mHomeElementInflater; @@ -192,7 +197,16 @@ public class LauncherPreviewRenderer extends ContextWrapper mUiHandler = new Handler(Looper.getMainLooper()); mContext = context; mIdp = idp; - mDp = idp.getDeviceProfile(context).copy(context); + mDp = idp.getDeviceProfile(context).toBuilder(context).setViewScaleProvider( + this::getAppWidgetScale).build(); + if (context instanceof PreviewContext) { + Context tempContext = ((PreviewContext) context).getBaseContext(); + mDpOrig = new InvariantDeviceProfile(tempContext, InvariantDeviceProfile + .getCurrentGridName(tempContext)).getDeviceProfile(tempContext) + .copy(tempContext); + } else { + mDpOrig = mDp; + } WindowInsets currentWindowInsets = context.getSystemService(WindowManager.class) .getCurrentWindowMetrics().getWindowInsets(); @@ -390,6 +404,41 @@ public class LauncherPreviewRenderer extends ContextWrapper addInScreenFromBind(view, info); } + @NonNull + private PointF getAppWidgetScale(@Nullable ItemInfo itemInfo) { + if (!(itemInfo instanceof LauncherAppWidgetInfo)) { + return DEFAULT_SCALE; + } + LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) itemInfo; + final Size launcherWidgetSize = mLauncherWidgetSpanInfo.get(info.appWidgetId); + if (launcherWidgetSize == null) { + return DEFAULT_SCALE; + } + final Size origSize = WidgetSizes.getWidgetSizePx(mDpOrig, + launcherWidgetSize.getWidth(), launcherWidgetSize.getHeight()); + final Size newSize = WidgetSizes.getWidgetSizePx(mDp, info.spanX, info.spanY); + final Rect previewInset = new Rect(); + final Rect origInset = new Rect(); + // When the setup() is called for the LayoutParams, insets are added to the width + // and height of the view. This is not accounted for in WidgetSizes and is handled + // here. + if (mDp.shouldInsetWidgets()) { + previewInset.set(mDp.inv.defaultWidgetPadding); + } else { + previewInset.setEmpty(); + } + if (mDpOrig.shouldInsetWidgets()) { + origInset.set(mDpOrig.inv.defaultWidgetPadding); + } else { + origInset.setEmpty(); + } + + return new PointF((float) newSize.getWidth() / (origSize.getWidth() + + origInset.left + origInset.right), + (float) newSize.getHeight() / (origSize.getHeight() + + origInset.top + origInset.bottom)); + } + private void inflateAndAddPredictedIcon(WorkspaceItemInfo info) { CellLayout screen = mWorkspaceScreens.get(info.screenId); View view = PredictedAppIconInflater.inflate(mHomeElementInflater, screen, info); diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java index 5eac01ef62..c8455b8a2b 100644 --- a/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java +++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragLayer.java @@ -38,12 +38,14 @@ import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.popup.PopupDataProvider; +import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.util.ShortcutUtil; import com.android.launcher3.util.TouchController; import com.android.launcher3.views.BaseDragLayer; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; /** * DragLayer for Secondary launcher @@ -194,15 +196,21 @@ public class SecondaryDragLayer extends BaseDragLayer return false; } + List systemShortcuts = new ArrayList<>(); + + // Hide redundant pin shortcut for app drawer icons if drag-n-drop is enabled. + if (!FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN.get() || !mActivity.isAppDrawerShown()) { + systemShortcuts.add(mPinnedAppsAdapter.getSystemShortcut(item, v)); + } + systemShortcuts.add(APP_INFO.getShortcut(mActivity, item, v)); + final PopupContainerWithArrow container = (PopupContainerWithArrow) mActivity.getLayoutInflater().inflate( R.layout.popup_container, mActivity.getDragLayer(), false); container.populateAndShow((BubbleTextView) v, popupDataProvider.getShortcutCountForItem(item), - Collections.emptyList(), - Arrays.asList(mPinnedAppsAdapter.getSystemShortcut(item, v), - APP_INFO.getShortcut(mActivity, item, v))); + Collections.emptyList(), systemShortcuts); container.requestFocus(); if (!FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN.get() || !mActivity.isAppDrawerShown()) { diff --git a/src/com/android/launcher3/util/ViewCapture.java b/src/com/android/launcher3/util/ViewCapture.java index cf4e84a84b..58c8269f97 100644 --- a/src/com/android/launcher3/util/ViewCapture.java +++ b/src/com/android/launcher3/util/ViewCapture.java @@ -240,6 +240,7 @@ public class ViewCapture implements OnDrawListener { public float translateX, translateY; public float scaleX, scaleY; public float alpha; + public float elevation; public int visibility; public boolean willNotDraw; @@ -271,6 +272,7 @@ public class ViewCapture implements OnDrawListener { visibility = view.getVisibility(); willNotDraw = view.willNotDraw(); + elevation = view.getElevation(); } /** @@ -303,6 +305,7 @@ public class ViewCapture implements OnDrawListener { .setAlpha(alpha) .setVisibility(visibility) .setWillNotDraw(willNotDraw) + .setElevation(elevation) .setClipChildren(clipChildren); ViewPropertyRef result = next; diff --git a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt index cf6be7fb58..2c1cbdf0ce 100644 --- a/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt +++ b/tests/src/com/android/launcher3/DeviceProfileBaseTest.kt @@ -20,6 +20,7 @@ import android.graphics.PointF import android.graphics.Rect import android.util.SparseArray import androidx.test.core.app.ApplicationProvider +import com.android.launcher3.DeviceProfile.DEFAULT_PROVIDER; import com.android.launcher3.util.DisplayController.Info import com.android.launcher3.util.WindowBounds import org.junit.Before @@ -61,7 +62,8 @@ abstract class DeviceProfileBaseTest { isMultiWindowMode, transposeLayoutWithOrientation, useTwoPanels, - isGestureMode + isGestureMode, + DEFAULT_PROVIDER ) protected fun initializeVarsForPhone(isGestureMode: Boolean = true, @@ -94,8 +96,6 @@ abstract class DeviceProfileBaseTest { numColumns = 4 numSearchContainerColumns = 4 - numFolderRows = 3 - numFolderColumns = 3 iconSize = floatArrayOf(60f, 54f, 60f, 60f) iconTextSize = FloatArray(4) { 14f } deviceType = InvariantDeviceProfile.TYPE_PHONE @@ -113,7 +113,14 @@ abstract class DeviceProfileBaseTest { PointF(16f, 16f), PointF(16f, 16f) ).toTypedArray() - folderBorderSpace = 16f + + numFolderRows = 3 + numFolderColumns = 3 + folderBorderSpaces = PointF(16f, 16f) + folderTopPadding = 24f + folderCellSize = PointF(80f, 94f) + + inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_4_5 horizontalMargin = FloatArray(4) { 22f } @@ -197,6 +204,13 @@ abstract class DeviceProfileBaseTest { PointF(16f, 64f), PointF(16f, 64f) ).toTypedArray() + + numFolderRows = 3 + numFolderColumns = 3 + folderBorderSpaces = PointF(16f, 16f) + folderTopPadding = 24f + folderCellSize = PointF(120f, 104f) + inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_6_5 horizontalMargin = floatArrayOf(54f, 120f, 54f, 54f) @@ -271,8 +285,6 @@ abstract class DeviceProfileBaseTest { numColumns = 4 numSearchContainerColumns = 4 - numFolderRows = 3 - numFolderColumns = 4 iconSize = floatArrayOf(60f, 52f, 52f, 60f) iconTextSize = floatArrayOf(14f, 14f, 12f, 14f) deviceType = InvariantDeviceProfile.TYPE_MULTI_DISPLAY @@ -290,7 +302,13 @@ abstract class DeviceProfileBaseTest { PointF(16f, 20f), PointF(20f, 20f) ).toTypedArray() - folderBorderSpace = 16f + + numFolderRows = 3 + numFolderColumns = 3 + folderBorderSpaces = PointF(16f, 16f) + folderTopPadding = 24f + folderCellSize = PointF(80f, 94f) + inlineNavButtonsEndSpacing = R.dimen.taskbar_button_margin_4_4 horizontalMargin = floatArrayOf(21.5f, 21.5f, 22.5f, 30.5f) diff --git a/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java b/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java index 93fa705880..082e243694 100644 --- a/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java +++ b/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java @@ -15,39 +15,273 @@ */ package com.android.launcher3.secondarydisplay; -import static androidx.test.core.app.ActivityScenario.launch; +import static android.content.Context.MODE_PRIVATE; +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static android.view.MotionEvent.ACTION_DOWN; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Point; +import android.os.SystemClock; +import android.view.MotionEvent; +import android.widget.TextView; -import androidx.test.core.app.ActivityScenario; -import androidx.test.espresso.intent.Intents; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.MediumTest; +import androidx.test.filters.LargeTest; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiObject2; +import androidx.test.uiautomator.Until; + +import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.tapl.LauncherInstrumentation; +import com.android.launcher3.ui.AbstractLauncherUiTest; +import com.android.launcher3.util.LauncherModelHelper; import org.junit.After; -import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; /** - * Tests for {@link SecondaryDisplayLauncher} + * Tests for {@link SecondaryDisplayLauncher}. + * TODO (b/242776943): Remove anti-patterns & migrate prediction row tests to Quickstep directory */ -@MediumTest +@LargeTest @RunWith(AndroidJUnit4.class) -public class SecondaryDisplayLauncherTest { +public final class SecondaryDisplayLauncherTest extends AbstractLauncherUiTest { + private static final int WAIT_TIME_MS = 5000; + private static final int LONG_PRESS_DURATION_MS = 1000; + private static final int DRAG_TIME_MS = 160; - @Before - public void setUp() { - Intents.init(); + private static final String PINNED_APPS_KEY = "pinned_apps"; + + // Variables required to coordinate drag steps. + private Point mStartPoint; + private Point mEndPoint; + private long mDownTime; + + @Override + public void setUp() throws Exception { + super.setUp(); + setDragNDropFlag(true); } @After public void tearDown() { - Intents.release(); + mTargetContext.getSharedPreferences(PINNED_APPS_KEY, MODE_PRIVATE) + .edit().clear().commit(); } @Test - public void testAllAppsListOpens() { - ActivityScenario launcher = - launch(SecondaryDisplayLauncher.class); - launcher.onActivity(l -> l.showAppDrawer(true)); + @Ignore + public void initializeSecondaryDisplayLauncher_allAppsButtonVisible() { + assertThat(findObjectByResourceName("all_apps_button")).isNotNull(); + } + + @Test + @Ignore + public void allAppsButtonTap_opensAppDrawer() { + openAppDrawer(); + assertThat(findObjectByResourceName("search_container_all_apps")).isNotNull(); + } + + @Test + @Ignore("Launcher3 without quickstep doesn't have a predictions row.") + public void appDrawerOpened_predictionRowAppDividerVisible() { + openAppDrawer(); + assertThat(findObjectByResourceName("apps_divider_view")).isNotNull(); + } + + @Test + @Ignore + public void dragNDropDisabled_pinIconAddsToWorkspace() { + setDragNDropFlag(false); + openAppDrawer(); + UiObject2 app = findDescendantByResourceName( + findObjectByResourceName("apps_list_view"), "icon"); + app.click(LONG_PRESS_DURATION_MS); + UiObject2 popupContainer = findObjectByResourceName("popup_container"); + assertThat(popupContainer).isNotNull(); + UiObject2 pinIcon = findDescendantByTextOrDesc(popupContainer, "Add to home screen"); + assertThat(pinIcon).isNotNull(); + pinIcon.click(); + String appName = app.getContentDescription(); + assertThat(findAppInWorkspace(appName)).isNotNull(); + } + + @Test + @Ignore + public void pressBackFromAllApps_popupMenuOpen_returnsToWorkspace() { + openAppDrawer(); + assertThat(findObjectByResourceName("search_container_all_apps")).isNotNull(); + + findDescendantByResourceName(findObjectByResourceName("apps_list_view"), "icon") + .click(LONG_PRESS_DURATION_MS); + assertThat(findObjectByResourceName("popup_container")).isNotNull(); + + // First back press should close only popup menu. + mDevice.pressBack(); + assertThat(findObjectByResourceName("search_container_all_apps")).isNotNull(); + assertThat(findObjectByResourceName("popup_container")).isNull(); + + // Second back press should close app drawer. + mDevice.pressBack(); + assertThat(findObjectByResourceName("popup_container")).isNull(); + assertThat(findObjectByResourceName("search_container_all_apps")).isNull(); + } + + @Test + @Ignore("Launcher3 without quickstep doesn't have a predictions row.") + public void dragNDropFromPredictionsRow_pinToGrid() { + openAppDrawer(); + assertThat(findObjectByResourceName("prediction_row")).isNotNull(); + String appName = startDragFromPredictionRow(); + moveAppToCenterOfScreen(); + dropApp(); + + // Ensure app was added. + assertThat(findAppInWorkspace(appName)).isNotNull(); + } + + @Test + @Ignore + public void dragNDropFromAppDrawer_pinToGrid() { + openAppDrawer(); + String draggedAppName = startDragFromAllApps(); + moveAppToCenterOfScreen(); + dropApp(); + + // Ensure app was added. + assertThat(findAppInWorkspace(draggedAppName)).isNotNull(); + } + + @Test + @Ignore + public void tapRemoveButton_unpinApp() { + openAppDrawer(); + String draggedAppName = startDragFromAllApps(); + moveAppToCenterOfScreen(); + dropApp(); + removeAppByName(draggedAppName); + assertThat(findAppInWorkspace(draggedAppName)).isNull(); + } + + private void openAppDrawer() { + UiObject2 allAppsButton = findObjectByResourceName("all_apps_button"); + assertThat(allAppsButton).isNotNull(); + allAppsButton.click(); + } + + private String startDragFromAllApps() { + // Find app from app drawer. + UiObject2 allApps = findObjectByResourceName("apps_list_view"); + assertThat(allApps).isNotNull(); + UiObject2 icon = findDescendantByResourceName(allApps, "icon"); + assertThat(icon).isNotNull(); + String appName = icon.getContentDescription(); + + // Start drag action. + mDownTime = SystemClock.uptimeMillis(); + mStartPoint = icon.getVisibleCenter(); + mEndPoint = new Point(mStartPoint.x, mStartPoint.y); + mLauncher.sendPointer(mDownTime, mDownTime, ACTION_DOWN, mStartPoint, + LauncherInstrumentation.GestureScope.INSIDE); + assertThat(findObjectByResourceName("popup_container")).isNotNull(); + return appName; + } + + private String startDragFromPredictionRow() { + // Find app from predictions. + UiObject2 predictionRow = findObjectByResourceName("prediction_row"); + assertThat(predictionRow).isNotNull(); + + UiObject2 icon = findDescendantByResourceName(predictionRow, "icon"); + assertThat(icon).isNotNull(); + + String appName = icon.getContentDescription(); + UiObject2 app = findDescendantByAppName(predictionRow, appName); + assertThat(app).isNotNull(); + + // Start drag action. + mDownTime = SystemClock.uptimeMillis(); + mStartPoint = icon.getVisibleCenter(); + mEndPoint = new Point(mStartPoint.x, mStartPoint.y); + mLauncher.sendPointer(mDownTime, mDownTime, ACTION_DOWN, mStartPoint, + LauncherInstrumentation.GestureScope.INSIDE); + assertThat(findObjectByResourceName("popup_container")).isNotNull(); + return appName; + } + + private void moveAppToCenterOfScreen() { + mEndPoint.set(mDevice.getDisplayWidth() / 2, mDevice.getDisplayHeight() / 2); + mLauncher.movePointer(mDownTime, SystemClock.uptimeMillis(), DRAG_TIME_MS, true, + mStartPoint, mEndPoint, LauncherInstrumentation.GestureScope.INSIDE); + } + + private void dropApp() { + mLauncher.sendPointer(mDownTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, + mEndPoint, LauncherInstrumentation.GestureScope.INSIDE); + } + + private void removeAppByName(String appName) { + // Find app within home screen. + UiObject2 app = findDescendantByAppName(findObjectByResourceName("workspace_grid"), + appName); + if (app == null) return; + + // Open app's popup container. + app.click(LONG_PRESS_DURATION_MS); + UiObject2 popupContainer = findObjectByResourceName("popup_container"); + assertThat(popupContainer).isNotNull(); + + // Grab & click remove button. + UiObject2 removeButton = findDescendantByTextOrDesc(popupContainer, "Remove"); + assertThat(removeButton).isNotNull(); + removeButton.click(); + } + + private UiObject2 findAppInWorkspace(String appName) { + UiObject2 workspace = findObjectByResourceName("workspace_grid"); + return findDescendantByAppName(workspace, appName); + } + + private UiObject2 findObjectByResourceName(String resourceName) { + return mDevice.wait(Until.findObject(By.res(mTargetPackage, resourceName)), WAIT_TIME_MS); + } + + private UiObject2 findDescendantByResourceName(UiObject2 outerObject, + String resourceName) { + assertThat(outerObject).isNotNull(); + return outerObject.findObject(By.res(mTargetPackage, resourceName)); + } + + private UiObject2 findDescendantByAppName(UiObject2 outerObject, String appName) { + assertThat(outerObject).isNotNull(); + return outerObject.findObject(By.clazz(TextView.class).text(appName) + .pkg(mDevice.getLauncherPackageName())); + } + + private UiObject2 findDescendantByTextOrDesc(UiObject2 outerObject, String content) { + assertThat(outerObject).isNotNull(); + UiObject2 innerObject = outerObject.findObject(By.desc(content)); + if (innerObject == null) innerObject = outerObject.findObject(By.text(content)); + return innerObject; + } + + private void startSecondaryDisplayActivity() { + mTargetContext.startActivity(( + new Intent(mTargetContext, SecondaryDisplayLauncher.class).addFlags( + FLAG_ACTIVITY_NEW_TASK))); + } + + private void setDragNDropFlag(Boolean status) { + Context context = new LauncherModelHelper().sandboxContext; + context.getSharedPreferences(FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE).edit() + .putBoolean(FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN.key, status) + .commit(); + FeatureFlags.initialize(context); + startSecondaryDisplayActivity(); } }