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

Commit d9b7dd4a authored by Selim Cinek's avatar Selim Cinek
Browse files

Implemented animations for rounding

The corners now animate nicely instead of just
jumping.

Bug: 69168591
Test: manual, swipe away notifications
Change-Id: Ia45774b1fed4d7b0a5cf2ec56ff1560ff685503c
parent 0228a255
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -77,6 +77,14 @@
    <item type="id" name="action_move_tl_30" />
    <item type="id" name="action_move_rb_full" />

    <item type="id" name="bottom_roundess_animator_tag"/>
    <item type="id" name="bottom_roundess_animator_start_tag"/>
    <item type="id" name="bottom_roundess_animator_end_tag"/>

    <item type="id" name="top_roundess_animator_tag"/>
    <item type="id" name="top_roundess_animator_start_tag"/>
    <item type="id" name="top_roundess_animator_end_tag"/>

    <!-- Accessibility actions for the notification menu -->
    <item type="id" name="action_snooze_undo"/>
    <item type="id" name="action_snooze_shorter"/>
+2 −1
Original line number Diff line number Diff line
@@ -904,7 +904,8 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    @Override
    protected void applyRoundness() {
        super.applyRoundness();
        applyBackgroundRoundness(getBackgroundRadiusTop(), getBackgroundRadiusBottom());
        applyBackgroundRoundness(getCurrentBackgroundRadiusTop(),
                getCurrentBackgroundRadiusBottom());
    }

    protected void applyBackgroundRoundness(float topRadius, float bottomRadius) {
+1 −0
Original line number Diff line number Diff line
@@ -1025,6 +1025,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mKeepInParent = keepInParent;
    }

    @Override
    public boolean isRemoved() {
        return mRemoved;
    }
+61 −21
Original line number Diff line number Diff line
@@ -29,12 +29,33 @@ import android.view.ViewOutlineProvider;

import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
import com.android.systemui.statusbar.stack.AnimationProperties;
import com.android.systemui.statusbar.stack.StackStateAnimator;

/**
 * Like {@link ExpandableView}, but setting an outline for the height and clipping.
 */
public abstract class ExpandableOutlineView extends ExpandableView {

    private static final AnimatableProperty TOP_ROUNDNESS = AnimatableProperty.from(
            "topRoundness",
            ExpandableOutlineView::setTopRoundnessInternal,
            ExpandableOutlineView::getCurrentTopRoundness,
            R.id.top_roundess_animator_tag,
            R.id.top_roundess_animator_end_tag,
            R.id.top_roundess_animator_start_tag);
    private static final AnimatableProperty BOTTOM_ROUNDNESS = AnimatableProperty.from(
            "bottomRoundness",
            ExpandableOutlineView::setBottomRoundnessInternal,
            ExpandableOutlineView::getCurrentBottomRoundness,
            R.id.bottom_roundess_animator_tag,
            R.id.bottom_roundess_animator_end_tag,
            R.id.bottom_roundess_animator_start_tag);
    private static final AnimationProperties ROUNDNESS_PROPERTIES =
            new AnimationProperties().setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);

    private final Rect mOutlineRect = new Rect();
    private boolean mCustomOutline;
    private float mOutlineAlpha = -1f;
@@ -42,8 +63,10 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    private boolean mAlwaysRoundBothCorners;
    private Path mTmpPath = new Path();
    private Path mTmpPath2 = new Path();
    private float mCurrentBottomRoundness;
    private float mCurrentTopRoundness;
    private float mBottomRoundness;
    private float mTopRoundness;
    private float mBottomRoundNess;

    /**
     * {@code true} if the children views of the {@link ExpandableOutlineView} are translated when
@@ -94,15 +117,15 @@ public abstract class ExpandableOutlineView extends ExpandableView {
            return null;
        }
        float topRoundness = mAlwaysRoundBothCorners
                ? mOutlineRadius : mTopRoundness * mOutlineRadius;
                ? mOutlineRadius : mCurrentTopRoundness * mOutlineRadius;
        float bottomRoundness = mAlwaysRoundBothCorners
                ? mOutlineRadius : mBottomRoundNess * mOutlineRadius;
                ? mOutlineRadius : mCurrentBottomRoundness * mOutlineRadius;
        if (topRoundness + bottomRoundness > height) {
            float overShoot = topRoundness + bottomRoundness - height;
            topRoundness -= overShoot * mTopRoundness
                    / (mTopRoundness + mBottomRoundNess);
            bottomRoundness -= overShoot * mBottomRoundNess
                    / (mTopRoundness + mBottomRoundNess);
            topRoundness -= overShoot * mCurrentTopRoundness
                    / (mCurrentTopRoundness + mCurrentBottomRoundness);
            bottomRoundness -= overShoot * mCurrentBottomRoundness
                    / (mCurrentTopRoundness + mCurrentBottomRoundness);
        }
        getRoundedRectPath(left, top, right, bottom, topRoundness,
                bottomRoundness, mTmpPath);
@@ -158,8 +181,8 @@ public abstract class ExpandableOutlineView extends ExpandableView {
    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.save();
        if (needsContentClipping() && (mAlwaysRoundBothCorners || mTopRoundness > 0
                || mBottomRoundNess > 0 || mCustomOutline)) {
        if (needsContentClipping() && (mAlwaysRoundBothCorners || mCurrentTopRoundness > 0
                || mCurrentBottomRoundness > 0 || mCustomOutline)) {
            Path clipPath = getCustomClipPath();
            if (clipPath == null) {
                clipPath = getClipPath();
@@ -189,10 +212,11 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        setClipToOutline(mAlwaysRoundBothCorners);
    }

    public void setTopRoundness(float topRoundness) {
    public void setTopRoundness(float topRoundness, boolean animate) {
        if (mTopRoundness != topRoundness) {
            mTopRoundness = topRoundness;
            applyRoundness();
            PropertyAnimator.setProperty(this, TOP_ROUNDNESS, topRoundness,
                    ROUNDNESS_PROPERTIES, animate);
        }
    }

@@ -201,23 +225,39 @@ public abstract class ExpandableOutlineView extends ExpandableView {
        invalidate();
    }

    protected float getBackgroundRadiusTop() {
        return mTopRoundness * mOutlineRadius;
    protected float getCurrentBackgroundRadiusTop() {
        return mCurrentTopRoundness * mOutlineRadius;
    }

    protected float getCurrentTopRoundness() {
        return mCurrentTopRoundness;
    }

    protected float getCurrentBottomRoundness() {
        return mCurrentBottomRoundness;
    }

    protected float getTopRoundness() {
        return mTopRoundness;
    protected float getCurrentBackgroundRadiusBottom() {
        return mCurrentBottomRoundness * mOutlineRadius;
    }

    protected float getBackgroundRadiusBottom() {
        return mBottomRoundNess * mOutlineRadius;
    public void setBottomRoundNess(float bottomRoundness, boolean animate) {
        if (mBottomRoundness != bottomRoundness) {
            mBottomRoundness = bottomRoundness;
            PropertyAnimator.setProperty(this, BOTTOM_ROUNDNESS, bottomRoundness,
                    ROUNDNESS_PROPERTIES, animate);
        }
    }

    public void setBottomRoundNess(float bottomRoundness) {
        if (mBottomRoundNess != bottomRoundness) {
            mBottomRoundNess = bottomRoundness;

    private void setTopRoundnessInternal(float topRoundness) {
        mCurrentTopRoundness = topRoundness;
        applyRoundness();
    }

    private void setBottomRoundnessInternal(float bottomRoundness) {
        mCurrentBottomRoundness = bottomRoundness;
        applyRoundness();
    }

    public void onDensityOrFontScaleChanged() {
+4 −0
Original line number Diff line number Diff line
@@ -202,6 +202,10 @@ public abstract class ExpandableView extends FrameLayout {
        return mDark;
    }

    public boolean isRemoved() {
        return false;
    }

    /**
     * See {@link #setHideSensitive}. This is a variant which notifies this view in advance about
     * the upcoming state of hiding sensitive notifications. It gets called at the very beginning
Loading