From e2ef8f2d7480f77a3984a42cbbb4af9c95fe5dae Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Wed, 25 Jul 2018 23:37:26 +0200 Subject: [PATCH] send notification about TBR request to the wearable --- .../androidaps/plugins/Loop/LoopPlugin.java | 9 +++- .../plugins/Wear/ActionStringHandler.java | 13 ++++++ .../androidaps/plugins/Wear/WearPlugin.java | 9 ++++ .../wearintegration/WatchUpdaterService.java | 26 ++++++++++++ .../androidaps/data/ListenerService.java | 40 +++++++++++++++++- wear/src/main/res/drawable/notif_icon.png | Bin 0 -> 3123 bytes 6 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 wear/src/main/res/drawable/notif_icon.png diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 59fbb7e694..ff0037e6a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -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.EventNewOpenLoopNotification; 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.commands.Command; import info.nightscout.utils.FabricPrivacy; @@ -385,7 +386,8 @@ public class LoopPlugin extends PluginBase { .setAutoCancel(true) .setPriority(Notification.PRIORITY_HIGH) .setCategory(Notification.CATEGORY_ALARM) - .setVisibility(Notification.VISIBILITY_PUBLIC); + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setLocalOnly(true); // Creates an explicit intent for an Activity in your app 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. mNotificationManager.notify(Constants.notificationID, builder.build()); MainApp.bus().post(new EventNewOpenLoopNotification()); + + // Send to Wear + ActionStringHandler.handleInitiate("changeRequest"); + } else if (allowNotification) { // dismiss notifications NotificationManager notificationManager = (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(Constants.notificationID); + ActionStringHandler.handleInitiate("cancelChangeRequest"); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index fc4728c53c..e8b102f8d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -1,8 +1,10 @@ package info.nightscout.androidaps.plugins.Wear; +import android.content.Context; import android.os.HandlerThread; import android.support.annotation.NonNull; +import com.crashlytics.android.answers.CustomEvent; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -352,6 +354,17 @@ public class ActionStringHandler { } 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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 6cb47e1a3a..1250d5c8df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -192,6 +192,15 @@ public class WearPlugin extends PluginBase { 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) { watchUS = wus; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index b5d30ad071..f8144a30bf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -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_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest"); + public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest"); private GoogleApiClient googleApiClient; 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 BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; 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; @@ -153,6 +155,11 @@ public class WatchUpdaterService extends WearableListenerService implements String message = intent.getStringExtra("message"); String actionstring = intent.getStringExtra("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 { 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() { if (googleApiClient.isConnected()) { diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index 7297d51815..403d8d0ddd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.data; +import android.app.Notification; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; 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 BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress"; 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 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_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; @@ -273,7 +277,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp showConfirmationDialog(title, message, actionstring); } - }else if (path.equals(NEW_STATUS_PATH)) { + } else if (path.equals(NEW_STATUS_PATH)) { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); messageIntent.setAction(Intent.ACTION_SEND); @@ -294,6 +298,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp editor.putBoolean("wearcontrol", wearcontrol); 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 { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); 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) { Intent cancelIntent = new Intent(this, ListenerService.class); cancelIntent.setAction(ACTION_CANCELBOLUS); diff --git a/wear/src/main/res/drawable/notif_icon.png b/wear/src/main/res/drawable/notif_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..480d0eaf778f20b95946a31a32b13136dd303327 GIT binary patch literal 3123 zcmV-349xS1P)YSa3NT8xcWW2r_`YmK$W zN43?a!ABz1sI;KfR#UY_L~ZMX`luqW6|D=(;6htb5In4~3)4T&H+4A9oO|xwyYx$L zcJIC4oSE-2-}@?h5R%kZfEJ)P&)o|Wjfo}rsNosErTarIp&uD;?dXn0mfOCMGfq^BKZW05x z23QMxEPp?hGxP;^2L{OV_5_BC@vH{#0apQ!8Lhf%y%wqt;`ab%0H;=2Z-HllC*=ON z18a;{8>{ToUl=e17zLaROsI0aF5q{-#YU^N7AB|~i9cM3+O5ix+km@({{S6%Hx@cz z;m)ZX-2D8i1So>!q z#4iCR8m(GAiGL|c?JQtE@YNE;103eyp%-1vEKNW3+k=7%%QH5B-4W zlhpQc*Q_c7JU>4pV(pj6{d(U$FiGvnz?%{q)B-+pKQ4ja0z3pfn4~uGY{wGWJH&+H z!0kzDD^)chNv%_>bHvYw)PAzj>a8TTN)B+f9BODCk*M_;{~>Tk$#rJ{bCT4KbXUP> z^|C~W>jU`b0h3GFfF!j8fVTq?UI#G7Xw~Xnlly=v^@P+;>PD;GyyrEEi@RQuscO&x z9OD~0u|e|#xbH}Iy2;ms(7}He32!fzhz?KkMZ{YPb?*XxT||X z)C6L%GcYen?E&5$e+9T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