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

Commit dbc90fad authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Controls UI - Stateless controls" into rvc-dev

parents 02e00a37 53a8bbdd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.systemui.controls

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

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

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

package com.android.systemui.controls.management

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

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

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

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

    fun createDialog(label: CharSequence): Dialog {

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

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

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

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