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;
|
}
|
}
|