forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#10285: Add a custom TextView for links with a11y i…
…mprovements.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
) | ||
|
||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 tolink
.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".