use of android.text.style.ClickableSpan in project Signal-Android by signalapp.
the class RegistrationLockDialog method showReminderIfNecessary.
public static void showReminderIfNecessary(@NonNull Context context) {
if (!RegistrationLockReminders.needsReminder(context))
return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
AlertDialog dialog = new AlertDialog.Builder(context, R.style.RationaleDialog).setView(R.layout.registration_lock_reminder_view).setCancelable(true).setOnCancelListener(d -> RegistrationLockReminders.scheduleReminder(context, false)).create();
WindowManager windowManager = ServiceUtil.getWindowManager(context);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
dialog.getWindow().setLayout((int) (metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);
EditText pinEditText = dialog.findViewById(R.id.pin);
TextView reminder = dialog.findViewById(R.id.reminder);
assert pinEditText != null;
assert reminder != null;
SpannableString reminderIntro = new SpannableString(context.getString(R.string.RegistrationLockDialog_reminder));
SpannableString reminderText = new SpannableString(context.getString(R.string.RegistrationLockDialog_registration_lock_is_enabled_for_your_phone_number));
SpannableString forgotText = new SpannableString(context.getString(R.string.RegistrationLockDialog_i_forgot_my_pin));
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
dialog.dismiss();
new AlertDialog.Builder(context).setTitle(R.string.RegistrationLockDialog_forgotten_pin).setMessage(R.string.RegistrationLockDialog_registration_lock_helps_protect_your_phone_number_from_unauthorized_registration_attempts).setPositiveButton(android.R.string.ok, null).create().show();
}
};
reminderIntro.setSpan(new StyleSpan(Typeface.BOLD), 0, reminderIntro.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
forgotText.setSpan(clickableSpan, 0, forgotText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
reminder.setText(new SpannableStringBuilder(reminderIntro).append(" ").append(reminderText).append(" ").append(forgotText));
reminder.setMovementMethod(LinkMovementMethod.getInstance());
pinEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s != null && s.toString().replace(" ", "").equals(TextSecurePreferences.getRegistrationLockPin(context))) {
dialog.dismiss();
RegistrationLockReminders.scheduleReminder(context, true);
}
}
});
}
use of android.text.style.ClickableSpan in project Collar by CodeZsx.
the class ClickableMovementMethod method onTouchEvent.
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
ImageClickableSpan[] imageSpans = buffer.getSpans(off, off, ImageClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
}
return true;
} else if (imageSpans.length != 0) {
if (action == MotionEvent.ACTION_UP) {
imageSpans[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(imageSpans[0]), buffer.getSpanEnd(imageSpans[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
use of android.text.style.ClickableSpan in project android_packages_apps_Settings by crdroidandroid.
the class LinkifyUtils method linkify.
/**
* Applies the text into the {@link TextView} and part of it a clickable link.
* The text surrounded with "LINK_BEGIN" and "LINK_END" will become a clickable link. Only
* supports at most one link.
* @return true if the link has been successfully applied, or false if the original text
* contains no link place holders.
*/
public static boolean linkify(TextView textView, StringBuilder text, final OnClickListener listener) {
// Remove place-holders from the string and record their positions
final int beginIndex = text.indexOf(PLACE_HOLDER_LINK_BEGIN);
if (beginIndex == -1) {
textView.setText(text);
return false;
}
text.delete(beginIndex, beginIndex + PLACE_HOLDER_LINK_BEGIN.length());
final int endIndex = text.indexOf(PLACE_HOLDER_LINK_END);
if (endIndex == -1) {
textView.setText(text);
return false;
}
text.delete(endIndex, endIndex + PLACE_HOLDER_LINK_END.length());
textView.setText(text.toString(), BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());
Spannable spannableContent = (Spannable) textView.getText();
ClickableSpan spannableLink = new ClickableSpan() {
@Override
public void onClick(View widget) {
listener.onClick();
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
spannableContent.setSpan(spannableLink, beginIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return true;
}
use of android.text.style.ClickableSpan in project android_packages_apps_SetupWizard by LineageOS.
the class LineageSettingsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSetupWizardApp = (SetupWizardApp) getApplication();
setNextText(R.string.next);
String privacy_policy = getString(R.string.services_privacy_policy);
String policySummary = getString(R.string.services_explanation, privacy_policy);
SpannableString ss = new SpannableString(policySummary);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
// At this point of the setup, the device has already been unlocked (if frp
// had been enabled), so there should be no issues regarding security
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(PRIVACY_POLICY_URI));
try {
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Unable to start activity " + intent.toString(), e);
}
}
};
ss.setSpan(clickableSpan, policySummary.length() - privacy_policy.length() - 1, policySummary.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView privacyPolicy = (TextView) findViewById(R.id.privacy_policy);
privacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
privacyPolicy.setText(ss);
mMetricsRow = findViewById(R.id.metrics);
mMetricsRow.setOnClickListener(mMetricsClickListener);
String metricsHelpImproveLineage = getString(R.string.services_help_improve_cm, getString(R.string.os_name));
String metricsSummary = getString(R.string.services_metrics_label, metricsHelpImproveLineage, getString(R.string.os_name));
final SpannableStringBuilder metricsSpan = new SpannableStringBuilder(metricsSummary);
metricsSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), 0, metricsHelpImproveLineage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView metrics = (TextView) findViewById(R.id.enable_metrics_summary);
metrics.setText(metricsSpan);
mMetrics = (CheckBox) findViewById(R.id.enable_metrics_checkbox);
mNavKeysRow = findViewById(R.id.nav_keys);
mNavKeysRow.setOnClickListener(mNavKeysClickListener);
mNavKeys = (CheckBox) findViewById(R.id.nav_keys_checkbox);
boolean needsNavBar = true;
try {
IWindowManager windowManager = WindowManagerGlobal.getWindowManagerService();
needsNavBar = windowManager.needsNavigationBar();
} catch (RemoteException e) {
}
mHideNavKeysRow = hideKeyDisabler(this);
if (mHideNavKeysRow || needsNavBar) {
mNavKeysRow.setVisibility(View.GONE);
} else {
boolean navKeysDisabled = isKeyDisablerActive(this);
mNavKeys.setChecked(navKeysDisabled);
}
mPrivacyGuardRow = findViewById(R.id.privacy_guard);
mPrivacyGuardRow.setOnClickListener(mPrivacyGuardClickListener);
mPrivacyGuard = (CheckBox) findViewById(R.id.privacy_guard_checkbox);
mPrivacyGuard.setChecked(LineageSettings.Secure.getInt(getContentResolver(), LineageSettings.Secure.PRIVACY_GUARD_DEFAULT, 0) == 1);
}
use of android.text.style.ClickableSpan in project Signal-Android by WhisperSystems.
the class ConversationItem method getLongMessageSpan.
// / Event handlers
private Spannable getLongMessageSpan(@NonNull MessageRecord messageRecord) {
String message;
Runnable action;
if (messageRecord.isMms()) {
TextSlide slide = ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide();
if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_DONE) {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
} else if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_STARTED) {
message = getResources().getString(R.string.ConversationItem_pending);
action = () -> {
};
} else if (slide != null) {
message = getResources().getString(R.string.ConversationItem_download_more);
action = () -> singleDownloadClickListener.onClick(bodyText, slide);
} else {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
}
} else {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
}
SpannableStringBuilder span = new SpannableStringBuilder(message);
CharacterStyle style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
if (eventListener != null && batchSelected.isEmpty()) {
action.run();
}
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
span.setSpan(style, 0, span.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return span;
}
Aggregations