Merge "Replace reflection with Suppliers." into tm-dev
This commit is contained in:
@@ -54,7 +54,7 @@ import com.android.systemui.animation.Interpolators
|
|||||||
import com.android.systemui.controls.ControlsMetricsLogger
|
import com.android.systemui.controls.ControlsMetricsLogger
|
||||||
import com.android.systemui.controls.controller.ControlsController
|
import com.android.systemui.controls.controller.ControlsController
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor
|
import com.android.systemui.util.concurrency.DelayableExecutor
|
||||||
import kotlin.reflect.KClass
|
import java.util.function.Supplier
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the widgets that make up the UI representation of a {@link Control}. Updates to the view
|
* Wraps the widgets that make up the UI representation of a {@link Control}. Updates to the view
|
||||||
@@ -90,20 +90,20 @@ class ControlViewHolder(
|
|||||||
status: Int,
|
status: Int,
|
||||||
template: ControlTemplate,
|
template: ControlTemplate,
|
||||||
deviceType: Int
|
deviceType: Int
|
||||||
): KClass<out Behavior> {
|
): Supplier<out Behavior> {
|
||||||
return when {
|
return when {
|
||||||
status != Control.STATUS_OK -> StatusBehavior::class
|
status != Control.STATUS_OK -> Supplier { StatusBehavior() }
|
||||||
template == ControlTemplate.NO_TEMPLATE -> TouchBehavior::class
|
template == ControlTemplate.NO_TEMPLATE -> Supplier { TouchBehavior() }
|
||||||
template is ThumbnailTemplate -> ThumbnailBehavior::class
|
template is ThumbnailTemplate -> Supplier { ThumbnailBehavior() }
|
||||||
|
|
||||||
// Required for legacy support, or where cameras do not use the new template
|
// Required for legacy support, or where cameras do not use the new template
|
||||||
deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class
|
deviceType == DeviceTypes.TYPE_CAMERA -> Supplier { TouchBehavior() }
|
||||||
template is ToggleTemplate -> ToggleBehavior::class
|
template is ToggleTemplate -> Supplier { ToggleBehavior() }
|
||||||
template is StatelessTemplate -> TouchBehavior::class
|
template is StatelessTemplate -> Supplier { TouchBehavior() }
|
||||||
template is ToggleRangeTemplate -> ToggleRangeBehavior::class
|
template is ToggleRangeTemplate -> Supplier { ToggleRangeBehavior() }
|
||||||
template is RangeTemplate -> ToggleRangeBehavior::class
|
template is RangeTemplate -> Supplier { ToggleRangeBehavior() }
|
||||||
template is TemperatureControlTemplate -> TemperatureControlBehavior::class
|
template is TemperatureControlTemplate -> Supplier { TemperatureControlBehavior() }
|
||||||
else -> DefaultBehavior::class
|
else -> Supplier { DefaultBehavior() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,13 +253,14 @@ class ControlViewHolder(
|
|||||||
|
|
||||||
fun bindBehavior(
|
fun bindBehavior(
|
||||||
existingBehavior: Behavior?,
|
existingBehavior: Behavior?,
|
||||||
clazz: KClass<out Behavior>,
|
supplier: Supplier<out Behavior>,
|
||||||
offset: Int = 0
|
offset: Int = 0
|
||||||
): Behavior {
|
): Behavior {
|
||||||
val behavior = if (existingBehavior == null || existingBehavior!!::class != clazz) {
|
val newBehavior = supplier.get()
|
||||||
|
val behavior = if (existingBehavior == null ||
|
||||||
|
existingBehavior::class != newBehavior::class) {
|
||||||
// Behavior changes can signal a change in template from the app or
|
// Behavior changes can signal a change in template from the app or
|
||||||
// first time setup
|
// first time setup
|
||||||
val newBehavior = clazz.java.newInstance()
|
|
||||||
newBehavior.initialize(this)
|
newBehavior.initialize(this)
|
||||||
|
|
||||||
// let behaviors define their own, if necessary, and clear any existing ones
|
// let behaviors define their own, if necessary, and clear any existing ones
|
||||||
|
|||||||
Reference in New Issue
Block a user