/** * @param context * @param spannable * @param title * @return */ public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) { if (spannable == null || spannable.length() <= 0) { Log.e(TAG, "getText spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();"); return new SpannableStringBuilder(); } SpannableStringBuilder builder = new SpannableStringBuilder(spannable); builder.clearSpans();// should clear old spans URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class); if (urls != null) { for (URLSpan urlSpan : urls) { if (urlSpan != null) { MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title); builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable .getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } } } return builder; }
public void unbind() { textViewRef = null; lastUpdateMillis = 0; logBuilder.clearSpans(); logBuilder.clear(); logEventQueue.clear(); }
@Override public void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
private void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
@Override public void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
@Override public void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
private void clearTypedText() { mDefaultKeySsb.clear(); mDefaultKeySsb.clearSpans(); Selection.setSelection(mDefaultKeySsb, 0); }
String htmlLinkText = "Lorem ipsum <a href='http://www.google.com'>dolor</a> sit amet"; testView.setText(Html.fromHtml(htmlLinkText)); testView.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence text = testView.getText(); if (text instanceof Spannable) { int end = text.length(); Spannable sp = (Spannable) testView.getText(); URLSpan[] urls = sp.getSpans(0, end, URLSpan.class); SpannableStringBuilder style = new SpannableStringBuilder(text); style.clearSpans();//should clear old spans for (URLSpan url : urls) { CustomerTextClick click = new CustomerTextClick(url.getURL()); style.setSpan(click, sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } testView.setText(style); }
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_client, null); TextView contentView = view.findViewById(R.id.client_device_dialog); String content = String.format(getString(R.string.about_client), BuildConfig.VERSION_NAME); contentView.setText(Html.fromHtml(content)); contentView.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence text = contentView.getText(); if (text instanceof Spannable) { int end = text.length(); Spannable sp = (Spannable) contentView.getText(); URLSpan[] urls = sp.getSpans(0, end, URLSpan.class); SpannableStringBuilder style = new SpannableStringBuilder(text); style.clearSpans();// should clear old spans for (URLSpan url : urls) { style.setSpan(new UrlSpan(url.getURL()), sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } contentView.setText(style); } AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setView(view) .setTitle(R.string.about) .setPositiveButton(android.R.string.ok, null); return builder.create(); } }
private void txtViewSetText(TextView view, CharSequence text, BufferType type) { CharSequence t = text; if (t instanceof Spannable) { int end = text.length(); Spannable sp = (Spannable) t; URLSpan[] urls = sp.getSpans(0, end, URLSpan.class); SpannableStringBuilder style = new SpannableStringBuilder(text); if (urls.length > 0) { view.setMovementMethod(LinkMovementMethod.getInstance()); for (URLSpan url : urls) { HJURLSpan myURLSpan = new HJURLSpan(view, url.getURL()); style.clearSpans(); style.setSpan(myURLSpan, sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_INCLUSIVE); } } view.setText(style, type); } }
@Override public void clearSearchResult() { if (mApps.setOrderedFilter(null)) { mAppsRecyclerView.onSearchResultsChanged(); } // Clear the search query mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); }
@Override public void clearSearchResult() { mApps.setOrderedFilter(null); mAppsRecyclerView.onSearchResultsChanged(); // Clear the search query mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); } }
@Override public void clearSearchResult() { if (mApps.setOrderedFilter(null)) { mAppsRecyclerView.onSearchResultsChanged(); } // Clear the search query mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); }
@Override public void clearSearchResult() { if (mApps.setOrderedFilter(null)) { mAppsRecyclerView.onSearchResultsChanged(); } // Clear the search query mSearchQueryBuilder.clear(); mSearchQueryBuilder.clearSpans(); Selection.setSelection(mSearchQueryBuilder, 0); }
@Override protected void handleEventQueue() throws InterruptedException { final LogEvent event = logEventQueue.poll(MIN_PRINT_PERIOD, TimeUnit.MILLISECONDS); if (textViewRef != null) { final TextView textView = textViewRef.get(); if (textView != null) { final long currentMillis = System.currentTimeMillis(); if (event != null) { final int start = logBuilder.length(); logBuilder.append(event.toString()); logBuilder.setSpan(new ForegroundColorSpan(event.getLevel() .getColor()), start, logBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); logBuilder.append("\n"); } if ((currentMillis - lastUpdateMillis > MIN_PRINT_PERIOD || lastUpdateMillis == 0) && logBuilder.length() > 0) { postLogToUIThread(new SpannedString(logBuilder)); lastUpdateMillis = currentMillis; logBuilder.clearSpans(); logBuilder.clear(); } } } }