List of usage examples for android.text SpannableStringBuilder append
public SpannableStringBuilder append(char text)
From source file:com.gh4a.fragment.RepositoryFragment.java
private void fillData() { TextView tvRepoName = (TextView) mContentView.findViewById(R.id.tv_repo_name); SpannableStringBuilder repoName = new SpannableStringBuilder(); repoName.append(mRepository.getOwner().getLogin()); repoName.append("/"); repoName.append(mRepository.getName()); repoName.setSpan(new IntentSpan(tvRepoName.getContext()) { @Override/*from w w w.j ava 2s . c o m*/ protected Intent getIntent() { return IntentUtils.getUserActivityIntent(getActivity(), mRepository.getOwner()); } }, 0, mRepository.getOwner().getLogin().length(), 0); tvRepoName.setText(repoName); tvRepoName.setMovementMethod(UiUtils.CHECKING_LINK_METHOD); TextView tvParentRepo = (TextView) mContentView.findViewById(R.id.tv_parent); if (mRepository.isFork() && mRepository.getParent() != null) { Repository parent = mRepository.getParent(); tvParentRepo.setVisibility(View.VISIBLE); tvParentRepo.setText( getString(R.string.forked_from, parent.getOwner().getLogin() + "/" + parent.getName())); tvParentRepo.setOnClickListener(this); tvParentRepo.setTag(parent); } else { tvParentRepo.setVisibility(View.GONE); } fillTextView(R.id.tv_desc, 0, mRepository.getDescription()); fillTextView(R.id.tv_language, R.string.repo_language, mRepository.getLanguage()); fillTextView(R.id.tv_url, 0, !StringUtils.isBlank(mRepository.getHomepage()) ? mRepository.getHomepage() : mRepository.getHtmlUrl()); mContentView.findViewById(R.id.cell_stargazers).setOnClickListener(this); mContentView.findViewById(R.id.cell_forks).setOnClickListener(this); mContentView.findViewById(R.id.cell_pull_requests).setOnClickListener(this); mContentView.findViewById(R.id.tv_contributors_label).setOnClickListener(this); mContentView.findViewById(R.id.other_info).setOnClickListener(this); mContentView.findViewById(R.id.tv_releases_label).setOnClickListener(this); Permissions permissions = mRepository.getPermissions(); updateClickableLabel(R.id.tv_collaborators_label, permissions != null && permissions.hasPushAccess()); updateClickableLabel(R.id.tv_downloads_label, mRepository.isHasDownloads()); updateClickableLabel(R.id.tv_wiki_label, mRepository.isHasWiki()); TextView tvStargazersCount = (TextView) mContentView.findViewById(R.id.tv_stargazers_count); tvStargazersCount.setText(String.valueOf(mRepository.getWatchers())); TextView tvForksCount = (TextView) mContentView.findViewById(R.id.tv_forks_count); tvForksCount.setText(String.valueOf(mRepository.getForks())); LinearLayout llIssues = (LinearLayout) mContentView.findViewById(R.id.cell_issues); if (mRepository.isHasIssues()) { llIssues.setVisibility(View.VISIBLE); llIssues.setOnClickListener(this); // value will be filled when PR count arrives } else { llIssues.setVisibility(View.GONE); } mContentView.findViewById(R.id.tv_private) .setVisibility(mRepository.isPrivate() ? View.VISIBLE : View.GONE); }
From source file:com.tct.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;/*from ww w .ja v a 2 s .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); }//from www . ja va 2 s . co 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:com.android.messaging.datamodel.MessageNotificationState.java
/** * Performs a query on the database./* w w w . jav a 2s .co m*/ */ private static ConversationInfoList createConversationInfoList() { // Map key is conversation id. We use LinkedHashMap to ensure that entries are iterated in // the same order they were originally added. We scan unseen messages from newest to oldest, // so the corresponding conversations are added in that order, too. final Map<String, ConversationLineInfo> convLineInfos = new LinkedHashMap<>(); int messageCount = 0; Cursor convMessageCursor = null; try { final Context context = Factory.get().getApplicationContext(); final DatabaseWrapper db = DataModel.get().getDatabase(); convMessageCursor = db.rawQuery(ConversationMessageData.getNotificationQuerySql(), null); if (convMessageCursor != null && convMessageCursor.moveToFirst()) { if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "MessageNotificationState: Found unseen message notifications."); } final ConversationMessageData convMessageData = new ConversationMessageData(); HashMap<String, Integer> firstNames = null; String conversationIdForFirstNames = null; String groupConversationName = null; final int maxMessages = getMaxMessagesInConversationNotification(); do { convMessageData.bind(convMessageCursor); // First figure out if this is a valid message. String authorFullName = convMessageData.getSenderFullName(); String authorFirstName = convMessageData.getSenderFirstName(); final String messageText = convMessageData.getText(); final String convId = convMessageData.getConversationId(); final String messageId = convMessageData.getMessageId(); CharSequence text = messageText; final boolean isManualDownloadNeeded = convMessageData.getIsMmsNotification(); if (isManualDownloadNeeded) { // Don't try and convert the text from html if it's sms and not a sms push // notification. Assert.equals(MessageData.BUGLE_STATUS_INCOMING_YET_TO_MANUAL_DOWNLOAD, convMessageData.getStatus()); text = context.getResources().getString(R.string.message_title_manual_download); } ConversationLineInfo currConvInfo = convLineInfos.get(convId); if (currConvInfo == null) { final ConversationListItemData convData = ConversationListItemData .getExistingConversation(db, convId); if (!convData.getNotificationEnabled()) { // Skip conversations that have notifications disabled. continue; } final int subId = BugleDatabaseOperations.getSelfSubscriptionId(db, convData.getSelfId()); groupConversationName = convData.getName(); final Uri avatarUri = AvatarUriUtil.createAvatarUri( convMessageData.getSenderProfilePhotoUri(), convMessageData.getSenderFullName(), convMessageData.getSenderNormalizedDestination(), convMessageData.getSenderContactLookupKey()); currConvInfo = new ConversationLineInfo(convId, convData.getIsGroup(), groupConversationName, convData.getIncludeEmailAddress(), convMessageData.getReceivedTimeStamp(), convData.getSelfId(), convData.getNotificationSoundUri(), convData.getNotificationEnabled(), convData.getNotifiationVibrate(), avatarUri, convMessageData.getSenderContactLookupUri(), subId, convData.getParticipantCount()); convLineInfos.put(convId, currConvInfo); } // Prepare the message line if (currConvInfo.mTotalMessageCount < maxMessages) { if (currConvInfo.mIsGroup) { if (authorFirstName == null) { // authorFullName might be null as well. In that case, we won't // show an author. That is better than showing all the group // names again on the 2nd line. authorFirstName = authorFullName; } } else { // don't recompute this if we don't need to if (!TextUtils.equals(conversationIdForFirstNames, convId)) { firstNames = scanFirstNames(convId); conversationIdForFirstNames = convId; } if (firstNames != null) { final Integer count = firstNames.get(authorFirstName); if (count != null && count > 1) { authorFirstName = authorFullName; } } if (authorFullName == null) { authorFullName = groupConversationName; } if (authorFirstName == null) { authorFirstName = groupConversationName; } } final String subjectText = MmsUtils.cleanseMmsSubject(context.getResources(), convMessageData.getMmsSubject()); if (!TextUtils.isEmpty(subjectText)) { final String subjectLabel = context.getString(R.string.subject_label); final SpannableStringBuilder spanBuilder = new SpannableStringBuilder(); spanBuilder.append( context.getString(R.string.notification_subject, subjectLabel, subjectText)); spanBuilder.setSpan(new TextAppearanceSpan(context, R.style.NotificationSubjectText), 0, subjectLabel.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (!TextUtils.isEmpty(text)) { // Now add the actual message text below the subject header. spanBuilder.append(System.getProperty("line.separator") + text); } text = spanBuilder; } // If we've got attachments, find the best one. If one of the messages is // a photo, save the url so we'll display a big picture notification. // Otherwise, show the first one we find. Uri attachmentUri = null; String attachmentType = null; final MessagePartData messagePartData = getMostInterestingAttachment(convMessageData); if (messagePartData != null) { attachmentUri = messagePartData.getContentUri(); attachmentType = messagePartData.getContentType(); } currConvInfo.mLineInfos .add(new MessageLineInfo(currConvInfo.mIsGroup, authorFullName, authorFirstName, text, attachmentUri, attachmentType, isManualDownloadNeeded, messageId)); } messageCount++; currConvInfo.mTotalMessageCount++; } while (convMessageCursor.moveToNext()); } } finally { if (convMessageCursor != null) { convMessageCursor.close(); } } if (convLineInfos.isEmpty()) { return null; } else { return new ConversationInfoList(messageCount, Lists.newLinkedList(convLineInfos.values())); } }
From source file:com.abcvoipsip.ui.messages.MessageAdapter.java
private CharSequence formatMessage(String contact, String body, String contentType) { SpannableStringBuilder buf = new SpannableStringBuilder(); if (!TextUtils.isEmpty(body)) { // Converts html to spannable if ContentType is "text/html". if (contentType != null && "text/html".equals(contentType)) { buf.append("\n"); buf.append(Html.fromHtml(body)); } else {/*from w w w. j a v a 2s. c o m*/ SmileyParser parser = SmileyParser.getInstance(); buf.append(parser.addSmileySpans(body)); } } // We always show two lines because the optional icon bottoms are // aligned with the // bottom of the text field, assuming there are two lines for the // message and the sent time. buf.append("\n"); int startOffset = buf.length(); startOffset = buf.length(); buf.setSpan(mTextSmallSpan, startOffset, buf.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return buf; }
From source file:com.chen.mail.browse.SendersView.java
public static SpannableStringBuilder createMessageInfo(Context context, Conversation conv, final boolean resourceCachingRequired) { SpannableStringBuilder messageInfo = new SpannableStringBuilder(); try {/*from www. j a v a 2 s .c o m*/ ConversationInfo conversationInfo = conv.conversationInfo; int sendingStatus = conv.sendingState; boolean hasSenders = false; // This covers the case where the sender is "me" and this is a draft // message, which means this will only run once most of the time. for (MessageInfo m : conversationInfo.messageInfos) { if (!TextUtils.isEmpty(m.sender)) { hasSenders = true; break; } } getSenderResources(context, resourceCachingRequired); if (conversationInfo != null) { int count = conversationInfo.messageCount; int draftCount = conversationInfo.draftCount; boolean showSending = sendingStatus == UIProvider.ConversationSendingState.SENDING; if (count > 1) { messageInfo.append(count + ""); } messageInfo.setSpan( CharacterStyle.wrap(conv.read ? sMessageInfoReadStyleSpan : sMessageInfoUnreadStyleSpan), 0, messageInfo.length(), 0); if (draftCount > 0) { // If we are showing a message count or any draft text and there // is at least 1 sender, prepend the sending state text with a // comma. if (hasSenders || count > 1) { messageInfo.append(sSendersSplitToken); } SpannableStringBuilder draftString = new SpannableStringBuilder(); if (draftCount == 1) { draftString.append(sDraftSingularString); } else { draftString.append(sDraftPluralString + String.format(sDraftCountFormatString, draftCount)); } draftString.setSpan(CharacterStyle.wrap(sDraftsStyleSpan), 0, draftString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); messageInfo.append(draftString); } if (showSending) { // If we are showing a message count or any draft text, prepend // the sending state text with a comma. if (count > 1 || draftCount > 0) { messageInfo.append(sSendersSplitToken); } SpannableStringBuilder sending = new SpannableStringBuilder(); sending.append(sSendingString); sending.setSpan(sSendingStyleSpan, 0, sending.length(), 0); messageInfo.append(sending); } // Prepend a space if we are showing other message info text. if (count > 1 || (draftCount > 0 && hasSenders) || showSending) { messageInfo.insert(0, sMessageCountSpacerString); } } } finally { if (!resourceCachingRequired) { clearResourceCache(); } } return messageInfo; }
From source file:com.battlelancer.seriesguide.ui.dialogs.AddShowDialogFragment.java
private void populateShowViews(Show show) { if (show == null) { mButtonPositive.setEnabled(false); if (!AndroidUtils.isNetworkConnected(getActivity())) { overview.setText(R.string.offline); }//from w w w. j a v a 2 s . c om return; } mButtonPositive.setEnabled(true); ButterKnife.apply(labelViews, VISIBLE, true); // title, overview title.setText(show.title); overview.setText(show.overview); SpannableStringBuilder meta = new SpannableStringBuilder(); // status boolean isContinuing = JsonExportTask.ShowStatusExport.CONTINUING.equals(show.status); meta.append(getString(isContinuing ? R.string.show_isalive : R.string.show_isnotalive)); // if continuing, paint status green meta.setSpan( new TextAppearanceSpan(getActivity(), isContinuing ? R.style.TextAppearance_Subhead_Green : R.style.TextAppearance_Subhead_Dim), 0, meta.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); meta.append("\n"); // release day and time String[] values = TimeTools.formatToShowReleaseTimeAndDay(getActivity(), show.airtime, show.country, show.airday); meta.append(values[1]).append(" ").append(values[0]); meta.append("\n"); // network, runtime meta.append(show.network); meta.append("\n"); meta.append(getString(R.string.runtime_minutes, show.runtime)); showmeta.setText(meta); // TheTVDB rating tvdbRating.setText(show.rating > 0 ? String.valueOf(show.rating) : getString(R.string.norating)); // genres Utils.setValueOrPlaceholder(genres, Utils.splitAndKitTVDBStrings(show.genres)); // original release Utils.setValueOrPlaceholder(released, TimeTools.getShowReleaseYear(show.firstAired, show.airtime, show.country)); // poster Utils.loadPosterThumbnail(getActivity(), poster, show.poster); }
From source file:com.android.tv.guide.ProgramItemView.java
public void setValues(TableEntry entry, int selectedGenreId, long fromUtcMillis, long toUtcMillis, String gapTitle) {/* w ww . ja va2 s .c o m*/ mTableEntry = entry; ViewGroup.LayoutParams layoutParams = getLayoutParams(); layoutParams.width = entry.getWidth(); setLayoutParams(layoutParams); String title = entry.program != null ? entry.program.getTitle() : null; String episode = entry.program != null ? entry.program.getEpisodeDisplayTitle(getContext()) : null; TextAppearanceSpan titleStyle = sGrayedOutProgramTitleStyle; TextAppearanceSpan episodeStyle = sGrayedOutEpisodeTitleStyle; if (entry.getWidth() < sVisibleThreshold) { setText(null); } else { if (entry.isGap()) { title = gapTitle; episode = null; } else if (entry.hasGenre(selectedGenreId)) { titleStyle = sProgramTitleStyle; episodeStyle = sEpisodeTitleStyle; } if (TextUtils.isEmpty(title)) { title = getResources().getString(R.string.program_title_for_no_information); } if (mTableEntry.scheduledRecording != null) { //TODO(dvr): use a proper icon for UI status. title = "" + title; } SpannableStringBuilder description = new SpannableStringBuilder(); description.append(title); if (!TextUtils.isEmpty(episode)) { description.append('\n'); // Add a 'zero-width joiner'/ZWJ in order to ensure we have the same line height for // all lines. This is a non-printing character so it will not change the horizontal // spacing however it will affect the line height. As we ensure the ZWJ has the same // text style as the title it will make sure the line height is consistent. description.append('\u200D'); int middle = description.length(); description.append(episode); description.setSpan(titleStyle, 0, middle, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); description.setSpan(episodeStyle, middle, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { description.setSpan(titleStyle, 0, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } setText(description); } measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); mTextWidth = getMeasuredWidth() - getPaddingStart() - getPaddingEnd(); int start = GuideUtils.convertMillisToPixel(entry.entryStartUtcMillis); int guideStart = GuideUtils.convertMillisToPixel(fromUtcMillis); layoutVisibleArea(guideStart - start); // Maximum width for us to use a ripple mMaxWidthForRipple = GuideUtils.convertMillisToPixel(fromUtcMillis, toUtcMillis); }
From source file:org.mariotaku.twidere.view.NameView.java
public void updateText(@Nullable BidiFormatter formatter) { final SpannableStringBuilder sb = new SpannableStringBuilder(); final String primaryText = mNameFirst ? mName : mScreenName; final String secondaryText = mNameFirst ? mScreenName : mName; if (primaryText != null) { int start = sb.length(); if (formatter != null && !isInEditMode()) { sb.append(formatter.unicodeWrap(primaryText)); } else {// w w w . j a v a 2s . c om sb.append(primaryText); } int end = sb.length(); sb.setSpan(mPrimaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mPrimaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mPrimaryTextSize, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } sb.append(mTwoLine ? '\n' : ' '); if (secondaryText != null) { int start = sb.length(); if (formatter != null && !isInEditMode()) { sb.append(formatter.unicodeWrap(secondaryText)); } else { sb.append(secondaryText); } int end = sb.length(); sb.setSpan(mSecondaryTextColor, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mSecondaryTextStyle, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sb.setSpan(mSecondaryTextSize, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } setText(sb); }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void startImg(SpannableStringBuilder text, Attributes attributes, HtmlParser.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null;/* w ww . j av a 2 s. c om*/ if (img != null) { d = img.getDrawable(src); } if (d == null) { d = ResourcesCompat.getDrawable(Resources.getSystem(), android.R.drawable.ic_menu_report_image, null); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }