Wear cancel bolus via content intent to progress card
This commit is contained in:
parent
7ec3ff2a17
commit
8c37809751
|
@ -50,12 +50,14 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
private GoogleApiClient googleApiClient;
|
||||
public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
|
||||
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 NEW_STATUS_PATH = "/sendstatustowear";
|
||||
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
|
||||
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
|
||||
|
||||
|
||||
|
||||
boolean wear_integration = false;
|
||||
SharedPreferences mPrefs;
|
||||
|
||||
|
@ -139,11 +141,22 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
@Override
|
||||
public void onMessageReceived(MessageEvent event) {
|
||||
if (wear_integration) {
|
||||
if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH))
|
||||
if (event != null && event.getPath().equals(WEARABLE_RESEND_PATH)) {
|
||||
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() {
|
||||
|
||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||
|
|
|
@ -22,6 +22,8 @@ import com.google.android.gms.wearable.NodeApi;
|
|||
import com.google.android.gms.wearable.Wearable;
|
||||
import com.google.android.gms.wearable.WearableListenerService;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by emmablack on 12/26/14.
|
||||
*/
|
||||
|
@ -29,13 +31,18 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
GoogleApiClient.OnConnectionFailedListener {
|
||||
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_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
|
||||
|
||||
private static final String OPEN_SETTINGS = "/openwearsettings";
|
||||
private static final String NEW_STATUS_PATH = "/sendstatustowear";
|
||||
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
|
||||
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_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS";
|
||||
|
||||
private static final String ACTION_RESEND_BULK = "com.dexdrip.stephenblack.nightwatch.RESEND_BULK_DATA";
|
||||
GoogleApiClient googleApiClient;
|
||||
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() {
|
||||
new DataRequester(this).execute();
|
||||
}
|
||||
|
||||
public void cancelBolus() {
|
||||
new BolusCancelTask(this).execute();
|
||||
}
|
||||
|
||||
public void googleApiConnect() {
|
||||
googleApiClient = new GoogleApiClient.Builder(this)
|
||||
.addConnectionCallbacks(this)
|
||||
|
@ -84,7 +126,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
|
||||
googleApiConnect();
|
||||
requestData();
|
||||
} else if(intent != null && ACTION_CANCELBOLUS.equals(intent.getAction())){
|
||||
googleApiConnect();
|
||||
cancelBolus();
|
||||
}
|
||||
//TODO: add action to cancel bolus
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
@ -131,23 +177,29 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
|
||||
private void showBolusProgress(int progresspercent) {
|
||||
int notificationId = 001;
|
||||
// Build intent for notification content
|
||||
Intent viewIntent = new Intent();
|
||||
PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);
|
||||
// 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);
|
||||
cancelIntent.setAction(ACTION_CANCELBOLUS);
|
||||
PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);;
|
||||
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_icon)
|
||||
.setContentTitle("Bolus Progress")
|
||||
.setContentText(progresspercent + "%")
|
||||
.setContentIntent(viewPendingIntent);
|
||||
.setContentIntent(cancelPendingIntent);
|
||||
|
||||
// Get an instance of the NotificationManager service
|
||||
//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.
|
||||
// Build the notification and issues it with notification manager.
|
||||
notificationManager.notify(notificationId, notificationBuilder.build());
|
||||
|
||||
//TODO: Cancel notification when 100%
|
||||
}
|
||||
|
||||
public static void requestData(Context context) {
|
||||
|
|
|
@ -43,6 +43,13 @@
|
|||
<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/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/resources" 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/rs" 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/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/full/assets" type="java-resource" />
|
||||
|
|
Loading…
Reference in a new issue