commit
0766f62a7c
|
@ -2,6 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="info.nightscout.androidaps">
|
||||
|
||||
<permission android:name="com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE"/>
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
|
|
|
@ -52,6 +52,8 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
|
|||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearFragment;
|
||||
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
|
||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslineFragment;
|
||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
|
@ -117,6 +119,7 @@ public class MainApp extends Application {
|
|||
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.getPlugin());
|
||||
|
||||
if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this));
|
||||
pluginsList.add(StatuslineFragment.getPlugin(this));
|
||||
pluginsList.add(new PersistentNotificationPlugin(this));
|
||||
pluginsList.add(NSClientInternalFragment.getPlugin());
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugi
|
|||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||
import info.nightscout.utils.LocaleHelper;
|
||||
|
||||
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
@ -138,6 +139,11 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
}
|
||||
}
|
||||
|
||||
StatuslinePlugin statuslinePlugin = (StatuslinePlugin) MainApp.getSpecificPlugin(StatuslinePlugin.class);
|
||||
if (statuslinePlugin != null && statuslinePlugin.isEnabled(PluginBase.GENERAL)) {
|
||||
addPreferencesFromResource(R.xml.pref_xdripstatus);
|
||||
}
|
||||
|
||||
initSummary(getPreferenceScreen());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package info.nightscout.androidaps.plugins.XDripStatusline;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
/**
|
||||
* Created by adrian on 17/11/16.
|
||||
*/
|
||||
|
||||
public class StatuslineFragment extends Fragment {
|
||||
|
||||
private static StatuslinePlugin statuslinePlugin;
|
||||
|
||||
public static StatuslinePlugin getPlugin(Context ctx) {
|
||||
|
||||
if (statuslinePlugin == null) {
|
||||
statuslinePlugin = new StatuslinePlugin(ctx);
|
||||
}
|
||||
|
||||
return statuslinePlugin;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
package info.nightscout.androidaps.plugins.XDripStatusline;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
/**
|
||||
* Created by adrian on 17/11/16.
|
||||
*/
|
||||
|
||||
public class StatuslinePlugin implements PluginBase {
|
||||
|
||||
//broadcast related constants
|
||||
public static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
|
||||
public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
|
||||
public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
|
||||
|
||||
|
||||
static boolean fragmentEnabled = false;
|
||||
private static boolean lastLoopStatus;
|
||||
|
||||
private final Context ctx;
|
||||
SharedPreferences mPrefs;
|
||||
|
||||
StatuslinePlugin(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
|
||||
if (fragmentEnabled) {
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return PluginBase.GENERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFragmentClass() {
|
||||
return StatuslineFragment.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return ctx.getString(R.string.xdripstatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameShort() {
|
||||
String name = MainApp.sResources.getString(R.string.xdripstatus_shortname);
|
||||
if (!name.trim().isEmpty()) {
|
||||
//only if translation exists
|
||||
return name;
|
||||
}
|
||||
// use long name as fallback
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int type) {
|
||||
return type == GENERAL && fragmentEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleInTabs(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHidden(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFragment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showInList(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||
if (type == GENERAL) {
|
||||
this.fragmentEnabled = fragmentEnabled;
|
||||
|
||||
if (fragmentEnabled) {
|
||||
MainApp.bus().register(this);
|
||||
sendStatus();
|
||||
}
|
||||
else{
|
||||
MainApp.bus().unregister(this);
|
||||
sendStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||
// do nothing, no gui
|
||||
}
|
||||
|
||||
|
||||
private void sendStatus() {
|
||||
|
||||
|
||||
String status = ""; // sent once on disable
|
||||
|
||||
if(fragmentEnabled) {
|
||||
status = buildStatusString();
|
||||
}
|
||||
|
||||
|
||||
//sendData
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(EXTRA_STATUSLINE, status);
|
||||
Intent intent = new Intent(ACTION_NEW_EXTERNAL_STATUSLINE);
|
||||
intent.putExtras(bundle);
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
ctx.sendBroadcast(intent, RECEIVER_PERMISSION);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String buildStatusString() {
|
||||
String status = "";
|
||||
boolean shortString = true; // make setting?
|
||||
|
||||
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
|
||||
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) {
|
||||
status += ctx.getString(R.string.disabledloop) + "\n";
|
||||
lastLoopStatus = false;
|
||||
} else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) {
|
||||
lastLoopStatus = true;
|
||||
}
|
||||
|
||||
//Temp basal
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
|
||||
if (pump.isTempBasalInProgress()) {
|
||||
TempBasal activeTemp = pump.getTempBasal();
|
||||
if (shortString) {
|
||||
status += activeTemp.toStringShort();
|
||||
} else {
|
||||
status += activeTemp.toStringMedium();
|
||||
}
|
||||
}
|
||||
|
||||
//IOB
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||
|
||||
|
||||
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
|
||||
status += "("
|
||||
+ DecimalFormatter.to2Decimal(bolusIob.iob) + "|"
|
||||
+ DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
// status may be formated differently
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventTreatmentChange ev) {
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventRefreshGui ev) {
|
||||
|
||||
//Filter events where loop is (de)activated
|
||||
|
||||
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
if (activeloop == null) return;
|
||||
|
||||
if ((lastLoopStatus != activeloop.isEnabled(PluginBase.LOOP))) {
|
||||
sendStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return fragmentEnabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -600,4 +600,7 @@
|
|||
<string name="nav_about">About</string>
|
||||
<string name="smscommunicator_missingsmspermission">Missing SMS permission</string>
|
||||
<string name="dev">DEV</string>
|
||||
<string name="xdripstatus_settings">xDrip Status (watch)</string>
|
||||
<string name="xdripstatus">xDrip Statusline (watch)</string>
|
||||
<string name="xdripstatus_shortname">xds</string>
|
||||
</resources>
|
||||
|
|
14
app/src/main/res/xml/pref_xdripstatus.xml
Normal file
14
app/src/main/res/xml/pref_xdripstatus.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:key="xdripstatus"
|
||||
android:title="@string/xdripstatus_settings">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="xdripstatus_detailediob"
|
||||
android:title="@string/wear_detailedIOB_title"
|
||||
android:summary="@string/wear_detailedIOB_summary"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue