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

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

Set GroupedTaskView child thumbnails in onMeasure

* Also add indicator if split was originally started
in portrait of landscape, so we know which dimension
of the divider bar to use if user goes to overview
and then rotates device (horizontal divider vs
vertical)

Fixes: 199461137
Test: Swipe to overview with staged split
Rotate device with and without live tile
Doesn't overlap with overview actions

Change-Id: I8b7f104f16d5b7265828f1b3d98ba3426b28d44f
parent 2d9741b8
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ public class GroupedTaskView extends TaskView {
    private Task mSecondaryTask;
    private TaskThumbnailView mSnapshotView2;
    private CancellableTask mThumbnailLoadRequest2;
    private SplitConfigurationOptions.StagedSplitBounds mSplitBoundsConfig;

    public GroupedTaskView(Context context) {
        super(context);
@@ -57,7 +58,7 @@ public class GroupedTaskView extends TaskView {
        mTaskIdContainer[1] = secondary.key.id;
        mTaskIdAttributeContainer[1] = new TaskIdAttributeContainer(secondary, mSnapshotView2);
        mSnapshotView2.bind(secondary);
        adjustThumbnailBoundsForSplit(splitBoundsConfig, orientedState);
        mSplitBoundsConfig = splitBoundsConfig;
    }

    @Override
@@ -121,23 +122,26 @@ public class GroupedTaskView extends TaskView {
    public void onRecycle() {
        super.onRecycle();
        mSnapshotView2.setThumbnail(mSecondaryTask, null);
        mSplitBoundsConfig = null;
    }

    @Override
    public void setOverlayEnabled(boolean overlayEnabled) {
        super.setOverlayEnabled(overlayEnabled);
        mSnapshotView2.setOverlayEnabled(overlayEnabled);
    }

    private void adjustThumbnailBoundsForSplit(
            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
            RecentsOrientedState orientedState) {
        if (splitBoundsConfig == null) {
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(widthSize, heightSize);
        if (mSplitBoundsConfig == null || mSnapshotView == null || mSnapshotView2 == null) {
            return;
        }

        orientedState.getOrientationHandler().setGroupedTaskViewThumbnailBounds(
                mSnapshotView, mSnapshotView2, this, splitBoundsConfig,
        getPagedOrientationHandler().measureGroupedTaskViewThumbnailBounds(mSnapshotView,
                mSnapshotView2, widthSize, heightSize, mSplitBoundsConfig,
                mActivity.getDeviceProfile());
    }

    @Override
    public void setOverlayEnabled(boolean overlayEnabled) {
        super.setOverlayEnabled(overlayEnabled);
        mSnapshotView2.setOverlayEnabled(overlayEnabled);
    }
}
+22 −14
Original line number Diff line number Diff line
@@ -408,22 +408,30 @@ public class LandscapePagedViewHandler implements PagedOrientationHandler {
    }

    @Override
    public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2,
            View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
            DeviceProfile dp) {
    public void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
            int parentWidth, int parentHeight,
            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp) {
        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
        int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot;
        int totalThumbnailWidth = taskParent.getWidth();
        int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
        int dividerBar = splitBoundsConfig.visualDividerBounds.width();
        ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams();
        ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams();

        primaryLp.width = totalThumbnailWidth;
        primaryLp.height = (int) (totalThumbnailHeight * splitBoundsConfig.leftTaskPercent);

        secondaryLp.width = totalThumbnailWidth;
        secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar;
        mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar);
        int primarySnapshotHeight;
        int primarySnapshotWidth;
        int secondarySnapshotHeight;
        int secondarySnapshotWidth;

        primarySnapshotWidth = parentWidth;
        primarySnapshotHeight = (int) (totalThumbnailHeight * splitBoundsConfig.leftTaskPercent);

        secondarySnapshotWidth = parentWidth;
        secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;
        secondarySnapshot.setTranslationY(primarySnapshotHeight + spaceAboveSnapshot + dividerBar);
        primarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY));
        secondarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight,
                        View.MeasureSpec.EXACTLY));
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -162,7 +162,8 @@ public interface PagedOrientationHandler {
            SplitConfigurationOptions.StagedSplitBounds splitInfo,
            @SplitConfigurationOptions.StagePosition int desiredStagePosition);

    void setGroupedTaskViewThumbnailBounds(View mSnapshot1, View mSnapshot2, View taskParent,
    void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
            int parentWidth, int parentHeight,
            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp);

    // Overview TaskMenuView methods
+36 −26
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.widget.LinearLayout;

@@ -511,35 +510,46 @@ public class PortraitPagedViewHandler implements PagedOrientationHandler {
    }

    @Override
    public void setGroupedTaskViewThumbnailBounds(View mSnapshotView, View mSnapshotView2,
            View taskParent, SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig,
            DeviceProfile dp) {
    public void measureGroupedTaskViewThumbnailBounds(View primarySnapshot, View secondarySnapshot,
            int parentWidth, int parentHeight,
            SplitConfigurationOptions.StagedSplitBounds splitBoundsConfig, DeviceProfile dp) {
        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
        int totalThumbnailHeight = taskParent.getHeight() - spaceAboveSnapshot;
        int totalThumbnailWidth = taskParent.getWidth();
        int dividerBar = (dp.isLandscape ?
                splitBoundsConfig.visualDividerBounds.width() :
                splitBoundsConfig.visualDividerBounds.height());
        ViewGroup.LayoutParams primaryLp = mSnapshotView.getLayoutParams();
        ViewGroup.LayoutParams secondaryLp = mSnapshotView2.getLayoutParams();

        int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
        int dividerBar = (splitBoundsConfig.appsStackedVertically ?
                splitBoundsConfig.visualDividerBounds.height() :
                splitBoundsConfig.visualDividerBounds.width());
        int primarySnapshotHeight;
        int primarySnapshotWidth;
        int secondarySnapshotHeight;
        int secondarySnapshotWidth;
        float taskPercent = splitBoundsConfig.appsStackedVertically ?
                splitBoundsConfig.topTaskPercent : splitBoundsConfig.leftTaskPercent;
        if (dp.isLandscape) {
            primaryLp.height = totalThumbnailHeight;
            primaryLp.width = (int) (totalThumbnailWidth * splitBoundsConfig.leftTaskPercent);

            secondaryLp.height = totalThumbnailHeight;
            secondaryLp.width = totalThumbnailWidth - primaryLp.width - dividerBar;
            mSnapshotView2.setTranslationX(primaryLp.width + dividerBar);
            mSnapshotView2.setTranslationY(spaceAboveSnapshot);
            primarySnapshotHeight = totalThumbnailHeight;
            primarySnapshotWidth = (int) (parentWidth * taskPercent);

            secondarySnapshotHeight = totalThumbnailHeight;
            secondarySnapshotWidth = parentWidth - primarySnapshotWidth - dividerBar;
            int translationX = primarySnapshotWidth + dividerBar;
            secondarySnapshot.setTranslationX(translationX);
            secondarySnapshot.setTranslationY(spaceAboveSnapshot);
        } else {
            primaryLp.width = totalThumbnailWidth;
            primaryLp.height = (int) (totalThumbnailHeight * splitBoundsConfig.topTaskPercent);

            secondaryLp.width = totalThumbnailWidth;
            secondaryLp.height = totalThumbnailHeight - primaryLp.height - dividerBar;
            mSnapshotView2.setTranslationY(primaryLp.height + spaceAboveSnapshot + dividerBar);
            mSnapshotView2.setTranslationX(0);
        }
            primarySnapshotWidth = parentWidth;
            primarySnapshotHeight = (int) (totalThumbnailHeight * taskPercent);

            secondarySnapshotWidth = parentWidth;
            secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;
            int translationY = primarySnapshotHeight + spaceAboveSnapshot + dividerBar;
            secondarySnapshot.setTranslationY(translationY);
            secondarySnapshot.setTranslationX(0);
        }
        primarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY));
        secondarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight,
                        View.MeasureSpec.EXACTLY));
    }

    @Override
+9 −1
Original line number Diff line number Diff line
@@ -93,7 +93,13 @@ public final class SplitConfigurationOptions {
        // This class is orientation-agnostic, so we compute both for later use
        public final float topTaskPercent;
        public final float leftTaskPercent;

        /**
         * 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
         * rotation where the bounds won't change, but this variable can indicate what orientation
         * the bounds were originally in
         */
        public final boolean appsStackedVertically;

        public StagedSplitBounds(Rect leftTopBounds, Rect rightBottomBounds) {
            this.leftTopBounds = leftTopBounds;
@@ -103,10 +109,12 @@ public final class SplitConfigurationOptions {
                // vertical apps, horizontal divider
                this.visualDividerBounds = new Rect(leftTopBounds.left, leftTopBounds.bottom,
                        leftTopBounds.right, rightBottomBounds.top);
                appsStackedVertically = true;
            } else {
                // horizontal apps, vertical divider
                this.visualDividerBounds = new Rect(leftTopBounds.right, leftTopBounds.top,
                        rightBottomBounds.left, leftTopBounds.bottom);
                appsStackedVertically = false;
            }

            leftTaskPercent = this.leftTopBounds.width() / (float) rightBottomBounds.right;