public class RightUpperCornerText extends TextView {
private Paint mPaint;
private String mCornerText;
private Context mContext;
public RightUpperCornerText(Context context) {
super(context);
init(context);
}
public RightUpperCornerText(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public RightUpperCornerText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
mContext = context;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(Color.WHITE);
float cornerSize = getTextSize() * 0.6f;
if (cornerSize > 50) {
cornerSize = 50;
}
mPaint.setTextSize(cornerSize);
mCornerText = "";
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
String text = (String) getText();
Rect bounds = new Rect();
getPaint().getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(mCornerText, getPaddingLeft() + bounds.right + bounds.left,
(canvas.getHeight() + bounds.top) / 2 + mPaint.measureText(mCornerText),
mPaint);
}
public void setCornertext(String text) {
mCornerText = text;
}
public void setCornertextSize(float size) {
mPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
size, mContext.getResources().getDisplayMetrics()));
invalidate();
}
}