Merge "Init MediaHost with KeyguardMediaController's initialization, not wait until the controller is attached." into sc-dev

This commit is contained in:
Cecilia Hong
2021-04-28 12:44:22 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 6 deletions

View File

@@ -54,6 +54,14 @@ class KeyguardMediaController @Inject constructor(
}
}
})
// First let's set the desired state that we want for this host
mediaHost.expansion = MediaHostState.COLLAPSED
mediaHost.showsOnlyActiveMedia = true
mediaHost.falsingProtectionNeeded = true
// Let's now initialize this view, which also creates the host view for us.
mediaHost.init(MediaHierarchyManager.LOCATION_LOCKSCREEN)
}
var visibilityChangedListener: ((Boolean) -> Unit)? = null
@@ -71,13 +79,7 @@ class KeyguardMediaController @Inject constructor(
*/
fun attachSinglePaneContainer(mediaView: MediaHeaderView?) {
singlePaneContainer = mediaView
// First let's set the desired state that we want for this host
mediaHost.expansion = MediaHostState.COLLAPSED
mediaHost.showsOnlyActiveMedia = true
mediaHost.falsingProtectionNeeded = true
// Let's now initialize this view, which also creates the host view for us.
mediaHost.init(MediaHierarchyManager.LOCATION_LOCKSCREEN)
// Required to show it for the first time, afterwards visibility is managed automatically
mediaHost.visible = true
mediaHost.addVisibilityChangeListener { visible ->
@@ -133,6 +135,10 @@ class KeyguardMediaController @Inject constructor(
}
// might be called a few times for the same view, no need to add hostView again
if (activeContainer?.childCount == 0) {
// Detach the hostView from its parent view if exists
mediaHost.hostView.parent ?.let {
(it as? ViewGroup)?.removeView(mediaHost.hostView)
}
activeContainer.addView(mediaHost.hostView)
}
setVisibility(activeContainer, View.VISIBLE)

View File

@@ -25,6 +25,8 @@ class MediaHost constructor(
private val tmpLocationOnScreen: IntArray = intArrayOf(0, 0)
private var inited: Boolean = false
/**
* Get the current bounds on the screen. This makes sure the state is fresh and up to date
*/
@@ -84,6 +86,11 @@ class MediaHost constructor(
* transitions.
*/
fun init(@MediaLocation location: Int) {
if (inited) {
return
}
inited = true
this.location = location
hostView = mediaHierarchyManager.register(this)
hostView.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {