List of usage examples for android.support.v4.text BidiFormatter unicodeWrap
public String unicodeWrap(String str)
From source file:com.android.mail.utils.EmptyStateUtils.java
/** * Given an empty folder, set the corresponding text for indicating the empty state. *///from ww w. j a v a 2 s. c o m public static void bindEmptyFolderText(TextView view, Folder folder, Resources res, String searchQuery, BidiFormatter bidiFormatter) { if (folder == null) { view.setText(R.string.empty_folder); } else if (folder.isInbox()) { view.setText(R.string.empty_inbox); } else if (folder.isSearch()) { final String text = res.getString(R.string.empty_search, bidiFormatter.unicodeWrap(searchQuery)); view.setText(text); } else if (folder.isSpam()) { view.setText(R.string.empty_spam_folder); } else if (folder.isTrash()) { view.setText(R.string.empty_trash_folder); } else { view.setText(R.string.empty_folder); } }
From source file:com.keylesspalace.tusky.util.NotificationHelper.java
private static String wrapItemAt(JSONArray array, int index, BidiFormatter bidiFormatter) throws JSONException { return bidiFormatter.unicodeWrap(array.get(index).toString()); }
From source file:com.keylesspalace.tusky.util.NotificationHelper.java
@Nullable private static String titleForType(Context context, Notification notification, BidiFormatter bidiFormatter) { String accountName = bidiFormatter.unicodeWrap(notification.getAccount().getName()); switch (notification.getType()) { case MENTION: return String.format(context.getString(R.string.notification_mention_format), accountName); case FOLLOW://from w ww . ja va 2 s . co m return String.format(context.getString(R.string.notification_follow_format), accountName); case FAVOURITE: return String.format(context.getString(R.string.notification_favourite_format), accountName); case REBLOG: return String.format(context.getString(R.string.notification_reblog_format), accountName); } return null; }
From source file:com.markupartist.sthlmtraveling.utils.DateTimeUtil.java
public static CharSequence routeToTimeDisplay(Context context, Route route) { java.text.DateFormat format = android.text.format.DateFormat.getTimeFormat(context); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); Pair<Date, RealTimeState> departsAt = route.departsAt(true); Pair<Date, RealTimeState> arrivesAt = route.arrivesAt(true); String departsAtStr = format.format(departsAt.first); String arrivesAtStr = format.format(arrivesAt.first); CharSequence displayTime;//from w w w.j av a 2s. c o m if (!DateUtils.isToday(departsAt.first.getTime())) { displayTime = String.format("%s %s %s", bidiFormatter.unicodeWrap(DateUtils.getRelativeTimeSpanString(departsAt.first.getTime(), System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS).toString()), bidiFormatter.unicodeWrap(departsAtStr), bidiFormatter.unicodeWrap(arrivesAtStr)); } else { displayTime = String.format("%s %s", bidiFormatter.unicodeWrap(departsAtStr), bidiFormatter.unicodeWrap(arrivesAtStr)); } ForegroundColorSpan spanDepartsAt = new ForegroundColorSpan( ContextCompat.getColor(context, ViewHelper.getTextColorByRealtimeState(departsAt.second))); Pattern patternDepartsAt = Pattern.compile(departsAtStr); displayTime = SpanUtils.createSpannable(displayTime, patternDepartsAt, spanDepartsAt); ForegroundColorSpan spanArrivessAt = new ForegroundColorSpan( ContextCompat.getColor(context, ViewHelper.getTextColorByRealtimeState(arrivesAt.second))); Pattern patternArrivesAt = Pattern.compile(arrivesAtStr); displayTime = SpanUtils.createSpannable(displayTime, patternArrivesAt, spanArrivessAt); return displayTime; }
From source file:com.android.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;/*from w w w .j av a2 s . com*/ final BidiFormatter bidiFormatter = getBidiFormatter(); final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject); final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject); sb.append('\u0020'); final Settings settings = account.settings; final int start = sb.length(); if (settings.importanceMarkersEnabled && conv.isImportant()) { sb.append(".\u0020"); sb.setSpan(new ReplacementSpan() { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return mImportanceMarkerDrawable.getIntrinsicWidth(); } @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int baseline, int bottom, Paint paint) { canvas.save(); final int transY = baseline + mChipVerticalOffset - mImportanceMarkerDrawable.getIntrinsicHeight(); canvas.translate(x, transY); mImportanceMarkerDrawable.draw(canvas); canvas.restore(); } }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */); mFolderDisplayer.constructFolderChips(sb); final int end = sb.length(); sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(sb); setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.android.mail.ui.FolderItemView.java
public void bind(final Folder folder, final DropHandler dropHandler, final BidiFormatter bidiFormatter) { mFolder = folder;//from w w w. j a v a 2 s . co m mDropHandler = dropHandler; mFolderTextView.setText(bidiFormatter.unicodeWrap(folder.name)); mFolderParentIcon.setVisibility(mFolder.hasChildren ? View.VISIBLE : View.GONE); if (mFolder.isInbox() && mFolder.unseenCount > 0) { mUnreadCountTextView.setVisibility(View.GONE); setUnseenCount(mFolder.getBackgroundColor(Color.BLACK), mFolder.unseenCount); } else { mUnseenCountTextView.setVisibility(View.GONE); setUnreadCount(Utils.getFolderUnreadDisplayCount(mFolder)); } }
From source file:com.tct.mail.ui.ConversationListEmptyView.java
/** * Initializes the empty view to use the proper icon and text * based on the type of folder that will be visible. *///from w w w.ja va 2 s .c om public void setupEmptyView(final Folder folder, final String searchQuery, final BidiFormatter bidiFormatter) { if (folder == null) { setupIconAndText(R.drawable.empty_folders, R.string.empty_folder); return; } if (folder.isInbox()) { setupIconAndText(R.drawable.empty_inbox, R.string.empty_inbox); } else if (folder.isSearch()) { setupIconAndText(R.drawable.empty_search, R.string.empty_search, bidiFormatter.unicodeWrap(searchQuery)); } else if (folder.isSpam()) { setupIconAndText(R.drawable.empty_spam, R.string.empty_spam_folder); } else if (folder.isTrash()) { setupIconAndText(R.drawable.empty_trash, R.string.empty_trash_folder); } else { setupIconAndText(R.drawable.empty_folders, R.string.empty_folder); } }
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 w w w. j a v a 2s . com } // 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.tct.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;/* w w w.ja va2 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: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 {//from w w w. j a v a2s .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); }