For #10049: Provide correct seek bar value to screen readers.
This commit is contained in:
parent
00862708ae
commit
721e290734
|
@ -29,9 +29,11 @@ import android.util.Log
|
|||
import android.util.TypedValue
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
import android.widget.SeekBar
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat.RANGE_TYPE_PERCENT
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import org.mozilla.fenix.R
|
||||
|
@ -340,6 +342,25 @@ class TextPercentageSeekBarPreference @JvmOverloads constructor(
|
|||
val percentage = NumberFormat.getPercentInstance().format(decimalValue)
|
||||
mSeekBarValueTextView?.text = percentage
|
||||
}
|
||||
|
||||
mSeekBar?.setAccessibilityDelegate(object :
|
||||
View.AccessibilityDelegate() {
|
||||
override fun onInitializeAccessibilityNodeInfo(
|
||||
host: View?,
|
||||
info: AccessibilityNodeInfo?
|
||||
) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info)
|
||||
val initialInfo = info?.rangeInfo
|
||||
info?.rangeInfo = initialInfo?.let {
|
||||
AccessibilityNodeInfo.RangeInfo.obtain(
|
||||
RANGE_TYPE_PERCENT,
|
||||
MIN_VALUE.toFloat(),
|
||||
SEEK_BAR_MAX.toFloat(),
|
||||
convertCurrentValue(it.current)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,6 +454,10 @@ class TextPercentageSeekBarPreference @JvmOverloads constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun convertCurrentValue(current: Float): Float {
|
||||
return current * STEP_SIZE + MIN_VALUE.toFloat()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SeekBarPreference"
|
||||
private const val STEP_SIZE = 5
|
||||
|
|
Loading…
Reference in New Issue
Block a user