Skip to content

Instantly share code, notes, and snippets.

@noaht11
Last active September 1, 2016 05:16
Show Gist options
  • Save noaht11/a38559cf96c1c81af188ef972eb9b2c8 to your computer and use it in GitHub Desktop.
Save noaht11/a38559cf96c1c81af188ef972eb9b2c8 to your computer and use it in GitHub Desktop.
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
// Shift everything mLeftMarginPx to the left to create an empty space on the left (creating the margin)
x += mLeftMarginPx;
if (mChipHeight != -1) {
// If we set a chip height, adjust to vertically center chip in the line
// Adding (bottom - top) / 2 shifts the chip down so the top of it will be centered vertically
// Subtracting (mChipHeight / 2) shifts the chip back up so that the center of it will be centered vertically (as desired)
top += ((bottom - top) / 2) - (mChipHeight / 2);
bottom = top + mChipHeight;
}
// Perform actual drawing
drawBackground(canvas, x, top, bottom, paint);
drawText(canvas, x, top, bottom, paint, mTextToDraw);
if (mIcon != null) {
drawIcon(canvas, x, top, bottom, paint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment