resend(), bigchart watchface layout overhaul, fix nullpointer exception, only send when enabled
This commit is contained in:
parent
2e0ac569eb
commit
e2c3069374
4 changed files with 103 additions and 144 deletions
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterServi
|
|||
public class WearPlugin implements PluginBase {
|
||||
|
||||
static boolean fragmentEnabled = true;
|
||||
private static WatchUpdaterService watchUS;
|
||||
private final Context ctx;
|
||||
|
||||
WearPlugin(Context ctx){
|
||||
|
@ -63,6 +64,9 @@ public class WearPlugin implements PluginBase {
|
|||
@Override
|
||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||
WearPlugin.fragmentEnabled = fragmentEnabled;
|
||||
if(watchUS!=null){
|
||||
watchUS.setSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,8 +75,10 @@ public class WearPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
private void sendDataToWatch(){
|
||||
if (isEnabled(getType())) {
|
||||
ctx.startService(new Intent(ctx, WatchUpdaterService.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @Subscribe
|
||||
|
@ -108,8 +114,17 @@ public class WearPlugin implements PluginBase {
|
|||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBasalProfile ev) { sendDataToWatch(); }
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return fragmentEnabled;
|
||||
}
|
||||
|
||||
public static void registerWatchUpdaterService(WatchUpdaterService wus){
|
||||
watchUS = wus;
|
||||
}
|
||||
|
||||
public static void unRegisterWatchUpdaterService(){
|
||||
watchUS = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
public class WatchUpdaterService extends WearableListenerService implements
|
||||
GoogleApiClient.ConnectionCallbacks,
|
||||
|
@ -45,9 +45,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
|
||||
boolean wear_integration = false;
|
||||
boolean pebble_integration = false;
|
||||
SharedPreferences mPrefs;
|
||||
SharedPreferences.OnSharedPreferenceChangeListener mPreferencesListener;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -60,17 +58,11 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
}
|
||||
|
||||
public void listenForChangeInSettings() {
|
||||
mPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
setSettings();
|
||||
}
|
||||
};
|
||||
mPrefs.registerOnSharedPreferenceChangeListener(mPreferencesListener);
|
||||
WearPlugin.registerWatchUpdaterService(this);
|
||||
}
|
||||
|
||||
public void setSettings() {
|
||||
//TODO Adrian: check if wear plugin is active or better: Never call from Plugin if not enabled!
|
||||
wear_integration = true; //mPrefs.getBoolean("wear_sync", false);
|
||||
wear_integration = WearPlugin.isEnabled();
|
||||
if (wear_integration) {
|
||||
googleApiConnect();
|
||||
}
|
||||
|
@ -140,12 +132,6 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||
if (lastBG != null) {
|
||||
/**bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
if (glucoseStatus != null)
|
||||
deltaView.setText("Δ " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units);
|
||||
BgReading.units = profile.getUnits();**/
|
||||
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
|
||||
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
|
||||
|
@ -153,16 +139,6 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMapSingleBG(lastBG, glucoseStatus));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
BgReading bg = BgReading.last();
|
||||
if (bg != null) {
|
||||
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
|
||||
if (wear_integration) {
|
||||
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap(bg, mPrefs, new BgGraphBuilder(getApplicationContext())));
|
||||
}
|
||||
}*/
|
||||
ToastUtils.showToastInUiThread(this, "sendData()");
|
||||
}
|
||||
|
||||
private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) {
|
||||
|
@ -175,17 +151,19 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
} else if (lastBG.value < lowMark) {
|
||||
sgvLevel = -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DataMap dataMap = new DataMap();
|
||||
|
||||
int battery = getBatteryLevel(getApplicationContext());
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits()));
|
||||
dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta));
|
||||
dataMap.putDouble("timestamp", lastBG.getTimeIndex()); //TODO: change that to long (was like that in NW)
|
||||
dataMap.putString("delta", NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()));
|
||||
if(glucoseStatus == null) {
|
||||
dataMap.putString("slopeArrow", "NONE" );
|
||||
dataMap.putString("delta", "");
|
||||
} else {
|
||||
dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta));
|
||||
dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()));
|
||||
}
|
||||
dataMap.putString("battery", "" + battery);
|
||||
dataMap.putLong("sgvLevel", sgvLevel);
|
||||
dataMap.putInt("batteryLevel", (battery>=30)?1:0);
|
||||
|
@ -197,6 +175,23 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
return dataMap;
|
||||
}
|
||||
|
||||
private String deltastring(double deltaMGDL, double deltaMMOL, String units) {
|
||||
String deltastring = "";
|
||||
if (deltaMGDL >=0){
|
||||
deltastring += "+";
|
||||
} else{
|
||||
deltastring += "-";
|
||||
|
||||
}
|
||||
if (units.equals(Constants.MGDL)){
|
||||
deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMGDL));
|
||||
}
|
||||
else {
|
||||
deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL));
|
||||
}
|
||||
return deltastring;
|
||||
}
|
||||
|
||||
private String slopeArrow(double delta) {
|
||||
String arrow = "NONE";
|
||||
if (delta <= (-3.5*5)) {
|
||||
|
@ -219,22 +214,24 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
|
||||
|
||||
private void resendData() {
|
||||
/**if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
|
||||
long startTime = new Date().getTime() - (60000 * 60 * 24);
|
||||
BgReading last_bg = BgReading.last();
|
||||
List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
|
||||
BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getApplicationContext());
|
||||
if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); }
|
||||
long startTime = System.currentTimeMillis() - (long)(60000 * 60 * 5.5);
|
||||
BgReading last_bg = MainApp.getDbHelper().lastBg();
|
||||
|
||||
if (last_bg == null) return;
|
||||
|
||||
List<BgReading> graph_bgs = MainApp.getDbHelper().getDataFromTime(startTime);
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
|
||||
if (!graph_bgs.isEmpty()) {
|
||||
DataMap entries = dataMap(last_bg, mPrefs, bgGraphBuilder);
|
||||
DataMap entries = dataMapSingleBG(last_bg, glucoseStatus);
|
||||
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
|
||||
for (BgReading bg : graph_bgs) {
|
||||
dataMaps.add(dataMap(bg, mPrefs, bgGraphBuilder));
|
||||
dataMaps.add(dataMapSingleBG(bg, glucoseStatus));
|
||||
}
|
||||
entries.putDataMapArrayList("entries", dataMaps);
|
||||
|
||||
new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries);
|
||||
}*/
|
||||
ToastUtils.showToastInUiThread(this, "resendData()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -264,75 +261,12 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
}
|
||||
}
|
||||
|
||||
/**private DataMap dataMap(BgReading bg, SharedPreferences sPrefs, BgGraphBuilder bgGraphBuilder) {
|
||||
Double highMark = Double.parseDouble(sPrefs.getString("highValue", "170"));
|
||||
Double lowMark = Double.parseDouble(sPrefs.getString("lowValue", "70"));
|
||||
DataMap dataMap = new DataMap();
|
||||
|
||||
int battery = BgSendQueue.getBatteryLevel(getApplicationContext());
|
||||
|
||||
dataMap.putString("sgvString", bgGraphBuilder.unitized_string(bg.calculated_value));
|
||||
dataMap.putString("slopeArrow", bg.slopeArrow());
|
||||
dataMap.putDouble("timestamp", bg.timestamp); //TODO: change that to long (was like that in NW)
|
||||
dataMap.putString("delta", bgGraphBuilder.unitizedDeltaString(true, true));
|
||||
dataMap.putString("battery", "" + battery);
|
||||
dataMap.putLong("sgvLevel", sgvLevel(bg.calculated_value, sPrefs, bgGraphBuilder));
|
||||
dataMap.putInt("batteryLevel", (battery>=30)?1:0);
|
||||
dataMap.putDouble("sgvDouble", bg.calculated_value);
|
||||
dataMap.putDouble("high", inMgdl(highMark, sPrefs));
|
||||
dataMap.putDouble("low", inMgdl(lowMark, sPrefs));
|
||||
//TODO: Add raw again
|
||||
//dataMap.putString("rawString", threeRaw((prefs.getString("units", "mgdl").equals("mgdl"))));
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
|
||||
// TODO: Integrate these helper methods into BGGraphBuilder.
|
||||
// TODO: clean them up (no "if(boolean){return true; else return false;").
|
||||
// TODO: Make the needed methods in BgGraphBuilder static.
|
||||
|
||||
public long sgvLevel(double sgv_double, SharedPreferences prefs, BgGraphBuilder bgGB) {
|
||||
Double highMark = Double.parseDouble(prefs.getString("highValue", "170"));
|
||||
Double lowMark = Double.parseDouble(prefs.getString("lowValue", "70"));
|
||||
if(bgGB.unitized(sgv_double) >= highMark) {
|
||||
return 1;
|
||||
} else if (bgGB.unitized(sgv_double) >= lowMark) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public double inMgdl(double value, SharedPreferences sPrefs) {
|
||||
if (!doMgdl(sPrefs)) {
|
||||
return value * Constants.MMOLL_TO_MGDL;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean doMgdl(SharedPreferences sPrefs) {
|
||||
String unit = sPrefs.getString("units", "mgdl");
|
||||
if (unit.compareTo("mgdl") == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (googleApiClient != null && googleApiClient.isConnected()) {
|
||||
googleApiClient.disconnect();
|
||||
}
|
||||
if (mPrefs != null && mPreferencesListener != null) {
|
||||
mPrefs.unregisterOnSharedPreferenceChangeListener(mPreferencesListener);
|
||||
}
|
||||
WearPlugin.unRegisterWatchUpdaterService();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:weightSum="1">
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
|
@ -19,12 +18,10 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:paddingTop="5dp"
|
||||
android:weightSum="1"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delta"
|
||||
android:textSize="30sp"
|
||||
|
@ -51,30 +48,38 @@
|
|||
<lecho.lib.hellocharts.view.LineChartView
|
||||
android:id="@+id/chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="77dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="center_horizontal|top" />
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/aps_status"
|
||||
android:textSize="18sp"
|
||||
android:text="E xU/h IOB: x (x+x)"
|
||||
android:layout_width="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:weightSum="1">
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/watch_time"
|
||||
android:textSize="35sp"
|
||||
android:text="12:00"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:layout_marginRight="6dp"
|
||||
android:layout_gravity="center_horizontal|top" />
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timestamp"
|
||||
|
@ -83,8 +88,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_gravity="top"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:weightSum="1">
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
|
@ -19,12 +18,10 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:paddingTop="5dp"
|
||||
android:weightSum="1"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/delta"
|
||||
android:textSize="30sp"
|
||||
|
@ -51,30 +48,38 @@
|
|||
<lecho.lib.hellocharts.view.LineChartView
|
||||
android:id="@+id/chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="77dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="center_horizontal|top" />
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/aps_status"
|
||||
android:textSize="18sp"
|
||||
android:text="E xU/h IOB: x (x+x)"
|
||||
android:layout_width="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:weightSum="1">
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/watch_time"
|
||||
android:textSize="35sp"
|
||||
android:text="12:00"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:layout_marginRight="6dp"
|
||||
android:layout_gravity="center_horizontal|top" />
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/timestamp"
|
||||
|
@ -83,8 +88,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FFFFFF"
|
||||
android:layout_gravity="top"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in a new issue