Code Monkey home page Code Monkey logo

maskara's Introduction

Maskara

Build Status API

A simple way to format text fields without getting affected by input filters.

Normal Completable Persistent
maskara maskara maskara

How It Works

Used to define how to format the text.

  • value is used to define the format string. E.g. +90 (___) ___ __ __

There's no limitation here. You can use any type of characters with any type of input filters.

  • maskCharacter is used to define which characters in the format string user can edit. E.g. _

It's not mandatory to define this explicitly. Mask will set the character with most occurences in the format string as maskCharacter by default.

You should use non alphanumeric characters here.

Used to define mask visibility and cursor behaviour.

  • Normal Mask is never visible. Cursor is not limited.

  • Completable Mask becomes visible right after the user started typing until the user deleted everything. Cursor is not limited.

  • Persistent Mask becomes visible right after the user started typing and never becomes hidden. Cursor is limited between mask characters.

You can retrieve these from both the widget and the listener.

  • masked Masked version of input text.

  • unMasked Raw version of input text.

  • isDone Validity of input text.

Usage

With Widget

<com.santalu.maskara.widget.MaskEditText
    android:id="@+id/input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
    app:mask="+90 (___) ___ __ __"
    app:maskCharacter="_"
    app:maskStyle="completable" />

To get the result:

val masked = input.masked
val raw = input.unMasked
val isDone = input.isDone

Without Widget

val mask = Mask(
    value = "+90 (___) ___ __ __",
    character = '_',
    style = MaskStyle.COMPLETABLE
)
val listener = MaskChangedListener(mask)
textField.addTextChangedListener(listener)

To get the result:

val masked = listener.masked
val raw = listener.unMasked
val isDone = listener.isDone

Dependencies

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.santalu:maskara:1.0.0'
}

License

Copyright 2020 Fatih Santalu

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

maskara's People

Contributors

danielbenedykt avatar santalu 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maskara's Issues

Problem with change textColor

I am trying to change the color of the text with "android:textColor".
But for some reason, the color remains "colorPrimary" from the library.

Does this library have the ability to change the color of the text?

Thank you in advance)

从中间删除时,格式化有问题

bug: 定义手机格式"### #### ####",然后输入123 4567 8900,然后从头部开始删除比如2或者3后,格式变成了12 4567 8900,正确的应该是124 5678 900

Apply mask from right to left

Is it possible to use a mask that as the user enters additional values, they will appear starting with the right-most digit, pushing older digit entries left as they type?
For example, I have the following mask: ##.###,##
What I want to input: 100,00
But since the mask starts from left to right if I try to input 100,00 I will end up with 10.000, due to the natural mask comportament.

Android Manifest Error After adding this dependency.

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
	is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
	Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-30:19 to override.

capture

Version 1.0.0 -> 1.1.1 Change Log?

Hi, you're project is great and I noticed you have a update [1.0.0 -> 1.1.1].

Is it possible to get a change log or release notes on what changed from these two versions? Would love to know if there bug fixes or performance improvements!

Format gets duplicated when deleting

Using the following code and format

<com.google.android.material.textfield.TextInputLayout
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:layout_margin="@dimen/material_margin"
                        android:hint="@string/phone">

                    <com.santalu.maskedittext.MaskEditText
                            android:id="@+id/PhoneTextInput"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="phone"
                            app:met_mask="###-###-####x######"/>

                </com.google.android.material.textfield.TextInputLayout>

</com.google.android.material.textfield.TextInputLayout>

When placing your cursor before the 'x' (for extension) and deleting a number creates duplicate 'x' characters.

image

Unable to add text in this view

I have used this widget in my project but when I'll try to click on this view in the sake of adding the text, unable to add text in it

IndexOutOfBounds when hitting space bar

Using the following mask.

val postCodeMask = Mask(
            value = "___ ___",
            character = '_',
            style = MaskStyle.NORMAL
        )

I get an IndexOutOfBoundsExeption when hitting the space character when the user hits the space bar key, not sure if this an expected behaviour. I would expect here the space bar to be treated as the space character.

Stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: __________________t, PID: 21295
    java.lang.IndexOutOfBoundsException: setSpan (5 ... 5) ends beyond length 4
        at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1325)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:676)
        at android.text.Selection.setSelection(Selection.java:94)
        at android.text.Selection.setSelection(Selection.java:78)
        at android.text.Selection.setSelection(Selection.java:153)
        at com.santalu.maskara.MaskResultKt.apply(MaskResult.kt:26)
        at com.santalu.maskara.MaskChangedListener.afterTextChanged(MaskChangedListener.kt:31)
        at android.widget.TextView.sendAfterTextChanged(TextView.java:10551)
        at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:13388)
        at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1277)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:577)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:507)
        at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:37)
        at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:843)
        at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:197)
        at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:177)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:339)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:89)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

IP Mask

How to use it for : IP Mask

example :
192.168.0.1
198.168.127.250

every part : 0..255

also with hint like :
input ip : xxx.xxx.xxx.xxx

Input duplication on Android 7.1.1 (API 25)

Hey. Just to let you know, I'm not sure if this is some weird interaction between your lib and android 7.1.1, but for some reason, the input is getting duplicated sometimes. Example bellow:

Mask: ##:##:##:##:##:##
inputType: textCapCharacters
Scenario: try typing ABCDEFGHIL on a software keyboard (it works fine with a hardware keyboard).

You'll see the following result "AB:CD:CD:...". It duplicates the "CD" right after you type "D". This happens with other strings as well.

Adding the input type as "textCapCharacters | textNoSuggestions" fixes the issue.

[BUG] setText doesn't work.

mask-edittext is totally broken when you use previously saved value. You just can't setText to MaskEditText. Also you cannot fix problem cos MaskEditText is final class.

Could you be so kind to fix this bug? Thx

Masking Fails when editing from between

Hi,
I am using your mask edittext. It works fine in a normal user case but it fails when i edit a phone number from between
(568) 766-4444
Mask :- (###) ###-####

And then if i put the cursor in between, let say near the "-" and press backspace on the keyboard multiple times, so now the phone number becomes :-
()))) )----85

Strange behaviour deleting and writing some characters more times (twice or three)

Strange behaviour: use this example
<com.santalu.maskedittext.MaskEditText
android:id="@+id/etPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="some text"
android:inputType="text"
app:met_mask="## ## ## ## ## ## ## ##"
/>

At runtime, put some characters, than delete some of them using back button, do this action (put some characters than delete some ones) more times (twice or three).
As result i see some characters repeated.

Widget makes the app crash if used without a mask

Hi @santalu!

The widget makes the app crash if it is used without a mask. It is becasue a null listener is added on the overriden function onAttachedToWindow

I have replaced line 65 of MaskEditText.kt with the following validation to fix the issue

if(maskChangedListener != null) {
addTextChangedListener(maskChangedListener)
}

Good library!!

Thank you!

Cesar.-

Support for multi line

Apply mask on the each line:

<com.santalu.maskedittext.MaskEditText
	android:id="@+id/phones_input"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:inputType="textMultiLine|phone"
	android:scrollbars="vertical"
	android:minLines="4"
	android:maxLines="4"
	android:lines="4"
	app:mask="+90(###) ### ## ##"/>

Unable to type the number in mask

There is one issue with mask. If you set phone code to let's say +998 (__) ____ - __ - , here the code contains the digits 9 and 8, then you cannot type 9 and 8 when you just open keyboard. Similarly, if it is +78 () ____ - __ - __, then you cannot type 7 and 8 in the beginning

Format gets duplicated when deleting

Hello, Dear Developer.
Using the following code and format

<com.santalu.maskedittext.MaskEditText
android:id="@+id/maskEditText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="21dp"
android:layout_marginLeft="21dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="21dp"
android:layout_marginRight="21dp"
android:background="@drawable/rounded_input_phone_pass"
android:hint="Telephone nomery"
android:inputType="phone"
android:paddingLeft="23dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2"
app:met_mask="+8(###) ### - ## - ##" />
After first delete numbers in mask. Happend this:
01
02

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.