List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder
public SpannableStringBuilder()
From source file:com.gh4a.activities.IssueActivity.java
private void fillData() { // set details inside listview header ImageView ivGravatar = (ImageView) mListHeaderView.findViewById(R.id.iv_gravatar); AvatarHandler.assignAvatar(ivGravatar, mIssue.getUser()); ivGravatar.setOnClickListener(this); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); boolean closed = Constants.Issue.STATE_CLOSED.equals(mIssue.getState()); int stateTextResId = closed ? R.string.closed : R.string.open; int stateColorAttributeId = closed ? R.attr.colorIssueClosed : R.attr.colorIssueOpen; tvState.setText(getString(stateTextResId).toUpperCase(Locale.getDefault())); transitionHeaderToColor(stateColorAttributeId, closed ? R.attr.colorIssueClosedDark : R.attr.colorIssueOpenDark); UiUtils.trySetListOverscrollColor(mRecyclerView, UiUtils.resolveColor(this, stateColorAttributeId)); TextView tvExtra = (TextView) mListHeaderView.findViewById(R.id.tv_extra); tvExtra.setText(ApiHelpers.getUserLogin(this, mIssue.getUser())); TextView tvTimestamp = (TextView) mListHeaderView.findViewById(R.id.tv_timestamp); tvTimestamp.setText(StringUtils.formatRelativeTime(this, mIssue.getCreatedAt(), true)); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); tvTitle.setText(mIssue.getTitle());// w ww. j a v a2s. c om String body = mIssue.getBodyHtml(); TextView descriptionView = (TextView) mListHeaderView.findViewById(R.id.tv_desc); if (!StringUtils.isBlank(body)) { body = HtmlUtils.format(body).toString(); mImageGetter.bind(descriptionView, body, mIssue.getNumber()); } descriptionView.setMovementMethod(UiUtils.CHECKING_LINK_METHOD); View milestoneGroup = mListHeaderView.findViewById(R.id.milestone_container); if (mIssue.getMilestone() != null) { TextView tvMilestone = (TextView) mListHeaderView.findViewById(R.id.tv_milestone); tvMilestone.setText(mIssue.getMilestone().getTitle()); milestoneGroup.setVisibility(View.VISIBLE); } else { milestoneGroup.setVisibility(View.GONE); } View assigneeGroup = mListHeaderView.findViewById(R.id.assignee_container); if (mIssue.getAssignee() != null) { TextView tvAssignee = (TextView) mListHeaderView.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin()); ImageView ivAssignee = (ImageView) mListHeaderView.findViewById(R.id.iv_assignee); AvatarHandler.assignAvatar(ivAssignee, mIssue.getAssignee()); ivAssignee.setOnClickListener(this); assigneeGroup.setVisibility(View.VISIBLE); } else { assigneeGroup.setVisibility(View.GONE); } List<Label> labels = mIssue.getLabels(); View labelGroup = mListHeaderView.findViewById(R.id.label_container); if (labels != null && !labels.isEmpty()) { TextView labelView = (TextView) mListHeaderView.findViewById(R.id.labels); SpannableStringBuilder builder = new SpannableStringBuilder(); for (Label label : labels) { int pos = builder.length(); IssueLabelSpan span = new IssueLabelSpan(this, label, true); builder.append(label.getName()); builder.setSpan(span, pos, pos + label.getName().length(), 0); } labelView.setText(builder); labelGroup.setVisibility(View.VISIBLE); } else { labelGroup.setVisibility(View.GONE); } TextView tvPull = (TextView) mListHeaderView.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } else { tvPull.setVisibility(View.GONE); } mHeader.setVisibility(View.VISIBLE); updateFabVisibility(); updateCommentLockState(); }
From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java
private void setTemperature(TextView view, int labelResId, double value) { SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(getString(labelResId)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Caption), 0, builder.length(), 0);/*from w ww .j a v a2 s. com*/ builder.append("\n"); int lengthOld = builder.length(); builder.append(String.format(Locale.getDefault(), "%.1f", value)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Display3), lengthOld, builder.length(), 0); lengthOld = builder.length(); builder.append(getString(R.string.unit_celsius)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_App_Unit), lengthOld, builder.length(), 0); view.setText(builder); }
From source file:com.android.tv.guide.ProgramItemView.java
public void setValues(TableEntry entry, int selectedGenreId, long fromUtcMillis, long toUtcMillis, String gapTitle) {//from w ww.j av a 2 s . co 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.rm3l.ddwrt.tiles.syslog.StatusSyslogTile.java
@Override public void onLoadFinished(@NotNull Loader<NVRAMInfo> loader, @Nullable NVRAMInfo data) { //Set tiles/*from w w w . j a va2 s.c o m*/ Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); layout.findViewById(R.id.tile_status_router_syslog_header_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_router_syslog_content_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_router_syslog_state).setVisibility(View.VISIBLE); layout.findViewById(R.id.tile_status_router_syslog_content).setVisibility(View.VISIBLE); if (data == null) { data = new NVRAMInfo().setException(new DDWRTNoDataException("No Data!")); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_router_syslog_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } final String syslogdEnabledPropertyValue = data.getProperty(SYSLOGD_ENABLE); final boolean isSyslogEnabled = "1".equals(syslogdEnabledPropertyValue); final TextView syslogState = (TextView) this.layout.findViewById(R.id.tile_status_router_syslog_state); final View syslogContentView = this.layout.findViewById(R.id.tile_status_router_syslog_content); final EditText filterEditText = (EditText) this.layout .findViewById(R.id.tile_status_router_syslog_filter); syslogState.setText( syslogdEnabledPropertyValue == null ? "-" : (isSyslogEnabled ? "Enabled" : "Disabled")); syslogState.setVisibility(mDisplayStatus ? View.VISIBLE : View.GONE); final TextView logTextView = (TextView) syslogContentView; if (isSyslogEnabled) { //Highlight textToFind for new log lines final String newSyslog = data.getProperty(SYSLOG, EMPTY_STRING); //Hide container if no data at all (no existing data, and incoming data is empty too) final View scrollView = layout.findViewById(R.id.tile_status_router_syslog_content_scrollview); //noinspection ConstantConditions Spanned newSyslogSpan = new SpannableString(newSyslog); final SharedPreferences sharedPreferences = this.mParentFragmentPreferences; final String existingSearch = sharedPreferences != null ? sharedPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (!isNullOrEmpty(existingSearch)) { if (isNullOrEmpty(filterEditText.getText().toString())) { filterEditText.setText(existingSearch); } if (!isNullOrEmpty(newSyslog)) { //noinspection ConstantConditions newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch); } } // if (!(isNullOrEmpty(existingSearch) || isNullOrEmpty(newSyslog))) { // filterEditText.setText(existingSearch); // //noinspection ConstantConditions // newSyslogSpan = findAndHighlightOutput(newSyslog, existingSearch); // } if (isNullOrEmpty(logTextView.getText().toString()) && isNullOrEmpty(newSyslog)) { scrollView.setVisibility(View.INVISIBLE); } else { scrollView.setVisibility(View.VISIBLE); logTextView.setMovementMethod(new ScrollingMovementMethod()); logTextView.append( new SpannableStringBuilder().append(Html.fromHtml("<br/>")).append(newSyslogSpan)); } filterEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (filterEditText.getRight() - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { //Reset everything filterEditText.setText(EMPTY_STRING); //this will trigger the TextWatcher, thus disabling the "Find" button //Highlight text in textview final String currentText = logTextView.getText().toString(); logTextView.setText(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING) .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING)); if (sharedPreferences != null) { final SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING); editor.apply(); } return true; } } return false; } }); filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { final String textToFind = filterEditText.getText().toString(); if (isNullOrEmpty(textToFind)) { //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present return true; } if (sharedPreferences != null) { if (textToFind.equalsIgnoreCase(existingSearch)) { //No need to go further as this is already the string we are looking for return true; } final SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind); editor.apply(); } //Highlight text in textview final String currentText = logTextView.getText().toString(); logTextView.setText( findAndHighlightOutput(currentText.replaceAll(SLASH_FONT_HTML, EMPTY_STRING) .replaceAll(FONT_COLOR_YELLOW_HTML, EMPTY_STRING), textToFind)); return true; } return false; } }); } } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } doneWithLoaderInstance(this, loader, R.id.tile_status_router_syslog_togglebutton_title, R.id.tile_status_router_syslog_togglebutton); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 3) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { myTTS = new TextToSpeech(_context, this); } else {/* w w w . jav a 2 s. com*/ SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(textInfo.getText()); ssb.append(redText(R.string.setup_tts_failed)); ssb.append('\n'); textInfo.setText(ssb); svMyview.fullScroll(View.FOCUS_DOWN); } } }
From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java
@Override public void onInit(int i) { if (i == TextToSpeech.SUCCESS) { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(textInfo.getText());/*from ww w . jav a 2 s . c om*/ ssb.append(myTTS.getDefaultEngine() + " "); ssb.append(greenText(R.string.setup_tts_default_locale)); ssb.append(myTTS.getLanguage().getLanguage()); ssb.append('\n'); textInfo.setText(ssb); svMyview.fullScroll(View.FOCUS_DOWN); } else { myTTS.shutdown(); myTTS = null; } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
public HtmlToSpannedConverter(String subject, String source, ThemeColors colors, HtmlParser.ImageGetter imageGetter, boolean openSpoilers, Parser parser) { mSource = source;/*from w w w . j a v a2 s . c o m*/ mSpannableStringBuilder = new SpannableStringBuilder(); if (!TextUtils.isEmpty(subject)) { mSpannableStringBuilder.append(subject); int len = mSpannableStringBuilder.length(); mSpannableStringBuilder.setSpan(new RelativeSizeSpan(1.25f), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mSpannableStringBuilder.setSpan(new StyleSpan(Typeface.BOLD), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (colors != null) { mSpannableStringBuilder.setSpan(new ForegroundColorSpan(colors.subjectForeground), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mSpannableStringBuilder.append('\n'); mStartLength = mSpannableStringBuilder.length(); } mColors = colors; mOpenSpoilers = openSpoilers; mImageGetter = imageGetter; mReader = parser; }
From source file:com.uwetrottmann.wpdisplay.ui.DisplayFragment.java
private void setText(TextView view, int labelResId, String value) { SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(getString(labelResId)); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Caption), 0, builder.length(), 0);//from w w w. ja va 2s .c o m builder.append("\n"); int lengthOld = builder.length(); builder.append(value); builder.setSpan(new TextAppearanceSpan(getActivity(), R.style.TextAppearance_AppCompat_Display1), lengthOld, builder.length(), 0); view.setText(builder); }
From source file:com.heneryh.aquanotes.ui.CtlrStatusFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//*from ww w . j a va 2 s .c o m*/ private void updateControllerTabs(Ctlr cntl, Cursor cursor) { try { mSessionCursor = true; // Header Area cntl.mTitleString = cursor.getString(ControllersQuery.TITLE); cntl.mSubtitle = cursor.getString(ControllersQuery.WAN_URL); cntl.mTitleView.setText(cntl.mTitleString); cntl.mSubtitleView.setText(cntl.mSubtitle); // Probes Tab Area cntl.mUrl = "http://test"; //cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(cntl.mUrl)) { cntl.mUrl = ""; } cntl.mHashtag = ""; //cursor.getString(SessionsQuery.HASHTAG); if (!TextUtils.isEmpty(cntl.mHashtag)) { // Create the button text SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(getString(R.string.tag_stream) + " "); int boldStart = sb.length(); sb.append(getHashtagsString(cntl.mHashtag)); sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); cntl.mTagDisplayView.setText(sb); cntl.mTagDisplayView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(getActivity(), TagStreamActivity.class); intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString("was hash tag")); startActivity(intent); } }); } else { cntl.mTagDisplayView.setVisibility(View.GONE); } cntl.mRoomName = "Room"; cntl.mRoomId = "Rm 202"; //cursor.getString(SessionsQuery.ROOM_ID); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. // cntl.mStarred.setOnCheckedChangeListener(null); // cntl.mStarred.setChecked(false); // cntl.mStarred.setOnCheckedChangeListener(this); final String sessionAbstract = "I can work on the order these show up, it is just a sort on the query. Note there is a title above in the header between the l/r icons. Also a title down in the tab host header. I will do one or the other not both. Oh, and you have to swipe l/r once to get that top title to sync."; //cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(cntl.mAbstractView, sessionAbstract); cntl.mAbstractView.setVisibility(View.VISIBLE); cntl.mHasSummaryContent = true; } else { cntl.mAbstractView.setVisibility(View.GONE); } final String sessionRequirements = "How shall I lay out this screen??? Suggestions?"; //cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(cntl.mRequirementsView, sessionRequirements); cntl.mRequirementsBlockView.setVisibility(View.VISIBLE); cntl.mHasSummaryContent = true; } else { cntl.mRequirementsBlockView.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !cntl.mHasSummaryContent) { cntl.mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + cntl.mTitleString); // updateLinksTab(cursor); // updateNotesTab(); updateWorkspaceHeader(cntl.index); } finally { // cursor.close(); } }
From source file:com.silentcircle.contacts.vcard.ManageVCardActivity.java
private Dialog getVCardFileSelectDialog(boolean multipleSelect) { final int size = mAllVCardFileList.size(); final VCardSelectedListener listener = new VCardSelectedListener(multipleSelect); final AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle(R.string.select_vcard_title_remove).setPositiveButton(android.R.string.ok, listener) .setOnCancelListener(mCancelListener).setNegativeButton(android.R.string.cancel, mCancelListener); CharSequence[] items = new CharSequence[size]; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < size; i++) { VCardFile vcardFile = mAllVCardFileList.get(i); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); stringBuilder.append(vcardFile.getName()); stringBuilder.append('\n'); int indexToBeSpanned = stringBuilder.length(); // Smaller date text looks better, since each file name becomes easier to read. // The value set to RelativeSizeSpan is arbitrary. You can change it to any other // value (but the value bigger than 1.0f would not make nice appearance :) stringBuilder.append("(" + dateFormat.format(new Date(vcardFile.getLastModified())) + ")"); stringBuilder.setSpan(new RelativeSizeSpan(0.7f), indexToBeSpanned, stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); items[i] = stringBuilder;/*from w w w. j a v a2s . c om*/ } if (multipleSelect) { builder.setMultiChoiceItems(items, (boolean[]) null, listener); } else { builder.setSingleChoiceItems(items, 0, listener); } return builder.create(); }