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
This commit is contained in:
@@ -21,7 +21,6 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -99,8 +98,6 @@ public class FingerprintSettings extends SubSettings {
|
||||
public static final String ANNOTATION_URL = "url";
|
||||
public static final String ANNOTATION_ADMIN_DETAILS = "admin_details";
|
||||
|
||||
public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
Intent modIntent = new Intent(super.getIntent());
|
||||
@@ -158,20 +155,6 @@ public class FingerprintSettings extends SubSettings {
|
||||
private FingerprintRemoveSidecar mRemovalSidecar;
|
||||
private HashMap<Integer, String> mFingerprintsRenaming;
|
||||
|
||||
final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
|
||||
ANNOTATION_URL, (view) -> {
|
||||
final Context context = view.getContext();
|
||||
Intent intent = HelpUtils.getHelpIntent(context, getString(getHelpResource()),
|
||||
context.getClass().getName());
|
||||
if (intent != null) {
|
||||
try {
|
||||
view.startActivityForResult(intent, 0);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity was not found for intent, " + intent.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FingerprintAuthenticateSidecar.Listener mAuthenticateListener =
|
||||
new FingerprintAuthenticateSidecar.Listener() {
|
||||
@Override
|
||||
@@ -360,11 +343,15 @@ public class FingerprintSettings extends SubSettings {
|
||||
ANNOTATION_ADMIN_DETAILS, (view) -> {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(activity, admin);
|
||||
});
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(
|
||||
activity, getString(getHelpResource()), activity.getClass().getName());
|
||||
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(
|
||||
activity, ANNOTATION_URL, helpIntent);
|
||||
pref.setTitle(AnnotationSpan.linkify(getText(admin != null
|
||||
? R.string
|
||||
.security_settings_fingerprint_enroll_disclaimer_lockscreen_disabled
|
||||
: R.string.security_settings_fingerprint_enroll_disclaimer),
|
||||
mUrlLinkInfo, adminLinkInfo));
|
||||
linkInfo, adminLinkInfo));
|
||||
}
|
||||
|
||||
protected void removeFingerprintPreference(int fingerprintId) {
|
||||
|
@@ -22,7 +22,6 @@ import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -33,7 +32,6 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@@ -58,7 +56,7 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
|
||||
public static final String ANNOTATION_URL = "url";
|
||||
|
||||
private static final String TAG = "PrivateDnsModeDialogFragment";
|
||||
private static final String TAG = "PrivateDnsModeDialog";
|
||||
// DNS_MODE -> RadioButton id
|
||||
private static final Map<String, Integer> PRIVATE_DNS_MAP;
|
||||
|
||||
@@ -83,21 +81,6 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
@VisibleForTesting
|
||||
String mMode;
|
||||
|
||||
private final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
|
||||
ANNOTATION_URL, (widget) -> {
|
||||
final Context context = widget.getContext();
|
||||
final Intent intent = HelpUtils.getHelpIntent(context,
|
||||
getString(R.string.help_uri_private_dns),
|
||||
context.getClass().getName());
|
||||
if (intent != null) {
|
||||
try {
|
||||
widget.startActivityForResult(intent, 0);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity was not found for intent, " + intent.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static void show(FragmentManager fragmentManager) {
|
||||
if (fragmentManager.findFragmentByTag(TAG) == null) {
|
||||
final PrivateDnsModeDialogFragment fragment = new PrivateDnsModeDialogFragment();
|
||||
@@ -139,8 +122,15 @@ public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment imp
|
||||
|
||||
final TextView helpTextView = view.findViewById(R.id.private_dns_help_info);
|
||||
helpTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
helpTextView.setText(AnnotationSpan.linkify(
|
||||
context.getText(R.string.private_dns_help_message), mUrlLinkInfo));
|
||||
final Intent helpIntent = HelpUtils.getHelpIntent(context,
|
||||
context.getString(R.string.help_uri_private_dns),
|
||||
context.getClass().getName());
|
||||
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(context,
|
||||
ANNOTATION_URL, helpIntent);
|
||||
if (linkInfo.isActionable()) {
|
||||
helpTextView.setText(AnnotationSpan.linkify(
|
||||
context.getText(R.string.private_dns_help_message), linkInfo));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user