List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE
int SPAN_EXCLUSIVE_EXCLUSIVE
To view the source code for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.
Click Source Link
From source file:Main.java
public static Spannable replaceTags(String str, Context context) { try {//from w w w . j ava2 s.com int start = -1; int startColor = -1; int end = -1; StringBuilder stringBuilder = new StringBuilder(str); while ((start = stringBuilder.indexOf("<br>")) != -1) { stringBuilder.replace(start, start + 4, "\n"); } while ((start = stringBuilder.indexOf("<br/>")) != -1) { stringBuilder.replace(start, start + 5, "\n"); } ArrayList<Integer> bolds = new ArrayList<>(); ArrayList<Integer> colors = new ArrayList<>(); while ((start = stringBuilder.indexOf("<b>")) != -1 || (startColor = stringBuilder.indexOf("<c")) != -1) { if (start != -1) { stringBuilder.replace(start, start + 3, ""); end = stringBuilder.indexOf("</b>"); stringBuilder.replace(end, end + 4, ""); bolds.add(start); bolds.add(end); } else if (startColor != -1) { stringBuilder.replace(startColor, startColor + 2, ""); end = stringBuilder.indexOf(">", startColor); int color = Color.parseColor(stringBuilder.substring(startColor, end)); stringBuilder.replace(startColor, end + 1, ""); end = stringBuilder.indexOf("</c>"); stringBuilder.replace(end, end + 4, ""); colors.add(startColor); colors.add(end); colors.add(color); } } SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder); for (int a = 0; a < colors.size() / 3; a++) { spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spannableStringBuilder; } catch (Exception e) { } return new SpannableStringBuilder(str); }
From source file:org.mariotaku.twidere.util.HtmlSpanBuilder.java
private static void applyTag(SpannableStringBuilder sb, int start, int end, TagInfo info) { if (info.name.equalsIgnoreCase("br")) { sb.append('\n'); } else {//from w w w . j a v a2 s .c om final Object span = createSpan(info); if (span == null) return; sb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }
From source file:com.none.tom.simplerssreader.utils.SearchUtils.java
public static void setSearchResultsSpan(final Activity activity, final SearchResults results, final Spannable s, final int colorHighlightCurrent, final int colorHighlight, final int colorFont, final int position) { final int index = results.columnIndexOf(position); int i = 0;//from ww w.j a v a 2s. c o m for (final Map.Entry<Integer, Integer> entry : results.getRowIndicesAt(index).entrySet()) { final int start = entry.getKey(); final int end = entry.getValue(); final BackgroundColorSpan span; if (results.isCurrent(index, i)) { span = new BackgroundColorSpan(colorHighlightCurrent); } else { span = new BackgroundColorSpan(colorHighlight); } s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (ThemeUtils.isDarkThemeSelected(activity)) { s.setSpan(new ForegroundColorSpan(colorFont), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } i++; } }
From source file:Main.java
public static SpannableStringBuilder replaceTags(String str, int flag) { try {//w w w .j a v a 2s .co m int start; int end; StringBuilder stringBuilder = new StringBuilder(str); if ((flag & FLAG_TAG_BR) != 0) { while ((start = stringBuilder.indexOf("<br>")) != -1) { stringBuilder.replace(start, start + 4, "\n"); } while ((start = stringBuilder.indexOf("<br/>")) != -1) { stringBuilder.replace(start, start + 5, "\n"); } } ArrayList<Integer> bolds = new ArrayList<>(); if ((flag & FLAG_TAG_BOLD) != 0) { while ((start = stringBuilder.indexOf("<b>")) != -1) { stringBuilder.replace(start, start + 3, ""); end = stringBuilder.indexOf("</b>"); if (end == -1) { end = stringBuilder.indexOf("<b>"); } stringBuilder.replace(end, end + 4, ""); bolds.add(start); bolds.add(end); } } ArrayList<Integer> colors = new ArrayList<>(); if ((flag & FLAG_TAG_COLOR) != 0) { while ((start = stringBuilder.indexOf("<c#")) != -1) { stringBuilder.replace(start, start + 2, ""); end = stringBuilder.indexOf(">", start); int color = Color.parseColor(stringBuilder.substring(start, end)); stringBuilder.replace(start, end + 1, ""); end = stringBuilder.indexOf("</c>"); stringBuilder.replace(end, end + 4, ""); colors.add(start); colors.add(end); colors.add(color); } } SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder); // for (int a = 0; a < bolds.size() / 2; a++) { // spannableStringBuilder.setSpan( // new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), // bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // } for (int a = 0; a < colors.size() / 3; a++) { spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spannableStringBuilder; } catch (Exception e) { e.printStackTrace(); } return new SpannableStringBuilder(str); }
From source file:com.justwayward.reader.view.BookContentTextView.java
public void setText(String text) { int startIndex = 0; while (true) { int start = text.indexOf(""); int end = text.indexOf(""); if (start < 0 || end < 0) { append(text.substring(startIndex)); break; }// w ww. j av a2 s . c o m append(text.substring(startIndex, start)); SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1)); spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); append(spanableInfo); //setMovementMethod()??? setMovementMethod(LinkMovementMethod.getInstance()); text = text.substring(end + 1); LogUtils.e(spanableInfo.toString()); } }
From source file:com.freshdigitable.udonroad.CombinedScreenNameTextView.java
public void setNames(User user) { final String name = user.getName(); final String screenName = user.getScreenName(); if (this.name != null && this.name.equals(name) && this.screenName != null && this.screenName.equals(screenName)) { return;//from ww w. ja va 2 s .c o m } final String formatted = name + (TextViewCompat.getMaxLines(this) == 2 ? "\n" : " ") + "@" + screenName; final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(formatted); spannableStringBuilder.setSpan(STYLE_BOLD, 0, name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(spannableStringBuilder); this.name = name; this.screenName = screenName; }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
private Spannable makeAsteriskSpan() { SpannableString sb = new SpannableString("*"); sb.setSpan(new AsteriskSpan(getContext()), sb.length() - 1, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb;// w w w . java 2 s .c o m }
From source file:im.zico.fancy.common.widget.HackyMovementMethod.java
@Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { if (mGray == null) { mGray = new BackgroundColorSpan( ContextCompat.getColor(widget.getContext(), R.color.alpha_spannable_pressed)); }//from w ww . j a va 2 s .c om mIsLinkHit = false; int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); int line = widget.getLayout().getLineForVertical(y); int offset = widget.getLayout().getOffsetForHorizontal(line, x); ClickableSpan[] spans = buffer.getSpans(offset, offset, ClickableSpan.class); if (spans.length != 0) { int start = buffer.getSpanStart(spans[0]); int end = buffer.getSpanEnd(spans[0]); mIsLinkHit = true; if (action == MotionEvent.ACTION_DOWN) { buffer.setSpan(mGray, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (action == MotionEvent.ACTION_UP) { spans[0].onClick(widget); buffer.removeSpan(mGray); } return true; } } else { buffer.removeSpan(mGray); } return Touch.onTouchEvent(widget, buffer, event); }
From source file:com.github.michalbednarski.intentslab.browser.RegisteredReceiverFetcher.java
@Override Object getEntries(Context context) { try {/* w w w. ja v a 2s . c o m*/ final Categorizer<RegisteredReceiverInfo> categorizer = new ProcessCategorizer(); (new RegisteredReceiversParser(mExcludeProtected) { @Override protected void onReceiverFound(RegisteredReceiverInfo receiverInfo) { categorizer.add(receiverInfo); } }).parse(context); return categorizer.getResult(); } catch (SecurityException e) { // Create message about error SpannableStringBuilder ssb = new SpannableStringBuilder( context.getString(R.string.registered_receivers_denied)); ssb.append("\n"); int commandStart = ssb.length(); if (ComponentFetcher.DEVELOPMENT_PERMISSIONS_SUPPORTED) { ssb.append("pm grant ").append(context.getPackageName()).append(" android.permission.DUMP"); } else { ssb.append(RemoteEntryPoint.getScriptFile(context).getAbsolutePath()); } int commandEnd = ssb.length(); ssb.setSpan(new StyleSpan(Typeface.BOLD), commandStart, commandEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return new CustomError(ssb); } catch (Throwable e) { e.printStackTrace(); return new CustomError(Utils.describeException(e)); } }
From source file:com.none.tom.simplerssreader.view.ReadMoreTextView.java
@SuppressWarnings("SameParameterValue") public void setText(final CharSequence text, final int maxEms) { if (!TextUtils.isEmpty(text) && text.length() > maxEms) { final SpannableStringBuilder ssb = new SpannableStringBuilder(text.subSequence(0, maxEms)); ssb.append('\u2026'); final int textLength = ssb.length(); ssb.append('\n'); ssb.append(getContext().getString(R.string.read_more)); final int readMoreLength = ssb.length() - textLength; ssb.setSpan(new ReadMoreClickableSpan(), textLength, textLength + readMoreLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); super.setText(ssb); setMaxEms(maxEms + readMoreLength); setMovementMethod(LinkMovementMethod.getInstance()); mText = text;/*from www . j a va2 s . c o m*/ } else { super.setText(text); } }