Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/com/nightscout/android/dexcom/DexcomG4Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import com.nightscout.android.R;
import com.nightscout.android.settings.SettingsActivity;

import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.os.BatteryManager;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
Expand All @@ -38,6 +42,8 @@ public class DexcomG4Activity extends Activity {
private TextView mTitleTextView;
private TextView mDumpTextView;
private Button b1;
public static String batLevel = "0";
BatteryReceiver mArrow;


//All I'm really doing here is creating a simple activity to launch and maintain the service
Expand All @@ -62,10 +68,28 @@ public void run() {
mDumpTextView.setTextColor(Color.WHITE);
mDumpTextView.setText("\n" + record.displayTime + "\n" + record.bGValue + "\n" + record.trendArrow + "\n");
}
mArrow = new BatteryReceiver();
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);
mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mIntentFilter.addAction(Intent.ACTION_BATTERY_OKAY);
Intent batteryIntent=registerReceiver(mArrow,mIntentFilter);

mHandler.postDelayed(updateDataView, 30000);
}
};

private class BatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
if (arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_LOW)
|| arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_CHANGED)
|| arg1.getAction().equalsIgnoreCase(Intent.ACTION_BATTERY_OKAY)) {
batLevel =String.format("%s", arg1.getIntExtra("level", 0));
}
}
}

//Look for and launch the service, display status to user
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down
7 changes: 7 additions & 0 deletions src/com/nightscout/android/upload/UploadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.util.Log;

import com.mongodb.*;
import com.nightscout.android.dexcom.DexcomG4Activity;
import com.nightscout.android.dexcom.EGVRecord;

import org.apache.http.client.ResponseHandler;
Expand Down Expand Up @@ -133,6 +134,12 @@ private void doMongoUpload(SharedPreferences prefs, EGVRecord... records) {
testData.put("direction", record.trend);
dexcomData.update(testData, testData, true, false, WriteConcern.UNACKNOWLEDGED);
}
//Uploading Settings Data
BasicDBObject SettingsData = new BasicDBObject();
SettingsData.put("type","settings");
SettingsData.put("battery", DexcomG4Activity.batLevel);
dexcomData.update(SettingsData, SettingsData, true, false, WriteConcern.UNACKNOWLEDGED);

client.close();
} catch (Exception e) {
Log.e(TAG, "Unable to upload data to mongo", e);
Expand Down