diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index e7a8bb2efc..bf3dc7f9d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -106,9 +106,9 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl tempBasal.setVisibility(View.GONE); else tempBasal.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized()) + /* if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized()) fill.setVisibility(View.GONE); - else + else */ fill.setVisibility(View.VISIBLE); if (!Config.APS) tempTarget.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index cac8007e69..2941148ce5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterService; /** @@ -141,6 +142,14 @@ public class WearPlugin implements PluginBase { sendDataToWatch(false, true, false); } + + @Subscribe + public void onStatusEvent(final EventOverviewBolusProgress ev) { + Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS); + intent.putExtra("progresspercent", ev.percent); + ctx.startService(intent); + } + public static boolean isEnabled() { return fragmentEnabled; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 66383cf7d5..0eb903de90 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -44,6 +44,7 @@ public class WatchUpdaterService extends WearableListenerService implements public static final String ACTION_OPEN_SETTINGS = WatchUpdaterService.class.getName().concat(".OpenSettings"); public static final String ACTION_SEND_STATUS = WatchUpdaterService.class.getName().concat(".SendStatus"); public static final String ACTION_SEND_BASALS = WatchUpdaterService.class.getName().concat(".SendBasals"); + public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress"); private GoogleApiClient googleApiClient; @@ -52,6 +53,7 @@ public class WatchUpdaterService extends WearableListenerService implements 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; @@ -115,6 +117,8 @@ public class WatchUpdaterService extends WearableListenerService implements sendStatus(); } else if (ACTION_SEND_BASALS.equals(action)) { sendBasals(); + } else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){ + sendBolusProgress(intent.getIntExtra("progresspercent", 0)); } else { sendData(); } @@ -423,6 +427,20 @@ public class WatchUpdaterService extends WearableListenerService implements } } + private void sendBolusProgress(int progresspercent) { + 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().putInt("progresspercent", progresspercent); + PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); + Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); + } else { + Log.e("BolusProgress", "No connection to wearable available!"); + } + } + private void sendStatus() { if (googleApiClient.isConnected()) { diff --git a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java index d969706e11..43dd7afd8d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/ListenerService.java @@ -1,10 +1,15 @@ package info.nightscout.androidaps; +import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; 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; import com.google.android.gms.common.api.GoogleApiClient; @@ -27,6 +32,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp 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"; @@ -97,7 +103,9 @@ public class ListenerService extends WearableListenerService implements GoogleAp Intent intent = new Intent(this, NWPreferences.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); - + } else if (path.equals(BOLUS_PROGRESS_PATH)) { + int progress = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getInt("progresspercent", 0); + showBolusProgress(progress); } else if (path.equals(NEW_STATUS_PATH)) { dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Intent messageIntent = new Intent(); @@ -121,6 +129,27 @@ 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); + + NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_icon) + .setContentTitle("Bolus Progress") + .setContentText(progresspercent + "%") + .setContentIntent(viewPendingIntent); + +// 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()); + } + public static void requestData(Context context) { Intent intent = new Intent(context, ListenerService.class); intent.setAction(ACTION_RESEND); diff --git a/wear/wear.iml b/wear/wear.iml index d38c08321d..ce3df746e7 100644 --- a/wear/wear.iml +++ b/wear/wear.iml @@ -43,13 +43,6 @@ - - - - - - - @@ -58,6 +51,13 @@ + + + + + + + @@ -66,14 +66,6 @@ - - - - - - - - @@ -82,6 +74,14 @@ + + + + + + + + @@ -122,6 +122,7 @@ + @@ -134,10 +135,14 @@ + + + +