wear confirm roundtrip working

This commit is contained in:
AdrianLxM 2017-02-08 15:15:22 +01:00
parent 8e9d73e3a3
commit d2d0d4b51a
3 changed files with 20 additions and 7 deletions

View file

@ -44,7 +44,12 @@ public class WearFragment extends Fragment implements FragmentBase {
public void onClick(View view) {
//TODO: revert after debugging!
//getPlugin(getContext()).openSettings();
getPlugin(getContext()).requestActionConfirmation("Titel", "bla bla", "action 1 string");
String title = "CONFIRM"; //TODO: i18n
String message = "Insulin: 7.0U \n" +
"Carbs: 26 \n" +
"CONSTRAINTS APPLIED!!!"; //TODO: apply constraints
String actionstring = "Bolus 7.0 Carbs 26"; //TODO: to be returned by watch if confirmed
getPlugin(getContext()).requestActionConfirmation(title, message, actionstring);
}
});

View file

@ -161,6 +161,8 @@ public class WatchUpdaterService extends WearableListenerService implements
}
if (event != null && event.getPath().equals(WEARABLE_INITIATE_ACTIONSTRING_PATH)) {
ToastUtils.showToastInUiThread(this, "INITIATE1");
String actionstring = new String(event.getData());
ToastUtils.showToastInUiThread(this, "INITIATE: " + actionstring);
//TODO: watch initiated action
@ -487,10 +489,12 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMapRequest.getDataMap().putString("message", message);
dataMapRequest.getDataMap().putString("actionstring", actionstring);
ToastUtils.showToastInUiThread(this, "SENT: " + actionstring);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("ActionConfirmationRequest", "No connection to wearable available!");
Log.e("confirmationRequest", "No connection to wearable available!");
}
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -134,8 +135,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
} else {
googleApiClient.blockingConnect(15, TimeUnit.SECONDS);
if (googleApiClient.isConnected()) {
//TODO: copy send code
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
for (Node node : nodes.getNodes()) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), mMessagePath, mActionstring.getBytes());
}
}
}
return null;
@ -288,7 +292,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
Intent actionIntent = new Intent(this, ListenerService.class);
actionIntent.setAction(ACTION_CONFIRMATION);
actionIntent.putExtra("actionstring", actionstring);
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, 0);;
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_UPDATE_CURRENT);;
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
@ -307,8 +311,8 @@ public class ListenerService extends WearableListenerService implements GoogleAp
notificationManager.notify(CONFIRM_NOTIF_ID, notificationBuilder.build());
// keep the confirmation dialog open for half a minute.
scheduleDismiss(CONFIRM_NOTIF_ID, 30);
// keep the confirmation dialog open for one minute.
scheduleDismiss(CONFIRM_NOTIF_ID, 60);
}