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 Spannable text, @NonNull Pattern pattern,
        @Nullable String scheme) 

Source Link

Document

Applies a regex to a Spannable turning the matches into links.

Usage

From source file:net.i2p.android.router.dialog.AboutDialog.java

@Override
public Dialog onCreateDialog(Bundle SavedInstanceState) {
    LayoutInflater li = LayoutInflater.from(getActivity());
    View view = li.inflate(R.layout.fragment_dialog_about, null);

    final String currentVersion = Util.getOurVersion(getActivity());
    TextView tv = (TextView) view.findViewById(R.id.about_version);
    tv.setText(currentVersion);/*  w  w  w. j  a va2s .  c om*/

    tv = (TextView) view.findViewById(R.id.url_project);
    Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://");
    tv = (TextView) view.findViewById(R.id.url_android_bugs);
    Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://");
    tv = (TextView) view.findViewById(R.id.url_android_volunteer);
    Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://");
    tv = (TextView) view.findViewById(R.id.url_donate);
    Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://");

    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    b.setTitle(R.string.menu_about).setView(view).setNeutralButton(R.string.label_licenses,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent lic = new Intent(getActivity(), LicenseActivity.class);
                    startActivity(lic);
                }
            });
    return b.create();
}

From source file:ch.fixme.status.Main.java

private void populateDataHs() {
    try {//w w w  . j  a va  2s .  c om
        HashMap<String, Object> data = new ParseGeneric(mResultHs).getData();

        // Initialize views
        LayoutInflater inflater = getLayoutInflater();
        LinearLayout vg = (LinearLayout) inflater.inflate(R.layout.base, null);
        ScrollView scroll = (ScrollView) findViewById(R.id.scroll);
        scroll.removeAllViews();
        scroll.addView(vg);

        // Mandatory fields
        ((TextView) findViewById(R.id.space_name)).setText((String) data.get(ParseGeneric.API_NAME));
        ((TextView) findViewById(R.id.space_url)).setText((String) data.get(ParseGeneric.API_URL));
        getImageTask = new GetImage(R.id.space_image);
        getImageTask.execute((String) data.get(ParseGeneric.API_LOGO));

        // Status text
        String status_txt = "";
        if ((Boolean) data.get(ParseGeneric.API_STATUS)) {
            status_txt = OPEN;
            ((TextView) findViewById(R.id.status_txt))
                    .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_online, 0, 0, 0);
        } else {
            status_txt = CLOSED;
            ((TextView) findViewById(R.id.status_txt))
                    .setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.presence_busy, 0, 0, 0);
        }
        if (data.containsKey(ParseGeneric.API_STATUS_TXT)) {
            status_txt += ": " + (String) data.get(ParseGeneric.API_STATUS_TXT);
        }
        ((TextView) findViewById(R.id.status_txt)).setText(status_txt);

        // Status last change
        if (data.containsKey(ParseGeneric.API_LASTCHANGE)) {
            TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
            tv.setAutoLinkMask(0);
            tv.setText(
                    getString(R.string.api_lastchange) + " " + (String) data.get(ParseGeneric.API_LASTCHANGE));
            vg.addView(tv);
        }

        // Status duration
        if (data.containsKey(ParseGeneric.API_EXT_DURATION) && (Boolean) data.get(ParseGeneric.API_STATUS)) {
            TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
            tv.setText(getString(R.string.api_duration) + " " + (String) data.get(ParseGeneric.API_EXT_DURATION)
                    + getString(R.string.api_duration_hours));
            vg.addView(tv);
        }

        // Location
        Pattern ptn = Pattern.compile("^.*$", Pattern.DOTALL);
        if (data.containsKey(ParseGeneric.API_ADDRESS) || data.containsKey(ParseGeneric.API_LON)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_location));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);
            // Address
            if (data.containsKey(ParseGeneric.API_ADDRESS)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_ADDRESS));
                Linkify.addLinks(tv, ptn, MAP_SEARCH);
                vg.addView(tv);
            }
            // Lon/Lat
            if (data.containsKey(ParseGeneric.API_LON) && data.containsKey(ParseGeneric.API_LAT)) {
                String addr = (data.containsKey(ParseGeneric.API_ADDRESS))
                        ? (String) data.get(ParseGeneric.API_ADDRESS)
                        : getString(R.string.empty);
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_LON) + ", "
                        + (String) data.get(ParseGeneric.API_LAT));
                Linkify.addLinks(tv, ptn, String.format(MAP_COORD, (String) data.get(ParseGeneric.API_LAT),
                        (String) data.get(ParseGeneric.API_LON), addr));
                vg.addView(tv);
            }
        }

        // Contact
        if (data.containsKey(ParseGeneric.API_PHONE) || data.containsKey(ParseGeneric.API_TWITTER)
                || data.containsKey(ParseGeneric.API_IRC) || data.containsKey(ParseGeneric.API_EMAIL)
                || data.containsKey(ParseGeneric.API_ML)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(R.string.api_contact);
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);

            // Phone
            if (data.containsKey(ParseGeneric.API_PHONE)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_PHONE));
                vg.addView(tv);
            }
            // SIP
            if (data.containsKey(ParseGeneric.API_SIP)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_SIP));
                vg.addView(tv);
            }
            // Twitter
            if (data.containsKey(ParseGeneric.API_TWITTER)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText(TWITTER + (String) data.get(ParseGeneric.API_TWITTER));
                vg.addView(tv);
            }
            // Identica
            if (data.containsKey(ParseGeneric.API_IDENTICA)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_IDENTICA));
                vg.addView(tv);
            }
            // Foursquare
            if (data.containsKey(ParseGeneric.API_FOURSQUARE)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText(FOURSQUARE + (String) data.get(ParseGeneric.API_FOURSQUARE));
                vg.addView(tv);
            }
            // IRC
            if (data.containsKey(ParseGeneric.API_IRC)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setAutoLinkMask(0);
                tv.setText((String) data.get(ParseGeneric.API_IRC));
                vg.addView(tv);
            }
            // Email
            if (data.containsKey(ParseGeneric.API_EMAIL)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_EMAIL));
                vg.addView(tv);
            }
            // Jabber
            if (data.containsKey(ParseGeneric.API_JABBER)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_JABBER));
                vg.addView(tv);
            }
            // Mailing-List
            if (data.containsKey(ParseGeneric.API_ML)) {
                TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                tv.setText((String) data.get(ParseGeneric.API_ML));
                vg.addView(tv);
            }
        }

        // Sensors
        if (data.containsKey(ParseGeneric.API_SENSORS)) {
            // Title
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_sensors));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);

            HashMap<String, ArrayList<HashMap<String, String>>> sensors = (HashMap<String, ArrayList<HashMap<String, String>>>) data
                    .get(ParseGeneric.API_SENSORS);
            Set<String> names = sensors.keySet();
            Iterator<String> it = names.iterator();
            while (it.hasNext()) {
                String name = it.next();
                // Subtitle
                String name_title = name.toLowerCase().replace("_", " ");
                name_title = name_title.substring(0, 1).toUpperCase()
                        + name_title.substring(1, name_title.length());
                TextView subtitle = (TextView) inflater.inflate(R.layout.subtitle, null);
                subtitle.setText(name_title);
                vg.addView(subtitle);
                // Sensors data
                ArrayList<HashMap<String, String>> sensorsData = sensors.get(name);
                for (HashMap<String, String> elem : sensorsData) {
                    RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.entry_sensor, null);
                    if (elem.containsKey(ParseGeneric.API_VALUE)) {
                        ((TextView) rl.findViewById(R.id.entry_value))
                                .setText(elem.get(ParseGeneric.API_VALUE));
                    } else {
                        rl.findViewById(R.id.entry_value).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_UNIT)) {
                        ((TextView) rl.findViewById(R.id.entry_unit)).setText(elem.get(ParseGeneric.API_UNIT));
                    } else {
                        rl.findViewById(R.id.entry_unit).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_NAME2)) {
                        ((TextView) rl.findViewById(R.id.entry_name)).setText(elem.get(ParseGeneric.API_NAME2));
                    } else {
                        rl.findViewById(R.id.entry_name).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_LOCATION2)) {
                        ((TextView) rl.findViewById(R.id.entry_location))
                                .setText(elem.get(ParseGeneric.API_LOCATION2));
                    } else {
                        rl.findViewById(R.id.entry_location).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_DESCRIPTION)) {
                        ((TextView) rl.findViewById(R.id.entry_description))
                                .setText(elem.get(ParseGeneric.API_DESCRIPTION));
                    } else {
                        rl.findViewById(R.id.entry_description).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_PROPERTIES)) {
                        ((TextView) rl.findViewById(R.id.entry_properties))
                                .setText(elem.get(ParseGeneric.API_PROPERTIES));
                    } else {
                        rl.findViewById(R.id.entry_properties).setVisibility(View.GONE);
                    }
                    if (elem.containsKey(ParseGeneric.API_MACHINES)) {
                        ((TextView) rl.findViewById(R.id.entry_other))
                                .setText(elem.get(ParseGeneric.API_MACHINES));
                    } else if (elem.containsKey(ParseGeneric.API_NAMES)) {
                        ((TextView) rl.findViewById(R.id.entry_other))
                                .setText(elem.get(ParseGeneric.API_NAMES));
                    } else {
                        rl.findViewById(R.id.entry_other).setVisibility(View.GONE);
                    }
                    vg.addView(rl);
                }
            }
        }

        // Stream and cam
        if (data.containsKey(ParseGeneric.API_STREAM) || data.containsKey(ParseGeneric.API_CAM)) {
            TextView title = (TextView) inflater.inflate(R.layout.title, null);
            title.setText(getString(R.string.api_stream));
            vg.addView(title);
            inflater.inflate(R.layout.separator, vg);
            // Stream
            if (data.containsKey(ParseGeneric.API_STREAM)) {
                HashMap<String, String> stream = (HashMap<String, String>) data.get(ParseGeneric.API_STREAM);
                for (Entry<String, String> entry : stream.entrySet()) {
                    final String type = entry.getKey();
                    final String url = entry.getValue();
                    TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                    tv.setText(url);
                    tv.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setDataAndType(Uri.parse(url), type);
                            startActivity(i);
                        }
                    });
                    vg.addView(tv);
                }
            }
            // Cam
            if (data.containsKey(ParseGeneric.API_CAM)) {
                HashMap<String, String> cam = (HashMap<String, String>) data.get(ParseGeneric.API_CAM);
                for (String value : cam.values()) {
                    TextView tv = (TextView) inflater.inflate(R.layout.entry, null);
                    tv.setText(value);
                    vg.addView(tv);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        showError(e.getClass().getCanonicalName(), e.getLocalizedMessage() + getString(R.string.error_generic));
    }
}