enabling wearcontrols from preferences

This commit is contained in:
AdrianLxM 2017-10-12 18:01:10 +02:00
parent 944e334231
commit f751638a7f
8 changed files with 48 additions and 31 deletions

View file

@ -140,8 +140,7 @@ allprojects {
}
dependencies {
wearWearApp project(path: ':wear', configuration: 'restrictedRelease')
wearcontrolWearApp project(path: ':wear', configuration: 'fullRelease')
wearApp project(':wear')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {

View file

@ -42,6 +42,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
@ -65,6 +66,7 @@ public class WatchUpdaterService extends WearableListenerService implements
private static final String OPEN_SETTINGS_PATH = "/openwearsettings";
private static final String NEW_STATUS_PATH = "/sendstatustowear";
private static final String NEW_PREFERENCES_PATH = "/sendpreferencestowear";
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
@ -326,6 +328,7 @@ public class WatchUpdaterService extends WearableListenerService implements
entries.putDataMapArrayList("entries", dataMaps);
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries);
}
sendPreferences();
sendBasals();
sendStatus();
}
@ -527,6 +530,22 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
private void sendPreferences() {
if (googleApiClient.isConnected()) {
boolean wearcontrol = SP.getBoolean("wearcontrol",false);
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH);
//unique content
dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis());
dataMapRequest.getDataMap().putBoolean("wearcontrol", wearcontrol);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
} else {
Log.e("SendStatus", "No connection to wearable available!");
}
}
@NonNull
private String generateStatusString() {
String status = "";

View file

@ -743,5 +743,7 @@
<string name="gettingpumpsettings">Gettings pump settings</string>
<string name="gettingpumptime">Getting pump time</string>
<string name="reuse">reuse</string>
<string name="wearcontrol_title">Controls from Watch</string>
<string name="wearcontrol_summary">Set Temp-Targets and enter Treatments from the watch.</string>
</resources>

View file

@ -4,6 +4,12 @@
android:key="wearplugin"
android:title="@string/wear_settings">
<SwitchPreference
android:defaultValue="false"
android:key="wearcontrol"
android:title="@string/wearcontrol_title"
android:summary="@string/wearcontrol_summary"/>
<SwitchPreference
android:defaultValue="true"
android:key="wear_detailediob"

View file

@ -42,33 +42,6 @@ android {
publishNonDefault true
productFlavors {
full {
applicationId = "info.nightscout.androidaps"
resValue "string", "label_xdrip", "AAPS"
resValue "string", "label_xdrip_large", "AAPS(Large)"
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
resValue "string", "label_xdrip_no_chart", "AAPS(NoChart)"
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
resValue "string", "label_xdrip_activity", "AAPS Prefs."
resValue "string", "app_settings", "AAPS Settings"
buildConfigField "boolean", "WEAR_CONTROL", "true"
}
restricted {
applicationId = "info.nightscout.androidaps"
resValue "string", "label_xdrip", "AAPS"
resValue "string", "label_xdrip_large", "AAPS(Large)"
resValue "string", "label_xdrip_big_chart", "AAPS(BigChart)"
resValue "string", "label_xdrip_no_chart", "AAPS(NoChart)"
resValue "string", "label_xdrip_circle", "AAPS(Circle)"
resValue "string", "label_xdrip_activity", "AAPS Prefs."
resValue "string", "app_settings", "AAPS Settings"
buildConfigField "boolean", "WEAR_CONTROL", "false"
}
}
}
allprojects {

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.data;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
@ -43,6 +44,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private static final String OPEN_SETTINGS = "/openwearsettings";
private static final String NEW_STATUS_PATH = "/sendstatustowear";
private static final String NEW_PREFERENCES_PATH = "/sendpreferencestowear";
public static final String BASAL_DATA_PATH = "/nightscout_watch_basal";
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
@ -282,6 +284,15 @@ public class ListenerService extends WearableListenerService implements GoogleAp
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("basals", dataMap.toBundle());
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
} else if (path.equals(NEW_PREFERENCES_PATH)){
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
if(dataMap.containsKey("wearcontrol")) {
boolean wearcontrol = dataMap.getBoolean("wearcontrol", false);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("wearcontrol", wearcontrol);
editor.commit();
}
} else {
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();

View file

@ -32,8 +32,9 @@ public class MainMenuActivity extends MenuListActivity {
@Override
protected String[] getElements() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
if(!BuildConfig.WEAR_CONTROL){
if(!sharedPreferences.getBoolean("wearcontrol", false)){
return new String[] {
"Settings",
"Re-Sync"};

View file

@ -37,7 +37,13 @@
</string-array>
<string name="label_xdrip">AAPS</string>
<string name="label_xdrip_large">AAPS(Large)</string>
<string name="label_xdrip_big_chart">AAPS(BigChart)</string>
<string name="label_xdrip_no_chart">AAPS(NoChart)</string>
<string name="label_xdrip_circle">AAPS(Circle)</string>
<string name="label_xdrip_activity">AAPS</string>
<string name="app_settings">AAPS Settings</string>
<string name="title_activity_bolus">BolusActivity</string>
<string name="hello_round">Hello Round World!</string>