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

Commit 5ec669db authored by Aaron Liu's avatar Aaron Liu
Browse files

Add transition layer between blueprints.

Invoke TransitionManager#beginDelayedTransition with our own transition.
The default transition, AutoTransition, does not work well with our
current clock because of its canvas caching and the Fade animation that
aniamtes the transition alpha. Directly animating the alpha seems to
work better.

Bug: 288464062
Test: switch between blueprints
Change-Id: If4e244d7558eb1b558d94b375ff7e7f453288d29
parent 96fe7f89
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@
package com.android.systemui.keyguard.ui.binder

import android.os.Trace
import android.transition.TransitionManager
import android.util.Log
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.keyguard.ui.view.layout.blueprints.transitions.BaseBlueprintTransition
import com.android.systemui.keyguard.ui.viewmodel.KeyguardBlueprintViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import kotlinx.coroutines.launch
@@ -40,16 +42,28 @@ class KeyguardBlueprintViewBinder {
                            Trace.beginSection("KeyguardBlueprint#applyBlueprint")
                            Log.d(TAG, "applying blueprint: $blueprint")

                            val cs =
                                ConstraintSet().apply {
                                    clone(constraintLayout)
                                    val emptyLayout = ConstraintSet.Layout()
                                knownIds.forEach { getConstraint(it).layout.copyFrom(emptyLayout) }
                                    knownIds.forEach {
                                        getConstraint(it).layout.copyFrom(emptyLayout)
                                    }
                                    blueprint.applyConstraints(this)
                                }

                            // Apply transition.
                            if (prevBluePrint != null && prevBluePrint != blueprint) {
                                TransitionManager.beginDelayedTransition(
                                    constraintLayout,
                                    BaseBlueprintTransition()
                                )
                            }

                            // Add and remove views of sections that are not contained by the
                            // other.
                                blueprint?.replaceViews(prevBluePrint, constraintLayout)
                                applyTo(constraintLayout)
                            }
                            blueprint.replaceViews(prevBluePrint, constraintLayout)
                            cs.applyTo(constraintLayout)

                            viewModel.currentBluePrint = blueprint
                            Trace.endSection()
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.view.layout.blueprints.transitions

import android.animation.Animator
import android.animation.ObjectAnimator
import android.transition.ChangeBounds
import android.transition.TransitionSet
import android.transition.TransitionValues
import android.transition.Visibility
import android.view.View
import android.view.ViewGroup

class BaseBlueprintTransition : TransitionSet() {
    init {
        ordering = ORDERING_SEQUENTIAL
        addTransition(AlphaOutVisibility())
            .addTransition(ChangeBounds())
            .addTransition(AlphaInVisibility())
    }
    class AlphaOutVisibility : Visibility() {
        override fun onDisappear(
            sceneRoot: ViewGroup?,
            view: View,
            startValues: TransitionValues?,
            endValues: TransitionValues?
        ): Animator {
            return ObjectAnimator.ofFloat(view, "alpha", 0f).apply {
                addUpdateListener { view.alpha = it.animatedValue as Float }
                start()
            }
        }
    }

    class AlphaInVisibility : Visibility() {
        override fun onAppear(
            sceneRoot: ViewGroup?,
            view: View,
            startValues: TransitionValues?,
            endValues: TransitionValues?
        ): Animator {
            return ObjectAnimator.ofFloat(view, "alpha", 1f).apply {
                addUpdateListener { view.alpha = it.animatedValue as Float }
                start()
            }
        }
    }
}