- changed wear versions
- added some code to listener - added some log entries
This commit is contained in:
parent
fda43c423d
commit
056ad650cd
4 changed files with 133 additions and 11 deletions
|
@ -1,8 +1,8 @@
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
wearableVersion = "2.4.0"
|
wearableVersion = "2.0.1"
|
||||||
playServicesWearable = "16.0.1"
|
playServicesWearable = "9.4.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateGitBuild = { ->
|
def generateGitBuild = { ->
|
||||||
|
|
|
@ -168,12 +168,28 @@
|
||||||
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
|
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service android:name=".data.ListenerService">
|
<service android:name=".data.ListenerService">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
|
<!-- <action android:name="com.google.android.gms.wearable.BIND_LISTENER" /> -->
|
||||||
|
<!-- listeners receive events that match the action and data filters -->
|
||||||
|
<!-- <action android:name="com.google.android.gms.wearable.CAPABILITY_CHANGED" /> -->
|
||||||
|
<action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_data"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_data_resend"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_cancel_bolus"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_confirmactionstring"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_initiateactionstring"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/openwearsettings"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/sendstatustowear"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/sendpreferencestowear"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_basal"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_bolusprogress"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_actionconfirmationrequest"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_changeconfirmationrequest"/>
|
||||||
|
<data android:scheme="wear" android:host="*" android:pathPrefix="/nightscout_watch_cancelnotificationrequest"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".interaction.menus.MainMenuActivity"
|
android:name=".interaction.menus.MainMenuActivity"
|
||||||
android:label="@string/label_actions_activity">
|
android:label="@string/label_actions_activity">
|
||||||
|
|
|
@ -7,16 +7,19 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
|
import com.google.android.gms.wearable.ChannelApi;
|
||||||
import com.google.android.gms.wearable.DataEvent;
|
import com.google.android.gms.wearable.DataEvent;
|
||||||
import com.google.android.gms.wearable.DataEventBuffer;
|
import com.google.android.gms.wearable.DataEventBuffer;
|
||||||
import com.google.android.gms.wearable.DataMap;
|
import com.google.android.gms.wearable.DataMap;
|
||||||
|
@ -33,12 +36,15 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
import info.nightscout.androidaps.interaction.actions.AcceptActivity;
|
||||||
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
import info.nightscout.androidaps.interaction.actions.CPPActivity;
|
||||||
import info.nightscout.androidaps.interaction.utils.SafeParse;
|
import info.nightscout.androidaps.interaction.utils.SafeParse;
|
||||||
|
import info.nightscout.androidaps.interaction.utils.WearUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by emmablack on 12/26/14.
|
* Created by emmablack on 12/26/14.
|
||||||
*/
|
*/
|
||||||
public class ListenerService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks,
|
public class ListenerService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks,
|
||||||
GoogleApiClient.OnConnectionFailedListener {
|
GoogleApiClient.OnConnectionFailedListener, ChannelApi.ChannelListener {
|
||||||
|
|
||||||
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";
|
||||||
|
@ -67,19 +73,35 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
private DismissThread confirmThread;
|
private DismissThread confirmThread;
|
||||||
private DismissThread bolusprogressThread;
|
private DismissThread bolusprogressThread;
|
||||||
|
private static final String TAG = "ListenerService";
|
||||||
|
|
||||||
|
private DataRequester mDataRequester = null;
|
||||||
|
|
||||||
|
|
||||||
public class DataRequester extends AsyncTask<Void, Void, Void> {
|
public class DataRequester extends AsyncTask<Void, Void, Void> {
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
String path;
|
||||||
|
byte[] payload;
|
||||||
|
|
||||||
DataRequester(Context context) {
|
// DataRequester(Context context) {
|
||||||
mContext = context;
|
// mContext = context;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DataRequester(Context context, String thispath, byte[] thispayload) {
|
||||||
|
path = thispath;
|
||||||
|
payload = thispayload;
|
||||||
|
Log.d(TAG, "DataRequester DataRequester: " + thispath + " lastRequest:" + lastRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
@ -154,6 +176,9 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
||||||
|
forceGoogleApiConnect();
|
||||||
|
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
NodeApi.GetConnectedNodesResult nodes =
|
NodeApi.GetConnectedNodesResult nodes =
|
||||||
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
|
Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
|
||||||
|
@ -176,7 +201,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestData() {
|
public void requestData() {
|
||||||
new DataRequester(this).execute();
|
sendData(WEARABLE_RESEND_PATH, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelBolus() {
|
public void cancelBolus() {
|
||||||
|
@ -191,7 +216,48 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
new MessageActionTask(this, WEARABLE_INITIATE_ACTIONSTRING_PATH, actionstring).execute();
|
new MessageActionTask(this, WEARABLE_INITIATE_ACTIONSTRING_PATH, actionstring).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void googleApiConnect() {
|
|
||||||
|
private synchronized void sendData(String path, byte[] payload) {
|
||||||
|
if (path == null) return;
|
||||||
|
if (mDataRequester != null) {
|
||||||
|
Log.d(TAG, "sendData DataRequester != null lastRequest:" + WearUtil.dateTimeText(lastRequest));
|
||||||
|
if (mDataRequester.getStatus() != AsyncTask.Status.FINISHED) {
|
||||||
|
Log.d(TAG, "sendData Should be canceled? Let run 'til finished.");
|
||||||
|
//mDataRequester.cancel(true);
|
||||||
|
}
|
||||||
|
//mDataRequester = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "sendData: execute lastRequest:" + WearUtil.dateTimeText(lastRequest));
|
||||||
|
mDataRequester = (DataRequester) new DataRequester(this, path, payload).execute();
|
||||||
|
|
||||||
|
|
||||||
|
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
|
// Log.d(TAG, "sendData SDK < M call execute lastRequest:" + WearUtil.dateTimeText(lastRequest));
|
||||||
|
// mDataRequester = (DataRequester) new DataRequester(this, path, payload).execute();
|
||||||
|
// } else {
|
||||||
|
// Log.d(TAG, "sendData SDK >= M call executeOnExecutor lastRequest:" + WearUtil.dateTimeText(lastRequest));
|
||||||
|
// // TODO xdrip executor
|
||||||
|
// mDataRequester = (DataRequester) new DataRequester(this, path, payload).executeOnExecutor(xdrip.executor);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void googleApiConnect() {
|
||||||
|
if (googleApiClient != null) {
|
||||||
|
// Remove old listener(s)
|
||||||
|
try {
|
||||||
|
Wearable.ChannelApi.removeListener(googleApiClient, this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Wearable.MessageApi.removeListener(googleApiClient, this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
googleApiClient = new GoogleApiClient.Builder(this)
|
googleApiClient = new GoogleApiClient.Builder(this)
|
||||||
.addConnectionCallbacks(this)
|
.addConnectionCallbacks(this)
|
||||||
.addOnConnectionFailedListener(this)
|
.addOnConnectionFailedListener(this)
|
||||||
|
@ -201,6 +267,20 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void forceGoogleApiConnect() {
|
||||||
|
if ((googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) || googleApiClient == null) {
|
||||||
|
try {
|
||||||
|
Log.d(TAG, "forceGoogleApiConnect: forcing google api reconnection");
|
||||||
|
googleApiConnect();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
|
if (intent != null && ACTION_RESEND.equals(intent.getAction())) {
|
||||||
|
@ -261,8 +341,10 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
if (event.getType() == DataEvent.TYPE_CHANGED) {
|
if (event.getType() == DataEvent.TYPE_CHANGED) {
|
||||||
|
|
||||||
|
|
||||||
String path = event.getDataItem().getUri().getPath();
|
String path = event.getDataItem().getUri().getPath();
|
||||||
|
|
||||||
|
Log.d(TAG, "Path: {}" + path + ", Event=" + event);
|
||||||
|
|
||||||
if (path.equals(OPEN_SETTINGS)) {
|
if (path.equals(OPEN_SETTINGS)) {
|
||||||
Intent intent = new Intent(this, AAPSPreferences.class);
|
Intent intent = new Intent(this, AAPSPreferences.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
@ -480,6 +562,9 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(Bundle bundle) {
|
public void onConnected(Bundle bundle) {
|
||||||
|
Log.d(TAG, "onConnected call requestData");
|
||||||
|
|
||||||
|
Wearable.ChannelApi.addListener(googleApiClient, this);
|
||||||
requestData();
|
requestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,8 +584,10 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
if (googleApiClient != null && googleApiClient.isConnected()) {
|
if (googleApiClient != null && googleApiClient.isConnected()) {
|
||||||
googleApiClient.disconnect();
|
googleApiClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (googleApiClient != null) {
|
if (googleApiClient != null) {
|
||||||
Wearable.MessageApi.removeListener(googleApiClient, this);
|
Wearable.MessageApi.removeListener(googleApiClient, this);
|
||||||
|
Wearable.ChannelApi.removeListener(googleApiClient, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.androidaps.interaction.utils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by andy on 3/5/19.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class WearUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static String dateTimeText(long timeInMs) {
|
||||||
|
Date d = new Date(timeInMs);
|
||||||
|
return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue