For 11271 - Provide useful tab counter message for accessibility
parent
96d2307df0
commit
1356b3e426
|
@ -34,11 +34,22 @@ open class TabCounter @JvmOverloads constructor(
|
||||||
TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics
|
TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics
|
||||||
).toInt()
|
).toInt()
|
||||||
counter_text.setPadding(0, shiftThreeDp, shiftThreeDp, 0)
|
counter_text.setPadding(0, shiftThreeDp, shiftThreeDp, 0)
|
||||||
|
updateContentDescription(0)
|
||||||
|
|
||||||
animationSet = createAnimatorSet()
|
animationSet = createAnimatorSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateContentDescription(count: Int) {
|
||||||
|
counter_root.contentDescription = if (count == 1) {
|
||||||
|
context?.getString(R.string.open_tab_tray_single)
|
||||||
|
} else {
|
||||||
|
context?.getString(R.string.open_tab_tray_plural, count.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setCountWithAnimation(count: Int) {
|
fun setCountWithAnimation(count: Int) {
|
||||||
|
updateContentDescription(count)
|
||||||
|
|
||||||
// Don't animate from initial state.
|
// Don't animate from initial state.
|
||||||
if (this.count == 0) {
|
if (this.count == 0) {
|
||||||
setCount(count)
|
setCount(count)
|
||||||
|
@ -69,6 +80,7 @@ open class TabCounter @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCount(count: Int) {
|
fun setCount(count: Int) {
|
||||||
|
updateContentDescription(count)
|
||||||
adjustTextSize(count)
|
adjustTextSize(count)
|
||||||
|
|
||||||
counter_text.text = formatForDisplay(count)
|
counter_text.text = formatForDisplay(count)
|
||||||
|
|
|
@ -4,14 +4,12 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.components.toolbar
|
package org.mozilla.fenix.components.toolbar
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.browser.session.SessionManager
|
import mozilla.components.browser.session.SessionManager
|
||||||
import mozilla.components.concept.toolbar.Toolbar
|
import mozilla.components.concept.toolbar.Toolbar
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
|
@ -34,12 +32,6 @@ class TabCounterToolbarButton(
|
||||||
showTabs.invoke()
|
showTabs.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
val count = sessionManager.sessions.count {
|
|
||||||
it.private == isPrivate
|
|
||||||
}
|
|
||||||
|
|
||||||
contentDescription = getDescriptionForTabCount(context, count)
|
|
||||||
|
|
||||||
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||||
override fun onViewAttachedToWindow(v: View?) {
|
override fun onViewAttachedToWindow(v: View?) {
|
||||||
setCount(sessionManager.sessionsOfType(private = isPrivate).count())
|
setCount(sessionManager.sessionsOfType(private = isPrivate).count())
|
||||||
|
@ -66,18 +58,10 @@ class TabCounterToolbarButton(
|
||||||
val count = sessionManager.sessionsOfType(private = isPrivate).count()
|
val count = sessionManager.sessionsOfType(private = isPrivate).count()
|
||||||
|
|
||||||
reference.get()?.let {
|
reference.get()?.let {
|
||||||
it.contentDescription = getDescriptionForTabCount(it.context, count)
|
|
||||||
it.setCountWithAnimation(count)
|
it.setCountWithAnimation(count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDescriptionForTabCount(context: Context?, count: Int): String? {
|
|
||||||
return if (count > 1) context?.getString(
|
|
||||||
R.string.tab_counter_content_description_multi_tab,
|
|
||||||
count
|
|
||||||
) else context?.getString(R.string.tab_counter_content_description_one_tab)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val sessionManagerObserver = object : SessionManager.Observer {
|
private val sessionManagerObserver = object : SessionManager.Observer {
|
||||||
override fun onSessionAdded(session: Session) {
|
override fun onSessionAdded(session: Session) {
|
||||||
updateCount()
|
updateCount()
|
||||||
|
|
|
@ -21,6 +21,10 @@
|
||||||
<string name="no_open_tabs_description">Your open tabs will be shown here.</string>
|
<string name="no_open_tabs_description">Your open tabs will be shown here.</string>
|
||||||
<!-- No Private Tabs Message Description -->
|
<!-- No Private Tabs Message Description -->
|
||||||
<string name="no_private_tabs_description">Your private tabs will be shown here.</string>
|
<string name="no_private_tabs_description">Your private tabs will be shown here.</string>
|
||||||
|
<!-- Message announced to the user when tab tray is selected with 1 tab -->
|
||||||
|
<string name="open_tab_tray_single">1 open tab. Tap to switch tabs.</string>
|
||||||
|
<!-- Message announced to the user when tab tray is selected with 0 or 2+ tabs -->
|
||||||
|
<string name="open_tab_tray_plural">%1$s open tabs. Tap to switch tabs.</string>
|
||||||
|
|
||||||
<!-- About content. The first parameter is the name of the application. (For example: Fenix) -->
|
<!-- About content. The first parameter is the name of the application. (For example: Fenix) -->
|
||||||
<string name="about_content">%1$s is produced by Mozilla.</string>
|
<string name="about_content">%1$s is produced by Mozilla.</string>
|
||||||
|
|
Loading…
Reference in New Issue