wear dismiss progressnotification on cancel + stub for treatment confirmation
This commit is contained in:
parent
20d32d042f
commit
d1a3645be7
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -39,10 +38,13 @@ 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;
|
||||
public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
|
||||
public static final int CONFIRM_NOTIF_ID = 002;
|
||||
|
||||
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_CONFIRMATION = "com.dexdrip.stephenblack.nightwatch.CONFIRMACTION";
|
||||
|
||||
|
||||
private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
|
||||
GoogleApiClient googleApiClient;
|
||||
|
@ -130,7 +132,26 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
requestData();
|
||||
} else if(intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())){
|
||||
googleApiConnect();
|
||||
|
||||
//dismiss notification
|
||||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(ListenerService.this);
|
||||
notificationManager.cancel(BOLUS_PROGRESS_NOTIF_ID);
|
||||
|
||||
//send cancel-request to phone.
|
||||
cancelBolus();
|
||||
|
||||
|
||||
} else if(intent != null && ACTION_CONFIRMATION.equals(intent.getAction())){
|
||||
googleApiConnect();
|
||||
|
||||
//dismiss notification
|
||||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(ListenerService.this);
|
||||
notificationManager.cancel(CONFIRM_NOTIF_ID);
|
||||
|
||||
|
||||
//TODO: send confirmation string to phone
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
@ -204,25 +225,53 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(this);
|
||||
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||
notificationManager.notify(BOLUS_PROGRESS_NOTIF_ID, notificationBuilder.build());
|
||||
|
||||
if (progresspercent == 100){
|
||||
scheduleDismiss();
|
||||
scheduleDismiss(BOLUS_PROGRESS_NOTIF_ID, 5);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleDismiss() {
|
||||
private void showConfirmationDialog(String title, String message, String actionstring) {
|
||||
|
||||
Intent actionIntent = new Intent(this, ListenerService.class);
|
||||
actionIntent.setAction(ACTION_CONFIRMATION);
|
||||
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, 0);;
|
||||
|
||||
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
|
||||
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_icon)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setContentIntent(actionPendingIntent)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setVibrate(vibratePattern)
|
||||
.addAction(R.drawable.ic_confirm, title, actionPendingIntent);
|
||||
|
||||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(this);
|
||||
|
||||
notificationManager.notify(CONFIRM_NOTIF_ID, notificationBuilder.build());
|
||||
|
||||
// keep the confirmation dialog open for half a minute.
|
||||
scheduleDismiss(CONFIRM_NOTIF_ID, 30);
|
||||
|
||||
}
|
||||
|
||||
private void scheduleDismiss(final int notificationId, final int seconds) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(seconds * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NotificationManagerCompat notificationManager =
|
||||
NotificationManagerCompat.from(ListenerService.this);
|
||||
notificationManager.cancel(NOTIFICATION_ID);
|
||||
notificationManager.cancel(notificationId);
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
|
BIN
wear/src/main/res/drawable-hdpi/ic_confirm.png
Normal file
BIN
wear/src/main/res/drawable-hdpi/ic_confirm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 291 B |
BIN
wear/src/main/res/drawable-mdpi/ic_confirm.png
Normal file
BIN
wear/src/main/res/drawable-mdpi/ic_confirm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 196 B |
BIN
wear/src/main/res/drawable-xhdpi/ic_confirm.png
Normal file
BIN
wear/src/main/res/drawable-xhdpi/ic_confirm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 289 B |
BIN
wear/src/main/res/drawable-xxhdpi/ic_confirm.png
Normal file
BIN
wear/src/main/res/drawable-xxhdpi/ic_confirm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 462 B |
|
@ -66,14 +66,6 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/full/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/full/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/full/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
|
||||
|
@ -82,6 +74,14 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
|
@ -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/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" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" 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/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" />
|
||||
|
@ -122,6 +114,14 @@
|
|||
<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" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" 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/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" />
|
||||
|
|
Loading…
Reference in a new issue