Wear added bolusprogress and dismiss when finished

This commit is contained in:
AdrianLxM 2017-02-07 09:17:19 +01:00
parent 10d71325dd
commit f4b553fe52
4 changed files with 42 additions and 24 deletions

View file

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

View file

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

View file

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

View file

@ -106,14 +106,6 @@
<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/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/resources" 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/rs" 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/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />