Example usage for android.text.util Linkify EMAIL_ADDRESSES

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

Introduction

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

Prototype

int EMAIL_ADDRESSES

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

Click Source Link

Document

Bit field indicating that email addresses should be matched in methods that take an options mask

Usage

From source file:com.tct.email.provider.EmailMessageCursor.java

public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn,
        final String textColumn) {
    super(cursor);
    mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn);
    mTextColumnIndex = cursor.getColumnIndex(textColumn);
    final int cursorSize = cursor.getCount();
    mHtmlParts = new SparseArray<String>(cursorSize);
    mTextParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
    mHtmlLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_HTML_LINKIFY);
    mHtmlLinkifyParts = new SparseArray<String>(cursorSize);
    mTextLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_TEXT_LINKIFY);
    mTextLinkifyParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E

    final ContentResolver cr = c.getContentResolver();

    while (cursor.moveToNext()) {
        final int position = cursor.getPosition();
        final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_S
        InputStream htmlIn = null;
        InputStream textIn = null;
        try {//  ww  w .  j  a  v  a2s .  c o  m
            if (mHtmlColumnIndex != -1) {
                final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId);
                //WARNING: Actually openInput will used 2 PIPE(FD) to connect,but if some exception happen during connect,
                //such as fileNotFoundException,maybe the connection will not be closed. just a try!!!
                htmlIn = cr.openInputStream(htmlUri);
                final String underlyingHtmlString;
                try {
                    underlyingHtmlString = IOUtils.toString(htmlIn);
                } finally {
                    htmlIn.close();
                    htmlIn = null;
                }
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_S
                final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString);
                mHtmlParts.put(position, sanitizedHtml);
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_E
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for sanitized html
                if (!TextUtils.isEmpty(sanitizedHtml)) {
                    final String linkifyHtml = com.tct.mail.utils.Linkify.addLinks(sanitizedHtml);
                    mHtmlLinkifyParts.put(position, linkifyHtml);
                } else {
                    mHtmlLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyHtml,current message %d",
                    messageId);
            mHtmlLinkifyParts.put(position, "");
        }
        try {
            if (mTextColumnIndex != -1) {
                final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId);
                textIn = cr.openInputStream(textUri);
                final String underlyingTextString;
                try {
                    underlyingTextString = IOUtils.toString(textIn);
                } finally {
                    textIn.close();
                    textIn = null;
                }
                mTextParts.put(position, underlyingTextString);
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for underlying text string
                if (!TextUtils.isEmpty(underlyingTextString)) {
                    final SpannableString spannable = new SpannableString(underlyingTextString);
                    Linkify.addLinks(spannable,
                            Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
                    final String linkifyText = Html.toHtml(spannable);
                    mTextLinkifyParts.put(position, linkifyText);
                } else {
                    mTextLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyText,current message %d",
                    messageId);
            mTextLinkifyParts.put(position, "");
        }
        //NOTE:Remember that this just a protective code,for better release Not used Resources.
        if (htmlIn != null) {
            try {
                htmlIn.close();
            } catch (IOException e1) {
                LogUtils.v(LogUtils.TAG, e1, "IOException happen while close the htmlInput connection ");
            }
        }
        if (textIn != null) {
            try {
                textIn.close();
            } catch (IOException e2) {
                LogUtils.v(LogUtils.TAG, e2, "IOException happen while close the textInput connection ");
            }
        } // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_E
    }
    cursor.moveToPosition(-1);
}

From source file:org.eyeseetea.malariacare.LoginActivity.java

/**
 * Shows an alert dialog asking for acceptance of the EULA terms. If ok calls login function,
 * do/* w  ww  .java  2s .c o  m*/
 * nothing otherwise
 */
public void askEula(int titleId, int rawId, final Context context) {
    InputStream message = context.getResources().openRawResource(rawId);
    String stringMessage = Utils.convertFromInputStreamToString(message).toString();
    final SpannableString linkedMessage = new SpannableString(Html.fromHtml(stringMessage));
    Linkify.addLinks(linkedMessage, Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);

    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(context.getString(titleId))
            .setMessage(linkedMessage)
            .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    rememberEulaAccepted(context);
                    login(serverText.getText().toString(), usernameEditText.getText().toString(),
                            passwordEditText.getText().toString());
                }
            }).setNegativeButton(android.R.string.no, null).create();

    dialog.show();

    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:io.github.protino.codewatch.ui.ProfileActivity.java

private void bindViews() {
    Glide.with(this).load(profileItem.getPhotoUrl()).asBitmap()
            .placeholder(R.drawable.ic_account_circle_white_24dp).into(new BitmapImageViewTarget(avatar) {
                @Override/*from w w  w  .j a va  2  s  .  co m*/
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(),
                            resource);
                    drawable.setCircular(true);
                    avatar.setImageDrawable(drawable);
                }
            });

    userName.setText(profileItem.getName());
    collapsingToolbarLayout.setTitle(profileItem.getName());

    rank.setText(String.valueOf(profileItem.getRank()));

    website.setText(profileItem.getWebsite());
    Linkify.addLinks(website, Linkify.WEB_URLS);
    removeViewIfNoData(website);

    email.setText(profileItem.getEmail());
    Linkify.addLinks(email, Linkify.EMAIL_ADDRESSES);
    removeViewIfNoData(email);

    location.setText(profileItem.getLocation());
    removeViewIfNoData(location);

    dailyAverage.setText(getString(R.string.daily_average_format,
            FormatUtils.getFormattedTime(this, profileItem.getDailyAverage())));

    JSONObject languageMap;
    try {
        languageMap = new JSONObject(profileItem.getLanguageStats());
        Iterator<?> keys = languageMap.keys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            languageList.add(new Pair<>(key, languageMap.getInt(key)));
        }
    } catch (JSONException e) {
        Timber.e(e);
    }
    languageAdapter.swapData(languageList);
}

From source file:de.kaidev.vertretungsplanapp.MainActivity.java

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
    mDrawerLayout.closeDrawer(mDrawer);/*from   w  w  w  .  j  a  v  a 2s. c o  m*/
    switch (menuItem.getItemId()) {
    case R.id.navigation_drawer_settings:
        final Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        break;
    case R.id.navigation_drawer_class:
        String[] items = getResources().getStringArray(R.array.klassen_liste);
        BuilderDialogFragment.newInstance(new DialogBuilder().setTitle("Klasse whlen").setItems(items))
                .show(getSupportFragmentManager(), FRAGMENT_KLASSE);
        break;
    case R.id.navigation_drawer_info:
        BuilderDialogFragment
                .newInstance(new DialogBuilder().setTitle("Info")
                        .setMessage(heute.getDate() + "\n" + heute.getInfo() + "\n\n" + morgen.getDate() + "\n"
                                + morgen.getInfo())
                        .setPositiveButton("OK"))
                .show(getSupportFragmentManager(), FRAGMENT_DEFAULT);
        break;
    case R.id.navigation_drawer_about:
        BuilderDialogFragment
                .newInstance(new DialogBuilder().setTitle("ber die App")
                        .setMessage("Vielen Dank, dass du die VertretungsplanApp fr das Krupp "
                                + "Gymnasium verwendest!\n\n"
                                + "Falls du Anregungen oder Kritik hast, kannst du gerne eine E-Mail an "
                                + "kai.volkenborn@krupp-gymnasium.eu schicken\n" + "\n"
                                + "Copyright: Kai Volkenborn 2015\n" + "Version: " + MyApplication.versionName
                                + "\n" + "\n" + "Diese App verwendet folgende Software von Drittanbietern:\n"
                                + "ACRA, Retrolambda, Android Retrolambda Lombok, Google Gson, "
                                + "Apache Commons IO, TabLayoutHelper, RecyclerView-FlexibleDivider, "
                                + "Material Dialogs, Lightweight Stream API, LicensesDialog\n"
                                + "Fr mehr Informationen klicke auf \nDrittanbieter Software\"")
                        .setLinkify(Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS).setPositiveButton("OK")
                        .setNeutralButton("Drittanbieter Software"))
                .show(getSupportFragmentManager(), FRAGMENT_BER);
        break;
    case R.id.navigation_drawer_links:
        BuilderDialogFragment.newInstance(new DialogBuilder().setTitle(R.string.main_dialog_about_title)
                .setMessage("Whle \"ffnen\", um den Vertretungsplan " + "im Browser zu ffnen.")
                .setPositiveButton("ffnen")).show(getSupportFragmentManager(), FRAGMENT_LINK);
        break;
    }
    return false;
}

From source file:com.gmail.taneza.ronald.carbs.main.MainActivity.java

private void showAboutDialog() {
    StringBuilder sb = new StringBuilder();
    sb.append(String.format(Locale.getDefault(), "%s%n", getText(R.string.app_name)));
    sb.append(String.format(Locale.getDefault(), "%s: %s%n%n", getText(R.string.about_version_label),
            getVersion()));/* w w w .  j a  v a2s . c  o  m*/
    sb.append(String.format(Locale.getDefault(), "%s", getText(R.string.about_info)));

    SpannableString aboutString = new SpannableString(sb.toString());
    Linkify.addLinks(aboutString, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    TextView aboutBodyView = (TextView) layoutInflater.inflate(R.layout.dialog_about, null);
    aboutBodyView.setText(aboutString);
    aboutBodyView.setMovementMethod(new LinkMovementMethod());

    new AlertDialog.Builder(this).setTitle(R.string.about).setView(aboutBodyView)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // do nothing
                }
            }).show();
}

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  .j a v a 2 s  .c  o m
    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);

}