Wear cancel bolus via content intent to progress card

This commit is contained in:
AdrianLxM 2017-02-06 19:35:27 +01:00
parent 7ec3ff2a17
commit 8c37809751
3 changed files with 79 additions and 14 deletions

View file

@ -50,12 +50,14 @@ public class WatchUpdaterService extends WearableListenerService implements
private GoogleApiClient googleApiClient; private GoogleApiClient googleApiClient;
public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
public static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend"; public static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend";
private static final String WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
private static final String OPEN_SETTINGS_PATH = "/openwearsettings"; private static final String OPEN_SETTINGS_PATH = "/openwearsettings";
private static final String NEW_STATUS_PATH = "/sendstatustowear"; private static final String NEW_STATUS_PATH = "/sendstatustowear";
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";
boolean wear_integration = false; boolean wear_integration = false;
SharedPreferences mPrefs; SharedPreferences mPrefs;
@ -139,9 +141,20 @@ public class WatchUpdaterService extends WearableListenerService implements
@Override @Override
public void onMessageReceived(MessageEvent event) { public void onMessageReceived(MessageEvent event) {
if (wear_integration) { if (wear_integration) {
if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH)) if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH)) {
resendData(); resendData();
} }
if (event != null && event.getPath().equals(WEARABLE_CANCELBOLUS_PATH)) {
cancelBolus();
}
}
}
private void cancelBolus() {
//ToastUtils.showToastInUiThread(this, "cancelBolus()");
PumpInterface pump = MainApp.getConfigBuilder();
pump.stopBolusDelivering();
} }
private void sendData() { private void sendData() {

View file

@ -22,6 +22,8 @@ import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable; import com.google.android.gms.wearable.Wearable;
import com.google.android.gms.wearable.WearableListenerService; import com.google.android.gms.wearable.WearableListenerService;
import java.util.concurrent.TimeUnit;
/** /**
* Created by emmablack on 12/26/14. * Created by emmablack on 12/26/14.
*/ */
@ -29,13 +31,18 @@ public class ListenerService extends WearableListenerService implements GoogleAp
GoogleApiClient.OnConnectionFailedListener { GoogleApiClient.OnConnectionFailedListener {
private static final String WEARABLE_DATA_PATH = "/nightscout_watch_data"; private static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
private static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend"; private static final String WEARABLE_RESEND_PATH = "/nightscout_watch_data_resend";
private static final String WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
private static final String OPEN_SETTINGS = "/openwearsettings"; private static final String OPEN_SETTINGS = "/openwearsettings";
private static final String NEW_STATUS_PATH = "/sendstatustowear"; private static final String NEW_STATUS_PATH = "/sendstatustowear";
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";
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_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA"; private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
GoogleApiClient googleApiClient; GoogleApiClient googleApiClient;
private long lastRequest = 0; private long lastRequest = 0;
@ -65,10 +72,45 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} }
} }
public class BolusCancelTask extends AsyncTask<Void, Void, Void> {
Context mContext;
BolusCancelTask(Context context) {
mContext = context;
}
@Override
protected Void doInBackground(Void... params) {
if (googleApiClient.isConnected()) {
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
for (Node node : nodes.getNodes()) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_CANCELBOLUS_PATH, null);
}
} else {
googleApiClient.blockingConnect(15, TimeUnit.SECONDS);
if (googleApiClient.isConnected()) {
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
for (Node node : nodes.getNodes()) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_CANCELBOLUS_PATH, null);
}
}
}
return null;
}
}
public void requestData() { public void requestData() {
new DataRequester(this).execute(); new DataRequester(this).execute();
} }
public void cancelBolus() {
new BolusCancelTask(this).execute();
}
public void googleApiConnect() { public void googleApiConnect() {
googleApiClient = new GoogleApiClient.Builder(this) googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this) .addConnectionCallbacks(this)
@ -84,7 +126,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
if (intent != null && ACTION_RESEND.equals(intent.getAction())) { if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
googleApiConnect(); googleApiConnect();
requestData(); requestData();
} else if(intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())){
googleApiConnect();
cancelBolus();
} }
//TODO: add action to cancel bolus
return START_STICKY; return START_STICKY;
} }
@ -132,15 +178,19 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private void showBolusProgress(int progresspercent) { private void showBolusProgress(int progresspercent) {
int notificationId = 001; int notificationId = 001;
// Build intent for notification content // Build intent for notification content
Intent viewIntent = new Intent(); //TODO: Add Action in order to see that it is a cancel event
PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0); Intent cancelIntent = new Intent(this, ListenerService.class);
cancelIntent.setAction(ACTION_CANCELBOLUS);
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);;
NotificationCompat.Builder notificationBuilder = NotificationCompat.Builder notificationBuilder =
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 + "%")
.setContentIntent(viewPendingIntent); .setContentIntent(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 =
@ -148,6 +198,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
// 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(notificationId, notificationBuilder.build());
//TODO: Cancel notification when 100%
} }
public static void requestData(Context context) { public static void requestData(Context context) {

View file

@ -43,6 +43,13 @@
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/fullDebug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/fullDebug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/fullDebug/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/fullDebug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/full/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/full/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/assets" type="java-test-resource" />
@ -51,13 +58,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testFullDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/full/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/full/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/full/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/full/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/full/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/full/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/full/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/full/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/full/assets" type="java-resource" />