wear status working

This commit is contained in:
AdrianLxM 2016-11-17 21:51:29 +01:00
parent e2c3069374
commit b93273d706
7 changed files with 132 additions and 107 deletions

View file

@ -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 + ") ";
}
}
}

View file

@ -22,4 +22,7 @@ public class WearFragment implements FragmentBase {
}
//TODO Adrian: setting for short/long status string
//TODO Adrian: resend buttons
}

View file

@ -74,45 +74,67 @@ public class WearPlugin implements PluginBase {
}
private void sendDataToWatch(){
if (isEnabled(getType())) {
ctx.startService(new Intent(ctx, WatchUpdaterService.class));
private void sendDataToWatch(boolean status, boolean basals, boolean bgValue){
if (isEnabled(getType())) { //only start service when this plugin is enabled
if(bgValue){
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
public void onStatusEvent(final EventPreferenceChange ev) {
//TODO Adrian: probably a high/low mark change? Send it instantly?
sendDataToWatch();
}
@Subscribe
public void onStatusEvent(final EventRefreshGui ev) {
sendDataToWatch();
//TODO Adrian: anything here that is not covered by other cases?
sendDataToWatch();
}
*/
@Subscribe
public void onStatusEvent(final EventTreatmentChange ev) {
sendDataToWatch(true, true, false);
}
@Subscribe
public void onStatusEvent(final EventTreatmentChange ev) {
sendDataToWatch();
}*/
@Subscribe
public void onStatusEvent(final EventTempBasalChange ev) {
sendDataToWatch();
sendDataToWatch(true, true, false);
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
sendDataToWatch();
sendDataToWatch(true, true, true);
}
/* @Subscribe
public void onStatusEvent(final EventNewOpenLoopNotification ev) {
//TODO Adrian: Do they come through as notification cards already? update status?
sendDataToWatch();
}*/
@Subscribe
public void onStatusEvent(final EventNewBasalProfile ev) { sendDataToWatch(); }
public void onStatusEvent(final EventNewBasalProfile ev) {
sendDataToWatch(false, true, false);
}
public static boolean isEnabled() {
return fragmentEnabled;

View file

@ -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));
}
}

View file

@ -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);
}
}
}

View file

@ -24,8 +24,12 @@ import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
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.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
@ -102,7 +106,7 @@ public class WatchUpdaterService extends WearableListenerService implements
} else if (ACTION_OPEN_SETTINGS.equals(action)) {
sendNotification();
} else if (ACTION_SEND_STATUS.equals(action)) {
sendStatus(intent.getStringExtra("externalStatusString"));
sendStatus();
} else {
sendData();
}
@ -248,8 +252,38 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
private void sendStatus(String status) {
private void sendStatus() {
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);
//unique content
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());

View file

@ -78,6 +78,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
private String rawString = "000 | 000 | 000";
private String batteryString = "--";
private String sgvString = "--";
private String externalStatusString = "no status";
private TextView statusView;
@Override
public void onCreate() {
@ -122,8 +124,9 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
mDelta = (TextView) stub.findViewById(R.id.delta);
mRelativeLayout = (RelativeLayout) stub.findViewById(R.id.main_layout);
chart = (LineChartView) stub.findViewById(R.id.chart);
statusView = (TextView) stub.findViewById(R.id.aps_status);
layoutSet = true;
showAgoRawBatt();
showAgeAndStatus();
mRelativeLayout.measure(specW, specH);
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
mRelativeLayout.getMeasuredHeight());
@ -185,7 +188,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
wakeLock.acquire(50);
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BIGChart.this);
mTime.setText(timeFormat.format(System.currentTimeMillis()));
showAgoRawBatt();
showAgeAndStatus();
if(ageLevel()<=0) {
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
@ -204,11 +207,8 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getBundleExtra("data");
if (bundle ==null){
return;
}
DataMap dataMap = DataMap.fromBundle(bundle);
if (layoutSet) {
if (layoutSet && bundle !=null) {
DataMap dataMap = DataMap.fromBundle(bundle);
wakeLock.acquire(50);
sgvLevel = dataMap.getLong("sgvLevel");
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);
mTime.setText(timeFormat.format(System.currentTimeMillis()));
showAgoRawBatt();
showAgeAndStatus();
String delta = dataMap.getString("delta");
@ -254,20 +254,40 @@ 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"))) {
startAnimation();
}
}
//status
bundle = intent.getBundleExtra("status");
if (layoutSet && bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
wakeLock.acquire(50);
externalStatusString = dataMap.getString("externalStatusString");
showAgeAndStatus();
} else {
Log.d("ERROR: ", "DATA IS NOT YET SET");
mRelativeLayout.measure(specW, specH);
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
mRelativeLayout.getMeasuredHeight());
invalidate();
setColor();
}
}
}
private void showAgoRawBatt() {
private void showAgeAndStatus() {
if( mTimestamp == null){
return;
if( mTimestamp != null){
mTimestamp.setText(readingAge(true));
}
boolean showStatus = sharedPrefs.getBoolean("showExternalStatus", false);
if(showStatus){
statusView.setText(externalStatusString);
statusView.setVisibility(View.VISIBLE);
} else {
statusView.setVisibility(View.GONE);
}
mTimestamp.setText(readingAge(true));
}
public void setColor() {
@ -285,7 +305,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
setColor();
if(layoutSet){
showAgoRawBatt();
showAgeAndStatus();
mRelativeLayout.measure(specW, specH);
mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(),
mRelativeLayout.getMeasuredHeight());
@ -347,6 +367,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
protected void setColorDark() {
mTime.setTextColor(Color.WHITE);
statusView.setTextColor(Color.WHITE);
mRelativeLayout.setBackgroundColor(Color.BLACK);
if (sgvLevel == 1) {
mSgv.setTextColor(Color.YELLOW);
@ -404,6 +425,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
mTime.setTextColor(Color.BLACK);
statusView.setTextColor(Color.BLACK);
if (chart != null) {
highColor = Utils.COLOR_ORANGE;
midColor = Color.BLUE;
@ -425,6 +447,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
mDelta.setTextColor(Color.RED);
}
mTimestamp.setTextColor(Color.WHITE);
statusView.setTextColor(Color.WHITE);
mTime.setTextColor(Color.WHITE);
if (chart != null) {