Format center-text for week-sleep-pie

This commit is contained in:
cpfeiffer 2017-02-23 21:15:57 +01:00
parent 437ec6c9b7
commit 49e1b55ad8
3 changed files with 18 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import com.github.mikephil.charting.formatter.IValueFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@ -60,7 +59,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
MyChartsData mcd = (MyChartsData) chartsData;
// setupLegend(mWeekChart);
mTodayPieChart.setCenterText(NumberFormat.getNumberInstance(mLocale).format(mcd.getDayData().totalValue));
mTodayPieChart.setCenterText(mcd.getDayData().centerText);
mTodayPieChart.setData(mcd.getDayData().data);
mWeekChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
@ -128,9 +127,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
data.setDrawValues(false);
return new DayData(data, totalValue);
return new DayData(data, formatPieValue(totalValue));
}
protected abstract String formatPieValue(int value);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -234,11 +235,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
private static class DayData {
private final PieData data;
private final int totalValue;
private final CharSequence centerText;
DayData(PieData data, int totalValue) {
DayData(PieData data, String centerText) {
this.data = data;
this.totalValue = totalValue;
this.centerText = centerText;
}
}

View File

@ -38,12 +38,17 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
return (int) (totalSeconds / 60);
}
@Override
protected String formatPieValue(int value) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES);
}
@Override
IValueFormatter getFormatter() {
return new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES);
return formatPieValue((int) value);
}
};
}

View File

@ -30,6 +30,11 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
return analysis.calculateTotalSteps(activitySamples);
}
@Override
protected String formatPieValue(int value) {
return String.valueOf(value);
}
@Override
IValueFormatter getFormatter() {
return null;