Skip to content

Commit 75e7464

Browse files
committed
Merge pull request #49 from junk2005x/master
add support for use in xml layouts.
2 parents 4f29916 + 6fc56e5 commit 75e7464

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/com/jjoe64/graphview/BarGraphView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.graphics.Canvas;
5+
import android.util.AttributeSet;
56

67
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
78

@@ -10,6 +11,10 @@
1011
* @author Muhammad Shahab Hameed
1112
*/
1213
public class BarGraphView extends GraphView {
14+
public BarGraphView(Context context, AttributeSet attrs) {
15+
super(context, attrs);
16+
}
17+
1318
public BarGraphView(Context context, String title) {
1419
super(context, title);
1520
}

src/com/jjoe64/graphview/GraphView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.graphics.Paint;
1111
import android.graphics.Paint.Align;
1212
import android.graphics.RectF;
13+
import android.util.AttributeSet;
1314
import android.view.MotionEvent;
1415
import android.view.View;
1516
import android.widget.LinearLayout;
@@ -253,6 +254,14 @@ protected void onDraw(Canvas canvas) {
253254
private double manualMinYValue;
254255
private GraphViewStyle graphViewStyle;
255256

257+
public GraphView(Context context, AttributeSet attrs) {
258+
this(context, attrs.getAttributeValue(null, "title"));
259+
260+
int width = attrs.getAttributeIntValue("android", "layout_width", LayoutParams.MATCH_PARENT);
261+
int height = attrs.getAttributeIntValue("android", "layout_height", LayoutParams.MATCH_PARENT);
262+
setLayoutParams(new LayoutParams(width, height));
263+
}
264+
256265
/**
257266
*
258267
* @param context

src/com/jjoe64/graphview/LineGraphView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.graphics.Canvas;
55
import android.graphics.Paint;
6+
import android.util.AttributeSet;
67

78
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
89

@@ -18,6 +19,14 @@ public class LineGraphView extends GraphView {
1819
private final Paint paintBackground;
1920
private boolean drawBackground;
2021

22+
public LineGraphView(Context context, AttributeSet attrs) {
23+
super(context, attrs);
24+
25+
paintBackground = new Paint();
26+
paintBackground.setARGB(255, 20, 40, 60);
27+
paintBackground.setStrokeWidth(4);
28+
}
29+
2130
public LineGraphView(Context context, String title) {
2231
super(context, title);
2332

0 commit comments

Comments
 (0)