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

Commit fa05cb22 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Scale screenWidth for split proportionally for thumbnail matrix

* Created TODO(b/254378592) to consolidate different
SplitBounds classes

Fixes: 250817893
Test: Checked phone/tablet swiping quickswitching
portrait and landscape

Change-Id: If5c55d10a0d21b7984442d01f306c2016eba3701
parent 1de186f8
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public class SplitBounds implements Parcelable {
    // This class is orientation-agnostic, so we compute both for later use
    public final float topTaskPercent;
    public final float leftTaskPercent;
    public final float dividerWidthPercent;
    public final float dividerHeightPercent;
    /**
     * If {@code true}, that means at the time of creation of this object, the
     * split-screened apps were vertically stacked. This is useful in scenarios like
@@ -62,8 +64,12 @@ public class SplitBounds implements Parcelable {
            appsStackedVertically = false;
        }

        leftTaskPercent = this.leftTopBounds.width() / (float) rightBottomBounds.right;
        topTaskPercent = this.leftTopBounds.height() / (float) rightBottomBounds.bottom;
        float totalWidth = rightBottomBounds.right - leftTopBounds.left;
        float totalHeight = rightBottomBounds.bottom - leftTopBounds.top;
        leftTaskPercent = leftTopBounds.width() / totalWidth;
        topTaskPercent = leftTopBounds.height() / totalHeight;
        dividerWidthPercent = visualDividerBounds.width() / totalWidth;
        dividerHeightPercent = visualDividerBounds.height() / totalHeight;
    }

    public SplitBounds(Parcel parcel) {
@@ -75,6 +81,8 @@ public class SplitBounds implements Parcelable {
        appsStackedVertically = parcel.readBoolean();
        leftTopTaskId = parcel.readInt();
        rightBottomTaskId = parcel.readInt();
        dividerWidthPercent = parcel.readInt();
        dividerHeightPercent = parcel.readInt();
    }

    @Override
@@ -87,6 +95,8 @@ public class SplitBounds implements Parcelable {
        parcel.writeBoolean(appsStackedVertically);
        parcel.writeInt(leftTopTaskId);
        parcel.writeInt(rightBottomTaskId);
        parcel.writeFloat(dividerWidthPercent);
        parcel.writeFloat(dividerHeightPercent);
    }

    @Override
+39 −6
Original line number Diff line number Diff line
package com.android.systemui.shared.recents.utilities;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.view.Surface.ROTATION_180;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;

import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.Surface;

import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.wm.shell.util.SplitBounds;

/**
 * Utility class to position the thumbnail in the TaskView
@@ -16,10 +19,26 @@ public class PreviewPositionHelper {

    public static final float MAX_PCT_BEFORE_ASPECT_RATIOS_CONSIDERED_DIFFERENT = 0.1f;

    /**
     * Specifies that a stage is positioned at the top half of the screen if
     * in portrait mode or at the left half of the screen if in landscape mode.
     * TODO(b/254378592): Remove after consolidation
     */
    public static final int STAGE_POSITION_TOP_OR_LEFT = 0;

    /**
     * Specifies that a stage is positioned at the bottom half of the screen if
     * in portrait mode or at the right half of the screen if in landscape mode.
     * TODO(b/254378592): Remove after consolidation
     */
    public static final int STAGE_POSITION_BOTTOM_OR_RIGHT = 1;

    // Contains the portion of the thumbnail that is unclipped when fullscreen progress = 1.
    private final RectF mClippedInsets = new RectF();
    private final Matrix mMatrix = new Matrix();
    private boolean mIsOrientationChanged;
    private SplitBounds mSplitBounds;
    private int mDesiredStagePosition;

    public Matrix getMatrix() {
        return mMatrix;
@@ -33,6 +52,11 @@ public class PreviewPositionHelper {
        return mIsOrientationChanged;
    }

    public void setSplitBounds(SplitBounds splitBounds, int desiredStagePosition) {
        mSplitBounds = splitBounds;
        mDesiredStagePosition = desiredStagePosition;
    }

    /**
     * Updates the matrix based on the provided parameters
     */
@@ -42,10 +66,19 @@ public class PreviewPositionHelper {
        boolean isRotated = false;
        boolean isOrientationDifferent;

        float fullscreenTaskWidth = screenWidthPx;
        if (mSplitBounds != null && !mSplitBounds.appsStackedVertically) {
            // For landscape, scale the width
            float taskPercent = mDesiredStagePosition == STAGE_POSITION_TOP_OR_LEFT
                    ? mSplitBounds.leftTaskPercent
                    : (1 - (mSplitBounds.leftTaskPercent + mSplitBounds.dividerWidthPercent));
            // Scale landscape width to that of actual screen
            fullscreenTaskWidth = screenWidthPx * taskPercent;
        }
        int thumbnailRotation = thumbnailData.rotation;
        int deltaRotate = getRotationDelta(currentRotation, thumbnailRotation);
        RectF thumbnailClipHint = new RectF();
        float canvasScreenRatio = canvasWidth / (float) screenWidthPx;
        float canvasScreenRatio = canvasWidth / fullscreenTaskWidth;
        float scaledTaskbarSize = taskbarSize * canvasScreenRatio;
        thumbnailClipHint.bottom = isTablet ? scaledTaskbarSize : 0;

@@ -180,7 +213,7 @@ public class PreviewPositionHelper {
     * portrait or vice versa, {@code false} otherwise
     */
    private boolean isOrientationChange(int deltaRotation) {
        return deltaRotation == Surface.ROTATION_90 || deltaRotation == Surface.ROTATION_270;
        return deltaRotation == ROTATION_90 || deltaRotation == ROTATION_270;
    }

    private void setThumbnailRotation(int deltaRotate, Rect thumbnailPosition) {
@@ -189,13 +222,13 @@ public class PreviewPositionHelper {

        mMatrix.setRotate(90 * deltaRotate);
        switch (deltaRotate) { /* Counter-clockwise */
            case Surface.ROTATION_90:
            case ROTATION_90:
                translateX = thumbnailPosition.height();
                break;
            case Surface.ROTATION_270:
            case ROTATION_270:
                translateY = thumbnailPosition.width();
                break;
            case Surface.ROTATION_180:
            case ROTATION_180:
                translateX = thumbnailPosition.width();
                translateY = thumbnailPosition.height();
                break;