diff options
| author | 2023-09-09 01:57:51 +0000 | |
|---|---|---|
| committer | 2023-09-09 01:57:51 +0000 | |
| commit | 36a62535ea8c91d3f10d1abea95293282e1833cd (patch) | |
| tree | 1d27651a4afc08df2887bb8d63ff054de60949e0 /packages/SystemUI/src | |
| parent | 138b88bfd5680cd7e8a44438023736fd912c01b6 (diff) | |
| parent | 166271d5b92832a3cf0650b920f6514d9ff0a341 (diff) | |
Merge changes I02646ed9,Iec8e6fa4 into main
* changes:
Augment blueprint command line tool
Add parent class for shortcut sections
Diffstat (limited to 'packages/SystemUI/src')
7 files changed, 136 insertions, 148 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBlueprintRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBlueprintRepository.kt index f91ae743d956..f5ef27daecdd 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBlueprintRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardBlueprintRepository.kt @@ -24,6 +24,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardBlueprint import com.android.systemui.keyguard.ui.view.layout.blueprints.DefaultKeyguardBlueprint.Companion.DEFAULT import com.android.systemui.keyguard.ui.view.layout.blueprints.KeyguardBlueprintModule import java.io.PrintWriter +import java.util.TreeMap import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow @@ -52,11 +53,12 @@ constructor( blueprints: Set<@JvmSuppressWildcards KeyguardBlueprint>, @Application private val applicationScope: CoroutineScope, ) { - private val blueprintIdMap: Map<String, KeyguardBlueprint> = blueprints.associateBy { it.id } + private val blueprintIdMap: TreeMap<String, KeyguardBlueprint> = TreeMap() private val _blueprint: MutableSharedFlow<KeyguardBlueprint> = MutableSharedFlow(replay = 1) val blueprint: Flow<KeyguardBlueprint> = _blueprint.asSharedFlow() init { + blueprintIdMap.putAll(blueprints.associateBy { it.id }) applyBlueprint(blueprintIdMap[DEFAULT]!!) applicationScope.launch { configurationRepository.onAnyConfigurationChange.collect { refreshBlueprint() } @@ -69,6 +71,20 @@ constructor( * @param blueprintId * @return whether the transition has succeeded. */ + fun applyBlueprint(index: Int): Boolean { + ArrayList(blueprintIdMap.values)[index]?.let { + applyBlueprint(it) + return true + } + return false + } + + /** + * Emits the blueprint value to the collectors. + * + * @param blueprintId + * @return whether the transition has succeeded. + */ fun applyBlueprint(blueprintId: String?): Boolean { val blueprint = blueprintIdMap[blueprintId] ?: return false applyBlueprint(blueprint) @@ -89,6 +105,6 @@ constructor( /** Prints all available blueprints to the PrintWriter. */ fun printBlueprints(pw: PrintWriter) { - blueprintIdMap.forEach { entry -> pw.println("${entry.key}") } + blueprintIdMap.onEachIndexed { index, entry -> pw.println("$index: ${entry.key}") } } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBlueprintInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBlueprintInteractor.kt index 390ad7ef892b..6ce91854ea56 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBlueprintInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardBlueprintInteractor.kt @@ -37,6 +37,16 @@ constructor(private val keyguardBlueprintRepository: KeyguardBlueprintRepository return keyguardBlueprintRepository.applyBlueprint(blueprintId) } + /** + * Transitions to a blueprint. + * + * @param blueprintId + * @return whether the transition has succeeded. + */ + fun transitionToBlueprint(blueprintId: Int): Boolean { + return keyguardBlueprintRepository.applyBlueprint(blueprintId) + } + /** Re-emits the blueprint value to the collectors. */ fun refreshBlueprint() { keyguardBlueprintRepository.refreshBlueprint() diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/KeyguardBlueprintCommandListener.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/KeyguardBlueprintCommandListener.kt index 36d21f1babe2..ce7ec0e22f1c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/KeyguardBlueprintCommandListener.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/KeyguardBlueprintCommandListener.kt @@ -16,6 +16,7 @@ package com.android.systemui.keyguard.ui.view.layout +import androidx.core.text.isDigitsOnly import com.android.systemui.keyguard.data.repository.KeyguardBlueprintRepository import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor import com.android.systemui.statusbar.commandline.Command @@ -45,7 +46,11 @@ constructor( return } - if (keyguardBlueprintInteractor.transitionToBlueprint(arg)) { + if ( + arg.isDigitsOnly() && keyguardBlueprintInteractor.transitionToBlueprint(arg.toInt()) + ) { + pw.println("Transition succeeded!") + } else if (keyguardBlueprintInteractor.transitionToBlueprint(arg)) { pw.println("Transition succeeded!") } else { pw.println("Invalid argument! To see available blueprint ids, run:") diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/ShortcutsBesideUdfpsKeyguardBlueprint.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/ShortcutsBesideUdfpsKeyguardBlueprint.kt index 79a97fbd19df..6534dcf5c86b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/ShortcutsBesideUdfpsKeyguardBlueprint.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/blueprints/ShortcutsBesideUdfpsKeyguardBlueprint.kt @@ -61,6 +61,6 @@ constructor( ) companion object { - const val SHORTCUTS_BESIDE_UDFPS = "shortcutsBesideUdfps" + const val SHORTCUTS_BESIDE_UDFPS = "shortcuts-besides-udfps" } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AlignShortcutsToUdfpsSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AlignShortcutsToUdfpsSection.kt index 79b715799d31..5aba229434d7 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AlignShortcutsToUdfpsSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AlignShortcutsToUdfpsSection.kt @@ -18,8 +18,6 @@ package com.android.systemui.keyguard.ui.view.layout.sections import android.content.res.Resources -import android.view.View -import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet.BOTTOM @@ -27,13 +25,10 @@ import androidx.constraintlayout.widget.ConstraintSet.LEFT import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID import androidx.constraintlayout.widget.ConstraintSet.RIGHT import androidx.constraintlayout.widget.ConstraintSet.TOP -import androidx.core.content.res.ResourcesCompat import com.android.systemui.R -import com.android.systemui.animation.view.LaunchableImageView import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags -import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel @@ -53,10 +48,7 @@ constructor( private val falsingManager: FalsingManager, private val indicationController: KeyguardIndicationController, private val vibratorHelper: VibratorHelper, -) : KeyguardSection() { - private var leftShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null - private var rightShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null - +) : BaseShortcutSection() { override fun addViews(constraintLayout: ConstraintLayout) { if (featureFlags.isEnabled(Flags.MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA)) { addLeftShortcut(constraintLayout) @@ -109,67 +101,4 @@ constructor( connect(R.id.end_button, BOTTOM, R.id.lock_icon_view, BOTTOM) } } - - override fun removeViews(constraintLayout: ConstraintLayout) { - leftShortcutHandle?.destroy() - rightShortcutHandle?.destroy() - constraintLayout.removeView(R.id.start_button) - constraintLayout.removeView(R.id.end_button) - } - - private fun addLeftShortcut(constraintLayout: ConstraintLayout) { - val padding = - constraintLayout.resources.getDimensionPixelSize( - R.dimen.keyguard_affordance_fixed_padding - ) - val view = - LaunchableImageView(constraintLayout.context, null).apply { - id = R.id.start_button - scaleType = ImageView.ScaleType.FIT_CENTER - background = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_bg, - context.theme - ) - foreground = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_selected_border, - context.theme - ) - visibility = View.INVISIBLE - setPadding(padding, padding, padding, padding) - } - constraintLayout.addView(view) - } - - private fun addRightShortcut(constraintLayout: ConstraintLayout) { - if (constraintLayout.findViewById<View>(R.id.end_button) != null) return - - val padding = - constraintLayout.resources.getDimensionPixelSize( - R.dimen.keyguard_affordance_fixed_padding - ) - val view = - LaunchableImageView(constraintLayout.context, null).apply { - id = R.id.end_button - scaleType = ImageView.ScaleType.FIT_CENTER - background = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_bg, - context.theme - ) - foreground = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_selected_border, - context.theme - ) - visibility = View.INVISIBLE - setPadding(padding, padding, padding, padding) - } - constraintLayout.addView(view) - } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt new file mode 100644 index 000000000000..d046a196e94e --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt @@ -0,0 +1,99 @@ +package com.android.systemui.keyguard.ui.view.layout.sections + +import android.view.View +import android.widget.ImageView +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.ResourcesCompat +import com.android.systemui.R +import com.android.systemui.animation.view.LaunchableImageView +import com.android.systemui.keyguard.shared.model.KeyguardSection +import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder + +abstract class BaseShortcutSection : KeyguardSection() { + protected var leftShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null + protected var rightShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null + + override fun removeViews(constraintLayout: ConstraintLayout) { + leftShortcutHandle?.destroy() + rightShortcutHandle?.destroy() + constraintLayout.removeView(R.id.start_button) + constraintLayout.removeView(R.id.end_button) + } + + protected fun addLeftShortcut(constraintLayout: ConstraintLayout) { + val padding = + constraintLayout.resources.getDimensionPixelSize( + R.dimen.keyguard_affordance_fixed_padding + ) + val view = + LaunchableImageView(constraintLayout.context, null).apply { + id = R.id.start_button + scaleType = ImageView.ScaleType.FIT_CENTER + background = + ResourcesCompat.getDrawable( + context.resources, + R.drawable.keyguard_bottom_affordance_bg, + context.theme + ) + foreground = + ResourcesCompat.getDrawable( + context.resources, + R.drawable.keyguard_bottom_affordance_selected_border, + context.theme + ) + visibility = View.INVISIBLE + setPadding(padding, padding, padding, padding) + } + constraintLayout.addView(view) + } + + protected fun addRightShortcut(constraintLayout: ConstraintLayout) { + if (constraintLayout.findViewById<View>(R.id.end_button) != null) return + + val padding = + constraintLayout.resources.getDimensionPixelSize( + R.dimen.keyguard_affordance_fixed_padding + ) + val view = + LaunchableImageView(constraintLayout.context, null).apply { + id = R.id.end_button + scaleType = ImageView.ScaleType.FIT_CENTER + background = + ResourcesCompat.getDrawable( + context.resources, + R.drawable.keyguard_bottom_affordance_bg, + context.theme + ) + foreground = + ResourcesCompat.getDrawable( + context.resources, + R.drawable.keyguard_bottom_affordance_selected_border, + context.theme + ) + visibility = View.INVISIBLE + setPadding(padding, padding, padding, padding) + } + constraintLayout.addView(view) + } + /** + * 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 { + return other is BaseShortcutSection + } + + /** + * Defines hashcode as class. + * + * This is to enable set operations to be done as an optimization to blueprint transitions. + */ + override fun hashCode(): Int { + return KEY.hashCode() + } + + companion object { + private const val KEY = "shortcuts" + } +} diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt index a2db1df4fa5c..13ef985287f6 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt @@ -18,21 +18,16 @@ package com.android.systemui.keyguard.ui.view.layout.sections import android.content.res.Resources -import android.view.View -import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet.BOTTOM import androidx.constraintlayout.widget.ConstraintSet.LEFT import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID import androidx.constraintlayout.widget.ConstraintSet.RIGHT -import androidx.core.content.res.ResourcesCompat import com.android.systemui.R -import com.android.systemui.animation.view.LaunchableImageView import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags -import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel @@ -52,10 +47,7 @@ constructor( private val falsingManager: FalsingManager, private val indicationController: KeyguardIndicationController, private val vibratorHelper: VibratorHelper, -) : KeyguardSection() { - private var leftShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null - private var rightShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null - +) : BaseShortcutSection() { override fun addViews(constraintLayout: ConstraintLayout) { if (featureFlags.isEnabled(Flags.MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA)) { addLeftShortcut(constraintLayout) @@ -108,67 +100,4 @@ constructor( connect(R.id.end_button, BOTTOM, PARENT_ID, BOTTOM, verticalOffsetMargin) } } - - override fun removeViews(constraintLayout: ConstraintLayout) { - leftShortcutHandle?.destroy() - rightShortcutHandle?.destroy() - constraintLayout.removeView(R.id.start_button) - constraintLayout.removeView(R.id.end_button) - } - - private fun addLeftShortcut(constraintLayout: ConstraintLayout) { - val padding = - constraintLayout.resources.getDimensionPixelSize( - R.dimen.keyguard_affordance_fixed_padding - ) - val view = - LaunchableImageView(constraintLayout.context, null).apply { - id = R.id.start_button - scaleType = ImageView.ScaleType.FIT_CENTER - background = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_bg, - context.theme - ) - foreground = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_selected_border, - context.theme - ) - visibility = View.INVISIBLE - setPadding(padding, padding, padding, padding) - } - constraintLayout.addView(view) - } - - private fun addRightShortcut(constraintLayout: ConstraintLayout) { - if (constraintLayout.findViewById<View>(R.id.end_button) != null) return - - val padding = - constraintLayout.resources.getDimensionPixelSize( - R.dimen.keyguard_affordance_fixed_padding - ) - val view = - LaunchableImageView(constraintLayout.context, null).apply { - id = R.id.end_button - scaleType = ImageView.ScaleType.FIT_CENTER - background = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_bg, - context.theme - ) - foreground = - ResourcesCompat.getDrawable( - context.resources, - R.drawable.keyguard_bottom_affordance_selected_border, - context.theme - ) - visibility = View.INVISIBLE - setPadding(padding, padding, padding, padding) - } - constraintLayout.addView(view) - } } |