Edittext Picker Library📋

Behind the scene story of removing hectic code of java to create multi-functional edittext library

Introduction

Past Procedure

Old pattern of validation

But now, its over😳

Implementation EdittextPicker??

Gradle

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.AliAzaz:Edittext-Library:1.0.2'
}

XML and JAVA

<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxReq"
---------
app:required="true" />
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtMask"
---------
app:mask="+92(###)####-###" />
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxRange"
---------
android:inputType="number"
app:maxValue="100"
app:minValue="10"
app:type="range" />
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxRange"
---------
android:hint="##.##"
android:inputType="number"
app:defaultValue="999"
app:maxValue="100"
app:minValue="10"
app:pattern="^(\\d{2,2}\\.\\d{2,2})$"
app:type="range" />
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxDefault"
---------
app:defaultValue="null"
app:pattern="[^0-9]{2,4}[0-9]{3,5}"
app:type="equal" />

Soon, I’ll also upload an article about HOW TO DEFINE PATTERN in ANDROID 🤞💥

New pattern of validation

Combined All Components CODE Snippet

<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxRange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Range of number 5-10"
android:inputType="number"
android:textColor="@color/colorPrimary"
app:defaultValue="999"
app:maxValue="100"
app:minValue="10"
app:required="true"
app:type="range"/>
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxRangeMaskPat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="##.##"
android:inputType="number"
app:defaultValue="0"
app:mask="##.##"
app:maxValue="40"
app:minValue="0.5"
app:pattern="^(\\d{2,2}\\.\\d{2,2})$"
app:required="true"
app:type="range"/>
<!--Accept first 2-4 characters
then 3-5 numbers-->
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxDefault"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="follow pattern or default values 'null'"
app:defaultValue="null"
app:pattern="[^0-9]{2,4}[0-9]{3,5}"
app:required="false"
app:type="equal"/>
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="##-##-####"
android:inputType="number"
app:mask="##-##-####"
app:required="false"/>
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="+92(###)####-###"
android:inputType="phone"
app:mask="+92(###)####-###"
app:required="true" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SUBMIT" />
private boolean validateComponents() {     if (!txtBoxRange.isRangeTextValidate())
return false;
if (!txtBoxRangeMaskPat.isRangeTextValidate())
return false;
if (!txtBoxDefault.isTextEqualToPattern())
return false;
if (!txtDate.isEmptyTextBox())
return false;
return txtPhone.isEmptyTextBox();
}
private void clearFields() {
txtBoxRange.setText(null);
txtBoxRangeMaskPat.setText(null);
txtBoxDefault.setText(null);
txtMask.setText(null);
}
//Call this listener in OnCreatebtnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (validateComponents()) {
Toast.makeText(MainActivity.this, "Successfully submitted!!", Toast.LENGTH_SHORT).show();
clearFields();
}
}
});

OUTPUT

Do you want to HELP this library?

@AndroidAppsDeveloper, @OpensourceContributor, @Writer @Researcher

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store