summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tsung-Mao Fang <tmfang@google.com> 2021-05-24 21:47:15 +0800
committer Tsung-Mao Fang <tmfang@google.com> 2021-05-31 09:40:14 +0000
commiteb72a217bf4428c97bc758ce24c7fb358536499d (patch)
treec96354505e7bcff8f17ba7ffb54ec2d8338168fe
parent68d3b19012d73d2009f4e51aa2b3447093ee51b8 (diff)
Let talkback can identify a hyper link
Assign an URL span on the learn more text view, so talkback can treat it as a hyperlink now. Then, user can use three-fingers gesture to open talkback menu. Test: Set an action on a footer preference, and use talkabck. Talkback speaks correct content and user can operate the talkback menu. Fix: 188009297 Change-Id: I33aa27cfa8e9eba95375eb361a5e035a803a9759
-rw-r--r--packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java28
1 files changed, 25 insertions, 3 deletions
diff --git a/packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java b/packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java
index 33bf590cc2bb..005c75c45a46 100644
--- a/packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java
+++ b/packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java
@@ -20,7 +20,7 @@ import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
-import android.text.style.UnderlineSpan;
+import android.text.style.URLSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
@@ -67,9 +67,9 @@ public class FooterPreference extends Preference {
TextView learnMore = holder.itemView.findViewById(R.id.settingslib_learn_more);
if (learnMore != null && mLearnMoreListener != null) {
learnMore.setVisibility(View.VISIBLE);
- learnMore.setOnClickListener(mLearnMoreListener);
SpannableString learnMoreText = new SpannableString(learnMore.getText());
- learnMoreText.setSpan(new UnderlineSpan(), 0, learnMoreText.length(), 0);
+ learnMoreText.setSpan(new FooterLearnMoreSpan(mLearnMoreListener), 0,
+ learnMoreText.length(), 0);
learnMore.setText(learnMoreText);
if (!TextUtils.isEmpty(mLearnMoreContentDescription)) {
learnMore.setContentDescription(mLearnMoreContentDescription);
@@ -271,4 +271,26 @@ public class FooterPreference extends Preference {
return footerPreference;
}
}
+
+ /**
+ * A {@link URLSpan} that opens a support page when clicked
+ */
+ static class FooterLearnMoreSpan extends URLSpan {
+
+ private final View.OnClickListener mClickListener;
+
+ FooterLearnMoreSpan(View.OnClickListener clickListener) {
+ // sets the url to empty string so we can prevent any other span processing from
+ // clearing things we need in this string.
+ super("");
+ mClickListener = clickListener;
+ }
+
+ @Override
+ public void onClick(View widget) {
+ if (mClickListener != null) {
+ mClickListener.onClick(widget);
+ }
+ }
+ }
}