List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:Main.java
public static SpannableString setTextBold(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*from w w w. j a va 2s . c om*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextItalic(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }// w w w .ja va 2 s.co m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextSuper(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*w ww. jav a 2 s. c o m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new SuperscriptSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextBoldItalic(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }// www .j a v a2 s.c o m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextURL(String content, int startIndex, int endIndex, String url) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }//from w w w . j a v a 2 s .c o m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new URLSpan(url), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextUnderline(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }//ww w . jav a 2 s .com SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new UnderlineSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString linkifyGid(String gid) { if (gid == null) { return null; }//w w w .j ava 2 s . com SpannableString ret = new SpannableString(gid); String name = gid.substring(0, gid.lastIndexOf("@")); String authority = gid.substring(gid.lastIndexOf("@") + 1); String mainAuth = authority.contains("/") ? authority.substring(0, authority.indexOf("/")) : authority; if (auths.containsKey(mainAuth)) { String link; try { if (auths.get(mainAuth).length == 1) { link = auths.get(mainAuth)[0]; } else if (auths.get(mainAuth).length == 2) { link = auths.get(mainAuth)[0] + URLEncoder.encode(name, "UTF-8") + auths.get(mainAuth)[1]; } else { return ret; } } catch (UnsupportedEncodingException e) { return ret; } ret = new SpannableString(Html.fromHtml("<a href=\"" + link + "\">" + gid + "</a>")); } else if (mainAuth.matches(".*\\..*")) { // if it contains a dot // we try a link to the supposed webpage of this auth ret = new SpannableString(Html.fromHtml("<a href=\"http://" + mainAuth + "\">" + gid + "</a>")); } return ret; }
From source file:Main.java
public static SpannableString setTextStrikethrough(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }//from w w w. ja v a2s .c om SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StrikethroughSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString replaceImageSpan(CharSequence charSequence, String regPattern, Drawable drawable) {/*from w w w . j av a 2 s. c om*/ SpannableString ss = charSequence instanceof SpannableString ? (SpannableString) charSequence : new SpannableString(charSequence); try { ImageSpan is = new ImageSpan(drawable); Pattern pattern = Pattern.compile(regPattern); Matcher matcher = pattern.matcher(ss); while (matcher.find()) { String key = matcher.group(); ss.setSpan(is, matcher.start(), matcher.start() + key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } catch (Exception ex) { } return ss; }
From source file:Main.java
public static SpannableString setTextSize(String content, int startIndex, int endIndex, int fontSize) { if (TextUtils.isEmpty(content) || fontSize <= 0 || startIndex >= endIndex || startIndex < 0 || endIndex >= content.length()) { return null; }/* w w w .ja v a 2 s. com*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new AbsoluteSizeSpan(fontSize), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }