Example usage for android.text.util Linkify WEB_URLS

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

Introduction

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

Prototype

int WEB_URLS

To view the source code for android.text.util Linkify WEB_URLS.

Click Source Link

Document

Bit field indicating that web URLs should be matched in methods that take an options mask

Usage

From source file:com.abcvoipsip.ui.prefs.CodecsFragment.java

@Override
@SuppressWarnings("unchecked")
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from ww w  .  j ava 2 s .c  o m
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return false;
    }

    HashMap<String, Object> codec = null;
    codec = (HashMap<String, Object>) mAdapter.getItem(info.position);

    if (codec == null) {
        // If for some reason the requested item isn't available, do nothing
        return false;
    }
    int selId = item.getItemId();
    if (selId == MENU_ITEM_ACTIVATE) {
        boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
        final short newPrio = isDisabled ? (short) 1 : (short) 0;
        if (NON_FREE_CODECS.containsKey(codec.get(CODEC_ID)) && isDisabled) {
            final HashMap<String, Object> fCodec = codec;

            final TextView message = new TextView(getActivity());
            final SpannableString s = new SpannableString(
                    getString(R.string.this_codec_is_not_free) + NON_FREE_CODECS.get(codec.get(CODEC_ID)));
            Linkify.addLinks(s, Linkify.WEB_URLS);
            message.setText(s);
            message.setMovementMethod(LinkMovementMethod.getInstance());
            message.setPadding(10, 10, 10, 10);

            //Alert user that we will disable for all incoming calls as he want to quit
            new AlertDialog.Builder(getActivity()).setTitle(R.string.warning).setView(message)
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            setCodecActivated(fCodec, newPrio);
                        }
                    }).setNegativeButton(R.string.cancel, null).show();
        } else {
            setCodecActivated(codec, newPrio);
        }
        return true;
    }
    return false;
}

From source file:de.baumann.thema.FragmentWallpaper.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.color) {
        ColorPickerDialogBuilder.with(getActivity()).initialColor(0xff2196f3).setTitle(R.string.custom)
                .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER).density(9)
                .setPositiveButton(R.string.yes, new ColorPickerClickListener() {
                    @Override// ww w . ja  v  a  2  s . c  o  m
                    public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
                        try {
                            WallpaperManager wm = WallpaperManager.getInstance(getActivity());
                            // Create 1x1 bitmap to store the color
                            Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
                            // Make a canvas with which we can draw to the bitmap
                            Canvas canvas = new Canvas(bmp);
                            // Fill with color and save
                            canvas.drawColor(selectedColor);
                            canvas.save();

                            wm.setBitmap(bmp);
                            bmp.recycle();
                            Snackbar.make(imgHeader, R.string.applying, Snackbar.LENGTH_LONG).show();
                        } catch (IOException e) {
                            // oh lord!
                        }
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).build().show();
        return false;
    }

    if (id == R.id.help) {

        SpannableString s;

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            s = new SpannableString(
                    Html.fromHtml(getString(R.string.help_wallpaper), Html.FROM_HTML_MODE_LEGACY));
        } else {
            //noinspection deprecation
            s = new SpannableString(Html.fromHtml(getString(R.string.help_wallpaper)));
        }
        Linkify.addLinks(s, Linkify.WEB_URLS);

        final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.title_wallpaper).setMessage(s)
                .setPositiveButton(getString(R.string.yes), null);
        dialog.show();

        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java

private TextView handleBuildSuccessTextView(final String logUrl) {
    TextView showText = new TextView(getActivity());

    showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    showText.setPadding(15, 30, 15, 30);
    showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl));
    showText.setAutoLinkMask(Activity.RESULT_OK);
    showText.setMovementMethod(LinkMovementMethod.getInstance());
    showText.setOnLongClickListener(new View.OnLongClickListener() {

        @Override//from  w  w w  .  j  a va  2  s  . c om
        public boolean onLongClick(View v) {
            @SuppressWarnings("deprecation")
            ClipboardManager manager = (ClipboardManager) getActivity()
                    .getSystemService(Activity.CLIPBOARD_SERVICE);
            manager.setText(logUrl);
            Toast.makeText(getActivity(), R.string.log_submit_activity__copied_to_clipboard, Toast.LENGTH_SHORT)
                    .show();
            return true;
        }
    });

    Linkify.addLinks(showText, Linkify.WEB_URLS);
    return showText;
}

From source file:de.baumann.hhsmoodle.popup.Popup_note.java

private void setNotesList() {

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "note_title", "note_content", "note_creation" };
    final String search = sharedPref.getString("filter_note_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "note_title");

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_note.this, layoutstyle, row, column, xml_id,
            0) {//  w ww . j a  v  a 2 s .  c  om
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (note_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_note.this,
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(Popup_note.this)
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });
            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = Popup_note.this.getLayoutInflater();

            final ViewGroup nullParent = null;
            final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.app_att) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(note_content);
            Linkify.addLinks(textInput, Linkify.WEB_URLS);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);

            switch (note_icon) {
            case "3":
                be.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                be.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                be.setImageResource(R.drawable.circle_red);
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(Popup_note.this)
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.todo_menu), getString(R.string.bookmark_createEvent),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(Popup_note.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", note_title)
                                        .putString("handleTextText", note_content)
                                        .putString("handleTextIcon", note_icon)
                                        .putString("handleTextSeqno", _id)
                                        .putString("handleTextAttachment", note_attachment)
                                        .putString("handleTextCreate", note_creation).apply();
                                helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {

                                Todo_DbAdapter db = new Todo_DbAdapter(Popup_note.this);
                                db.open();
                                if (db.isExist(note_title)) {
                                    Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                            .show();
                                } else {
                                    db.insert(note_title, note_content, "3", "true", helper_main.createDate());
                                    ViewPager viewPager = (ViewPager) Popup_note.this
                                            .findViewById(R.id.viewpager);
                                    viewPager.setCurrentItem(2);
                                    Popup_note.this.setTitle(R.string.todo_title);
                                    dialog.dismiss();
                                }
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, note_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, note_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:de.baumann.thema.Screen_Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.license) {

        SpannableString s;//from  ww w  .  jav  a  2  s .  c o m

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            s = new SpannableString(Html.fromHtml(getString(R.string.about_text), Html.FROM_HTML_MODE_LEGACY));
        } else {
            //noinspection deprecation
            s = new SpannableString(Html.fromHtml(getString(R.string.about_text)));
        }
        Linkify.addLinks(s, Linkify.WEB_URLS);

        final AlertDialog d = new AlertDialog.Builder(Screen_Main.this).setTitle(R.string.about_title)
                .setMessage(s)
                .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).show();
        d.show();
        ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    }

    if (id == R.id.changelog) {
        Uri uri = Uri.parse("https://github.com/scoute-dich/Blue-Minimal/blob/master/CHANGELOG.md"); // missing 'http://' will cause crashed
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    if (id == R.id.donate) {
        Uri uri = Uri
                .parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NP6TGYDYP9SHY"); // missing 'http://' will cause crashed
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.facebook.android.GraphExplorer.java

public void setText(final String txt) {
    mHandler.post(new Runnable() {

        /*/*from w ww. j a va 2  s  . c  o  m*/
         * A transform filter that simply returns just the text captured by
         * the first regular expression group.
         */
        TransformFilter idFilter = new TransformFilter() {
            @Override
            public final String transformUrl(final Matcher match, String url) {
                return match.group(1);
            }
        };

        @Override
        public void run() {
            mViewURLButton.setVisibility(TextUtils.isEmpty(txt) ? View.INVISIBLE : View.VISIBLE);
            mFieldsConnectionsButton.setVisibility(TextUtils.isEmpty(txt) ? View.INVISIBLE : View.VISIBLE);
            mOutput.setVisibility(TextUtils.isEmpty(txt) ? View.INVISIBLE : View.VISIBLE);
            mBackParentButton.setVisibility(TextUtils.isEmpty(mParentObjectId) ? View.INVISIBLE : View.VISIBLE);

            String convertedTxt = txt.replace("\\/", "/");
            mOutput.setText(convertedTxt);
            mScrollView.scrollTo(0, 0);

            Linkify.addLinks(mOutput, Linkify.WEB_URLS);
            /*
             * Linkify the object ids so they can be clicked. match pattern:
             * "id" : "objectid" (objectid can be int or int_int)
             */
            Pattern pattern = Pattern.compile("\"id\": \"(\\d*_?\\d*)\"");
            String scheme = "fbGraphEx://";
            Linkify.addLinks(mOutput, pattern, scheme, null, idFilter);
        }
    });
}

From source file:de.baumann.thema.FragmentSound.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.help:
        SpannableString s;//from ww w  .java  2 s  . c  o m

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            s = new SpannableString(Html.fromHtml(getString(R.string.help_sound), Html.FROM_HTML_MODE_LEGACY));
        } else {
            //noinspection deprecation
            s = new SpannableString(Html.fromHtml(getString(R.string.help_sound)));
        }
        Linkify.addLinks(s, Linkify.WEB_URLS);

        final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.sound)
                .setMessage(s).setPositiveButton(getString(R.string.yes), null);
        dialog.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/**
 * Creates the Application Info dialog with clickable links.
 * // w w  w  .  j a  va2 s  . co m
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private void showVersionInfoDialog() throws UnsupportedEncodingException, IOException {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.app_name) + " " + getString(R.string.version_name));

    AssetManager assetManager = getResources().getAssets();
    String versionInfoFile = getString(R.string.versioninfo_asset);
    InputStreamReader reader = new InputStreamReader(assetManager.open(versionInfoFile), "UTF-8");
    BufferedReader br = new BufferedReader(reader);
    StringBuffer sbuf = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        sbuf.append(line);
        sbuf.append("\r\n");
    }

    final ScrollView scroll = new ScrollView(this);
    final TextView message = new TextView(this);
    final SpannableString sWlinks = new SpannableString(sbuf.toString());
    Linkify.addLinks(sWlinks, Linkify.WEB_URLS);
    message.setText(sWlinks);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(15, 15, 15, 15);
    scroll.addView(message);
    alertDialog.setView(scroll);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // nothing to do, just dismiss dialog
        }
    });
    alertDialog.show();
}

From source file:com.keepassdroid.EntryActivity.java

private void showSamsungDialog() {
    String text = getString(R.string.clipboard_error).concat(System.getProperty("line.separator"))
            .concat(getString(R.string.clipboard_error_url));
    SpannableString s = new SpannableString(text);
    TextView tv = new TextView(this);
    tv.setText(s);//from www.java 2 s . co  m
    tv.setAutoLinkMask(RESULT_OK);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(s, Linkify.WEB_URLS);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.clipboard_error_title)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setView(tv).show();

}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

private void showAnnouncementDialogIfNeeded(Intent intent) {
    final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE);
    final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);

    if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message);
        final String yes = intent.getStringExtra(EXTRA_DIALOG_YES);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes);
        final String no = intent.getStringExtra(EXTRA_DIALOG_NO);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no);
        final String url = intent.getStringExtra(EXTRA_DIALOG_URL);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url);
        final SpannableString spannable = new SpannableString(message == null ? "" : message);
        Linkify.addLinks(spannable, Linkify.WEB_URLS);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);//from w  ww . jav a2  s . c  o  m
        }
        builder.setMessage(spannable);
        if (!TextUtils.isEmpty(no)) {
            builder.setNegativeButton(no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
        }
        if (!TextUtils.isEmpty(yes)) {
            builder.setPositiveButton(yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.show();
        final TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        if (messageView != null) {
            // makes the embedded links in the text clickable, if there are any
            messageView.setMovementMethod(LinkMovementMethod.getInstance());
        }
        mShowedAnnouncementDialog = true;
    }
}