FormattEditText


Source link: https://github.com/PaXLiCh/FormattEditText

Formatted EditText

Useful components for formatting phone numbers, prices, counters. Simple implementations of a EditText widgets, which can help to visualise inputted text. Classes are inherited from AppCompatEditText.

MaskedEditText based on code of Reinaldo Arrosi

Integration

Add the library project or grab to build.gradle:

compile 'ru.kolotnev:formatt-edit-text:0.7'

or plain maven:

<dependency>
<groupId>ru.kolotnev</groupId>
<artifactId>formatt-edit-text</artifactId>
<version>0.7</version>
<type>pom</type> </dependency> 

Usage

Masked EditText

Insert the view in XML:

 <ru.kolotnev.formattedittext.MaskedEditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text=""

app:mask="+999-9A?*"

app:placeholder="_"/>

Properties:

  • mask — mask for text
  • placeholder — character will be shown where an input is expected an by default the placeholder char is a white-space

Methods:

setMask(String mask) This is used to set a mask. MaskedEditText will try to match the current text with the new mask, so if you change the mask and your text is still valid you'll not lose it.

getMask() This method returns the current mask.

setPlaceholder(char placeholder) This is used to set the placeholder character. This character is shown where an input is expected an by default the placeholder char is a white-space

getPlaceholder() This method returns the current character that is being used as the placeholder char.

getText(boolean removeMask) This method is exactly like getText() except that you're able to pass a parameter that will determine if the value returned will contain the mask characters or not.

Mask

The mask is a simple sequence of character where some of these have a special meaning. Any character that does not have a special meaning will be treated as a literal character and will appear as is in the MaskedEditText.

These are the chars that have a special meaning within the mask:

  • 9 — Numeric mask (this will accept only numbers to be typed)
  • A — Alpha mask (this will accept only alphabetic letters to be typed)
  • * — Alphanumeric (this will accept numbers and alphabetic letters to be typed)
  • ? — Character mask (this will accept anything to be typed)
Examples:
  • phone mask: (999) 999-9999
  • money: $999,999,999.99
  • random valid mask: (A)?*99A-9++*??
Escape char:

If you need one of these special chars to be treated as a literal char you can use the escape char \ in front of it:

Please note that each character \ must be also escaped, so the number of escapes is always doubled to be \\

Example: Suppose that in the phone mask we need to add a preceding digit that will always be 9, to do this we can change the mask like this:

  • phone mask: \\9(999) 999-9999

If you need to display the escape char as a literal char just double the escape char like this:

  • phone mask: \\\\(999) 999-9999

Escape chars are escape only one character \. Therefore, the following literal characters must be also written with the escape character:

  • phone mask: \\\\\\9(999) 999-9999

Do not specify android:inputType, it will be automatically set on the fly by specified mask string. If mask string contains only numeric mask characters (and literals), InputType will be set to TYPE_CLASS_NUMBER, otherwise TYPE_CLASS_TEXT.

Decimal EditText

Insert the view in XML:

 <ru.kolotnev.formattedittext.DecimalEditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="numberSigned"

app:plural="@plurals/plural_decimal_test_decimal"

app:rounding="3"/>

Properties:

  • plural — plural resource
  • rounding — amount of digits after comma (zero for integer)

Methods:

BigDecimal getValue() Returns decimal value from entered text.

setValue(BigDecimal value) Sets new value and updates view.

int getDecimalRounding() Gets current amount of fraction digits.

setDecimalRounding(int decimalRounding) Sets amount of fraction digits for formatting and identifying decimal.

int getPluralResource() Gets resource ID of plural for formatting view of input field.

setPluralResource(int pluralResource) Sets plural for formatting of current value with label and updates view.

setFormat(int decimalRounding, int pluralResource) Set whole format of edit text field for displaying decimal value.

setLimits(BigDecimal min, BigDecimal max) Sets the limits for value which can be entered (both ZERO limits means no limits).

Currency EditText

Insert the view in XML:

 <ru.kolotnev.formattedittext.CurrencyEditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:currency="USD"

app:locale="fr"/>

Properties:

  • currency — currency code in ISO 4217
  • locale — locale code in ISO 639

Methods:

BigDecimal getValue() Get current decimal value for currency.

setValue(BigDecimal bigDecimal) Sets new value for edit field.

Locale getLocale() Gets current locale for text field.

setLocale(Locale locale) Sets locale for text field.

Currency getCurrency() Returns current currency for text field.

setCurrency(Currency currency) Sets new currency for text field.

License

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.

Resources

An Android dialog library, has strong extensibility, customizability, and for conveniently building Material Design Dialog in Android version 2.2 ~ L.

Scroll + discover = DiscrollView

You can apply some transformation on discroll:

  • alpha
  • scale
  • translation (fromLeft, fromBottom, fromRight, fromTop) fromLeft+fromRight and fromBottom+fromTop are forbidden couples.
  • bgcolor

A pager transformer for Android with parallax effect.

Titanic is an Android experiment reproducing this effect:

Layout inflation library for Android which uses annotation processing to write the code you don't want to write and simplify your compound views.

Use the annotation @AfterInflate on your compound view's methods you want to run straight after the layout is inflated with Michelangelo.

TextChronometer is a very simple library offering a widget showing a live time formatted like "4 seconds ago": This library is very convenient if you are building apps with a live timeline.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes