From 80de9c0cd85b96846029547385d7989029ed783e Mon Sep 17 00:00:00 2001 From: LadyViktoria Date: Fri, 10 Feb 2017 11:34:05 +0100 Subject: [PATCH 01/10] use validation lib in cpp --- .../CircadianPercentageProfileFragment.java | 25 +++++++---- .../CircadianPercentageProfilePlugin.java | 2 +- .../circadianpercentageprofile_fragment.xml | 41 ++++++++++++++----- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index ca07d190a8..96aaafc673 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -20,6 +20,7 @@ import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.TextView; +import com.andreabaccega.widget.FormEditText; import com.squareup.otto.Subscribe; import org.slf4j.Logger; @@ -50,8 +51,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag RadioButton mmolView; EditText targetlowView; EditText targethighView; - EditText percentageView; - EditText timeshiftView; + FormEditText percentageView; + FormEditText timeshiftView; TextView profileView; TextView baseprofileIC; TextView baseprofileBasal; @@ -75,8 +76,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow); targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh); - percentageView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); - timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); + percentageView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); + timeshiftView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview); baseprofileBasal = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal); baseprofileBasalLayout = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout); @@ -217,15 +218,21 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag public void onTextChanged(CharSequence s, int start, int before, int count) { - if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) { - circadianPercentageProfilePlugin.percentage = 100; - } else { - circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString()); + if (percentageView.testValidity()) { + if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) { + circadianPercentageProfilePlugin.percentage = 100; + } else { + circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString()); + } + updateProfileInfo(); + } + if (timeshiftView.testValidity()) { + circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString()); + updateProfileInfo(); } circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString()); circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); - circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString()); circadianPercentageProfilePlugin.storeSettings(); updateProfileInfo(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java index 56aa813c29..cca3f99477 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java @@ -253,7 +253,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte @Override public NSProfile getProfile() { - performLimitCheck(); + // performLimitCheck(); return convertedProfile; } diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 92d08c4a11..7d864353c6 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -1,4 +1,5 @@ + android:padding="5dp" + android:backgroundTint="@color/mdtp_transparent_black" + android:background="@drawable/pillborder" + android:backgroundTintMode="src_over"> - - + android:inputType="number" + android:selectAllOnFocus="true" + android:textAlignment="center" /> + + + android:padding="5dp" + android:backgroundTint="@color/mdtp_transparent_black" + android:background="@drawable/pillborder" + android:backgroundTintMode="src_over"> - + android:inputType="number" + android:selectAllOnFocus="true" + android:textAlignment="center" /> From 11d0f1aebf098a0fd206d990b4dcffabcd082895 Mon Sep 17 00:00:00 2001 From: LadyViktoria Date: Fri, 10 Feb 2017 14:24:56 +0100 Subject: [PATCH 02/10] better keyboard handling in fragments --- .../nightscout/androidaps/MainActivity.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index b81138ed60..c804f8ae58 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -1,10 +1,12 @@ package info.nightscout.androidaps; import android.Manifest; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.Rect; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; @@ -16,6 +18,10 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.fonts.FontAwesomeModule; @@ -259,4 +265,21 @@ public class MainActivity extends AppCompatActivity { } } } + + @Override + public boolean dispatchTouchEvent(MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + View v = getCurrentFocus(); + if ( v instanceof EditText) { + Rect outRect = new Rect(); + v.getGlobalVisibleRect(outRect); + if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) { + v.clearFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + } + } + return super.dispatchTouchEvent(event); + } } From 48a158b036b8c678c424710f62df8ada25005399 Mon Sep 17 00:00:00 2001 From: LadyViktoria Date: Fri, 10 Feb 2017 17:29:59 +0100 Subject: [PATCH 03/10] use validation lib in cpp - better event handling --- .../CircadianPercentageProfileFragment.java | 61 +++++++++++++------ .../circadianpercentageprofile_fragment.xml | 5 +- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 96aaafc673..c1ee67bfa8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -65,12 +65,14 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag ImageView iceditIcon; ImageView isfeditIcon; BasalEditDialog basalEditDialog; + LinearLayout ll; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false); + ll = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_linearlayout); diaView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_dia); mgdlView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mgdl); mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); @@ -138,23 +140,6 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); - timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean b) { - if (b) - ToastUtils.showToastInUiThread(getContext(), getString(R.string.timeshift_hint)); - - } - }); - - percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean b) { - if (b) - ToastUtils.showToastInUiThread(getContext(), getString(R.string.percentagefactor_hint)); - } - }); - timeIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -202,6 +187,47 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); + timeshiftView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + timeshiftView.setError(null); + } + }); + + percentageView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + percentageView.setError(null); + } + }); + + timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + timeshiftView.clearFocus(); + ll.requestFocusFromTouch(); + timeshiftView.setError(null); + } + else { + timeshiftView.setError(getString(R.string.timeshift_hint), null); + } + } + }); + + percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + percentageView.clearFocus(); + ll.requestFocusFromTouch(); + percentageView.setError(null); + } + else { + percentageView.setError(getString(R.string.percentagefactor_hint), null); + } + } + }); TextWatcher textWatch = new TextWatcher() { @@ -368,6 +394,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag super.onResume(); MainApp.bus().register(this); onStatusEvent(null); + ll.requestFocusFromTouch(); } @Subscribe diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 7d864353c6..6d9b21fd35 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -13,7 +13,10 @@ + android:orientation="vertical" + android:id="@+id/circadianpercentageprofile_linearlayout" + android:focusable="true" + android:focusableInTouchMode="true" > Date: Fri, 10 Feb 2017 17:39:09 +0100 Subject: [PATCH 04/10] use validation lib in cpp - add a timer --- .../CircadianPercentageProfileFragment.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index c1ee67bfa8..fef7c5fffc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.CircadianPercentageProfile; import android.app.Activity; import android.content.Context; import android.os.Bundle; +import android.os.CountDownTimer; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.text.Editable; @@ -210,7 +211,14 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag timeshiftView.setError(null); } else { - timeshiftView.setError(getString(R.string.timeshift_hint), null); + new CountDownTimer(5000, 1000) { //timer for 5sec + public void onTick(long millisUntilFinished) { + timeshiftView.setError(getString(R.string.timeshift_hint), null); + } + public void onFinish() { + timeshiftView.setError(null); + } + }.start(); } } }); @@ -224,7 +232,14 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag percentageView.setError(null); } else { - percentageView.setError(getString(R.string.percentagefactor_hint), null); + new CountDownTimer(5000, 1000) { //timer for 5sec + public void onTick(long millisUntilFinished) { + percentageView.setError(getString(R.string.percentagefactor_hint), null); + } + public void onFinish() { + percentageView.setError(null); + } + }.start(); } } }); From 49e08f3357056aacdfd7873ab5da891dca67265b Mon Sep 17 00:00:00 2001 From: LadyViktoria Date: Fri, 10 Feb 2017 18:00:10 +0100 Subject: [PATCH 05/10] use validation lib in cpp - add counter --- .../CircadianPercentageProfileFragment.java | 104 ++++++++---------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index fef7c5fffc..0bed2495d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -141,6 +141,54 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); + timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + boolean counter = false; + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + timeshiftView.clearFocus(); + ll.requestFocusFromTouch(); + } + else { + if (!counter) { + new CountDownTimer(5000, 1000) { //timer for 5sec + public void onTick(long millisUntilFinished) { + timeshiftView.setError(getString(R.string.timeshift_hint), null); + } + public void onFinish() { + timeshiftView.setError(null); + } + }.start(); + counter = true; + } + } + } + }); + + percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + boolean counter = false; + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + percentageView.clearFocus(); + ll.requestFocusFromTouch(); + } + else { + if (!counter) { + new CountDownTimer(5000, 1000) { //timer for 5sec + public void onTick(long millisUntilFinished) { + percentageView.setError(getString(R.string.percentagefactor_hint), null); + } + public void onFinish() { + percentageView.setError(null); + } + }.start(); + counter = true; + } + } + } + }); + timeIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -188,62 +236,6 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); - timeshiftView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - timeshiftView.setError(null); - } - }); - - percentageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - percentageView.setError(null); - } - }); - - timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean hasFocus) { - if (!hasFocus) { - timeshiftView.clearFocus(); - ll.requestFocusFromTouch(); - timeshiftView.setError(null); - } - else { - new CountDownTimer(5000, 1000) { //timer for 5sec - public void onTick(long millisUntilFinished) { - timeshiftView.setError(getString(R.string.timeshift_hint), null); - } - public void onFinish() { - timeshiftView.setError(null); - } - }.start(); - } - } - }); - - percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean hasFocus) { - if (!hasFocus) { - percentageView.clearFocus(); - ll.requestFocusFromTouch(); - percentageView.setError(null); - } - else { - new CountDownTimer(5000, 1000) { //timer for 5sec - public void onTick(long millisUntilFinished) { - percentageView.setError(getString(R.string.percentagefactor_hint), null); - } - public void onFinish() { - percentageView.setError(null); - } - }.start(); - } - } - }); - TextWatcher textWatch = new TextWatcher() { @Override From 279c67bb70b54b0ee39faafa69c306e254cdefac Mon Sep 17 00:00:00 2001 From: viktoria Date: Sat, 11 Feb 2017 00:16:25 +0100 Subject: [PATCH 06/10] use validation lib in cpp - add snackbar --- app/build.gradle | 1 + .../CircadianPercentageProfileFragment.java | 178 ++++++++++++------ .../circadianpercentageprofile_fragment.xml | 21 ++- 3 files changed, 138 insertions(+), 62 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ec7e25f692..ca49fa5e1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,6 +126,7 @@ dependencies { compile 'com.android.support:cardview-v7:23.4.0' compile 'com.android.support:recyclerview-v7:23.4.0' compile 'com.android.support:gridlayout-v7:23.4.0' + compile 'com.android.support:design:23.4.0' compile 'com.wdullaer:materialdatetimepicker:2.3.0' compile 'com.squareup:otto:1.3.7' compile 'com.j256.ormlite:ormlite-core:4.46' diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 0bed2495d9..0c7856f8c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -4,18 +4,20 @@ package info.nightscout.androidaps.plugins.CircadianPercentageProfile; import android.app.Activity; import android.content.Context; import android.os.Bundle; -import android.os.CountDownTimer; +import android.support.design.widget.Snackbar; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RadioButton; @@ -36,7 +38,6 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; -import info.nightscout.utils.ToastUtils; public class CircadianPercentageProfileFragment extends Fragment implements FragmentBase { private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfileFragment.class); @@ -47,11 +48,11 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag return circadianPercentageProfilePlugin; } - EditText diaView; + FormEditText diaView; RadioButton mgdlView; RadioButton mmolView; - EditText targetlowView; - EditText targethighView; + FormEditText targetlowView; + FormEditText targethighView; FormEditText percentageView; FormEditText timeshiftView; TextView profileView; @@ -68,17 +69,20 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag BasalEditDialog basalEditDialog; LinearLayout ll; + Boolean percentageViewHint = true; + Boolean timeshiftViewHint = true; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.circadianpercentageprofile_fragment, container, false); ll = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_linearlayout); - diaView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_dia); + ll.requestFocusFromTouch(); + diaView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_dia); mgdlView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mgdl); mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); - targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow); - targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh); + targetlowView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow); + targethighView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh); percentageView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); timeshiftView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview); @@ -141,54 +145,6 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); - timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - boolean counter = false; - @Override - public void onFocusChange(View view, boolean hasFocus) { - if (!hasFocus) { - timeshiftView.clearFocus(); - ll.requestFocusFromTouch(); - } - else { - if (!counter) { - new CountDownTimer(5000, 1000) { //timer for 5sec - public void onTick(long millisUntilFinished) { - timeshiftView.setError(getString(R.string.timeshift_hint), null); - } - public void onFinish() { - timeshiftView.setError(null); - } - }.start(); - counter = true; - } - } - } - }); - - percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { - boolean counter = false; - @Override - public void onFocusChange(View view, boolean hasFocus) { - if (!hasFocus) { - percentageView.clearFocus(); - ll.requestFocusFromTouch(); - } - else { - if (!counter) { - new CountDownTimer(5000, 1000) { //timer for 5sec - public void onTick(long millisUntilFinished) { - percentageView.setError(getString(R.string.percentagefactor_hint), null); - } - public void onFinish() { - percentageView.setError(null); - } - }.start(); - counter = true; - } - } - } - }); - timeIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -236,6 +192,71 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } }); + timeshiftView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + timeshiftView.clearFocus(); + ll.requestFocusFromTouch(); + } + else { + if (timeshiftViewHint) { + customSnackbar(view, getString(R.string.timeshift_hint), "timeshiftViewHint"); + } + } + } + }); + + percentageView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + percentageView.clearFocus(); + ll.requestFocusFromTouch(); + } + else { + if (percentageViewHint) { + customSnackbar(view, getString(R.string.percentagefactor_hint), "percentageViewHint"); + } + } + } + }); + + diaView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + diaView.clearFocus(); + ll.requestFocusFromTouch(); + } + } + }); + + targethighView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + targethighView.clearFocus(); + ll.requestFocusFromTouch(); + } + } + }); + + targetlowView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus) { + targetlowView.clearFocus(); + ll.requestFocusFromTouch(); + } + } + }); + TextWatcher textWatch = new TextWatcher() { @Override @@ -263,9 +284,18 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString()); updateProfileInfo(); } - circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString()); - circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); - circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); + if (diaView.testValidity()) { + circadianPercentageProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString()); + updateProfileInfo(); + } + if (targethighView.testValidity()) { + circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); + updateProfileInfo(); + } + if (targetlowView.testValidity()) { + circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); + updateProfileInfo(); + } circadianPercentageProfilePlugin.storeSettings(); updateProfileInfo(); } @@ -282,6 +312,34 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag return layout; } + private void customSnackbar(View view, String Msg, final String Hint) { + if (timeshiftViewHint || percentageViewHint) { + Snackbar mSnackBar = Snackbar.make(view, + Msg, + Snackbar.LENGTH_LONG) + .setDuration(7000) + .setActionTextColor(getResources().getColor(R.color.notificationInfo)) + .setAction(getString(R.string.dismiss), new View.OnClickListener() { + @Override + public void onClick(View v) { + if (Hint.equals("percentageViewHint")) { + percentageViewHint = false; + } else if (Hint.equals("timeshiftViewHint")) { + timeshiftViewHint = false; + } + } + }); + view = mSnackBar.getView(); + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams(); + params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; + view.setLayoutParams(params); + view.setBackgroundColor(getResources().getColor(R.color.cardview_dark_background)); + TextView mainTextView = (TextView) (view).findViewById(android.support.design.R.id.snackbar_text); + mainTextView.setTextColor(getResources().getColor(R.color.mdtp_white)); + mSnackBar.show(); + } + } + private void updateProfileInfo() { StringBuilder sb = new StringBuilder(); sb.append("

"); @@ -314,6 +372,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag basalEditDialog.dismiss(); } basalEditDialog = null; + ll.requestFocusFromTouch(); } public static class BasalEditDialog extends DialogFragment { @@ -394,6 +453,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag basalEditDialog = null; MainApp.bus().unregister(this); + ll.requestFocusFromTouch(); } @Override diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 6d9b21fd35..99bf9f0235 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -253,7 +253,12 @@ android:text="@string/dia" android:textAppearance="?android:attr/textAppearanceMedium" /> - - - Date: Sat, 11 Feb 2017 00:47:14 +0100 Subject: [PATCH 07/10] use validation lib in cpp - small changes --- .../CircadianPercentageProfileFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 0c7856f8c2..6dbc27c2c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -69,8 +69,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag BasalEditDialog basalEditDialog; LinearLayout ll; - Boolean percentageViewHint = true; - Boolean timeshiftViewHint = true; + static Boolean percentageViewHint = true; + static Boolean timeshiftViewHint = true; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -202,7 +202,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } else { if (timeshiftViewHint) { - customSnackbar(view, getString(R.string.timeshift_hint), "timeshiftViewHint"); + customSnackbar(view, getString(R.string.timeshift_hint)); } } } @@ -218,7 +218,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag } else { if (percentageViewHint) { - customSnackbar(view, getString(R.string.percentagefactor_hint), "percentageViewHint"); + customSnackbar(view, getString(R.string.percentagefactor_hint)); } } } @@ -312,7 +312,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag return layout; } - private void customSnackbar(View view, String Msg, final String Hint) { + private void customSnackbar(View view, final String Msg) { if (timeshiftViewHint || percentageViewHint) { Snackbar mSnackBar = Snackbar.make(view, Msg, @@ -322,9 +322,9 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag .setAction(getString(R.string.dismiss), new View.OnClickListener() { @Override public void onClick(View v) { - if (Hint.equals("percentageViewHint")) { + if (Msg.equals(getString(R.string.percentagefactor_hint))) { percentageViewHint = false; - } else if (Hint.equals("timeshiftViewHint")) { + } else if (Msg.equals(getString(R.string.timeshift_hint))) { timeshiftViewHint = false; } } From e4c529fa1f26e066b930add300f46bd34af3c14e Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 11 Feb 2017 19:59:20 +0100 Subject: [PATCH 08/10] reenable safety function --- .../CircadianPercentageProfilePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java index cca3f99477..56aa813c29 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfilePlugin.java @@ -253,7 +253,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte @Override public NSProfile getProfile() { - // performLimitCheck(); + performLimitCheck(); return convertedProfile; } From 1f5dd4750a2da2a8ab40b4399c728e45aaae49fb Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 11 Feb 2017 22:18:28 +0100 Subject: [PATCH 09/10] CPP dismiss info when focus is lost --- .../CircadianPercentageProfileFragment.java | 23 ++++++++++++++----- .../circadianpercentageprofile_fragment.xml | 2 +- app/src/main/res/values/strings.xml | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java index 6dbc27c2c5..0b31f360bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/CircadianPercentageProfile/CircadianPercentageProfileFragment.java @@ -43,6 +43,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag private static Logger log = LoggerFactory.getLogger(CircadianPercentageProfileFragment.class); private static CircadianPercentageProfilePlugin circadianPercentageProfilePlugin = new CircadianPercentageProfilePlugin(); + private Object snackbarCaller; public static CircadianPercentageProfilePlugin getPlugin() { return circadianPercentageProfilePlugin; @@ -68,6 +69,7 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag ImageView isfeditIcon; BasalEditDialog basalEditDialog; LinearLayout ll; + Snackbar mSnackBar; static Boolean percentageViewHint = true; static Boolean timeshiftViewHint = true; @@ -197,12 +199,15 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { + if(mSnackBar!=null && snackbarCaller == timeshiftView){ + mSnackBar.dismiss(); + } timeshiftView.clearFocus(); ll.requestFocusFromTouch(); } else { if (timeshiftViewHint) { - customSnackbar(view, getString(R.string.timeshift_hint)); + customSnackbar(view, getString(R.string.timeshift_hint), timeshiftView); } } } @@ -213,12 +218,15 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { + if(mSnackBar!=null && snackbarCaller == percentageView){ + mSnackBar.dismiss(); + } percentageView.clearFocus(); ll.requestFocusFromTouch(); } else { if (percentageViewHint) { - customSnackbar(view, getString(R.string.percentagefactor_hint)); + customSnackbar(view, getString(R.string.percentagefactor_hint), percentageView); } } } @@ -312,14 +320,17 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag return layout; } - private void customSnackbar(View view, final String Msg) { + private void customSnackbar(View view, final String Msg, Object snackbarCaller) { + if(mSnackBar!= null) mSnackBar.dismiss(); + + this.snackbarCaller = snackbarCaller; if (timeshiftViewHint || percentageViewHint) { - Snackbar mSnackBar = Snackbar.make(view, + mSnackBar = Snackbar.make(view, Msg, Snackbar.LENGTH_LONG) - .setDuration(7000) + .setDuration(Snackbar.LENGTH_LONG) .setActionTextColor(getResources().getColor(R.color.notificationInfo)) - .setAction(getString(R.string.dismiss), new View.OnClickListener() { + .setAction(getString(R.string.dont_show_again), new View.OnClickListener() { @Override public void onClick(View v) { if (Msg.equals(getString(R.string.percentagefactor_hint))) { diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 99bf9f0235..347695c413 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -278,7 +278,7 @@ Remote calibration not allowed Calibration sent xDrip is not receiving calibrations + Don\'t show again From 2e6d754c8695d899a74a35cbd0bb4487ab3a196f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 11 Feb 2017 22:26:16 +0100 Subject: [PATCH 10/10] mmol/l fix --- app/src/main/res/layout/circadianpercentageprofile_fragment.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml index 347695c413..fbf85c7c59 100644 --- a/app/src/main/res/layout/circadianpercentageprofile_fragment.xml +++ b/app/src/main/res/layout/circadianpercentageprofile_fragment.xml @@ -290,7 +290,7 @@