Skip to content

Commit 19113bf

Browse files
author
paolorotolo
committed
Merge remote-tracking branch 'remotes/origin/freestyle-libre' into develop
# Conflicts: # app/src/main/AndroidManifest.xml # app/src/main/java/org/glucosio/android/activity/AddGlucoseActivity.java # app/src/main/java/org/glucosio/android/presenter/AddGlucosePresenter.java
2 parents 455d872 + 4e301db commit 19113bf

21 files changed

+781
-2
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ dependencies {
129129
transitive = true
130130
}
131131

132+
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
133+
compile files('libs/commons-math3-3.6.jar')
134+
132135
// Butterknife
133136
compile "com.jakewharton:butterknife:${butterKnifeVer}"
134137
apt "com.jakewharton:butterknife-compiler:${butterKnifeVer}"

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2121
package="org.glucosio.android">
2222

23+
<!-- Required to read FreeStyle Libre -->
24+
<uses-permission
25+
android:name="android.permission.NFC"
26+
android:required="false" />
27+
28+
<uses-feature
29+
android:name="android.hardware.nfc"
30+
android:required="false" />
31+
2332
<!-- Required to export and save CSV or graph -->
2433
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2534
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -137,6 +146,19 @@
137146
android:name="android.support.PARENT_ACTIVITY"
138147
android:value="org.glucosio.android.activity.MainActivity" />
139148
</activity>
149+
<activity android:name=".activity.FreestyleLibreActivity">
150+
151+
<!-- NFC for FreeStyle -->
152+
<intent-filter>
153+
<action android:name="android.nfc.action.TECH_DISCOVERED" />
154+
155+
<category android:name="android.intent.category.DEFAULT" />
156+
</intent-filter>
157+
158+
<meta-data
159+
android:name="android.nfc.action.TECH_DISCOVERED"
160+
android:resource="@xml/nfc_tech_filter" />
161+
</activity>
140162
<activity
141163
android:name=".activity.A1cCalculatorActivity"
142164
android:label="@string/activity_converter_title"

app/src/main/java/org/glucosio/android/activity/AddGlucoseActivity.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import android.os.Bundle;
2424
import android.support.design.widget.Snackbar;
25+
import android.support.design.widget.TextInputLayout;
26+
import android.support.v7.app.AppCompatActivity;
27+
import android.support.v7.widget.AppCompatButton;
2528
import android.support.v7.widget.Toolbar;
2629
import android.view.View;
2730
import android.widget.AdapterView;
@@ -49,6 +52,8 @@ public class AddGlucoseActivity extends AddReadingActivity {
4952
private TextView readingTextView;
5053
private EditText typeCustomEditText;
5154
private EditText notesEditText;
55+
private AppCompatButton addFreeStyleButton;
56+
private TextInputLayout readingInputLayout;
5257
private LabelledSpinner readingTypeSpinner;
5358
private boolean isCustomType = false;
5459

@@ -74,6 +79,8 @@ protected void onCreate(Bundle savedInstanceState) {
7479
readingTypeSpinner.setItemsArray(R.array.dialog_add_measured_list);
7580
readingTextView = (TextView) findViewById(R.id.glucose_add_concentration);
7681
typeCustomEditText = (EditText) findViewById(R.id.glucose_type_custom);
82+
readingInputLayout = (TextInputLayout) findViewById(R.id.glucose_add_concentration_layout);
83+
addFreeStyleButton = (AppCompatButton) findViewById(R.id.glucose_add_freestyle_button);
7784
notesEditText = (EditText) findViewById(R.id.glucose_add_notes);
7885

7986
this.createDateTimeViewAndListener();
@@ -138,7 +145,38 @@ public void onNothingChosen(View labelledSpinner, AdapterView<?> adapterView) {
138145
presenter.updateSpinnerTypeTime();
139146
}
140147

141-
this.getDoneFAB().postDelayed(this.getFabAnimationRunnable(), 600);
148+
this.getDoneFAB().postDelayed(this.getFabAnimationRunnable(), 600)
149+
150+
// Check if activity was started from a NFC sensor
151+
if (getIntent().getExtras() != null) {
152+
Bundle p;
153+
String reading;
154+
155+
p = getIntent().getExtras();
156+
reading = p.getString("reading");
157+
if (reading!=null) {
158+
// If yes, first convert the decimal value from Freestyle to Integer
159+
double d = Double.parseDouble(reading);
160+
int glucoseValue = (int) d;
161+
readingTextView.setText(glucoseValue + "");
162+
readingInputLayout.setErrorEnabled(true);
163+
readingInputLayout.setError(getResources().getString(R.string.dialog_add_glucose_freestylelibre_added));
164+
addFreeStyleButton.setVisibility(View.GONE);
165+
166+
addAnalyticsEvent();
167+
}
168+
}
169+
170+
// Check if FreeStyle support is enabled in Preferences
171+
if (presenter.isFreeStyleLibreEnabled()) {
172+
addFreeStyleButton.setVisibility(View.VISIBLE);
173+
addFreeStyleButton.setOnClickListener(new View.OnClickListener() {
174+
@Override
175+
public void onClick(View view) {
176+
startLibreActivity();
177+
}
178+
});
179+
}
142180
}
143181

144182
private void addAnalyticsEvent() {
@@ -172,6 +210,10 @@ public void showErrorMessage() {
172210
Snackbar.make(rootLayout, getString(R.string.dialog_error2), Snackbar.LENGTH_SHORT).show();
173211
}
174212

213+
public void startLibreActivity() {
214+
Intent intent = new Intent(this, FreestyleLibreActivity.class);
215+
startActivity(intent);
216+
}
175217

176218
public void showDuplicateErrorMessage() {
177219
View rootLayout = findViewById(android.R.id.content);
@@ -193,4 +235,5 @@ public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int se
193235
DecimalFormat df = new DecimalFormat("00");
194236
updateSpinnerTypeHour(Integer.parseInt(df.format(hourOfDay)));
195237
}
238+
196239
}

0 commit comments

Comments
 (0)