-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphView.java
More file actions
37 lines (30 loc) · 1.12 KB
/
GraphView.java
File metadata and controls
37 lines (30 loc) · 1.12 KB
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
package com.redkb.graphviewdemo;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
public class GraphView extends View {
private static final int STROKE_WIDTH_DP = 4;
private final Paint mPaintLine = new Paint();
public GraphView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mPaintLine.setColor(Color.BLUE);
mPaintLine.setStrokeWidth((int) dpToPx(STROKE_WIDTH_DP));
}
@Override
protected void onDraw(Canvas canvas) {
drawAxes(canvas);
super.onDraw(canvas);
}
private void drawAxes(Canvas canvas) {
canvas.drawLine(0, 0, 0, canvas.getHeight(), mPaintLine);
canvas.drawLine(0, canvas.getHeight(), canvas.getWidth(), canvas.getHeight(), mPaintLine);
}
private float dpToPx(float value) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
}
}