List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder
public SpannableStringBuilder()
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 {//w w w. ja v a 2 s . co 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.google.android.marvin.mytalkback.speechrules.NodeSpeechRuleProcessor.java
/** * If the supplied node has a label, replaces the builder text with a * version formatted with the label.//ww w .ja va 2 s.c om */ private void formatTextWithLabel(AccessibilityNodeInfoCompat node, SpannableStringBuilder builder) { final AccessibilityNodeInfoCompat labelNode = AccessibilityNodeInfoCompatUtils.getLabeledBy(node); if (labelNode == null) { return; } final SpannableStringBuilder labelDescription = new SpannableStringBuilder(); appendDescriptionForTree(labelNode, labelDescription, null, null); if (TextUtils.isEmpty(labelDescription)) { return; } final String labeled = mContext.getString(R.string.template_labeled_item, builder, labelDescription); // Replace the text of the builder. builder.clear(); builder.append(labeled); }
From source file:app.abhijit.iter.MainActivity.java
private void setupGettingStartedHint() { TextView gettingStartedHint = (TextView) findViewById(R.id.hint_getting_started); int lineHeight = gettingStartedHint.getLineHeight(); Drawable hamburgerIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_hamburger, null); hamburgerIcon.setBounds(0, 0, lineHeight, lineHeight); SpannableStringBuilder hintText = new SpannableStringBuilder(); hintText.append(getResources().getString(R.string.hint_getting_started_1)).append(" "); hintText.setSpan(new ImageSpan(hamburgerIcon), hintText.length() - 1, hintText.length(), 0); hintText.append(getResources().getString(R.string.hint_getting_started_2)); gettingStartedHint.setText(hintText); }
From source file:com.android.screenspeak.speechrules.NodeSpeechRuleProcessor.java
/** * If the supplied node has a label, replaces the builder text with a * version formatted with the label./*from w w w. j a v a2s .com*/ */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void formatTextWithLabel(AccessibilityNodeInfoCompat node, SpannableStringBuilder builder) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return; // TODO(KM): add getLabeledBy to support lib AccessibilityNodeInfo info = (AccessibilityNodeInfo) node.getInfo(); if (info == null) return; AccessibilityNodeInfo labeledBy = info.getLabeledBy(); if (labeledBy == null) return; AccessibilityNodeInfoCompat labelNode = new AccessibilityNodeInfoCompat(labeledBy); final SpannableStringBuilder labelDescription = new SpannableStringBuilder(); Set<AccessibilityNodeInfoCompat> visitedNodes = new HashSet<>(); appendDescriptionForTree(labelNode, labelDescription, null, null, visitedNodes); AccessibilityNodeInfoUtils.recycleNodes(visitedNodes); if (TextUtils.isEmpty(labelDescription)) { return; } final String labeled = mContext.getString(R.string.template_labeled_item, builder, labelDescription); Spannable spannableLabeledText = StringBuilderUtils.createSpannableFromTextWithTemplate(labeled, builder); // Replace the text of the builder. builder.clear(); builder.append(spannableLabeledText); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); Resources res = context.getResources(); mLauncher = Launcher.getLauncher(context); mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); mApps = new AlphabeticalAppsList(context); mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this); mApps.setAdapter(mAdapter);/*from w w w . j a v a2s.c o m*/ mLayoutManager = mAdapter.getLayoutManager(); mItemDecoration = mAdapter.getItemDecoration(); DeviceProfile grid = mLauncher.getDeviceProfile(); if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) { mRecyclerViewBottomPadding = 0; setPadding(0, 0, 0, 0); } else { mRecyclerViewBottomPadding = res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding); } mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); }
From source file:com.groksolutions.grok.mobile.annotation.AnnotationListFragment.java
/** * Format annotation message footer for list item display * * @param annotation/*from w w w. jav a 2s .c o m*/ * @param showDate * @return */ SpannableStringBuilder formatAnnotationFooter(Annotation annotation, boolean showDate) { int pos, rightPos; Date created = new Date(annotation.getCreated()); // Format text SpannableStringBuilder text = new SpannableStringBuilder(); // <div align="right"> rightPos = pos = text.length(); //<small>6/30/14 3:25 PM - </small> // Show date if different annotation or if created date changed if (showDate) { text.append(_dateFormat.format(created)).append(" "); } text.append(_timeFormat.format(created)).append(" - "); text.setSpan(new RelativeSizeSpan(0.5f), pos, text.length(), 0); // User pos = text.length(); text.append(annotation.getUser()); text.setSpan(new RelativeSizeSpan(1.0f), pos, text.length(), 0); // </div align="right"> text.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_OPPOSITE), rightPos, text.length(), 0); // Attach hidden annotation ID to the text. // This ID is used by the actions attached to the list text.setSpan(new android.text.Annotation("id", annotation.getId()), 0, text.length(), 0); return text; }
From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java
private static final CharSequence obtainVerbatim(String text) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new SpannableStringBuilder().append(text, new TtsSpan.VerbatimBuilder(text).build(), 0); } else {/*from www. j a va 2 s.c o m*/ return text; } }
From source file:com.kncwallet.wallet.ui.HomeFragment.java
@Override public void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); viewBalance = view.findViewById(R.id.wallet_balance); viewBalance.setEnabled(false);/*ww w .j a va 2s .co m*/ viewBalanceBtc = (CurrencyTextView) view.findViewById(R.id.wallet_balance_btc); viewBalanceLocal = (CurrencyTextView) view.findViewById(R.id.wallet_balance_local); viewBalanceLocal.setPrecision(Constants.LOCAL_PRECISION, 0); viewBalanceLocal.setStrikeThru(Constants.TEST); viewBalanceBtc.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { HomeFragment.this.switchBalance(); } }); viewBalanceLocal.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { HomeFragment.this.switchBalance(); } }); viewProgress = (TextView) view.findViewById(R.id.wallet_balance_progress); TextView header = ((TextView) view.findViewById(R.id.header_text)); bitcoinAddressLabel = (TextView) view.findViewById(R.id.bitcoin_address_label); header.setText(R.string.home_heading); //transaction list stuff final ViewPagerTabs pagerTabs = (ViewPagerTabs) view.findViewById(R.id.transactions_pager_tabs); pagerTabs.addTabLabels(R.string.wallet_transactions_fragment_tab_sent, R.string.wallet_transactions_fragment_tab_all, R.string.wallet_transactions_fragment_tab_received); final ViewPager subViewPager = (ViewPager) view.findViewById(R.id.transactions_pager); transactionsListViewPagerAdapter = new TransactionsListViewPagerAdapter(activity); subViewPager.setAdapter(transactionsListViewPagerAdapter); subViewPager.setOnPageChangeListener(pagerTabs); subViewPager.setPageMargin(0); subViewPager.setCurrentItem(1); subViewPager.setPageMarginDrawable(R.color.knc_background_darker); subViewPager.setOffscreenPageLimit(3); pagerTabs.forceRedrawAtPosition(1); bottomLayout = (LinearLayout) view.findViewById(R.id.home_bottom); bottomLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { ((WalletActivity) activity).handleExportKeys(); } }); final SpannableStringBuilder text = new SpannableStringBuilder(); text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup))); text.append("\n"); text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety))); TextView bottomBackupinfo = (TextView) bottomLayout.findViewById(R.id.home_bottom_backup_info); bottomBackupinfo.setText(text); }
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); }// w w w .j a v a2s . com 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.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 ww w . j a v a2 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); } }