-
-
Save virendersran01/c5f46bbec2afbc89bd0b921894b838b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Create placeholder drawable | |
* */ | |
private void setDrawable() { | |
drawable = new Drawable() { | |
@Override | |
public void draw(@NonNull Canvas canvas) { | |
int centerX = Math.round(canvas.getWidth() * 0.5f); | |
int centerY = Math.round(canvas.getHeight() * 0.5f); | |
/* | |
* To draw text | |
* */ | |
if (text != null) { | |
float textWidth = textPaint.measureText(text) * 0.5f; | |
float textBaseLineHeight = textPaint.getFontMetrics().ascent * -0.4f; | |
/* | |
* Draw the background color before drawing initials text | |
* */ | |
if (shape == RECTANGLE) { | |
canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint); | |
} else { | |
canvas.drawCircle(centerX, | |
centerY, | |
Math.max(canvas.getHeight() / 2, textWidth / 2), | |
paint); | |
} | |
/* | |
* Draw the text above the background color | |
* */ | |
canvas.drawText(text, centerX - textWidth, centerY + textBaseLineHeight, textPaint); | |
} | |
} | |
@Override | |
public void setAlpha(int alpha) { | |
} | |
@Override | |
public void setColorFilter(ColorFilter colorFilter) { | |
} | |
@Override | |
public int getOpacity() { | |
return PixelFormat.UNKNOWN; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment