Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For 11271 - Provide useful tab counter message for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing authored and ekager committed Jun 10, 2020
1 parent 96d2307 commit 1356b3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ open class TabCounter @JvmOverloads constructor(
TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics
).toInt()
counter_text.setPadding(0, shiftThreeDp, shiftThreeDp, 0)
updateContentDescription(0)

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) {
updateContentDescription(count)

// Don't animate from initial state.
if (this.count == 0) {
setCount(count)
Expand Down Expand Up @@ -69,6 +80,7 @@ open class TabCounter @JvmOverloads constructor(
}

fun setCount(count: Int) {
updateContentDescription(count)
adjustTextSize(count)

counter_text.text = formatForDisplay(count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

package org.mozilla.fenix.components.toolbar

import android.content.Context
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.toolbar.Toolbar
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.sessionsOfType
import java.lang.ref.WeakReference

Expand All @@ -34,12 +32,6 @@ class TabCounterToolbarButton(
showTabs.invoke()
}

val count = sessionManager.sessions.count {
it.private == isPrivate
}

contentDescription = getDescriptionForTabCount(context, count)

addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View?) {
setCount(sessionManager.sessionsOfType(private = isPrivate).count())
Expand All @@ -66,18 +58,10 @@ class TabCounterToolbarButton(
val count = sessionManager.sessionsOfType(private = isPrivate).count()

reference.get()?.let {
it.contentDescription = getDescriptionForTabCount(it.context, 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 {
override fun onSessionAdded(session: Session) {
updateCount()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<string name="no_open_tabs_description">Your open tabs will be shown here.</string>
<!-- No Private Tabs Message Description -->
<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) -->
<string name="about_content">%1$s is produced by Mozilla.</string>
Expand Down

0 comments on commit 1356b3e

Please sign in to comment.