Merge pull request #519 from andrew-warrington/watchfaces

Update of watchfaces
This commit is contained in:
AdrianLxM 2017-12-04 17:51:16 +01:00 committed by GitHub
commit f71f972f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 32 deletions

View file

@ -308,6 +308,15 @@ public class NSDeviceStatus {
return Html.fromHtml(string.toString());
}
public static double getOpenApsTimestamp() {
if (deviceStatusOpenAPSData.clockSuggested != 0) {
return deviceStatusOpenAPSData.clockSuggested;
} else {
return -1;
}
}
public Spanned getExtendedOpenApsStatus() {
StringBuilder string = new StringBuilder();

View file

@ -552,13 +552,7 @@ public class WatchUpdaterService extends WearableListenerService implements
String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim();
//OpenAPS status
String openApsString = String.valueOf(NSDeviceStatus.getInstance().getOpenApsStatus());
String openApsStatus = "";
if(openApsString != null) {
int index = openApsString.indexOf("m");
if(index > 0)
openApsStatus = openApsString.substring(0, index);
}
Double openApsStatus = NSDeviceStatus.getOpenApsTimestamp();
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH);
//unique content
@ -570,7 +564,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putString("tempBasal", tempBasal);
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
dataMapRequest.getDataMap().putString("openApsStatus", openApsStatus);
dataMapRequest.getDataMap().putDouble("openApsStatus", openApsStatus);
dataMapRequest.getDataMap().putString("bgi", bgiString);
dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false));
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0);

View file

@ -29,6 +29,7 @@ public class DateUtil {
*/
private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ";
private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
private static String FORMAT_DATE_ISO_MSEC_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
/**
* Takes in an ISO date string of the following format:
@ -42,15 +43,31 @@ public class DateUtil {
throws Exception {
SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO, Locale.getDefault());
Date date;
f.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
date = f.parse(isoDateString);
return date;
} catch (ParseException e) {
}
f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC, Locale.getDefault());
f.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
date = f.parse(isoDateString);
}
return date;
} catch (ParseException e) {
}
f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC_UTC, Locale.getDefault());
f.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
date = f.parse(isoDateString);
return date;
} catch (ParseException e) {
}
throw new ParseException("Unparseable date: " + isoDateString, 0);
}
/**
@ -72,6 +89,7 @@ public class DateUtil {
public static String toISOString(Date date) {
return toISOString(date, FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
}
public static String toISOString(long date) {
return toISOString(new Date(date), FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
}
@ -125,6 +143,7 @@ public class DateUtil {
public static String dateAndTimeString(Date date) {
return dateString(date) + " " + timeString(date);
}
public static String dateAndTimeString(long mills) {
return dateString(mills) + " " + timeString(mills);
}

View file

@ -19,6 +19,7 @@ public class DateUtilTest {
public void fromISODateStringTest() throws Exception {
assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
assertEquals( 1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime());
assertEquals( 1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime());
}

View file

@ -85,7 +85,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
public boolean detailedIOB = false;
public boolean showBGI = false;
public String openApsStatus = "0";
public Double openApsStatus;
public String externalStatusString = "no status";
public String sSgv = "---";
public String sDirection = "--";
@ -267,8 +267,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
sBgi = dataMap.getString("bgi");
showBGI = dataMap.getBoolean("showBgi");
externalStatusString = dataMap.getString("externalStatusString");
openApsStatus = dataMap.getString("openApsStatus");
batteryLevel = dataMap.getInt("batteryLevel");
openApsStatus = dataMap.getDouble("openApsStatus");
}
setDataFields();
@ -453,18 +453,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
if (mLoop != null) {
if (sharedPrefs.getBoolean("showExternalStatus", true)) {
mLoop.setVisibility(View.VISIBLE);
if (openApsStatus != null && openApsStatus != "") {
mLoop.setText(openApsStatus + "'");
if (Integer.valueOf(openApsStatus) > 14) {
if (openApsStatus != null) {
int mins = (int) ((System.currentTimeMillis() - openApsStatus) / 1000 / 60);
mLoop.setText(mins + "'");
if (mins > 14) {
loopLevel = 0;
//if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
mLoop.setBackgroundResource(R.drawable.loop_red_25);
//}
} else {
loopLevel = 1;
//if (getCurrentWatchMode() == WatchMode.INTERACTIVE) {
mLoop.setBackgroundResource(R.drawable.loop_green_25);
//}
}
} else {
mLoop.setText("-'");