public void setTextViewHtmlLink(TextView tv , String assertHtmlFile){
String htmltxt = null;
try{
if (htmltxt == null) {
InputStream is = this.getAssets().open(assertHtmlFile,AssetManager.ACCESS_BUFFER);
htmltxt = new String(Util.IS2ByteArray(is));
}
tv.setText(Html.fromHtml(htmltxt));
tv.setMovementMethod(LinkMovementMethod.getInstance());
CharSequence text = tv.getText();
if (text instanceof Spannable){
int end = text.length();
Spannable sp = (Spannable)tv.getText();
URLSpan[] urls = sp.getSpans( 0 , end, URLSpan.class );
SpannableStringBuilder style = new SpannableStringBuilder(text);
style.clearSpans(); // should clear old spans
for (URLSpan url : urls){
MyURLSpan myURLSpan = new MyURLSpan(url.getURL());
style.setSpan(myURLSpan,sp.getSpanStart(url),sp.getSpanEnd(url),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.rgb(244, 115, 33)), sp.getSpanStart(url),sp.getSpanEnd(url),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// style.setSpan(new BackgroundColorSpan(Color.rgb(244, 115, 33)), sp.getSpanStart(url),sp.getSpanEnd(url),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tv.setText(style);
}
}catch(Exception e){
tv.setText("");
}
}
private class MyURLSpan extends ClickableSpan {
private String mUrl;
MyURLSpan(String url) {
mUrl = url;
}
@Override
public void onClick(View widget) {
// Toast.makeText(LoginActivity.this, mUrl, Toast.LENGTH_LONG).show();
//send intent
// widget.setBackgroundColor(Color.parseColor("#00000000"));
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/html");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{mUrl});
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Get the Tullett Support");
LoginActivity.this.startActivity(Intent.createChooser(sendIntent, "Email via:"));
}
}