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

Commit 9b29ea6e authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Make keyboard backlight indicator more accessible

1. Adding dialog title to describe what this dialog is about instead of default generic "SystemUI"
2. Update content description whenever value changes (or is shown for the first time)

Eventually we should write e2e test for a11y behaviour but currently e2e test for backlight indicator
is not yet viable because of driver issues, tracked as b/279899582

Test: Enable Talkback -> trigger backlight indicator -> notice announcement of "keyboard backlight indicator" and current level.
Test: Enable Talkback -> trigger backlight indicator -> change level -> notice announcement of new level
Fixes: 308407114
Change-Id: Ic1847b01c1d7b6ac928420052659688bf7ced7a8
parent 6d617f78
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3255,4 +3255,9 @@
    <string name="privacy_dialog_active_app_usage_2">In use by <xliff:g id="app_name" example="Gmail">%1$s</xliff:g> (<xliff:g id="attribution_label" example="For Wallet">%2$s</xliff:g> \u2022 <xliff:g id="proxy_label" example="Speech services">%3$s</xliff:g>)</string>
    <!-- Label for recent app usage of a phone sensor with sub-attribution and proxy label in the privacy dialog [CHAR LIMIT=NONE] -->
    <string name="privacy_dialog_recent_app_usage_2">Recently used by <xliff:g id="app_name" example="Gmail">%1$s</xliff:g> (<xliff:g id="attribution_label" example="For Wallet">%2$s</xliff:g> \u2022 <xliff:g id="proxy_label" example="Speech services">%3$s</xliff:g>)</string>

    <!-- Content description for keyboard backlight brightness dialog [CHAR LIMIT=NONE] -->
    <string name="keyboard_backlight_dialog_title">Keyboard backlight</string>
    <!-- Content description for keyboard backlight brightness value [CHAR LIMIT=NONE] -->
    <string name="keyboard_backlight_value">Level %1$d of %2$d</string>
</resources>
+22 −7
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.view.Window
import android.view.WindowManager
import android.view.accessibility.AccessibilityEvent
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
@@ -78,23 +79,29 @@ class KeyboardBacklightDialog(
    private lateinit var stepProperties: StepViewProperties

    @ColorInt
    var filledRectangleColor = getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
    private val filledRectangleColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
    @ColorInt
    var emptyRectangleColor =
    private val emptyRectangleColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorOutlineVariant)
    @ColorInt
    var backgroundColor = getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceBright)
    private val backgroundColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceBright)
    @ColorInt
    var defaultIconColor = getColorFromStyle(com.android.internal.R.attr.materialColorOnPrimary)
    private val defaultIconColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorOnPrimary)
    @ColorInt
    var defaultIconBackgroundColor =
    private val defaultIconBackgroundColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorPrimary)
    @ColorInt
    var dimmedIconColor = getColorFromStyle(com.android.internal.R.attr.materialColorOnSurface)
    private val dimmedIconColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorOnSurface)
    @ColorInt
    var dimmedIconBackgroundColor =
    private val dimmedIconBackgroundColor =
        getColorFromStyle(com.android.internal.R.attr.materialColorSurfaceDim)

    private val levelContentDescription = context.getString(R.string.keyboard_backlight_value)

    init {
        currentLevel = initialCurrentLevel
        maxLevel = initialMaxLevel
@@ -103,6 +110,8 @@ class KeyboardBacklightDialog(
    override fun onCreate(savedInstanceState: Bundle?) {
        setUpWindowProperties(this)
        setWindowPosition()
        // title is used for a11y announcement
        window?.setTitle(context.getString(R.string.keyboard_backlight_dialog_title))
        updateResources()
        rootView = buildRootView()
        setContentView(rootView)
@@ -159,6 +168,12 @@ class KeyboardBacklightDialog(
        currentLevel = current
        updateIconTile()
        updateStepColors()
        updateAccessibilityInfo()
    }

    private fun updateAccessibilityInfo() {
        rootView.contentDescription = String.format(levelContentDescription, currentLevel, maxLevel)
        rootView.sendAccessibilityEvent(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION)
    }

    private fun updateIconTile() {