Merge "Add dimmed background to range toggles" into rvc-dev
This commit is contained in:
@@ -17,7 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item>
|
<item
|
||||||
|
android:id="@+id/background">
|
||||||
<shape>
|
<shape>
|
||||||
<solid android:color="@color/control_default_background" />
|
<solid android:color="@color/control_default_background" />
|
||||||
<corners android:radius="@dimen/control_corner_radius" />
|
<corners android:radius="@dimen/control_corner_radius" />
|
||||||
|
|||||||
@@ -1252,6 +1252,7 @@
|
|||||||
<dimen name="control_status_expanded">18sp</dimen>
|
<dimen name="control_status_expanded">18sp</dimen>
|
||||||
<dimen name="control_base_item_margin">2dp</dimen>
|
<dimen name="control_base_item_margin">2dp</dimen>
|
||||||
<dimen name="control_status_padding">3dp</dimen>
|
<dimen name="control_status_padding">3dp</dimen>
|
||||||
|
<fraction name="controls_toggle_bg_intensity">5%</fraction>
|
||||||
|
|
||||||
<!-- Home Controls activity view detail panel-->
|
<!-- Home Controls activity view detail panel-->
|
||||||
<dimen name="controls_activity_view_top_padding">25dp</dimen>
|
<dimen name="controls_activity_view_top_padding">25dp</dimen>
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ class ControlViewHolder(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val toggleBackgroundIntensity: Float = layout.context.resources
|
||||||
|
.getFraction(R.fraction.controls_toggle_bg_intensity, 1, 1)
|
||||||
private var stateAnimator: ValueAnimator? = null
|
private var stateAnimator: ValueAnimator? = null
|
||||||
|
private val baseLayer: GradientDrawable
|
||||||
val icon: ImageView = layout.requireViewById(R.id.icon)
|
val icon: ImageView = layout.requireViewById(R.id.icon)
|
||||||
val status: TextView = layout.requireViewById(R.id.status)
|
val status: TextView = layout.requireViewById(R.id.status)
|
||||||
val title: TextView = layout.requireViewById(R.id.title)
|
val title: TextView = layout.requireViewById(R.id.title)
|
||||||
@@ -85,6 +88,7 @@ class ControlViewHolder(
|
|||||||
ld.mutate()
|
ld.mutate()
|
||||||
clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) as ClipDrawable
|
clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) as ClipDrawable
|
||||||
clipLayer.alpha = ALPHA_DISABLED
|
clipLayer.alpha = ALPHA_DISABLED
|
||||||
|
baseLayer = ld.findDrawableByLayerId(R.id.background) as GradientDrawable
|
||||||
// needed for marquee to start
|
// needed for marquee to start
|
||||||
status.setSelected(true)
|
status.setSelected(true)
|
||||||
}
|
}
|
||||||
@@ -171,11 +175,12 @@ class ControlViewHolder(
|
|||||||
|
|
||||||
val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset)
|
val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset)
|
||||||
|
|
||||||
val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme())
|
val fg = context.resources.getColorStateList(ri.foreground, context.theme)
|
||||||
val (bg, newAlpha) = if (enabled) {
|
val bg = context.resources.getColor(R.color.control_default_background, context.theme)
|
||||||
Pair(ri.enabledBackground, ALPHA_ENABLED)
|
val (clip, newAlpha) = if (enabled) {
|
||||||
|
listOf(ri.enabledBackground, ALPHA_ENABLED)
|
||||||
} else {
|
} else {
|
||||||
Pair(R.color.control_default_background, ALPHA_DISABLED)
|
listOf(R.color.control_default_background, ALPHA_DISABLED)
|
||||||
}
|
}
|
||||||
|
|
||||||
status.setTextColor(fg)
|
status.setTextColor(fg)
|
||||||
@@ -187,14 +192,22 @@ class ControlViewHolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
(clipLayer.getDrawable() as GradientDrawable).apply {
|
(clipLayer.getDrawable() as GradientDrawable).apply {
|
||||||
val newColor = context.resources.getColor(bg, context.theme)
|
val newClipColor = context.resources.getColor(clip, context.theme)
|
||||||
|
val newBaseColor = if (behavior is ToggleRangeBehavior) {
|
||||||
|
ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity)
|
||||||
|
} else {
|
||||||
|
bg
|
||||||
|
}
|
||||||
stateAnimator?.cancel()
|
stateAnimator?.cancel()
|
||||||
if (animated) {
|
if (animated) {
|
||||||
val oldColor = color?.defaultColor ?: newColor
|
val oldColor = color?.defaultColor ?: newClipColor
|
||||||
|
val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor
|
||||||
stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply {
|
stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply {
|
||||||
addUpdateListener {
|
addUpdateListener {
|
||||||
alpha = it.animatedValue as Int
|
alpha = it.animatedValue as Int
|
||||||
setColor(ColorUtils.blendARGB(oldColor, newColor, it.animatedFraction))
|
setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction))
|
||||||
|
baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor,
|
||||||
|
newBaseColor, it.animatedFraction))
|
||||||
}
|
}
|
||||||
addListener(object : AnimatorListenerAdapter() {
|
addListener(object : AnimatorListenerAdapter() {
|
||||||
override fun onAnimationEnd(animation: Animator?) {
|
override fun onAnimationEnd(animation: Animator?) {
|
||||||
@@ -207,7 +220,8 @@ class ControlViewHolder(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alpha = newAlpha
|
alpha = newAlpha
|
||||||
setColor(newColor)
|
setColor(newClipColor)
|
||||||
|
baseLayer.setColor(newBaseColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user