International Phone Input


Source link: https://github.com/Rimoto/IntlPhoneInput

International Phone Input

What is it?

IntlNumberInput is a custom view for Android that allows the user to enter his phone number in an elegant and friendly way. It adds a flag dropdown to any input, automatically detects the user's country, displays a relevant placeholder and auto formats the number as they type.


***Full Demo Video - https://youtu.be/vDL6gBtltng ***

Features

  1. Formatting the number as the user types Aautomatically
  2. Automatically set the input placeholder to an example number for the selected country
  3. Selecting a country from the dropdown will update the dial code in the input
  4. Typing a different dial code will automatically update the displayed flag
  5. Easy embedding as a Custom View
  6. Listener available to detect validity change
  7. Automatically detect phone number when information available
  8. Listen to "done" even on the keyboard
  9. More..

Download

Download via Gradle or Maven:

compile 'net.rimoto:intlphoneinput:1.0.1'

or Maven:

<dependency>
<groupId>net.rimoto</groupId>
<artifactId>intlphoneinput</artifactId>
<version>1.0.1</version> </dependency>

Usage

It's easy like 1-2-3!

  1. Add the view to your layout XML:
<net.rimoto.intlphoneinput.IntlPhoneInput
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/my_phone_input" />
  1. Set text size, text color and flag padding:
<net.rimoto.intlphoneinput.IntlPhoneInput
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:textSize="14sp"
  app:textColor="#000000"
  app:flagPaddingBottom="4dp"
  app:flagPaddingEnd="4dp"
  app:flagPaddingStart="4dp"
  app:flagPaddingTop="4dp"
  app:flagPaddingBottom="4dp"
  android:id="@+id/my_phone_input" />
  1. Add it in your java
IntlPhoneInput phoneInputView = (IntlPhoneInput) findById(R.id.my_phone_input);
  1. Check for validity and get the number!
String myInternationalNumber; if(phoneInputView.isValid()) {

  myInternationalNumber = phoneInputView.getNumber();
 
}

Public methods

  1. boolean isValid()

  2. void setEnabled(boolean enabled)

  3. void setOnValidityChange(IntlPhoneInputListener listener)

    public interface IntlPhoneInputListener {
    
    void done(View view, boolean isValid);
     
    }
    

    This simple structure allows you to use lambda expression! (with retrolambda):

    mIntlPhoneInput.setOnValidityChange((view, isValid) -> {
    
    if(isValid) {
    ...
    }
     
    }
     
  4. void setOnKeyboardDone(IntlPhoneInputListener listener)

  5. void hideKeyboard()

  6. void setDefault() - Set default number: if can detect line by permission(requires android.permission.READ_PHONE_STATE), else- example number for country as hint(detect by SIM info if has permission, else by locale). This method automatically invoked on init

  7. void setEmptyDeafult(String iso) - Set example hint for iso

  8. void setEmptyDefault() - Set example hint by locale

  9. void setNumber(String number) - Set number, number in E.164 format(i.e. +972501234567)

  10. String getNumber() or String getText() - Get number in E.164 format

Attributions

  1. Inspired by intl-tel-input for jQuery
  2. Flag images from region-flags
  3. Original country data from mledoze's World countries in JSON, CSV and XML
  4. Formatting/validation/example number code from libphonenumber

Sponsors

Thanks to our sponsors for this project:

  1. JetBrains - for providing the great IDE PhpStorm
  2. Rimoto

LICENSE

Copyright 2015 Rimoto LTD, AlmogBaku  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

RxJava bindings for DBFlow models, and query language.

A custom ImageButton that invoke onClickListener only when touch is inside the circle not outside (rectangle area of button).

Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview.

Simple and easy json parser, json generator, and data holder based on JSONArray and JSONObject for android.

Pinview library for Android.

Material Chip view can be used as tags for categories, contacts or creating text clouds.

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