Loading packages/SystemUI/src/com/android/systemui/controls/ui/Behavior.kt +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ interface Behavior { /** * Will be invoked on every update provided to the Control * * @param cws ControlWithState, as loaded from favorites and/or the application * @param colorOffset An additional flag to control rendering color. See [RenderInfo] */ fun bind(cws: ControlWithState) fun bind(cws: ControlWithState, colorOffset: Int = 0) } packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +42 −28 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.service.controls.Control import android.service.controls.DeviceTypes import android.service.controls.actions.ControlAction import android.service.controls.templates.ControlTemplate import android.service.controls.templates.RangeTemplate import android.service.controls.templates.StatelessTemplate import android.service.controls.templates.TemperatureControlTemplate import android.service.controls.templates.ToggleRangeTemplate Loading Loading @@ -69,6 +70,25 @@ class ControlViewHolder( const val MIN_LEVEL = 0 const val MAX_LEVEL = 10000 fun findBehaviorClass( status: Int, template: ControlTemplate, deviceType: Int ): KClass<out Behavior> { return when { status == Control.STATUS_UNKNOWN -> StatusBehavior::class status == Control.STATUS_ERROR -> StatusBehavior::class status == Control.STATUS_NOT_FOUND -> StatusBehavior::class deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class template is ToggleTemplate -> ToggleBehavior::class template is StatelessTemplate -> TouchBehavior::class template is ToggleRangeTemplate -> ToggleRangeBehavior::class template is RangeTemplate -> ToggleRangeBehavior::class template is TemperatureControlTemplate -> TemperatureControlBehavior::class else -> DefaultBehavior::class } } } private val toggleBackgroundIntensity: Float = layout.context.resources Loading Loading @@ -124,18 +144,7 @@ class ControlViewHolder( }) } val clazz = findBehavior(controlStatus, template, deviceType) if (behavior == null || behavior!!::class != clazz) { // Behavior changes can signal a change in template from the app or // first time setup behavior = clazz.java.newInstance() behavior?.initialize(this) // let behaviors define their own, if necessary, and clear any existing ones layout.setAccessibilityDelegate(null) } behavior?.bind(cws) behavior = bindBehavior(behavior, findBehaviorClass(controlStatus, template, deviceType)) layout.setContentDescription("${title.text} ${subtitle.text} ${status.text}") } Loading Loading @@ -194,25 +203,30 @@ class ControlViewHolder( fun usePanel(): Boolean = deviceType in ControlViewHolder.FORCE_PANEL_DEVICES private fun findBehavior( status: Int, template: ControlTemplate, deviceType: Int ): KClass<out Behavior> { return when { status == Control.STATUS_UNKNOWN -> StatusBehavior::class status == Control.STATUS_ERROR -> StatusBehavior::class status == Control.STATUS_NOT_FOUND -> StatusBehavior::class deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class template is ToggleTemplate -> ToggleBehavior::class template is StatelessTemplate -> TouchBehavior::class template is ToggleRangeTemplate -> ToggleRangeBehavior::class template is TemperatureControlTemplate -> TemperatureControlBehavior::class else -> DefaultBehavior::class fun bindBehavior( existingBehavior: Behavior?, clazz: KClass<out Behavior>, offset: Int = 0 ): Behavior { val behavior = if (existingBehavior == null || existingBehavior!!::class != clazz) { // Behavior changes can signal a change in template from the app or // first time setup val newBehavior = clazz.java.newInstance() newBehavior.initialize(this) // let behaviors define their own, if necessary, and clear any existing ones layout.setAccessibilityDelegate(null) newBehavior } else { existingBehavior } return behavior.also { it.bind(cws, offset) } } internal fun applyRenderInfo(enabled: Boolean, offset: Int = 0, animated: Boolean = true) { internal fun applyRenderInfo(enabled: Boolean, offset: Int, animated: Boolean = true) { setEnabled(enabled) val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset) Loading packages/SystemUI/src/com/android/systemui/controls/ui/DefaultBehavior.kt +2 −2 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class DefaultBehavior : Behavior { this.cvh = cvh } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { cvh.status.setText(cws.control?.getStatusText() ?: "") cvh.applyRenderInfo(false) cvh.applyRenderInfo(false, colorOffset) } } packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class StatusBehavior : Behavior { this.cvh = cvh } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { val status = cws.control?.status ?: Control.STATUS_UNKNOWN val msg = when (status) { Control.STATUS_ERROR -> R.string.controls_error_generic Loading @@ -35,6 +35,6 @@ class StatusBehavior : Behavior { else -> com.android.internal.R.string.loading } cvh.status.setText(cvh.context.getString(msg)) cvh.applyRenderInfo(false) cvh.applyRenderInfo(false, colorOffset) } } packages/SystemUI/src/com/android/systemui/controls/ui/TemperatureControlBehavior.kt +29 −11 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.controls.ui import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.service.controls.Control import android.service.controls.templates.ControlTemplate import android.service.controls.templates.TemperatureControlTemplate import com.android.systemui.R Loading @@ -29,17 +30,13 @@ class TemperatureControlBehavior : Behavior { lateinit var clipLayer: Drawable lateinit var control: Control lateinit var cvh: ControlViewHolder lateinit var template: TemperatureControlTemplate var subBehavior: Behavior? = null override fun initialize(cvh: ControlViewHolder) { this.cvh = cvh cvh.layout.setOnClickListener { _ -> cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) } } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { this.control = cws.control!! cvh.status.setText(control.getStatusText()) Loading @@ -47,11 +44,32 @@ class TemperatureControlBehavior : Behavior { val ld = cvh.layout.getBackground() as LayerDrawable clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) template = control.getControlTemplate() as TemperatureControlTemplate val template = control.getControlTemplate() as TemperatureControlTemplate val activeMode = template.getCurrentActiveMode() val subTemplate = template.getTemplate() if (subTemplate == ControlTemplate.getNoTemplateObject() || subTemplate == ControlTemplate.getErrorTemplate()) { // No sub template is specified, apply a default look with basic touch interaction. // Treat an error as no template. val enabled = activeMode != 0 && activeMode != TemperatureControlTemplate.MODE_OFF clipLayer.setLevel(if (enabled) MAX_LEVEL else MIN_LEVEL) cvh.applyRenderInfo(enabled, activeMode) cvh.layout.setOnClickListener { _ -> cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) } } else { // A sub template has been specified, use this as the default behavior for user // interactions (touch, range) subBehavior = cvh.bindBehavior( subBehavior, ControlViewHolder.findBehaviorClass( control.status, subTemplate, control.deviceType ), activeMode ) } } } Loading
packages/SystemUI/src/com/android/systemui/controls/ui/Behavior.kt +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ interface Behavior { /** * Will be invoked on every update provided to the Control * * @param cws ControlWithState, as loaded from favorites and/or the application * @param colorOffset An additional flag to control rendering color. See [RenderInfo] */ fun bind(cws: ControlWithState) fun bind(cws: ControlWithState, colorOffset: Int = 0) }
packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +42 −28 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.service.controls.Control import android.service.controls.DeviceTypes import android.service.controls.actions.ControlAction import android.service.controls.templates.ControlTemplate import android.service.controls.templates.RangeTemplate import android.service.controls.templates.StatelessTemplate import android.service.controls.templates.TemperatureControlTemplate import android.service.controls.templates.ToggleRangeTemplate Loading Loading @@ -69,6 +70,25 @@ class ControlViewHolder( const val MIN_LEVEL = 0 const val MAX_LEVEL = 10000 fun findBehaviorClass( status: Int, template: ControlTemplate, deviceType: Int ): KClass<out Behavior> { return when { status == Control.STATUS_UNKNOWN -> StatusBehavior::class status == Control.STATUS_ERROR -> StatusBehavior::class status == Control.STATUS_NOT_FOUND -> StatusBehavior::class deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class template is ToggleTemplate -> ToggleBehavior::class template is StatelessTemplate -> TouchBehavior::class template is ToggleRangeTemplate -> ToggleRangeBehavior::class template is RangeTemplate -> ToggleRangeBehavior::class template is TemperatureControlTemplate -> TemperatureControlBehavior::class else -> DefaultBehavior::class } } } private val toggleBackgroundIntensity: Float = layout.context.resources Loading Loading @@ -124,18 +144,7 @@ class ControlViewHolder( }) } val clazz = findBehavior(controlStatus, template, deviceType) if (behavior == null || behavior!!::class != clazz) { // Behavior changes can signal a change in template from the app or // first time setup behavior = clazz.java.newInstance() behavior?.initialize(this) // let behaviors define their own, if necessary, and clear any existing ones layout.setAccessibilityDelegate(null) } behavior?.bind(cws) behavior = bindBehavior(behavior, findBehaviorClass(controlStatus, template, deviceType)) layout.setContentDescription("${title.text} ${subtitle.text} ${status.text}") } Loading Loading @@ -194,25 +203,30 @@ class ControlViewHolder( fun usePanel(): Boolean = deviceType in ControlViewHolder.FORCE_PANEL_DEVICES private fun findBehavior( status: Int, template: ControlTemplate, deviceType: Int ): KClass<out Behavior> { return when { status == Control.STATUS_UNKNOWN -> StatusBehavior::class status == Control.STATUS_ERROR -> StatusBehavior::class status == Control.STATUS_NOT_FOUND -> StatusBehavior::class deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class template is ToggleTemplate -> ToggleBehavior::class template is StatelessTemplate -> TouchBehavior::class template is ToggleRangeTemplate -> ToggleRangeBehavior::class template is TemperatureControlTemplate -> TemperatureControlBehavior::class else -> DefaultBehavior::class fun bindBehavior( existingBehavior: Behavior?, clazz: KClass<out Behavior>, offset: Int = 0 ): Behavior { val behavior = if (existingBehavior == null || existingBehavior!!::class != clazz) { // Behavior changes can signal a change in template from the app or // first time setup val newBehavior = clazz.java.newInstance() newBehavior.initialize(this) // let behaviors define their own, if necessary, and clear any existing ones layout.setAccessibilityDelegate(null) newBehavior } else { existingBehavior } return behavior.also { it.bind(cws, offset) } } internal fun applyRenderInfo(enabled: Boolean, offset: Int = 0, animated: Boolean = true) { internal fun applyRenderInfo(enabled: Boolean, offset: Int, animated: Boolean = true) { setEnabled(enabled) val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset) Loading
packages/SystemUI/src/com/android/systemui/controls/ui/DefaultBehavior.kt +2 −2 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class DefaultBehavior : Behavior { this.cvh = cvh } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { cvh.status.setText(cws.control?.getStatusText() ?: "") cvh.applyRenderInfo(false) cvh.applyRenderInfo(false, colorOffset) } }
packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class StatusBehavior : Behavior { this.cvh = cvh } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { val status = cws.control?.status ?: Control.STATUS_UNKNOWN val msg = when (status) { Control.STATUS_ERROR -> R.string.controls_error_generic Loading @@ -35,6 +35,6 @@ class StatusBehavior : Behavior { else -> com.android.internal.R.string.loading } cvh.status.setText(cvh.context.getString(msg)) cvh.applyRenderInfo(false) cvh.applyRenderInfo(false, colorOffset) } }
packages/SystemUI/src/com/android/systemui/controls/ui/TemperatureControlBehavior.kt +29 −11 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.controls.ui import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.service.controls.Control import android.service.controls.templates.ControlTemplate import android.service.controls.templates.TemperatureControlTemplate import com.android.systemui.R Loading @@ -29,17 +30,13 @@ class TemperatureControlBehavior : Behavior { lateinit var clipLayer: Drawable lateinit var control: Control lateinit var cvh: ControlViewHolder lateinit var template: TemperatureControlTemplate var subBehavior: Behavior? = null override fun initialize(cvh: ControlViewHolder) { this.cvh = cvh cvh.layout.setOnClickListener { _ -> cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) } } override fun bind(cws: ControlWithState) { override fun bind(cws: ControlWithState, colorOffset: Int) { this.control = cws.control!! cvh.status.setText(control.getStatusText()) Loading @@ -47,11 +44,32 @@ class TemperatureControlBehavior : Behavior { val ld = cvh.layout.getBackground() as LayerDrawable clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) template = control.getControlTemplate() as TemperatureControlTemplate val template = control.getControlTemplate() as TemperatureControlTemplate val activeMode = template.getCurrentActiveMode() val subTemplate = template.getTemplate() if (subTemplate == ControlTemplate.getNoTemplateObject() || subTemplate == ControlTemplate.getErrorTemplate()) { // No sub template is specified, apply a default look with basic touch interaction. // Treat an error as no template. val enabled = activeMode != 0 && activeMode != TemperatureControlTemplate.MODE_OFF clipLayer.setLevel(if (enabled) MAX_LEVEL else MIN_LEVEL) cvh.applyRenderInfo(enabled, activeMode) cvh.layout.setOnClickListener { _ -> cvh.controlActionCoordinator.touch(cvh, template.getTemplateId(), control) } } else { // A sub template has been specified, use this as the default behavior for user // interactions (touch, range) subBehavior = cvh.bindBehavior( subBehavior, ControlViewHolder.findBehaviorClass( control.status, subTemplate, control.deviceType ), activeMode ) } } }