Skip to content

Commit

Permalink
done some changes in fucntionality in default checking and update exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
AliAzaz committed Apr 18, 2019
1 parent 847dd22 commit e7aad84
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 53 deletions.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private boolean validateComponents() {
if (!((EditTextPicker) txtBoxRangeMaskPat).isRangeTextValidate())
return false;

return ((EditTextPicker) txtBoxDefault).isTextEqual();
return ((EditTextPicker) txtBoxDefault).isTextEqualToPattern();
}

private void clearFields() {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
app:required="true"
app:type="range" />

<!--Accept first 2 - 4 characters with 3 - 5 numbers-->
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxDefault"
android:layout_width="0dp"
Expand All @@ -147,6 +148,7 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@+id/txtBoxRangeMaskPat"
app:pattern="[^0-9]{2,4}[0-9]{3,5}"
app:required="true"
app:type="equal" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class EditTextPicker extends AppCompatEditText implements TextWatcher {

private float min, max;
private Object defaultvalue;
private float min, max, floatdefaultvalue;
private String defaultvalue;
private String mask;
private String pattern;
private Integer type;
Expand Down Expand Up @@ -44,7 +44,7 @@ public EditTextPicker(Context context, AttributeSet attrs) {

min = a.getFloat(R.styleable.EditTextPicker_minValue, -1);
max = a.getFloat(R.styleable.EditTextPicker_maxValue, -1);
defaultvalue = a.getFloat(R.styleable.EditTextPicker_defaultValue, -1);
floatdefaultvalue = a.getFloat(R.styleable.EditTextPicker_defaultValue, -1);

if (min == -1)
throw new RuntimeException("Min value not provided");
Expand Down Expand Up @@ -92,14 +92,30 @@ public void setMax(float max) {
this.max = max;
}

public Object getDefaultvalue() {
public float getFloatdefaultvalue() {
return floatdefaultvalue;
}

public void setFloatdefaultvalue(float floatdefaultvalue) {
this.floatdefaultvalue = floatdefaultvalue;
}

public String getDefaultvalue() {
return defaultvalue;
}

public void setDefaultvalue(Object defaultvalue) {
public void setDefaultvalue(String defaultvalue) {
this.defaultvalue = defaultvalue;
}

public String getPattern() {
return pattern;
}

public void setPattern(String pattern) {
this.pattern = pattern;
}

public String getMask() {
return mask;
}
Expand Down Expand Up @@ -153,8 +169,7 @@ private void maskingEditText(String mask) {

// call for checking empty textbox
public boolean isEmptyTextBox() {
if (!required)
return true;
if (!required) return true;
if (super.getText().toString().isEmpty()) {
Log.i(this.getContext().getClass().getName(), this.getContext().getResources().getResourceEntryName(super.getId()) + ": Empty!!");
super.setError("Required! ");
Expand All @@ -173,12 +188,12 @@ public boolean isRangeTextValidate() {
if (!checkingPattern()) return false;

if (Float.valueOf(super.getText().toString()) < min || Float.valueOf(super.getText().toString()) > max) {
if ((Float) defaultvalue != -1) {
if (floatdefaultvalue != -1) {
Float dValue = Float.parseFloat(super.getText().toString());
if (Float.parseFloat(super.getText().toString()) == Math.round(Float.parseFloat(super.getText().toString())))
dValue = Float.parseFloat(super.getText().toString().split("\\.")[0]);

if (dValue.equals(defaultvalue)) {
if (dValue.equals(floatdefaultvalue)) {
invalidate();
return true;
}
Expand All @@ -203,26 +218,20 @@ public boolean isRangeTextValidate() {
}

// call for checking default value in textbox
public boolean isTextEqual() {
public boolean isTextEqualToPattern() {
if (!required) return true;
if (!isEmptyTextBox()) return false;
if (!checkingPattern()) return false;
if (!super.getText().toString().equals(String.valueOf(defaultvalue))) {
super.setError("Not equal to default value: " + defaultvalue + " !!");
super.setFocusableInTouchMode(true);
super.requestFocus();
Log.i(this.getContext().getClass().getName(), this.getContext().getResources().getResourceEntryName(super.getId()) + ": Not Equal to default value: " + defaultvalue + "!!");
invalidate();
return false;
if (!checkingPattern()) {
if (!super.getText().toString().equals(String.valueOf(defaultvalue))) return false;
}
super.setError(null);
super.clearFocus();
invalidate();
return true;
}

public boolean checkingPattern() {
if (!required)
return true;
if (pattern == null)
return true;
if (pattern == null) return true;
if (!super.getText().toString().matches(pattern)) {
super.setError("Not match to pattern!!");
super.setFocusableInTouchMode(true);
Expand Down

0 comments on commit e7aad84

Please sign in to comment.