Skip to content

Commit

Permalink
For mozilla-mobile#10285: Add a custom TextView for links with a11y i…
Browse files Browse the repository at this point in the history
…mprovements.
  • Loading branch information
mcarare committed Apr 29, 2020
1 parent 18bd93c commit eb0828c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.utils

import android.content.Context
import android.util.AttributeSet
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK
import androidx.appcompat.widget.AppCompatTextView
import org.mozilla.fenix.R

/**
* An [AppCompatTextView] that announces as link in screen readers for a11y purposes
*/
class LinkTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {

override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo?) {
super.onInitializeAccessibilityNodeInfo(info)
val customClick =
AccessibilityNodeInfo.AccessibilityAction(
AccessibilityNodeInfo.ACTION_CLICK,
context.resources.getString(R.string.link_text_view_action_click_announcement)

This comment has been minimized.

Copy link
@eeejay

eeejay May 5, 2020

You shouldn't need to add custom actions here with localized strings. I think adding a stock click action (aka AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK), and setting a role description in the "extras" bundle to link.

You can see how we do the latter in geckoview.

This will give the user a consistent presentation they get in web views when encountering a link. TalkBack should announce something like "Learn More, link". and after a pause "double tap to activate".

)

info?.addAction(customClick)
// disable long click announcement, as there is no action to be performed on long click
info?.isLongClickable = false
info?.removeAction(ACTION_LONG_CLICK)
}

override fun createAccessibilityNodeInfo(): AccessibilityNodeInfo {
contentDescription =
this.text.toString() + ", " + context.resources.getString(R.string.link_text_view_type_announcement)
return super.createAccessibilityNodeInfo()
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1324,4 +1324,9 @@
<string name="login_deletion_confirmation">Are you sure you want to delete this login?</string>
<!-- Positive action of a dialog asking to delete -->
<string name="dialog_delete_positive">Delete</string>

<!-- Content description (not visible, for screen readers etc.) used to announce [LinkTextView]. -->
<string name="link_text_view_type_announcement">Link</string>
<!-- Action description for click (not visible, for screen readers etc.) for [LinkTextView]. -->
<string name="link_text_view_action_click_announcement">Follow link</string>
</resources>

0 comments on commit eb0828c

Please sign in to comment.