-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmBaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
package com.xxmassdeveloper.mpchartexample.realm; | ||
|
||
import android.graphics.Color; | ||
import android.graphics.Typeface; | ||
import android.os.Bundle; | ||
|
||
import com.github.mikephil.charting.charts.BarLineChartBase; | ||
import com.github.mikephil.charting.charts.Chart; | ||
import com.github.mikephil.charting.components.XAxis; | ||
import com.github.mikephil.charting.components.YAxis; | ||
import com.github.mikephil.charting.data.ChartData; | ||
import com.github.mikephil.charting.formatter.PercentFormatter; | ||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData; | ||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase; | ||
|
||
import io.realm.Realm; | ||
import io.realm.RealmConfiguration; | ||
|
||
/** | ||
* Created by Philipp Jahoda on 05/11/15. | ||
*/ | ||
public abstract class RealmBaseActivity extends DemoBase { | ||
|
||
protected Realm mRealm; | ||
|
||
protected Typeface mTf; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setTitle("Realm.io Examples"); | ||
} | ||
|
||
protected void setup(Chart<?> chart) { | ||
|
||
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | ||
|
||
// no description text | ||
chart.setDescription(""); | ||
chart.setNoDataTextDescription("You need to provide data for the chart."); | ||
|
||
// enable touch gestures | ||
chart.setTouchEnabled(true); | ||
|
||
if (chart instanceof BarLineChartBase) { | ||
|
||
BarLineChartBase mChart = (BarLineChartBase) chart; | ||
|
||
mChart.setDrawGridBackground(false); | ||
|
||
// enable scaling and dragging | ||
mChart.setDragEnabled(true); | ||
mChart.setScaleEnabled(true); | ||
|
||
// if disabled, scaling can be done on x- and y-axis separately | ||
mChart.setPinchZoom(false); | ||
|
||
YAxis leftAxis = mChart.getAxisLeft(); | ||
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines | ||
leftAxis.setTypeface(mTf); | ||
leftAxis.setTextSize(8f); | ||
leftAxis.setTextColor(Color.DKGRAY); | ||
leftAxis.setValueFormatter(new PercentFormatter()); | ||
|
||
XAxis xAxis = mChart.getXAxis(); | ||
xAxis.setTypeface(mTf); | ||
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | ||
xAxis.setTextSize(8f); | ||
xAxis.setTextColor(Color.DKGRAY); | ||
|
||
mChart.getAxisRight().setEnabled(false); | ||
} | ||
} | ||
|
||
protected void styleData(ChartData data) { | ||
data.setValueTypeface(mTf); | ||
data.setValueTextSize(8f); | ||
data.setValueTextColor(Color.DKGRAY); | ||
data.setValueFormatter(new PercentFormatter()); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory. | ||
RealmConfiguration realmConfig = new RealmConfiguration.Builder(getApplicationContext()).build(); | ||
Realm.setDefaultConfiguration(realmConfig); | ||
|
||
mRealm = Realm.getDefaultInstance(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mRealm.close(); | ||
} | ||
|
||
protected void writeToDB(int objectCount) { | ||
|
||
mRealm.beginTransaction(); | ||
|
||
mRealm.delete(RealmDemoData.class); | ||
|
||
for (int i = 0; i < objectCount; i++) { | ||
|
||
float value = 40f + (float) (Math.random() * 60f); | ||
|
||
RealmDemoData d = new RealmDemoData(i, value); | ||
mRealm.copyToRealm(d); | ||
} | ||
|
||
mRealm.commitTransaction(); | ||
} | ||
|
||
protected void writeToDBStack(int objectCount) { | ||
|
||
mRealm.beginTransaction(); | ||
|
||
mRealm.delete(RealmDemoData.class); | ||
|
||
for (int i = 0; i < objectCount; i++) { | ||
|
||
float val1 = 34f + (float) (Math.random() * 12.0f); | ||
float val2 = 34f + (float) (Math.random() * 12.0f); | ||
float[] stack = new float[]{val1, val2, 100 - val1 - val2}; | ||
|
||
RealmDemoData d = new RealmDemoData(i, stack); | ||
mRealm.copyToRealm(d); | ||
} | ||
|
||
mRealm.commitTransaction(); | ||
} | ||
|
||
protected void writeToDBCandle(int objectCount) { | ||
|
||
mRealm.beginTransaction(); | ||
|
||
mRealm.delete(RealmDemoData.class); | ||
|
||
for (int i = 0; i < objectCount; i++) { | ||
|
||
float mult = 50; | ||
float val = (float) (Math.random() * 40) + mult; | ||
|
||
float high = (float) (Math.random() * 9) + 8f; | ||
float low = (float) (Math.random() * 9) + 8f; | ||
|
||
float open = (float) (Math.random() * 6) + 1f; | ||
float close = (float) (Math.random() * 6) + 1f; | ||
|
||
boolean even = i % 2 == 0; | ||
|
||
RealmDemoData d = new RealmDemoData(i, val + high, val - low, even ? val + open : val - open, | ||
even ? val - close : val + close); | ||
|
||
mRealm.copyToRealm(d); | ||
} | ||
|
||
mRealm.commitTransaction(); | ||
} | ||
|
||
protected void writeToDBBubble(int objectCount) { | ||
|
||
mRealm.beginTransaction(); | ||
|
||
mRealm.delete(RealmDemoData.class); | ||
|
||
for (int i = 0; i < objectCount; i++) { | ||
|
||
float value = 30f + (float) (Math.random() * 100.0); | ||
float size = 15f + (float) (Math.random() * 20.0); | ||
|
||
RealmDemoData d = new RealmDemoData(i, value, size); | ||
mRealm.copyToRealm(d); | ||
} | ||
|
||
mRealm.commitTransaction(); | ||
} | ||
|
||
protected void writeToDBPie() { | ||
|
||
mRealm.beginTransaction(); | ||
|
||
mRealm.delete(RealmDemoData.class); | ||
|
||
float value1 = 15f + (float) (Math.random() * 8f); | ||
float value2 = 15f + (float) (Math.random() * 8f); | ||
float value3 = 15f + (float) (Math.random() * 8f); | ||
float value4 = 15f + (float) (Math.random() * 8f); | ||
float value5 = 100f - value1 - value2 - value3 - value4; | ||
|
||
float[] values = new float[] { value1, value2, value3, value4, value5 }; | ||
String[] labels = new String[]{ "iOS", "Android", "WP 10", "BlackBerry", "Other"}; | ||
|
||
for (int i = 0; i < values.length; i++) { | ||
RealmDemoData d = new RealmDemoData(values[i], labels[i]); | ||
mRealm.copyToRealm(d); | ||
} | ||
|
||
mRealm.commitTransaction(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.xxmassdeveloper.mpchartexample.realm; | ||
|
||
import android.os.Bundle; | ||
import android.view.WindowManager; | ||
|
||
import com.github.mikephil.charting.animation.Easing; | ||
import com.github.mikephil.charting.charts.BarChart; | ||
import com.github.mikephil.charting.data.BarData; | ||
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet; | ||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet; | ||
import com.github.mikephil.charting.utils.ColorTemplate; | ||
import com.xxmassdeveloper.mpchartexample.R; | ||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData; | ||
|
||
import java.util.ArrayList; | ||
|
||
import io.realm.RealmResults; | ||
|
||
/** | ||
* Created by Philipp Jahoda on 21/10/15. | ||
*/ | ||
public class RealmDatabaseActivityBar extends RealmBaseActivity { | ||
|
||
private BarChart mChart; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
setContentView(R.layout.activity_barchart_noseekbar); | ||
|
||
mChart = (BarChart) findViewById(R.id.chart1); | ||
setup(mChart); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); // setup realm | ||
|
||
// write some demo-data into the realm.io database | ||
writeToDB(20); | ||
|
||
// add data to the chart | ||
setData(); | ||
} | ||
|
||
private void setData() { | ||
|
||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll(); | ||
|
||
//RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries | ||
RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "yValue"); // stacked entries | ||
set.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")}); | ||
set.setLabel("Realm BarDataSet"); | ||
|
||
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>(); | ||
dataSets.add(set); // add the dataset | ||
|
||
// create a data object with the dataset list | ||
BarData data = new BarData(dataSets); | ||
styleData(data); | ||
|
||
// set data | ||
mChart.setData(data); | ||
mChart.setFitBars(true); | ||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
MPChartExample/src/com/xxmassdeveloper/mpchartexample/realm/RealmDatabaseActivityBubble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.xxmassdeveloper.mpchartexample.realm; | ||
|
||
import android.os.Bundle; | ||
import android.view.WindowManager; | ||
|
||
import com.github.mikephil.charting.animation.Easing; | ||
import com.github.mikephil.charting.charts.BubbleChart; | ||
import com.github.mikephil.charting.data.BubbleData; | ||
import com.github.mikephil.charting.data.realm.implementation.RealmBubbleDataSet; | ||
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet; | ||
import com.github.mikephil.charting.utils.ColorTemplate; | ||
import com.xxmassdeveloper.mpchartexample.R; | ||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData; | ||
|
||
import java.util.ArrayList; | ||
|
||
import io.realm.RealmResults; | ||
|
||
/** | ||
* Created by Philipp Jahoda on 21/10/15. | ||
*/ | ||
public class RealmDatabaseActivityBubble extends RealmBaseActivity { | ||
|
||
private BubbleChart mChart; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
setContentView(R.layout.activity_bubblechart_noseekbar); | ||
|
||
mChart = (BubbleChart) findViewById(R.id.chart1); | ||
setup(mChart); | ||
|
||
mChart.getXAxis().setDrawGridLines(false); | ||
mChart.getAxisLeft().setDrawGridLines(false); | ||
mChart.setPinchZoom(true); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); // setup realm | ||
|
||
// write some demo-data into the realm.io database | ||
writeToDBBubble(10); | ||
|
||
// add data to the chart | ||
setData(); | ||
} | ||
|
||
private void setData() { | ||
|
||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll(); | ||
|
||
RealmBubbleDataSet<RealmDemoData> set = new RealmBubbleDataSet<RealmDemoData>(result, "xValue", "yValue", "bubbleSize"); | ||
set.setLabel("Realm BubbleDataSet"); | ||
set.setColors(ColorTemplate.COLORFUL_COLORS, 110); | ||
|
||
ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>(); | ||
dataSets.add(set); // add the dataset | ||
|
||
// create a data object with the dataset list | ||
BubbleData data = new BubbleData(dataSets); | ||
styleData(data); | ||
|
||
// set data | ||
mChart.setData(data); | ||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); | ||
} | ||
} |
Oops, something went wrong.