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

Commit e7e879de authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

Adds toggle support for quick affordances.

Introduces the ability to toggle quick affordance buttons on the
lock-screen.

Developers of keyguard quick affordances will now have the option of
providing an ON or OFF state for their toggle (or leave it unset) and
the reset of the system will reflect that state onto the UI.

Bug: 253094565
Test: Temporarily added a fake toggle config to the collection of
keyguard quick affordances and made sure it looks correct on both dark
and light themes on the lock-screen and toggles appropriately. Also
expansed existing unit tests to cover for the new state.

Change-Id: Idddb4baeb19c603a6663347a7b4319751f02fd2f
parent f4ceebba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ constructor(
                KeyguardQuickAffordanceModel.Visible(
                    configKey = configs[index]::class,
                    icon = visibleState.icon,
                    toggle = visibleState.toggle,
                )
            } else {
                KeyguardQuickAffordanceModel.Hidden
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyguard.domain.model

import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.domain.quickaffordance.KeyguardQuickAffordanceConfig
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import kotlin.reflect.KClass

/**
@@ -35,5 +36,7 @@ sealed class KeyguardQuickAffordanceModel {
        val configKey: KClass<out KeyguardQuickAffordanceConfig>,
        /** An icon for the affordance. */
        val icon: Icon,
        /** The toggle state for the affordance. */
        val toggle: KeyguardQuickAffordanceToggleState,
    ) : KeyguardQuickAffordanceModel()
}
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.android.systemui.keyguard.domain.quickaffordance
import android.content.Intent
import com.android.systemui.animation.ActivityLaunchAnimator
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordanceToggleState
import kotlinx.coroutines.flow.Flow

/** Defines interface that can act as data source for a single quick affordance model. */
@@ -44,6 +45,9 @@ interface KeyguardQuickAffordanceConfig {
        data class Visible(
            /** An icon for the affordance. */
            val icon: Icon,
            /** The toggle state for the affordance. */
            val toggle: KeyguardQuickAffordanceToggleState =
                KeyguardQuickAffordanceToggleState.NotSupported,
        ) : State()
    }

+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 *
 */

package com.android.systemui.keyguard.shared.quickaffordance

/** Enumerates all possible toggle states for a quick affordance on the lock-screen. */
sealed class KeyguardQuickAffordanceToggleState {
    /** Toggling is not supported. */
    object NotSupported : KeyguardQuickAffordanceToggleState()
    /** The quick affordance is on. */
    object On : KeyguardQuickAffordanceToggleState()
    /** The quick affordance is off. */
    object Off : KeyguardQuickAffordanceToggleState()
}
+14 −2
Original line number Diff line number Diff line
@@ -238,14 +238,26 @@ object KeyguardBottomAreaViewBinder {

        IconViewBinder.bind(viewModel.icon, view)

        view.isActivated = viewModel.isActivated
        view.drawable.setTint(
            Utils.getColorAttrDefaultColor(
                view.context,
                if (viewModel.isActivated) {
                    com.android.internal.R.attr.textColorPrimaryInverse
                } else {
                    com.android.internal.R.attr.textColorPrimary
                },
            )
        )
        view.backgroundTintList =
            Utils.getColorAttr(view.context, com.android.internal.R.attr.colorSurface)
            Utils.getColorAttr(
                view.context,
                if (viewModel.isActivated) {
                    com.android.internal.R.attr.colorAccentPrimary
                } else {
                    com.android.internal.R.attr.colorSurface
                }
            )

        view.isClickable = viewModel.isClickable
        if (viewModel.isClickable) {
Loading