From 43c79704ed5f82e5c7d4b7176a56301c53fad3fa Mon Sep 17 00:00:00 2001 From: Jeremy Sim Date: Fri, 8 Apr 2022 17:48:08 -0700 Subject: [PATCH] Fix placement bug with split staging icon in RtL Fixes a bug where switching the phone to RtL caused Overview's split staging icon to be placed incorrectly. The bug was caused by the fact that FrameLayout margins were not working consistently in RtL. This may be another bug; more investigation required (b/201920967). This fix makes it so that the icon is positioned using setX and setY rather than margins. Fixes: 227372971 Test: Manual Change-Id: I6e5371d20e8e2e4e6f41ba93d0dfa36ed085c103 --- .../quickstep/views/FloatingTaskView.java | 4 +--- .../touch/LandscapePagedViewHandler.java | 11 +++++----- .../touch/PagedOrientationHandler.java | 4 ++-- .../touch/PortraitPagedViewHandler.java | 22 +++++++++---------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java index c13ab02a56..54420de6cb 100644 --- a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java +++ b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java @@ -239,12 +239,10 @@ public class FloatingTaskView extends FrameLayout { * offscreen). */ void centerIconView(IconView iconView, float onScreenRectCenterX, float onScreenRectCenterY) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) iconView.getLayoutParams(); - mOrientationHandler.updateStagedSplitIconParams(params, onScreenRectCenterX, + mOrientationHandler.updateStagedSplitIconParams(iconView, onScreenRectCenterX, onScreenRectCenterY, mFullscreenParams.mScaleX, mFullscreenParams.mScaleY, iconView.getDrawableWidth(), iconView.getDrawableHeight(), mActivity.getDeviceProfile(), mStagePosition); - iconView.setLayoutParams(params); } private static class SplitOverlayProperties { diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java index 88a4d66273..27f7e54ae0 100644 --- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java +++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java @@ -413,16 +413,15 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler { } @Override - public void updateStagedSplitIconParams(FrameLayout.LayoutParams out, float onScreenRectCenterX, + public void updateStagedSplitIconParams(View out, float onScreenRectCenterX, float onScreenRectCenterY, float fullscreenScaleX, float fullscreenScaleY, int drawableWidth, int drawableHeight, DeviceProfile dp, @StagePosition int stagePosition) { float inset = dp.getInsets().top; - out.leftMargin = Math.round(onScreenRectCenterX / fullscreenScaleX - - 1.0f * drawableWidth / 2); - out.topMargin = Math.round((onScreenRectCenterY + (inset / 2f)) / fullscreenScaleY - - 1.0f * drawableHeight / 2); - + out.setX(Math.round(onScreenRectCenterX / fullscreenScaleX + - 1.0f * drawableWidth / 2)); + out.setY(Math.round((onScreenRectCenterY + (inset / 2f)) / fullscreenScaleY + - 1.0f * drawableHeight / 2)); } @Override diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java index 510a728765..e34e19576f 100644 --- a/src/com/android/launcher3/touch/PagedOrientationHandler.java +++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java @@ -117,7 +117,7 @@ public interface PagedOrientationHandler { /** * Centers an icon in the split staging area, accounting for insets. - * @param out The LayoutParams of the icon that needs to be centered. + * @param out The icon that needs to be centered. * @param onScreenRectCenterX The x-center of the on-screen staging area (most of the Rect is * offscreen). * @param onScreenRectCenterY The y-center of the on-screen staging area (most of the Rect is @@ -129,7 +129,7 @@ public interface PagedOrientationHandler { * @param dp The device profile, used to report rotation and hardware insets. * @param stagePosition 0 if the staging area is pinned to top/left, 1 for bottom/right. */ - void updateStagedSplitIconParams(FrameLayout.LayoutParams out, float onScreenRectCenterX, + void updateStagedSplitIconParams(View out, float onScreenRectCenterX, float onScreenRectCenterY, float fullscreenScaleX, float fullscreenScaleY, int drawableWidth, int drawableHeight, DeviceProfile dp, @StagePosition int stagePosition); diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java index d88656c9f0..132b28abab 100644 --- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java +++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java @@ -487,29 +487,29 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler { } @Override - public void updateStagedSplitIconParams(FrameLayout.LayoutParams out, float onScreenRectCenterX, + public void updateStagedSplitIconParams(View out, float onScreenRectCenterX, float onScreenRectCenterY, float fullscreenScaleX, float fullscreenScaleY, int drawableWidth, int drawableHeight, DeviceProfile dp, @StagePosition int stagePosition) { boolean pinToRight = stagePosition == STAGE_POSITION_BOTTOM_OR_RIGHT; if (!dp.isLandscape) { float inset = dp.getInsets().top; - out.leftMargin = Math.round(onScreenRectCenterX / fullscreenScaleX - - 1.0f * drawableWidth / 2); - out.topMargin = Math.round((onScreenRectCenterY + (inset / 2f)) / fullscreenScaleY - - 1.0f * drawableHeight / 2); + out.setX(Math.round(onScreenRectCenterX / fullscreenScaleX + - 1.0f * drawableWidth / 2)); + out.setY(Math.round((onScreenRectCenterY + (inset / 2f)) / fullscreenScaleY + - 1.0f * drawableHeight / 2)); } else { if (pinToRight) { float inset = dp.getInsets().right; - out.leftMargin = Math.round((onScreenRectCenterX - (inset / 2f)) / fullscreenScaleX - - 1.0f * drawableWidth / 2); + out.setX(Math.round((onScreenRectCenterX - (inset / 2f)) / fullscreenScaleX + - 1.0f * drawableWidth / 2)); } else { float inset = dp.getInsets().left; - out.leftMargin = Math.round((onScreenRectCenterX + (inset / 2f)) / fullscreenScaleX - - 1.0f * drawableWidth / 2); + out.setX(Math.round((onScreenRectCenterX + (inset / 2f)) / fullscreenScaleX + - 1.0f * drawableWidth / 2)); } - out.topMargin = Math.round(onScreenRectCenterY / fullscreenScaleY - - 1.0f * drawableHeight / 2); + out.setY(Math.round(onScreenRectCenterY / fullscreenScaleY + - 1.0f * drawableHeight / 2)); } }