wear timeticks

This commit is contained in:
AdrianLxM 2018-03-04 13:35:17 +01:00
parent a503bfaeef
commit 5a80215578

View file

@ -388,41 +388,42 @@ public class BgGraphBuilder {
public Axis xAxis() { public Axis xAxis() {
final boolean is24 = DateFormat.is24HourFormat(context); final boolean is24 = DateFormat.is24HourFormat(context);
SimpleDateFormat timeFormat = new SimpleDateFormat(is24? "HH" : "h a");
timeFormat.setTimeZone(TimeZone.getDefault());
long timeNow = System.currentTimeMillis();
Axis xAxis = new Axis(); Axis xAxis = new Axis();
xAxis.setAutoGenerated(false); xAxis.setAutoGenerated(false);
List<AxisValue> xAxisValues = new ArrayList<AxisValue>(); List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
SimpleDateFormat timeFormat = new SimpleDateFormat(is24? "HH" : "h a");
timeFormat.setTimeZone(TimeZone.getDefault());
long start_hour = today.getTime().getTime();
long timeNow = System.currentTimeMillis();
long endTime = getPredictionEndTime(); //get the time-tick at the full hour after start_time
GregorianCalendar startGC = new GregorianCalendar();
startGC.setTimeInMillis(start_time);
startGC.set(Calendar.MILLISECOND, 0);
startGC.set(Calendar.SECOND, 0);
startGC.set(Calendar.MINUTE, 0);
startGC.add(Calendar.HOUR, 1);
long start_hour = startGC.getTimeInMillis();
for (int l = 0; l <= 24; l++) {
if ((start_hour + (60000 * 60 * (l))) < endTime) {
if ((start_hour + (60000 * 60 * (l + 1))) >= endTime) {
endHour = start_hour + (60000 * 60 * (l));
l = 25;
}
}
}
//Display current time on the graph //Display current time on the graph
SimpleDateFormat longTimeFormat = new SimpleDateFormat(is24? "HH:mm" : "h:mm a"); SimpleDateFormat longTimeFormat = new SimpleDateFormat(is24? "HH:mm" : "h:mm a");
xAxisValues.add(new AxisValue(fuzz(timeNow), (longTimeFormat.format(timeNow)).toCharArray())); xAxisValues.add(new AxisValue(fuzz(timeNow), (longTimeFormat.format(timeNow)).toCharArray()));
//Add whole hours endTime the axis (as long as they are more than 15 mins away from the current time) long hourTick = start_hour;
for (int l = 0; l <= 24; l++) {
long timestamp = endHour - (60000 * 60 * l); // add all full hours within the timeframe
if((timestamp - endTime < 0) && (timestamp > start_time)) { while (hourTick < end_time){
if(Math.abs(timestamp - timeNow) > (1000 * 60 * 8 * timespan)){ if(Math.abs(hourTick - timeNow) > (1000 * 60 * 8 * timespan)){
xAxisValues.add(new AxisValue(fuzz(timestamp), (timeFormat.format(timestamp)).toCharArray())); xAxisValues.add(new AxisValue(fuzz(hourTick), (timeFormat.format(hourTick)).toCharArray()));
}else { } else {
xAxisValues.add(new AxisValue(fuzz(timestamp), "".toCharArray())); //don't print hour label if too close to now to avoid overlaps
} xAxisValues.add(new AxisValue(fuzz(hourTick), "".toCharArray()));
} }
//increment by one hour
hourTick += 60*60*1000;
} }
xAxis.setValues(xAxisValues); xAxis.setValues(xAxisValues);
xAxis.setTextSize(10); xAxis.setTextSize(10);
xAxis.setHasLines(true); xAxis.setHasLines(true);