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

Commit e47b183a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expand the clip path for bundle groups" into main

parents 8e78e9d7 7fc909e9
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -148,6 +148,32 @@ public class NotificationChildrenContainerTest extends SysuiTestCase {
                NotificationChildrenContainer.NUMBER_OF_CHILDREN_BUNDLE_EXPANDED);
                NotificationChildrenContainer.NUMBER_OF_CHILDREN_BUNDLE_EXPANDED);
    }
    }


    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void testExpandedClipRect_bundle_expandedChildren_requiresExtraClipping() {
        ComposeView headerView = new ComposeView(mContext);
        mBundle.setBundleHeaderView(headerView);

        NotificationChildrenContainer childrenContainer = mBundle.getChildrenContainer();
        childrenContainer.setBundleHeaderViewModel(mock(BundleHeaderViewModel.class));
        childrenContainer.getContainingNotification().expandNotification();
        childrenContainer.setChildrenExpanded(true);
        Assert.assertNotNull(childrenContainer.getExpandedClipRect(mGroup));
        Assert.assertTrue(childrenContainer.childNeedsExpandedClipPath(mGroup));
    }

    @Test
    @EnableFlags(NotificationBundleUi.FLAG_NAME)
    public void testExpandedClipRect_bundle_notExpandedChildren_doesNotRequireExtraClipping() {
        ComposeView headerView = new ComposeView(mContext);
        mBundle.setBundleHeaderView(headerView);

        NotificationChildrenContainer childrenContainer = mBundle.getChildrenContainer();
        childrenContainer.setBundleHeaderViewModel(mock(BundleHeaderViewModel.class));
        childrenContainer.getContainingNotification().expandNotification();
        childrenContainer.setChildrenExpanded(false);
        Assert.assertFalse(childrenContainer.childNeedsExpandedClipPath(mGroup));
    }


    @Test
    @Test
    public void testShowingAsLowPriority_lowPriority() {
    public void testShowingAsLowPriority_lowPriority() {
+37 −0
Original line number Original line Diff line number Diff line
@@ -25,9 +25,11 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Trace;
import android.os.Trace;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
@@ -159,6 +161,7 @@ public class NotificationChildrenContainer extends ViewGroup
    private int mMinSingleLineHeight;
    private int mMinSingleLineHeight;


    private NotificationChildrenContainerLogger mLogger;
    private NotificationChildrenContainerLogger mLogger;
    private ArrayMap<String, RectF> mExpandedClipRect = new ArrayMap<>();


    public NotificationChildrenContainer(Context context) {
    public NotificationChildrenContainer(Context context) {
        this(context, null);
        this(context, null);
@@ -860,6 +863,7 @@ public class NotificationChildrenContainer extends ViewGroup
        boolean childrenExpandedAndNotAnimating = mChildrenExpanded
        boolean childrenExpandedAndNotAnimating = mChildrenExpanded
                && !mContainingNotification.isGroupExpansionChanging();
                && !mContainingNotification.isGroupExpansionChanging();
        int launchTransitionCompensation = 0;
        int launchTransitionCompensation = 0;
        mExpandedClipRect.clear();
        for (int i = 0; i < childCount; i++) {
        for (int i = 0; i < childCount; i++) {
            ExpandableNotificationRow child = mAttachedChildren.get(i);
            ExpandableNotificationRow child = mAttachedChildren.get(i);
            if (NotificationBundleUi.isEnabled()) {
            if (NotificationBundleUi.isEnabled()) {
@@ -920,6 +924,13 @@ public class NotificationChildrenContainer extends ViewGroup
            childState.location = parentState.location;
            childState.location = parentState.location;
            childState.inShelf = parentState.inShelf;
            childState.inShelf = parentState.inShelf;
            yPosition += intrinsicHeight;
            yPosition += intrinsicHeight;

            // If this is a group summary and a child of a bundle, then the clip path needs to
            // be expanded otherwise the summary children will be clipped when translated
            if (childNeedsExpandedClipPath(child)) {
                RectF expandClipRect = getExpandedClipRect(child);
                mExpandedClipRect.put(child.getKey(), expandClipRect);
            }
        }
        }
        if (mOverflowNumber != null) {
        if (mOverflowNumber != null) {
            ExpandableNotificationRow overflowView = mAttachedChildren.get(Math.min(
            ExpandableNotificationRow overflowView = mAttachedChildren.get(Math.min(
@@ -1146,6 +1157,23 @@ public class NotificationChildrenContainer extends ViewGroup
        }
        }
    }
    }


    @VisibleForTesting
    protected boolean childNeedsExpandedClipPath(ExpandableNotificationRow child) {
        return isBundle() && mChildrenExpanded && child.isSummaryWithChildren();
    }

    @VisibleForTesting
    protected RectF getExpandedClipRect(ExpandableNotificationRow summaryRow) {
        RectF expandedRect;
        float maxAbsChildTranslation = getWidth() / 2.0f;
        expandedRect = new RectF();
        expandedRect.left = -maxAbsChildTranslation;
        expandedRect.top = 0;
        expandedRect.bottom = mContainingNotification.getActualHeight();
        expandedRect.right = summaryRow.getWidth() + maxAbsChildTranslation;
        return expandedRect;
    }

    @Override
    @Override
    protected boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime) {
    protected boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime) {
        boolean isCanvasChanged = false;
        boolean isCanvasChanged = false;
@@ -1153,8 +1181,10 @@ public class NotificationChildrenContainer extends ViewGroup
        Path clipPath = mChildClipPath;
        Path clipPath = mChildClipPath;
        if (clipPath != null) {
        if (clipPath != null) {
            final float translation;
            final float translation;
            RectF expandClipRect = null;
            if (child instanceof ExpandableNotificationRow notificationRow) {
            if (child instanceof ExpandableNotificationRow notificationRow) {
                translation = notificationRow.getTranslation();
                translation = notificationRow.getTranslation();
                expandClipRect = mExpandedClipRect.get(notificationRow.getKey());
            } else {
            } else {
                translation = child.getTranslationX();
                translation = child.getTranslationX();
            }
            }
@@ -1166,6 +1196,13 @@ public class NotificationChildrenContainer extends ViewGroup
                canvas.clipPath(clipPath);
                canvas.clipPath(clipPath);
                clipPath.offset(-translation, 0f);
                clipPath.offset(-translation, 0f);
            } else {
            } else {
                if (expandClipRect != null) {
                    // Expand clip path with a rect that has the same height as the parent
                    // but is wider by width/2 so that grand-child translations are not clipped
                    // Only applies to bundle headers
                    clipPath = new Path(clipPath);
                    clipPath.addRect(expandClipRect, Direction.CW);
                }
                canvas.clipPath(clipPath);
                canvas.clipPath(clipPath);
            }
            }
        }
        }