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 2941148ce5..9ee4e974a8 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
@@ -147,6 +147,7 @@ public class WearPlugin implements PluginBase {
public void onStatusEvent(final EventOverviewBolusProgress ev) {
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
intent.putExtra("progresspercent", ev.percent);
+ intent.putExtra("progressstatus", ev.status);
ctx.startService(intent);
}
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 7f5575e01d..e84ab99730 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
@@ -120,7 +120,7 @@ public class WatchUpdaterService extends WearableListenerService implements
} else if (ACTION_SEND_BASALS.equals(action)) {
sendBasals();
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){
- sendBolusProgress(intent.getIntExtra("progresspercent", 0));
+ sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus")?intent.getStringExtra("progressstatus"):"");
} else {
sendData();
}
@@ -152,7 +152,6 @@ public class WatchUpdaterService extends WearableListenerService implements
}
private void cancelBolus() {
- //ToastUtils.showToastInUiThread(this, "cancelBolus()");
PumpInterface pump = MainApp.getConfigBuilder();
pump.stopBolusDelivering();
}
@@ -440,12 +439,13 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
- private void sendBolusProgress(int progresspercent) {
+ private void sendBolusProgress(int progresspercent, String status) {
if (googleApiClient.isConnected()) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(BOLUS_PROGRESS_PATH);
//unique content
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putString("bolusProgress", "bolusProgress");
+ dataMapRequest.getDataMap().putString("progressstatus", status);
dataMapRequest.getDataMap().putInt("progresspercent", progresspercent);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
diff --git a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java
index b38f138c23..9cb724bac9 100644
--- a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java
+++ b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java
@@ -1,5 +1,6 @@
package info.nightscout.androidaps;
+import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -8,7 +9,6 @@ import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
-import android.support.v4.app.NotificationCompat.WearableExtender;
import com.google.android.gms.common.ConnectionResult;
@@ -38,7 +38,7 @@ 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 int NOTIFICATION_ID = 001;
private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA";
private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS";
@@ -151,7 +151,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
startActivity(intent);
} else if (path.equals(BOLUS_PROGRESS_PATH)) {
int progress = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getInt("progresspercent", 0);
- showBolusProgress(progress);
+ String status = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("progressstatus", "");
+ showBolusProgress(progress, status);
} else if (path.equals(NEW_STATUS_PATH)) {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();
@@ -175,10 +176,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
}
}
- private void showBolusProgress(int progresspercent) {
- int notificationId = 001;
- // Build intent for notification content
- //TODO: Add Action in order to see that it is a cancel event
+ private void showBolusProgress(int progresspercent, String progresstatus) {
Intent cancelIntent = new Intent(this, ListenerService.class);
cancelIntent.setAction(ACTION_CANCELBOLUS);
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);;
@@ -187,24 +185,43 @@ public class ListenerService extends WearableListenerService implements GoogleAp
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_icon)
.setContentTitle("Bolus Progress")
- .setContentText(progresspercent + "%")
+ .setContentText(progresspercent + "% - " + progresstatus)
.setContentIntent(cancelPendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
- .setVibrate(new long[]{0, 100, 1000})
+ .setVibrate(new long[]{0, 50, 1000})
.addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent);
- //TODO: set separate cancel extension with icon
-
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
// Build the notification and issues it with notification manager.
- notificationManager.notify(notificationId, notificationBuilder.build());
+ notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
- //TODO: Cancel notification when 100%
+ if (progresspercent == 100){
+ scheduleDismiss();
+ }
}
+ private void scheduleDismiss() {
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ NotificationManagerCompat notificationManager =
+ NotificationManagerCompat.from(ListenerService.this);
+ notificationManager.cancel(NOTIFICATION_ID);
+ }
+ });
+ t.start();
+ }
+
+
+
public static void requestData(Context context) {
Intent intent = new Intent(context, ListenerService.class);
intent.setAction(ACTION_RESEND);
diff --git a/wear/wear.iml b/wear/wear.iml
index 33cd39a6c1..20c1f89da7 100644
--- a/wear/wear.iml
+++ b/wear/wear.iml
@@ -106,14 +106,6 @@
-
-
-
-
-
-
-
-
@@ -122,6 +114,14 @@
+
+
+
+
+
+
+
+