mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/10285: Add a custom TextView for links with a11y improvements.
This commit is contained in:
parent
3cd4cfe0a1
commit
00ea11c80f
34
app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt
Normal file
34
app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt
Normal file
@ -0,0 +1,34 @@
|
||||
/* 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 extras = info?.extras
|
||||
extras?.putCharSequence(
|
||||
"AccessibilityNodeInfo.roleDescription",
|
||||
context.resources.getString(R.string.link_text_view_type_announcement)
|
||||
)
|
||||
// disable long click announcement, as there is no action to be performed on long click
|
||||
info?.isLongClickable = false
|
||||
info?.removeAction(ACTION_LONG_CLICK)
|
||||
}
|
||||
}
|
@ -1418,5 +1418,6 @@
|
||||
<string name="top_sites_max_limit_content">To add a new top site, remove one. Long press the site and select remove.</string>
|
||||
<!-- Confirmation dialog button text when top sites limit is reached. -->
|
||||
<string name="top_sites_max_limit_confirmation_button">OK, Got It</string>
|
||||
|
||||
<!-- Content description (not visible, for screen readers etc.) used to announce [LinkTextView]. -->
|
||||
<string name="link_text_view_type_announcement">link</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user