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:org.kontalk.ui.view.TextContentView.java

@Override
public void bind(long databaseId, TextComponent component, Pattern highlight) {
    mComponent = component;//from   ww w  .j  a  v a2 s  . c  om

    SpannableStringBuilder formattedMessage = formatMessage(highlight);
    setTextStyle(this);

    // linkify!
    if (formattedMessage.length() < MAX_AFFORDABLE_SIZE)
        Linkify.addLinks(formattedMessage, Linkify.ALL);

    /*
     * workaround for bugs:
     * http://code.google.com/p/android/issues/detail?id=17343
     * http://code.google.com/p/android/issues/detail?id=22493
     * applies from Honeycomb to JB 4.2.2 afaik
     */
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB
            && android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1)
        // from http://stackoverflow.com/a/12303155/1045199
        formattedMessage.append("\u200b"); // was: \u2060

    setText(formattedMessage);
}

From source file:truesculpt.ui.panels.WebFilePanel.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getManagers().getUtilsManager().updateFullscreenWindowStatus(getWindow());

    setContentView(R.layout.webfile);//from w w w .java2  s.  co  m

    getManagers().getUsageStatisticsManager().TrackEvent("OpenFromWeb", "", 1);

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setWebViewClient(new MyWebViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new JavaScriptInterface(this, getManagers()), "Android");

    int nVersionCode = getManagers().getUpdateManager().getCurrentVersionCode();
    mWebView.loadUrl(mStrBaseWebSite + "?version=" + nVersionCode);

    mPublishToWebBtn = (Button) findViewById(R.id.publish_to_web);
    mPublishToWebBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String name = getManagers().getMeshManager().getName();
            final File imagefile = new File(getManagers().getFileManager().GetImageFileName());
            final File objectfile = new File(getManagers().getFileManager().GetObjectFileName());

            getManagers().getUsageStatisticsManager().TrackEvent("PublishToWeb", name, 1);

            if (imagefile.exists() && objectfile.exists()) {
                try {
                    final File zippedObject = File.createTempFile("object", "zip");
                    zippedObject.deleteOnExit();

                    BufferedReader in = new BufferedReader(new FileReader(objectfile));
                    BufferedOutputStream out = new BufferedOutputStream(
                            new GZIPOutputStream(new FileOutputStream(zippedObject)));
                    System.out.println("Compressing file");
                    int c;
                    while ((c = in.read()) != -1) {
                        out.write(c);
                    }
                    in.close();
                    out.close();

                    long size = 0;

                    size = new FileInputStream(imagefile).getChannel().size();
                    size += new FileInputStream(zippedObject).getChannel().size();
                    size /= 1000;

                    final SpannableString msg = new SpannableString(
                            "You will upload your latest saved version of this scupture representing " + size
                                    + " ko of data\n\n"
                                    + "When clicking the yes button you accept to publish your sculpture under the terms of the creative commons share alike, non commercial license\n"
                                    + "http://creativecommons.org/licenses/by-nc-sa/3.0"
                                    + "\n\nDo you want to proceed ?");
                    Linkify.addLinks(msg, Linkify.ALL);

                    AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this);
                    builder.setMessage(msg).setCancelable(false)
                            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int id) {
                                    PublishPicture(imagefile, zippedObject, name);
                                }
                            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                    AlertDialog dlg = builder.create();
                    dlg.show();

                    // Make the textview clickable. Must be called after
                    // show()
                    ((TextView) dlg.findViewById(android.R.id.message))
                            .setMovementMethod(LinkMovementMethod.getInstance());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this);
                builder.setMessage(
                        "File has not been saved, you need to save it before publishing\nDo you want to proceed to save window ?")
                        .setCancelable(false)
                        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                ((FileSelectorPanel) getParent()).getTabHost().setCurrentTab(2);
                            }
                        }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                            }
                        });
                builder.show();
            }
        }
    });
}

From source file:com.github.dfa.diaspora_android.activity.PodSelectionActivity.java

private void showPodConfirmationDialog(final String selectedPod) {
    // Make a clickable link
    final SpannableString dialogMessage = new SpannableString(getString(R.string.confirm_pod, selectedPod));
    Linkify.addLinks(dialogMessage, Linkify.ALL);

    // Check if online
    if (!Helpers.isOnline(PodSelectionActivity.this)) {
        Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show();
        return;//  www .  j a v  a2  s.com
    }

    // Show dialog
    new AlertDialog.Builder(PodSelectionActivity.this).setTitle(getString(R.string.confirmation))
            .setMessage(dialogMessage)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    onPodSelectionConfirmed(selectedPod);
                }
            }).setNegativeButton(android.R.string.no, null).show();
}

From source file:com.ugedal.weeklyschedule.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from  w w  w .jav a  2  s  .  co m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.

    int id = item.getItemId();
    int group_id = item.getGroupId();
    if (group_id == R.id.trinn_chooser) {
        // Save new state, and update the fragment
        SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt(getString(R.string.current_grade_key), id);
        editor.apply();

        TextView text = (TextView) findViewById(R.id.textView);
        text.setText(item.getTitle());

        getSupportActionBar().setTitle(item.getTitle());
        mListFragment.myList.clear();
        mListFragment.adapter.notifyDataSetChanged();
        swipeContainer.setRefreshing(true);

        mListFragment.refreshContent();

    }
    if (id == R.id.nav_about) {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle(getString(R.string.about));
        final SpannableString s = new SpannableString(getText(R.string.about_message));
        Linkify.addLinks(s, Linkify.WEB_URLS);
        alertDialog.setMessage(s);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        alertDialog.show();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.holder.MessageComposerHolder.java

public void bindView(final MessageCenterFragment fragment, final MessageCenterRecyclerViewAdapter adapter,
        final Composer composer) {
    title.setText(composer.title);/* ww w.j a va 2s .com*/

    closeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (!TextUtils.isEmpty(message.getText().toString().trim()) || !images.isEmpty()) {
                Bundle bundle = new Bundle();
                bundle.putString("message", composer.closeBody);
                bundle.putString("positive", composer.closeDiscard);
                bundle.putString("negative", composer.closeCancel);
                ApptentiveAlertDialog.show(fragment, bundle,
                        Constants.REQUEST_CODE_CLOSE_COMPOSING_CONFIRMATION);
            } else {
                if (adapter.getListener() != null) {
                    adapter.getListener().onCancelComposing();
                }
            }
        }
    });

    sendButton.setContentDescription(composer.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (adapter.getListener() != null) {
                adapter.getListener().onFinishComposing();
            }
        }
    });

    message.setHint(composer.messageHint);

    message.removeTextChangedListener(textWatcher);
    textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (adapter.getListener() != null) {
                adapter.getListener().beforeComposingTextChanged(charSequence);
            }
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            if (adapter.getListener() != null) {
                adapter.getListener().onComposingTextChanged(charSequence);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (adapter.getListener() != null) {
                adapter.getListener().afterComposingTextChanged(editable.toString());
            }
            Linkify.addLinks(editable,
                    Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.MAP_ADDRESSES);
        }
    };
    message.addTextChangedListener(textWatcher);

    attachButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (adapter.getListener() != null) {
                adapter.getListener().onAttachImage();
            }
        }
    });

    attachments.setupUi();
    attachments.setupLayoutListener();
    attachments.setListener(new ApptentiveImageGridView.ImageItemClickedListener() {
        @Override
        public void onClick(int position, ImageItem image) {
            if (adapter.getListener() != null) {
                adapter.getListener().onClickAttachment(position, image);
            }
        }
    });
    attachments.setAdapterIndicator(R.drawable.apptentive_ic_remove_attachment);

    attachments.setImageIndicatorCallback(fragment);
    //Initialize image attachments band with empty data
    clearImageAttachmentBand();
    attachments.setVisibility(View.GONE);
    attachments.setData(new ArrayList<ImageItem>());
    setAttachButtonState();

    if (adapter.getListener() != null) {
        adapter.getListener().onComposingViewCreated(this, message, attachments);
    }
}

From source file:org.sirimangalo.meditationplus.AdapterChat.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View rowView;/*from w  w  w . j  a v a 2  s .c  om*/

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.list_item_chat, parent, false);
    } else {
        rowView = convertView;
    }

    JSONObject p = values.get(position);
    try {
        int then = Integer.parseInt(p.getString("time"));
        long nowL = System.currentTimeMillis() / 1000;
        int now = (int) nowL;

        int ela = now - then;
        int day = 60 * 60 * 24;
        ela = ela > day ? day : ela;
        int intColor = 255 - Math.round((float) ela * 255 / day);
        intColor = intColor > 100 ? intColor : 100;
        String hexTransparency = Integer.toHexString(intColor);
        hexTransparency = hexTransparency.length() > 1 ? hexTransparency : "0" + hexTransparency;
        String hexColor = "#" + hexTransparency + "000000";
        int transparency = Color.parseColor(hexColor);

        TextView time = (TextView) rowView.findViewById(R.id.time);
        if (time != null) {
            String ts = null;
            ts = Utils.time2Ago(then);
            time.setText(ts);
            time.setTextColor(transparency);
        }

        TextView mess = (TextView) rowView.findViewById(R.id.message);
        if (mess != null) {

            final String username = p.getString("username");

            String messageString = p.getString("message");

            messageString = Html.fromHtml(messageString).toString();

            SpannableString messageSpan = Utils.replaceSmilies(context, messageString, intColor);

            if (messageString.contains("@" + loggedUser)) {
                int index = messageString.indexOf("@" + loggedUser);
                messageSpan.setSpan(new StyleSpan(Typeface.BOLD), index, index + loggedUser.length() + 1,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                messageSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "990000")),
                        index, index + loggedUser.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            for (String user : users) {
                if (!user.equals(loggedUser) && messageString.contains("@" + user)) {
                    int index = messageString.indexOf("@" + user);
                    messageSpan = Utils.createProfileSpan(context, index, index + user.length() + 1, user,
                            messageSpan);
                    messageSpan.setSpan(
                            new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "009900")), index,
                            index + user.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }

            Spannable userSpan = Utils.createProfileSpan(context, 0, username.length(), username,
                    new SpannableString(username + ": "));

            if (p.getString("me").equals("true"))
                userSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "0000FF")), 0,
                        userSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            else
                userSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#" + hexTransparency + "000000")), 0,
                        userSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            CharSequence full = TextUtils.concat(userSpan, messageSpan);

            mess.setTextColor(transparency);
            mess.setText(full);
            mess.setMovementMethod(LinkMovementMethod.getInstance());
            Linkify.addLinks(mess, Linkify.ALL);
            mess.setTag(p.getString("cid"));
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return rowView;

}

From source file:org.sufficientlysecure.localcalendar.ui.MainActivity.java

private void showAbout() {
    SpannableString s = new SpannableString(getText(R.string.about));
    Linkify.addLinks(s, Linkify.ALL);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(s);/*w w  w. j a  va 2 s  . c om*/
    AlertDialog alert = builder.create();
    alert.show();
    ((TextView) alert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.androzic.About.java

private void updateAboutInfo(final View view) {
    // version/*from w  ww .  j a v a  2s  . co m*/
    String versionName = null;
    int versionBuild = 0;
    try {
        versionName = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                0).versionName;
        versionBuild = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                0).versionCode;
    } catch (NameNotFoundException ex) {
        versionName = "unable to retreive version";
    }
    final TextView version = (TextView) view.findViewById(R.id.version);
    version.setText(getString(R.string.version, versionName, versionBuild));

    // home links
    StringBuilder links = new StringBuilder();
    links.append("<a href=\"");
    links.append(": http://androzic.com");
    links.append("\">");
    links.append(getString(R.string.homepage));
    links.append("</a><br /><a href=\"");
    links.append(getString(R.string.faquri));
    links.append("\">");
    links.append(getString(R.string.faq));
    links.append("</a><br /><a href=\"");
    links.append(getString(R.string.featureuri));
    links.append("\">");
    links.append(getString(R.string.feedback));
    links.append("</a>");
    final TextView homelinks = (TextView) view.findViewById(R.id.homelinks);
    homelinks.setText(Html.fromHtml(links.toString()));
    homelinks.setMovementMethod(LinkMovementMethod.getInstance());

    // community links
    StringBuilder communities = new StringBuilder();
    communities.append("<a href=\"");
    communities.append(getString(R.string.googleplusuri));
    communities.append("\">");
    communities.append(getString(R.string.googleplus));
    communities.append("</a><br /><a href=\"");
    communities.append(getString(R.string.facebookuri));
    communities.append("\">");
    communities.append(getString(R.string.facebook));
    communities.append("</a><br /><a href=\"");
    communities.append(getString(R.string.twitteruri));
    communities.append("\">");
    communities.append(getString(R.string.twitter));
    communities.append("</a>");
    final TextView communitylinks = (TextView) view.findViewById(R.id.communitylinks);
    communitylinks.setText(Html.fromHtml(communities.toString()));
    communitylinks.setMovementMethod(LinkMovementMethod.getInstance());

    // donations
    StringBuilder donations = new StringBuilder();
    donations.append("<a href=\"");
    donations.append(getString(R.string.playuri));
    donations.append("\">");
    donations.append(getString(R.string.donate_google));
    donations.append("</a><br /><a href=\"");
    donations.append(getString(R.string.paypaluri));
    donations.append("\">");
    donations.append(getString(R.string.donate_paypal));
    donations.append("</a>");

    final TextView donationlinks = (TextView) view.findViewById(R.id.donationlinks);
    donationlinks.setText(Html.fromHtml(donations.toString()));
    donationlinks.setMovementMethod(LinkMovementMethod.getInstance());

    Androzic application = Androzic.getApplication();
    if (application.isPaid) {
        view.findViewById(R.id.donations).setVisibility(View.GONE);
        view.findViewById(R.id.donationtext).setVisibility(View.GONE);
        donationlinks.setVisibility(View.GONE);
    }

    // license
    final SpannableString message = new SpannableString(
            Html.fromHtml(getString(R.string.app_eula).replace("/n", "<br/>")));
    Linkify.addLinks(message, Linkify.WEB_URLS);
    final TextView license = (TextView) view.findViewById(R.id.license);
    license.setText(message);
    license.setMovementMethod(LinkMovementMethod.getInstance());

    // credits
    String[] names = getResources().getStringArray(R.array.credit_names);
    String[] merits = getResources().getStringArray(R.array.credit_merits);

    StringBuilder credits = new StringBuilder();
    for (int i = 0; i < names.length; i++) {
        credits.append("<b>");
        credits.append(merits[i]);
        credits.append("</b> &mdash; ");
        credits.append(names[i]);
        credits.append("<br />");
    }

    final TextView creditlist = (TextView) view.findViewById(R.id.credits);
    creditlist.setText(Html.fromHtml(credits.toString()));

    // dedication
    final TextView dedicated = (TextView) view.findViewById(R.id.dedicated);
    dedicated.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            clicks = 1;
            dedicated.setVisibility(View.GONE);
            View photo = view.findViewById(R.id.photo);
            photo.setVisibility(View.VISIBLE);
            photo.setOnClickListener(redirect);
        }
    });
}

From source file:org.freespanish.diccionario.main.MainActivity.java

@Override
public void showAboutDialog() {

    final SpannableString spannableString = new SpannableString(getString(R.string.about_msg));
    Linkify.addLinks(spannableString, Linkify.ALL);

    final AlertDialog aboutDialog = new AlertDialog.Builder(this).setPositiveButton(android.R.string.ok, null)
            .setTitle(getString(R.string.app_name) + " " + getString(R.string.app_version))
            .setMessage(spannableString).create();

    aboutDialog.show();//from w  ww.  jav a  2s.co m

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

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 {/*from w  w  w.  j ava  2 s.  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);
}