From fed54f7dc4ad27ac86e3a72d4cb6bfef72c80836 Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Tue, 23 Jun 2020 21:15:06 +0800 Subject: [PATCH] [Settings] Learn more link should be removed when not supported. Learn more wording with link only help people when configured. When no link available, these wording had better removed to avoid from confusing people. Bug: 159510116 Test: manual Merged-In: I36b74b2b4586546090fb88562e8f4f052a877709 Change-Id: If7061e0be201b2f98964a7b0eec42cc17cb11ae3 --- res/values/strings.xml | 6 +++--- ...abledInDsdsFooterPreferenceController.java | 2 +- .../settings/utils/AnnotationSpan.java | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 09a895735d7..13ad23441ff 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -11337,11 +11337,11 @@ - When using 2 SIMs, this phone will be limited to 4G. Learn more. + When using 2 SIMs, this phone will be limited to 4G. Learn more - When using 2 SIMs, this tablet will be limited to 4G. Learn more. + When using 2 SIMs, this tablet will be limited to 4G. Learn more - When using 2 SIMs, this device will be limited to 4G. Learn more. + When using 2 SIMs, this device will be limited to 4G. Learn more diff --git a/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceController.java b/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceController.java index 4077e91ae8d..3911fb8038e 100644 --- a/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceController.java +++ b/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceController.java @@ -69,7 +69,7 @@ public class NrDisabledInDsdsFooterPreferenceController extends BasePreferenceCo if (linkInfo.isActionable()) { return AnnotationSpan.linkify(mContext.getText(R.string.no_5g_in_dsds_text), linkInfo); } else { - return mContext.getText(R.string.no_5g_in_dsds_text); + return AnnotationSpan.textWithoutLink(mContext.getText(R.string.no_5g_in_dsds_text)); } } diff --git a/src/com/android/settings/utils/AnnotationSpan.java b/src/com/android/settings/utils/AnnotationSpan.java index e6457dac793..137c8cfbab0 100644 --- a/src/com/android/settings/utils/AnnotationSpan.java +++ b/src/com/android/settings/utils/AnnotationSpan.java @@ -27,6 +27,9 @@ import android.text.style.URLSpan; import android.util.Log; import android.view.View; +import java.util.Arrays; +import java.util.Comparator; + /** * This class is used to add {@link View.OnClickListener} for the text been wrapped by * annotation. @@ -75,6 +78,23 @@ public class AnnotationSpan extends URLSpan { return builder; } + /** + * get the text part without having text for link part + */ + public static CharSequence textWithoutLink(CharSequence encodedText) { + SpannableString msg = new SpannableString(encodedText); + Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class); + if (spans == null) { + return encodedText; + } + Arrays.sort(spans, Comparator.comparingInt(span -> -msg.getSpanStart(span))); + StringBuilder msgWithoutLink = new StringBuilder(msg.toString()); + for (Annotation span : spans) { + msgWithoutLink.delete(msg.getSpanStart(span), msg.getSpanEnd(span)); + } + return msgWithoutLink.toString(); + } + /** * Data class to store the annotation and the click action */