Search in sources :

Example 86 with ClickableSpan

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);
            }
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Typeface(android.graphics.Typeface) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) Context(android.content.Context) Spanned(android.text.Spanned) ProgressBar(android.widget.ProgressBar) WindowManager(android.view.WindowManager) ClickableSpan(android.text.style.ClickableSpan) NonNull(android.support.annotation.NonNull) LinkMovementMethod(android.text.method.LinkMovementMethod) R(org.thoughtcrime.securesms.R) Editable(android.text.Editable) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) Toast(android.widget.Toast) Display(android.view.Display) View(android.view.View) Button(android.widget.Button) Build(android.os.Build) Log(android.util.Log) DialogInterface(android.content.DialogInterface) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) AsyncTask(android.os.AsyncTask) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) IOException(java.io.IOException) SwitchPreferenceCompat(org.thoughtcrime.securesms.components.SwitchPreferenceCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Optional(org.whispersystems.libsignal.util.guava.Optional) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Activity(android.app.Activity) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) EditText(android.widget.EditText) SpannableStringBuilder(android.text.SpannableStringBuilder) DisplayMetrics(android.util.DisplayMetrics) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder) Display(android.view.Display)

Example 87 with ClickableSpan

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;
}
Also used : Layout(android.text.Layout) ClickableSpan(android.text.style.ClickableSpan)

Example 88 with ClickableSpan

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;
}
Also used : ClickableSpan(android.text.style.ClickableSpan) TextView(android.widget.TextView) View(android.view.View) TextPaint(android.text.TextPaint) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint)

Example 89 with ClickableSpan

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);
}
Also used : IWindowManager(android.view.IWindowManager) Intent(android.content.Intent) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RemoteException(android.os.RemoteException) SpannableString(android.text.SpannableString) TextView(android.widget.TextView) RemoteException(android.os.RemoteException) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 90 with ClickableSpan

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;
}
Also used : NonNull(androidx.annotation.NonNull) TextSlide(org.thoughtcrime.securesms.mms.TextSlide) SpannableString(android.text.SpannableString) ClickableSpan(android.text.style.ClickableSpan) LinkPreviewView(org.thoughtcrime.securesms.components.LinkPreviewView) AlertView(org.thoughtcrime.securesms.components.AlertView) ViewOnceMessageView(org.thoughtcrime.securesms.revealable.ViewOnceMessageView) PlaybackSpeedToggleTextView(org.thoughtcrime.securesms.components.PlaybackSpeedToggleTextView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) DocumentView(org.thoughtcrime.securesms.components.DocumentView) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) QuoteView(org.thoughtcrime.securesms.components.QuoteView) SharedContactView(org.thoughtcrime.securesms.components.SharedContactView) TextView(android.widget.TextView) ReactionsConversationView(org.thoughtcrime.securesms.reactions.ReactionsConversationView) BorderlessImageView(org.thoughtcrime.securesms.components.BorderlessImageView) AudioView(org.thoughtcrime.securesms.components.AudioView) BadgeImageView(org.thoughtcrime.securesms.badges.BadgeImageView) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) TextPaint(android.text.TextPaint)

Aggregations

ClickableSpan (android.text.style.ClickableSpan)133 View (android.view.View)76 TextView (android.widget.TextView)55 TextPaint (android.text.TextPaint)50 SpannableString (android.text.SpannableString)46 Layout (android.text.Layout)37 Spannable (android.text.Spannable)28 SpannableStringBuilder (android.text.SpannableStringBuilder)24 Intent (android.content.Intent)17 NonNull (androidx.annotation.NonNull)15 Paint (android.graphics.Paint)14 Context (android.content.Context)12 Spanned (android.text.Spanned)12 URLSpan (android.text.style.URLSpan)12 ImageView (android.widget.ImageView)12 StyleSpan (android.text.style.StyleSpan)9 Uri (android.net.Uri)8 SuppressLint (android.annotation.SuppressLint)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 DialogInterface (android.content.DialogInterface)6