danar fragment update, danar pump password, toast with sound
This commit is contained in:
parent
62bb4d640f
commit
dbb0a6a659
10 changed files with 64 additions and 43 deletions
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.DanaR;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
@ -30,6 +31,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
|
@ -55,6 +57,7 @@ import info.nightscout.client.data.NSProfile;
|
|||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.SetWarnColor;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
|
@ -64,7 +67,6 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
private Handler mHandler;
|
||||
private static HandlerThread mHandlerThread;
|
||||
|
||||
private boolean mBounded;
|
||||
private static ExecutionService mExecutionService;
|
||||
|
||||
private static DanaRPump sDanaRPump = new DanaRPump();
|
||||
|
@ -73,7 +75,6 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
boolean fragmentPumpEnabled = true;
|
||||
boolean fragmentProfileEnabled = true;
|
||||
boolean fragmentPumpVisible = true;
|
||||
boolean visibleNow = false;
|
||||
|
||||
private Handler loopHandler = new Handler();
|
||||
private Runnable refreshLoop = null;
|
||||
|
@ -100,6 +101,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
public DanaRFragment() {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
useExtendedBoluses = sharedPreferences.getBoolean("danar_useextended", false);
|
||||
|
||||
mHandlerThread = new HandlerThread(DanaRFragment.class.getSimpleName());
|
||||
mHandlerThread.start();
|
||||
|
||||
|
@ -111,8 +113,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
|
||||
public static DanaRFragment newInstance() {
|
||||
DanaRFragment fragment = new DanaRFragment();
|
||||
return fragment;
|
||||
return new DanaRFragment();
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
|
@ -131,20 +132,11 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
refreshLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (visibleNow) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
|
||||
updateGUI();
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||
}
|
||||
};
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000l);
|
||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +166,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
});
|
||||
|
||||
historyButton.setOnClickListener(new View.OnClickListener() {
|
||||
historyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
||||
|
@ -217,13 +209,11 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
log.debug("Service is disconnected");
|
||||
mBounded = false;
|
||||
mExecutionService = null;
|
||||
}
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
log.debug("Service is connected");
|
||||
mBounded = true;
|
||||
ExecutionService.LocalBinder mLocalBinder = (ExecutionService.LocalBinder) service;
|
||||
mExecutionService = mLocalBinder.getServiceInstance();
|
||||
}
|
||||
|
@ -735,13 +725,11 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
}
|
||||
|
||||
public static boolean isConnected() {
|
||||
if (mExecutionService != null) return mExecutionService.isConnected();
|
||||
return false;
|
||||
return mExecutionService != null && mExecutionService.isConnected();
|
||||
}
|
||||
|
||||
public static boolean isConnecting() {
|
||||
if (mExecutionService != null) return mExecutionService.isConnecting();
|
||||
return false;
|
||||
return mExecutionService != null && mExecutionService.isConnecting();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -770,6 +758,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
pump.put("reservoir", (int) getDanaRPump().reservoirRemainingUnits);
|
||||
pump.put("clock", DateUtil.toISOString(new Date()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return pump;
|
||||
}
|
||||
|
@ -781,24 +770,13 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
|
||||
|
||||
// GUI functions
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
|
||||
if (isVisibleToUser) {
|
||||
visibleNow = true;
|
||||
updateGUI();
|
||||
} else
|
||||
visibleNow = false;
|
||||
|
||||
}
|
||||
|
||||
private void updateGUI() {
|
||||
final DateFormat formatTime = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && visibleNow && basaBasalRateView != null)
|
||||
if (activity != null && basaBasalRateView != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
@ -863,6 +841,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("PointlessBooleanExpression")
|
||||
@Override
|
||||
public Double applyBasalConstraints(Double absoluteRate) {
|
||||
double origAbsoluteRate = absoluteRate;
|
||||
|
@ -876,16 +855,18 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface
|
|||
return absoluteRate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("PointlessBooleanExpression")
|
||||
@Override
|
||||
public Integer applyBasalConstraints(Integer percentRate) {
|
||||
Integer origPercentRate = percentRate;
|
||||
if (percentRate < 0) percentRate = 0;
|
||||
if (percentRate > 200) percentRate = 200;
|
||||
if (percentRate != origPercentRate && Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit)
|
||||
if (!Objects.equals(percentRate, origPercentRate) && Config.logConstraintsChanges && !Objects.equals(origPercentRate, Constants.basalPercentOnlyForCheckLimit))
|
||||
log.debug("Limiting percent rate " + origPercentRate + "% to " + percentRate + "%");
|
||||
return percentRate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("PointlessBooleanExpression")
|
||||
@Override
|
||||
public Double applyBolusConstraints(Double insulin) {
|
||||
double origInsulin = insulin;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class DanaRPump {
|
|||
public Date shippingDate = new Date(0);
|
||||
public String shippingCountry = "";
|
||||
public boolean isNewPump = false;
|
||||
public int accessCode = -1;
|
||||
public int password = -1;
|
||||
public Date pumpTime = new Date(0);
|
||||
|
||||
// Status
|
||||
|
|
|
@ -177,6 +177,10 @@ public class DanaRHistoryActivity extends Activity {
|
|||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mExecutionService.isConnected() || mExecutionService.isConnecting()) {
|
||||
ToastUtils.showToastInUiThread(getApplicationContext(), getString(R.string.pumpbusy));
|
||||
return;
|
||||
}
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -76,6 +76,7 @@ import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusProgress;
|
|||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
|
||||
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class ExecutionService extends Service {
|
||||
|
@ -175,6 +176,10 @@ public class ExecutionService extends Service {
|
|||
}
|
||||
|
||||
public void connect(String from) {
|
||||
if (danaRPump.isNewPump && danaRPump.password != SafeParse.stringToInt(SP.getString("danar_password", "-1"))) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||
return;
|
||||
}
|
||||
if (isConnected()) {
|
||||
if (Config.logDanaBTComm)
|
||||
log.debug("already connected from:" + from);
|
||||
|
@ -182,6 +187,7 @@ public class ExecutionService extends Service {
|
|||
}
|
||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
||||
synchronized (connectionInProgress) {
|
||||
log.debug("entering connection whie loop");
|
||||
connectionInProgress = true;
|
||||
mWakeLock.acquire();
|
||||
getBTSocketForSelectedPump();
|
||||
|
@ -258,6 +264,7 @@ public class ExecutionService extends Service {
|
|||
mSerialIOThread.sendMessage(tempStatusMsg); // do this before statusBasic because here is temp duration
|
||||
mSerialIOThread.sendMessage(exStatusMsg);
|
||||
mSerialIOThread.sendMessage(statusMsg);
|
||||
waitMsec(100);
|
||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
||||
mSerialIOThread.sendMessage(new MsgSettingShippingInfo()); // TODO: show it somewhere
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ public class MsgInitConnStatusOption extends MessageBase {
|
|||
int h = intFromBuff(bytes, 7, 1);
|
||||
int i = intFromBuff(bytes, 8, 1);
|
||||
if (bytes.length >= 21) {
|
||||
DanaRFragment.getDanaRPump().accessCode = intFromBuff(bytes, 9, 2) ^ 0x3463;
|
||||
DanaRFragment.getDanaRPump().password = intFromBuff(bytes, 9, 2) ^ 0x3463;
|
||||
DanaRFragment.getDanaRPump().isNewPump = true;
|
||||
if (Config.logDanaMessageDetail)
|
||||
log.debug("Pump password: " + DanaRFragment.getDanaRPump().accessCode);
|
||||
log.debug("Pump password: " + DanaRFragment.getDanaRPump().password);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package info.nightscout.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ToastUtils {
|
||||
|
||||
public class ToastUtils {
|
||||
public static void showToastInUiThread(final Context ctx,
|
||||
final String string) {
|
||||
|
||||
|
@ -18,4 +19,22 @@ public class ToastUtils {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void showToastInUiThread(final Context ctx,
|
||||
final String string, int soundID) {
|
||||
|
||||
showToastInUiThread(ctx, string);
|
||||
playSound(ctx, soundID);
|
||||
}
|
||||
|
||||
public static void playSound(final Context ctx, final int soundID) {
|
||||
final MediaPlayer soundMP = MediaPlayer.create(ctx, soundID);
|
||||
soundMP.start();
|
||||
soundMP.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
mp.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -226,7 +226,6 @@
|
|||
<string name="end_user_license_agreement">Licenční ujednání</string>
|
||||
<string name="end_user_license_agreement_i_understand">ROZUMÍM A PORVZUJI</string>
|
||||
<string name="hoursago">h zpět</string>
|
||||
<string name="limits_title"></string>
|
||||
<string name="nobtadapter">Nenalezen bluetooth adaptér</string>
|
||||
<string name="percent">Procent</string>
|
||||
<string name="reloadprofile">Obnovit profil</string>
|
||||
|
@ -276,4 +275,8 @@
|
|||
<string name="danar_sbolus">S bolus</string>
|
||||
<string name="danar_totaluploaded" formatted="false">Celkem nahráno %d záznamů</string>
|
||||
<string name="uploading">Nahrávám</string>
|
||||
<string name="pumpbusy">Pumpa je zaneprázdněna</string>
|
||||
<string name="wrongpumppassword">Špatné heslo k pumpě</string>
|
||||
<string name="mm640g"></string>
|
||||
<string name="danar_password">Heslo k pumpě (pouze verze 2016)</string>
|
||||
</resources>
|
|
@ -253,5 +253,4 @@
|
|||
<string name="nobtadapter">Kein Bluetoothadapter gefunden</string>
|
||||
<string name="remotebolusnotallowed">Remote Bolus nicht erlaubt</string>
|
||||
<string formatted="false" name="replywithcode">Um Bolus %.2fU bitte mit %s antworten</string>
|
||||
<string name="limits_title"></string>
|
||||
</resources>
|
||||
|
|
|
@ -285,5 +285,8 @@
|
|||
<string name="danar_history_refill">Refill</string>
|
||||
<string name="danar_history_syspend">Suspend</string>
|
||||
<string name="danar_history_connectingfor" formatted="false">Connecting for %d s</string>
|
||||
<string name="danar_password">Pump password (2016 pump only)</string>
|
||||
<string name="wrongpumppassword">Wrong pump password!</string>
|
||||
<string name="pumpbusy">Pump is busy</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
android:dialogTitle="@string/danar_bt_name_title"
|
||||
android:key="danar_bt_name"
|
||||
android:title="@string/danar_bt_name_title" />
|
||||
<EditTextPreference
|
||||
android:title="@string/danar_password"
|
||||
android:key="danar_password"
|
||||
android:inputType="numberPassword">
|
||||
</EditTextPreference>
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="danar_useextended"
|
||||
|
|
Loading…
Reference in a new issue