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

Commit 4bc5ffe1 authored by Bhavuk Jain's avatar Bhavuk Jain
Browse files

Fixed content description for clock face width slider

This CL aims at fixing the content description for clock face width
slider. This ensures that we announce the range as well as the label
when focussed on the clock face width slider.

Bug: b/418223312
Flag: EXEMPT bugfix
Test: Tested by building & installing picker on local, and checking if
the content description contains range and label as well.

Change-Id: I42fd17a4e26b29688af5225fb373d64830d73530
parent 71533ec8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -647,4 +647,16 @@
    [CHAR LIMIT=128].
    -->
    <string name="custom_clocks_label">Custom Clocks</string>

    <!--
    Accessibility label for the Clock face width label.
    -->
    <string name="clock_face_width">Clock face width</string>

    <!--
    Accessibility announcement template for a numerical range.
    %1$d is the minimum value, %2$d is the maximum value.
    Example: "range from 1 to 7". [CHAR LIMIT=none]
    -->
    <string name="range_announcement_template">range from %1$d to %2$d</string>
</resources>
+57 −1
Original line number Diff line number Diff line
@@ -23,10 +23,12 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.core.view.get
import androidx.core.view.isEmpty
import androidx.core.view.isVisible
@@ -137,7 +139,61 @@ object ClockFloatingSheetBinder {
        val axisPresetSlider: Slider =
            clockStyleContent.requireViewById(R.id.clock_axis_preset_slider)

        // Clock color
        // Setting content description for the clock face width slider
        val sliderLabel = appContext.getString(R.string.clock_face_width)
        axisPresetSlider.contentDescription = sliderLabel
        axisPresetSlider.setAccessibilityDelegate(
            object : View.AccessibilityDelegate() {
                override fun onInitializeAccessibilityNodeInfo(
                    host: View,
                    info: AccessibilityNodeInfo,
                ) {
                    super.onInitializeAccessibilityNodeInfo(host, info)
                    val infoCompat = AccessibilityNodeInfoCompat.wrap(info)

                    if (host !is Slider) return

                    // increased these values by 1.0 in order to announce for content description
                    val actualMin = host.valueFrom + 1.0f
                    val actualMax = host.valueTo + 1.0f
                    val currentValueActual = host.value + 1.0f

                    val normalizedPosition =
                        if (actualMax - actualMin == 0f) {
                            0f
                        } else {
                            ((currentValueActual - actualMin) / (actualMax - actualMin)).coerceIn(
                                0f,
                                1f,
                            )
                        }
                    val mappedValueFloat = actualMin + normalizedPosition * (actualMax - actualMin)
                    val mappedValueInt = Math.round(mappedValueFloat)

                    val conceptualMinInt = actualMin.toInt()
                    val conceptualMaxInt = actualMax.toInt()
                    // this is a workaround that is needed because talkback isn't announcing the
                    // range using RangeInfo on the material slider.
                    val hardcodedRangeText =
                        appContext.getString(
                            R.string.range_announcement_template,
                            conceptualMinInt,
                            conceptualMaxInt,
                        )
                    val customRangeInfo =
                        AccessibilityNodeInfoCompat.RangeInfoCompat.obtain(
                            AccessibilityNodeInfoCompat.RangeInfoCompat.RANGE_TYPE_INT,
                            actualMin,
                            actualMax,
                            mappedValueInt.toFloat(),
                        )
                    infoCompat.rangeInfo = customRangeInfo
                    infoCompat.text = null
                    infoCompat.stateDescription = "$mappedValueInt, $hardcodedRangeText"
                }
            }
        )

        val clockColorContent: View = view.requireViewById(R.id.clock_floating_sheet_color_content)

        val clockColorAdapter =