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:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java
private boolean checkEditTextField(List<String> strings, TextInputLayout layout, TextInputEditText field) { if (strings == null || layout == null) { return false; }//from w w w . j a v a 2s . c om if (strings.isEmpty()) { layout.setErrorEnabled(true); layout.setError(getString(R.string.error_empty_link)); layout.requestFocus(); return false; } boolean valid = true; int curLineStartIndex = 0; for (String s : strings) { if (!Utils.isValidTrackerUrl(s)) { /* Select invalid url */ field.getText().setSpan( new ForegroundColorSpan( ContextCompat.getColor(activity.getApplicationContext(), R.color.error)), curLineStartIndex, curLineStartIndex + s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); valid = false; } /* Considering newline char */ curLineStartIndex += s.length() + 1; } if (valid) { layout.setErrorEnabled(false); layout.setError(null); } else { layout.setErrorEnabled(true); layout.setError(getString(R.string.error_invalid_link)); layout.requestFocus(); } return valid; }
From source file:org.de.jmg.learn._MainActivity.java
public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt) throws Exception { if (iv != null) { iv.setVisibility(View.GONE); }//from w ww . ja v a 2s. c om if (iv2 != null) iv2.setVisibility(View.GONE); try { if (_btnRight == null) return; EndEdit(DontPrompt); setBtnsEnabled(true); if (showBeds && _vok.getIndex() >= 1) { _btnRight.setEnabled(true); _btnWrong.setEnabled(true); _btnEdit.setEnabled(true); _btnSkip.setEnabled(true); _btnView.setEnabled(true); } else { _btnRight.setEnabled(false); _btnWrong.setEnabled(false); if (_vok.getIndex() < 1) { _btnEdit.setEnabled(false); _btnSkip.setEnabled(false); _btnView.setEnabled(false); } } if (LoadNext) _vok.setLernIndex((short) (_vok.getLernIndex() + 1)); View v; TextView t; String txtBed = getString(R.string.cloze); if (showBeds) { v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; t.setText(lib.getSpanableString(_vok.getBedeutung1())); txtBed = t.getText().toString(); } v = findViewById(R.id.word); t = (TextView) v; assert t != null; String txtWord = getString(R.string.cloze); if (!_vok.reverse || showBeds) { t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE); txtWord = t.getText().toString(); txtWord = replaceClozes(txtWord, txtBed); speak(txtWord, _vok.getLangWord(), "word", true); } else { t.setText(""); } if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedWord.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedWord.setTypeface(Typeface.DEFAULT); } t.scrollTo(0, 0); v = findViewById(R.id.Comment); t = (TextView) v; assert t != null; t.setVisibility(View.VISIBLE); SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar()); URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class); for (final URLSpan span : urlSpans) { int start = tspanKom.getSpanStart(span); int end = tspanKom.getSpanEnd(span); String txt = tspanKom.toString().substring(start, end); if (txtIsPicture(txt)) { tspanKom.removeSpan(span); tspanKom.setSpan(new urlclickablespan(span.getURL()) { @Override public void onClick(View widget) { Bitmap b; try { b = lib.downloadpicture(this.url); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = _txtMeaning1.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("addImageView", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } _txtMeaning1.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } t.setText(tspanKom, TextView.BufferType.SPANNABLE); if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedKom.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedKom.setTypeface(Typeface.DEFAULT); } if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) { t.setVisibility(View.GONE); } else { t.setVisibility(View.VISIBLE); } t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) { t.setImeOptions(EditorInfo.IME_ACTION_NEXT); } if (_vok.reverse || showBeds) { SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1()); //final String picname = _main.getString(R.string.picture); t.setVisibility(View.VISIBLE); if (txtIsPicture(tspan.toString())) { URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class); for (URLSpan url : urlspn) { Bitmap b; try { b = lib.downloadpicture(url.getURL()); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = t.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("Imagview", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } t.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } } else { // iv.setVisibility(View.GONE); t.setVisibility(View.VISIBLE); } t.setText(tspan); } else { t.setText(Vokabel.getComment(_vok.getBedeutung1())); } if (_vok.reverse || showBeds) { String txt = t.getText().toString(); txt = replaceClozes(txt, txtWord); speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse); } if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } t.setOnFocusChangeListener(FocusListenerMeaning1); t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning2); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning2"); } } v = findViewById(R.id.txtMeaning3); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning3"); } } if (_vok.reverse && showBeds) speak(txtWord, _vok.getLangWord(), "word"); lib.setBgEditText(_txtMeaning1, _MeaningBG); lib.setBgEditText(_txtMeaning2, _MeaningBG); lib.setBgEditText(_txtMeaning3, _MeaningBG); if (!_isSmallDevice && !requestFocusEdWord) { _txtMeaning1.requestFocus(); } else { if (!requestFocusEdWord) _txtWord.requestFocus(); else _txtedWord.requestFocus(); } SetActionBarTitle(); _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this); hideKeyboard(); if (showBeds) { _scrollView.scrollTo(0, _txtMeaning1.getTop()); } else { _txtWord.requestFocus(); _scrollView.fullScroll(View.FOCUS_UP); } } }); } catch (Exception e) { lib.ShowException(_main, e); } }
From source file:org.miaowo.miaowo.util.Html.java
private static void setSpanFromMark(Spannable text, Object mark, Object... spans) { int where = text.getSpanStart(mark); text.removeSpan(mark);// w w w.j ava 2 s . c o m int len = text.length(); if (where != len) { for (Object span : spans) { text.setSpan(span, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:eu.faircode.netguard.ActivitySettings.java
private void markPro(Preference pref, String sku) { if (sku == null || !IAB.isPurchased(sku, this)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean dark = prefs.getBoolean("dark_theme", false); SpannableStringBuilder ssb = new SpannableStringBuilder(" " + pref.getTitle()); ssb.setSpan(//from w w w . j ava 2s .co m new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); pref.setTitle(ssb); } }
From source file:com.lloydtorres.stately.helpers.SparkleHelper.java
/** * Overloaded to deal with spoilers./* w w w . ja va 2 s .c o m*/ */ public static void setStyledTextView(Context c, TextView t, String holder, List<Spoiler> spoilers, FragmentManager fm) { if (t instanceof HtmlTextView) { try { ((HtmlTextView) t).setHtml(holder); } catch (Exception e) { logError(e.toString()); t.setText(c.getString(R.string.bbcode_parse_error)); t.setTypeface(t.getTypeface(), Typeface.ITALIC); } } else { t.setText(fromHtml(holder)); } // Deal with spoilers here styleLinkifiedTextView(c, t); // Ensures TextView contains a spannable Spannable span = new SpannableString(t.getText()); String rawSpan = span.toString(); int startFromIndex = 0; for (int i = 0; i < spoilers.size(); i++) { Spoiler s = spoilers.get(i); int start = rawSpan.indexOf(s.replacer, startFromIndex); if (start != -1) { int end = start + s.replacer.length(); startFromIndex = end; SpoilerSpan clickyDialog = new SpoilerSpan(c, s, fm); span.setSpan(clickyDialog, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } t.setText(span); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static SpannableStringBuilder replaceTags(String str, int flag) { try {// w w w . j a v a2s . c o 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) { FileLog.e("tmessages", e); } return new SpannableStringBuilder(str); }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Create a chip that represents just the email address of a recipient. At some later point, this chip will be * attached to a real contact entry, if one exists. *//*from www. j a v a 2 s .com*/ // VisibleForTesting void createReplacementChip(final int tokenStart, final int tokenEnd, final Editable editable, final boolean visible) { if (alreadyHasChip(tokenStart, tokenEnd)) // There is already a chip present at this location. // Don't recreate it. return; String token = editable.toString().substring(tokenStart, tokenEnd); final String trimmedToken = token.trim(); final int commitCharIndex = trimmedToken.lastIndexOf(COMMIT_CHAR_COMMA); if (commitCharIndex != -1 && commitCharIndex == trimmedToken.length() - 1) token = trimmedToken.substring(0, trimmedToken.length() - 1); final RecipientEntry entry = createTokenizedEntry(token); if (entry != null) { DrawableRecipientChip chip = null; try { if (!mNoChips) { /* * leave space for the contact icon if this is not just an email address */ final boolean leaveSpace = TextUtils.isEmpty(entry.getDisplayName()) || TextUtils.equals(entry.getDisplayName(), entry.getDestination()); chip = visible ? constructChipSpan(entry, false, leaveSpace) : new InvisibleRecipientChip(entry); } } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); } editable.setSpan(chip, tokenStart, tokenEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Add this chip to the list of entries "to replace" if (chip != null) { if (mTemporaryRecipients == null) mTemporaryRecipients = new ArrayList<DrawableRecipientChip>(); chip.setOriginalText(token); mTemporaryRecipients.add(chip); } } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
public static SpannableStringBuilder replaceTags(String str, int flag) { try {/*from ww w .j a v a 2s .c o 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); } } 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); } return spannableStringBuilder; } catch (Exception e) { FileLog.e(e); } return new SpannableStringBuilder(str); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
private void markPro(Preference pref, String sku) { if (sku == null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean dark = prefs.getBoolean("dark_theme", false); SpannableStringBuilder ssb = new SpannableStringBuilder(" " + pref.getTitle()); ssb.setSpan(// w ww . j av a 2 s .c o m new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); pref.setTitle(ssb); } }
From source file:org.telegram.ui.ArticleViewer.java
private CharSequence getText(TLRPC.RichText parentRichText, TLRPC.RichText richText, TLRPC.PageBlock parentBlock) {// w w w . j a v a 2 s .c o m if (richText instanceof TLRPC.TL_textFixed) { return getText(parentRichText, ((TLRPC.TL_textFixed) richText).text, parentBlock); } else if (richText instanceof TLRPC.TL_textItalic) { return getText(parentRichText, ((TLRPC.TL_textItalic) richText).text, parentBlock); } else if (richText instanceof TLRPC.TL_textBold) { return getText(parentRichText, ((TLRPC.TL_textBold) richText).text, parentBlock); } else if (richText instanceof TLRPC.TL_textUnderline) { return getText(parentRichText, ((TLRPC.TL_textUnderline) richText).text, parentBlock); } else if (richText instanceof TLRPC.TL_textStrike) { return getText(parentRichText, ((TLRPC.TL_textStrike) richText).text, parentBlock); } else if (richText instanceof TLRPC.TL_textEmail) { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder( getText(parentRichText, ((TLRPC.TL_textEmail) richText).text, parentBlock)); MetricAffectingSpan innerSpans[] = spannableStringBuilder.getSpans(0, spannableStringBuilder.length(), MetricAffectingSpan.class); spannableStringBuilder.setSpan( new TextPaintUrlSpan(innerSpans == null || innerSpans.length == 0 ? getTextPaint(parentRichText, richText, parentBlock) : null, getUrl(richText)), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableStringBuilder; } else if (richText instanceof TLRPC.TL_textUrl) { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder( getText(parentRichText, ((TLRPC.TL_textUrl) richText).text, parentBlock)); MetricAffectingSpan innerSpans[] = spannableStringBuilder.getSpans(0, spannableStringBuilder.length(), MetricAffectingSpan.class); spannableStringBuilder.setSpan( new TextPaintUrlSpan(innerSpans == null || innerSpans.length == 0 ? getTextPaint(parentRichText, richText, parentBlock) : null, getUrl(richText)), 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableStringBuilder; } else if (richText instanceof TLRPC.TL_textPlain) { return ((TLRPC.TL_textPlain) richText).text; } else if (richText instanceof TLRPC.TL_textEmpty) { return ""; } else if (richText instanceof TLRPC.TL_textConcat) { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); int count = richText.texts.size(); for (int a = 0; a < count; a++) { TLRPC.RichText innerRichText = richText.texts.get(a); CharSequence innerText = getText(parentRichText, innerRichText, parentBlock); int flags = getTextFlags(innerRichText); int startLength = spannableStringBuilder.length(); spannableStringBuilder.append(innerText); if (flags != 0 && !(innerText instanceof SpannableStringBuilder)) { if ((flags & TEXT_FLAG_URL) != 0) { String url = getUrl(innerRichText); if (url == null) { url = getUrl(parentRichText); } spannableStringBuilder.setSpan( new TextPaintUrlSpan(getTextPaint(parentRichText, innerRichText, parentBlock), url), startLength, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { spannableStringBuilder.setSpan( new TextPaintSpan(getTextPaint(parentRichText, innerRichText, parentBlock)), startLength, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return spannableStringBuilder; } return "not supported " + richText; }