mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 01:55:50 +01:00
Migrate from MPAndroidChart 2.1.0 to 2.1.4
This actually makes our CustomLegendRenderer and CustomBarChart unnecessary.
This commit is contained in:
parent
ab78d167d9
commit
8ba307657a
@ -46,7 +46,7 @@ dependencies {
|
||||
compile 'com.android.support:support-v4:23.0.0'
|
||||
compile 'com.github.tony19:logback-android-classic:1.1.1-3'
|
||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||
compile 'com.github.PhilJay:MPAndroidChart:2.1.0'
|
||||
compile 'com.github.PhilJay:MPAndroidChart:v2.1.4'
|
||||
compile 'com.github.pfichtner:durationformatter:0.1.1'
|
||||
}
|
||||
|
||||
|
@ -125,8 +125,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
legendLabels.add(akDeepSleep.label);
|
||||
legendColors.add(akNotWorn.color);
|
||||
legendLabels.add(akNotWorn.label);
|
||||
chart.getLegend().setColors(legendColors);
|
||||
chart.getLegend().setLabels(legendLabels);
|
||||
chart.getLegend().setCustom(legendColors, legendLabels);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,31 +0,0 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarChart;
|
||||
|
||||
/**
|
||||
* A BarChart with some specific customization, like
|
||||
* <li>using a custom legend renderer that always uses fixed labels and colors</li>
|
||||
*/
|
||||
public class CustomBarChart extends BarChart {
|
||||
|
||||
public CustomBarChart(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomBarChart(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CustomBarChart(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
mLegendRenderer = new CustomLegendRenderer(getViewPortHandler(), getLegend());
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
|
||||
import com.github.mikephil.charting.components.Legend;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.renderer.LegendRenderer;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
/**
|
||||
* A legend renderer that does *not* calculate the labels and colors automatically
|
||||
* from the data sets or the data entries.
|
||||
* <p/>
|
||||
* Instead, they have to be provided manually, because otherwise the legend will
|
||||
* be empty.
|
||||
*/
|
||||
public class CustomLegendRenderer extends LegendRenderer {
|
||||
public CustomLegendRenderer(ViewPortHandler viewPortHandler, Legend legend) {
|
||||
super(viewPortHandler, legend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeLegend(ChartData<?> data) {
|
||||
if (!mLegend.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// don't call super to avoid computing colors and labels
|
||||
// super.computeLegend(data);
|
||||
|
||||
Typeface tf = mLegend.getTypeface();
|
||||
|
||||
if (tf != null)
|
||||
mLegendLabelPaint.setTypeface(tf);
|
||||
|
||||
mLegendLabelPaint.setTextSize(mLegend.getTextSize());
|
||||
mLegendLabelPaint.setColor(mLegend.getTextColor());
|
||||
|
||||
// calculate all dimensions of the mLegend
|
||||
mLegend.calculateDimensions(mLegendLabelPaint);
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@ import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.utils.ValueFormatter;
|
||||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -71,7 +72,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
PieDataSet set = new PieDataSet(entries, "");
|
||||
set.setValueFormatter(new ValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value) {
|
||||
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
|
||||
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
|
||||
}
|
||||
});
|
||||
@ -166,8 +167,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
legendLabels.add(akLightSleep.label);
|
||||
legendColors.add(akDeepSleep.color);
|
||||
legendLabels.add(akDeepSleep.label);
|
||||
chart.getLegend().setColors(legendColors);
|
||||
chart.getLegend().setLabels(legendLabels);
|
||||
chart.getLegend().setCustom(legendColors, legendLabels);
|
||||
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
}
|
||||
|
||||
|
@ -194,8 +194,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
List<String> legendLabels = new ArrayList<>(1);
|
||||
legendColors.add(akActivity.color);
|
||||
legendLabels.add(getContext().getString(R.string.chart_steps));
|
||||
chart.getLegend().setColors(legendColors);
|
||||
chart.getLegend().setLabels(legendLabels);
|
||||
chart.getLegend().setCustom(legendColors, legendLabels);
|
||||
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,10 @@
|
||||
android:layout_weight="40">
|
||||
</com.github.mikephil.charting.charts.PieChart>
|
||||
|
||||
<nodomain.freeyourgadget.gadgetbridge.activities.charts.CustomBarChart
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/sleepchart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
android:layout_weight="20" />
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity$PlaceholderFragment">
|
||||
|
||||
<nodomain.freeyourgadget.gadgetbridge.activities.charts.CustomBarChart
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/activitysleepchart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -11,10 +11,10 @@
|
||||
android:layout_weight="20">
|
||||
</com.github.mikephil.charting.charts.PieChart>
|
||||
|
||||
<nodomain.freeyourgadget.gadgetbridge.activities.charts.CustomBarChart
|
||||
<com.github.mikephil.charting.charts.BarChart
|
||||
android:id="@+id/sleepchart"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
|
||||
android:layout_weight="20" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user