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

Commit aedb139c authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

Merge "Big clock was not centering correctly on splitshade" into main

parents d1e2bc06 1566653d
Loading
Loading
Loading
Loading
+36 −22
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
import com.android.systemui.res.R
import com.android.systemui.shared.R as sharedR
import com.google.android.material.math.MathUtils
import kotlin.math.abs

internal fun View.setRect(rect: Rect) =
@@ -59,15 +60,6 @@ class ClockSizeTransition(
        override fun captureEndValues(transition: TransitionValues) = captureValues(transition)
        override fun captureStartValues(transition: TransitionValues) = captureValues(transition)
        override fun getTransitionProperties(): Array<String> = TRANSITION_PROPERTIES
        open fun mutateBounds(
            view: View,
            fromVis: Int,
            toVis: Int,
            fromBounds: Rect,
            toBounds: Rect,
            fromSSBounds: Rect?,
            toSSBounds: Rect?
        ) {}

        private fun captureValues(transition: TransitionValues) {
            val view = transition.view
@@ -81,6 +73,16 @@ class ClockSizeTransition(
            transition.values[SMARTSPACE_BOUNDS] = Rect(ss.left, ss.top, ss.right, ss.bottom)
        }

        open fun mutateBounds(
            view: View,
            fromIsVis: Boolean,
            toIsVis: Boolean,
            fromBounds: Rect,
            toBounds: Rect,
            fromSSBounds: Rect?,
            toSSBounds: Rect?
        ) {}

        override fun createAnimator(
            sceenRoot: ViewGroup,
            startValues: TransitionValues?,
@@ -88,7 +90,6 @@ class ClockSizeTransition(
        ): Animator? {
            if (startValues == null || endValues == null) return null

            val fromView = startValues.view
            var fromVis = startValues.values[PROP_VISIBILITY] as Int
            var fromIsVis = fromVis == View.VISIBLE
            var fromAlpha = startValues.values[PROP_ALPHA] as Float
@@ -111,7 +112,7 @@ class ClockSizeTransition(
                fromVis = View.INVISIBLE
            }

            mutateBounds(toView, fromVis, toVis, fromBounds, toBounds, fromSSBounds, toSSBounds)
            mutateBounds(toView, fromIsVis, toIsVis, fromBounds, toBounds, fromSSBounds, toSSBounds)
            if (fromIsVis == toIsVis && fromBounds.equals(toBounds)) {
                if (DEBUG) {
                    Log.w(
@@ -127,7 +128,7 @@ class ClockSizeTransition(

            val sendToBack = fromIsVis && !toIsVis
            fun lerp(start: Int, end: Int, fract: Float): Int =
                (start * (1f - fract) + end * fract).toInt()
                MathUtils.lerp(start.toFloat(), end.toFloat(), fract).toInt()
            fun computeBounds(fract: Float): Rect =
                Rect(
                    lerp(fromBounds.left, toBounds.left, fract),
@@ -136,9 +137,14 @@ class ClockSizeTransition(
                    lerp(fromBounds.bottom, toBounds.bottom, fract)
                )

            fun assignAnimValues(src: String, alpha: Float, fract: Float, vis: Int? = null) {
            fun assignAnimValues(src: String, fract: Float, vis: Int? = null) {
                val bounds = computeBounds(fract)
                if (DEBUG) Log.i(TAG, "$src: $toView; alpha=$alpha; vis=$vis; bounds=$bounds;")
                val alpha = MathUtils.lerp(fromAlpha, toAlpha, fract)
                if (DEBUG)
                    Log.i(
                        TAG,
                        "$src: $toView; fract=$fract; alpha=$alpha; vis=$vis; bounds=$bounds;"
                    )
                toView.setVisibility(vis ?: View.VISIBLE)
                toView.setAlpha(alpha)
                toView.setRect(bounds)
@@ -154,12 +160,12 @@ class ClockSizeTransition(
                )
            }

            return ValueAnimator.ofFloat(fromAlpha, toAlpha).also { anim ->
            return ValueAnimator.ofFloat(0f, 1f).also { anim ->
                // We enforce the animation parameters on the target view every frame using a
                // predraw listener. This is suboptimal but prevents issues with layout passes
                // overwriting the animation for individual frames.
                val predrawCallback = OnPreDrawListener {
                    assignAnimValues("predraw", anim.animatedValue as Float, anim.animatedFraction)
                    assignAnimValues("predraw", anim.animatedFraction)
                    return@OnPreDrawListener true
                }

@@ -169,16 +175,18 @@ class ClockSizeTransition(
                anim.addListener(
                    object : AnimatorListenerAdapter() {
                        override fun onAnimationStart(anim: Animator) {
                            assignAnimValues("start", fromAlpha, 0f)
                            assignAnimValues("start", 0f, fromVis)
                        }

                        override fun onAnimationEnd(anim: Animator) {
                            assignAnimValues("end", toAlpha, 1f, toVis)
                            assignAnimValues("end", 1f, toVis)
                            if (sendToBack) toView.translationZ = 0f
                            toView.viewTreeObserver.removeOnPreDrawListener(predrawCallback)
                        }
                    }
                )

                assignAnimValues("init", 0f, fromVis)
                toView.viewTreeObserver.addOnPreDrawListener(predrawCallback)
            }
        }
@@ -216,13 +224,16 @@ class ClockSizeTransition(

        override fun mutateBounds(
            view: View,
            fromVis: Int,
            toVis: Int,
            fromIsVis: Boolean,
            toIsVis: Boolean,
            fromBounds: Rect,
            toBounds: Rect,
            fromSSBounds: Rect?,
            toSSBounds: Rect?
        ) {
            // Move normally if clock is not changing visibility
            if (fromIsVis == toIsVis) return

            fromBounds.left = toBounds.left
            fromBounds.right = toBounds.right
            if (viewModel.useLargeClock) {
@@ -271,13 +282,16 @@ class ClockSizeTransition(

        override fun mutateBounds(
            view: View,
            fromVis: Int,
            toVis: Int,
            fromIsVis: Boolean,
            toIsVis: Boolean,
            fromBounds: Rect,
            toBounds: Rect,
            fromSSBounds: Rect?,
            toSSBounds: Rect?
        ) {
            // Move normally if clock is not changing visibility
            if (fromIsVis == toIsVis) return

            toBounds.left = fromBounds.left
            toBounds.right = fromBounds.right
            if (!viewModel.useLargeClock) {
+2 −2
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ class DefaultClockSteppingTransition(
    }

    companion object {
        private const val PROP_BOUNDS_LEFT = "splitShadeTransitionAdapter:boundsLeft"
        private const val PROP_X_IN_WINDOW = "splitShadeTransitionAdapter:xInWindow"
        private const val PROP_BOUNDS_LEFT = "DefaultClockSteppingTransition:boundsLeft"
        private const val PROP_X_IN_WINDOW = "DefaultClockSteppingTransition:xInWindow"
        private val TRANSITION_PROPERTIES = arrayOf(PROP_BOUNDS_LEFT, PROP_X_IN_WINDOW)
        private const val KEYGUARD_STATUS_VIEW_CUSTOM_CLOCK_MOVE_DURATION_MS = 1000L
    }