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

Commit d7a992ac authored by András Kurucz's avatar András Kurucz Committed by Automerger Merge Worker
Browse files

Merge "Move "max to height" roundness logic to Roundable.kt" into udc-qpr-dev am: b5efe939

parents e6c162e4 b5efe939
Loading
Loading
Loading
Loading
+53 −3
Original line number Diff line number Diff line
@@ -3,7 +3,10 @@ package com.android.systemui.statusbar.notification
import android.util.FloatProperty
import android.view.View
import androidx.annotation.FloatRange
import com.android.systemui.Dependency
import com.android.systemui.R
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.statusbar.notification.stack.AnimationProperties
import com.android.systemui.statusbar.notification.stack.StackStateAnimator
import kotlin.math.abs
@@ -20,6 +23,8 @@ interface Roundable {
    /** Properties required for a Roundable */
    val roundableState: RoundableState

    val clipHeight: Int

    /** Current top roundness */
    @get:FloatRange(from = 0.0, to = 1.0)
    @JvmDefault
@@ -40,12 +45,16 @@ interface Roundable {
    /** Current top corner in pixel, based on [topRoundness] and [maxRadius] */
    @JvmDefault
    val topCornerRadius: Float
        get() = topRoundness * maxRadius
        get() =
            if (roundableState.newHeadsUpAnimFlagEnabled) roundableState.topCornerRadius
            else topRoundness * maxRadius

    /** Current bottom corner in pixel, based on [bottomRoundness] and [maxRadius] */
    @JvmDefault
    val bottomCornerRadius: Float
        get() = bottomRoundness * maxRadius
        get() =
            if (roundableState.newHeadsUpAnimFlagEnabled) roundableState.bottomCornerRadius
            else bottomRoundness * maxRadius

    /** Get and update the current radii */
    @JvmDefault
@@ -320,14 +329,20 @@ interface Roundable {
 * @param roundable Target of the radius animation
 * @param maxRadius Max corner radius in pixels
 */
class RoundableState(
class RoundableState
@JvmOverloads
constructor(
    internal val targetView: View,
    private val roundable: Roundable,
    maxRadius: Float,
    private val featureFlags: FeatureFlags = Dependency.get(FeatureFlags::class.java)
) {
    internal var maxRadius = maxRadius
        private set

    internal val newHeadsUpAnimFlagEnabled
        get() = featureFlags.isEnabled(Flags.IMPROVED_HUN_ANIMATIONS)

    /** Animatable for top roundness */
    private val topAnimatable = topAnimatable(roundable)

@@ -344,6 +359,41 @@ class RoundableState(
    internal var bottomRoundness = 0f
        private set

    internal val topCornerRadius: Float
        get() {
            val height = roundable.clipHeight
            val topRadius = topRoundness * maxRadius
            val bottomRadius = bottomRoundness * maxRadius

            if (height == 0) {
                return 0f
            } else if (topRadius + bottomRadius > height) {
                // The sum of top and bottom corner radii should be at max the clipped height
                val overShoot = topRadius + bottomRadius - height
                return topRadius - (overShoot * topRoundness / (topRoundness + bottomRoundness))
            }

            return topRadius
        }

    internal val bottomCornerRadius: Float
        get() {
            val height = roundable.clipHeight
            val topRadius = topRoundness * maxRadius
            val bottomRadius = bottomRoundness * maxRadius

            if (height == 0) {
                return 0f
            } else if (topRadius + bottomRadius > height) {
                // The sum of top and bottom corner radii should be at max the clipped height
                val overShoot = topRadius + bottomRadius - height
                return bottomRadius -
                    (overShoot * bottomRoundness / (topRoundness + bottomRoundness))
            }

            return bottomRadius
        }

    /** Last requested top roundness associated by [SourceType] */
    internal val topRoundnessMap = mutableMapOf<SourceType, Float>()

+8 −0
Original line number Diff line number Diff line
@@ -566,12 +566,20 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView

    @Override
    public float getTopCornerRadius() {
        if (isNewHeadsUpAnimFlagEnabled()) {
            return super.getTopCornerRadius();
        }

        float fraction = getInterpolatedAppearAnimationFraction();
        return MathUtils.lerp(0, super.getTopCornerRadius(), fraction);
    }

    @Override
    public float getBottomCornerRadius() {
        if (isNewHeadsUpAnimFlagEnabled()) {
            return super.getBottomCornerRadius();
        }

        float fraction = getInterpolatedAppearAnimationFraction();
        return MathUtils.lerp(0, super.getBottomCornerRadius(), fraction);
    }
+21 −1
Original line number Diff line number Diff line
@@ -28,7 +28,10 @@ import android.util.IndentingPrintWriter;
import android.view.View;
import android.view.ViewOutlineProvider;

import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.statusbar.notification.RoundableState;
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainer;
import com.android.systemui.util.DumpUtilsKt;
@@ -47,12 +50,14 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    private float mOutlineAlpha = -1f;
    private boolean mAlwaysRoundBothCorners;
    private Path mTmpPath = new Path();
    private final FeatureFlags mFeatureFlags;

    /**
     * {@code false} if the children views of the {@link ExpandableOutlineView} are translated when
     * it is moved. Otherwise, the translation is set on the {@code ExpandableOutlineView} itself.
     */
    protected boolean mDismissUsingRowTranslationX = true;

    private float[] mTmpCornerRadii = new float[8];

    private final ViewOutlineProvider mProvider = new ViewOutlineProvider() {
@@ -81,6 +86,15 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        return mRoundableState;
    }

    @Override
    public int getClipHeight() {
        if (mCustomOutline) {
            return mOutlineRect.height();
        }

        return super.getClipHeight();
    }

    protected Path getClipPath(boolean ignoreTranslation) {
        int left;
        int top;
@@ -112,7 +126,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {
            return EMPTY_PATH;
        }
        float bottomRadius = mAlwaysRoundBothCorners ? getMaxRadius() : getBottomCornerRadius();
        if (topRadius + bottomRadius > height) {
        if (!isNewHeadsUpAnimFlagEnabled() && (topRadius + bottomRadius > height)) {
            float overShoot = topRadius + bottomRadius - height;
            float currentTopRoundness = getTopRoundness();
            float currentBottomRoundness = getBottomRoundness();
@@ -153,6 +167,7 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        super(context, attrs);
        setOutlineProvider(mProvider);
        initDimens();
        mFeatureFlags = Dependency.get(FeatureFlags.class);
    }

    @Override
@@ -360,4 +375,9 @@ public abstract class ExpandableOutlineView extends ExpandableView {
            }
        });
    }

    // TODO(b/290365128) replace with ViewRefactorFlag
    protected boolean isNewHeadsUpAnimFlagEnabled() {
        return mFeatureFlags.isEnabled(Flags.IMPROVED_HUN_ANIMATIONS);
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -93,6 +93,12 @@ public abstract class ExpandableView extends FrameLayout implements Dumpable, Ro
        return mRoundableState;
    }

    @Override
    public int getClipHeight() {
        int clipHeight = Math.max(mActualHeight - mClipTopAmount - mClipBottomAmount, 0);
        return Math.max(clipHeight, mMinimumHeightForClipping);
    }

    private void initDimens() {
        mContentShift = getResources().getDimensionPixelSize(
                R.dimen.shelf_transform_content_shift);
+5 −0
Original line number Diff line number Diff line
@@ -119,6 +119,11 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper imple
        return mRoundableState;
    }

    @Override
    public int getClipHeight() {
        return mView.getHeight();
    }

    @Override
    public void applyRoundnessAndInvalidate() {
        if (mRoundnessChangedListener != null) {
Loading