Wear added bolusprogress and dismiss when finished
This commit is contained in:
parent
10d71325dd
commit
f4b553fe52
4 changed files with 42 additions and 24 deletions
|
@ -147,6 +147,7 @@ public class WearPlugin implements PluginBase {
|
||||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||||
intent.putExtra("progresspercent", ev.percent);
|
intent.putExtra("progresspercent", ev.percent);
|
||||||
|
intent.putExtra("progressstatus", ev.status);
|
||||||
ctx.startService(intent);
|
ctx.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
} else if (ACTION_SEND_BASALS.equals(action)) {
|
} else if (ACTION_SEND_BASALS.equals(action)) {
|
||||||
sendBasals();
|
sendBasals();
|
||||||
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){
|
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){
|
||||||
sendBolusProgress(intent.getIntExtra("progresspercent", 0));
|
sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus")?intent.getStringExtra("progressstatus"):"");
|
||||||
} else {
|
} else {
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,6 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelBolus() {
|
private void cancelBolus() {
|
||||||
//ToastUtils.showToastInUiThread(this, "cancelBolus()");
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
pump.stopBolusDelivering();
|
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()) {
|
if (googleApiClient.isConnected()) {
|
||||||
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(BOLUS_PROGRESS_PATH);
|
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(BOLUS_PROGRESS_PATH);
|
||||||
//unique content
|
//unique content
|
||||||
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
||||||
dataMapRequest.getDataMap().putString("bolusProgress", "bolusProgress");
|
dataMapRequest.getDataMap().putString("bolusProgress", "bolusProgress");
|
||||||
|
dataMapRequest.getDataMap().putString("progressstatus", status);
|
||||||
dataMapRequest.getDataMap().putInt("progresspercent", progresspercent);
|
dataMapRequest.getDataMap().putInt("progresspercent", progresspercent);
|
||||||
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||||
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps;
|
package info.nightscout.androidaps;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -8,7 +9,6 @@ import android.os.Bundle;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.support.v4.app.NotificationCompat.WearableExtender;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
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 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 int NOTIFICATION_ID = 001;
|
||||||
|
|
||||||
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";
|
||||||
|
@ -151,7 +151,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else if (path.equals(BOLUS_PROGRESS_PATH)) {
|
} else if (path.equals(BOLUS_PROGRESS_PATH)) {
|
||||||
int progress = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getInt("progresspercent", 0);
|
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)) {
|
} else if (path.equals(NEW_STATUS_PATH)) {
|
||||||
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
||||||
Intent messageIntent = new Intent();
|
Intent messageIntent = new Intent();
|
||||||
|
@ -175,10 +176,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBolusProgress(int progresspercent) {
|
private void showBolusProgress(int progresspercent, String progresstatus) {
|
||||||
int notificationId = 001;
|
|
||||||
// Build intent for notification content
|
|
||||||
//TODO: Add Action in order to see that it is a cancel event
|
|
||||||
Intent cancelIntent = new Intent(this, ListenerService.class);
|
Intent cancelIntent = new Intent(this, ListenerService.class);
|
||||||
cancelIntent.setAction(ACTION_CANCELBOLUS);
|
cancelIntent.setAction(ACTION_CANCELBOLUS);
|
||||||
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);;
|
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);;
|
||||||
|
@ -187,24 +185,43 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
new NotificationCompat.Builder(this)
|
new NotificationCompat.Builder(this)
|
||||||
.setSmallIcon(R.drawable.ic_icon)
|
.setSmallIcon(R.drawable.ic_icon)
|
||||||
.setContentTitle("Bolus Progress")
|
.setContentTitle("Bolus Progress")
|
||||||
.setContentText(progresspercent + "%")
|
.setContentText(progresspercent + "% - " + progresstatus)
|
||||||
.setContentIntent(cancelPendingIntent)
|
.setContentIntent(cancelPendingIntent)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
.setVibrate(new long[]{0, 100, 1000})
|
.setVibrate(new long[]{0, 50, 1000})
|
||||||
.addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent);
|
.addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent);
|
||||||
|
|
||||||
//TODO: set separate cancel extension with icon
|
|
||||||
|
|
||||||
// Get an instance of the NotificationManager service
|
// Get an instance of the NotificationManager service
|
||||||
NotificationManagerCompat notificationManager =
|
NotificationManagerCompat notificationManager =
|
||||||
NotificationManagerCompat.from(this);
|
NotificationManagerCompat.from(this);
|
||||||
|
|
||||||
// Build the notification and issues it with notification manager.
|
// 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) {
|
public static void requestData(Context context) {
|
||||||
Intent intent = new Intent(context, ListenerService.class);
|
Intent intent = new Intent(context, ListenerService.class);
|
||||||
intent.setAction(ACTION_RESEND);
|
intent.setAction(ACTION_RESEND);
|
||||||
|
|
|
@ -106,14 +106,6 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||||
|
@ -122,6 +114,14 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
|
|
Loading…
Reference in a new issue