diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 2cb501b99a..68df307dbf 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -114,7 +114,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe try { // activity may be destroyed setUpTabs(true); } catch (IllegalStateException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } boolean lockScreen = BuildConfig.NSCLIENTOLNY && SP.getBoolean("lockscreen", false); if (lockScreen) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 18727d87f0..fcd92331b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -4,6 +4,7 @@ import android.app.Application; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; +import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; @@ -167,10 +168,7 @@ public class MainApp extends Application { Thread t = new Thread(new Runnable() { @Override public void run() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - } + SystemClock.sleep(5000); PumpInterface pump = MainApp.getConfigBuilder(); if (pump != null) pump.refreshDataFromPump("Initialization"); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java index 41587e79b9..60dd92a2c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java @@ -50,7 +50,7 @@ public class AlarmSoundService extends Service { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); afd.close(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } player.setLooping(true); // Set looping player.setVolume(100, 100); @@ -59,7 +59,7 @@ public class AlarmSoundService extends Service { player.prepare(); player.start(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return START_STICKY; diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 39eb023cb3..05af04230d 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -244,7 +244,7 @@ public class DataService extends IntentService { MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT)); } } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) { Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.URGENT); @@ -269,7 +269,7 @@ public class DataService extends IntentService { if (targetlow != null) OverviewPlugin.bgTargetLow = targetlow; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } @@ -298,7 +298,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } // Handle profile @@ -313,7 +313,7 @@ public class DataService extends IntentService { if (Config.logIncommingData) log.debug("Received profileStore: " + activeProfile + " " + profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } if (intent.getAction().equals(Intents.ACTION_NEW_TREATMENT)) { @@ -332,7 +332,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -353,7 +353,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -376,7 +376,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -401,7 +401,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -430,7 +430,7 @@ public class DataService extends IntentService { } } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java index bd924d35b5..3240e79327 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java +++ b/app/src/main/java/info/nightscout/androidaps/data/IobTotal.java @@ -2,6 +2,8 @@ package info.nightscout.androidaps.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; @@ -9,6 +11,8 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.Round; public class IobTotal { + private static Logger log = LoggerFactory.getLogger(IobTotal.class); + public double iob; public double activity; public double bolussnooze; @@ -86,7 +90,7 @@ public class IobTotal { json.put("activity", activity); json.put("time", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } @@ -100,7 +104,7 @@ public class IobTotal { json.put("activity", activity); json.put("time", DateUtil.toISOString(new Date(time))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 984d92c4e5..09885448e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -109,7 +109,7 @@ public class Profile { MainApp.bus().post(new EventDismissNotification(Notification.TARGET_MISSING)); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.invalidprofile)); } } @@ -129,7 +129,7 @@ public class Profile { try { json.put("units", units); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } @@ -156,7 +156,7 @@ public class Profile { Double value = o.getDouble("value"); sparse.put(tas, value); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return sparse; @@ -176,7 +176,7 @@ public class Profile { } lastValue = value; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return lastValue; @@ -215,7 +215,7 @@ public class Profile { if (index + 1 < array.length()) retValue += "\n"; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retValue; @@ -297,7 +297,7 @@ public class Profile { } return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new BasalValue[0]; } diff --git a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java index 3e2217454f..f97d8b5e02 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java @@ -50,7 +50,7 @@ public class ProfileStore { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } @@ -65,7 +65,7 @@ public class ProfileStore { return defaultProfileName; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return defaultProfileName; } @@ -90,7 +90,7 @@ public class ProfileStore { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } @@ -108,7 +108,7 @@ public class ProfileStore { ret.add(profileName); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java index bfddeff320..7a4a520bee 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java +++ b/app/src/main/java/info/nightscout/androidaps/data/PumpEnactResult.java @@ -5,6 +5,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -12,6 +14,8 @@ import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; public class PumpEnactResult extends Object { + private static Logger log = LoggerFactory.getLogger(PumpEnactResult.class); + public boolean success = false; // request was processed successfully (but possible no change was needed) public boolean enacted = false; // request was processed successfully and change has been made public String comment = ""; @@ -101,7 +105,7 @@ public class PumpEnactResult extends Object { result.put("duration", duration); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index f65da51176..b80f4f932e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -142,7 +142,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { JSONObject object = new JSONObject(json); mbg = object.getDouble("mgdl"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Profile.fromMgdlToUnits(mbg, units); } @@ -155,7 +155,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { units = object.getString("units"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (glucose != 0d) { double mmol = 0d; @@ -186,7 +186,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { if (object.has("notes")) return object.getString("notes"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Translator.translate(eventType); } @@ -198,7 +198,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { if (object.has("duration")) return object.getInt("duration") * 60 * 1000L; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 2b4cc87f20..55533aeb4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -207,7 +207,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(true); scheduleBgChange(); // trigger refresh @@ -234,7 +234,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, Treatment.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -244,7 +244,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, TempTarget.class, true); TableUtils.createTableIfNotExists(connectionSource, TempTarget.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTemporaryTargetChange(); } @@ -255,7 +255,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } VirtualPumpPlugin.setFakingStatus(false); scheduleTemporaryBasalChange(); @@ -267,7 +267,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class); updateEarliestDataChange(0); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleExtendedBolusChange(); } @@ -277,7 +277,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -287,7 +287,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleProfileSwitchChange(); } @@ -353,7 +353,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -430,7 +430,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { bgReadings = daoBgreadings.query(preparedQuery); return bgReadings; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -441,7 +441,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoDbRequest().create(dbr); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -449,7 +449,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().delete(dbr); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -458,7 +458,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().deleteById(nsClientId); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -478,7 +478,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return delete(dbList.get(0)); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -487,7 +487,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { TableUtils.clearTable(connectionSource, DbRequest.class); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -495,7 +495,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { return getDaoDbRequest().closeableIterator(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return null; } } @@ -583,7 +583,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -593,7 +593,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTreatments().delete(treatment); updateEarliestDataChange(treatment.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -603,7 +603,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTreatments().update(treatment); updateEarliestDataChange(treatment.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTreatmentChange(); } @@ -636,7 +636,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return trList.get(0); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -685,7 +685,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { treatments = daoTreatments.query(preparedQuery); return treatments; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -715,7 +715,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } createOrUpdate(treatment); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -733,7 +733,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempTargets = daoTempTargets.query(preparedQuery); return tempTargets; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -787,7 +787,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -797,7 +797,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTempTargets().delete(tempTarget); scheduleTemporaryTargetChange(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -847,7 +847,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempTarget.source = Source.NIGHTSCOUT; createOrUpdate(tempTarget); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -874,7 +874,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -885,7 +885,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoDanaRHistory().createOrUpdate(record); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -900,7 +900,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { PreparedQuery preparedQuery = queryBuilder.prepare(); historyList = getDaoDanaRHistory().query(preparedQuery); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); historyList = new ArrayList<>(); } return historyList; @@ -927,7 +927,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1013,7 +1013,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1023,7 +1023,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTemporaryBasal().delete(tempBasal); updateEarliestDataChange(tempBasal.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleTemporaryBasalChange(); } @@ -1039,7 +1039,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { tempbasals = getDaoTemporaryBasal().query(preparedQuery); return tempbasals; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1132,7 +1132,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { createOrUpdate(tempBasal); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1161,7 +1161,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return list.get(0); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1242,7 +1242,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1252,7 +1252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoExtendedBolus().delete(extendedBolus); updateEarliestDataChange(extendedBolus.date); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleExtendedBolusChange(); } @@ -1268,7 +1268,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBoluses = getDaoExtendedBolus().query(preparedQuery); return extendedBoluses; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1298,7 +1298,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1349,7 +1349,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBolus._id = trJson.getString("_id"); createOrUpdate(extendedBolus); } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1383,7 +1383,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoCareportalEvents().createOrUpdate(careportalEvent); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -1392,7 +1392,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoCareportalEvents().delete(careportalEvent); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } scheduleCareportalEventChange(); } @@ -1413,7 +1413,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { else return null; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -1429,7 +1429,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { careportalEvents = getDaoCareportalEvents().query(preparedQuery); return careportalEvents; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1453,7 +1453,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.debug("CareportalEvent not found database: " + _id); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1486,7 +1486,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { careportalEvent._id = trJson.getString("_id"); createOrUpdate(careportalEvent); } catch (SQLException | JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1521,7 +1521,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitches = daoProfileSwitch.query(preparedQuery); return profileSwitches; } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return new ArrayList(); } @@ -1575,7 +1575,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return true; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -1585,7 +1585,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoProfileSwitch().delete(profileSwitch); scheduleProfileSwitchChange(); } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1640,7 +1640,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitch.profilePlugin = trJson.getString("profilePlugin"); createOrUpdate(profileSwitch); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -1667,7 +1667,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java index 203436661c..fcda5c9c04 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java @@ -77,7 +77,7 @@ public class DbRequest { if (_id != null) object.put("_id", _id); if (nsClientID != null) object.put("nsClientID", nsClientID); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return object; } @@ -96,7 +96,7 @@ public class DbRequest { if (jsonObject.has("nsClientID")) result.nsClientID = jsonObject.getString("nsClientID"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index fb99934382..cd5efc7465 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -60,7 +60,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { try { profile = new Profile(new JSONObject(profileJson)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return profile; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index 8a4d4001cb..f434a08d96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -21,6 +21,9 @@ import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; @@ -37,6 +40,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; public class FillDialog extends DialogFragment implements OnClickListener { + private static Logger log = LoggerFactory.getLogger(FillDialog.class); Button deliverButton; TextView insulin; @@ -183,8 +187,8 @@ public class FillDialog extends DialogFragment implements OnClickListener { builder.setNegativeButton(getString(R.string.cancel), null); builder.show(); dismiss(); - } catch (Exception e) { - e.printStackTrace(); + } catch (RuntimeException e) { + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java index c85d5c4540..1bfab76993 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java @@ -17,6 +17,9 @@ import android.widget.RadioButton; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.Constants; @@ -28,6 +31,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(NewExtendedBolusDialog.class); PlusMinusEditText editInsulin; PlusMinusEditText editDuration; @@ -115,7 +119,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 9582dced87..9bd6cd26c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -19,6 +19,9 @@ import android.widget.RelativeLayout; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; @@ -32,6 +35,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener { + private static Logger log = LoggerFactory.getLogger(NewTempBasalDialog.class); RadioButton percentRadio; RadioButton absoluteRadio; @@ -180,7 +184,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index b10ab5dab8..cc337d6c00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -482,7 +482,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return data; } @@ -577,7 +577,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick ret += "\n"; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; @@ -596,7 +596,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick try { doProfileSwitch(profileStore, data.getString("profile"), data.getInt("duration")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } else if (options.executeTempTarget) { @@ -623,13 +623,13 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick NSUpload.uploadCareportalEntryToNS(data); Answers.getInstance().logCustom(new CustomEvent("TempTarget")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } else { NSUpload.uploadCareportalEntryToNS(data); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 6bc0e1e807..aa603286f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -185,7 +185,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (SP.contains(settingVisible)) p.setFragmentVisible(type, SP.getBoolean(settingVisible, true) && SP.getBoolean(settingEnabled, true)); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } @@ -989,7 +989,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain MainApp.bus().post(new EventNewNotification(notarget)); return new Profile(new JSONObject("{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"20\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"6\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"8\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}}")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index e04efb70cb..81e0493746 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -227,7 +227,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { o.started = new Date(SP.getLong("Objectives" + num + "started", 0L)); o.accomplished = new Date(SP.getLong("Objectives" + num + "accomplished", 0L)); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } bgIsAvailableInNS = SP.getBoolean("Objectives" + "bgIsAvailableInNS", false); @@ -235,7 +235,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { try { manualEnacts = SP.getInt("Objectives" + "manualEnacts", 0); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (Config.logPrefsChange) log.debug("Objectives loaded"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java index 1e40005b36..4e0f8ef107 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java @@ -2,11 +2,14 @@ package info.nightscout.androidaps.plugins.IobCobCalculator; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Created by mike on 06.01.2017. */ public class AutosensResult { + private static Logger log = LoggerFactory.getLogger(AutosensResult.class); //default values to show when autosens algorithm is not called public double ratio = 1d; @@ -24,7 +27,7 @@ public class AutosensResult { ret.put("sensResult", sensResult); ret.put("ratio", ratio); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ret; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 69e161524f..a1a3d9c904 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -7,6 +7,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,6 +19,8 @@ import info.nightscout.utils.DecimalFormatter; * Created by mike on 09.06.2016. */ public class APSResult { + private static Logger log = LoggerFactory.getLogger(APSResult.class); + public String reason; public double rate; public int duration; @@ -72,7 +76,7 @@ public class APSResult { json.put("reason", reason); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return json; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java index 3080717773..acf59865d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/DeviceStatus.java @@ -397,7 +397,7 @@ public class DeviceStatus { if (uploaderBattery != 0) record.put("uploaderBattery", uploaderBattery); if (created_at != null) record.put("created_at" , created_at); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return record; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java index 76a2855478..114ace4c30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/UploadQueue.java @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.NSClientInternal; import android.content.Context; import android.content.Intent; +import android.os.SystemClock; import com.j256.ormlite.dao.CloseableIterator; @@ -35,10 +36,7 @@ public class UploadQueue { if (NSClientService.handler == null) { Context context = MainApp.instance(); context.startService(new Intent(context, NSClientService.class)); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - } + SystemClock.sleep(2000); } } @@ -90,7 +88,7 @@ public class UploadQueue { log.debug("Removed item from UploadQueue. " + UploadQueue.status()); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }); @@ -126,7 +124,7 @@ public class UploadQueue { iterator.close(); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java index b4ba0c3364..709c53f6d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSAddAck.java @@ -49,7 +49,7 @@ public class NSAddAck implements Ack { } return; } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java index 2824e922aa..1ec6e3991c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/acks/NSPingAck.java @@ -1,7 +1,11 @@ package info.nightscout.androidaps.plugins.NSClientInternal.acks; +import android.os.SystemClock; + import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.socket.client.Ack; @@ -9,6 +13,8 @@ import io.socket.client.Ack; * Created by mike on 29.12.2015. */ public class NSPingAck implements Ack { + private static Logger log = LoggerFactory.getLogger(NSPingAck.class); + public long mills = 0; public boolean received = false; public boolean auth_received = false; @@ -27,7 +33,7 @@ public class NSPingAck implements Ack { write = authorization.optBoolean("write"); write_treatment = authorization.optBoolean("write_treatment"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } received = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java index 7c6862cb14..4ee2427af8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java @@ -32,7 +32,7 @@ public class BroadcastStatus { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode); } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName); bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode); @@ -49,7 +49,7 @@ public class BroadcastStatus { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode); } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName); bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 99644c7ba3..572cf7e055 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -192,7 +192,7 @@ public class BroadcastTreatment { ret.add(newarr); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); ret = new ArrayList<>(); ret.add(array); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java index f7a7f79303..1c28b790d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSAlarm.java @@ -2,12 +2,16 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Created by mike on 11.06.2017. */ public class NSAlarm { + private static Logger log = LoggerFactory.getLogger(NSAlarm.class); + JSONObject data; public NSAlarm(JSONObject data) { @@ -20,7 +24,7 @@ public class NSAlarm { try { retval = data.getInt("level"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -32,7 +36,7 @@ public class NSAlarm { try { retval = data.getString("group"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -44,7 +48,7 @@ public class NSAlarm { try { retval = data.getString("title"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; @@ -56,7 +60,7 @@ public class NSAlarm { try { retval = data.getString("message"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return retval; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java index 74b5f688d9..93d46fa18e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSCal.java @@ -19,7 +19,7 @@ public class NSCal { intercept = json.getDouble("intercept"); scale = json.getDouble("scale"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); log.debug("Data: " + json.toString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index 8ce3fc87e2..2a2e1b8044 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -5,6 +5,8 @@ import android.text.Spanned; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Iterator; @@ -70,6 +72,7 @@ import info.nightscout.utils.SP; } */ public class NSDeviceStatus { + private static Logger log = LoggerFactory.getLogger(NSDeviceStatus.class); private static NSDeviceStatus instance = null; @@ -102,7 +105,7 @@ public class NSDeviceStatus { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -237,7 +240,7 @@ public class NSDeviceStatus { deviceStatusPumpData.extended = Html.fromHtml(exteneded.toString()); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -278,7 +281,7 @@ public class NSDeviceStatus { deviceStatusOpenAPSData.clockEnacted = clock; } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -315,7 +318,7 @@ public class NSDeviceStatus { string.append("").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append(" ").append(deviceStatusOpenAPSData.suggested.getString("reason")).append("
"); return Html.fromHtml(string.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return Html.fromHtml(""); } @@ -353,7 +356,7 @@ public class NSDeviceStatus { uploaders.put(device, uploader); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java index 79fa60c3bb..353dd49b74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSMbg.java @@ -17,7 +17,7 @@ public class NSMbg { mbg = json.getDouble("mgdl"); this.json = json.toString(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); log.debug("Data: " + json.toString()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java index c2c3aa036f..3feced94cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSettingsStatus.java @@ -4,6 +4,8 @@ import android.support.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; import java.util.Objects; @@ -99,6 +101,8 @@ import java.util.Objects; } */ public class NSSettingsStatus { + private static Logger log = LoggerFactory.getLogger(NSSettingsStatus.class); + private static NSSettingsStatus instance = null; public static NSSettingsStatus getInstance() { @@ -160,7 +164,7 @@ public class NSSettingsStatus { return new JSONObject(extended); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; @@ -195,7 +199,7 @@ public class NSSettingsStatus { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -207,7 +211,7 @@ public class NSSettingsStatus { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -219,7 +223,7 @@ public class NSSettingsStatus { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -231,7 +235,7 @@ public class NSSettingsStatus { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -243,7 +247,7 @@ public class NSSettingsStatus { try { ret = new Date(data.getString(key)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -255,7 +259,7 @@ public class NSSettingsStatus { try { ret = data.getBoolean(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -301,7 +305,7 @@ public class NSSettingsStatus { return pump != null && pump.has(setting) ? pump.getDouble(setting) : 30; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0d; } @@ -317,7 +321,7 @@ public class NSSettingsStatus { return pump; } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -329,7 +333,7 @@ public class NSSettingsStatus { return pump.getBoolean("enableAlerts"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } @@ -341,7 +345,7 @@ public class NSSettingsStatus { return pump.getString("fields"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -353,7 +357,7 @@ public class NSSettingsStatus { return pump.getBoolean("enableAlerts"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java index 78ddc7a8f7..af134ea50d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSSgv.java @@ -2,12 +2,16 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * * {"mgdl":105,"mills":1455136282375,"device":"xDrip-BluetoothWixel","direction":"Flat","filtered":98272,"unfiltered":98272,"noise":1,"rssi":100} */ public class NSSgv { + private static Logger log = LoggerFactory.getLogger(NSSgv.class); + private JSONObject data; public NSSgv(JSONObject obj) { @@ -20,7 +24,7 @@ public class NSSgv { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -32,7 +36,7 @@ public class NSSgv { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -44,7 +48,7 @@ public class NSSgv { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java index 1b48f27e2f..a9f960edd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSTreatment.java @@ -2,10 +2,14 @@ package info.nightscout.androidaps.plugins.NSClientInternal.data; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; public class NSTreatment { + private static Logger log = LoggerFactory.getLogger(NSTreatment.class); + private JSONObject data; private String action = null; // "update", "remove" or null (add) @@ -21,7 +25,7 @@ public class NSTreatment { try { ret = data.getString(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -33,7 +37,7 @@ public class NSTreatment { try { ret = data.getDouble(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -45,7 +49,7 @@ public class NSTreatment { try { ret = data.getInt(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -57,7 +61,7 @@ public class NSTreatment { try { ret = data.getLong(key); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; @@ -69,7 +73,7 @@ public class NSTreatment { try { ret = new Date(data.getString(key)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return ret; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 3546a1d5e0..a9f3509213 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -50,9 +50,18 @@ public class DBAccessReceiver extends BroadcastReceiver { String _id = null; JSONObject data = null; String action = bundles.getString("action"); - try { collection = bundles.getString("collection"); } catch (Exception e) {} - try { _id = bundles.getString("_id"); } catch (Exception e) {} - try { data = new JSONObject(bundles.getString("data")); } catch (Exception e) {} + try { + collection = bundles.getString("collection"); + } catch (Exception e) { + } + try { + _id = bundles.getString("_id"); + } catch (Exception e) { + } + try { + data = new JSONObject(bundles.getString("data")); + } catch (Exception e) { + } if (data == null && !action.equals("dbRemove") || _id == null && action.equals("dbRemove")) { log.debug("DBACCESS no data inside record"); @@ -67,7 +76,7 @@ public class DBAccessReceiver extends BroadcastReceiver { try { data.put("NSCLIENT_ID", nsclientid); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (!isAllowedCollection(collection)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index cbc18acbca..465d5e42c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -258,7 +258,7 @@ public class NSClientService extends Service { authMessage.put("from", latestDateInReceivedData); // send data newer than authMessage.put("secret", nsAPIhashCode); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return; } MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth")); @@ -326,7 +326,7 @@ public class NSClientService extends Service { try { MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", data.has("message") ? data.getString("message") : "received")); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } BroadcastAnnouncement.handleAnnouncement(data, getApplicationContext()); log.debug(data.toString()); @@ -561,7 +561,7 @@ public class NSClientService extends Service { } MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } //MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end"); } finally { @@ -583,7 +583,7 @@ public class NSClientService extends Service { mSocket.emit("dbUpdate", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -597,7 +597,7 @@ public class NSClientService extends Service { mSocket.emit("dbUpdateUnset", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -610,7 +610,7 @@ public class NSClientService extends Service { mSocket.emit("dbRemove", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -633,7 +633,7 @@ public class NSClientService extends Service { mSocket.emit("dbAdd", message, ack); MainApp.bus().post(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -684,10 +684,11 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason)); CloseableIterator iterator = null; + int maxcount = 30; try { iterator = MainApp.getDbHelper().getDbRequestInterator(); try { - while (iterator.hasNext()) { + while (iterator.hasNext() && maxcount > 0) { DbRequest dbr = iterator.next(); if (dbr.action.equals("dbAdd")) { NSAddAck addAck = new NSAddAck(); @@ -702,12 +703,13 @@ public class NSClientService extends Service { NSUpdateAck updateUnsetAck = new NSUpdateAck(dbr.action, dbr._id); dbUpdateUnset(dbr, updateUnsetAck); } + maxcount--; } } finally { iterator.close(); } } catch (SQLException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 7833dbf54e..44ab8ecb14 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -103,7 +103,7 @@ public class DetermineBasalAdapterAMAJS { try { result = new DetermineBasalResultAMA(v8ObjectReuslt, new JSONObject(ret)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java index c2a55ff894..31501b7032 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalResultAMA.java @@ -5,6 +5,8 @@ import com.eclipsesource.v8.V8Object; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; @@ -15,6 +17,8 @@ import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.data.IobTotal; public class DetermineBasalResultAMA extends APSResult { + private static Logger log = LoggerFactory.getLogger(DetermineBasalResultAMA.class); + public Date date; public JSONObject json = new JSONObject(); public double eventualBG; @@ -69,7 +73,7 @@ public class DetermineBasalResultAMA extends APSResult { try { newResult.json = new JSONObject(json.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } newResult.eventualBG = eventualBG; newResult.snoozeBG = snoozeBG; @@ -83,7 +87,7 @@ public class DetermineBasalResultAMA extends APSResult { JSONObject ret = new JSONObject(this.json.toString()); return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -126,7 +130,7 @@ public class DetermineBasalResultAMA extends APSResult { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return array; } @@ -151,7 +155,7 @@ public class DetermineBasalResultAMA extends APSResult { } } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return latest; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java index 419a55f057..c0d0662747 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAFragment.java @@ -112,7 +112,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam()); iobDataView.setText(String.format(MainApp.sResources.getString(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); iobDataView.setText("JSONException"); } profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam())); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 53bcfcf1ec..28bc0f9e4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -160,8 +160,8 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { double maxIob = SP.getDouble("openapsma_max_iob", 1.5d); double maxBasal = SP.getDouble("openapsma_max_basal", 1d); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); + double minBg = Profile.toMgdl(profile.getTargetLow(), units); + double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); double targetBg = (minBg + maxBg) / 2; minBg = Round.roundTo(minBg, 0.1d); @@ -242,7 +242,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { try { determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index a03ef9731b..a8f797f8c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -135,7 +135,7 @@ public class DetermineBasalAdapterMAJS { try { result = new DetermineBasalResultMA(v8ObjectReuslt, new JSONObject(ret)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } storedGlucoseStatus = mV8rt.executeStringScript("JSON.stringify(" + PARAM_glucoseStatus + ");"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java index a0cd1a75b0..23f7c14a88 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalResultMA.java @@ -7,11 +7,14 @@ import com.eclipsesource.v8.V8Object; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.plugins.Loop.APSResult; public class DetermineBasalResultMA extends APSResult { + private static Logger log = LoggerFactory.getLogger(DetermineBasalResultMA.class); public JSONObject json = new JSONObject(); public double eventualBG; @@ -70,7 +73,7 @@ public class DetermineBasalResultMA extends APSResult { try { newResult.json = new JSONObject(json.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } newResult.eventualBG = eventualBG; newResult.snoozeBG = snoozeBG; @@ -84,7 +87,7 @@ public class DetermineBasalResultMA extends APSResult { JSONObject ret = new JSONObject(this.json.toString()); return ret; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 95f1235161..a5c2276a2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -160,8 +160,8 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { double maxIob = SP.getDouble("openapsma_max_iob", 1.5d); double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1")); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); + double minBg = Profile.toMgdl(profile.getTargetLow(), units); + double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); double targetBg = (minBg + maxBg) / 2; minBg = Round.roundTo(minBg, 0.1d); @@ -196,7 +196,8 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getDia(), "dia", 2, 7)) return; if (!checkOnlyHardLimits(profile.getIc(), "carbratio", 2, 100)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900)) return; + if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf().doubleValue(), units), "sens", 2, 900)) + return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; @@ -224,7 +225,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { try { determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index f536af5860..192bffba3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs; import android.app.Activity; import android.os.Bundle; +import android.os.SystemClock; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; @@ -22,7 +23,6 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; public class BolusProgressDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(BolusProgressDialog.class); @@ -36,8 +36,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL public static boolean bolusEnded = false; public static boolean running = true; - boolean started = false; - public BolusProgressDialog() { super(); } @@ -123,11 +121,6 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL } } - @Subscribe - public void onStatusEvent(final EventDanaRBolusStart ev) { - started = true; - } - @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { if(BolusProgressDialog.running){ @@ -156,11 +149,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL Thread t = new Thread(new Runnable() { @Override public void run() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(5000); BolusProgressDialog.bolusEnded = true; Activity activity = getActivity(); if (activity != null) { @@ -171,7 +160,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL try { dismiss(); } catch (Exception e) { - e.printStackTrace(); // TODO: do this better way + log.error("Unhandled exception", e); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java index 1179841098..95bcea7908 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java @@ -14,6 +14,8 @@ import android.widget.EditText; import android.widget.Spinner; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -27,6 +29,7 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.SafeParse; public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class); QuickWizard.QuickWizardEntry entry = new QuickWizard().newEmptyItem(); QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard; @@ -104,7 +107,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic int validToInt = DateUtil.toSeconds(toSpinner.getSelectedItem().toString()); entry.storage.put("validTo", validToInt); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } quickWizard.addOrUpdate(entry); dismiss(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index e2edb1e76a..faa3ff0785 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -7,6 +7,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -19,6 +20,9 @@ import android.widget.TextView; import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.CustomEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DecimalFormat; import java.util.Objects; @@ -35,6 +39,7 @@ import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; public class NewTreatmentDialog extends DialogFragment implements OnClickListener { + private static Logger log = LoggerFactory.getLogger(NewTreatmentDialog.class); NumberPicker editCarbs; NumberPicker editInsulin; @@ -80,15 +85,16 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Double insulin = SafeParse.stringToDouble(editInsulin.getText()); final Integer carbs = SafeParse.stringToInt(editCarbs.getText()); - String confirmMessage = getString(R.string.entertreatmentquestion) + "\n"; + String confirmMessage = getString(R.string.entertreatmentquestion) + "
"; Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs); - confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; - confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + confirmMessage += getString(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""; + confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - insulin != 0 || !Objects.equals(carbsAfterConstraints, carbs)) - confirmMessage += "\n" + getString(R.string.constraintapllied); + confirmMessage += "
" + getString(R.string.constraintapllied); + final double finalInsulinAfterConstraints = insulinAfterConstraints; final int finalCarbsAfterConstraints = carbsAfterConstraints; @@ -97,7 +103,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(this.getContext().getString(R.string.confirmation)); - builder.setMessage(confirmMessage); + builder.setMessage(Html.fromHtml(confirmMessage)); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { @@ -130,7 +136,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene builder.show(); dismiss(); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } break; case R.id.cancel: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index bda03a8a27..98428f9493 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -9,6 +9,7 @@ import android.os.HandlerThread; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.text.Editable; +import android.text.Html; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; @@ -274,13 +275,16 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com case R.id.ok: if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) { DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); + String confirmMessage = getString(R.string.entertreatmentquestion); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(calculatedCarbs); - confirmMessage += "\n" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U"; - confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + confirmMessage += "
" + getString(R.string.bolus) + ": " + "" + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U" + ""; + confirmMessage += "
" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; + + if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -299,7 +303,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); - builder.setMessage(confirmMessage); + builder.setMessage(Html.fromHtml(confirmMessage)); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { @@ -550,7 +554,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com boluscalcJSON.put("insulintrend", wizard.insulinFromTrend); boluscalcJSON.put("insulin", calculatedTotalInsulin); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index d871bd4c40..ac5a57d963 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -664,7 +664,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, boluscalcJSON.put("insulintrend", wizard.insulinFromTrend); boluscalcJSON.put("insulin", wizard.calculatedTotalInsulin); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } if (wizard.calculatedTotalInsulin > 0d && quickWizardEntry.carbs() > 0d) { DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index 30148f94c2..bb89a70fdf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -4,6 +4,8 @@ import com.squareup.otto.Subscribe; import org.json.JSONArray; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,6 +19,7 @@ import info.nightscout.utils.SP; * Created by mike on 05.08.2016. */ public class OverviewPlugin implements PluginBase { + private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class); public static double bgTargetLow = 80d; public static double bgTargetHigh = 180d; @@ -30,7 +33,7 @@ public class OverviewPlugin implements PluginBase { try { quickWizard.setData(new JSONArray(storedData)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } MainApp.bus().register(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java index 63ad14ab6b..2962575a68 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java @@ -6,6 +6,8 @@ import android.preference.PreferenceManager; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Date; @@ -18,6 +20,7 @@ import info.nightscout.utils.DateUtil; */ public class QuickWizard { + private static Logger log = LoggerFactory.getLogger(QuickWizard.class); public class QuickWizardEntry { public JSONObject storage; @@ -36,7 +39,7 @@ public class QuickWizard { try { storage = new JSONObject(emptyData); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } position = -1; } @@ -54,7 +57,7 @@ public class QuickWizard { try { return storage.getString("buttonText"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return ""; } @@ -63,7 +66,7 @@ public class QuickWizard { try { return storage.getInt("carbs"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -80,7 +83,7 @@ public class QuickWizard { try { return storage.getInt("validFrom"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -89,7 +92,7 @@ public class QuickWizard { try { return storage.getInt("validTo"); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -117,7 +120,7 @@ public class QuickWizard { try { return new QuickWizardEntry((JSONObject) storage.get(position), position); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return null; } @@ -127,7 +130,7 @@ public class QuickWizard { try { if (new QuickWizardEntry((JSONObject) storage.get(i), i).isActive()) return true; } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return false; @@ -157,7 +160,7 @@ public class QuickWizard { try { storage.put(newItem.position, newItem.storage); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } save(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index 768cdf90e7..6158a00978 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -253,7 +253,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put(profileName, profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); convertedProfileName = profileName; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java index 8aca0a8dbc..51d231edeb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java @@ -229,7 +229,7 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put("LocalProfile", profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); convertedProfileName = "LocalProfile"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index 758521d5a8..cb9a189ff7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -134,7 +134,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { try { profile = new ProfileStore(new JSONObject(profileString)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); profile = null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java index e02f4918c2..687f45ee97 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java @@ -191,7 +191,7 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { profile.put("units", mgdl ? Constants.MGDL : Constants.MMOL); store.put("SimpleProfile", profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 96871ac128..9b85807cd1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -703,7 +703,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index 55fdc7ad04..7948d00d96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.PumpDanaR; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.text.DecimalFormat; import java.util.Date; @@ -16,6 +18,8 @@ import info.nightscout.utils.SP; * Created by mike on 04.07.2016. */ public class DanaRPump { + private static Logger log = LoggerFactory.getLogger(DanaRPump.class); + private static DanaRPump instance = null; public static DanaRPump getInstance() { @@ -189,7 +193,7 @@ public class DanaRPump { profile.put("units", units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL); store.put(PROFILE_PREFIX + (activeProfile + 1), profile); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (Exception e) { return null; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java index 461b353c3e..af3b852aa6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaR; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +45,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -158,7 +159,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); } synchronized (message) { @@ -166,14 +166,10 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java index 0668a74c1d..e7813fac10 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java @@ -220,7 +220,7 @@ public class DanaRNSHistorySync { MainApp.bus().post(ev); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 606eab3794..419d5feb2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -75,7 +76,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBasic; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -209,9 +209,9 @@ public class DanaRExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -352,7 +352,7 @@ public class DanaRExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } @@ -415,7 +415,6 @@ public class DanaRExecutionService extends Service { } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); long startTime = System.currentTimeMillis(); if (!stop.stopped) { @@ -552,10 +551,6 @@ public class DanaRExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index e912eac0b4..d688010de6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -700,7 +700,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java index 597a49a676..566b32831f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaRKorean; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +46,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -159,7 +160,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); } synchronized (message) { @@ -167,14 +167,10 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index b7c9f8ca2c..470d526360 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -66,7 +67,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread; @@ -205,9 +205,9 @@ public class DanaRKoreanExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -345,7 +345,7 @@ public class DanaRKoreanExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } @@ -408,7 +408,6 @@ public class DanaRKoreanExecutionService extends Service { } MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); if (!stop.stopped) { mSerialIOThread.sendMessage(start); @@ -524,10 +523,6 @@ public class DanaRKoreanExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 82bbc23e5c..65d3917381 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -632,7 +632,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits); pumpjson.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pumpjson; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java index 0b67b6acc6..244014f3d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/SerialIOThread.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2; import android.bluetooth.BluetoothSocket; +import android.os.SystemClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +46,7 @@ public class SerialIOThread extends Thread { mOutputStream = mRfCommSocket.getOutputStream(); mInputStream = mRfCommSocket.getInputStream(); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } this.start(); } @@ -159,7 +160,6 @@ public class SerialIOThread extends Thread { mOutputStream.write(messageBytes); } catch (Exception e) { log.error("sendMessage write exception: ", e); - e.printStackTrace(); } synchronized (message) { @@ -167,14 +167,10 @@ public class SerialIOThread extends Thread { message.wait(5000); } catch (InterruptedException e) { log.error("sendMessage InterruptedException", e); - e.printStackTrace(); } } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); if (!message.received) { log.warn("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 0ac333787a..618549a4ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -11,6 +11,7 @@ import android.content.IntentFilter; import android.os.Binder; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import com.squareup.otto.Subscribe; @@ -37,7 +38,6 @@ import info.nightscout.androidaps.plugins.Overview.Notification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.*; -import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread; @@ -180,9 +180,9 @@ public class DanaRv2ExecutionService extends Service { try { mRfcommSocket.connect(); } catch (IOException e) { - //e.printStackTrace(); + //log.error("Unhandled exception", e); if (e.getMessage().contains("socket closed")) { - e.printStackTrace(); + log.error("Unhandled exception", e); break; } } @@ -325,7 +325,7 @@ public class DanaRv2ExecutionService extends Service { NSUpload.uploadError(MainApp.sResources.getString(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); } } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return true; } @@ -412,7 +412,6 @@ public class DanaRv2ExecutionService extends Service { } if (amount > 0) { MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables - MainApp.bus().post(new EventDanaRBolusStart()); if (!stop.stopped) { mSerialIOThread.sendMessage(start); @@ -554,10 +553,6 @@ public class DanaRv2ExecutionService extends Service { } private void waitMsec(long msecs) { - try { - Thread.sleep(msecs); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(msecs); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c04ec9b12f..3f7e689275 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.PumpVirtual; import android.content.SharedPreferences; +import android.os.SystemClock; import android.preference.PreferenceManager; import org.json.JSONException; @@ -222,28 +223,19 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { Double delivering = 0d; while (delivering < detailedBolusInfo.insulin) { - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivering), delivering); bolusingEvent.percent = Math.min((int) (delivering / detailedBolusInfo.insulin * 100), 100); MainApp.bus().post(bolusingEvent); delivering += 0.1d; } - try { - Thread.sleep(200); - } catch (InterruptedException e) { - } + SystemClock.sleep(200); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.bolusdelivered), detailedBolusInfo.insulin); bolusingEvent.percent = 100; MainApp.bus().post(bolusingEvent); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - } + SystemClock.sleep(1000); if (Config.logPumpComm) log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); @@ -415,7 +407,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { pump.put("reservoir", reservoirInUnits); pump.put("clock", DateUtil.toISOString(new Date())); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return pump; } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java index bff2e6695a..c4a9fa89b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java @@ -7,6 +7,8 @@ import android.os.Bundle; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; @@ -16,6 +18,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; public class NSAlarmReceiver extends BroadcastReceiver { + private static Logger log = LoggerFactory.getLogger(NSAlarmReceiver.class); @Override public void onReceive(Context context, Intent intent) { @@ -27,7 +30,7 @@ public class NSAlarmReceiver extends BroadcastReceiver { try { json = new JSONObject(data); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return; } NSAlarm nsAlarm = new NSAlarm(json); diff --git a/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java b/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java index 1e501fbdf0..b8eb49e98e 100644 --- a/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java +++ b/app/src/main/java/info/nightscout/utils/ImportExportPrefs.java @@ -76,9 +76,9 @@ public class ImportExportPrefs { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.exported)); } catch (FileNotFoundException e) { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file); - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }) @@ -127,9 +127,9 @@ public class ImportExportPrefs { }); } catch (FileNotFoundException e) { ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file); - e.printStackTrace(); + log.error("Unhandled exception", e); } catch (IOException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } }) diff --git a/app/src/main/java/info/nightscout/utils/JSONFormatter.java b/app/src/main/java/info/nightscout/utils/JSONFormatter.java index a37169f061..499ba01652 100644 --- a/app/src/main/java/info/nightscout/utils/JSONFormatter.java +++ b/app/src/main/java/info/nightscout/utils/JSONFormatter.java @@ -6,6 +6,8 @@ import android.text.Spanned; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Iterator; @@ -13,6 +15,7 @@ import java.util.Iterator; * Created by mike on 11.07.2016. */ public class JSONFormatter { + private static Logger log = LoggerFactory.getLogger(JSONFormatter.class); public static Spanned format(final String jsonString) { final JsonVisitor visitor = new JsonVisitor(4, ' '); @@ -24,7 +27,7 @@ public class JSONFormatter { else return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return Html.fromHtml(""); } } @@ -34,7 +37,7 @@ public class JSONFormatter { try { return Html.fromHtml(visitor.visit(object, 0)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); return Html.fromHtml(""); } } diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 09ecbc9370..e6cb358ac1 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -61,7 +61,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -98,7 +98,7 @@ public class NSUpload { DbLogger.dbAdd(intent, data.toString()); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -123,7 +123,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -151,7 +151,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -179,7 +179,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -240,7 +240,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, deviceStatus.mongoRecord().toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -264,7 +264,7 @@ public class NSUpload { if (detailedBolusInfo.carbTime != 0) data.put("preBolus", detailedBolusInfo.carbTime); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } uploadCareportalEntryToNS(data); } @@ -286,7 +286,7 @@ public class NSUpload { data.put("enteredBy", MainApp.instance().getString(R.string.app_name)); uploadCareportalEntryToNS(data); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -315,7 +315,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -333,7 +333,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbRemove(intent, _id); } catch (Exception e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -356,7 +356,7 @@ public class NSUpload { context.sendBroadcast(intent); DbLogger.dbAdd(intent, data.toString()); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -372,7 +372,7 @@ public class NSUpload { data.put("notes", error); data.put("isAnnouncement", true); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("data", data.toString()); Intent intent = new Intent(Intents.ACTION_DATABASE); @@ -394,7 +394,7 @@ public class NSUpload { data.put("created_at", DateUtil.toISOString(new Date())); data.put("notes", MainApp.sResources.getString(R.string.androidaps_start)); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } bundle.putString("data", data.toString()); Intent intent = new Intent(Intents.ACTION_DATABASE); diff --git a/app/src/main/java/info/nightscout/utils/OKDialog.java b/app/src/main/java/info/nightscout/utils/OKDialog.java index 72e0ddd8d2..6bd84cbe71 100644 --- a/app/src/main/java/info/nightscout/utils/OKDialog.java +++ b/app/src/main/java/info/nightscout/utils/OKDialog.java @@ -2,6 +2,7 @@ package info.nightscout.utils; import android.app.Activity; import android.content.DialogInterface; +import android.os.SystemClock; import android.support.v7.app.AlertDialog; import android.support.v7.view.ContextThemeWrapper; import android.text.Spanned; @@ -28,10 +29,7 @@ public class OKDialog { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (runnable != null) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } + SystemClock.sleep(100); activity.runOnUiThread(runnable); } } @@ -52,10 +50,7 @@ public class OKDialog { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (runnable != null) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } + SystemClock.sleep(100); activity.runOnUiThread(runnable); } } diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index 2ad591b1ef..8a1fac75a3 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -253,7 +253,7 @@ public class TimeListEdit { return item.getInt("timeAsSeconds"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0; } @@ -265,7 +265,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } return 0d; } @@ -278,7 +278,7 @@ public class TimeListEdit { return item.getDouble("value"); } } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } return 0d; @@ -305,7 +305,7 @@ public class TimeListEdit { } if (save != null) save.run(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } @@ -322,7 +322,7 @@ public class TimeListEdit { editItem(index, timeAsSeconds, value1, value2); if (save != null) save.run(); } catch (JSONException e) { - e.printStackTrace(); + log.error("Unhandled exception", e); } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cb9206a4c7..4c5c58c993 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,6 +3,7 @@ #ff00ff #00ffff #FFFB8C00 + #FFFFCC03 #8BC34A #FFFFFF #00FF00 diff --git a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java index 711e6a76f4..af1b2f7bac 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/ListenerService.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.app.NotificationCompat; @@ -400,11 +401,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp @Override public void run() { - try { - Thread.sleep(seconds * 1000); - } catch (InterruptedException e) { - //e.printStackTrace(); - } + SystemClock.sleep(seconds * 1000); synchronized (this) { if(valid) { NotificationManagerCompat notificationManager = diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java index 510382b20b..25fe619b2a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java @@ -15,6 +15,7 @@ import android.graphics.Rect; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; @@ -473,11 +474,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { updateRainbow(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(40); } mSgv.getPaint().setShader(null); setIsAnimated(false); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java index f9df8eb97e..73930d8365 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -15,6 +15,7 @@ import android.graphics.RectF; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.LocalBroadcastManager; import android.support.wearable.watchface.WatchFaceStyle; @@ -504,11 +505,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { animationStep(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(40); } setIsAnimated(false); prepareDrawTime(); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java index ab283e8656..9bb452c480 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java @@ -15,6 +15,7 @@ import android.graphics.Rect; import android.graphics.Shader; import android.os.Bundle; import android.os.PowerManager; +import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; @@ -427,11 +428,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref setIsAnimated(true); for (int i = 0; i <= 8 * 1000 / 40; i++) { updateRainbow(); - try { - Thread.sleep(40); - } catch (InterruptedException e) { - e.printStackTrace(); - } + SystemClock.sleep(40); } mSgv.getPaint().setShader(null); setIsAnimated(false);