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()); return Html.fromHtml(string.toString());
} }
public static double getOpenApsTimestamp() {
if (deviceStatusOpenAPSData.clockSuggested != 0) {
return deviceStatusOpenAPSData.clockSuggested;
} else {
return -1;
}
}
public Spanned getExtendedOpenApsStatus() { public Spanned getExtendedOpenApsStatus() {
StringBuilder string = new StringBuilder(); StringBuilder string = new StringBuilder();

View file

@ -552,13 +552,7 @@ public class WatchUpdaterService extends WearableListenerService implements
String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim(); String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim();
//OpenAPS status //OpenAPS status
String openApsString = String.valueOf(NSDeviceStatus.getInstance().getOpenApsStatus()); Double openApsStatus = NSDeviceStatus.getOpenApsTimestamp();
String openApsStatus = "";
if(openApsString != null) {
int index = openApsString.indexOf("m");
if(index > 0)
openApsStatus = openApsString.substring(0, index);
}
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH);
//unique content //unique content
@ -570,7 +564,7 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putString("tempBasal", tempBasal); dataMapRequest.getDataMap().putString("tempBasal", tempBasal);
dataMapRequest.getDataMap().putString("battery", "" + phoneBattery); dataMapRequest.getDataMap().putString("battery", "" + phoneBattery);
dataMapRequest.getDataMap().putString("rigBattery", rigBattery); dataMapRequest.getDataMap().putString("rigBattery", rigBattery);
dataMapRequest.getDataMap().putString("openApsStatus", openApsStatus); dataMapRequest.getDataMap().putDouble("openApsStatus", openApsStatus);
dataMapRequest.getDataMap().putString("bgi", bgiString); dataMapRequest.getDataMap().putString("bgi", bgiString);
dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false));
dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); 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 = "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 = "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: * Takes in an ISO date string of the following format:
@ -42,15 +43,31 @@ public class DateUtil {
throws Exception { throws Exception {
SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO, Locale.getDefault()); SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO, Locale.getDefault());
Date date; Date date;
f.setTimeZone(TimeZone.getTimeZone("UTC")); f.setTimeZone(TimeZone.getTimeZone("UTC"));
try { try {
date = f.parse(isoDateString); date = f.parse(isoDateString);
return date;
} catch (ParseException e) { } catch (ParseException e) {
f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC, Locale.getDefault());
f.setTimeZone(TimeZone.getTimeZone("UTC"));
date = f.parse(isoDateString);
} }
return date;
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) { public static String toISOString(Date date) {
return toISOString(date, FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC")); return toISOString(date, FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
} }
public static String toISOString(long date) { public static String toISOString(long date) {
return toISOString(new Date(date), FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC")); return toISOString(new Date(date), FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC"));
} }
@ -125,6 +143,7 @@ public class DateUtil {
public static String dateAndTimeString(Date date) { public static String dateAndTimeString(Date date) {
return dateString(date) + " " + timeString(date); return dateString(date) + " " + timeString(date);
} }
public static String dateAndTimeString(long mills) { public static String dateAndTimeString(long mills) {
return dateString(mills) + " " + timeString(mills); return dateString(mills) + " " + timeString(mills);
} }
@ -146,19 +165,19 @@ public class DateUtil {
} }
public static String timeFrameString(long timeInMillis){ public static String timeFrameString(long timeInMillis) {
long remainingTimeMinutes = timeInMillis/(1000*60); long remainingTimeMinutes = timeInMillis / (1000 * 60);
long remainingTimeHours = remainingTimeMinutes/60; long remainingTimeHours = remainingTimeMinutes / 60;
remainingTimeMinutes = remainingTimeMinutes%60; remainingTimeMinutes = remainingTimeMinutes % 60;
return "(" + ((remainingTimeHours >0)?(remainingTimeHours + "h "):"") + remainingTimeMinutes + "')"; return "(" + ((remainingTimeHours > 0) ? (remainingTimeHours + "h ") : "") + remainingTimeMinutes + "')";
} }
public static String sinceString(long timestamp){ public static String sinceString(long timestamp) {
return timeFrameString(System.currentTimeMillis()-timestamp); return timeFrameString(System.currentTimeMillis() - timestamp);
} }
public static String untilString(long timestamp){ public static String untilString(long timestamp) {
return timeFrameString(timestamp- System.currentTimeMillis()); return timeFrameString(timestamp - System.currentTimeMillis());
} }

View file

@ -19,6 +19,7 @@ public class DateUtilTest {
public void fromISODateStringTest() throws Exception { public void fromISODateStringTest() throws Exception {
assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime()); assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime());
assertEquals( 1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+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 detailedIOB = false;
public boolean showBGI = false; public boolean showBGI = false;
public String openApsStatus = "0"; public Double openApsStatus;
public String externalStatusString = "no status"; public String externalStatusString = "no status";
public String sSgv = "---"; public String sSgv = "---";
public String sDirection = "--"; public String sDirection = "--";
@ -267,8 +267,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
sBgi = dataMap.getString("bgi"); sBgi = dataMap.getString("bgi");
showBGI = dataMap.getBoolean("showBgi"); showBGI = dataMap.getBoolean("showBgi");
externalStatusString = dataMap.getString("externalStatusString"); externalStatusString = dataMap.getString("externalStatusString");
openApsStatus = dataMap.getString("openApsStatus");
batteryLevel = dataMap.getInt("batteryLevel"); batteryLevel = dataMap.getInt("batteryLevel");
openApsStatus = dataMap.getDouble("openApsStatus");
} }
setDataFields(); setDataFields();
@ -453,18 +453,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen
if (mLoop != null) { if (mLoop != null) {
if (sharedPrefs.getBoolean("showExternalStatus", true)) { if (sharedPrefs.getBoolean("showExternalStatus", true)) {
mLoop.setVisibility(View.VISIBLE); mLoop.setVisibility(View.VISIBLE);
if (openApsStatus != null && openApsStatus != "") { if (openApsStatus != null) {
mLoop.setText(openApsStatus + "'"); int mins = (int) ((System.currentTimeMillis() - openApsStatus) / 1000 / 60);
if (Integer.valueOf(openApsStatus) > 14) { mLoop.setText(mins + "'");
if (mins > 14) {
loopLevel = 0; loopLevel = 0;
//if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { mLoop.setBackgroundResource(R.drawable.loop_red_25);
mLoop.setBackgroundResource(R.drawable.loop_red_25);
//}
} else { } else {
loopLevel = 1; loopLevel = 1;
//if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { mLoop.setBackgroundResource(R.drawable.loop_green_25);
mLoop.setBackgroundResource(R.drawable.loop_green_25);
//}
} }
} else { } else {
mLoop.setText("-'"); mLoop.setText("-'");