send notification about TBR request to the wearable

This commit is contained in:
Sebastian Lenz 2018-07-25 23:37:26 +02:00
parent 5bb6635cab
commit e2ef8f2d74
6 changed files with 95 additions and 2 deletions

View file

@ -45,6 +45,7 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
@ -385,7 +386,8 @@ public class LoopPlugin extends PluginBase {
.setAutoCancel(true) .setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH) .setPriority(Notification.PRIORITY_HIGH)
.setCategory(Notification.CATEGORY_ALARM) .setCategory(Notification.CATEGORY_ALARM)
.setVisibility(Notification.VISIBILITY_PUBLIC); .setVisibility(Notification.VISIBILITY_PUBLIC)
.setLocalOnly(true);
// Creates an explicit intent for an Activity in your app // Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class); Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class);
@ -407,10 +409,15 @@ public class LoopPlugin extends PluginBase {
// mId allows you to update the notification later on. // mId allows you to update the notification later on.
mNotificationManager.notify(Constants.notificationID, builder.build()); mNotificationManager.notify(Constants.notificationID, builder.build());
MainApp.bus().post(new EventNewOpenLoopNotification()); MainApp.bus().post(new EventNewOpenLoopNotification());
// Send to Wear
ActionStringHandler.handleInitiate("changeRequest");
} else if (allowNotification) {
// dismiss notifications // dismiss notifications
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.notificationID); notificationManager.cancel(Constants.notificationID);
ActionStringHandler.handleInitiate("cancelChangeRequest");
} }
} }

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.Wear; package info.nightscout.androidaps.plugins.Wear;
import android.content.Context;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.crashlytics.android.answers.CustomEvent;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -352,6 +354,17 @@ public class ActionStringHandler {
} }
rAction += "ecarbs " + carbsAfterConstraints + " " + starttimestamp + " " + duration; rAction += "ecarbs " + carbsAfterConstraints + " " + starttimestamp + " " + duration;
} else if ("changeRequest".equals(act[0])) {
////////////////////////////////////////////// CHANGE REQUEST
rTitle = MainApp.gs(R.string.openloop_newsuggestion);
rAction = "changeRequest";
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
rMessage += finalLastRun.constraintsProcessed;
WearPlugin.getPlugin().requestChangeConfirmation(rTitle, rMessage, rAction);
lastSentTimestamp = System.currentTimeMillis();
lastConfirmActionString = rAction;
return;
} else return; } else return;

View file

@ -192,6 +192,15 @@ public class WearPlugin extends PluginBase {
ctx.startService(intent); ctx.startService(intent);
} }
public void requestChangeConfirmation(String title, String message, String actionstring) {
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_CHANGECONFIRMATIONREQUEST);
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.putExtra("actionstring", actionstring);
ctx.startService(intent);
}
public static void registerWatchUpdaterService(WatchUpdaterService wus) { public static void registerWatchUpdaterService(WatchUpdaterService wus) {
watchUS = wus; watchUS = wus;
} }

View file

@ -64,6 +64,7 @@ public class WatchUpdaterService extends WearableListenerService implements
public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress"); public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress");
public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest"); public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest");
public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest");
private GoogleApiClient googleApiClient; private GoogleApiClient googleApiClient;
public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
@ -78,6 +79,7 @@ public class WatchUpdaterService extends WearableListenerService implements
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal"; public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
public static final String ACTION_CHANGECONFIRMATION_REQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
boolean wear_integration = false; boolean wear_integration = false;
@ -153,6 +155,11 @@ public class WatchUpdaterService extends WearableListenerService implements
String message = intent.getStringExtra("message"); String message = intent.getStringExtra("message");
String actionstring = intent.getStringExtra("actionstring"); String actionstring = intent.getStringExtra("actionstring");
sendActionConfirmationRequest(title, message, actionstring); sendActionConfirmationRequest(title, message, actionstring);
} else if (ACTION_SEND_CHANGECONFIRMATIONREQUEST.equals(action)) {
String title = intent.getStringExtra("title");
String message = intent.getStringExtra("message");
String actionstring = intent.getStringExtra("actionstring");
sendChangeConfirmationRequest(title, message, actionstring);
} else { } else {
sendData(); sendData();
} }
@ -577,6 +584,25 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
} }
private void sendChangeConfirmationRequest(String title, String message, String actionstring) {
if (googleApiClient.isConnected()) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CHANGECONFIRMATION_REQUEST_PATH);
//unique content
dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putString("changeConfirmationRequest", "changeConfirmationRequest");
dataMapRequest.getDataMap().putString("title", title);
dataMapRequest.getDataMap().putString("message", message);
dataMapRequest.getDataMap().putString("actionstring", actionstring);
log.debug("Requesting confirmation from wear: " + actionstring);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("changeConfirmRequest", "No connection to wearable available!");
}
}
private void sendStatus() { private void sendStatus() {
if (googleApiClient.isConnected()) { if (googleApiClient.isConnected()) {

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.data; package info.nightscout.androidaps.data;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -49,10 +51,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal"; public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest"; public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
public static final String NEW_CHANGECONFIRMATIONREQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
public static final int BOLUS_PROGRESS_NOTIF_ID = 001; public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
public static final int CONFIRM_NOTIF_ID = 002; public static final int CONFIRM_NOTIF_ID = 002;
public static final int CHANGE_NOTIF_ID = 556677;
private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA";
private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS";
@ -294,6 +298,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
editor.putBoolean("wearcontrol", wearcontrol); editor.putBoolean("wearcontrol", wearcontrol);
editor.commit(); editor.commit();
} }
} else if (path.equals(NEW_CHANGECONFIRMATIONREQUEST_PATH)) {
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
notifyChangeRequest(title, message, actionstring);
} else { } else {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent(); Intent messageIntent = new Intent();
@ -305,6 +314,35 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
} }
private void notifyChangeRequest(String title, String message, String actionstring) {
Notification.Builder builder =
new Notification.Builder(this); //,"AndroidAPS-Openloop");
builder.setSmallIcon(R.drawable.notif_icon)
.setContentTitle(title)
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH);
// Creates an explicit intent for an Activity in your app
Intent intent = new Intent(this, AcceptActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle params = new Bundle();
params.putString("title", title);
params.putString("message", message);
params.putString("actionstring", actionstring);
intent.putExtras(params);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(CHANGE_NOTIF_ID, builder.build());
}
private void showBolusProgress(int progresspercent, String progresstatus) { private void showBolusProgress(int progresspercent, String progresstatus) {
Intent cancelIntent = new Intent(this, ListenerService.class); Intent cancelIntent = new Intent(this, ListenerService.class);
cancelIntent.setAction(ACTION_CANCELBOLUS); cancelIntent.setAction(ACTION_CANCELBOLUS);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB