Skip to content

Commit c67d763

Browse files
author
Adam Howard
committed
added feature: boxes are ticked automatically when their corresponding input has data put into it, and unticked automatically when cleared
1 parent 6bffbbd commit c67d763

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

TODO.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ TODO
33

44
* Add freeform 'notes', tweetsize or less
55
- the max size should depend on the size of a single text, varying on how much other data (QA, CP etc) we're sending.
6-
* Use a dialog to specify a list of phone numbers to share the entries with via SMS
7-
- validate entered numbers are real phone numbers
8-
- format the extant numbers so they look better
9-
- add a way to an/all entry(ies)
6+
* For the Edit Numbers Dialog:
7+
- format the extant numbers so they look better (eg font)
8+
- add a way to delete an/all entry(ies)
109
- set a max number of recipients (5?), to prevent our app from being accused of spamming by the android watchdogs
11-
* Choose output format for data, eg CSV, JSON
1210
* Create a Log Review screen, which displays the ~5 most recent entries
13-
* Automatically tick a field when data is entered, and automatically untick it when it becomes blank
11+
1412

1513

1614
Done
@@ -19,9 +17,12 @@ Done
1917
* Make the entry-time editable
2018
* Store entries locally
2119
- probably in a file
22-
20+
* Automatically tick a field when data is entered, and automatically untick it when it becomes blank
21+
* Use a dialog to specify a list of phone numbers to share the entries with via SMS
22+
- validate entered numbers are real phone numbers
2323

2424
Long-Term
2525
---------
2626

27-
* Sync data across instances
27+
* Sync data across instances
28+
* Allow users to choose output format for data, eg CSV, JSON

app/src/main/java/com/medavox/diabeticdiary/MainActivity.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
import android.support.v7.app.AppCompatActivity;
1515
import android.os.Bundle;
1616
import android.telephony.SmsManager;
17+
import android.text.Editable;
1718
import android.text.InputFilter;
1819
import android.text.Spanned;
20+
import android.text.TextWatcher;
1921
import android.util.Log;
2022
import android.view.LayoutInflater;
2123
import android.view.Menu;
@@ -98,8 +100,30 @@ protected void onCreate(Bundle savedInstanceState) {
98100

99101
for(int i = 0; i < inputs.length; i++) {
100102
inputs[i] = (EditText) findViewById(inputIDs[i]);
103+
104+
//tick the box to include data when there is, and untick it when it's not
105+
final CheckBox cb = checkBoxes[i];
106+
inputs[i].addTextChangedListener(new TextWatcher() {
107+
@Override
108+
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
109+
110+
@Override
111+
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
112+
113+
@Override
114+
public void afterTextChanged(Editable editable) {
115+
if(editable.length() == 0 && cb.isChecked()) {
116+
cb.setChecked(false);
117+
}
118+
else if(editable.length() > 0 && !cb.isChecked()) {
119+
cb.setChecked(true);
120+
}
121+
}
122+
});
101123
}
102124

125+
126+
103127
//for BG input, only allow 2 digits before the decimal place, and 1 after
104128
//Log.i(TAG, "existing filters: "+inputs[0].getFilters().length);
105129
inputs[0].setFilters(new InputFilter[]{new DecimalDigitsInputFilter(2,1)});
@@ -171,18 +195,17 @@ public void clickRecordButton() {
171195
String csvFormatLine = sdf.format(new Date(instantOpened));
172196

173197
//select which fields have been ticked
174-
String out = "Diabetic Diary ENTRY @ "+ DateTime.get(instantOpened,
175-
DateTime.TimeFormat.MINUTES)+" {";
198+
String out = DateTime.get(instantOpened,
199+
DateTime.TimeFormat.MINUTES, DateFormat.BRIEF_WITH_DAY)+": ";
176200
boolean anyTicked = false;
177201
for(int i = 0; i < checkBoxes.length; i++) {
178202
csvFormatLine += ",";
179203
if(checkBoxes[i].isChecked()) {
180204
anyTicked = true;
181-
out += names[i]+":"+inputs[i].getText()+"; ";
205+
out += names[i]+":"+inputs[i].getText()+", ";
182206
csvFormatLine += inputs[i].getText();
183207
}
184208
}
185-
out += "}";
186209
//csvFormatLine = csvFormatLine.substring(1);
187210
Log.i(TAG, out);
188211

@@ -418,8 +441,8 @@ public void onClick(View view) {
418441
@Override
419442
public void onClick(View view) {
420443
SharedPreferences.Editor editor = sp.edit();
421-
//bizarrely, there doesn't seem to a method in ArrayAdapters
422-
// to get all the data out in one go
444+
//bizarrely, there doesn't seem to be a method in ArrayAdapters,
445+
// to get all the data out in one go. eg ArrayAdapter.getArray()
423446
ArrayAdapter<String> adapter = (ArrayAdapter<String>)listView.getAdapter();
424447
Set<String> newData = new HashSet<String>(adapter.getCount());
425448
String numbersAsString = "";

app/src/main/res/layout/edit_numbers_dialog.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
android:orientation="horizontal">
1919

2020
<EditText
21-
2221
xmlns:android="http://schemas.android.com/apk/res/android"
2322
android:id="@+id/number_edit_box"
2423
android:layout_width="match_parent"
2524
android:layout_height="match_parent"
2625
android:layout_weight="2"
27-
android:inputType="phone"/>
26+
android:inputType="phone"
27+
android:maxLines="1"
28+
android:maxLength="15"/>
2829

2930
<Button
3031
android:id="@+id/add_number_button"

app/src/main/res/layout/edit_numbers_list_item.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
android:maxLines="1"
6-
android:maxLength="15"/>
5+
/>

0 commit comments

Comments
 (0)