wear sending confirmation requests
This commit is contained in:
parent
d1a3645be7
commit
8e9d73e3a3
4 changed files with 112 additions and 8 deletions
|
@ -42,7 +42,10 @@ public class WearFragment extends Fragment implements FragmentBase {
|
||||||
view.findViewById(R.id.wear_opensettings).setOnClickListener(new View.OnClickListener() {
|
view.findViewById(R.id.wear_opensettings).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
getPlugin(getContext()).openSettings();
|
//TODO: revert after debugging!
|
||||||
|
//getPlugin(getContext()).openSettings();
|
||||||
|
getPlugin(getContext()).requestActionConfirmation("Titel", "bla bla", "action 1 string");
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,15 @@ public class WearPlugin implements PluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void requestActionConfirmation(String title, String message, String actionstring){
|
||||||
|
|
||||||
|
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST);
|
||||||
|
intent.putExtra("title", title);
|
||||||
|
intent.putExtra("message", message);
|
||||||
|
intent.putExtra("actionstring", actionstring);
|
||||||
|
ctx.startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
return fragmentEnabled;
|
return fragmentEnabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,16 +45,21 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
public static final String ACTION_SEND_STATUS = WatchUpdaterService.class.getName().concat(".SendStatus");
|
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_BASALS = WatchUpdaterService.class.getName().concat(".SendBasals");
|
||||||
public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress");
|
public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress");
|
||||||
|
public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest");
|
||||||
|
|
||||||
|
|
||||||
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 WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
|
||||||
|
public static final String WEARABLE_CONFIRM_ACTIONSTRING_PATH = "/nightscout_watch_confirmactionstring";
|
||||||
|
public static final String WEARABLE_INITIATE_ACTIONSTRING_PATH = "/nightscout_watch_initiateactionstring";
|
||||||
|
|
||||||
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";
|
||||||
|
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +126,13 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
sendBasals();
|
sendBasals();
|
||||||
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){
|
} else if (ACTION_SEND_BOLUSPROGRESS.equals(action)){
|
||||||
sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus")?intent.getStringExtra("progressstatus"):"");
|
sendBolusProgress(intent.getIntExtra("progresspercent", 0), intent.hasExtra("progressstatus")?intent.getStringExtra("progressstatus"):"");
|
||||||
} else {
|
} else if (ACTION_SEND_ACTIONCONFIRMATIONREQUEST.equals(action)){
|
||||||
|
String title = intent.getStringExtra("title");
|
||||||
|
String message = intent.getStringExtra("message");
|
||||||
|
String actionstring = intent.getStringExtra("actionstring");
|
||||||
|
sendActionConfirmationRequest(title, message, actionstring);
|
||||||
|
}
|
||||||
|
else {
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -148,6 +159,18 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
if (event != null && event.getPath().equals(WEARABLE_CANCELBOLUS_PATH)) {
|
if (event != null && event.getPath().equals(WEARABLE_CANCELBOLUS_PATH)) {
|
||||||
cancelBolus();
|
cancelBolus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event != null && event.getPath().equals(WEARABLE_INITIATE_ACTIONSTRING_PATH)) {
|
||||||
|
String actionstring = new String(event.getData());
|
||||||
|
ToastUtils.showToastInUiThread(this, "INITIATE: " + actionstring);
|
||||||
|
//TODO: watch initiated action
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event != null && event.getPath().equals(WEARABLE_CONFIRM_ACTIONSTRING_PATH)) {
|
||||||
|
String actionstring = new String(event.getData());
|
||||||
|
ToastUtils.showToastInUiThread(this, "CONFIRM: " + actionstring);
|
||||||
|
//TODO: watch confirmed action
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,6 +477,23 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendActionConfirmationRequest(String title, String message, String actionstring) {
|
||||||
|
if (googleApiClient.isConnected()) {
|
||||||
|
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CONFIRMATION_REQUEST_PATH);
|
||||||
|
//unique content
|
||||||
|
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
|
||||||
|
dataMapRequest.getDataMap().putString("actionConfirmationRequest", "actionConfirmationRequest");
|
||||||
|
dataMapRequest.getDataMap().putString("title", title);
|
||||||
|
dataMapRequest.getDataMap().putString("message", message);
|
||||||
|
dataMapRequest.getDataMap().putString("actionstring", actionstring);
|
||||||
|
|
||||||
|
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||||
|
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
||||||
|
} else {
|
||||||
|
Log.e("ActionConfirmationRequest", "No connection to wearable available!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void sendStatus() {
|
private void sendStatus() {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,15 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
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 WEARABLE_CANCELBOLUS_PATH = "/nightscout_watch_cancel_bolus";
|
||||||
|
public static final String WEARABLE_CONFIRM_ACTIONSTRING_PATH = "/nightscout_watch_confirmactionstring";
|
||||||
|
public static final String WEARABLE_INITIATE_ACTIONSTRING_PATH = "/nightscout_watch_initiateactionstring";
|
||||||
|
|
||||||
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";
|
||||||
|
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
||||||
|
|
||||||
|
|
||||||
public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
|
public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
|
||||||
public static final int CONFIRM_NOTIF_ID = 002;
|
public static final int CONFIRM_NOTIF_ID = 002;
|
||||||
|
@ -86,11 +90,11 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
NodeApi.GetConnectedNodesResult nodes =
|
NodeApi.GetConnectedNodesResult nodes =
|
||||||
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
|
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
|
||||||
for (Node node : nodes.getNodes()) {
|
for (Node node : nodes.getNodes()) {
|
||||||
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_CANCELBOLUS_PATH, null);
|
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_CANCELBOLUS_PATH, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
googleApiClient.blockingConnect(15, TimeUnit.SECONDS);
|
googleApiClient.blockingConnect(15, TimeUnit.SECONDS);
|
||||||
|
@ -107,6 +111,37 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MessageActionTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
Context mContext;
|
||||||
|
String mActionstring;
|
||||||
|
String mMessagePath;
|
||||||
|
|
||||||
|
MessageActionTask(Context context, String messagePath, String actionstring) {
|
||||||
|
mContext = context;
|
||||||
|
mActionstring = actionstring;
|
||||||
|
mMessagePath = messagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(), mMessagePath, mActionstring.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
googleApiClient.blockingConnect(15, TimeUnit.SECONDS);
|
||||||
|
if (googleApiClient.isConnected()) {
|
||||||
|
//TODO: copy send code
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void requestData() {
|
public void requestData() {
|
||||||
new DataRequester(this).execute();
|
new DataRequester(this).execute();
|
||||||
}
|
}
|
||||||
|
@ -115,6 +150,14 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
new BolusCancelTask(this).execute();
|
new BolusCancelTask(this).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendConfirmActionstring(String actionstring) {
|
||||||
|
new MessageActionTask(this, WEARABLE_CONFIRM_ACTIONSTRING_PATH, actionstring).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendInitiateActionstring(String actionstring) {
|
||||||
|
new MessageActionTask(this, WEARABLE_INITIATE_ACTIONSTRING_PATH, actionstring).execute();
|
||||||
|
}
|
||||||
|
|
||||||
public void googleApiConnect() {
|
public void googleApiConnect() {
|
||||||
googleApiClient = new GoogleApiClient.Builder(this)
|
googleApiClient = new GoogleApiClient.Builder(this)
|
||||||
.addConnectionCallbacks(this)
|
.addConnectionCallbacks(this)
|
||||||
|
@ -150,12 +193,15 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
NotificationManagerCompat.from(ListenerService.this);
|
NotificationManagerCompat.from(ListenerService.this);
|
||||||
notificationManager.cancel(CONFIRM_NOTIF_ID);
|
notificationManager.cancel(CONFIRM_NOTIF_ID);
|
||||||
|
|
||||||
|
String actionstring = intent.getStringExtra("actionstring");
|
||||||
|
sendConfirmActionstring(actionstring);
|
||||||
|
|
||||||
//TODO: send confirmation string to phone
|
//TODO: send confirmation string to phone
|
||||||
}
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataChanged(DataEventBuffer dataEvents) {
|
public void onDataChanged(DataEventBuffer dataEvents) {
|
||||||
|
|
||||||
|
@ -175,7 +221,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
int progress = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getInt("progresspercent", 0);
|
int progress = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getInt("progresspercent", 0);
|
||||||
String status = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("progressstatus", "");
|
String status = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("progressstatus", "");
|
||||||
showBolusProgress(progress, status);
|
showBolusProgress(progress, status);
|
||||||
} else if (path.equals(NEW_STATUS_PATH)) {
|
} else if (path.equals(ACTION_CONFIRMATION_REQUEST_PATH)) {
|
||||||
|
String title = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("title");
|
||||||
|
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
|
||||||
|
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
|
||||||
|
showConfirmationDialog(title, message, actionstring);
|
||||||
|
}else if (path.equals(NEW_STATUS_PATH)) {
|
||||||
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
||||||
Intent messageIntent = new Intent();
|
Intent messageIntent = new Intent();
|
||||||
messageIntent.setAction(Intent.ACTION_SEND);
|
messageIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
@ -236,6 +287,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
Intent actionIntent = new Intent(this, ListenerService.class);
|
Intent actionIntent = new Intent(this, ListenerService.class);
|
||||||
actionIntent.setAction(ACTION_CONFIRMATION);
|
actionIntent.setAction(ACTION_CONFIRMATION);
|
||||||
|
actionIntent.putExtra("actionstring", actionstring);
|
||||||
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, 0);;
|
PendingIntent actionPendingIntent = PendingIntent.getService(this, 0, actionIntent, 0);;
|
||||||
|
|
||||||
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
|
long[] vibratePattern = new long[]{0, 100, 50, 100, 50};
|
||||||
|
|
Loading…
Reference in a new issue