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

Commit dc4b512e authored by Ned Burns's avatar Ned Burns Committed by Android (Google) Code Review
Browse files

Merge "Revert "Make keyboard backlight indicator more accessible"" into main

parents da3d8e9d abcb004d
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -3266,9 +3266,4 @@
    <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>
+7 −22
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ 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
@@ -79,29 +78,23 @@ class KeyboardBacklightDialog(
    private lateinit var stepProperties: StepViewProperties

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

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

    init {
        currentLevel = initialCurrentLevel
        maxLevel = initialMaxLevel
@@ -110,8 +103,6 @@ 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)
@@ -168,12 +159,6 @@ 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() {
+0 −84
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.keyboard.backlight.ui.view

import android.testing.TestableLooper.RunWithLooper
import android.view.View
import android.view.accessibility.AccessibilityEvent
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWithLooper
@SmallTest
@RunWith(JUnit4::class)
class KeyboardBacklightDialogTest : SysuiTestCase() {

    private lateinit var dialog: KeyboardBacklightDialog
    private lateinit var rootView: View
    private val descriptionString = context.getString(R.string.keyboard_backlight_value)

    @Before
    fun setUp() {
        dialog =
            KeyboardBacklightDialog(context, initialCurrentLevel = 0, initialMaxLevel = MAX_LEVEL)
        dialog.show()
        rootView = dialog.requireViewById(R.id.keyboard_backlight_dialog_container)
    }

    @Test
    fun rootViewContentDescription_containsInitialLevel() {
        assertThat(rootView.contentDescription).isEqualTo(contentDescriptionForLevel(INITIAL_LEVEL))
    }

    @Test
    fun contentDescriptionUpdated_afterEveryLevelUpdate() {
        val events = startCollectingAccessibilityEvents(rootView)

        dialog.updateState(current = 1, max = MAX_LEVEL)

        assertThat(rootView.contentDescription).isEqualTo(contentDescriptionForLevel(1))
        assertThat(events).contains(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION)
    }

    private fun contentDescriptionForLevel(level: Int): String {
        return String.format(descriptionString, level, MAX_LEVEL)
    }

    private fun startCollectingAccessibilityEvents(rootView: View): MutableList<Int> {
        val events = mutableListOf<Int>()
        rootView.accessibilityDelegate =
            object : View.AccessibilityDelegate() {
                override fun sendAccessibilityEvent(host: View, eventType: Int) {
                    super.sendAccessibilityEvent(host, eventType)
                    events.add(eventType)
                }
            }
        return events
    }

    companion object {
        private const val MAX_LEVEL = 5
        private const val INITIAL_LEVEL = 0
    }
}