1 package com
.owncloud
.android
.ui
;
3 import android
.graphics
.Canvas
;
4 import android
.graphics
.Color
;
5 import android
.graphics
.ColorFilter
;
6 import android
.graphics
.Paint
;
7 import android
.graphics
.PixelFormat
;
8 import android
.graphics
.Rect
;
9 import android
.graphics
.drawable
.Drawable
;
12 * Created by tobi on 24.05.15.
14 public class TextDrawable
extends Drawable
{
16 private final String text
;
17 private final Integer color
;
18 private final Float size
;
20 public TextDrawable(String text
, int r
, int g
, int b
, float size
) {
23 this.color
= Color
.rgb(r
, g
, b
);
26 // this.paint = new Paint();
27 //// paint.setColor(Color.BLACK);
28 //// paint.setTextSize(18f);
29 //// paint.setAntiAlias(true);
30 //// paint.setFakeBoldText(true);
32 //// paint.setARGB(255, r, g, b);
33 //// paint.setStyle(Paint.Style.FILL);
34 //// paint.setTextAlign(Paint.Align.CENTER);
37 // paint.setColor(Color.BLACK);
38 // paint.setTextSize(22f);
39 // paint.setAntiAlias(true);
40 // paint.setFakeBoldText(true);
41 // paint.setTextAlign(Paint.Align.CENTER);
45 public void draw(Canvas canvas
) {
46 // TODO Paint in Constructor
47 Paint bg
= new Paint();
48 bg
.setStyle(Paint
.Style
.FILL
);
50 canvas
.drawRect(0,-20,20,40,bg
);
52 Paint paint
= new Paint();
53 paint
.setColor(Color
.WHITE
);
54 paint
.setTextSize(20);
55 paint
.setAntiAlias(true
);
56 paint
.setFakeBoldText(true
);
57 // paint.setTextAlign(Paint.Align.CENTER);
59 Rect bounds
= new Rect();
60 paint
.getTextBounds(text
, 0, text
.length(), bounds
);
61 int x
= (canvas
.getWidth() / 2) - (bounds
.width() / 2);
62 int y
= (canvas
.getHeight() / 2) - (bounds
.height() / 2);
64 // canvas.drawText(text, x, y, paint);
65 canvas
.drawText(text
, 4, 6, paint
);
69 public void setAlpha(int alpha
) {
70 // paint.setAlpha(alpha);
74 public void setColorFilter(ColorFilter cf
) {
75 // paint.setColorFilter(cf);
79 public int getOpacity() {
80 return PixelFormat
.TRANSLUCENT
;