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

Commit 7d0c9340 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Make keyboard backlight indicator more accessible" into main

parents 43e49fd3 9b29ea6e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3266,4 +3266,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() {