List of usage examples for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE
int SPAN_INCLUSIVE_EXCLUSIVE
To view the source code for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE.
Click Source Link
From source file:net.kourlas.voipms_sms.adapters.ConversationRecyclerViewAdapter.java
@Override public void onBindViewHolder(MessageViewHolder messageViewHolder, int i) { Message message = messages.get(i);/* w ww. j a v a2s . c o m*/ int viewType = getItemViewType(i); if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_RIGHT_PRIMARY) { QuickContactBadge contactBadge = messageViewHolder.getContactBadge(); if (viewType == ITEM_LEFT_PRIMARY) { contactBadge.assignContactFromPhone(message.getContact(), true); } else { contactBadge.assignContactFromPhone(message.getDid(), true); } String photoUri; if (viewType == ITEM_LEFT_PRIMARY) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact()); } else { photoUri = Utils.getContactPhotoUri(applicationContext, ContactsContract.Profile.CONTENT_URI); if (photoUri == null) { photoUri = Utils.getContactPhotoUri(applicationContext, message.getDid()); } } if (photoUri != null) { contactBadge.setImageURI(Uri.parse(photoUri)); } else { contactBadge.setImageToDefault(); } } View smsContainer = messageViewHolder.getSmsContainer(); TextView messageText = messageViewHolder.getMessageText(); SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder(); messageTextBuilder.append(message.getText()); if (!filterConstraint.equals("")) { int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (index != -1) { messageTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); messageTextBuilder.setSpan( new ForegroundColorSpan(ContextCompat.getColor(applicationContext, R.color.dark_gray)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } } messageText.setText(messageTextBuilder); TextView dateText = messageViewHolder.getDateText(); if (!message.isDelivered()) { if (!message.isDeliveryInProgress()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); if (isItemChecked(i)) { dateTextBuilder .append(applicationContext.getString(R.string.conversation_message_not_sent_selected)); } else { dateTextBuilder.append(applicationContext.getString(R.string.conversation_message_not_sent)); } dateTextBuilder.setSpan( new ForegroundColorSpan( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateText.setText(dateTextBuilder); dateText.setVisibility(View.VISIBLE); } else { dateText.setText(applicationContext.getString(R.string.conversation_message_sending)); dateText.setVisibility(View.VISIBLE); } } else if (i == messages.size() - 1 || ((viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) && getItemViewType(i + 1) != ITEM_LEFT_SECONDARY) || ((viewType == ITEM_RIGHT_PRIMARY || viewType == ITEM_RIGHT_SECONDARY) && getItemViewType(i + 1) != ITEM_RIGHT_SECONDARY)) { dateText.setText(Utils.getFormattedDate(applicationContext, message.getDate(), false)); dateText.setVisibility(View.VISIBLE); } else { dateText.setVisibility(View.GONE); } if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) { smsContainer.setBackgroundResource(isItemChecked(i) ? android.R.color.holo_blue_dark : R.color.primary); } else { smsContainer.setBackgroundResource( isItemChecked(i) ? android.R.color.holo_blue_dark : android.R.color.white); messageText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); messageText.setLinkTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white) : ContextCompat.getColor(applicationContext, R.color.dark_gray)); dateText.setTextColor( isItemChecked(i) ? ContextCompat.getColor(applicationContext, R.color.message_translucent_white) : ContextCompat.getColor(applicationContext, R.color.message_translucent_dark_grey)); } }
From source file:com.tct.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;/* ww w . j a v a2s . c o m*/ final BidiFormatter bidiFormatter = getBidiFormatter(); if (TextUtils.isEmpty(mSubject)) { mSubject = conv.subject; } final SpannableStringBuilder sb = new SpannableStringBuilder(bidiFormatter.unicodeWrap(mSubject)); sb.append('\u0020'); final Settings settings = account.settings; final int start = sb.length(); if (settings.importanceMarkersEnabled && conv.isImportant()) { sb.append(".\u0020"); sb.setSpan(new DynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BASELINE) { @Override public Drawable getDrawable() { Drawable d = getContext().getResources() .getDrawable(R.drawable.ic_email_caret_none_important_unread); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_S // mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */); // mFolderDisplayer.appendFolderSpans(sb, bidiFormatter); // final int end = sb.length(); // sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(sb); //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_S // if(isNeedMove()){ // setMovementMethod(LinkMovementMethod.getInstance()); // } //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_E //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_E }
From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java
public void updateViews() { this.setOrientation(VERTICAL); float scale = getResources().getDisplayMetrics().density; this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding), getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding)); LinearLayout timeStartEndLayout = new LinearLayout(getContext()); TextView timeStartEndText = new TextView(getContext()); timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip)); timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL); }/* w ww . j a v a2s . c o m*/ } // Check if we have Realtime for start and or end. boolean hasRealtime = false; Pair<Date, RealTimeState> transitTime = trip.departsAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } else { transitTime = trip.arrivesAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } } // if (hasRealtime) { // ImageView liveDrawable = new ImageView(getContext()); // liveDrawable.setImageResource(R.drawable.ic_live); // ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0); // timeStartEndLayout.addView(liveDrawable); // // AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f); // animation1.setDuration(600); // animation1.setRepeatMode(Animation.REVERSE); // animation1.setRepeatCount(Animation.INFINITE); // // liveDrawable.startAnimation(animation1); // } timeStartEndLayout.addView(timeStartEndText); LinearLayout startAndEndPointLayout = new LinearLayout(getContext()); TextView startAndEndPoint = new TextView(getContext()); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); startAndEndPoint.setText(String.format("%s %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()), bidiFormatter.unicodeWrap(trip.toStop().getName()))); startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL); } } ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale)); startAndEndPointLayout.addView(startAndEndPoint); RelativeLayout timeLayout = new RelativeLayout(getContext()); LinearLayout routeChanges = new LinearLayout(getContext()); routeChanges.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); changesLayoutParams.gravity = Gravity.CENTER_VERTICAL; if (trip.hasAlertsOrNotes()) { ImageView warning = new ImageView(getContext()); warning.setImageResource(R.drawable.ic_trip_deviation); ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0); routeChanges.addView(warning); } int currentTransportCount = 1; int transportCount = trip.getLegs().size(); for (Leg leg : trip.getLegs()) { if (!leg.isTransit() && transportCount > 3) { if (leg.getDistance() < 150) { continue; } } if (currentTransportCount > 1 && transportCount >= currentTransportCount) { ImageView separator = new ImageView(getContext()); separator.setImageResource(R.drawable.transport_separator); ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0); separator.setLayoutParams(changesLayoutParams); routeChanges.addView(separator); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(separator, -1f); } } ImageView changeImageView = new ImageView(getContext()); Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg); changeImageView.setImageDrawable(transportDrawable); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(changeImageView, -1f); } ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0); changeImageView.setLayoutParams(changesLayoutParams); routeChanges.addView(changeImageView); if (currentTransportCount <= 3) { String lineName = leg.getRouteShortName(); if (!TextUtils.isEmpty(lineName)) { TextView lineNumberView = new TextView(getContext()); lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan( LegUtil.getColor(getContext(), leg), Color.WHITE, ViewHelper.dipsToPix(getContext().getResources(), 4)); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(lineName); sb.append(' '); sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); lineNumberView.setText(sb); ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale), (int) (2 * scale), 0); lineNumberView.setLayoutParams(changesLayoutParams); routeChanges.addView(lineNumberView); } } currentTransportCount++; } TextView durationText = new TextView(getContext()); durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000)); durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); durationText.setTypeface(Typeface.DEFAULT_BOLD); timeLayout.addView(routeChanges); timeLayout.addView(durationText); RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText .getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END); } else { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } durationText.setLayoutParams(durationTextParams); View divider = new View(getContext()); ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); divider.setLayoutParams(dividerParams); this.addView(timeLayout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams(); params.height = LayoutParams.MATCH_PARENT; params.addRule(RelativeLayout.CENTER_VERTICAL); routeChanges.setLayoutParams(params); this.addView(startAndEndPointLayout); this.addView(timeStartEndLayout); if (mShowDivider) { this.addView(divider); } }
From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java
@Override public Spannable getDisplayedAuthor(Context context, boolean linkify, int color) { if (displayedAuthor == null) { if (TextUtils.isEmpty(by)) { displayedAuthor = new SpannableString(""); } else {/*w w w . j a v a 2 s .c o m*/ defaultColor = ContextCompat.getColor(context, AppUtils.getThemedResId(context, linkify ? android.R.attr.textColorLink : android.R.attr.textColorSecondary)); displayedAuthor = createAuthorSpannable(linkify); } } if (displayedAuthor.length() == 0) { return displayedAuthor; } displayedAuthor.setSpan(new ForegroundColorSpan(color != 0 ? color : defaultColor), AUTHOR_SEPARATOR.length(), displayedAuthor.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return displayedAuthor; }
From source file:io.github.hidroh.materialistic.widget.StoryView.java
public void setPromoted(int change) { SpannableString spannable = new SpannableString(String.format(Locale.US, PROMOTED, change)); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(mPromotedColorResId), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mRankTextView.append(spannable);/*from w w w . j a v a 2 s . co m*/ }
From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java
@Override public Spannable getDisplayedTime(Context context) { if (displayedTime == null) { SpannableStringBuilder builder = new SpannableStringBuilder( dead ? context.getString(R.string.dead_prefix) + " " : ""); SpannableString timeSpannable = new SpannableString(AppUtils.getAbbreviatedTimeSpan(time * 1000)); if (deleted) { timeSpannable.setSpan(new StrikethroughSpan(), 0, timeSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }// w ww . jav a 2s. c o m builder.append(timeSpannable); displayedTime = builder; } return displayedTime; }
From source file:com.easemob.chatuidemo.activity.GroupPickContactsActivity.java
private void setSelectedNumber(int number) { String numberStr = number + ""; SpannableString spannableString = new SpannableString( String.format(getString(R.string.filter_selected), number)); spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), 2, 2 + numberStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); selectedNumberTextView.setText(spannableString); }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords, final int indexInSuggestedWords) { if (indexInSuggestedWords >= suggestedWords.size()) { return null; }/*from w w w . j ava 2 s .c om*/ final String word = suggestedWords.getLabel(indexInSuggestedWords); // TODO: don't use the index to decide whether this is the auto-correction/typed word, as // this is brittle final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect && indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION; final boolean isTypedWordValid = suggestedWords.mTypedWordValid && indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD; if (!isAutoCorrection && !isTypedWordValid) { return word; } final int len = word.length(); final Spannable spannedWord = new SpannableString(word); final int options = mSuggestionStripOptions; if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0) || (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) { spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) { spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } return spannedWord; }
From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java
@NonNull private SpannableString createAuthorSpannable(boolean authorLink) { SpannableString bySpannable = new SpannableString(AUTHOR_SEPARATOR + by); if (!authorLink) { return bySpannable; }// w w w. j av a 2 s . c o m bySpannable.setSpan(new StyleSpan(Typeface.BOLD), AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View view) { view.getContext() .startActivity(new Intent(Intent.ACTION_VIEW).setData(AppUtils.createUserUri(getBy()))); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; bySpannable.setSpan(clickableSpan, AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return bySpannable; }
From source file:com.keylesspalace.tusky.activity.ComposeActivity.java
private static void highlightSpans(Spannable text, int colour) { // Strip all existing colour spans. int n = text.length(); ForegroundColorSpan[] oldSpans = text.getSpans(0, n, ForegroundColorSpan.class); for (int i = oldSpans.length - 1; i >= 0; i--) { text.removeSpan(oldSpans[i]);/* w ww .j ava 2 s . c o m*/ } // Colour the mentions and hashtags. String string = text.toString(); int start; int end = 0; while (end < n) { char[] chars = { '#', '@' }; FindCharsResult found = findStart(string, end, chars); start = found.stringIndex; if (start < 0) { break; } if (found.charIndex == 0) { end = findEndOfHashtag(string, start); } else if (found.charIndex == 1) { end = findEndOfMention(string, start); } else { break; } if (end < 0) { break; } text.setSpan(new ForegroundColorSpan(colour), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } }