Merge "Find a background to animate when launching a dialog or activity" into tm-dev am: 18906f73ef
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17075008 Change-Id: I6d0407838e71b0bb623f7e46161c0cf0db0fa88a
This commit is contained in:
@@ -33,6 +33,7 @@ import android.view.ViewGroup
|
|||||||
import android.view.ViewGroupOverlay
|
import android.view.ViewGroupOverlay
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import com.android.internal.jank.InteractionJankMonitor
|
import com.android.internal.jank.InteractionJankMonitor
|
||||||
|
import java.util.LinkedList
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
private const val TAG = "GhostedViewLaunchAnimatorController"
|
private const val TAG = "GhostedViewLaunchAnimatorController"
|
||||||
@@ -81,21 +82,51 @@ open class GhostedViewLaunchAnimatorController(
|
|||||||
* [backgroundView].
|
* [backgroundView].
|
||||||
*/
|
*/
|
||||||
private var backgroundDrawable: WrappedDrawable? = null
|
private var backgroundDrawable: WrappedDrawable? = null
|
||||||
private val backgroundInsets by lazy { getBackground()?.opticalInsets ?: Insets.NONE }
|
private val backgroundInsets by lazy { background?.opticalInsets ?: Insets.NONE }
|
||||||
private var startBackgroundAlpha: Int = 0xFF
|
private var startBackgroundAlpha: Int = 0xFF
|
||||||
|
|
||||||
private val ghostedViewLocation = IntArray(2)
|
private val ghostedViewLocation = IntArray(2)
|
||||||
private val ghostedViewState = LaunchAnimator.State()
|
private val ghostedViewState = LaunchAnimator.State()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the background of the [ghostedView]. This background will be used to draw the
|
* The background of the [ghostedView]. This background will be used to draw the background of
|
||||||
* background of the background view that is expanding up to the final animation position. This
|
* the background view that is expanding up to the final animation position.
|
||||||
* is called at the start of the animation.
|
|
||||||
*
|
*
|
||||||
* Note that during the animation, the alpha value value of this background will be set to 0,
|
* Note that during the animation, the alpha value value of this background will be set to 0,
|
||||||
* then set back to its initial value at the end of the animation.
|
* then set back to its initial value at the end of the animation.
|
||||||
*/
|
*/
|
||||||
protected open fun getBackground(): Drawable? = ghostedView.background
|
private val background: Drawable?
|
||||||
|
|
||||||
|
init {
|
||||||
|
/** Find the first view with a background in [view] and its children. */
|
||||||
|
fun findBackground(view: View): Drawable? {
|
||||||
|
if (view.background != null) {
|
||||||
|
return view.background
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform a BFS to find the largest View with background.
|
||||||
|
val views = LinkedList<View>().apply {
|
||||||
|
add(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
while (views.isNotEmpty()) {
|
||||||
|
val v = views.removeFirst()
|
||||||
|
if (v.background != null) {
|
||||||
|
return v.background
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v is ViewGroup) {
|
||||||
|
for (i in 0 until v.childCount) {
|
||||||
|
views.add(v.getChildAt(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
background = findBackground(ghostedView)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the corner radius of [background]. The background is the one that was returned by
|
* Set the corner radius of [background]. The background is the one that was returned by
|
||||||
@@ -113,7 +144,7 @@ open class GhostedViewLaunchAnimatorController(
|
|||||||
|
|
||||||
/** Return the current top corner radius of the background. */
|
/** Return the current top corner radius of the background. */
|
||||||
protected open fun getCurrentTopCornerRadius(): Float {
|
protected open fun getCurrentTopCornerRadius(): Float {
|
||||||
val drawable = getBackground() ?: return 0f
|
val drawable = background ?: return 0f
|
||||||
val gradient = findGradientDrawable(drawable) ?: return 0f
|
val gradient = findGradientDrawable(drawable) ?: return 0f
|
||||||
|
|
||||||
// TODO(b/184121838): Support more than symmetric top & bottom radius.
|
// TODO(b/184121838): Support more than symmetric top & bottom radius.
|
||||||
@@ -122,7 +153,7 @@ open class GhostedViewLaunchAnimatorController(
|
|||||||
|
|
||||||
/** Return the current bottom corner radius of the background. */
|
/** Return the current bottom corner radius of the background. */
|
||||||
protected open fun getCurrentBottomCornerRadius(): Float {
|
protected open fun getCurrentBottomCornerRadius(): Float {
|
||||||
val drawable = getBackground() ?: return 0f
|
val drawable = background ?: return 0f
|
||||||
val gradient = findGradientDrawable(drawable) ?: return 0f
|
val gradient = findGradientDrawable(drawable) ?: return 0f
|
||||||
|
|
||||||
// TODO(b/184121838): Support more than symmetric top & bottom radius.
|
// TODO(b/184121838): Support more than symmetric top & bottom radius.
|
||||||
@@ -162,9 +193,8 @@ open class GhostedViewLaunchAnimatorController(
|
|||||||
|
|
||||||
// We wrap the ghosted view background and use it to draw the expandable background. Its
|
// We wrap the ghosted view background and use it to draw the expandable background. Its
|
||||||
// alpha will be set to 0 as soon as we start drawing the expanding background.
|
// alpha will be set to 0 as soon as we start drawing the expanding background.
|
||||||
val drawable = getBackground()
|
startBackgroundAlpha = background?.alpha ?: 0xFF
|
||||||
startBackgroundAlpha = drawable?.alpha ?: 0xFF
|
backgroundDrawable = WrappedDrawable(background)
|
||||||
backgroundDrawable = WrappedDrawable(drawable)
|
|
||||||
backgroundView?.background = backgroundDrawable
|
backgroundView?.background = backgroundDrawable
|
||||||
|
|
||||||
// Create a ghost of the view that will be moving and fading out. This allows to fade out
|
// Create a ghost of the view that will be moving and fading out. This allows to fade out
|
||||||
|
|||||||
Reference in New Issue
Block a user