/IntlPhoneInput

International phone input for Android

Primary LanguageJavaOtherNOASSERTION

International Phone Input

Android Arsenal

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.

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

Features

  1. Automatically format the number as the user types
  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 'com.github.jarrodholliday:intlphoneinput:0.9.18'

or Maven:

<dependency>
  <groupId>com.github.jarrodholliday</groupId>
  <artifactId>intlphoneinput</artifactId>
  <version>0.9.12</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. Find 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

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.