Merge "Dim down controls when slider is active" into rvc-dev am: 56cd4dcad5
Change-Id: Ib5adfc3ebbdf4f53bd3b1a0639b1c672ec570f45
This commit is contained in:
@@ -1253,6 +1253,7 @@
|
||||
<dimen name="control_base_item_margin">2dp</dimen>
|
||||
<dimen name="control_status_padding">3dp</dimen>
|
||||
<fraction name="controls_toggle_bg_intensity">5%</fraction>
|
||||
<fraction name="controls_dimmed_alpha">40%</fraction>
|
||||
|
||||
<!-- Home Controls activity view detail panel-->
|
||||
<dimen name="controls_activity_view_top_padding">25dp</dimen>
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.service.controls.actions.ControlAction
|
||||
import com.android.systemui.controls.ControlStatus
|
||||
import com.android.systemui.controls.UserAwareController
|
||||
import com.android.systemui.controls.management.ControlsFavoritingActivity
|
||||
import com.android.systemui.controls.ui.ControlWithState
|
||||
import com.android.systemui.controls.ui.ControlsUiController
|
||||
import java.util.function.Consumer
|
||||
|
||||
@@ -111,6 +112,13 @@ interface ControlsController : UserAwareController {
|
||||
@ControlAction.ResponseResult response: Int
|
||||
)
|
||||
|
||||
/**
|
||||
* When a control should be highlighted, dimming down what's around it.
|
||||
*
|
||||
* @param cws focused control, or {@code null} if nothing should be highlighted.
|
||||
*/
|
||||
fun onFocusChanged(cws: ControlWithState?)
|
||||
|
||||
// FAVORITE MANAGEMENT
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher
|
||||
import com.android.systemui.controls.ControlStatus
|
||||
import com.android.systemui.controls.ControlsServiceInfo
|
||||
import com.android.systemui.controls.management.ControlsListingController
|
||||
import com.android.systemui.controls.ui.ControlWithState
|
||||
import com.android.systemui.controls.ui.ControlsUiController
|
||||
import com.android.systemui.dagger.qualifiers.Background
|
||||
import com.android.systemui.dump.DumpManager
|
||||
@@ -504,6 +505,10 @@ class ControlsControllerImpl @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFocusChanged(cws: ControlWithState?) {
|
||||
uiController.onFocusChanged(cws)
|
||||
}
|
||||
|
||||
override fun refreshStatus(componentName: ComponentName, control: Control) {
|
||||
if (!confirmAvailability()) {
|
||||
Log.d(TAG, "Controls not available")
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.service.controls.actions.CommandAction
|
||||
import android.util.Log
|
||||
import android.view.HapticFeedbackConstants
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.controls.controller.ControlsController
|
||||
|
||||
object ControlActionCoordinator {
|
||||
const val MIN_LEVEL = 0
|
||||
@@ -76,4 +77,8 @@ object ControlActionCoordinator {
|
||||
it.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun setFocusedElement(cvh: ControlViewHolder?, controlsController: ControlsController) {
|
||||
controlsController.onFocusChanged(cvh?.cws)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.service.controls.templates.StatelessTemplate
|
||||
import android.service.controls.templates.TemperatureControlTemplate
|
||||
import android.service.controls.templates.ToggleRangeTemplate
|
||||
import android.service.controls.templates.ToggleTemplate
|
||||
import android.util.MathUtils
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
@@ -68,6 +69,8 @@ class ControlViewHolder(
|
||||
|
||||
private val toggleBackgroundIntensity: Float = layout.context.resources
|
||||
.getFraction(R.fraction.controls_toggle_bg_intensity, 1, 1)
|
||||
private val dimmedAlpha: Float = layout.context.resources
|
||||
.getFraction(R.fraction.controls_dimmed_alpha, 1, 1)
|
||||
private var stateAnimator: ValueAnimator? = null
|
||||
private val baseLayer: GradientDrawable
|
||||
val icon: ImageView = layout.requireViewById(R.id.icon)
|
||||
@@ -82,6 +85,11 @@ class ControlViewHolder(
|
||||
var lastAction: ControlAction? = null
|
||||
val deviceType: Int
|
||||
get() = cws.control?.let { it.getDeviceType() } ?: cws.ci.deviceType
|
||||
var dimmed: Boolean = false
|
||||
set(value) {
|
||||
field = value
|
||||
bindData(cws)
|
||||
}
|
||||
|
||||
init {
|
||||
val ld = layout.getBackground() as LayerDrawable
|
||||
@@ -177,7 +185,8 @@ class ControlViewHolder(
|
||||
|
||||
val fg = context.resources.getColorStateList(ri.foreground, context.theme)
|
||||
val bg = context.resources.getColor(R.color.control_default_background, context.theme)
|
||||
val (clip, newAlpha) = if (enabled) {
|
||||
val dimAlpha = if (dimmed) dimmedAlpha else 1f
|
||||
var (clip, newAlpha) = if (enabled) {
|
||||
listOf(ri.enabledBackground, ALPHA_ENABLED)
|
||||
} else {
|
||||
listOf(R.color.control_default_background, ALPHA_DISABLED)
|
||||
@@ -202,12 +211,14 @@ class ControlViewHolder(
|
||||
if (animated) {
|
||||
val oldColor = color?.defaultColor ?: newClipColor
|
||||
val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor
|
||||
val oldAlpha = layout.alpha
|
||||
stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply {
|
||||
addUpdateListener {
|
||||
alpha = it.animatedValue as Int
|
||||
setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction))
|
||||
baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor,
|
||||
newBaseColor, it.animatedFraction))
|
||||
layout.alpha = MathUtils.lerp(oldAlpha, dimAlpha, it.animatedFraction)
|
||||
}
|
||||
addListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator?) {
|
||||
@@ -222,6 +233,7 @@ class ControlViewHolder(
|
||||
alpha = newAlpha
|
||||
setColor(newClipColor)
|
||||
baseLayer.setColor(newBaseColor)
|
||||
layout.alpha = dimAlpha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,5 @@ interface ControlsUiController {
|
||||
controlId: String,
|
||||
@ControlAction.ResponseResult response: Int
|
||||
)
|
||||
fun onFocusChanged(controlWithState: ControlWithState?)
|
||||
}
|
||||
|
||||
@@ -209,6 +209,20 @@ class ControlsUiControllerImpl @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFocusChanged(focusedControl: ControlWithState?) {
|
||||
controlViewsById.forEach { key: ControlKey, viewHolder: ControlViewHolder ->
|
||||
val state = controlsById.get(key) ?: return@forEach
|
||||
val shouldBeDimmed = focusedControl != null && state != focusedControl
|
||||
if (viewHolder.dimmed == shouldBeDimmed) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
uiExecutor.execute {
|
||||
viewHolder.dimmed = shouldBeDimmed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startFavoritingActivity(context: Context, si: StructureInfo) {
|
||||
startTargetedActivity(context, si, ControlsFavoritingActivity::class.java)
|
||||
}
|
||||
|
||||
@@ -175,6 +175,7 @@ class ToggleRangeBehavior : Behavior {
|
||||
fun beginUpdateRange() {
|
||||
status.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.control_status_expanded).toFloat())
|
||||
ControlActionCoordinator.setFocusedElement(cvh, cvh.controlsController)
|
||||
}
|
||||
|
||||
fun updateRange(level: Int, checked: Boolean, isDragging: Boolean) {
|
||||
@@ -243,6 +244,7 @@ class ToggleRangeBehavior : Behavior {
|
||||
status.setText("$currentStatusText $currentRangeValue")
|
||||
cvh.action(FloatAction(rangeTemplate.getTemplateId(),
|
||||
findNearestStep(levelToRangeValue(clipLayer.getLevel()))))
|
||||
ControlActionCoordinator.setFocusedElement(null, cvh.controlsController)
|
||||
}
|
||||
|
||||
fun findNearestStep(value: Float): Float {
|
||||
|
||||
Reference in New Issue
Block a user