Skip to content

Commit

Permalink
Merge branch 'feature/consolidate'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Calabrese committed May 31, 2014
2 parents 81dcaf2 + 84bffb7 commit 2c9cd57
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 253 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
*.iml
gen
out
*.apk
logs
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dexcom-uploader
====================

A community maintained fork of original android uploader.

We're currently consolidating multiple forks of the original code here.
This will support the 2 most common deployment models (REST / Hosted Mongo).
65 changes: 44 additions & 21 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Database"
android:key="pref_database">
<SwitchPreference
android:title="Uploading"
android:key="DatabaseSwitch"
android:disableDependentsState="false">
</SwitchPreference>
<EditTextPreference
android:dependency="DatabaseSwitch"
android:title="MongoDB URI"
android:key="MongoDB URI"
android:dialogTitle="Enter MongoDB URI">
</EditTextPreference>
<EditTextPreference
android:dependency="DatabaseSwitch"
android:title="Collection Name"
android:key="Collection Name"
android:dialogTitle="Enter Collection Name">
</EditTextPreference>
</PreferenceCategory>
<SwitchPreference
android:title="API Upload (REST)"
android:key="EnableRESTUpload"
android:disableDependentsState="false"
android:summary="The REST API is an alternative to direct mongodb upload">
</SwitchPreference>
<EditTextPreference
android:dependency="EnableRESTUpload"
android:title="API Base URL"
android:key="API Base URL"
android:dialogTitle="Enter Base API URL"
android:defaultValue="http://{YOUR-API-SERVER}/api"
android:dialogMessage="This only the base URL, the uploader will automatically append /entries for the POST">
</EditTextPreference>
<SwitchPreference
android:title="MongoDB Upload"
android:key="EnableMongoUpload"
android:disableDependentsState="false"
android:summary="If you're using MongoLab and Azure this should be enabled">
</SwitchPreference>
<EditTextPreference
android:dependency="EnableMongoUpload"
android:title="MongoDB URI"
android:key="MongoDB URI"
android:dialogTitle="Enter MongoDB URI"
android:dialogMessage="Replace example values in {}'s with your correct values"
android:defaultValue="mongodb://{user}:{password}@{host}.mongolab.com:{11111}/{database}">
</EditTextPreference>
<EditTextPreference
android:dependency="EnableMongoUpload"
android:title="Collection Name"
android:key="Collection Name"
android:dialogTitle="Enter Collection Name"
android:dialogMessage="This is the name of the collection where the CGM data will be stored">
</EditTextPreference>
<SwitchPreference
android:title="Wifi Hack"
android:key="EnableWifiHack"
android:disableDependentsState="false"
android:defaultValue="true"
android:summaryOn="Wifi will be disabled if there is a timeout (poor wifi signal/access point), this will allow mobile data to be used instead"
android:summaryOff="The uploader won't try to disable Wifi even if there is a timeout"
>
</SwitchPreference>
</PreferenceScreen>
90 changes: 40 additions & 50 deletions src/com/nightscout/android/dexcom/DexcomG4Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -27,43 +28,41 @@
/* Main activity for the DexcomG4Activity program */
public class DexcomG4Activity extends Activity {

private static final String TAG = DexcomG4Activity.class.getSimpleName();

private Handler mHandler = new Handler();

private int maxRetries = 20;
private int retryCount = 0;

private TextView mTitleTextView;
private TextView mDumpTextView;
private ScrollView mScrollView;
private Button b1;


//All I'm really doing here is creating a simple activity to launch and maintain the service
private Runnable updateDataView = new Runnable() {
public void run() {

if (!isMyServiceRunning()) {
if (retryCount < maxRetries) {
startService(new Intent(DexcomG4Activity.this,
DexcomG4Service.class));
mTitleTextView.setTextColor(Color.YELLOW);
mTitleTextView.setText("Connecting...");
++retryCount;
} else {
mHandler.removeCallbacks(updateDataView);
finish();
}
if (!isMyServiceRunning()) {
if (retryCount < maxRetries) {
startService(new Intent(DexcomG4Activity.this, DexcomG4Service.class));
mTitleTextView.setTextColor(Color.YELLOW);
mTitleTextView.setText("Connecting...");
Log.i(TAG, "Starting service " + retryCount + "/" + maxRetries);
++retryCount;
} else {
mTitleTextView.setTextColor(Color.GREEN);
mTitleTextView.setText("CGM Service Started");
EGVRecord record = DexcomG4Activity.this
.loadClassFile(new File(getBaseContext().getFilesDir(),
"save.bin"));
mDumpTextView.setTextColor(Color.WHITE);
mDumpTextView.setText("\n" + record.displayTime + "\n"
+ record.bGValue + "\n" + record.trendArrow + "\n");
mHandler.removeCallbacks(updateDataView);
Log.i(TAG, "Unable to restart service, trying to recreate the activity");
recreate();
}
mHandler.postDelayed(updateDataView, 30000);
} else {
mTitleTextView.setTextColor(Color.GREEN);
mTitleTextView.setText("CGM Service Started");
EGVRecord record = DexcomG4Activity.this.loadClassFile(new File(getBaseContext().getFilesDir(), "save.bin"));
mDumpTextView.setTextColor(Color.WHITE);
mDumpTextView.setText("\n" + record.displayTime + "\n" + record.bGValue + "\n" + record.trendArrow + "\n");
}
mHandler.postDelayed(updateDataView, 30000);
}
};

Expand All @@ -76,7 +75,6 @@ public void onCreate(Bundle savedInstanceState) {

mTitleTextView = (TextView) findViewById(R.id.demoTitle);
mDumpTextView = (TextView) findViewById(R.id.demoText);
mScrollView = (ScrollView) findViewById(R.id.demoScroller);

LinearLayout lnr = (LinearLayout) findViewById(R.id.container);

Expand All @@ -93,20 +91,19 @@ public void onCreate(Bundle savedInstanceState) {
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (b1.getText() == "Stop Uploading CGM Data") {
mHandler.removeCallbacks(updateDataView);
stopService(new Intent(DexcomG4Activity.this,
DexcomG4Service.class));
b1.setText("Start Uploading CGM Data");
mTitleTextView.setTextColor(Color.RED);
mTitleTextView.setText("CGM Service Stopped");
finish();

} else {
mHandler.removeCallbacks(updateDataView);
mHandler.post(updateDataView);
b1.setText("Stop Uploading CGM Data");
}
if (b1.getText() == "Stop Uploading CGM Data") {
mHandler.removeCallbacks(updateDataView);
stopService(new Intent(DexcomG4Activity.this, DexcomG4Service.class));
b1.setText("Start Uploading CGM Data");
mTitleTextView.setTextColor(Color.RED);
mTitleTextView.setText("CGM Service Stopped");
finish();

} else {
mHandler.removeCallbacks(updateDataView);
mHandler.post(updateDataView);
b1.setText("Stop Uploading CGM Data");
}
}
});

Expand All @@ -122,20 +119,16 @@ protected void onPause() {
protected void onResume() {
super.onResume();
//Refresh the status
EGVRecord record = this.loadClassFile(new File(this.getFilesDir(),
"save.bin"));
EGVRecord record = this.loadClassFile(new File(this.getFilesDir(), "save.bin"));
mDumpTextView.setTextColor(Color.WHITE);
mDumpTextView.setText("\n" + record.displayTime + "\n" + record.bGValue
+ "\n" + record.trendArrow + "\n");
mDumpTextView.setText("\n" + record.displayTime + "\n" + record.bGValue + "\n" + record.trendArrow + "\n");
}

//Check to see if service is running
private boolean isMyServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager
.getRunningServices(Integer.MAX_VALUE)) {
if (DexcomG4Service.class.getName().equals(
service.service.getClassName())) {
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DexcomG4Service.class.getName().equals(service.service.getClassName())) {
return true;
}
}
Expand All @@ -145,14 +138,11 @@ private boolean isMyServiceRunning() {
//Deserialize the EGVRecord (most recent) value
public EGVRecord loadClassFile(File f) {
try {
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream(f));
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
Object o = ois.readObject();
return (EGVRecord) o;
} catch (Exception ex) {

ex.printStackTrace();

Log.w(TAG, " unable to loadEGVRecord");
}
return new EGVRecord();
}
Expand Down
Loading

0 comments on commit 2c9cd57

Please sign in to comment.