From ce60b5c7ecfb6f848a50dfa46711a6d8eace480e Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Wed, 21 Feb 2018 13:33:31 +0100 Subject: [PATCH] Add next button to input dialog for moving directly to next measurement This fixes the last part of #81 (and #164) (together with #198). --- .../openscale/gui/views/MeasurementView.java | 31 ++++++++++++++++++- .../app/src/main/res/values/strings.xml | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java index 47172537..66a038d1 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java @@ -28,6 +28,7 @@ import android.text.SpannableStringBuilder; import android.util.TypedValue; import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; @@ -349,9 +350,25 @@ public abstract class MeasurementView extends TableLayout { input.setSelectAllOnFocus(true); builder.setView(input); + ViewGroup parent = (ViewGroup) getParent(); + MeasurementView view = null; + for (int i = parent.indexOfChild(this) + 1; i < parent.getChildCount(); ++i) { + MeasurementView next = (MeasurementView) parent.getChildAt(i); + if (!next.isEditable() || next instanceof DateMeasurementView || next instanceof TimeMeasurementView) { + continue; + } + view = next; + break; + } + final MeasurementView next = view; + builder.setPositiveButton(getResources().getString(R.string.label_ok), null); builder.setNegativeButton(getResources().getString(R.string.label_cancel), null); + if (next != null) { + builder.setNeutralButton(R.string.label_next, null); + } + final AlertDialog floatDialog = builder.create(); floatDialog.setOnShowListener(new DialogInterface.OnShowListener() { @@ -361,7 +378,6 @@ public abstract class MeasurementView extends TableLayout { Button positiveButton = floatDialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { - @Override public void onClick(View view) { if (validateAndSetInput(input)) { @@ -381,6 +397,19 @@ public abstract class MeasurementView extends TableLayout { floatDialog.dismiss(); } }); + + if (next != null) { + Button neutralButton = floatDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + neutralButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (validateAndSetInput(input)) { + floatDialog.dismiss(); + next.getInputDialog().show(); + } + } + }); + } } }); diff --git a/android_app/app/src/main/res/values/strings.xml b/android_app/app/src/main/res/values/strings.xml index f8b51019..9e514f8c 100644 --- a/android_app/app/src/main/res/values/strings.xml +++ b/android_app/app/src/main/res/values/strings.xml @@ -221,5 +221,6 @@ Permission not granted openScale requires permission to access the coarse location to search for Bluetooth devices Information + Next