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

Commit 71293a7c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Controls UI - Part 1 - Thumbnail support"

parents 901f0b50 547299df
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
 * Copyright 2010, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_enabled="false"
        android:color="@color/control_default_foreground" />
  <item android:color="@color/GM2_grey_100" />
</selector>
+2 −0
Original line number Diff line number Diff line
@@ -257,6 +257,8 @@
    <color name="control_enabled_heat_foreground">#FF8B66</color>
    <color name="control_enabled_default_foreground">@color/GM2_blue_300</color>
    <color name="control_enabled_cool_foreground">@color/GM2_blue_300</color>
    <color name="control_thumbnail_tint">#33000000</color>
    <color name="control_thumbnail_shadow_color">@*android:color/black</color>

    <!-- Docked misalignment message -->
    <color name="misalignment_text_color">#F28B82</color>
+4 −0
Original line number Diff line number Diff line
@@ -1269,6 +1269,10 @@
    <dimen name="controls_app_divider_height">2dp</dimen>
    <dimen name="controls_app_divider_side_margin">32dp</dimen>

    <item name="controls_thumbnail_shadow_x" type="dimen" format="float">2.0</item>
    <item name="controls_thumbnail_shadow_y" type="dimen" format="float">2.0</item>
    <item name="controls_thumbnail_shadow_radius" type="dimen" format="float">2.0</item>

    <dimen name="controls_card_margin">@dimen/control_base_item_margin</dimen>
    <item name="control_card_elevation" type="dimen" format="float">15</item>

+26 −9
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ 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.ThumbnailTemplate
import android.service.controls.templates.ToggleRangeTemplate
import android.service.controls.templates.ToggleTemplate
import android.util.MathUtils
@@ -87,8 +88,11 @@ class ControlViewHolder(
        ): KClass<out Behavior> {
            return when {
                status != Control.STATUS_OK -> StatusBehavior::class
                deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class
                template == ControlTemplate.NO_TEMPLATE -> TouchBehavior::class
                template is ThumbnailTemplate -> ThumbnailBehavior::class

                // Required for legacy support, or where cameras do not use the new template
                deviceType == DeviceTypes.TYPE_CAMERA -> TouchBehavior::class
                template is ToggleTemplate -> ToggleBehavior::class
                template is StatelessTemplate -> TouchBehavior::class
                template is ToggleRangeTemplate -> ToggleRangeBehavior::class
@@ -105,7 +109,7 @@ class ControlViewHolder(
    private var statusAnimator: Animator? = null
    private val baseLayer: GradientDrawable
    val icon: ImageView = layout.requireViewById(R.id.icon)
    private val status: TextView = layout.requireViewById(R.id.status)
    val status: TextView = layout.requireViewById(R.id.status)
    private var nextStatusText: CharSequence = ""
    val title: TextView = layout.requireViewById(R.id.title)
    val subtitle: TextView = layout.requireViewById(R.id.subtitle)
@@ -132,7 +136,6 @@ class ControlViewHolder(
        val ld = layout.getBackground() as LayerDrawable
        ld.mutate()
        clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) as ClipDrawable
        clipLayer.alpha = ALPHA_DISABLED
        baseLayer = ld.findDrawableByLayerId(R.id.background) as GradientDrawable
        // needed for marquee to start
        status.setSelected(true)
@@ -315,7 +318,9 @@ class ControlViewHolder(
            )
        }

        (clipLayer.getDrawable() as GradientDrawable).apply {
        clipLayer.getDrawable().apply {
            clipLayer.alpha = ALPHA_DISABLED

            val newBaseColor = if (behavior is ToggleRangeBehavior) {
                ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity)
            } else {
@@ -323,15 +328,25 @@ class ControlViewHolder(
            }
            stateAnimator?.cancel()
            if (animated) {
                val oldColor = color?.defaultColor ?: newClipColor
                val oldColor = if (this is GradientDrawable) {
                    this.color?.defaultColor ?: newClipColor
                } else {
                    newClipColor
                }
                val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor
                val oldAlpha = layout.alpha

                // Animate both alpha and background colors. Only animate colors for
                // GradientDrawables and not static images as used for the ThumbnailTemplate.
                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))
                        if (this is GradientDrawable) {
                            this.setColor(ColorUtils.blendARGB(oldColor, newClipColor,
                                it.animatedFraction))
                        }
                        baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor, newBaseColor,
                                it.animatedFraction))
                        layout.alpha = MathUtils.lerp(oldAlpha, 1f, it.animatedFraction)
                    }
                    addListener(object : AnimatorListenerAdapter() {
@@ -345,7 +360,9 @@ class ControlViewHolder(
                }
            } else {
                alpha = newAlpha
                setColor(newClipColor)
                if (this is GradientDrawable) {
                    this.setColor(newClipColor)
                }
                baseLayer.setColor(newBaseColor)
                layout.alpha = 1f
            }
+3 −1
Original line number Diff line number Diff line
@@ -92,7 +92,9 @@ private val deviceColorMap = mapOf<Int, Pair<Int, Int>>(
    (THERMOSTAT_RANGE + TemperatureControlTemplate.MODE_COOL) to
        Pair(R.color.thermo_cool_foreground, R.color.control_enabled_thermo_cool_background),
    DeviceTypes.TYPE_LIGHT
        to Pair(R.color.light_foreground, R.color.control_enabled_light_background)
        to Pair(R.color.light_foreground, R.color.control_enabled_light_background),
    DeviceTypes.TYPE_CAMERA
        to Pair(R.color.camera_foreground, R.color.control_enabled_default_background)
).withDefault {
        Pair(R.color.control_foreground, R.color.control_enabled_default_background)
}
Loading