summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/utils/AnnotationSpan.java
diff options
context:
space:
mode:
authorFan Zhang <zhfan@google.com>2018-03-20 18:07:31 -0700
committerFan Zhang <zhfan@google.com>2018-03-21 12:37:34 -0700
commit1ee2a88fd7a68f264bbd5799e39a22f7b19b5cfe (patch)
tree829b04a6994672c6d1bc19a03c520f5f07086b15 /src/com/android/settings/utils/AnnotationSpan.java
parentb5241a117fea4109ae40de4ebe660da269ef3af7 (diff)
downloadpackages_apps_Settings-1ee2a88fd7a68f264bbd5799e39a22f7b19b5cfe.tar.gz
packages_apps_Settings-1ee2a88fd7a68f264bbd5799e39a22f7b19b5cfe.tar.bz2
packages_apps_Settings-1ee2a88fd7a68f264bbd5799e39a22f7b19b5cfe.zip
Hide spannable link if it's not actionable
Created a new constructor that detects if intent is actionable and set a flag in LinkInfo. In fragments, first check if linkInfo is actionable, if not, don't do anything with it. Change-Id: Ibda12ecac2545d696acc7c197fc315e423b984aa Fixes: 74726487 Test: make RunSettingsRoboTests -j
Diffstat (limited to 'src/com/android/settings/utils/AnnotationSpan.java')
-rw-r--r--src/com/android/settings/utils/AnnotationSpan.java45
1 files changed, 39 insertions, 6 deletions
diff --git a/src/com/android/settings/utils/AnnotationSpan.java b/src/com/android/settings/utils/AnnotationSpan.java
index 645351df0b..c70cba53be 100644
--- a/src/com/android/settings/utils/AnnotationSpan.java
+++ b/src/com/android/settings/utils/AnnotationSpan.java
@@ -16,11 +16,15 @@
package com.android.settings.utils;
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
import android.text.Annotation;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.style.URLSpan;
+import android.util.Log;
import android.view.View;
/**
@@ -28,6 +32,7 @@ import android.view.View;
* annotation.
*/
public class AnnotationSpan extends URLSpan {
+
private final View.OnClickListener mClickListener;
private AnnotationSpan(View.OnClickListener lsn) {
@@ -58,8 +63,8 @@ public class AnnotationSpan extends URLSpan {
int end = msg.getSpanEnd(annotation);
AnnotationSpan link = null;
for (LinkInfo linkInfo : linkInfos) {
- if (linkInfo.annotation.equals(key)) {
- link = new AnnotationSpan(linkInfo.listener);
+ if (linkInfo.mAnnotation.equals(key)) {
+ link = new AnnotationSpan(linkInfo.mListener);
break;
}
}
@@ -74,12 +79,40 @@ public class AnnotationSpan extends URLSpan {
* Data class to store the annotation and the click action
*/
public static class LinkInfo {
- public final String annotation;
- public final View.OnClickListener listener;
+ private static final String TAG = "AnnotationSpan.LinkInfo";
+ private final String mAnnotation;
+ private final Boolean mActionable;
+ private final View.OnClickListener mListener;
public LinkInfo(String annotation, View.OnClickListener listener) {
- this.annotation = annotation;
- this.listener = listener;
+ mAnnotation = annotation;
+ mListener = listener;
+ mActionable = true; // assume actionable
+ }
+
+ public LinkInfo(Context context, String annotation, Intent intent) {
+ mAnnotation = annotation;
+ if (intent != null) {
+ mActionable = context.getPackageManager()
+ .resolveActivity(intent, 0 /* flags */) != null;
+ } else {
+ mActionable = false;
+ }
+ if (!mActionable) {
+ mListener = null;
+ } else {
+ mListener = view -> {
+ try {
+ view.startActivityForResult(intent, 0);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "Activity was not found for intent, " + intent);
+ }
+ };
+ }
+ }
+
+ public boolean isActionable() {
+ return mActionable;
}
}
}