List of usage examples for android.text SpannableStringBuilder getSpanStart
public int getSpanStart(Object what)
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endBlockquote(SpannableStringBuilder text, ThemeColors colors) { int len = text.length(); Object obj = getLast(text, Blockquote.class); int where = text.getSpanStart(obj); text.removeSpan(obj);//from w w w. j ava2s.co m if (where != len) { Blockquote b = (Blockquote) obj; if (b.mIsUnkfunc) { if (colors != null) { text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { text.setSpan(new QuoteSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endAibspoiler(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) { int len = text.length(); Object obj = getLast(text, Aibspoiler.class); int where = text.getSpanStart(obj); text.removeSpan(obj);//from w ww. j av a 2 s . com if (where != len && colors != null) { if (openSpoilers) { text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endSpan(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) { int len = text.length(); Object obj = getLast(text, Span.class); int where = text.getSpanStart(obj); text.removeSpan(obj);//from ww w . jav a2s . c o m if (where != len) { Span s = (Span) obj; if (s.mStyle != null) { List<Object> styleSpans = parseStyleAttributes(s.mStyle); for (Object span : styleSpans) { text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (colors != null && s.mIsAibquote) { text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (colors != null && s.mIsAibspoiler) { if (openSpoilers) { text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (s.mIsUnderline) { text.setSpan(new UnderlineSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (s.mIsStrike) { text.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
/** * ? ? SpoilerSpan ForegroundColorSpan ?? ? ?? ? *//*from w w w.ja v a 2 s. c om*/ private static void fixSpoilerSpans(SpannableStringBuilder builder, ThemeColors themeColors) { SpoilerSpan[] spoilers = builder.getSpans(0, builder.length(), SpoilerSpan.class); for (SpoilerSpan span : spoilers) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); builder.removeSpan(span); builder.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } ClickableURLSpan[] urls = builder.getSpans(0, builder.length(), ClickableURLSpan.class); for (ClickableURLSpan span : urls) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); builder.setSpan(new ForegroundColorSpan(themeColors.urlLinkForeground), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:com.android.tv.dvr.ui.DvrUiHelper.java
@NonNull public static CharSequence getStyledTitleWithEpisodeNumber(Context context, String title, String seasonNumber, String episodeNumber, int episodeNumberStyleResId) { if (TextUtils.isEmpty(title)) { return ""; }// w w w.j a v a 2 s. c o m SpannableStringBuilder builder; if (TextUtils.isEmpty(seasonNumber) || seasonNumber.equals("0")) { builder = TextUtils.isEmpty(episodeNumber) ? new SpannableStringBuilder(title) : new SpannableStringBuilder(Html.fromHtml(context.getString( R.string.program_title_with_episode_number_no_season, title, episodeNumber))); } else { builder = new SpannableStringBuilder(Html.fromHtml(context .getString(R.string.program_title_with_episode_number, title, seasonNumber, episodeNumber))); } Object[] spans = builder.getSpans(0, builder.length(), Object.class); if (spans.length > 0) { if (episodeNumberStyleResId != 0) { builder.setSpan(new TextAppearanceSpan(context, episodeNumberStyleResId), builder.getSpanStart(spans[0]), builder.getSpanEnd(spans[0]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } builder.removeSpan(spans[0]); } return new SpannableString(builder); }
From source file:org.pencilsofpromise.rss.RSSFragment.java
private Spanned removeContentSpanObjects(String sb) { SpannableStringBuilder spannedStr = (SpannableStringBuilder) Html.fromHtml(sb.toString().trim()); Object[] spannedObjects = spannedStr.getSpans(0, spannedStr.length(), Object.class); for (int i = 0; i < spannedObjects.length; i++) { if (spannedObjects[i] instanceof ImageSpan) spannedStr.replace(spannedStr.getSpanStart(spannedObjects[i]), spannedStr.getSpanEnd(spannedObjects[i]), ""); }/*from www. java2 s.c o m*/ return spannedStr; }
From source file:com.jecelyin.editor.v2.core.text.TextUtils.java
/** * Return a new CharSequence in which each of the source strings is * replaced by the corresponding element of the destinations. *///from www . ja va 2 s. co m public static CharSequence replace(CharSequence template, String[] sources, CharSequence[] destinations) { SpannableStringBuilder tb = new SpannableStringBuilder(template); for (int i = 0; i < sources.length; i++) { int where = indexOf(tb, sources[i]); if (where >= 0) tb.setSpan(sources[i], where, where + sources[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } for (int i = 0; i < sources.length; i++) { int start = tb.getSpanStart(sources[i]); int end = tb.getSpanEnd(sources[i]); if (start >= 0) { tb.replace(start, end, destinations[i]); } } return tb; }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { int start = strBuilder.getSpanStart(span); int end = strBuilder.getSpanEnd(span); int flags = strBuilder.getSpanFlags(span); ClickableSpan clickable = new ClickableSpan() { public void onClick(View view) { if (!mLoadingPlugin) { mLoadingPlugin = true;//www.jav a 2s . c o m String url = span.getURL(); if (url.startsWith("http://play.google.com/store/apps/details?id=")) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.replace("http://play.google.com/store/apps", "market:/")))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } mLoadingPlugin = false; } else if (url.startsWith("plugin://") || url.startsWith("plugins://")) { final File path = IOUtils.getDownloadDirectory(getApplicationContext()); if (!path.isDirectory()) { path.mkdirs(); } if (url.startsWith("plugin://")) { url = url.replace("plugin://", "http://"); } else if (url.startsWith("plugins://")) { url = url.replace("plugins://", "https://"); } String name = url.substring(url.lastIndexOf("/") + 1); mCurrentDownloadPlugin = new File(path, name); if (mCurrentDownloadPlugin.isFile()) { mCurrentDownloadPlugin.delete(); } final String downloadUrl = url; handler.post(new Runnable() { @Override public void run() { AsyncTask<String, Void, Boolean> async = new AsyncTask<String, Void, Boolean>() { private ProgressDialog mProgress; private File mPluginFile; protected void onPreExecute() { mProgress = new ProgressDialog(TvBrowser.this); mProgress.setMessage(getString(R.string.plugin_info_donwload).replace("{0}", mCurrentDownloadPlugin.getName())); mProgress.show(); }; @Override protected Boolean doInBackground(String... params) { mPluginFile = new File(params[0]); return IOUtils.saveUrl(params[0], params[1], 15000); } protected void onPostExecute(Boolean result) { mProgress.dismiss(); if (result) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(mPluginFile), "application/vnd.android.package-archive"); TvBrowser.this.startActivityForResult(intent, INSTALL_PLUGIN); } mLoadingPlugin = false; }; }; async.execute(mCurrentDownloadPlugin.toString(), downloadUrl); } }); } else { mLoadingPlugin = false; } } } }; strBuilder.setSpan(clickable, start, end, flags); strBuilder.removeSpan(span); }