Loading packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/blueprints/DefaultCommunalBlueprint.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ constructor( defaultCommunalWidgetSection: DefaultCommunalWidgetSection, ) : KeyguardBlueprint { override val id: String = COMMUNAL override val sections: Array<KeyguardSection> = arrayOf(defaultCommunalWidgetSection) override val sections: Set<KeyguardSection> = setOf(defaultCommunalWidgetSection) companion object { const val COMMUNAL = "communal" Loading packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/DefaultCommunalWidgetSection.kt +7 −2 Original line number Diff line number Diff line Loading @@ -42,9 +42,12 @@ constructor( private val communalWidgetViewModel: CommunalWidgetViewModel, private val communalWidgetViewAdapter: CommunalWidgetViewAdapter, private val keyguardBlueprintInteractor: Lazy<KeyguardBlueprintInteractor>, ) : KeyguardSection { ) : KeyguardSection() { private val widgetAreaViewId = R.id.communal_widget_wrapper override fun addViews(constraintLayout: ConstraintLayout) { override fun addViews(constraintLayout: ConstraintLayout) {} override fun bindData(constraintLayout: ConstraintLayout) { if (!featureFlags.isEnabled(Flags.WIDGET_ON_KEYGUARD)) { return } Loading @@ -65,4 +68,6 @@ constructor( connect(widgetAreaViewId, END, PARENT_ID, END) } } override fun removeViews(constraintLayout: ConstraintLayout) {} } packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardBlueprint.kt +24 −7 Original line number Diff line number Diff line Loading @@ -22,17 +22,34 @@ import androidx.constraintlayout.widget.ConstraintSet /** Determines the constraints for the ConstraintSet in the lockscreen root view. */ interface KeyguardBlueprint { val id: String val sections: Array<KeyguardSection> val sections: Set<KeyguardSection> fun addViews(constraintLayout: ConstraintLayout) { sections.forEach { it.addViews(constraintLayout) } /** * Add views to new blueprint. * * Finds sections that did not exist in the previous blueprint and add the corresponding views. * * @param previousBluePrint: KeyguardBlueprint the blueprint we are transitioning from. */ fun addViews(previousBlueprint: KeyguardBlueprint?, constraintLayout: ConstraintLayout) { sections.subtract((previousBlueprint?.sections ?: setOf()).toSet()).forEach { it.addViews(constraintLayout) it.bindData(constraintLayout) } } fun applyConstraints(constraintSet: ConstraintSet) { sections.forEach { it.applyConstraints(constraintSet) } /** * Remove views of old blueprint. * * Finds sections that are no longer in the next blueprint and remove the corresponding views. * * @param nextBluePrint: KeyguardBlueprint the blueprint we will transition to. */ fun removeViews(nextBlueprint: KeyguardBlueprint, constraintLayout: ConstraintLayout) { sections.subtract(nextBlueprint.sections).forEach { it.removeViews(constraintLayout) } } fun onDestroy() { sections.forEach { it.onDestroy() } fun applyConstraints(constraintSet: ConstraintSet) { sections.forEach { it.applyConstraints(constraintSet) } } } packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardSection.kt +30 −4 Original line number Diff line number Diff line Loading @@ -23,8 +23,34 @@ import androidx.constraintlayout.widget.ConstraintSet * Lower level modules that determine constraints for a particular section in the lockscreen root * view. */ interface KeyguardSection { fun addViews(constraintLayout: ConstraintLayout) fun applyConstraints(constraintSet: ConstraintSet) fun onDestroy() {} abstract class KeyguardSection { /** Adds the views to the root view. */ abstract fun addViews(constraintLayout: ConstraintLayout) /** Binds the views to data. */ abstract fun bindData(constraintLayout: ConstraintLayout) /** Applies layout constraints to the view in respect to the root view. */ abstract fun applyConstraints(constraintSet: ConstraintSet) /** Removes views and does any data binding destruction. */ abstract fun removeViews(constraintLayout: ConstraintLayout) /** * Defines equality as same class. * * This is to enable set operations to be done as an optimization to blueprint transitions. */ override fun equals(other: Any?): Boolean { other?.let { other -> return this::class == other::class } return false } /** * Defines hashcode as class. * * This is to enable set operations to be done as an optimization to blueprint transitions. */ override fun hashCode(): Int { return this::class.hashCode() } } packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt +11 −18 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.os.Trace import android.util.Log import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet import androidx.core.view.children import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.systemui.keyguard.ui.viewmodel.KeyguardBlueprintViewModel Loading @@ -37,26 +36,20 @@ class KeyguardBlueprintViewBinder { repeatOnLifecycle(Lifecycle.State.CREATED) { launch { viewModel.blueprint.collect { blueprint -> val prevBluePrint = viewModel.currentBluePrint Trace.beginSection("KeyguardBlueprint#applyBlueprint") Log.d(TAG, "applying blueprint: $blueprint") if (blueprint != viewModel.currentBluePrint) { viewModel.currentBluePrint?.onDestroy() } val constraintSet = // Add and remove views of sections that are not contained by the other. prevBluePrint?.removeViews(blueprint, constraintLayout) blueprint.addViews(prevBluePrint, constraintLayout) ConstraintSet().apply { clone(constraintLayout) val emptyLayout = ConstraintSet.Layout() knownIds.forEach { getConstraint(it).layout.copyFrom(emptyLayout) } blueprint.addViews(constraintLayout) knownIds.forEach { getConstraint(it).layout.copyFrom(emptyLayout) } blueprint.applyConstraints(this) applyTo(constraintLayout) } // Remove all unconstrained views. constraintLayout.children .filterNot { constraintSet.knownIds.contains(it.id) } .forEach { constraintLayout.removeView(it) } viewModel.currentBluePrint = blueprint Trace.endSection() Loading Loading
packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/blueprints/DefaultCommunalBlueprint.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ constructor( defaultCommunalWidgetSection: DefaultCommunalWidgetSection, ) : KeyguardBlueprint { override val id: String = COMMUNAL override val sections: Array<KeyguardSection> = arrayOf(defaultCommunalWidgetSection) override val sections: Set<KeyguardSection> = setOf(defaultCommunalWidgetSection) companion object { const val COMMUNAL = "communal" Loading
packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/DefaultCommunalWidgetSection.kt +7 −2 Original line number Diff line number Diff line Loading @@ -42,9 +42,12 @@ constructor( private val communalWidgetViewModel: CommunalWidgetViewModel, private val communalWidgetViewAdapter: CommunalWidgetViewAdapter, private val keyguardBlueprintInteractor: Lazy<KeyguardBlueprintInteractor>, ) : KeyguardSection { ) : KeyguardSection() { private val widgetAreaViewId = R.id.communal_widget_wrapper override fun addViews(constraintLayout: ConstraintLayout) { override fun addViews(constraintLayout: ConstraintLayout) {} override fun bindData(constraintLayout: ConstraintLayout) { if (!featureFlags.isEnabled(Flags.WIDGET_ON_KEYGUARD)) { return } Loading @@ -65,4 +68,6 @@ constructor( connect(widgetAreaViewId, END, PARENT_ID, END) } } override fun removeViews(constraintLayout: ConstraintLayout) {} }
packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardBlueprint.kt +24 −7 Original line number Diff line number Diff line Loading @@ -22,17 +22,34 @@ import androidx.constraintlayout.widget.ConstraintSet /** Determines the constraints for the ConstraintSet in the lockscreen root view. */ interface KeyguardBlueprint { val id: String val sections: Array<KeyguardSection> val sections: Set<KeyguardSection> fun addViews(constraintLayout: ConstraintLayout) { sections.forEach { it.addViews(constraintLayout) } /** * Add views to new blueprint. * * Finds sections that did not exist in the previous blueprint and add the corresponding views. * * @param previousBluePrint: KeyguardBlueprint the blueprint we are transitioning from. */ fun addViews(previousBlueprint: KeyguardBlueprint?, constraintLayout: ConstraintLayout) { sections.subtract((previousBlueprint?.sections ?: setOf()).toSet()).forEach { it.addViews(constraintLayout) it.bindData(constraintLayout) } } fun applyConstraints(constraintSet: ConstraintSet) { sections.forEach { it.applyConstraints(constraintSet) } /** * Remove views of old blueprint. * * Finds sections that are no longer in the next blueprint and remove the corresponding views. * * @param nextBluePrint: KeyguardBlueprint the blueprint we will transition to. */ fun removeViews(nextBlueprint: KeyguardBlueprint, constraintLayout: ConstraintLayout) { sections.subtract(nextBlueprint.sections).forEach { it.removeViews(constraintLayout) } } fun onDestroy() { sections.forEach { it.onDestroy() } fun applyConstraints(constraintSet: ConstraintSet) { sections.forEach { it.applyConstraints(constraintSet) } } }
packages/SystemUI/src/com/android/systemui/keyguard/shared/model/KeyguardSection.kt +30 −4 Original line number Diff line number Diff line Loading @@ -23,8 +23,34 @@ import androidx.constraintlayout.widget.ConstraintSet * Lower level modules that determine constraints for a particular section in the lockscreen root * view. */ interface KeyguardSection { fun addViews(constraintLayout: ConstraintLayout) fun applyConstraints(constraintSet: ConstraintSet) fun onDestroy() {} abstract class KeyguardSection { /** Adds the views to the root view. */ abstract fun addViews(constraintLayout: ConstraintLayout) /** Binds the views to data. */ abstract fun bindData(constraintLayout: ConstraintLayout) /** Applies layout constraints to the view in respect to the root view. */ abstract fun applyConstraints(constraintSet: ConstraintSet) /** Removes views and does any data binding destruction. */ abstract fun removeViews(constraintLayout: ConstraintLayout) /** * Defines equality as same class. * * This is to enable set operations to be done as an optimization to blueprint transitions. */ override fun equals(other: Any?): Boolean { other?.let { other -> return this::class == other::class } return false } /** * Defines hashcode as class. * * This is to enable set operations to be done as an optimization to blueprint transitions. */ override fun hashCode(): Int { return this::class.hashCode() } }
packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBlueprintViewBinder.kt +11 −18 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.os.Trace import android.util.Log import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet import androidx.core.view.children import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.systemui.keyguard.ui.viewmodel.KeyguardBlueprintViewModel Loading @@ -37,26 +36,20 @@ class KeyguardBlueprintViewBinder { repeatOnLifecycle(Lifecycle.State.CREATED) { launch { viewModel.blueprint.collect { blueprint -> val prevBluePrint = viewModel.currentBluePrint Trace.beginSection("KeyguardBlueprint#applyBlueprint") Log.d(TAG, "applying blueprint: $blueprint") if (blueprint != viewModel.currentBluePrint) { viewModel.currentBluePrint?.onDestroy() } val constraintSet = // Add and remove views of sections that are not contained by the other. prevBluePrint?.removeViews(blueprint, constraintLayout) blueprint.addViews(prevBluePrint, constraintLayout) ConstraintSet().apply { clone(constraintLayout) val emptyLayout = ConstraintSet.Layout() knownIds.forEach { getConstraint(it).layout.copyFrom(emptyLayout) } blueprint.addViews(constraintLayout) knownIds.forEach { getConstraint(it).layout.copyFrom(emptyLayout) } blueprint.applyConstraints(this) applyTo(constraintLayout) } // Remove all unconstrained views. constraintLayout.children .filterNot { constraintSet.knownIds.contains(it.id) } .forEach { constraintLayout.removeView(it) } viewModel.currentBluePrint = blueprint Trace.endSection() Loading