Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56a382bf authored by Jeremy Sim's avatar Jeremy Sim
Browse files

Fix drag zone translations for offscreen apps

Adds a translateX and translateY to the visual drop zones for splitscreen, in cases where the split layout extends offscreen to the left or top. Without this, the drag zones' LinearLayout follows display bounds, so they are not aligned with the actual app bounds.

I opted to use translation rather than mess with R.layout.global_drop_target, since these zones are only visual (the actual drop target follows app bounds correctly).

Fixes: 391428468
Flag: com.android.wm.shell.enable_flexible_two_app_split
Test: Visually correct when dragging icons over 10:90, 90:10, 50:50, and single app layouts
Change-Id: I58566f89507e9e4c71147211b60989ca75e79a57
parent f4f8f15f
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -413,6 +413,8 @@ public class DragLayout extends LinearLayout
    }

    private void updateDropZoneSizesForSingleTask() {
        resetDropZoneTranslations();

        final LinearLayout.LayoutParams dropZoneView1 =
                (LayoutParams) mDropZoneView1.getLayoutParams();
        final LinearLayout.LayoutParams dropZoneView2 =
@@ -427,6 +429,19 @@ public class DragLayout extends LinearLayout
        mDropZoneView2.setLayoutParams(dropZoneView2);
    }

    /** Zeroes out translationX and translationY on all drop zone views. */
    void resetDropZoneTranslations() {
        setDropZoneTranslations(0, 0);
    }

    /** Sets translationX and translationY on all drop zone views. */
    void setDropZoneTranslations(int x, int y) {
        mDropZoneView1.setTranslationX(x);
        mDropZoneView1.setTranslationY(y);
        mDropZoneView2.setTranslationX(x);
        mDropZoneView2.setTranslationY(y);
    }

    /**
     * Sets the size of the two drop zones based on the provided bounds. The divider sits between
     * the views and its size is included in the calculations.
@@ -435,6 +450,15 @@ public class DragLayout extends LinearLayout
     * @param bounds2 bounds to apply to the second dropzone view, null if split in half.
     */
    private void updateDropZoneSizes(Rect bounds1, Rect bounds2) {
        if (bounds1 == null || bounds2 == null) {
            // We're entering 50:50 split screen from a single app, no need for any translations.
            resetDropZoneTranslations();
        } else {
            // We're already in split, so align our drop zones to match the left/top app edge. This
            // is necessary because the left/top app can be offscreen.
            setDropZoneTranslations(bounds1.left, bounds1.top);
        }

        final int halfDivider = mDividerSize / 2;
        final LinearLayout.LayoutParams dropZoneView1 =
                (LayoutParams) mDropZoneView1.getLayoutParams();