diff --git a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java index 3757cd9a92..27a748d3f2 100644 --- a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java +++ b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java @@ -144,7 +144,6 @@ public final class DigitalWellBeingToast { public void initialize(Task task) { mTask = task; - THREAD_POOL_EXECUTOR.execute(() -> { final AppUsageLimit usageLimit = mLauncherApps.getAppUsageLimit( task.getTopComponent().getPackageName(), @@ -321,7 +320,7 @@ public final class DigitalWellBeingToast { mTaskView.getThumbnail().getLayoutParams()).bottomMargin; PagedOrientationHandler orientationHandler = mTaskView.getPagedOrientationHandler(); Pair translations = orientationHandler - .setDwbLayoutParamsAndGetTranslations(mTaskView.getMeasuredWidth(), + .getDwbLayoutTranslations(mTaskView.getMeasuredWidth(), mTaskView.getMeasuredHeight(), mStagedSplitBounds, deviceProfile, mTaskView.getThumbnails(), mTask.key.id, mBanner); mSplitOffsetTranslationX = translations.first; diff --git a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java index 3ddec26360..af9f818e4e 100644 --- a/quickstep/src/com/android/quickstep/views/GroupedTaskView.java +++ b/quickstep/src/com/android/quickstep/views/GroupedTaskView.java @@ -242,6 +242,7 @@ public class GroupedTaskView extends TaskView { mIconView2.setDrawableSize(iconDrawableSize, iconDrawableSize); mIconView2.setRotation(getPagedOrientationHandler().getDegreesRotated()); updateIconPlacement(); + updateSecondaryDwbPlacement(); } private void updateIconPlacement() { @@ -258,6 +259,13 @@ public class GroupedTaskView extends TaskView { isRtl, deviceProfile, mSplitBoundsConfig); } + private void updateSecondaryDwbPlacement() { + if (mSecondaryTask == null) { + return; + } + mDigitalWellBeingToast2.initialize(mSecondaryTask); + } + @Override protected void updateSnapshotRadius() { super.updateSnapshotRadius(); diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java index e26bf73d27..cdb8082da7 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/src/com/android/quickstep/views/TaskView.java @@ -897,6 +897,7 @@ public class TaskView extends FrameLayout implements Reusable { LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams(); orientationHandler.setIconAndSnapshotParams(mIconView, taskIconMargin, taskIconHeight, snapshotParams, isRtl); + updateDwbPlacement(); mSnapshotView.setLayoutParams(snapshotParams); iconParams.width = iconParams.height = taskIconHeight; mIconView.setLayoutParams(iconParams); @@ -909,6 +910,10 @@ public class TaskView extends FrameLayout implements Reusable { mSnapshotView.getTaskOverlay().updateOrientationState(orientationState); } + private void updateDwbPlacement() { + mDigitalWellBeingToast.initialize(mTask); + } + /** * Returns whether the task is part of overview grid and not being focused. */ diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java index a6c9c4d005..4a55d2e5b1 100644 --- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java @@ -310,9 +310,10 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { } @Override - public Pair setDwbLayoutParamsAndGetTranslations(int taskViewWidth, + public Pair getDwbLayoutTranslations(int taskViewWidth, int taskViewHeight, StagedSplitBounds splitBounds, DeviceProfile deviceProfile, View[] thumbnailViews, int desiredTaskId, View banner) { + boolean isRtl = banner.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; float translationX = 0; float translationY = 0; FrameLayout.LayoutParams bannerParams = (FrameLayout.LayoutParams) banner.getLayoutParams(); @@ -323,7 +324,7 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { FrameLayout.LayoutParams snapshotParams = (FrameLayout.LayoutParams) thumbnailViews[0] .getLayoutParams(); - bannerParams.gravity = TOP | START; + bannerParams.gravity = TOP | (isRtl ? END : START); if (splitBounds == null) { // Single, fullscreen case bannerParams.width = taskViewHeight - snapshotParams.topMargin; @@ -339,9 +340,11 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { // Set translations if (desiredTaskId == splitBounds.rightBottomTaskId) { - translationY = (snapshotParams.topMargin + taskViewHeight) - * (splitBounds.leftTaskPercent) + - (taskViewHeight * splitBounds.dividerWidthPercent); + float topLeftTaskPlusDividerPercent = splitBounds.appsStackedVertically + ? (splitBounds.topTaskPercent + splitBounds.dividerHeightPercent) + : (splitBounds.leftTaskPercent + splitBounds.dividerWidthPercent); + translationY = snapshotParams.topMargin + + ((taskViewHeight - snapshotParams.topMargin) * topLeftTaskPlusDividerPercent); } if (desiredTaskId == splitBounds.leftTopTaskId) { translationY = snapshotParams.topMargin; @@ -440,7 +443,9 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { StagedSplitBounds splitBoundsConfig, DeviceProfile dp) { int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx; int totalThumbnailHeight = parentHeight - spaceAboveSnapshot; - int dividerBar = splitBoundsConfig.visualDividerBounds.width(); + int dividerBar = splitBoundsConfig.appsStackedVertically + ? splitBoundsConfig.visualDividerBounds.height() + : splitBoundsConfig.visualDividerBounds.width(); int primarySnapshotHeight; int primarySnapshotWidth; int secondarySnapshotHeight; diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java index 19c4639f1d..923dcc6d01 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -191,7 +191,12 @@ public interface PagedOrientationHandler { */ PointF getAdditionalInsetForTaskMenu(float margin); - Pair setDwbLayoutParamsAndGetTranslations(int taskViewWidth, + /** + * Calculates the position where a Digital Wellbeing Banner should be placed on its parent + * TaskView. + * @return A Pair of Floats representing the proper x and y translations. + */ + Pair getDwbLayoutTranslations(int taskViewWidth, int taskViewHeight, StagedSplitBounds splitBounds, DeviceProfile deviceProfile, View[] thumbnailViews, int desiredTaskId, View banner); diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java index 01aea05366..a308182ebe 100644 --- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java +++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java @@ -324,7 +324,7 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { } @Override - public Pair setDwbLayoutParamsAndGetTranslations(int taskViewWidth, + public Pair getDwbLayoutTranslations(int taskViewWidth, int taskViewHeight, StagedSplitBounds splitBounds, DeviceProfile deviceProfile, View[] thumbnailViews, int desiredTaskId, View banner) { float translationX = 0; @@ -360,8 +360,11 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { FrameLayout.LayoutParams snapshotParams = (FrameLayout.LayoutParams) thumbnailViews[0] .getLayoutParams(); + float bottomRightTaskPlusDividerPercent = splitBounds.appsStackedVertically + ? (1f - splitBounds.topTaskPercent) + : (1f - splitBounds.leftTaskPercent); translationY = -((taskViewHeight - snapshotParams.topMargin) - * (1f - splitBounds.topTaskPercent)); + * bottomRightTaskPlusDividerPercent); } } return new Pair<>(translationX, translationY); diff --git a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java index 80a722947c..6dc0c9af42 100644 --- a/src/com/android/launcher3/touch/SeascapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/SeascapePagedViewHandler.java @@ -106,21 +106,25 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { return new PointF(-margin, margin); } + + @Override - public Pair setDwbLayoutParamsAndGetTranslations(int taskViewWidth, + public Pair getDwbLayoutTranslations(int taskViewWidth, int taskViewHeight, StagedSplitBounds splitBounds, DeviceProfile deviceProfile, View[] thumbnailViews, int desiredTaskId, View banner) { + boolean isRtl = banner.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; float translationX = 0; float translationY = 0; FrameLayout.LayoutParams bannerParams = (FrameLayout.LayoutParams) banner.getLayoutParams(); banner.setPivotX(0); banner.setPivotY(0); banner.setRotation(getDegreesRotated()); + translationX = taskViewWidth - banner.getHeight(); FrameLayout.LayoutParams snapshotParams = (FrameLayout.LayoutParams) thumbnailViews[0] .getLayoutParams(); - bannerParams.gravity = BOTTOM | END; - translationX = taskViewWidth - banner.getHeight(); + bannerParams.gravity = BOTTOM | (isRtl ? END : START); + if (splitBounds == null) { // Single, fullscreen case bannerParams.width = taskViewHeight - snapshotParams.topMargin; @@ -130,19 +134,22 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler { // Set correct width if (desiredTaskId == splitBounds.leftTopTaskId) { - bannerParams.width = thumbnailViews[1].getMeasuredHeight(); - } else { bannerParams.width = thumbnailViews[0].getMeasuredHeight(); + } else { + bannerParams.width = thumbnailViews[1].getMeasuredHeight(); } // Set translations if (desiredTaskId == splitBounds.rightBottomTaskId) { - translationY = -(taskViewHeight - snapshotParams.topMargin) - * (1f - splitBounds.leftTaskPercent) - + banner.getHeight(); + translationY = banner.getHeight(); } if (desiredTaskId == splitBounds.leftTopTaskId) { - translationY = banner.getHeight(); + float bottomRightTaskPlusDividerPercent = splitBounds.appsStackedVertically + ? (1f - splitBounds.topTaskPercent) + : (1f - splitBounds.leftTaskPercent); + translationY = banner.getHeight() + - ((taskViewHeight - snapshotParams.topMargin) + * bottomRightTaskPlusDividerPercent); } return new Pair<>(translationX, translationY); }