Java Code Examples for android.text.BoringLayout#make()

The following examples show how to use android.text.BoringLayout#make() . 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 vote down vote up
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 2
Source File: ContactChipDrawable.java    From material with Apache License 2.0 6 votes vote down vote up
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: SingleLineTextView.java    From FastTextView with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ContactChipSpan.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
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 5
Source File: ContactChipSpan.java    From material with Apache License 2.0 5 votes vote down vote up
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 6
Source File: WeekDatePicker.java    From WeekDatePicker with MIT License 4 votes vote down vote up
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);

            }

        }

    }