public static SpannableStringBuilder formatTimeRemaining(double routeDuration) {
long seconds = (long) routeDuration;
if (seconds < 0) {
throw new IllegalArgumentException("Duration must be greater than zero.");
}
long days = TimeUnit.SECONDS.toDays(seconds);
seconds -= TimeUnit.DAYS.toSeconds(days);
long hours = TimeUnit.SECONDS.toHours(seconds);
seconds -= TimeUnit.HOURS.toSeconds(hours);
long minutes = TimeUnit.SECONDS.toMinutes(seconds);
seconds -= TimeUnit.MINUTES.toSeconds(minutes);
if (seconds >= 30) {
minutes = minutes + 1;
}
List<SpanItem> spanItems = new ArrayList<>();
if (days != 0) {
String dayFormat = days > 1 ? DAYS : DAY;
spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(days)));
spanItems.add(new SpanItem(new RelativeSizeSpan(1f), dayFormat));
}
if (hours != 0) {
spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(hours)));
spanItems.add(new SpanItem(new RelativeSizeSpan(1f), HOUR));
}
if (minutes != 0) {
spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(minutes)));
spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
}
if (days == 0 && hours == 0 && minutes == 0) {
spanItems.add(new SpanItem(new StyleSpan(Typeface.BOLD), String.valueOf(1)));
spanItems.add(new SpanItem(new RelativeSizeSpan(1f), MINUTE));
}
return SpanUtils.combineSpans(spanItems);
}
java类android.graphics.Typeface的实例源码
TimeUtils.java 文件源码
项目:mapbox-navigation-android
阅读 23
收藏 0
点赞 0
评论 0
ElasticCheckButton.java 文件源码
项目:ElasticViews
阅读 24
收藏 0
点赞 0
评论 0
private void setTypeArray(TypedArray typedArray){
GradientDrawable bgShape = (GradientDrawable)view.getBackground();
round = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_round, round);
bgShape.setCornerRadius(round);
color = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_backgroundColor, color);
bgShape.setColor(color);
scale = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_scale, scale);
duration = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_duration, duration);
labelText = typedArray.getString(R.styleable.ElasticCheckButton_checkbutton_labelText);
view.setText(labelText);
labelColor = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelColor, labelColor);
view.setTextColor(labelColor);
labelSize = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelSize, labelSize);
view.setTextSize(labelSize);
labelStyle = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelStyle, labelStyle);
if(labelStyle == 0)
view.setTypeface(null, Typeface.NORMAL);
else if(labelStyle == 1)
view.setTypeface(null, Typeface.BOLD);
else if(labelStyle == 2)
view.setTypeface(null, Typeface.ITALIC);
alpha = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_alpha, alpha);
checked = typedArray.getBoolean(R.styleable.ElasticCheckButton_checkbutton_ischecked, checked);
if(checked) view.setAlpha(alpha);
}
MonthView.java 文件源码
项目:AssistantBySDK
阅读 27
收藏 0
点赞 0
评论 0
/**
* Sets up the text and style properties for painting. Override this if you
* want to use a different paint.
*/
protected void initView() {
mMonthTitlePaint = new Paint();
mMonthTitlePaint.setFakeBoldText(true);
mMonthTitlePaint.setAntiAlias(true);
mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
mMonthTitlePaint.setColor(mDayTextColor);
mMonthTitlePaint.setTextAlign(Align.CENTER);
mMonthTitlePaint.setStyle(Style.FILL);
mSelectedCirclePaint = new Paint();
mSelectedCirclePaint.setFakeBoldText(true);
mSelectedCirclePaint.setAntiAlias(true);
mSelectedCirclePaint.setColor(mTodayNumberColor);
mSelectedCirclePaint.setTextAlign(Align.CENTER);
mSelectedCirclePaint.setStyle(Style.FILL);
mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
mMonthDayLabelPaint = new Paint();
mMonthDayLabelPaint.setAntiAlias(true);
mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
mMonthDayLabelPaint.setColor(mMonthDayTextColor);
// mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(),"Roboto-Medium"));
mMonthDayLabelPaint.setStyle(Style.FILL);
mMonthDayLabelPaint.setTextAlign(Align.CENTER);
mMonthDayLabelPaint.setFakeBoldText(true);
mMonthNumPaint = new Paint();
mMonthNumPaint.setAntiAlias(true);
mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
mMonthNumPaint.setStyle(Style.FILL);
mMonthNumPaint.setTextAlign(Align.CENTER);
mMonthNumPaint.setFakeBoldText(false);
}
TerminalTextViewOverlay.java 文件源码
项目:GitHub
阅读 32
收藏 0
点赞 0
评论 0
public TerminalTextViewOverlay(Context context, TerminalView terminalView) {
super(context);
this.terminalView = terminalView;
clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
setTextColor(Color.TRANSPARENT);
setTypeface(Typeface.MONOSPACE);
setTextIsSelectable(true);
setCustomSelectionActionModeCallback(new TextSelectionActionModeCallback());
}
ExampleActivity.java 文件源码
项目:Alerter
阅读 32
收藏 0
点赞 0
评论 0
private void showAlertWithCustomFont() {
Alerter.create(ExampleActivity.this)
.setTitle("Alert Title")
.setTitleAppearance(R.style.AlertTextAppearance_Title)
.setTitleTypeface(Typeface.createFromAsset(getAssets(), "Pacifico-Regular.ttf"))
.setText("Alert text...")
.setTextAppearance(R.style.AlertTextAppearance_Text)
.setTextTypeface(Typeface.createFromAsset(getAssets(), "ScopeOne-Regular.ttf"))
.show();
}
TimerFragment.java 文件源码
项目:Channelize
阅读 27
收藏 0
点赞 0
评论 0
private void setScreenElements() {
mCircularProgressBar = (HoloCircularProgressBar) view.findViewById(R.id.circular_progressBar);
mTextViewTimer = (TextView)view.findViewById(R.id.text_timer);
mButtonStart = (Button)view.findViewById(R.id.button_start);
mButtonPause = (Button)view.findViewById(R.id.button_pause);
mButtonResume = (Button)view.findViewById(R.id.button_resume);
mButtonStop = (Button)view.findViewById(R.id.button_stop);
if (mTextViewTimer != null) {
mTextViewTimer.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Light.ttf"));
}
updateTimerLabel((int) TimeUnit.MINUTES.toSeconds(timerDuration));
}
AndroidCss.java 文件源码
项目:nativehtml
阅读 21
收藏 0
点赞 0
评论 0
static int getTextStyle(CssStyleDeclaration style) {
int flags = 0;
if (style.get(CssProperty.FONT_WEIGHT, CssUnit.NUMBER) > 600) {
flags |= Typeface.BOLD;
}
if (style.getEnum(CssProperty.FONT_STYLE) == CssEnum.ITALIC) {
flags |= Typeface.ITALIC;
}
return flags;
}
EasyRVHolder.java 文件源码
项目:BookReader-master
阅读 36
收藏 0
点赞 0
评论 0
@Override
public EasyRVHolder setTypeface(int viewId, Typeface typeface) {
TextView view = getView(viewId);
view.setTypeface(typeface);
view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
return this;
}
CCPTabView.java 文件源码
项目:browser
阅读 22
收藏 0
点赞 0
评论 0
/**
*
*/
private void init() {
int dip2px = DensityUtil.dip2px(2.0F);
padding = getResources().getDimensionPixelSize(R.dimen.SmallestPadding);
TextView description = new TextView(getContext());
description.setSingleLine();
description.setEllipsize(TextUtils.TruncateAt.END);
description.setTextColor(getResources().getColor(R.color.ccp_green));
description.setTextSize(TypedValue.COMPLEX_UNIT_PX , getResources().getDimensionPixelSize(R.dimen.HintTextSize) + dip2px);
description.setText(R.string.tab_view_name);
description.setTypeface(null, Typeface.NORMAL);
addView(mTabDescription = description);
ImageView descriptionImage = new ImageView(getContext());
descriptionImage.setImageResource(R.drawable.unread_dot);
descriptionImage.setVisibility(View.INVISIBLE);
addView(mTabImage = descriptionImage);
TextView tips = new TextView(getContext());
tips.setTextColor(getResources().getColor(android.R.color.white));
tips.setTextSize(0, getResources().getDimensionPixelSize(R.dimen.SmallestTextSize));
tips.setBackgroundResource(R.drawable.to_read_tips_onbackbtn);
tips.setGravity(Gravity.CENTER);
tips.setVisibility(View.INVISIBLE);
addView(mTabUnreadTips = tips);
setBackgroundResource(R.drawable.tab_item_bg);
}
HalfPieChartActivity.java 文件源码
项目:GitHub
阅读 28
收藏 0
点赞 0
评论 0
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
return s;
}