android.text.BoringLayout Java Examples
The following examples show how to use
android.text.BoringLayout.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContactChipDrawable.java From MDPreference with Apache License 2.0 | 6 votes |
public ContactChipDrawable(int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(textColor); mPaint.setTypeface(typeface); mPaint.setTextSize(textSize); mTextPaint = new TextPaint(mPaint); mMetrics = new BoringLayout.Metrics(); Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt(); mMetrics.ascent = temp.ascent; mMetrics.bottom = temp.bottom; mMetrics.descent = temp.descent; mMetrics.top = temp.top; mMetrics.leading = temp.leading; mRect = new RectF(); mMatrix = new Matrix(); mPaddingLeft = paddingLeft; mPaddingRight = paddingRight; mBackgroundColor = backgroundColor; }
Example #2
Source File: ContactChipDrawable.java From MDPreference with Apache License 2.0 | 6 votes |
private void updateLayout(){ if(mContactName == null) return; Rect bounds = getBounds(); if(bounds.width() == 0 || bounds.height() == 0) return; int outerWidth = Math.max(0, bounds.width() - bounds.height() - mPaddingLeft - mPaddingRight); mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f); if(mBoringLayout == null) mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); else mBoringLayout = mBoringLayout.replaceOrMake(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); }
Example #3
Source File: ContactChipDrawable.java From material with Apache License 2.0 | 6 votes |
public ContactChipDrawable(int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(textColor); mPaint.setTypeface(typeface); mPaint.setTextSize(textSize); mTextPaint = new TextPaint(mPaint); mMetrics = new BoringLayout.Metrics(); Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt(); mMetrics.ascent = temp.ascent; mMetrics.bottom = temp.bottom; mMetrics.descent = temp.descent; mMetrics.top = temp.top; mMetrics.leading = temp.leading; mRect = new RectF(); mMatrix = new Matrix(); mPaddingLeft = paddingLeft; mPaddingRight = paddingRight; mBackgroundColor = backgroundColor; }
Example #4
Source File: ContactChipDrawable.java From material with Apache License 2.0 | 6 votes |
private void updateLayout(){ if(mContactName == null) return; Rect bounds = getBounds(); if(bounds.width() == 0 || bounds.height() == 0) return; int outerWidth = Math.max(0, bounds.width() - bounds.height() - mPaddingLeft - mPaddingRight); mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f); if(mBoringLayout == null) mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); else mBoringLayout = mBoringLayout.replaceOrMake(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); }
Example #5
Source File: SingleLineTextView.java From FastTextView with Apache License 2.0 | 5 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mLayout == null && !TextUtils.isEmpty(mText)) { BoringLayout.Metrics fm = new BoringLayout.Metrics(); fm.width = (int) Layout.getDesiredWidth(mText, mTextPaint); mLayout = BoringLayout.make(mText, mTextPaint, MeasureSpec.getSize(widthMeasureSpec), TextViewAttrsHelper.getLayoutAlignment(this, getGravity()), mAttrsHelper.mSpacingMultiplier, mAttrsHelper.mSpacingAdd, fm, true); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
Example #6
Source File: ContactChipSpan.java From MDPreference with Apache License 2.0 | 5 votes |
public ContactChipSpan(CharSequence name, int height, int maxWidth, int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(textColor); mPaint.setTypeface(typeface); mPaint.setTextSize(textSize); mTextPaint = new TextPaint(mPaint); mRect = new RectF(); mMatrix = new Matrix(); mContactName = name; mPaddingLeft = paddingLeft; mPaddingRight = paddingRight; mBackgroundColor = backgroundColor; mHeight = height; mWidth = Math.round(Math.min(maxWidth, mPaint.measureText(name, 0, name.length()) + paddingLeft + paddingRight + height)); int outerWidth = Math.max(0, mWidth - mPaddingLeft - mPaddingRight - mHeight); Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt(); BoringLayout.Metrics mMetrics = new BoringLayout.Metrics(); mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f); mMetrics.ascent = temp.ascent; mMetrics.bottom = temp.bottom; mMetrics.descent = temp.descent; mMetrics.top = temp.top; mMetrics.leading = temp.leading; mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); }
Example #7
Source File: WeekDatePicker.java From WeekDatePicker with MIT License | 5 votes |
private static BoringLayout.Metrics toBoringFontMetrics(FontMetricsInt metrics, @Nullable BoringLayout.Metrics fontMetrics) { if (fontMetrics == null) { fontMetrics = new BoringLayout.Metrics(); } fontMetrics.ascent = metrics.ascent; fontMetrics.bottom = metrics.bottom; fontMetrics.descent = metrics.descent; fontMetrics.leading = metrics.leading; fontMetrics.top = metrics.top; return fontMetrics; }
Example #8
Source File: ContactChipSpan.java From material with Apache License 2.0 | 5 votes |
public ContactChipSpan(CharSequence name, int height, int maxWidth, int paddingLeft, int paddingRight, Typeface typeface, int textColor, int textSize, int backgroundColor) { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(textColor); mPaint.setTypeface(typeface); mPaint.setTextSize(textSize); mTextPaint = new TextPaint(mPaint); mRect = new RectF(); mMatrix = new Matrix(); mContactName = name; mPaddingLeft = paddingLeft; mPaddingRight = paddingRight; mBackgroundColor = backgroundColor; mHeight = height; mWidth = Math.round(Math.min(maxWidth, mPaint.measureText(name, 0, name.length()) + paddingLeft + paddingRight + height)); int outerWidth = Math.max(0, mWidth - mPaddingLeft - mPaddingRight - mHeight); Paint.FontMetricsInt temp = mTextPaint.getFontMetricsInt(); BoringLayout.Metrics mMetrics = new BoringLayout.Metrics(); mMetrics.width = Math.round(mTextPaint.measureText(mContactName, 0, mContactName.length()) + 0.5f); mMetrics.ascent = temp.ascent; mMetrics.bottom = temp.bottom; mMetrics.descent = temp.descent; mMetrics.top = temp.top; mMetrics.leading = temp.leading; mBoringLayout = BoringLayout.make(mContactName, mTextPaint, outerWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 1f, mMetrics, true, TextUtils.TruncateAt.END, outerWidth); }
Example #9
Source File: WeekDatePicker.java From WeekDatePicker with MIT License | 4 votes |
private void drawWeek(Canvas canvas, int layoutIndex, int weekOffset) { int saveCount = canvas.save(); int labelHeight = dayLabelLayouts[0].getHeight(); float circleRadius = dayWidth / 3; int centerY = layouts[0].getHeight() / 2; float dateLineOffset = circleRadius - centerY; for (int i = 0; i < 7; i++) { int itemIndex = weekOffset * 7 + i; BoringLayout layout = layouts[layoutIndex + i]; BoringLayout labelLayout = dayLabelLayouts[i]; dayLabelTextPain.setColor(getTextColor(dayLabelTextColor, itemIndex)); labelLayout.draw(canvas); dayTextPaint.setColor(getTextColor(dayTextColor, itemIndex)); int count = canvas.save(); canvas.translate(0, labelHeight + dateLineOffset + labelPadding); if (dayDrawable != null) { dayDrawable.setBounds(backgroundRect); dayDrawable.setState(getItemDrawableState(itemIndex)); dayDrawable.draw(canvas); } if (indicatorDrawable != null && dayIndicators.get(itemIndex - dayDelta, false)) { indicatorDrawable.setBounds(indicatorRect); indicatorDrawable.setState(getItemDrawableState(itemIndex)); indicatorDrawable.draw(canvas); } layout.draw(canvas); canvas.restoreToCount(count); canvas.translate(dayWidth, 0); } canvas.restoreToCount(saveCount); }
Example #10
Source File: WeekDatePicker.java From WeekDatePicker with MIT License | 4 votes |
private void remakeLayout() { if (getWidth() > 0) { LocalDate day = getRelativeFirstDay(-1); for (int i = 0; i < layouts.length; i++) { String dayText = String.valueOf(day.getDayOfMonth()); if (layouts[i] == null) { layouts[i] = BoringLayout.make(dayText, dayTextPaint, dayWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize, dayWidth); } else { layouts[i].replaceOrMake(dayText, dayTextPaint, dayWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize, dayWidth); } day = day.plusDays(1); } DayOfWeek dayOfWeek = firstDayOfWeek; // first index is 1 for (int i = 0; i < dayLabelLayouts.length; i++) { CharSequence name; if (labelNames == null) { name = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault()); } else { int index = dayOfWeek.getValue() - 1; name = labelNames[index]; } if (dayLabelLayouts[i] == null) { dayLabelLayouts[i] = BoringLayout.make(name, dayLabelTextPain, dayWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize, dayWidth); } else { dayLabelLayouts[i].replaceOrMake(name, dayLabelTextPain, dayWidth, Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize, dayWidth); } dayOfWeek = dayOfWeek.plus(1); } } }