LineRadarRenderer.java
2.72 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* Created by Philipp Jahoda on 25/01/16.
*/
public abstract class LineRadarRenderer extends LineScatterCandleRadarRenderer {
public LineRadarRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(animator, viewPortHandler);
}
/**
* Draws the provided path in filled mode with the provided drawable.
*
* @param c
* @param filledPath
* @param drawable
*/
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
if (clipPathSupported()) {
int save = c.save();
c.clipPath(filledPath);
drawable.setBounds((int) mViewPortHandler.contentLeft(),
(int) mViewPortHandler.contentTop(),
(int) mViewPortHandler.contentRight(),
(int) mViewPortHandler.contentBottom());
drawable.draw(c);
c.restoreToCount(save);
} else {
throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
"this code was run on API level " + Utils.getSDKInt() + ".");
}
}
/**
* Draws the provided path in filled mode with the provided color and alpha.
* Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this.
*
* @param c
* @param filledPath
* @param fillColor
* @param fillAlpha
*/
protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) {
int color = (fillAlpha << 24) | (fillColor & 0xffffff);
if (clipPathSupported()) {
int save = c.save();
c.clipPath(filledPath);
c.drawColor(color);
c.restoreToCount(save);
} else {
// save
Paint.Style previous = mRenderPaint.getStyle();
int previousColor = mRenderPaint.getColor();
// set
mRenderPaint.setStyle(Paint.Style.FILL);
mRenderPaint.setColor(color);
c.drawPath(filledPath, mRenderPaint);
// restore
mRenderPaint.setColor(previousColor);
mRenderPaint.setStyle(previous);
}
}
/**
* Clip path with hardware acceleration only working properly on API level 18 and above.
*
* @return
*/
private boolean clipPathSupported() {
return Utils.getSDKInt() >= 18;
}
}