wear status working
This commit is contained in:
parent
e2c3069374
commit
b93273d706
|
@ -204,4 +204,25 @@ public class TempBasal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toStringShort() {
|
||||||
|
String extended = isExtended ? "E" : "";
|
||||||
|
|
||||||
|
if (isAbsolute) {
|
||||||
|
return extended + DecimalFormatter.to2Decimal(absolute) + "U/h ";
|
||||||
|
} else { // percent
|
||||||
|
return percent + "% ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toStringMedium() {
|
||||||
|
String extended = isExtended ? "E" : "";
|
||||||
|
|
||||||
|
if (isAbsolute) {
|
||||||
|
return extended + DecimalFormatter.to2Decimal(absolute) + "U/h ("
|
||||||
|
+ getRealDuration() + "/" + duration + ") ";
|
||||||
|
} else { // percent
|
||||||
|
return percent + "% (" + getRealDuration() + "/" + duration + ") ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,4 +22,7 @@ public class WearFragment implements FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO Adrian: setting for short/long status string
|
||||||
|
//TODO Adrian: resend buttons
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,45 +74,67 @@ public class WearPlugin implements PluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendDataToWatch(){
|
private void sendDataToWatch(boolean status, boolean basals, boolean bgValue){
|
||||||
if (isEnabled(getType())) {
|
if (isEnabled(getType())) { //only start service when this plugin is enabled
|
||||||
|
|
||||||
|
if(bgValue){
|
||||||
ctx.startService(new Intent(ctx, WatchUpdaterService.class));
|
ctx.startService(new Intent(ctx, WatchUpdaterService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(basals){
|
||||||
|
//TODO send basals
|
||||||
|
}
|
||||||
|
|
||||||
|
if(status){
|
||||||
|
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_STATUS));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* @Subscribe
|
/* @Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
|
|
||||||
|
//TODO Adrian: probably a high/low mark change? Send it instantly?
|
||||||
sendDataToWatch();
|
sendDataToWatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventRefreshGui ev) {
|
public void onStatusEvent(final EventRefreshGui ev) {
|
||||||
|
|
||||||
|
//TODO Adrian: anything here that is not covered by other cases?
|
||||||
sendDataToWatch();
|
sendDataToWatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTreatmentChange ev) {
|
public void onStatusEvent(final EventTreatmentChange ev) {
|
||||||
sendDataToWatch();
|
sendDataToWatch(true, true, false);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||||
sendDataToWatch();
|
sendDataToWatch(true, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
sendDataToWatch();
|
|
||||||
|
sendDataToWatch(true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @Subscribe
|
/* @Subscribe
|
||||||
public void onStatusEvent(final EventNewOpenLoopNotification ev) {
|
public void onStatusEvent(final EventNewOpenLoopNotification ev) {
|
||||||
|
//TODO Adrian: Do they come through as notification cards already? update status?
|
||||||
sendDataToWatch();
|
sendDataToWatch();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBasalProfile ev) { sendDataToWatch(); }
|
public void onStatusEvent(final EventNewBasalProfile ev) {
|
||||||
|
sendDataToWatch(false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
return fragmentEnabled;
|
return fragmentEnabled;
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.Wear.wearintegration;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 14/02/16.
|
|
||||||
*/
|
|
||||||
public class ExternalStatusBroadcastReceier extends WakefulBroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
startWakefulService(context, new Intent(context, ExternalStatusService.class)
|
|
||||||
.setAction(ExternalStatusService.ACTION_NEW_EXTERNAL_STATUSLINE)
|
|
||||||
.putExtras(intent));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.Wear.wearintegration;
|
|
||||||
|
|
||||||
import android.app.IntentService;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 14/02/16.
|
|
||||||
*/
|
|
||||||
public class ExternalStatusService extends IntentService{
|
|
||||||
//constants
|
|
||||||
public static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
|
|
||||||
public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
|
|
||||||
public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
|
|
||||||
public static final int MAX_LEN = 40;
|
|
||||||
|
|
||||||
public ExternalStatusService() {
|
|
||||||
super("ExternalStatusService");
|
|
||||||
setIntentRedelivery(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onHandleIntent(Intent intent) {
|
|
||||||
|
|
||||||
if (intent == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
final String action = intent.getAction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
|
|
||||||
String statusline = intent.getStringExtra(EXTRA_STATUSLINE);
|
|
||||||
|
|
||||||
if(statusline.length() > MAX_LEN){
|
|
||||||
statusline = statusline.substring(0, MAX_LEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(statusline != null) {
|
|
||||||
// send to wear
|
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("wear_sync", false)) {
|
|
||||||
startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_STATUS).putExtra("externalStatusString", statusline));
|
|
||||||
/*By integrating the watch part of Nightwatch we inherited the same wakelock
|
|
||||||
problems NW had - so adding the same quick fix for now.
|
|
||||||
TODO: properly "wakelock" the wear (and probably pebble) services
|
|
||||||
*/
|
|
||||||
PowerManager powerManager = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
|
|
||||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
|
||||||
"quickFix4").acquire(15000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
WakefulBroadcastReceiver.completeWakefulIntent(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,8 +24,12 @@ import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
import info.nightscout.androidaps.db.TempBasal;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
|
||||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||||
import info.nightscout.client.data.NSProfile;
|
import info.nightscout.client.data.NSProfile;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
@ -102,7 +106,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
} else if (ACTION_OPEN_SETTINGS.equals(action)) {
|
} else if (ACTION_OPEN_SETTINGS.equals(action)) {
|
||||||
sendNotification();
|
sendNotification();
|
||||||
} else if (ACTION_SEND_STATUS.equals(action)) {
|
} else if (ACTION_SEND_STATUS.equals(action)) {
|
||||||
sendStatus(intent.getStringExtra("externalStatusString"));
|
sendStatus();
|
||||||
} else {
|
} else {
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
@ -248,8 +252,38 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendStatus(String status) {
|
private void sendStatus() {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
|
||||||
|
String status = "";
|
||||||
|
|
||||||
|
//TODO Adrian: Setting if short or medium string.
|
||||||
|
|
||||||
|
boolean shortString = true;
|
||||||
|
|
||||||
|
//Temp basal
|
||||||
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
|
|
||||||
|
if (pump.isTempBasalInProgress()) {
|
||||||
|
TempBasal activeTemp = pump.getTempBasal();
|
||||||
|
if (shortString) {
|
||||||
|
status += activeTemp.toStringShort();
|
||||||
|
} else {
|
||||||
|
status += activeTemp.toStringMedium();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//IOB
|
||||||
|
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||||
|
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||||
|
if (bolusIob == null) bolusIob = new IobTotal();
|
||||||
|
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||||
|
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||||
|
if (basalIob == null) basalIob = new IobTotal();
|
||||||
|
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "("
|
||||||
|
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
|
||||||
|
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
|
||||||
|
|
||||||
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH);
|
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH);
|
||||||
//unique content
|
//unique content
|
||||||
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
||||||
|
|
|
@ -78,6 +78,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
private String rawString = "000 | 000 | 000";
|
private String rawString = "000 | 000 | 000";
|
||||||
private String batteryString = "--";
|
private String batteryString = "--";
|
||||||
private String sgvString = "--";
|
private String sgvString = "--";
|
||||||
|
private String externalStatusString = "no status";
|
||||||
|
private TextView statusView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
@ -122,8 +124,9 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
mDelta = (TextView) stub.findViewById(R.id.delta);
|
mDelta = (TextView) stub.findViewById(R.id.delta);
|
||||||
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
|
||||||
chart = (LineChartView) stub.findViewById(R.id.chart);
|
chart = (LineChartView) stub.findViewById(R.id.chart);
|
||||||
|
statusView = (TextView) stub.findViewById(R.id.aps_status);
|
||||||
layoutSet = true;
|
layoutSet = true;
|
||||||
showAgoRawBatt();
|
showAgeAndStatus();
|
||||||
mRelativeLayout.measure(specW, specH);
|
mRelativeLayout.measure(specW, specH);
|
||||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
mRelativeLayout.getMeasuredHeight());
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
@ -185,7 +188,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
wakeLock.acquire(50);
|
wakeLock.acquire(50);
|
||||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
|
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
|
||||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||||
showAgoRawBatt();
|
showAgeAndStatus();
|
||||||
|
|
||||||
if(ageLevel()<=0) {
|
if(ageLevel()<=0) {
|
||||||
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||||
|
@ -204,11 +207,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Bundle bundle = intent.getBundleExtra("data");
|
Bundle bundle = intent.getBundleExtra("data");
|
||||||
if (bundle ==null){
|
if (layoutSet && bundle !=null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
DataMap dataMap = DataMap.fromBundle(bundle);
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||||
if (layoutSet) {
|
|
||||||
wakeLock.acquire(50);
|
wakeLock.acquire(50);
|
||||||
sgvLevel = dataMap.getLong("sgvLevel");
|
sgvLevel = dataMap.getLong("sgvLevel");
|
||||||
batteryLevel = dataMap.getInt("batteryLevel");
|
batteryLevel = dataMap.getInt("batteryLevel");
|
||||||
|
@ -227,7 +227,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
|
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
|
||||||
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
mTime.setText(timeFormat.format(System.currentTimeMillis()));
|
||||||
|
|
||||||
showAgoRawBatt();
|
showAgeAndStatus();
|
||||||
|
|
||||||
String delta = dataMap.getString("delta");
|
String delta = dataMap.getString("delta");
|
||||||
|
|
||||||
|
@ -254,22 +254,42 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
|
if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (sgvString.equals("100") || sgvString.equals("5.5") || sgvString.equals("5,5"))) {
|
||||||
startAnimation();
|
startAnimation();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//status
|
||||||
|
bundle = intent.getBundleExtra("status");
|
||||||
|
if (layoutSet && bundle != null) {
|
||||||
|
DataMap dataMap = DataMap.fromBundle(bundle);
|
||||||
|
wakeLock.acquire(50);
|
||||||
|
externalStatusString = dataMap.getString("externalStatusString");
|
||||||
|
|
||||||
|
showAgeAndStatus();
|
||||||
|
|
||||||
} else {
|
mRelativeLayout.measure(specW, specH);
|
||||||
Log.d("ERROR: ", "DATA IS NOT YET SET");
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
invalidate();
|
||||||
|
setColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showAgoRawBatt() {
|
private void showAgeAndStatus() {
|
||||||
|
|
||||||
if( mTimestamp == null){
|
if( mTimestamp != null){
|
||||||
return;
|
|
||||||
}
|
|
||||||
mTimestamp.setText(readingAge(true));
|
mTimestamp.setText(readingAge(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean showStatus = sharedPrefs.getBoolean("showExternalStatus", false);
|
||||||
|
|
||||||
|
|
||||||
|
if(showStatus){
|
||||||
|
statusView.setText(externalStatusString);
|
||||||
|
statusView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
statusView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setColor() {
|
public void setColor() {
|
||||||
if (sharedPrefs.getBoolean("dark", true)) {
|
if (sharedPrefs.getBoolean("dark", true)) {
|
||||||
setColorDark();
|
setColorDark();
|
||||||
|
@ -285,7 +305,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
|
||||||
setColor();
|
setColor();
|
||||||
if(layoutSet){
|
if(layoutSet){
|
||||||
showAgoRawBatt();
|
showAgeAndStatus();
|
||||||
mRelativeLayout.measure(specW, specH);
|
mRelativeLayout.measure(specW, specH);
|
||||||
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
|
||||||
mRelativeLayout.getMeasuredHeight());
|
mRelativeLayout.getMeasuredHeight());
|
||||||
|
@ -347,6 +367,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
|
|
||||||
protected void setColorDark() {
|
protected void setColorDark() {
|
||||||
mTime.setTextColor(Color.WHITE);
|
mTime.setTextColor(Color.WHITE);
|
||||||
|
statusView.setTextColor(Color.WHITE);
|
||||||
mRelativeLayout.setBackgroundColor(Color.BLACK);
|
mRelativeLayout.setBackgroundColor(Color.BLACK);
|
||||||
if (sgvLevel == 1) {
|
if (sgvLevel == 1) {
|
||||||
mSgv.setTextColor(Color.YELLOW);
|
mSgv.setTextColor(Color.YELLOW);
|
||||||
|
@ -404,6 +425,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
|
|
||||||
|
|
||||||
mTime.setTextColor(Color.BLACK);
|
mTime.setTextColor(Color.BLACK);
|
||||||
|
statusView.setTextColor(Color.BLACK);
|
||||||
if (chart != null) {
|
if (chart != null) {
|
||||||
highColor = Utils.COLOR_ORANGE;
|
highColor = Utils.COLOR_ORANGE;
|
||||||
midColor = Color.BLUE;
|
midColor = Color.BLUE;
|
||||||
|
@ -425,6 +447,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
|
||||||
mDelta.setTextColor(Color.RED);
|
mDelta.setTextColor(Color.RED);
|
||||||
}
|
}
|
||||||
mTimestamp.setTextColor(Color.WHITE);
|
mTimestamp.setTextColor(Color.WHITE);
|
||||||
|
statusView.setTextColor(Color.WHITE);
|
||||||
|
|
||||||
mTime.setTextColor(Color.WHITE);
|
mTime.setTextColor(Color.WHITE);
|
||||||
if (chart != null) {
|
if (chart != null) {
|
||||||
|
|
Loading…
Reference in a new issue