Git Product home page Git Product logo

aliazaz / edittext-picker Goto Github PK

View Code? Open in Web Editor NEW
63.0 5.0 8.0 1.94 MB

EditText/MaskText library use for empty, masking, pattern, and range validation📱📋

Home Page: https://android.jlelse.eu/edittext-picker-library-4c71ae7d7863

License: MIT License

Kotlin 100.00%
android-arsenal mask-edittext range-checking edittext-library masking masking-helper kotlin-android edittext-picker range-validation validation-library

edittext-picker's Introduction

EditTextPicker/Masked-Edittext Library

Build Status API Android Arsenal License: MIT

Edittext library by which you can easily achieve a lot of functionalities by directly implementing some lines of code in XML and on the Java side. The following are the functions that EditTextPicker provides:

  • Empty checking
  • Masking Edittext
  • Pattern checking
  • Range checking

Description:

Please see the description of this library in my article Edittext Picker Library

Result

pic-1   pic-2   pic-3

Implementation

In project.gradle add this code it in root build.gradle at the end of repositories:

dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Now, add the dependency in app.gradle:

dependencies {
    implementation 'com.github.AliAzaz:Edittext-Library:X.X.X'
}

Quick Usage

XML

Note: By default required is true. But if you don't want to validate specific edittext then simply set it to false: app:required="false"

-- Required Edittext

<com.edittextpicker.aliazaz.EditTextPicker
     android:id="@+id/txtBoxReq"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:required="true" />

-- Range (5-10) with a default value of 999

<com.edittextpicker.aliazaz.EditTextPicker
     android:id="@+id/txtBoxRange"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:inputType="number"
     app:defaultValue="999"
     app:maxValue="10"
     app:minValue="5"
     app:required="true"
     app:type="range" />

-- Masking

<com.edittextpicker.aliazaz.EditTextPicker
     android:id="@+id/txtMask"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:inputType="number"
     app:mask="##-##-####"
     app:required="false" />

-- Pattern with default value checking [Following pattern is: (2-4)Characters with (3-5)Digits ]

<com.edittextpicker.aliazaz.EditTextPicker
     android:id="@+id/txtBoxDefault"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:defaultValue="null"
     app:pattern="[^0-9]{2,4}[0-9]{3,5}"
     app:required="true"
     app:type="equal" />

Java/Kotlin

Implement this code in submit button click

--- For Required component

if (!txtBoxReq.isEmptyTextBox()) return;

-- For validating range component

if (!txtBoxRange.isRangeTextValidate()) return;

-- For validating pattern component

if (!txtBoxDefault.isTextEqualToPattern()) return;

Support Builder Pattern

This library also support chain request

txtPicker = EditTextPicker(this,
	     EditTextPickerBuilder().apply {
                setRequired(true)
                setRangeValues(0.5f, 40.0f)
                setMask("##.##")
                setPattern("^(\\d{2,2}\\.\\d{2,2})$")
          }.build())
          .apply {
                hint = "##.##"
                inputType = InputType.TYPE_CLASS_NUMBER
          }

Set values at Run time

Users can easily set the attribute values at runtime.

txtDate.setMask("##-##-####").setRequired(false)

EditText-Picker Gradle Configuration

  edittextpicker = 2.1.1
  gradle = 7.4.2
  kotlin = 1.8.0
  build_version = 34.0.0
  min_api_level = 21
  max_api_level = 34

CONNECT👍

LinkedIn Badge Twitter Badge Medium Badge Stackoverflow Badge

LICENSE

Distributed under the MIT license. See LICENSE information.

edittext-picker's People

Contributors

aliazaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

edittext-picker's Issues

[Bug] Focus Changes while pattern is still matching?

Hi, thanks for making this library, I've found it pretty useful. There is one issue I'm facing though -
I'm using a pattern to take vehicle number plate as input. I've used the following xml for this.

<com.edittextpicker.aliazaz.EditTextPicker
    android:id="@+id/vehicle_number"
    ...
    app:defaultValue="null"
    app:pattern="[A-Z]{2}[0-9]{2}[A-Z]+[0-9]+"
    app:required="true"
    app:type="equal" />

And the corresponding java code is :

edittext.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if(edittext.isTextEqualToPattern()){
                    ...
            }
        }
        ...
});

There is another (android's) edit text present in the view.
The issue: Text I want to enter in above field is "AB12CD1234". But the focus shifts to the other edit text as soon as I type "AB12CD1" (right when it matches the text for first time). This is an undesired behavior, I simply want to validate the text and not change the focus.

I'm fairly new to android, so can't say for sure, but I've checked your source and the bug seems to be around line 237 in isTextEqualToPattern() :

    // call for checking default value in textbox
    public boolean isTextEqualToPattern() {            
            ...
        if (!checkingTextPattern())
            ...
        super.setError(null);
        super.clearFocus(); // <-- Is this required?
            ...
    }

    private boolean checkingTextPattern() {
         ...
        if (!super.getText().toString().matches(pattern)) {
            super.setFocusableInTouchMode(true);
            super.requestFocus();
            ...
        }
        ...
    }

Mask not apply after change text

Hi
My mask was: ####-####-####-####

But when I change this input text with programmatically, mask not apply on it.

Please fix it.
Thanks

Changing the mask doesn't work

Hi!

If I created the component on XML and then try to change the mask on code it doesn't change. Even if I dont set the mask on the XML and just set it programatically it doesnt work.

<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/field1"
android:layout_width="match_parent"
android:layout_height="50dp"
app:mask="##-(##)-####"
android:textColor="@android:color/white"
android:textColorHint="@color/transparent_white"
android:textCursorDrawable="@null"
android:textSize="@dimen/login_edit_text_size"
android:background="@drawable/edit_text_white_underline"
android:gravity="center"
/>

field1.setMask("##-(##)-####");

any idea?

Thanks!

Implement property access syntax (builder pattern)

Implement property access syntax and its not mandatory to define all the required properties in XML like:

For Type Range:

  • minvalue
  • maxvalue

For Type Equal:

  • defaultvalue

Property access syntax means:


val txt = EditTextPicker(this)
  .setMask("##.##")
  .setType(RANGE)
  .setMinValue(20.00)
  .setMaxValue(60.00)
  .setDefaultValue(98)
val flag = false

val txt02 = EditTextPicker(this).setMask("##.##").setPattern("^(\\d{2,2}\\.\\d{2,2})$").setRequired(flag)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.