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

Commit 0d355abe authored by Uwais Ashraf's avatar Uwais Ashraf
Browse files

Extract GroupedTaskView size calcs to a method to prevent measure calls

Bug: 313644427
Flag: ACONFIG com.android.launcher3.enable_grid_only_overview TEAMFOOD
Flag: ACONFIG com.android.launcher3.enable_overview_icon_menu TEAMFOOD
Test: OverviewImageTest
Change-Id: I494f09455104372209b9087d13a704a4fe52bb62
parent ea784da6
Loading
Loading
Loading
Loading
+35 −16
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITIO
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN;

import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -533,33 +534,51 @@ public class LandscapePagedViewHandler implements RecentsPagedOrientationHandler
        int dividerBar = Math.round(totalThumbnailHeight * (splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent));
        int primarySnapshotHeight;
        int primarySnapshotWidth;
        int secondarySnapshotHeight;
        int secondarySnapshotWidth;

        float taskPercent = splitBoundsConfig.appsStackedVertically ?
                splitBoundsConfig.topTaskPercent : splitBoundsConfig.leftTaskPercent;
        primarySnapshotWidth = parentWidth;
        primarySnapshotHeight = (int) (totalThumbnailHeight * (taskPercent));
        Pair<Point, Point> taskViewSizes =
                getGroupedTaskViewSizes(dp, splitBoundsConfig, parentWidth, parentHeight);

        secondarySnapshotWidth = parentWidth;
        secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;

        int translationY = primarySnapshotHeight + spaceAboveSnapshot + dividerBar;
        int translationY = taskViewSizes.first.y + spaceAboveSnapshot + dividerBar;
        primarySnapshot.setTranslationY(spaceAboveSnapshot);
        secondarySnapshot.setTranslationY(translationY - spaceAboveSnapshot);

        primarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY)
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.y, View.MeasureSpec.EXACTLY)
        );
        secondarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight, View.MeasureSpec.EXACTLY)
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.y, View.MeasureSpec.EXACTLY)
        );
    }

    @Override
    public Pair<Point, Point> getGroupedTaskViewSizes(
            DeviceProfile dp,
            SplitBounds splitBoundsConfig,
            int parentWidth,
            int parentHeight) {
        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
        int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
        int dividerBar = Math.round(totalThumbnailHeight * (splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent));
        float taskPercent = splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.topTaskPercent
                : splitBoundsConfig.leftTaskPercent;

        Point firstTaskViewSize = new Point(
                parentWidth,
                (int) (totalThumbnailHeight * taskPercent)
        );
        Point secondTaskViewSize = new Point(
                parentWidth,
                totalThumbnailHeight - firstTaskViewSize.y - dividerBar
        );

        return new Pair<>(firstTaskViewSize, secondTaskViewSize);
    }

    @Override
    public void setTaskIconParams(FrameLayout.LayoutParams iconParams, int taskIconMargin,
            int taskIconHeight, int thumbnailTopMargin, boolean isRtl) {
+52 −28
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITIO
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN;

import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -530,25 +531,16 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
        float dividerScale = splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent;
        int primarySnapshotHeight;
        int primarySnapshotWidth;
        int secondarySnapshotHeight;
        int secondarySnapshotWidth;
        float taskPercent = splitBoundsConfig.appsStackedVertically ?
                splitBoundsConfig.topTaskPercent : splitBoundsConfig.leftTaskPercent;
        Pair<Point, Point> taskViewSizes =
                getGroupedTaskViewSizes(dp, splitBoundsConfig, parentWidth, parentHeight);
        if (dp.isLeftRightSplit) {
            int scaledDividerBar = Math.round(parentWidth * dividerScale);
            primarySnapshotHeight = totalThumbnailHeight;
            primarySnapshotWidth = Math.round(parentWidth * taskPercent);

            secondarySnapshotHeight = totalThumbnailHeight;
            secondarySnapshotWidth = parentWidth - primarySnapshotWidth - scaledDividerBar;
            if (isRtl) {
                int translationX = secondarySnapshotWidth + scaledDividerBar;
                int translationX = taskViewSizes.second.x + scaledDividerBar;
                primarySnapshot.setTranslationX(-translationX);
                secondarySnapshot.setTranslationX(0);
            } else {
                int translationX = primarySnapshotWidth + scaledDividerBar;
                int translationX = taskViewSizes.first.x + scaledDividerBar;
                secondarySnapshot.setTranslationX(translationX);
                primarySnapshot.setTranslationX(0);
            }
@@ -557,18 +549,8 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
            // Reset unused translations
            primarySnapshot.setTranslationY(0);
        } else {
            int taskbarHeight = dp.isTransientTaskbar ? 0 : dp.taskbarHeight;
            float scale = (float) totalThumbnailHeight / (dp.availableHeightPx - taskbarHeight);
            float topTaskHeight = dp.availableHeightPx * taskPercent;
            float finalDividerHeight = Math.round(totalThumbnailHeight * dividerScale);
            float scaledTopTaskHeight = topTaskHeight * scale;
            primarySnapshotWidth = parentWidth;
            primarySnapshotHeight = Math.round(scaledTopTaskHeight);

            secondarySnapshotWidth = parentWidth;
            secondarySnapshotHeight = Math.round(totalThumbnailHeight - primarySnapshotHeight
                    - finalDividerHeight);
            float translationY = primarySnapshotHeight + spaceAboveSnapshot + finalDividerHeight;
            float translationY = taskViewSizes.first.y + spaceAboveSnapshot + finalDividerHeight;
            secondarySnapshot.setTranslationY(translationY);

            FrameLayout.LayoutParams primaryParams =
@@ -584,11 +566,11 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
            primarySnapshot.setTranslationX(0);
        }
        primarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY));
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.y, View.MeasureSpec.EXACTLY));
        secondarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight,
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.y,
                        View.MeasureSpec.EXACTLY));
        primarySnapshot.setScaleX(1);
        secondarySnapshot.setScaleX(1);
@@ -596,6 +578,48 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
        secondarySnapshot.setScaleY(1);
    }

    @Override
    public Pair<Point, Point> getGroupedTaskViewSizes(
            DeviceProfile dp,
            SplitBounds splitBoundsConfig,
            int parentWidth,
            int parentHeight) {
        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
        int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
        float dividerScale = splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent;
        float taskPercent = splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.topTaskPercent
                : splitBoundsConfig.leftTaskPercent;

        Point firstTaskViewSize = new Point();
        Point secondTaskViewSize = new Point();

        if (dp.isLeftRightSplit) {
            int scaledDividerBar = Math.round(parentWidth * dividerScale);
            firstTaskViewSize.x = Math.round(parentWidth * taskPercent);
            firstTaskViewSize.y = totalThumbnailHeight;

            secondTaskViewSize.x = parentWidth - firstTaskViewSize.x - scaledDividerBar;
            secondTaskViewSize.y = totalThumbnailHeight;
        } else {
            int taskbarHeight = dp.isTransientTaskbar ? 0 : dp.taskbarHeight;
            float scale = (float) totalThumbnailHeight / (dp.availableHeightPx - taskbarHeight);
            float topTaskHeight = dp.availableHeightPx * taskPercent;
            float finalDividerHeight = Math.round(totalThumbnailHeight * dividerScale);
            float scaledTopTaskHeight = topTaskHeight * scale;
            firstTaskViewSize.x = parentWidth;
            firstTaskViewSize.y = Math.round(scaledTopTaskHeight);

            secondTaskViewSize.x = parentWidth;
            secondTaskViewSize.y = Math.round(totalThumbnailHeight - firstTaskViewSize.y
                    - finalDividerHeight);
        }

        return new Pair<>(firstTaskViewSize, secondTaskViewSize);
    }

    @Override
    public void setTaskIconParams(FrameLayout.LayoutParams iconParams, int taskIconMargin,
            int taskIconHeight, int thumbnailTopMargin, boolean isRtl) {
+10 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.quickstep.orientation;


import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -135,6 +136,15 @@ public interface RecentsPagedOrientationHandler extends PagedOrientationHandler
            int parentWidth, int parentHeight,
            SplitBounds splitBoundsConfig, DeviceProfile dp, boolean isRtl);

    /**
     * Creates two Points representing the dimensions of the two tasks in a GroupedTaskView
     *
     * @return first -> primary task snapshot, second -> secondary task snapshot.
     * x -> width, y -> height
     */
    Pair<Point, Point> getGroupedTaskViewSizes(DeviceProfile dp, SplitBounds splitBoundsConfig,
            int parentWidth, int parentHeight);

    // Overview TaskMenuView methods
    void setTaskIconParams(FrameLayout.LayoutParams iconParams,
            int taskIconMargin, int taskIconHeight, int thumbnailTopMargin, boolean isRtl);
+39 −17
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITIO
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN;

import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Pair;
@@ -342,29 +343,50 @@ public class SeascapePagedViewHandler extends LandscapePagedViewHandler {
        int dividerBar = Math.round(totalThumbnailHeight * (splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent));
        int primarySnapshotHeight;
        int primarySnapshotWidth;
        int secondarySnapshotHeight;
        int secondarySnapshotWidth;

        float taskPercent = splitBoundsConfig.appsStackedVertically ?
                splitBoundsConfig.topTaskPercent : splitBoundsConfig.leftTaskPercent;
        primarySnapshotWidth = parentWidth;
        primarySnapshotHeight = (int) (totalThumbnailHeight * (taskPercent));

        secondarySnapshotWidth = parentWidth;
        secondarySnapshotHeight = totalThumbnailHeight - primarySnapshotHeight - dividerBar;

        Pair<Point, Point> taskViewSizes =
                getGroupedTaskViewSizes(dp, splitBoundsConfig, parentWidth, parentHeight);

        secondarySnapshot.setTranslationY(0);
        primarySnapshot.setTranslationY(secondarySnapshotHeight + spaceAboveSnapshot + dividerBar);
        primarySnapshot.setTranslationY(taskViewSizes.second.y + spaceAboveSnapshot + dividerBar);

        primarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(primarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(primarySnapshotHeight, View.MeasureSpec.EXACTLY)
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.first.y, View.MeasureSpec.EXACTLY)
        );
        secondarySnapshot.measure(
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotWidth, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(secondarySnapshotHeight, View.MeasureSpec.EXACTLY)
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.x, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(taskViewSizes.second.y, View.MeasureSpec.EXACTLY)
        );
    }

    @Override
    public Pair<Point, Point> getGroupedTaskViewSizes(
            DeviceProfile dp,
            SplitBounds splitBoundsConfig,
            int parentWidth,
            int parentHeight) {
        // Measure and layout the thumbnails bottom up, since the primary is on the visual left
        // (portrait bottom) and secondary is on the right (portrait top)
        int spaceAboveSnapshot = dp.overviewTaskThumbnailTopMarginPx;
        int totalThumbnailHeight = parentHeight - spaceAboveSnapshot;
        int dividerBar = Math.round(totalThumbnailHeight * (splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.dividerHeightPercent
                : splitBoundsConfig.dividerWidthPercent));
        float taskPercent = splitBoundsConfig.appsStackedVertically
                ? splitBoundsConfig.topTaskPercent
                : splitBoundsConfig.leftTaskPercent;

        Point firstTaskViewSize = new Point(
                parentWidth,
                (int) (totalThumbnailHeight * taskPercent)
        );
        Point secondTaskViewSize = new Point(
                parentWidth,
                totalThumbnailHeight - firstTaskViewSize.y - dividerBar
        );

        return new Pair<>(firstTaskViewSize, secondTaskViewSize);
    }

    /* ---------- The following are only used by TaskViewTouchHandler. ---------- */
+44 −17
Original line number Diff line number Diff line
@@ -7,11 +7,14 @@ import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITIO
import static com.android.quickstep.util.SplitScreenUtils.convertLauncherSplitBoundsToShell;

import android.content.Context;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;

import androidx.annotation.NonNull;
@@ -37,10 +40,11 @@ import com.android.systemui.shared.recents.utilities.PreviewPositionHelper;
import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
import com.android.wm.shell.common.split.SplitScreenConstants.PersistentSnapPosition;

import kotlin.Unit;

import java.util.HashMap;
import java.util.function.Consumer;

import kotlin.Unit;

/**
 * TaskView that contains and shows thumbnails for not one, BUT TWO(!!) tasks
@@ -374,18 +378,7 @@ public class GroupedTaskView extends TaskView {
        }
        if (!enableOverviewIconMenu()) {
            updateIconPlacement();
            return;
        }

        if (getRecentsView() == null) {
            return;
        }

        int iconMargins = getResources().getDimensionPixelSize(
                R.dimen.task_thumbnail_icon_menu_start_margin) * 2;
        ((IconAppChipView) mIconView).setMaxWidth(mSnapshotView.getMeasuredWidth() - iconMargins);
        ((IconAppChipView) mIconView2).setMaxWidth(mSnapshotView2.getMeasuredWidth() - iconMargins);
        setOrientationState(getRecentsView().getPagedViewOrientedState());
    }

    @Override
@@ -395,8 +388,25 @@ public class GroupedTaskView extends TaskView {

    @Override
    public void setOrientationState(RecentsOrientedState orientationState) {
        super.setOrientationState(orientationState);
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        if (enableOverviewIconMenu() && mSplitBoundsConfig != null) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            Pair<Point, Point> groupedTaskViewSizes =
                    orientationState.getOrientationHandler().getGroupedTaskViewSizes(
                            deviceProfile,
                            mSplitBoundsConfig,
                            layoutParams.width,
                            layoutParams.height
                    );
            int iconMargins = getResources().getDimensionPixelSize(
                    R.dimen.task_thumbnail_icon_menu_start_margin) * 2;
            ((IconAppChipView) mIconView).setMaxWidth(groupedTaskViewSizes.first.x - iconMargins);
            ((IconAppChipView) mIconView2).setMaxWidth(groupedTaskViewSizes.second.x - iconMargins);
        }
        // setMaxWidth() needs to be called before mIconView.setIconOrientation which is called in
        // the super below.
        super.setOrientationState(orientationState);

        boolean isGridTask = deviceProfile.isTablet && !isFocusedTask();
        mIconView2.setIconOrientation(orientationState, isGridTask);
        updateIconPlacement();
@@ -412,10 +422,27 @@ public class GroupedTaskView extends TaskView {
        int taskIconHeight = deviceProfile.overviewTaskIconSizePx;
        boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;

        if (enableOverviewIconMenu()) {
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            Pair<Point, Point> groupedTaskViewSizes =
                    getPagedOrientationHandler()
                            .getGroupedTaskViewSizes(
                                    deviceProfile,
                                    mSplitBoundsConfig,
                                    layoutParams.width,
                                    layoutParams.height
                            );

            getPagedOrientationHandler().setSplitIconParams(mIconView.asView(), mIconView2.asView(),
                taskIconHeight, mSnapshotView.getMeasuredWidth(), mSnapshotView.getMeasuredHeight(),
                getMeasuredHeight(), getMeasuredWidth(), isRtl, deviceProfile,
                    taskIconHeight, groupedTaskViewSizes.first.x, groupedTaskViewSizes.first.y,
                    getLayoutParams().height, getLayoutParams().width, isRtl, deviceProfile,
                    mSplitBoundsConfig);
        } else {
            getPagedOrientationHandler().setSplitIconParams(mIconView.asView(), mIconView2.asView(),
                    taskIconHeight, mSnapshotView.getMeasuredWidth(),
                    mSnapshotView.getMeasuredHeight(), getMeasuredHeight(), getMeasuredWidth(),
                    isRtl, deviceProfile, mSplitBoundsConfig);
        }
    }

    private void updateSecondaryDwbPlacement() {
Loading