Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db32530c authored by Lucas Dupin's avatar Lucas Dupin Committed by Automerger Merge Worker
Browse files

Merge "Add dimmed background to range toggles" into rvc-dev am: 25363055

Change-Id: I2a1ee3931dc2b9c470f228d01f91e68e350db298
parents 58b32f89 25363055
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -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" />
+1 −0
Original line number Original line Diff line number Diff line
@@ -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>
+22 −8
Original line number Original line Diff line number Diff line
@@ -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)
            }
            }
        }
        }
    }
    }