endian11
2019-09-11 1b112103b7f53225f58a2956ac6ceabf2e212c41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package safeluck.drive.evaluation.customview;
 
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
 
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.util.Utils;
 
/**
 * MyApplication2
 * Created by lzw on 2019/3/18. 11:18:57
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class HouseView extends View {
 
    private Path path = new Path();
    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private float PADDING = Utils.px2dp(40);
    private double a = Math.toRadians(55.0);
    private int color = Color.parseColor("#99C3D1");
    private String text ;
 
 
 
    public HouseView(Context context) {
        this(context,null);
    }
 
    public HouseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArrowView,defStyleAttr,0);
        text = typedArray.getString(R.styleable.ArrowView_text);
        typedArray.recycle();
    }
 
    public HouseView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        path.moveTo(getWidth()/2-PADDING,getHeight()/2-PADDING);
        path.rLineTo(PADDING,0);
        path.rLineTo(PADDING*(float)Math.cos(a),PADDING*(float)Math.sin(a));
        path.rLineTo(-PADDING*(float)Math.cos(a),PADDING*(float)Math.sin(a));
        path.rLineTo(-(PADDING),0);
        path.rLineTo(0,PADDING);
        path.close();
        paint.setColor(color);
        canvas.drawPath(path,paint);
        paint.setColor(Color.parseColor("#1412f6"));
        char[] index =  getKeyChar(text);
        Paint.FontMetrics fm = paint.getFontMetrics();
        float childHeight = PADDING/text.length();
        for (int i = 0; i < text.length(); i++) {
            canvas.drawText(String.valueOf(index[i]),getWidth()/2-PADDING/3, (float) (((i + 0.5) * childHeight) - (fm.ascent + fm.descent) / 2)+PADDING/3, paint);
        }
    }
 
    protected char[] getKeyChar(String str) {
        char[] keys = new char[str.length()];
        for (int i = 0; i < keys.length; i++) {
            keys[i] = str.charAt(i);
        }
        return keys;
    }
}