1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-30 14:02:56 +01:00

Migrate to upstream MPAndroidChart v3.1.0

This commit is contained in:
Andreas Shimokawa 2019-08-24 12:41:26 +02:00
parent 2d233141b4
commit a69a139602
9 changed files with 33 additions and 33 deletions

View File

@ -79,7 +79,7 @@ dependencies {
exclude group: "com.google.android", module: "android" exclude group: "com.google.android", module: "android"
} }
implementation "org.slf4j:slf4j-api:1.7.12" implementation "org.slf4j:slf4j-api:1.7.12"
implementation "com.github.Freeyourgadget:MPAndroidChart:5e5bd6c1d3e95c515d4853647ae554e48ee1d593" implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
implementation "com.github.pfichtner:durationformatter:0.1.1" implementation "com.github.pfichtner:durationformatter:0.1.1"
implementation "de.cketti.library.changelog:ckchangelog:1.2.2" implementation "de.cketti.library.changelog:ckchangelog:1.2.2"
implementation "net.e175.klaus:solarpositioning:0.0.9" implementation "net.e175.klaus:solarpositioning:0.0.9"

View File

@ -36,6 +36,7 @@ import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet; import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -572,7 +573,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
lineData = new LineData(); lineData = new LineData();
} }
IAxisValueFormatter xValueFormatter = new SampleXLabelFormatter(tsTranslation); ValueFormatter xValueFormatter = new SampleXLabelFormatter(tsTranslation);
return new DefaultChartsData(lineData, xValueFormatter); return new DefaultChartsData(lineData, xValueFormatter);
} }
@ -753,14 +754,14 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
public static class DefaultChartsData<T extends ChartData<?>> extends ChartsData { public static class DefaultChartsData<T extends ChartData<?>> extends ChartsData {
private final T data; private final T data;
private IAxisValueFormatter xValueFormatter; private ValueFormatter xValueFormatter;
public DefaultChartsData(T data, IAxisValueFormatter xValueFormatter) { public DefaultChartsData(T data, ValueFormatter xValueFormatter) {
this.xValueFormatter = xValueFormatter; this.xValueFormatter = xValueFormatter;
this.data = data; this.data = data;
} }
public IAxisValueFormatter getXValueFormatter() { public ValueFormatter getXValueFormatter() {
return xValueFormatter; return xValueFormatter;
} }
@ -769,7 +770,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
} }
protected static class SampleXLabelFormatter implements IAxisValueFormatter { protected static class SampleXLabelFormatter extends ValueFormatter {
private final TimestampTranslation tsTranslation; private final TimestampTranslation tsTranslation;
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm"); SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
// SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); // SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
@ -791,7 +792,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
} }
protected static class PreformattedXIndexLabelFormatter implements IAxisValueFormatter { protected static class PreformattedXIndexLabelFormatter extends ValueFormatter {
private ArrayList<String> xLabels; private ArrayList<String> xLabels;
public PreformattedXIndexLabelFormatter(ArrayList<String> xLabels) { public PreformattedXIndexLabelFormatter(ArrayList<String> xLabels) {

View File

@ -37,8 +37,7 @@ import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -372,11 +371,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract String[] getPieLabels(); abstract String[] getPieLabels();
abstract IValueFormatter getPieValueFormatter(); abstract ValueFormatter getPieValueFormatter();
abstract IValueFormatter getBarValueFormatter(); abstract ValueFormatter getBarValueFormatter();
abstract IAxisValueFormatter getYAxisFormatter(); abstract ValueFormatter getYAxisFormatter();
abstract int[] getColors(); abstract int[] getColors();

View File

@ -143,7 +143,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
@Override @Override
protected void renderCharts() { protected void renderCharts() {
mChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart); mChart.animateX(ANIM_TIME, Easing.EaseInOutQuart);
// mChart.invalidate(); // mChart.invalidate();
} }

View File

@ -3,19 +3,17 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import android.graphics.Canvas; import android.graphics.Canvas;
import com.github.mikephil.charting.animation.ChartAnimator; import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider; import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.renderer.BarChartRenderer; import com.github.mikephil.charting.renderer.BarChartRenderer;
import com.github.mikephil.charting.utils.ViewPortHandler; import com.github.mikephil.charting.utils.ViewPortHandler;
public class AngledLabelsChartRenderer extends BarChartRenderer { public class AngledLabelsChartRenderer extends BarChartRenderer {
public AngledLabelsChartRenderer(BarDataProvider chart, ChartAnimator animator, ViewPortHandler viewPortHandler) { AngledLabelsChartRenderer(BarDataProvider chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(chart, animator, viewPortHandler); super(chart, animator, viewPortHandler);
} }
@Override @Override
public void drawValue(Canvas canvas, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) { public void drawValue(Canvas canvas, String valueText, float x, float y, int color) {
mValuePaint.setColor(color); mValuePaint.setColor(color);
@ -26,6 +24,7 @@ public class AngledLabelsChartRenderer extends BarChartRenderer {
canvas.save(); canvas.save();
canvas.rotate(-90, x, y); canvas.rotate(-90, x, y);
canvas.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint); canvas.drawText(valueText, x, y, mValuePaint);
canvas.restore(); canvas.restore();
}} }}

View File

@ -38,6 +38,7 @@ import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IValueFormatter; import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler; import com.github.mikephil.charting.utils.ViewPortHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -118,7 +119,7 @@ public class SleepChartFragment extends AbstractChartFragment {
} }
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS); String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
PieDataSet set = new PieDataSet(entries, ""); PieDataSet set = new PieDataSet(entries, "");
set.setValueFormatter(new IValueFormatter() { set.setValueFormatter(new ValueFormatter() {
@Override @Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS); return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
@ -269,7 +270,7 @@ public class SleepChartFragment extends AbstractChartFragment {
@Override @Override
protected void renderCharts() { protected void renderCharts() {
mActivityChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart); mActivityChart.animateX(ANIM_TIME, Easing.EaseInOutQuart);
mSleepAmountChart.invalidate(); mSleepAmountChart.invalidate();
} }

View File

@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import com.github.mikephil.charting.components.AxisBase; import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -25,7 +26,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
public class TimestampValueFormatter implements IAxisValueFormatter { public class TimestampValueFormatter extends ValueFormatter {
private final Calendar cal; private final Calendar cal;
// private DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); // private DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
private DateFormat dateFormat; private DateFormat dateFormat;

View File

@ -22,7 +22,7 @@ import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter; import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler; import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.ArrayList; import java.util.ArrayList;
@ -115,8 +115,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
} }
@Override @Override
IValueFormatter getPieValueFormatter() { ValueFormatter getPieValueFormatter() {
return new IValueFormatter() { return new ValueFormatter() {
@Override @Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return formatPieValue((long) value); return formatPieValue((long) value);
@ -125,8 +125,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
} }
@Override @Override
IValueFormatter getBarValueFormatter() { ValueFormatter getBarValueFormatter() {
return new IValueFormatter() { return new ValueFormatter() {
@Override @Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return DateTimeUtils.minutesToHHMM((int) value); return DateTimeUtils.minutesToHHMM((int) value);
@ -135,8 +135,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
} }
@Override @Override
IAxisValueFormatter getYAxisFormatter() { ValueFormatter getYAxisFormatter() {
return new IAxisValueFormatter() { return new ValueFormatter() {
@Override @Override
public String getFormattedValue(float value, AxisBase axis) { public String getFormattedValue(float value, AxisBase axis) {
return DateTimeUtils.minutesToHHMM((int) value); return DateTimeUtils.minutesToHHMM((int) value);

View File

@ -18,8 +18,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts; package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
@ -82,17 +81,17 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
} }
@Override @Override
IValueFormatter getPieValueFormatter() { ValueFormatter getPieValueFormatter() {
return null; return null;
} }
@Override @Override
IValueFormatter getBarValueFormatter() { ValueFormatter getBarValueFormatter() {
return null; return null;
} }
@Override @Override
IAxisValueFormatter getYAxisFormatter() { ValueFormatter getYAxisFormatter() {
return null; return null;
} }