Skip to content

Commit 3e0fc2e

Browse files
committed
Improved animations, added nineoldandroids library (special thanks to Jake Wharton).
1 parent b0caebe commit 3e0fc2e

File tree

17 files changed

+146
-59
lines changed

17 files changed

+146
-59
lines changed

MPChartExample/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.xxmassdeveloper.mpchartexample"
4-
android:versionCode="10"
5-
android:versionName="1.1.2" >
4+
android:versionCode="11"
5+
android:versionName="1.2.1" >
66

77
<uses-sdk
88
android:minSdkVersion="9"

MPChartExample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId 'com.xxmassdeveloper.mpchartexample'
88
minSdkVersion 16
99
targetSdkVersion 19
10-
versionCode 10
11-
versionName '1.1.2'
10+
versionCode 11
11+
versionName '1.2.1'
1212

1313
sourceSets {
1414
main {

MPChartExample/res/menu/bar.xml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,53 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
3-
<item android:id="@+id/actionToggleValues" android:title="Toggle Values"></item>
4-
<item android:id="@+id/actionToggleHighlight" android:title="Toggle Highlight"></item>
5-
<item android:id="@+id/actionToggleHighlightArrow" android:title="Toggle Highlight Arrow"></item>
6-
<item android:id="@+id/actionToggle3D" android:title="Toggle 3D"></item>
7-
<item
3+
4+
<item
5+
android:id="@+id/actionToggleValues"
6+
android:title="Toggle Values">
7+
</item>
8+
<item
9+
android:id="@+id/actionToggleHighlight"
10+
android:title="Toggle Highlight">
11+
</item>
12+
<item
13+
android:id="@+id/actionToggleHighlightArrow"
14+
android:title="Toggle Highlight Arrow">
15+
</item>
16+
<item
17+
android:id="@+id/actionToggle3D"
18+
android:title="Toggle 3D">
19+
</item>
20+
<item
821
android:id="@+id/animateX"
922
android:title="Animate X">
1023
</item>
11-
<item
24+
<item
1225
android:id="@+id/animateY"
1326
android:title="Animate Y">
1427
</item>
15-
<item android:id="@+id/animateXY" android:title="Animate XY"></item>
16-
<item android:id="@+id/actionToggleStartzero" android:title="Toggle StartZero"></item>
17-
<item android:id="@+id/actionToggleAdjustXLegend" android:title="Toggle AdjustXLegend"></item>
18-
<item
28+
<item
29+
android:id="@+id/animateXY"
30+
android:title="Animate XY">
31+
</item>
32+
<item
33+
android:id="@+id/actionToggleStartzero"
34+
android:title="Toggle StartZero">
35+
</item>
36+
<item
37+
android:id="@+id/actionToggleAdjustXLegend"
38+
android:title="Toggle AdjustXLegend">
39+
</item>
40+
<item
1941
android:id="@+id/actionToggleFilter"
2042
android:title="Toggle filter">
2143
</item>
22-
<item android:id="@+id/actionSave" android:title="Save to Gallery"></item>
23-
<item
44+
<item
45+
android:id="@+id/actionSave"
46+
android:title="Save to Gallery">
47+
</item>
48+
<item
2449
android:id="@+id/actionTogglePinch"
2550
android:title="Toggle PinchZoom">
2651
</item>
27-
</menu>
52+
53+
</menu>

MPChartExample/res/menu/scatter.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
android:id="@+id/actionToggleAdjustXLegend"
1818
android:title="Toggle AdjustXLegend">
1919
</item>
20-
<item
20+
<item
2121
android:id="@+id/animateX"
2222
android:title="Animate X">
2323
</item>
24-
<item
24+
<item
2525
android:id="@+id/animateY"
2626
android:title="Animate Y">
2727
</item>
28+
<item
29+
android:id="@+id/animateXY"
30+
android:title="Animate XY">
31+
</item>
2832
<item
2933
android:id="@+id/actionToggleFilter"
3034
android:title="Toggle filter">
@@ -33,8 +37,9 @@
3337
android:id="@+id/actionSave"
3438
android:title="Save to Gallery">
3539
</item>
36-
<item
40+
<item
3741
android:id="@+id/actionTogglePinch"
3842
android:title="Toggle PinchZoom">
3943
</item>
44+
4045
</menu>

MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ protected void onCreate(Bundle savedInstanceState) {
8181
// setting data
8282
mSeekBarX.setProgress(10);
8383
mSeekBarY.setProgress(100);
84+
85+
// add a nice and smooth animation
86+
mChart.animateY(2500);
8487

8588
// Legend l = mChart.getLegend();
8689
// l.setPosition(LegendPosition.BELOW_CHART_CENTER);

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
243243

244244
for (int i = 0; i < mSeekBarX.getProgress()+1; i++) {
245245
float mult = (mSeekBarY.getProgress() + 1);
246-
float val = (float) (Math.random() * mult) - 50;
246+
float val = (float) (Math.random() * mult) + 3;
247247
yVals1.add(new Entry(val, i));
248248
}
249249

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
148148
mChart.saveToPath("title" + System.currentTimeMillis(), "");
149149
break;
150150
}
151+
case R.id.animateX: {
152+
mChart.animateX(3000);
153+
break;
154+
}
155+
case R.id.animateY: {
156+
mChart.animateY(3000);
157+
break;
158+
}
159+
case R.id.animateXY: {
160+
161+
mChart.animateXY(3000, 3000);
162+
break;
163+
}
151164
}
152165
return true;
153166
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
185185
mChart.invalidate();
186186
break;
187187
}
188+
case R.id.animateX: {
189+
mChart.animateX(3000);
190+
break;
191+
}
192+
case R.id.animateY: {
193+
mChart.animateY(3000);
194+
break;
195+
}
196+
case R.id.animateXY: {
197+
198+
mChart.animateXY(3000, 3000);
199+
break;
200+
}
188201
case R.id.actionTogglePinch: {
189202
if (mChart.isPinchZoomEnabled())
190203
mChart.setPinchZoom(false);

MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
105105
holder.chart.setData(c);
106106

107107
// do not forget to refresh the chart
108-
holder.chart.invalidate();
108+
// holder.chart.invalidate();
109+
holder.chart.animateY(700);
109110

110111
return convertView;
111112
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
7070

7171
mSeekBarX.setProgress(45);
7272
mSeekBarY.setProgress(100);
73-
73+
7474
Legend l = mChart.getLegend();
7575
l.setPosition(LegendPosition.RIGHT_OF_CHART);
7676
}
@@ -160,7 +160,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
160160
}
161161
case R.id.actionToggleAdjustXLegend: {
162162
XLabels xLabels = mChart.getXLabels();
163-
163+
164164
if (xLabels.isAdjustXLabelsEnabled())
165165
xLabels.setAdjustXLabels(false);
166166
else
@@ -174,6 +174,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
174174
mChart.saveToPath("title" + System.currentTimeMillis(), "");
175175
break;
176176
}
177+
case R.id.animateX: {
178+
mChart.animateX(3000);
179+
break;
180+
}
181+
case R.id.animateY: {
182+
mChart.animateY(3000);
183+
break;
184+
}
185+
case R.id.animateXY: {
186+
187+
mChart.animateXY(3000, 3000);
188+
break;
189+
}
177190
}
178191
return true;
179192
}
@@ -199,13 +212,13 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
199212
double val = (Math.random() * mSeekBarY.getProgress()) + 3;
200213
values.add(new Entry((float) val, i));
201214
}
202-
203-
LineDataSet d = new LineDataSet(values, "DataSet " + (z+1));
215+
216+
LineDataSet d = new LineDataSet(values, "DataSet " + (z + 1));
204217
d.setLineWidth(2.5f);
205218
d.setCircleSize(4f);
206219
dataSets.add(d);
207220
}
208-
221+
209222
// make the first DataSet dashed
210223
dataSets.get(0).enableDashedLine(10, 10, 0);
211224

0 commit comments

Comments
 (0)