import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageButton;
private static int mTextSize = 24;
private static int mTextPadding = 20;
private static Paint gPaint = new Paint();
+ private static Path gPath = new Path();
+ private static int mTrianglePadding = 2;
+ private static int mTriangleSize = 30;
+
private Context mContext = null;
public static void setTextSize(int value) {
mTextPadding = value;
}
+ public static void setTrianglePadding(int value) {
+ mTrianglePadding = value;
+ }
+
+ public static void setTriangleSize(int value) {
+ mTriangleSize = value;
+ }
+
public void setText(String text) {
mText = text;
invalidate();
@Override
public void onDraw(Canvas canvas) {
- gPaint.setARGB(255, 255, 255, 255);
+ gPaint.setARGB(96, 255, 255, 255);
gPaint.setStrokeWidth(2);
gPaint.setStyle(Paint.Style.STROKE);
- canvas.drawRect(mTextPadding, mTextPadding, getWidth() - mTextPadding,
- getHeight() - mTextPadding, gPaint);
+ int w = getWidth();
+ int h = getHeight();
+ canvas.drawRect(mTextPadding, mTextPadding, w - mTextPadding,
+ h - mTextPadding, gPaint);
+ gPath.reset();
+ gPath.moveTo(w - mTextPadding - mTrianglePadding - mTriangleSize,
+ h - mTextPadding - mTrianglePadding);
+ gPath.lineTo(w - mTextPadding - mTrianglePadding,
+ h - mTextPadding - mTrianglePadding - mTriangleSize);
+ gPath.lineTo(w - mTextPadding - mTrianglePadding,
+ h - mTextPadding - mTrianglePadding);
+ gPath.close();
+ gPaint.setARGB(128, 255, 255, 255);
+ gPaint.setStrokeWidth(1);
+ gPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ canvas.drawPath(gPath, gPaint);
if (mText != null) {
gPaint.reset();
gPaint.setARGB(255, 255, 255, 255);
float textWidth = gPaint.measureText(mText);
Rect bounds = new Rect();
gPaint.getTextBounds(mText, 0, mText.length(), bounds);
- int x = (int) ((getWidth() - textWidth) / 2);
- int y = (getHeight() + bounds.height()) / 2;
+ int x = (int) ((w - textWidth) / 2);
+ int y = (h + bounds.height()) / 2;
canvas.drawText(mText, x, y, gPaint);
}