mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 11:17:33 +01:00
Format center-text for week-sleep-pie
This commit is contained in:
parent
437ec6c9b7
commit
49e1b55ad8
@ -23,7 +23,6 @@ import com.github.mikephil.charting.formatter.IValueFormatter;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -60,7 +59,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
|||||||
MyChartsData mcd = (MyChartsData) chartsData;
|
MyChartsData mcd = (MyChartsData) chartsData;
|
||||||
|
|
||||||
// setupLegend(mWeekChart);
|
// setupLegend(mWeekChart);
|
||||||
mTodayPieChart.setCenterText(NumberFormat.getNumberInstance(mLocale).format(mcd.getDayData().totalValue));
|
mTodayPieChart.setCenterText(mcd.getDayData().centerText);
|
||||||
mTodayPieChart.setData(mcd.getDayData().data);
|
mTodayPieChart.setData(mcd.getDayData().data);
|
||||||
|
|
||||||
mWeekChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
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
|
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
|
||||||
data.setDrawValues(false);
|
data.setDrawValues(false);
|
||||||
|
|
||||||
return new DayData(data, totalValue);
|
return new DayData(data, formatPieValue(totalValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract String formatPieValue(int value);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
@ -234,11 +235,11 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
private static class DayData {
|
private static class DayData {
|
||||||
private final PieData data;
|
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.data = data;
|
||||||
this.totalValue = totalValue;
|
this.centerText = centerText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,12 +38,17 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
|||||||
return (int) (totalSeconds / 60);
|
return (int) (totalSeconds / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String formatPieValue(int value) {
|
||||||
|
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
IValueFormatter getFormatter() {
|
IValueFormatter getFormatter() {
|
||||||
return new IValueFormatter() {
|
return new IValueFormatter() {
|
||||||
@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.MINUTES);
|
return formatPieValue((int) value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
|
|||||||
return analysis.calculateTotalSteps(activitySamples);
|
return analysis.calculateTotalSteps(activitySamples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String formatPieValue(int value) {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
IValueFormatter getFormatter() {
|
IValueFormatter getFormatter() {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user