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

Commit 31926475 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Fallback to KeygaurdSliceView for clock switch when smartspace unavailable

Bug: 327249281
Test: Manually checked animation on mokey
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint STAGING
Change-Id: Ie758caa9c7c0f0410b2a50d0e4eebf3cc6dcff2b
parent c1a39ae2
Loading
Loading
Loading
Loading
+26 −17
Original line number Original line Diff line number Diff line
@@ -38,6 +38,8 @@ import com.android.systemui.shared.R as sharedR
import com.google.android.material.math.MathUtils
import com.google.android.material.math.MathUtils
import kotlin.math.abs
import kotlin.math.abs


internal fun View.getRect(): Rect = Rect(this.left, this.top, this.right, this.bottom)

internal fun View.setRect(rect: Rect) =
internal fun View.setRect(rect: Rect) =
    this.setLeftTopRightBottom(rect.left, rect.top, rect.right, rect.bottom)
    this.setLeftTopRightBottom(rect.left, rect.top, rect.right, rect.bottom)


@@ -66,12 +68,18 @@ class ClockSizeTransition(
            val view = transition.view
            val view = transition.view
            transition.values[PROP_VISIBILITY] = view.visibility
            transition.values[PROP_VISIBILITY] = view.visibility
            transition.values[PROP_ALPHA] = view.alpha
            transition.values[PROP_ALPHA] = view.alpha
            transition.values[PROP_BOUNDS] = Rect(view.left, view.top, view.right, view.bottom)
            transition.values[PROP_BOUNDS] = view.getRect()


            if (!captureSmartspace) return
            if (!captureSmartspace) return
            val ss = (view.parent as View).findViewById<View>(sharedR.id.bc_smartspace_view)
            val parent = view.parent as View
            if (ss == null) return
            val targetSSView =
            transition.values[SMARTSPACE_BOUNDS] = Rect(ss.left, ss.top, ss.right, ss.bottom)
                parent.findViewById<View>(sharedR.id.bc_smartspace_view)
                    ?: parent.findViewById<View>(R.id.keyguard_slice_view)
            if (targetSSView == null) {
                Log.e(TAG, "Failed to find smartspace equivalent target for animation")
                return
            }
            transition.values[SMARTSPACE_BOUNDS] = targetSSView.getRect()
        }
        }


        open fun mutateBounds(
        open fun mutateBounds(
@@ -89,7 +97,13 @@ class ClockSizeTransition(
            startValues: TransitionValues?,
            startValues: TransitionValues?,
            endValues: TransitionValues?
            endValues: TransitionValues?
        ): Animator? {
        ): Animator? {
            if (startValues == null || endValues == null) return null
            if (startValues == null || endValues == null) {
                Log.w(
                    TAG,
                    "Couldn't create animator: startValues=$startValues; endValues=$endValues"
                )
                return null
            }


            var fromVis = startValues.values[PROP_VISIBILITY] as Int
            var fromVis = startValues.values[PROP_VISIBILITY] as Int
            var fromIsVis = fromVis == View.VISIBLE
            var fromIsVis = fromVis == View.VISIBLE
@@ -141,11 +155,12 @@ class ClockSizeTransition(
            fun assignAnimValues(src: String, fract: Float, vis: Int? = null) {
            fun assignAnimValues(src: String, fract: Float, vis: Int? = null) {
                val bounds = computeBounds(fract)
                val bounds = computeBounds(fract)
                val alpha = MathUtils.lerp(fromAlpha, toAlpha, fract)
                val alpha = MathUtils.lerp(fromAlpha, toAlpha, fract)
                if (DEBUG)
                if (DEBUG) {
                    Log.i(
                    Log.i(
                        TAG,
                        TAG,
                        "$src: $toView; fract=$fract; alpha=$alpha; vis=$vis; bounds=$bounds;"
                        "$src: $toView; fract=$fract; alpha=$alpha; vis=$vis; bounds=$bounds;"
                    )
                    )
                }
                toView.setVisibility(vis ?: View.VISIBLE)
                toView.setVisibility(vis ?: View.VISIBLE)
                toView.setAlpha(alpha)
                toView.setAlpha(alpha)
                toView.setRect(bounds)
                toView.setRect(bounds)
@@ -245,12 +260,9 @@ class ClockSizeTransition(
            // Move normally if clock is not changing visibility
            // Move normally if clock is not changing visibility
            if (fromIsVis == toIsVis) return
            if (fromIsVis == toIsVis) return


            fromBounds.left = toBounds.left
            fromBounds.set(toBounds)
            fromBounds.right = toBounds.right
            if (viewModel.isLargeClockVisible.value) {
            if (viewModel.isLargeClockVisible.value) {
                // Large clock shouldn't move
                // Large clock shouldn't move; fromBounds already set
                fromBounds.top = toBounds.top
                fromBounds.bottom = toBounds.bottom
            } else if (toSSBounds != null && fromSSBounds != null) {
            } else if (toSSBounds != null && fromSSBounds != null) {
                // Instead of moving the small clock the full distance, we compute the distance
                // Instead of moving the small clock the full distance, we compute the distance
                // smartspace will move. We then scale this to match the duration of this animation
                // smartspace will move. We then scale this to match the duration of this animation
@@ -306,12 +318,9 @@ class ClockSizeTransition(
            // Move normally if clock is not changing visibility
            // Move normally if clock is not changing visibility
            if (fromIsVis == toIsVis) return
            if (fromIsVis == toIsVis) return


            toBounds.left = fromBounds.left
            toBounds.set(fromBounds)
            toBounds.right = fromBounds.right
            if (!viewModel.isLargeClockVisible.value) {
            if (!viewModel.isLargeClockVisible.value) {
                // Large clock shouldn't move
                // Large clock shouldn't move; toBounds already set
                toBounds.top = fromBounds.top
                toBounds.bottom = fromBounds.bottom
            } else if (toSSBounds != null && fromSSBounds != null) {
            } else if (toSSBounds != null && fromSSBounds != null) {
                // Instead of moving the small clock the full distance, we compute the distance
                // Instead of moving the small clock the full distance, we compute the distance
                // smartspace will move. We then scale this to match the duration of this animation
                // smartspace will move. We then scale this to match the duration of this animation
@@ -321,7 +330,7 @@ class ClockSizeTransition(
                toBounds.top = fromBounds.top - ssTranslation
                toBounds.top = fromBounds.top - ssTranslation
                toBounds.bottom = fromBounds.bottom - ssTranslation
                toBounds.bottom = fromBounds.bottom - ssTranslation
            } else {
            } else {
                Log.w(TAG, "mutateBounds: smallClock received no smartspace bounds")
                Log.e(TAG, "mutateBounds: smallClock received no smartspace bounds")
            }
            }
        }
        }