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 = (int) Math.ceil(mTextPaint.measureText(mContactName, 0, mContactName.length())); 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); }