use validation lib in cpp

This commit is contained in:
LadyViktoria 2017-02-10 11:34:05 +01:00
parent 4857259eda
commit 80de9c0cd8
3 changed files with 47 additions and 21 deletions

View file

@ -20,6 +20,7 @@ import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
import com.andreabaccega.widget.FormEditText;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -50,8 +51,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
RadioButton mmolView; RadioButton mmolView;
EditText targetlowView; EditText targetlowView;
EditText targethighView; EditText targethighView;
EditText percentageView; FormEditText percentageView;
EditText timeshiftView; FormEditText timeshiftView;
TextView profileView; TextView profileView;
TextView baseprofileIC; TextView baseprofileIC;
TextView baseprofileBasal; TextView baseprofileBasal;
@ -75,8 +76,8 @@ public class CircadianPercentageProfileFragment extends Fragment implements Frag
mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol); mmolView = (RadioButton) layout.findViewById(R.id.circadianpercentageprofile_mmol);
targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow); targetlowView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targetlow);
targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh); targethighView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_targethigh);
percentageView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_percentage); percentageView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_percentage);
timeshiftView = (EditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift); timeshiftView = (FormEditText) layout.findViewById(R.id.circadianpercentageprofile_timeshift);
profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview); profileView = (TextView) layout.findViewById(R.id.circadianpercentageprofile_profileview);
baseprofileBasal = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal); baseprofileBasal = (TextView) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal);
baseprofileBasalLayout = (LinearLayout) layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout); 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, public void onTextChanged(CharSequence s, int start,
int before, int count) { int before, int count) {
if (percentageView.testValidity()) {
if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) { if (SafeParse.stringToInt(percentageView.getText().toString()) == 0) {
circadianPercentageProfilePlugin.percentage = 100; circadianPercentageProfilePlugin.percentage = 100;
} else { } else {
circadianPercentageProfilePlugin.percentage = SafeParse.stringToInt(percentageView.getText().toString()); 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.dia = SafeParse.stringToDouble(diaView.getText().toString());
circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString()); circadianPercentageProfilePlugin.targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString()); circadianPercentageProfilePlugin.targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
circadianPercentageProfilePlugin.timeshift = SafeParse.stringToInt(timeshiftView.getText().toString());
circadianPercentageProfilePlugin.storeSettings(); circadianPercentageProfilePlugin.storeSettings();
updateProfileInfo(); updateProfileInfo();
} }

View file

@ -253,7 +253,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
@Override @Override
public NSProfile getProfile() { public NSProfile getProfile() {
performLimitCheck(); // performLimitCheck();
return convertedProfile; return convertedProfile;
} }

View file

@ -1,4 +1,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:validate="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -33,9 +34,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:background="@drawable/pillborder"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="5dp"> android:padding="5dp"
android:backgroundTint="@color/mdtp_transparent_black"
android:background="@drawable/pillborder"
android:backgroundTintMode="src_over">
<ImageView <ImageView
android:id="@+id/circadianpercentageprofile_percentageicon" android:id="@+id/circadianpercentageprofile_percentageicon"
@ -44,23 +47,34 @@
android:src="@mipmap/ic_percentage" android:src="@mipmap/ic_percentage"
android:textAppearance="?android:attr/textAppearanceMedium"/> android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText <com.andreabaccega.widget.FormEditText
validate:testType="numericRange"
validate:minNumber="50"
validate:maxNumber="200"
android:digits="0123456789.,"
android:id="@+id/circadianpercentageprofile_percentage" android:id="@+id/circadianpercentageprofile_percentage"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/percentagefactor_hint" android:inputType="number"
android:inputType="number"/> android:selectAllOnFocus="true"
android:textAlignment="center" />
</LinearLayout> </LinearLayout>
<Space
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:background="@drawable/pillborder"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="5dp"> android:padding="5dp"
android:backgroundTint="@color/mdtp_transparent_black"
android:background="@drawable/pillborder"
android:backgroundTintMode="src_over">
<ImageView <ImageView
android:id="@+id/circadianpercentageprofile_timeicon" android:id="@+id/circadianpercentageprofile_timeicon"
@ -69,12 +83,17 @@
android:src="@mipmap/ic_time" android:src="@mipmap/ic_time"
android:textAppearance="?android:attr/textAppearanceMedium"/> android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText <com.andreabaccega.widget.FormEditText
validate:testType="numericRange"
validate:minNumber="0"
validate:maxNumber="24"
android:digits="0123456789.,"
android:id="@+id/circadianpercentageprofile_timeshift" android:id="@+id/circadianpercentageprofile_timeshift"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/timeshift_hint" android:inputType="number"
android:inputType="number"/> android:selectAllOnFocus="true"
android:textAlignment="center" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>