From 00ea11c80f999d509ab49493fdb0d819547a4427 Mon Sep 17 00:00:00 2001 From: mcarare Date: Wed, 29 Apr 2020 15:34:36 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/10285: Add a custom TextView for links with a11y improvements. --- .../org/mozilla/fenix/utils/LinkTextView.kt | 34 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt diff --git a/app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt b/app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt new file mode 100644 index 0000000000..88df32c648 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/utils/LinkTextView.kt @@ -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) + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 408eb60936..5ea444599e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1418,5 +1418,6 @@ To add a new top site, remove one. Long press the site and select remove. OK, Got It - + + link