Skip to content

Commit 58d6a07

Browse files
committed
* Many new styleable attrs
* Updated demo app with new styleables. * Uprev to 0.9.3
1 parent 7191887 commit 58d6a07

32 files changed

Lines changed: 752 additions & 375 deletions

DemoApp/src/main/java/com/androidplot/demos/BarPlotExampleActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void onCreate(Bundle savedInstanceState)
101101
selectionFormatter = new MyBarFormatter(Color.YELLOW, Color.WHITE);
102102

103103
selectionWidget = new TextLabelWidget(plot.getLayoutManager(), NO_SELECTION_TXT,
104-
new SizeMetrics(
104+
new Size(
105105
PixelUtils.dpToPix(100), SizeLayoutType.ABSOLUTE,
106106
PixelUtils.dpToPix(100), SizeLayoutType.ABSOLUTE),
107107
TextOrientationType.HORIZONTAL);

DemoApp/src/main/java/com/androidplot/demos/DualScaleXYPlotExampleActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.androidplot.ui.AnchorPosition;
3131
import com.androidplot.ui.DynamicTableModel;
3232
import com.androidplot.ui.SizeLayoutType;
33-
import com.androidplot.ui.SizeMetrics;
33+
import com.androidplot.ui.Size;
3434
import com.androidplot.xy.LineAndPointFormatter;
3535
import com.androidplot.xy.PointLabelFormatter;
3636
import com.androidplot.xy.SimpleXYSeries;
@@ -67,7 +67,7 @@ public void onCreate(Bundle savedInstanceState) {
6767

6868
final float f26 = PixelUtils.dpToPix(26);
6969
final float f10 = PixelUtils.dpToPix(10);
70-
final SizeMetrics sm = new SizeMetrics(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL);
70+
final Size sm = new Size(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL);
7171

7272
plot1 = (XYPlot) findViewById(R.id.mySimpleXYPlot_L);
7373
plot2 = (XYPlot) findViewById(R.id.mySimpleXYPlot_R);
@@ -159,10 +159,10 @@ public void onCreate(Bundle savedInstanceState) {
159159
* Setup and Position the LEFT Legend
160160
*/
161161
XYLegendWidget legendWidget_LEFT = plot1.getLegendWidget();
162-
legendWidget_LEFT.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
162+
legendWidget_LEFT.setSize(new Size(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
163163
legendWidget_LEFT.setPadding(1, 1, 1, 1);
164164
legendWidget_LEFT.setTableModel(new DynamicTableModel(1, 3));
165-
legendWidget_LEFT.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
165+
legendWidget_LEFT.setIconSize(new Size(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
166166
legendWidget_LEFT.getTextPaint().setTextSize(PixelUtils.dpToPix(9));
167167
legendWidget_LEFT.position(PixelUtils.dpToPix(30), XLayoutStyle.ABSOLUTE_FROM_LEFT, f10 + 2, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.LEFT_TOP);
168168

@@ -171,10 +171,10 @@ public void onCreate(Bundle savedInstanceState) {
171171
* Setup and Position the RIGHT Legend
172172
*/
173173
XYLegendWidget legendWidget_RIGHT = plot2.getLegendWidget();
174-
legendWidget_RIGHT.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
174+
legendWidget_RIGHT.setSize(new Size(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
175175
legendWidget_RIGHT.setPadding(1, 1, 1, 1);
176176
legendWidget_RIGHT.setTableModel(new DynamicTableModel(1, 3));
177-
legendWidget_RIGHT.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
177+
legendWidget_RIGHT.setIconSize(new Size(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
178178
legendWidget_RIGHT.getTextPaint().setTextSize(PixelUtils.dpToPix(9));
179179
legendWidget_RIGHT.getTextPaint().setTextAlign(Align.RIGHT);
180180
legendWidget_RIGHT.setMarginLeft(185);

DemoApp/src/main/java/com/androidplot/demos/ListViewActivity.java

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import android.widget.ArrayAdapter;
2727
import android.widget.ListView;
2828
import com.androidplot.Plot;
29-
import com.androidplot.xy.XYSeries;
30-
import com.androidplot.xy.LineAndPointFormatter;
31-
import com.androidplot.xy.SimpleXYSeries;
32-
import com.androidplot.xy.XYPlot;
29+
import com.androidplot.Series;
30+
import com.androidplot.ui.SeriesAndFormatter;
31+
import com.androidplot.util.PixelUtils;
32+
import com.androidplot.xy.*;
3333

3434
import java.util.ArrayList;
3535
import java.util.List;
@@ -41,21 +41,64 @@ public class ListViewActivity extends Activity {
4141
private static final int NUM_SERIES_PER_PLOT = 5;
4242
private ListView lv;
4343

44+
private List<List<SeriesAndFormatter<XYSeries, LineAndPointFormatter>>> seriesData = new ArrayList<>(NUM_PLOTS);
45+
4446
public void onCreate(Bundle savedInstanceState) {
4547
super.onCreate(savedInstanceState);
4648
setContentView(R.layout.listview_example);
49+
PixelUtils.init(this);
50+
generateData();
4751
lv = (ListView) findViewById(R.id.listView1);
4852
lv.setAdapter(new MyViewAdapter(getApplicationContext(), R.layout.listview_example_item, null));
4953
}
5054

55+
protected void generateData() {
56+
Random generator = new Random();
57+
for(int i = 0; i < NUM_PLOTS; i++) {
58+
List<SeriesAndFormatter<XYSeries, LineAndPointFormatter>> seriesList
59+
= new ArrayList<>(NUM_SERIES_PER_PLOT);
60+
61+
for (int k = 0; k < NUM_SERIES_PER_PLOT; k++) {
62+
ArrayList<Number> nums = new ArrayList<>();
63+
for (int j = 0; j < NUM_POINTS_PER_SERIES; j++) {
64+
nums.add(generator.nextFloat());
65+
}
66+
67+
double rl = Math.random();
68+
double gl = Math.random();
69+
double bl = Math.random();
70+
71+
double rp = Math.random();
72+
double gp = Math.random();
73+
double bp = Math.random();
74+
75+
LineAndPointFormatter lpf = new LineAndPointFormatter(
76+
Color.rgb(new Double(rl * 255).intValue(),
77+
new Double(gl * 255).intValue(), new Double(bl * 255).intValue()),
78+
Color.rgb(new Double(rp * 255).intValue(),
79+
new Double(gp * 255).intValue(), new Double(bp * 255).intValue()),
80+
null, null);
81+
82+
// for fun, configure interpolation on the formatter:
83+
lpf.setInterpolationParams(
84+
new CatmullRomInterpolator.Params(20, CatmullRomInterpolator.Type.Centripetal));
85+
86+
seriesList.add(new SeriesAndFormatter<XYSeries, LineAndPointFormatter>(
87+
new SimpleXYSeries(nums, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "S" + k),
88+
lpf));
89+
}
90+
seriesData.add(seriesList);
91+
}
92+
}
93+
5194
class MyViewAdapter extends ArrayAdapter<View> {
5295
public MyViewAdapter(Context context, int resId, List<View> views) {
5396
super(context, resId, views);
5497
}
5598

5699
@Override
57100
public int getCount() {
58-
return 5;
101+
return NUM_PLOTS;
59102
}
60103

61104
@Override
@@ -68,29 +111,12 @@ public View getView(int pos, View convertView, ViewGroup parent) {
68111
}
69112

70113
Plot p = (XYPlot) v.findViewById(R.id.xyplot);
71-
Random generator = new Random();
72-
114+
p.clear();
73115
p.setTitle("plot" + pos);
74116

75-
for (int k = 0; k < NUM_SERIES_PER_PLOT; k++) {
76-
ArrayList<Number> nums = new ArrayList<Number>();
77-
for (int j = 0; j < NUM_POINTS_PER_SERIES; j++) {
78-
nums.add(generator.nextFloat());
79-
}
80-
81-
double rl = Math.random();
82-
double gl = Math.random();
83-
double bl = Math.random();
84-
85-
double rp = Math.random();
86-
double gp = Math.random();
87-
double bp = Math.random();
88-
89-
XYSeries series = new SimpleXYSeries(nums, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "S" + k);
90-
p.addSeries(series, new LineAndPointFormatter(
91-
Color.rgb(new Double(rl * 255).intValue(), new Double(gl * 255).intValue(), new Double(bl * 255).intValue()),
92-
Color.rgb(new Double(rp * 255).intValue(), new Double(gp * 255).intValue(), new Double(bp * 255).intValue()),
93-
null, null));
117+
List<SeriesAndFormatter<XYSeries, LineAndPointFormatter>> thisSeriesList = seriesData.get(pos);
118+
for(SeriesAndFormatter<XYSeries, LineAndPointFormatter> sf : thisSeriesList) {
119+
p.addSeries(sf.getSeries(), sf.getFormatter());
94120
}
95121
p.redraw();
96122
return v;

DemoApp/src/main/java/com/androidplot/demos/XYRegionExampleActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ public Number parse(String string, ParsePosition position) {
246246

247247
// adjust the legend size so there is enough room
248248
// to draw the new legend grid:
249-
//plot.getLegendWidget().getHeightMetric().setLayoutType(SizeLayoutType.ABSOLUTE);
250-
//plot.getLegendWidget().getWidthMetric().setLayoutType(SizeLayoutType.ABSOLUTE);
249+
//plot.getLegendWidget().getHeight().setLayoutType(SizeLayoutType.ABSOLUTE);
250+
//plot.getLegendWidget().getWidth().setLayoutType(SizeLayoutType.ABSOLUTE);
251251
//plot.getLegendWidget().setSize(
252252
// new SizeMetrics(70, SizeLayoutType.ABSOLUTE, 80, SizeLayoutType.ABSOLUTE));
253253

DemoApp/src/main/res/layout/bar_plot_example.xml

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,49 @@
1616
-->
1717

1818
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:ap="http://schemas.android.com/apk/res-auto"
1920
style="@style/sample_activity"
2021
android:orientation="vertical">
2122

2223
<com.androidplot.xy.XYPlot
2324
android:id="@+id/mySimpleXYPlot"
2425
android:layout_width="fill_parent"
2526
android:layout_height="fill_parent"
26-
androidPlot.title="Growth"
27-
androidPlot.domainLabel="Month"
28-
androidPlot.rangeLabel="Revenue (millions)"
29-
androidPlot.titleWidget.labelPaint.textSize="@dimen/title_font_size"
30-
androidPlot.domainLabelWidget.labelPaint.textSize="@dimen/domain_label_font_size"
31-
androidPlot.rangeLabelWidget.labelPaint.textSize="@dimen/range_label_font_size"
32-
androidPlot.graphWidget.marginTop="20dp"
33-
androidPlot.graphWidget.marginLeft="15dp"
34-
androidPlot.graphWidget.marginBottom="25dp"
35-
androidPlot.graphWidget.marginRight="10dp"
36-
androidPlot.graphWidget.gridBackgroundPaint.color="#000000"
37-
androidPlot.graphWidget.domainGridLinePaint.alpha="0"
38-
androidPlot.graphWidget.domainOriginLinePaint.alpha="0"
39-
androidPlot.graphWidget.rangeLabelPaint.textSize="@dimen/range_tick_label_font_size"
40-
androidPlot.graphWidget.rangeOriginLabelPaint.textSize="@dimen/range_tick_label_font_size"
41-
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
42-
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
43-
androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
44-
androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
45-
androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
46-
androidPlot.legendWidget.heightMetric.value="25dp"
47-
androidPlot.legendWidget.positionMetrics.anchor="right_bottom"
48-
android:layout_weight="1"
49-
androidPlot.graphWidget.gridLinePaint.color="#000000"/>
27+
ap:backgroundColor="#FFFFFF"
28+
ap:label="Growth"
29+
ap:labelTextSize="@dimen/title_font_size"
30+
ap:labelTextColor="#000000"
31+
ap:domainLabel="Month"
32+
ap:rangeLabel="Revenue (millions)"
33+
ap:domainLabelTextColor="#000000"
34+
ap:rangeLabelTextColor="#000000"
35+
ap:rangeLabelTextSize="@dimen/range_label_font_size"
36+
ap:domainLabelTextSize="@dimen/domain_label_font_size"
37+
ap:rangeTickLabelTextColor="#000000"
38+
ap:domainTickLabelTextColor="#000000"
39+
ap:graphDomainLineColor="#000000"
40+
ap:graphRangeLineColor="#000000"
41+
ap:graphMarginTop="20dp"
42+
ap:graphMarginLeft="15dp"
43+
ap:graphMarginBottom="25dp"
44+
ap:graphMarginRight="10dp"
45+
ap:graphBackgroundColor="#FFFFFF"
46+
ap:gridBackgroundColor="#FFFFFF"
47+
ap:rangeOriginTickLabelTextSize="@dimen/range_tick_label_font_size"
48+
ap:domainOriginTickLabelTextSize="@dimen/domain_tick_label_font_size"
49+
ap:legendTextSize="@dimen/legend_text_font_size"
50+
ap:legendTextColor="#000000"
51+
ap:legendIconHeightSizeLayoutType="absolute"
52+
ap:legendIconHeight="10dp"
53+
ap:legendIconWidthSizeLayoutType="absolute"
54+
ap:legendIconWidth="10dp"
55+
ap:legendHeightSizeLayoutType="absolute"
56+
ap:legendHeight="30dp"
57+
ap:legendWidthSizeLayoutType="absolute"
58+
ap:legendWidth="200dp"
59+
ap:legendAnchorPosition="right_bottom"
60+
61+
android:layout_weight="1"/>
5062

5163
<LinearLayout
5264
android:layout_height="wrap_content"

DemoApp/src/main/res/layout/dynamicxyplot_example.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
3939
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
4040
androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
41-
androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
42-
androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
43-
androidPlot.legendWidget.heightMetric.value="25dp"
41+
androidPlot.legendWidget.iconSizeMetrics.height.value="15dp"
42+
androidPlot.legendWidget.iconSizeMetrics.width.value="15dp"
43+
androidPlot.legendWidget.height.value="25dp"
4444
androidPlot.legendWidget.positionMetrics.anchor="right_bottom"/>
4545

4646
</LinearLayout>

DemoApp/src/main/res/layout/listview_example.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<LinearLayout android:id="@+id/LinearLayout01"
33
android:layout_width="fill_parent"
44
android:layout_height="fill_parent"
5+
android:background="#000000"
56
xmlns:android="http://schemas.android.com/apk/res/android">
67
<ListView android:id="@+id/listView1"
78
android:layout_width="fill_parent"

DemoApp/src/main/res/layout/listview_example_item.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,32 @@
1717
-->
1818

1919
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:ap="http://schemas.android.com/apk/res-auto"
2021
android:layout_width="fill_parent"
2122
android:layout_height="fill_parent">
2223
<com.androidplot.xy.XYPlot
2324
android:id="@+id/xyplot"
2425
android:layout_width="fill_parent"
2526
android:layout_height="250dp"
26-
title="an xy plot"/>
27+
ap:backgroundColor="#000000"
28+
ap:graphBackgroundColor="#000000"
29+
ap:label="an xy plot"
30+
ap:labelTextSize="@dimen/title_font_size"
31+
ap:borderColor="#000000"
32+
ap:legendTextSize="15sp"
33+
ap:legendTextColor="#FFFFFF"
34+
ap:legendIconHeightSizeLayoutType="absolute"
35+
ap:legendIconHeight="10dp"
36+
ap:legendIconWidthSizeLayoutType="absolute"
37+
ap:legendIconWidth="10dp"
38+
ap:legendHeightSizeLayoutType="absolute"
39+
ap:legendHeight="30dp"
40+
ap:legendWidthSizeLayoutType="absolute"
41+
ap:legendWidth="200dp"
42+
ap:legendAnchorPosition="right_bottom"
43+
ap:graphMarginTop="20dp"
44+
ap:graphMarginLeft="15dp"
45+
ap:graphMarginBottom="25dp"
46+
ap:graphMarginRight="10dp"/>
2747

2848
</LinearLayout>

DemoApp/src/main/res/layout/orientation_sensor_example.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
4141
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
4242
androidPlot.legendWidget.textPaint.textSize="10dp"
43-
androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
44-
androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
45-
androidPlot.legendWidget.heightMetric.value="25dp"
43+
androidPlot.legendWidget.iconSizeMetrics.height.value="15dp"
44+
androidPlot.legendWidget.iconSizeMetrics.width.value="15dp"
45+
androidPlot.legendWidget.height.value="25dp"
4646
/>
4747
<com.androidplot.xy.XYPlot
4848
android:id="@+id/aprHistoryPlot"
@@ -73,9 +73,9 @@
7373
androidPlot.graphWidget.domainLabelPaint.textSize="@dimen/domain_tick_label_font_size"
7474
androidPlot.graphWidget.domainOriginLabelPaint.textSize="@dimen/domain_tick_label_font_size"
7575
androidPlot.legendWidget.textPaint.textSize="@dimen/legend_text_font_size"
76-
androidPlot.legendWidget.iconSizeMetrics.heightMetric.value="15dp"
77-
androidPlot.legendWidget.iconSizeMetrics.widthMetric.value="15dp"
78-
androidPlot.legendWidget.heightMetric.value="25dp"
76+
androidPlot.legendWidget.iconSizeMetrics.height.value="15dp"
77+
androidPlot.legendWidget.iconSizeMetrics.width.value="15dp"
78+
androidPlot.legendWidget.height.value="25dp"
7979
/>
8080

8181
</LinearLayout>

DemoApp/src/main/res/layout/simple_xy_plot_example.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
android:id="@+id/mySimpleXYPlot"
2424
android:layout_width="fill_parent"
2525
android:layout_height="fill_parent"
26-
ap:plotLabel="A Simple XY Plot"
26+
ap:label="A Simple XY Plot"
2727
ap:rangeLabel="range"
2828
ap:domainLabel="domain"
29-
ap:plotLabelTextSize="@dimen/title_font_size"
29+
ap:labelTextSize="@dimen/title_font_size"
3030
ap:rangeLabelTextSize="@dimen/range_label_font_size"
3131
ap:domainLabelTextSize="@dimen/domain_label_font_size"
3232
ap:graphMarginTop="20dp"
3333
ap:graphMarginBottom="25dp"
3434
ap:graphMarginLeft="15dp"
3535
ap:graphMarginRight="10dp"
36-
ap:graphRangeTickLabelTextSize="@dimen/range_tick_label_font_size"
37-
ap:graphRangeOriginTickLabelTextSize="@dimen/range_tick_label_font_size"
38-
ap:graphDomainTickLabelTextSize="@dimen/domain_tick_label_font_size"
39-
ap:graphDomainOriginTickLabelTextSize="@dimen/domain_tick_label_font_size"
36+
ap:rangeTickLabelTextSize="@dimen/range_tick_label_font_size"
37+
ap:rangeOriginTickLabelTextSize="@dimen/range_tick_label_font_size"
38+
ap:domainTickLabelTextSize="@dimen/domain_tick_label_font_size"
39+
ap:domainOriginTickLabelTextSize="@dimen/domain_tick_label_font_size"
4040
ap:legendTextSize="@dimen/legend_text_font_size"
4141
ap:legendIconHeight="15dp"
4242
ap:legendIconWidth="15dp"
43-
ap:legendHeight="25dp"
43+
ap:legendHeight="25"
4444
ap:legendAnchorPosition="right_bottom"/>
4545
</LinearLayout>

0 commit comments

Comments
 (0)