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

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

Merge "Add some logs and call onAnimationEnd when animation canceled" into main

parents 32e3f7af 2f238aeb
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -26,18 +26,11 @@ import javax.inject.Inject

/** A logger for all events related to the media tap-to-transfer receiver experience. */
@SysUISingleton
class MediaTttReceiverLogger
@Inject
constructor(
    @MediaTttReceiverLogBuffer buffer: LogBuffer,
) : TemporaryViewLogger<ChipReceiverInfo>(buffer, TAG) {
class MediaTttReceiverLogger @Inject constructor(@MediaTttReceiverLogBuffer buffer: LogBuffer) :
    TemporaryViewLogger<ChipReceiverInfo>(buffer, TAG) {

    /** Logs a change in the chip state for the given [mediaRouteId]. */
    fun logStateChange(
        stateName: String,
        mediaRouteId: String,
        packageName: String?,
    ) {
    fun logStateChange(stateName: String, mediaRouteId: String, packageName: String?) {
        MediaTttLoggerUtils.logStateChange(buffer, TAG, stateName, mediaRouteId, packageName)
    }

@@ -51,12 +44,27 @@ constructor(
        MediaTttLoggerUtils.logPackageNotFound(buffer, TAG, packageName)
    }

    fun logRippleAnimationEnd(id: Int) {
    fun logRippleAnimationEnd(id: Int, type: String) {
        buffer.log(
            tag,
            LogLevel.DEBUG,
            { int1 = id },
            { "ripple animation for view with id: $int1 is ended" }
            {
                int1 = id
                str1 = type
            },
            { "ripple animation for view with id=$int1 is ended, animation type=$str1" },
        )
    }

    fun logRippleAnimationStart(id: Int, type: String) {
        buffer.log(
            tag,
            LogLevel.DEBUG,
            {
                int1 = id
                str1 = type
            },
            { "ripple animation for view with id=$int1 is started, animation type=$str1" },
        )
    }

+5 −3
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ constructor(
        )
        rippleView.addOnAttachStateChangeListener(
            object : View.OnAttachStateChangeListener {
                override fun onViewDetachedFromWindow(view: View) {}
                override fun onViewDetachedFromWindow(view: View) {
                    view.visibility = View.GONE
                }

                override fun onViewAttachedToWindow(view: View) {
                    if (view == null) {
@@ -81,7 +83,7 @@ constructor(
                    } else {
                        layoutRipple(attachedRippleView)
                    }
                    attachedRippleView.expandRipple()
                    attachedRippleView.expandRipple(mediaTttReceiverLogger)
                    attachedRippleView.removeOnAttachStateChangeListener(this)
                }
            }
@@ -126,7 +128,7 @@ constructor(
        iconRippleView.setMaxSize(radius * 0.8f, radius * 0.8f)
        iconRippleView.setCenter(
            width * 0.5f,
            height - getReceiverIconSize() * 0.5f - getReceiverIconBottomMargin()
            height - getReceiverIconSize() * 0.5f - getReceiverIconBottomMargin(),
        )
        iconRippleView.setColor(getRippleColor(), RIPPLE_OPACITY)
    }
+22 −5
Original line number Diff line number Diff line
@@ -37,10 +37,14 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
        isStarted = false
    }

    fun expandRipple(onAnimationEnd: Runnable? = null) {
    fun expandRipple(logger: MediaTttReceiverLogger, onAnimationEnd: Runnable? = null) {
        duration = DEFAULT_DURATION
        isStarted = true
        super.startRipple(onAnimationEnd)
        super.startRipple {
            logger.logRippleAnimationEnd(id, EXPAND)
            onAnimationEnd?.run()
        }
        logger.logRippleAnimationStart(id, EXPAND)
    }

    /** Used to animate out the ripple. No-op if the ripple was never started via [startRipple]. */
@@ -53,10 +57,14 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
        animator.removeAllListeners()
        animator.addListener(
            object : AnimatorListenerAdapter() {
                override fun onAnimationCancel(animation: Animator) {
                    onAnimationEnd(animation)
                }

                override fun onAnimationEnd(animation: Animator) {
                    animation?.let {
                        visibility = GONE
                        logger.logRippleAnimationEnd(id)
                        logger.logRippleAnimationEnd(id, COLLAPSE)
                    }
                    onAnimationEnd?.run()
                    isStarted = false
@@ -64,13 +72,14 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
            }
        )
        animator.reverse()
        logger.logRippleAnimationStart(id, COLLAPSE)
    }

    // Expands the ripple to cover full screen.
    fun expandToFull(
        newHeight: Float,
        logger: MediaTttReceiverLogger,
        onAnimationEnd: Runnable? = null
        onAnimationEnd: Runnable? = null,
    ) {
        if (!isStarted) {
            return
@@ -95,10 +104,14 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
        }
        animator.addListener(
            object : AnimatorListenerAdapter() {
                override fun onAnimationCancel(animation: Animator) {
                    onAnimationEnd(animation)
                }

                override fun onAnimationEnd(animation: Animator) {
                    animation?.let {
                        visibility = GONE
                        logger.logRippleAnimationEnd(id)
                        logger.logRippleAnimationEnd(id, EXPAND_TO_FULL)
                    }
                    onAnimationEnd?.run()
                    isStarted = false
@@ -106,6 +119,7 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
            }
        )
        animator.start()
        logger.logRippleAnimationStart(id, EXPAND_TO_FULL)
    }

    // Calculates the actual starting percentage according to ripple shader progress set method.
@@ -151,5 +165,8 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi
    companion object {
        const val DEFAULT_DURATION = 333L
        const val EXPAND_TO_FULL_DURATION = 1000L
        private const val COLLAPSE = "collapse"
        private const val EXPAND_TO_FULL = "expand to full"
        private const val EXPAND = "expand"
    }
}