Skip to content
Snippets Groups Projects
Commit ac62d2e5 authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files
* 'master' of https://github.com/pazaan/640gAndroidUploader:
  adapt JSON  #61 (cherry picked from commit 454645ba)
  Push pump status  (bolusing / suspended) to NS  #61 (cherry picked from commit 4ffa2105)
  mv to setAlarmClock (API > 23)
  update crashlytics
  update realm lib to avoid realmIOException to many open files
  update realm lib to avoid realmIOException to many open files
  use different methods to set alarm depending on OS version
parents 565328eb 63e1bdb8
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ buildscript {
dependencies {
classpath 'io.fabric.tools:gradle:1.21.6'
classpath 'io.realm:realm-gradle-plugin:1.1.0'
classpath 'io.realm:realm-gradle-plugin:1.1.1'
classpath 'org.ajoberstar:grgit:1.5.0'
}
}
......@@ -144,7 +144,7 @@ release {
dependencies {
compile files('libs/slf4j-api-1.7.2.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.6.0@aar') {
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true;
}
compile('com.mikepenz:materialdrawer:5.2.9@aar') {
......
......@@ -4,6 +4,7 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
......@@ -16,8 +17,8 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
private static final String TAG = MedtronicCnlAlarmReceiver.class.getSimpleName();
private static final int ALARM_ID = 102; // Alarm id
private static PendingIntent pi = null;
private static AlarmManager am = null;
private static PendingIntent pendingIntent = null;
private static AlarmManager alarmManager = null;
@Override
public void onReceive(final Context context, Intent intent) {
......@@ -31,9 +32,9 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
public void setContext(Context context) {
cancelAlarm();
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MedtronicCnlAlarmReceiver.class);
pi = PendingIntent.getBroadcast(context, ALARM_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(context, ALARM_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
// Setting the alarm in 15 seconds from now
......@@ -43,7 +44,7 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
// Setting the alarm to call onRecieve
public void setAlarm(long millis) {
if (am == null || pi == null)
if (alarmManager == null || pendingIntent == null)
return;
cancelAlarm();
......@@ -53,7 +54,12 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
millis = System.currentTimeMillis();
Log.d(TAG, "AlarmManager set to fire at " + new Date(millis));
am.setExact(AlarmManager.RTC_WAKEUP, millis, pi);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(millis, null), pendingIntent);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, millis, pendingIntent);
} else
alarmManager.set(AlarmManager.RTC_WAKEUP, millis, pendingIntent);
}
// restarting the alarm after MedtronicCnlIntentService.POLL_PERIOD_MS from now
......@@ -63,10 +69,10 @@ public class MedtronicCnlAlarmReceiver extends WakefulBroadcastReceiver {
// Cancel the alarm.
public void cancelAlarm() {
if (am == null || pi == null)
if (alarmManager == null || pendingIntent == null)
return;
am.cancel(pi);
alarmManager.cancel(pendingIntent);
}
}
......@@ -258,11 +258,22 @@ public class NightscoutUploadIntentService extends IntentService {
iob.put("timestamp", record.getPumpDate());
iob.put("bolusiob", record.getActiveInsulin());
JSONObject status = new JSONObject();
if (record.isBolusing()) {
status.put("bolusing", true);
} else if (record.isSuspended()) {
status.put("suspended", true);
} else {
status.put("status", "normal");
}
JSONObject battery = new JSONObject();
battery.put("percent", record.getBatteryPercentage());
pumpInfo.put("iob", iob);
pumpInfo.put("battery", battery);
pumpInfo.put("status", status);
json.put("pump", pumpInfo);
String jsonString = json.toString();
Log.i(TAG, "Device Status JSON: " + jsonString);
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "io.realm:realm-gradle-plugin:1.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment