wear settings

This commit is contained in:
AdrianLxM 2016-11-24 16:08:01 +01:00
parent c633904e8c
commit 12e78656b7
10 changed files with 87 additions and 70 deletions

View file

@ -3,12 +3,14 @@ package info.nightscout.androidaps.plugins.Overview;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
@ -72,6 +74,7 @@ import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
@ -79,6 +82,7 @@ public class OverviewFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
private static OverviewPlugin overviewPlugin = new OverviewPlugin();
private SharedPreferences prefs;
public static OverviewPlugin getPlugin() {
return overviewPlugin;
@ -121,6 +125,8 @@ public class OverviewFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
View view = inflater.inflate(R.layout.overview_fragment, container, false);
bgView = (TextView) view.findViewById(R.id.overview_bg);
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
@ -578,8 +584,16 @@ public class OverviewFragment extends Fragment {
long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000L;
Double lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units);
Double highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units);
Double lowLine = SafeParse.stringToDouble(prefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(prefs.getString("high_mark", "0"));
if (lowLine < 1){
lowLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units);
}
if(highLine < 1){
highLine = NSProfile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units);
}
BarGraphSeries<DataPoint> basalsSeries = null;
LineGraphSeries<DataPoint> seriesLow = null;
@ -662,6 +676,7 @@ public class OverviewFragment extends Fragment {
}
maxBgValue = NSProfile.fromMgdlToUnits(maxBgValue, units);
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
if(highLine > maxBgValue) maxBgValue = highLine;
Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
BgReading[] inRange = new BgReading[inRangeArray.size()];

View file

@ -39,13 +39,14 @@ public class WearFragment extends Fragment implements FragmentBase {
}
});
view.findViewById(R.id.wear_opensettings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getPlugin(getContext()).openSettings();
}
});
return view;
}
//TODO Adrian: setting for short/long status string
//TODO Adrian: resend buttons
}

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.Wear.wearintegration.WatchUpdaterServi
public class WearPlugin implements PluginBase {
static boolean fragmentEnabled = true;
static boolean fragmentVisible = false;
static boolean fragmentVisible = true;
private static WatchUpdaterService watchUS;
private final Context ctx;
@ -94,25 +94,19 @@ public class WearPlugin implements PluginBase {
void resendDataToWatch(){
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND));
}
/* @Subscribe
public void onStatusEvent(final EventPreferenceChange ev) {
//TODO Adrian: probably a high/low mark change? Send it instantly?
sendDataToWatch();
void openSettings(){
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
}
@Subscribe
public void onStatusEvent(final EventRefreshGui ev) {
//TODO Adrian: anything here that is not covered by other cases?
sendDataToWatch();
public void onStatusEvent(final EventPreferenceChange ev) {
//possibly new high or low mark
resendDataToWatch();
}
*/
@Subscribe
public void onStatusEvent(final EventTreatmentChange ev) {
sendDataToWatch(true, true, false);
@ -125,7 +119,6 @@ public class WearPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
sendDataToWatch(true, true, true);
}

View file

@ -30,9 +30,11 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
public class WatchUpdaterService extends WearableListenerService implements
GoogleApiClient.ConnectionCallbacks,
@ -151,21 +153,38 @@ public class WatchUpdaterService extends WearableListenerService implements
}
private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) {
Double highMark = 170d; //in mg/dl TODO: dynamically read this?
Double lowMark = 70d;
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0"));
Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0"));
//convert to mg/dl
if (! profile.getUnits().equals(Constants.MGDL)){
lowLine *= Constants.MMOLL_TO_MGDL;
highLine *= Constants.MMOLL_TO_MGDL;
}
if (lowLine < 1){
lowLine = OverviewPlugin.bgTargetLow;
}
if(highLine < 1){
highLine = OverviewPlugin.bgTargetHigh;
}
long sgvLevel = 0l;
if (lastBG.value > highMark) {
if (lastBG.value > highLine) {
sgvLevel = 1;
} else if (lastBG.value < lowMark) {
} else if (lastBG.value < lowLine) {
sgvLevel = -1;
}
DataMap dataMap = new DataMap();
int battery = getBatteryLevel(getApplicationContext());
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits()));
dataMap.putDouble("timestamp", lastBG.getTimeIndex()); //TODO: change that to long (was like that in NW)
dataMap.putDouble("timestamp", lastBG.getTimeIndex());
if(glucoseStatus == null) {
dataMap.putString("slopeArrow", "" );
dataMap.putString("delta", "");
@ -179,8 +198,8 @@ public class WatchUpdaterService extends WearableListenerService implements
dataMap.putLong("sgvLevel", sgvLevel);
dataMap.putInt("batteryLevel", (battery>=30)?1:0);
dataMap.putDouble("sgvDouble", lastBG.value);
dataMap.putDouble("high", highMark);
dataMap.putDouble("low", lowMark);
dataMap.putDouble("high", highLine);
dataMap.putDouble("low", lowLine);
return dataMap;
}
@ -347,37 +366,6 @@ public class WatchUpdaterService extends WearableListenerService implements
}
}
//TODO: Adrian: replace fake data
/* long from = startTimeWindow;
long to = (now + from)/2;
double amount = 0.5;
from = (long)(startTimeWindow + (1/8d)*(now - startTimeWindow));
double fromBasal = 0.5;
to = (long)(startTimeWindow + (2/8d)*(now - startTimeWindow));
double toBasal = 0.5;
amount = 3;
temps.add(tempDatamap(from, fromBasal, to, toBasal, amount));
from = (long)(startTimeWindow + (6/8d)*(now - startTimeWindow));
fromBasal = 0.8;
to = (long)(startTimeWindow + (7/8d)*(now - startTimeWindow));
toBasal = 0.8;
amount = 0;
temps.add(tempDatamap(from, fromBasal, to, toBasal, amount));
*/
DataMap dm = new DataMap();
dm.putDataMapArrayList("basals", basals);
dm.putDataMapArrayList("temps", temps);
@ -421,9 +409,6 @@ public class WatchUpdaterService extends WearableListenerService implements
if (googleApiClient.isConnected()) {
String status = "";
//TODO Adrian: Setting if short or medium string.
boolean shortString = true;
//Temp basal

View file

@ -20,7 +20,20 @@
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="Resend All Data"
android:textColor="@color/colorProfileSwitchButton" />
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/wear_opensettings"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="Open Settings on Wear"
android:textColor="@color/colorTreatmentButton" />
</LinearLayout>

View file

@ -24,5 +24,21 @@
android:inputType="numberDecimal">
</EditTextPreference>
</PreferenceScreen>
<PreferenceScreen
android:title="Range for Visualization"
android:summary= "High and low mark for the charts in Overview and Smartwatch">
<EditTextPreference
android:title="LOW mark"
android:key="low_mark"
android:defaultValue="0"
android:inputType="number">
</EditTextPreference>
<EditTextPreference
android:title="HIGH mark"
android:key="high_mark"
android:defaultValue="0"
android:inputType="number">
</EditTextPreference>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -399,7 +399,6 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
public void run() {
//TODO:Wakelock?
setIsAnimated(true);
for (int i = 0; i <= 8 * 1000 / 40; i++) {
updateRainbow();

View file

@ -201,7 +201,6 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh
//Also possible: View.INVISIBLE instead of View.GONE (no layout change)
textView.setVisibility(View.INVISIBLE);
}
//TODO: add more view elements?
myLayout.measure(specW, specH);
myLayout.layout(0, 0, myLayout.getMeasuredWidth(),
@ -495,7 +494,6 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh
public void run() {
//TODO:Wakelock?
setIsAnimated(true);
for (int i = 0; i <= 8 * 1000 / 40; i++) {
animationStep();

View file

@ -94,7 +94,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String path = event.getDataItem().getUri().getPath();
if (path.equals(OPEN_SETTINGS)) {
//TODO: OpenSettings
Intent intent = new Intent(this, NWPreferences.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
@ -106,7 +105,6 @@ public class ListenerService extends WearableListenerService implements GoogleAp
messageIntent.putExtra("status", dataMap.toBundle());
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
} else if (path.equals(BASAL_DATA_PATH)){
//TODO Adrian receive basals in Watchfaces
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);

View file

@ -10,7 +10,6 @@ public class NWPreferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}