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

Commit 53a8bbdd authored by Matt Pietal's avatar Matt Pietal
Browse files

Controls UI - Stateless controls

Add support for touchable controls without any state. Refactor to
support using app icons as well as device type specific icons. Cache
icons since they will most likely be used many times.

Bug: 150849751
Test: visual

Change-Id: I2d729ced2361e623d3f575149b5c0b4492072ff3
parent 4a4e1e45
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -16,10 +16,12 @@


package com.android.systemui.controls
package com.android.systemui.controls


import android.content.ComponentName
import android.service.controls.Control
import android.service.controls.Control


data class ControlStatus(
data class ControlStatus(
    val control: Control,
    val control: Control,
    val component: ComponentName,
    var favorite: Boolean,
    var favorite: Boolean,
    val removed: Boolean = false
    val removed: Boolean = false
)
)
+6 −2
Original line number Original line Diff line number Diff line
@@ -238,7 +238,11 @@ class ControlsControllerImpl @Inject constructor (
                            }
                            }
                            val removed = findRemoved(favoritesForComponentKeys.toSet(), controls)
                            val removed = findRemoved(favoritesForComponentKeys.toSet(), controls)
                            val controlsWithFavorite = controls.map {
                            val controlsWithFavorite = controls.map {
                                ControlStatus(it, it.controlId in favoritesForComponentKeys)
                                ControlStatus(
                                    it,
                                    componentName,
                                    it.controlId in favoritesForComponentKeys
                                )
                            }
                            }
                            val loadData = createLoadDataObject(
                            val loadData = createLoadDataObject(
                                Favorites.getControlsForComponent(componentName)
                                Favorites.getControlsForComponent(componentName)
@@ -290,7 +294,7 @@ class ControlsControllerImpl @Inject constructor (
                .setTitle(controlInfo.controlTitle)
                .setTitle(controlInfo.controlTitle)
                .setDeviceType(controlInfo.deviceType)
                .setDeviceType(controlInfo.deviceType)
                .build()
                .build()
        return ControlStatus(control, true, setRemoved)
        return ControlStatus(control, componentName, true, setRemoved)
    }
    }


    private fun findRemoved(favoriteKeys: Set<String>, list: List<Control>): Set<String> {
    private fun findRemoved(favoriteKeys: Set<String>, list: List<Control>): Set<String> {
+6 −5
Original line number Original line Diff line number Diff line
@@ -16,8 +16,8 @@


package com.android.systemui.controls.management
package com.android.systemui.controls.management


import android.content.ComponentName
import android.graphics.Rect
import android.graphics.Rect
import android.graphics.drawable.Icon
import android.service.controls.DeviceTypes
import android.service.controls.DeviceTypes
import android.view.LayoutInflater
import android.view.LayoutInflater
import android.view.View
import android.view.View
@@ -147,7 +147,7 @@ private class ControlHolder(view: View, val favoriteCallback: ModelFavoriteChang
    override fun bindData(wrapper: ElementWrapper) {
    override fun bindData(wrapper: ElementWrapper) {
        wrapper as ControlWrapper
        wrapper as ControlWrapper
        val data = wrapper.controlStatus
        val data = wrapper.controlStatus
        val renderInfo = getRenderInfo(data.control.deviceType)
        val renderInfo = getRenderInfo(data.component, data.control.deviceType)
        title.text = data.control.title
        title.text = data.control.title
        subtitle.text = data.control.subtitle
        subtitle.text = data.control.subtitle
        favorite.isChecked = data.favorite
        favorite.isChecked = data.favorite
@@ -160,16 +160,17 @@ private class ControlHolder(view: View, val favoriteCallback: ModelFavoriteChang
    }
    }


    private fun getRenderInfo(
    private fun getRenderInfo(
        component: ComponentName,
        @DeviceTypes.DeviceType deviceType: Int
        @DeviceTypes.DeviceType deviceType: Int
    ): RenderInfo {
    ): RenderInfo {
        return RenderInfo.lookup(deviceType, true)
        return RenderInfo.lookup(itemView.context, component, deviceType, true)
    }
    }


    private fun applyRenderInfo(ri: RenderInfo) {
    private fun applyRenderInfo(ri: RenderInfo) {
        val context = itemView.context
        val context = itemView.context
        val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme())
        val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme())


        icon.setImageIcon(Icon.createWithResource(context, ri.iconResourceId))
        icon.setImageDrawable(ri.icon)
        icon.setImageTintList(fg)
        icon.setImageTintList(fg)
    }
    }
}
}
+3 −5
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ import android.app.Dialog
import android.content.ComponentName
import android.content.ComponentName
import android.content.DialogInterface
import android.content.DialogInterface
import android.content.Intent
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.Bundle
import android.os.Bundle
import android.os.UserHandle
import android.os.UserHandle
import android.service.controls.Control
import android.service.controls.Control
@@ -137,11 +136,10 @@ class ControlsRequestDialog @Inject constructor(
    }
    }


    fun createDialog(label: CharSequence): Dialog {
    fun createDialog(label: CharSequence): Dialog {

        val renderInfo = RenderInfo.lookup(this, component, control.deviceType, true)
        val renderInfo = RenderInfo.lookup(control.deviceType, true)
        val frame = LayoutInflater.from(this).inflate(R.layout.controls_dialog, null).apply {
        val frame = LayoutInflater.from(this).inflate(R.layout.controls_dialog, null).apply {
            requireViewById<ImageView>(R.id.icon).apply {
            requireViewById<ImageView>(R.id.icon).apply {
                setImageIcon(Icon.createWithResource(context, renderInfo.iconResourceId))
                setImageDrawable(renderInfo.icon)
                setImageTintList(
                setImageTintList(
                        context.resources.getColorStateList(renderInfo.foreground, context.theme))
                        context.resources.getColorStateList(renderInfo.foreground, context.theme))
            }
            }
+5 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.PendingIntent
import android.content.Intent
import android.content.Intent
import android.provider.Settings
import android.provider.Settings
import android.service.controls.actions.BooleanAction
import android.service.controls.actions.BooleanAction
import android.service.controls.actions.CommandAction
import android.util.Log
import android.util.Log
import android.view.HapticFeedbackConstants
import android.view.HapticFeedbackConstants


@@ -36,6 +37,10 @@ object ControlActionCoordinator {
        cvh.clipLayer.setLevel(nextLevel)
        cvh.clipLayer.setLevel(nextLevel)
    }
    }


    fun touch(cvh: ControlViewHolder, templateId: String) {
        cvh.action(CommandAction(templateId))
    }

    fun longPress(cvh: ControlViewHolder) {
    fun longPress(cvh: ControlViewHolder) {
        // Long press snould only be called when there is valid control state, otherwise ignore
        // Long press snould only be called when there is valid control state, otherwise ignore
        cvh.cws.control?.let {
        cvh.cws.control?.let {
Loading