Brought back the Realm demos, were removed by mistake
This commit is contained in:
parent
86d05e989a
commit
30cb069974
18 changed files with 1352 additions and 2 deletions
|
@ -47,12 +47,22 @@
|
|||
<activity android:name="RadarChartActivitry"></activity>
|
||||
<activity android:name="LineChartActivityColored"></activity>
|
||||
<activity android:name="DynamicalAddingActivity"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityLine"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityHorizontalBar"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityScatter"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityCandle"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityBubble"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityPie"></activity>
|
||||
<activity android:name=".realm.RealmDatabaseActivityRadar"></activity>
|
||||
<activity android:name=".realm.RealmMainActivity"></activity>
|
||||
<activity android:name="RealtimeLineChartActivity"></activity>
|
||||
<activity android:name="CombinedChartActivity"></activity>
|
||||
<activity android:name="PerformanceLineChart"></activity>
|
||||
<activity android:name="BarChartActivitySinus"></activity>
|
||||
<activity android:name="ScrollViewActivity"></activity>
|
||||
<activity android:name="StackedBarActivityNegative"></activity>
|
||||
<activity android:name=".realm.RealmWikiExample"></activity>
|
||||
<activity android:name=".BarChartPositiveNegative"></activity>
|
||||
<activity android:name=".FilledLineActivity"></activity>
|
||||
<activity android:name=".HalfPieChartActivity"></activity>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
apply plugin: 'com.android.application'
|
||||
//apply plugin: 'realm-android'
|
||||
apply plugin: 'realm-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
|
||||
import io.realm.RealmList;
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* Demo class that encapsulates data stored in realm.io database.
|
||||
* This class represents data suitable for all chart-types.
|
||||
*/
|
||||
public class RealmDemoData extends RealmObject {
|
||||
|
||||
private float yValue;
|
||||
private float xValue;
|
||||
|
||||
private float open, close, high, low;
|
||||
|
||||
private float bubbleSize;
|
||||
|
||||
private RealmList<RealmFloat> stackValues;
|
||||
|
||||
private String someStringField;
|
||||
|
||||
/**
|
||||
* label for pie entries
|
||||
*/
|
||||
private String label;
|
||||
|
||||
// ofc there could me more fields here...
|
||||
|
||||
public RealmDemoData() {
|
||||
|
||||
}
|
||||
|
||||
public RealmDemoData(float yValue) {
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
public RealmDemoData(float xValue, float yValue) {
|
||||
this.xValue = xValue;
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for stacked bars.
|
||||
*
|
||||
* @param xValue
|
||||
* @param stackValues
|
||||
*/
|
||||
public RealmDemoData(float xValue, float[] stackValues) {
|
||||
this.xValue = xValue;
|
||||
this.stackValues = new RealmList<RealmFloat>();
|
||||
|
||||
for (float val : stackValues) {
|
||||
this.stackValues.add(new RealmFloat(val));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for candles.
|
||||
*
|
||||
* @param xValue
|
||||
* @param high
|
||||
* @param low
|
||||
* @param open
|
||||
* @param close
|
||||
*/
|
||||
public RealmDemoData(float xValue, float high, float low, float open, float close) {
|
||||
this.yValue = (high + low) / 2f;
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
this.open = open;
|
||||
this.close = close;
|
||||
this.xValue = xValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for bubbles.
|
||||
*
|
||||
* @param xValue
|
||||
* @param yValue
|
||||
* @param bubbleSize
|
||||
*/
|
||||
public RealmDemoData(float xValue, float yValue, float bubbleSize) {
|
||||
this.xValue = xValue;
|
||||
this.yValue = yValue;
|
||||
this.bubbleSize = bubbleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for pie chart.
|
||||
*
|
||||
* @param yValue
|
||||
* @param label
|
||||
*/
|
||||
public RealmDemoData(float yValue, String label) {
|
||||
this.yValue = yValue;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public float getyValue() {
|
||||
return yValue;
|
||||
}
|
||||
|
||||
public void setyValue(float yValue) {
|
||||
this.yValue = yValue;
|
||||
}
|
||||
|
||||
public float getxValue() {
|
||||
return xValue;
|
||||
}
|
||||
|
||||
public void setxValue(float xValue) {
|
||||
this.xValue = xValue;
|
||||
}
|
||||
|
||||
public RealmList<RealmFloat> getStackValues() {
|
||||
return stackValues;
|
||||
}
|
||||
|
||||
public void setStackValues(RealmList<RealmFloat> stackValues) {
|
||||
this.stackValues = stackValues;
|
||||
}
|
||||
|
||||
public float getOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public void setOpen(float open) {
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
public float getClose() {
|
||||
return close;
|
||||
}
|
||||
|
||||
public void setClose(float close) {
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public float getHigh() {
|
||||
return high;
|
||||
}
|
||||
|
||||
public void setHigh(float high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public float getLow() {
|
||||
return low;
|
||||
}
|
||||
|
||||
public void setLow(float low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public float getBubbleSize() {
|
||||
return bubbleSize;
|
||||
}
|
||||
|
||||
public void setBubbleSize(float bubbleSize) {
|
||||
this.bubbleSize = bubbleSize;
|
||||
}
|
||||
|
||||
public String getSomeStringField() {
|
||||
return someStringField;
|
||||
}
|
||||
|
||||
public void setSomeStringField(String someStringField) {
|
||||
this.someStringField = someStringField;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.xxmassdeveloper.mpchartexample.custom;
|
||||
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 09/11/15.
|
||||
*/
|
||||
public class RealmFloat extends RealmObject {
|
||||
|
||||
private float floatValue;
|
||||
|
||||
public RealmFloat() {
|
||||
|
||||
}
|
||||
|
||||
public RealmFloat(float floatValue) {
|
||||
this.floatValue = floatValue;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
return floatValue;
|
||||
}
|
||||
|
||||
public void setFloatValue(float value) {
|
||||
this.floatValue = value;
|
||||
}
|
||||
}
|
|
@ -46,6 +46,7 @@ import com.xxmassdeveloper.mpchartexample.ScrollViewActivity;
|
|||
import com.xxmassdeveloper.mpchartexample.StackedBarActivity;
|
||||
import com.xxmassdeveloper.mpchartexample.StackedBarActivityNegative;
|
||||
import com.xxmassdeveloper.mpchartexample.fragments.SimpleChartDemo;
|
||||
import com.xxmassdeveloper.mpchartexample.realm.RealmMainActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -130,6 +131,10 @@ public class MainActivity extends Activity implements OnItemClickListener {
|
|||
"BarChart positive / negative",
|
||||
"This demonstrates how to create a BarChart with positive and negative values in different colors."));
|
||||
|
||||
ContentItem realm = new ContentItem(
|
||||
"Realm.io Database",
|
||||
"This demonstrates how to use this library with Realm.io mobile database.");
|
||||
objects.add(realm);
|
||||
|
||||
ContentItem time = new ContentItem(
|
||||
"Time Chart",
|
||||
|
@ -269,6 +274,10 @@ public class MainActivity extends Activity implements OnItemClickListener {
|
|||
i = new Intent(this, BarChartPositiveNegative.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 28:
|
||||
i = new Intent(this, RealmMainActivity.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 29:
|
||||
i = new Intent(this, LineChartTime.class);
|
||||
startActivity(i);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.CandleStickChart;
|
||||
import com.github.mikephil.charting.data.CandleData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmCandleDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
|
||||
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 RealmDatabaseActivityCandle extends RealmBaseActivity {
|
||||
|
||||
private CandleStickChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_candlechart_noseekbar);
|
||||
|
||||
mChart = (CandleStickChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBCandle(50);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "xValue", "high", "low", "open", "close");
|
||||
set.setLabel("Realm CandleDataSet");
|
||||
set.setShadowColor(Color.DKGRAY);
|
||||
set.setShadowWidth(0.7f);
|
||||
set.setDecreasingColor(Color.RED);
|
||||
set.setDecreasingPaintStyle(Paint.Style.FILL);
|
||||
set.setIncreasingColor(Color.rgb(122, 242, 84));
|
||||
set.setIncreasingPaintStyle(Paint.Style.STROKE);
|
||||
set.setNeutralColor(Color.BLUE);
|
||||
|
||||
ArrayList<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
CandleData data = new CandleData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.animation.Easing;
|
||||
import com.github.mikephil.charting.charts.HorizontalBarChart;
|
||||
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 RealmDatabaseActivityHorizontalBar extends RealmBaseActivity {
|
||||
|
||||
private HorizontalBarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_horizontalbarchart_noseekbar);
|
||||
|
||||
mChart = (HorizontalBarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMinValue(0f);
|
||||
mChart.setDrawValueAboveBar(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBStack(50);
|
||||
|
||||
// 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", "stackValues", "floatValue"); // stacked entries
|
||||
set.setColors(new int[]{ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E")});
|
||||
set.setLabel("Mobile OS distribution");
|
||||
set.setStackLabels(new String[]{"iOS", "Android", "Other"});
|
||||
|
||||
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);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
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.LineChart;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
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 RealmDatabaseActivityLine extends RealmBaseActivity {
|
||||
|
||||
private LineChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_linechart_noseekbar);
|
||||
|
||||
mChart = (LineChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setAxisMaxValue(150f);
|
||||
mChart.getAxisLeft().setAxisMinValue(0f);
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(40);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setDrawCubic(false);
|
||||
set.setLabel("Realm LineDataSet");
|
||||
set.setDrawCircleHole(false);
|
||||
set.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
set.setLineWidth(1.8f);
|
||||
set.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
LineData data = new LineData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmPieDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.custom.RealmDemoData;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 21/10/15.
|
||||
*/
|
||||
public class RealmDatabaseActivityPie extends RealmBaseActivity {
|
||||
|
||||
private PieChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_piechart_noseekbar);
|
||||
|
||||
mChart = (PieChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.setCenterText(generateCenterSpannableText());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDBPie();
|
||||
|
||||
// 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
|
||||
RealmPieDataSet<RealmDemoData> set = new RealmPieDataSet<RealmDemoData>(result, "yValue", "label"); // stacked entries
|
||||
set.setColors(ColorTemplate.VORDIPLOM_COLORS);
|
||||
set.setLabel("Example market share");
|
||||
set.setSliceSpace(2);
|
||||
|
||||
// create a data object with the dataset list
|
||||
PieData data = new PieData(set);
|
||||
styleData(data);
|
||||
data.setValueTextColor(Color.WHITE);
|
||||
data.setValueTextSize(12f);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400);
|
||||
}
|
||||
|
||||
private SpannableString generateCenterSpannableText() {
|
||||
|
||||
SpannableString s = new SpannableString("Realm.io\nmobile database");
|
||||
s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
|
||||
s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
|
||||
s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
|
||||
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
|
||||
s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
|
||||
return s;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.github.mikephil.charting.charts.RadarChart;
|
||||
import com.github.mikephil.charting.data.RadarData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmRadarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
|
||||
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 RealmDatabaseActivityRadar extends RealmBaseActivity {
|
||||
|
||||
private RadarChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_radarchart_noseekbar);
|
||||
|
||||
mChart = (RadarChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getYAxis().setEnabled(false);
|
||||
mChart.getXAxis().setEnabled(false);
|
||||
mChart.setWebAlpha(180);
|
||||
mChart.setWebColorInner(Color.DKGRAY);
|
||||
mChart.setWebColor(Color.GRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(7);
|
||||
|
||||
// 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
|
||||
RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "yValue"); // stacked entries
|
||||
set.setLabel("Realm RadarDataSet");
|
||||
set.setDrawFilled(true);
|
||||
set.setColor(ColorTemplate.rgb("#009688"));
|
||||
set.setFillColor(ColorTemplate.rgb("#009688"));
|
||||
set.setFillAlpha(130);
|
||||
set.setLineWidth(2f);
|
||||
|
||||
ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
RadarData data = new RadarData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
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.ScatterChart;
|
||||
import com.github.mikephil.charting.data.ScatterData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmScatterDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
|
||||
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 RealmDatabaseActivityScatter extends RealmBaseActivity {
|
||||
|
||||
private ScatterChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_scatterchart_noseekbar);
|
||||
|
||||
mChart = (ScatterChart) findViewById(R.id.chart1);
|
||||
setup(mChart);
|
||||
|
||||
mChart.getAxisLeft().setDrawGridLines(false);
|
||||
mChart.getXAxis().setDrawGridLines(false);
|
||||
mChart.setPinchZoom(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
writeToDB(45);
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
|
||||
|
||||
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
|
||||
set.setLabel("Realm ScatterDataSet");
|
||||
set.setScatterShapeSize(9f);
|
||||
set.setColor(ColorTemplate.rgb("#CDDC39"));
|
||||
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
|
||||
|
||||
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
|
||||
dataSets.add(set); // add the dataset
|
||||
|
||||
// create a data object with the dataset list
|
||||
ScatterData data = new ScatterData(dataSets);
|
||||
styleData(data);
|
||||
|
||||
// set data
|
||||
mChart.setData(data);
|
||||
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.ContentItem;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
import com.xxmassdeveloper.mpchartexample.notimportant.MyAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.Realm;
|
||||
import io.realm.RealmConfiguration;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 07/12/15.
|
||||
*/
|
||||
public class RealmMainActivity extends DemoBase implements AdapterView.OnItemClickListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
setTitle("Realm.io Examples");
|
||||
|
||||
ArrayList<ContentItem> objects = new ArrayList<ContentItem>();
|
||||
|
||||
objects.add(new ContentItem("Line Chart", "Creating a LineChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Bar Chart",
|
||||
"Creating a BarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Horizontal Bar Chart",
|
||||
"Creating a HorizontalBarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Scatter Chart",
|
||||
"Creating a ScatterChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Candle Stick Chart", "Creating a CandleStickChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Bubble Chart", "Creating a BubbleChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Pie Chart", "Creating a PieChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Radar Chart", "Creating a RadarChart with Realm.io database"));
|
||||
objects.add(new ContentItem("Realm Wiki", "This is the code related to the wiki entry about realm.io on the MPAndroidChart github page."));
|
||||
|
||||
MyAdapter adapter = new MyAdapter(this, objects);
|
||||
|
||||
ListView lv = (ListView) findViewById(R.id.listView1);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
lv.setOnItemClickListener(this);
|
||||
|
||||
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
|
||||
RealmConfiguration realmConfig = new RealmConfiguration.Builder(getApplicationContext()).build();
|
||||
Realm.setDefaultConfiguration(realmConfig);
|
||||
|
||||
Realm realm = Realm.getDefaultInstance();
|
||||
realm.beginTransaction();
|
||||
realm.deleteAll();
|
||||
realm.commitTransaction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
|
||||
|
||||
Intent i;
|
||||
|
||||
switch (pos) {
|
||||
case 0:
|
||||
i = new Intent(this, RealmDatabaseActivityLine.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 1:
|
||||
i = new Intent(this, RealmDatabaseActivityBar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 2:
|
||||
i = new Intent(this, RealmDatabaseActivityHorizontalBar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 3:
|
||||
i = new Intent(this, RealmDatabaseActivityScatter.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 4:
|
||||
i = new Intent(this, RealmDatabaseActivityCandle.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 5:
|
||||
i = new Intent(this, RealmDatabaseActivityBubble.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 6:
|
||||
i = new Intent(this, RealmDatabaseActivityPie.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 7:
|
||||
i = new Intent(this, RealmDatabaseActivityRadar.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
case 8:
|
||||
i = new Intent(this, RealmWikiExample.class);
|
||||
startActivity(i);
|
||||
break;
|
||||
}
|
||||
|
||||
overridePendingTransition(R.anim.move_right_in_activity, R.anim.move_left_out_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.realm, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("https://realm.io"));
|
||||
startActivity(i);
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
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.charts.LineChart;
|
||||
import com.github.mikephil.charting.components.AxisBase;
|
||||
import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet;
|
||||
import com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet;
|
||||
import com.github.mikephil.charting.formatter.AxisValueFormatter;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||
import com.github.mikephil.charting.utils.ColorTemplate;
|
||||
import com.xxmassdeveloper.mpchartexample.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.realm.RealmResults;
|
||||
|
||||
/**
|
||||
* Created by Philipp Jahoda on 18/12/15.
|
||||
*/
|
||||
public class RealmWikiExample extends RealmBaseActivity {
|
||||
|
||||
private LineChart lineChart;
|
||||
private BarChart barChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
setContentView(R.layout.activity_realm_wiki);
|
||||
|
||||
lineChart = (LineChart) findViewById(R.id.lineChart);
|
||||
barChart = (BarChart) findViewById(R.id.barChart);
|
||||
setup(lineChart);
|
||||
setup(barChart);
|
||||
|
||||
lineChart.setExtraBottomOffset(5f);
|
||||
barChart.setExtraBottomOffset(5f);
|
||||
|
||||
lineChart.getAxisLeft().setDrawGridLines(false);
|
||||
lineChart.getXAxis().setDrawGridLines(false);
|
||||
lineChart.getXAxis().setLabelCount(5);
|
||||
lineChart.getXAxis().setGranularity(1f);
|
||||
barChart.getAxisLeft().setDrawGridLines(false);
|
||||
barChart.getXAxis().setDrawGridLines(false);
|
||||
barChart.getXAxis().setLabelCount(5);
|
||||
barChart.getXAxis().setGranularity(1f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume(); // setup realm
|
||||
|
||||
mRealm.beginTransaction();
|
||||
|
||||
// write some demo-data into the realm.io database
|
||||
Score score1 = new Score(100f, 0f, "Peter");
|
||||
mRealm.copyToRealm(score1);
|
||||
Score score2 = new Score(110f, 1f, "Lisa");
|
||||
mRealm.copyToRealm(score2);
|
||||
Score score3 = new Score(130f, 2f, "Dennis");
|
||||
mRealm.copyToRealm(score3);
|
||||
Score score4 = new Score(70f, 3f, "Luke");
|
||||
mRealm.copyToRealm(score4);
|
||||
Score score5 = new Score(80f, 4f, "Sarah");
|
||||
mRealm.copyToRealm(score5);
|
||||
|
||||
mRealm.commitTransaction();
|
||||
|
||||
// add data to the chart
|
||||
setData();
|
||||
}
|
||||
|
||||
private void setData() {
|
||||
|
||||
// LINE-CHART
|
||||
final RealmResults<Score> results = mRealm.where(Score.class).findAll();
|
||||
|
||||
|
||||
AxisValueFormatter formatter = new AxisValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value, AxisBase axis) {
|
||||
return results.get((int) value).getPlayerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDecimalDigits() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
lineChart.getXAxis().setValueFormatter(formatter);
|
||||
barChart.getXAxis().setValueFormatter(formatter);
|
||||
|
||||
RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
lineDataSet.setDrawCubic(false);
|
||||
lineDataSet.setLabel("Result Scores");
|
||||
lineDataSet.setDrawCircleHole(false);
|
||||
lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
|
||||
lineDataSet.setLineWidth(1.8f);
|
||||
lineDataSet.setCircleSize(3.6f);
|
||||
|
||||
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
|
||||
dataSets.add(lineDataSet);
|
||||
|
||||
LineData lineData = new LineData(dataSets);
|
||||
styleData(lineData);
|
||||
|
||||
// set data
|
||||
lineChart.setData(lineData);
|
||||
lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
|
||||
|
||||
// BAR-CHART
|
||||
RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
|
||||
barDataSet.setColors(new int[]{ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")});
|
||||
barDataSet.setLabel("Realm BarDataSet");
|
||||
|
||||
ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
|
||||
barDataSets.add(barDataSet);
|
||||
|
||||
BarData barData = new BarData(barDataSets);
|
||||
styleData(barData);
|
||||
|
||||
barChart.setData(barData);
|
||||
barChart.setFitBars(true);
|
||||
barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.xxmassdeveloper.mpchartexample.realm;
|
||||
|
||||
|
||||
import io.realm.RealmObject;
|
||||
|
||||
/**
|
||||
* our data object
|
||||
*/
|
||||
public class Score extends RealmObject {
|
||||
|
||||
private float totalScore;
|
||||
|
||||
private float scoreNr;
|
||||
|
||||
private String playerName;
|
||||
|
||||
public Score() {
|
||||
}
|
||||
|
||||
public Score(float totalScore, float scoreNr, String playerName) {
|
||||
this.scoreNr = scoreNr;
|
||||
this.playerName = playerName;
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
// all getters and setters...
|
||||
|
||||
public float getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
public void setTotalScore(float totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
public float getScoreNr() {
|
||||
return scoreNr;
|
||||
}
|
||||
|
||||
public void setScoreNr(float scoreNr) {
|
||||
this.scoreNr = scoreNr;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
//classpath "io.realm:realm-gradle-plugin:1.1.0"
|
||||
classpath "io.realm:realm-gradle-plugin:1.1.0"
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue