List of usage examples for android.text Spannable length
int length();
From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java
private static Spannable getSpannableString(Context context, int strId, int typeface) { Spannable startersTitle = new SpannableString(context.getString(strId)); startersTitle.setSpan(new StyleSpan(typeface), 0, startersTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return startersTitle; }
From source file:cn.dreamtobe.emoji.ellipsize.helper.SpanEllipsizeEndHelper.java
private static void removeClickableSpan(Spannable content) { ClickableSpan[] clickSpans = content.getSpans(0, content.length(), ClickableSpan.class); for (int i = 0; i < clickSpans.length; i++) { content.removeSpan(clickSpans[i]); }//from ww w . ja va2 s. c o m }
From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java
public static NotificationCompat.Builder buildNotificationExtenderPages(Context context) { ArrayList<Notification> pages = new ArrayList<>(); // Create first page notification Bitmap tableImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto); Notification page1 = new NotificationCompat.Builder(context).extend( new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true).setBackground(tableImg)) .build();// w w w.j av a 2 s . co m pages.add(page1); // Create second page notification Spannable meatTitle = new SpannableString(context.getString(R.string.menu_meats)); meatTitle.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, meatTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); NotificationCompat.InboxStyle secondPageStyle = new NotificationCompat.InboxStyle(); secondPageStyle.setBigContentTitle("Page 2").setSummaryText("") .addLine(getSpannableString(context, R.string.menu_starters, Typeface.BOLD)) .addLine(context.getString(R.string.menu_starters_content1)) .addLine(context.getString(R.string.menu_starters_content2)) .addLine(getSpannableString(context, R.string.menu_meats, Typeface.BOLD)) .addLine(context.getString(R.string.menu_meats_content1)) .addLine(context.getString(R.string.menu_meats_content2)); Notification page2 = new NotificationCompat.Builder(context) .extend(new NotificationCompat.WearableExtender().setBackground( BitmapFactory.decodeResource(context.getResources(), R.drawable.table_restaurant))) .setStyle(secondPageStyle).build(); pages.add(page2); // Create builder for the main notification Bitmap restoImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto); return (NotificationCompat.Builder) buildNotificationSimpleNBackground(context) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(restoImg)) .extend(new NotificationCompat.WearableExtender().addPages(pages)); }
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter({ "eventBus", "post" }) public static void setCount(TextView textView, EventBus eventBus, Post post) { String text = "#" + post.getCount(); // there is no need to quote #1 if ("1".equals(post.getCount())) { textView.setText(text);// w w w. ja va 2s .co m } else { Spannable spannable = new SpannableString(text); URLSpan urlSpan = new URLSpan(StringUtils.EMPTY) { @Override public void onClick(@NonNull View widget) { eventBus.post(new QuoteEvent(post.getId(), post.getCount())); } }; spannable.setSpan(urlSpan, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(spannable); } }
From source file:dev.drsoran.moloko.util.UIUtils.java
public final static void makeLink(TextView textView, Spannable text, ClickableSpan onClickHandler) { if (onClickHandler != null) { text.setSpan(onClickHandler, 0, text.length(), 0); }/*www .j a va 2s. c om*/ textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setText(text, BufferType.SPANNABLE); }
From source file:com.silentcircle.common.util.ViewUtil.java
public static Intent createIntentForLinks(TextView view) { CharSequence text = view.getText(); if (text instanceof Spannable) { Spannable stext = (Spannable) text; URLSpan[] spans = stext.getSpans(0, stext.length(), URLSpan.class); if (spans != null && spans.length > 0) { ChooserBuilder chooser = new ChooserBuilder(view.getContext()); chooser.label(R.string.view); for (URLSpan span : spans) { String url = span.getURL(); CharSequence label = stext.subSequence(stext.getSpanStart(span), stext.getSpanEnd(span)); chooser.intent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), label); }/*from w w w. j a v a2s . c o m*/ return chooser.build(); } } return null; }
From source file:org.catnut.util.CatnutUtils.java
/** * textview//from ww w .j a v a2 s . c o m * * @param textView */ public static void removeLinkUnderline(TextView textView) { Spannable s = Spannable.Factory.getInstance().newSpannable(textView.getText()); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span : spans) { int start = s.getSpanStart(span); int end = s.getSpanEnd(span); s.removeSpan(span); span = new TweetURLSpan(span.getURL()); s.setSpan(span, start, end, 0); } textView.setText(s); }
From source file:org.onebusaway.android.util.UIUtils.java
public static void setClickableSpan(TextView v, ClickableSpan span) { Spannable text = (Spannable) v.getText(); text.setSpan(span, 0, text.length(), 0); v.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.onebusaway.android.util.UIUtils.java
public static void removeAllClickableSpans(TextView v) { Spannable text = (Spannable) v.getText(); ClickableSpan[] spans = text.getSpans(0, text.length(), ClickableSpan.class); for (ClickableSpan cs : spans) { text.removeSpan(cs);//from ww w . j a va 2 s .c om } }
From source file:com.bt.heliniumstudentapp.MainActivity.java
protected static void setToolbarTitle(AppCompatActivity context, String title, String subtitle) { final Spannable toolbarTitle = new SpannableString(title); toolbarTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, primaryTextColor)), 0, toolbarTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); try {//from www .ja v a 2 s . c om context.getSupportActionBar().setTitle(toolbarTitle); } catch (NullPointerException e) { return; } if (subtitle != null) { final Spannable toolbarSubtitle = new SpannableString(subtitle); toolbarSubtitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, secondaryTextColor)), 0, toolbarSubtitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); context.getSupportActionBar().setSubtitle(toolbarSubtitle); } }