Example usage for android.text.util Linkify addLinks

List of usage examples for android.text.util Linkify addLinks

Introduction

In this page you can find the example usage for android.text.util Linkify addLinks.

Prototype

public static final boolean addLinks(@NonNull TextView text, @LinkifyMask int mask) 

Source Link

Document

Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links.

Usage

From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java

void showServerPrompt(final boolean userInitiated) {
    final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);

    final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt));
    Linkify.addLinks(message, Linkify.ALL);

    final AlertDialog dialog = new AlertDialog.Builder(PTimerEditActivity.this).setTitle(R.string.server_title)
            .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();
                    if (userInitiated) {
                        finish();/*from   w ww . ja va 2  s  .c o  m*/
                    } else {
                        sendStatsToServerAndFinish();
                    }
                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2);
                    int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0);
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    if (userInitiated) {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2);

                    } else {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    if (userInitiated) {
                        // If the user initiated, err on the safe side and disable
                        // sending crash reports too. There's no way to turn them
                        // back on now aside from clearing data from this app, but
                        // it doesn't matter, we don't need error reports from every
                        // user ever.
                        prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();

    // Make links clicky
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.SpeechEd.SpeechEdEditActivity.java

void showServerPrompt(final boolean userInitiated) {
    final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);

    final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt));
    Linkify.addLinks(message, Linkify.ALL);

    final AlertDialog dialog = new AlertDialog.Builder(SpeechEdEditActivity.this)
            .setTitle(R.string.server_title).setMessage(message)
            .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();
                    if (userInitiated) {
                        finish();/*from   w w w.  j a  v a2 s  .  co  m*/
                    } else {
                        sendStatsToServerAndFinish();
                    }
                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2);
                    int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0);
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    if (userInitiated) {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2);

                    } else {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    if (userInitiated) {
                        // If the user initiated, err on the safe side and disable
                        // sending crash reports too. There's no way to turn them
                        // back on now aside from clearing data from this app, but
                        // it doesn't matter, we don't need error reports from every
                        // user ever.
                        prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();

    // Make links clicky
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

public void helpDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = getLayoutInflater();
    builder.setView(inflater.inflate(R.layout.info_dialog, null));
    AlertDialog ad = builder.create();/*  ww  w.ja  v  a  2  s.  c  om*/
    ad.setTitle("Mood Wallpaper");
    ad.setButton(AlertDialog.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    ad.show();

    TextView noteView = (TextView) ad.findViewById(R.id.web_link);
    noteView.setText("www.somthing.com/zert");
    Linkify.addLinks(noteView, Linkify.ALL);

    TextView email = (TextView) ad.findViewById(R.id.email_zert);
    email.setText("zert@gmail.com");
    Linkify.addLinks(email, Linkify.EMAIL_ADDRESSES);

}

From source file:com.Beat.RingdroidEditActivity.java

void showServerPrompt(final boolean userInitiated) {
    final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);

    final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt));
    Linkify.addLinks(message, Linkify.ALL);

    final AlertDialog dialog = new AlertDialog.Builder(RingdroidEditActivity.this)
            .setTitle(R.string.server_title).setMessage(message)
            .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();
                    if (userInitiated) {
                        finish();/*from www.jav  a2  s  . co m*/
                    } else {
                        sendStatsToServerAndFinish();
                    }
                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2);
                    int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0);
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    if (userInitiated) {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2);

                    } else {
                        prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    SharedPreferences.Editor prefsEditor = prefs.edit();
                    prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    if (userInitiated) {
                        // If the user initiated, err on the safe side and disable
                        // sending crash reports too. There's no way to turn them
                        // back on now aside from clearing data from this app, but
                        // it doesn't matter, we don't need error reports from every
                        // user ever.
                        prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    }
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();

    // Make links clicky
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Linkify partial HTML. Linkify methods remove all spans before building links, this
 * method preserves them.//  www  .  ja  va  2  s.co m
 * 
 * See: http://stackoverflow.com/questions/14538113/using-linkify-addlinks-combine-with-html-fromhtml
 * 
 * @param html         Partial HTML
 * @param linkifyMask   Linkify mask to use in Linkify.addLinks
 * 
 * @return            Spannable with all links
 */
public static Spannable linkifyHtml(String html, int linkifyMask) {
    // Get the spannable HTML
    Spanned text = Html.fromHtml(html);
    // Save the span details for later restoration
    URLSpan[] currentSpans = text.getSpans(0, text.length(), URLSpan.class);

    // Build an empty spannable then add the links
    SpannableString buffer = new SpannableString(text);
    Linkify.addLinks(buffer, linkifyMask);

    // Add back the HTML spannables
    for (URLSpan span : currentSpans) {
        int end = text.getSpanEnd(span);
        int start = text.getSpanStart(span);
        buffer.setSpan(span, start, end, 0);
    }
    return buffer;
}

From source file:cgeo.geocaching.CacheDetailActivity.java

private static void setPersonalNote(final TextView personalNoteView, final String personalNote) {
    personalNoteView.setText(personalNote, TextView.BufferType.SPANNABLE);
    if (StringUtils.isNotBlank(personalNote)) {
        personalNoteView.setVisibility(View.VISIBLE);
        Linkify.addLinks(personalNoteView, Linkify.MAP_ADDRESSES | Linkify.WEB_URLS);
    } else {//  w w  w.  j  a va2 s . co  m
        personalNoteView.setVisibility(View.GONE);
    }
}