use validation lib in cpp - add snackbar
This commit is contained in:
parent
49e08f3357
commit
279c67bb70
3 changed files with 138 additions and 62 deletions
|
@ -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'
|
||||
|
|
|
@ -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("<h3>");
|
||||
|
@ -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
|
||||
|
|
|
@ -253,7 +253,12 @@
|
|||
android:text="@string/dia"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
<com.andreabaccega.widget.FormEditText
|
||||
validate:testType="floatNumericRange"
|
||||
validate:floatminNumber="1.0"
|
||||
validate:floatmaxNumber="10.0"
|
||||
android:digits="0123456789.,"
|
||||
android:selectAllOnFocus="true"
|
||||
android:id="@+id/circadianpercentageprofile_dia"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -271,14 +276,24 @@
|
|||
android:text="@string/target_range"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
<com.andreabaccega.widget.FormEditText
|
||||
validate:testType="floatNumericRange"
|
||||
validate:floatminNumber="5.0"
|
||||
validate:floatmaxNumber="180.0"
|
||||
android:digits="0123456789.,"
|
||||
android:selectAllOnFocus="true"
|
||||
android:id="@+id/circadianpercentageprofile_targetlow"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="2"
|
||||
android:inputType="numberDecimal" />
|
||||
|
||||
<EditText
|
||||
<com.andreabaccega.widget.FormEditText
|
||||
validate:testType="floatNumericRange"
|
||||
validate:floatminNumber="10.0"
|
||||
validate:floatmaxNumber="270.0"
|
||||
android:digits="0123456789.,"
|
||||
android:selectAllOnFocus="true"
|
||||
android:id="@+id/circadianpercentageprofile_targethigh"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
Loading…
Reference in a new issue