Giter Club home page Giter Club logo

intlphoneinput's Introduction

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. 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.

intlphoneinput's People

Contributors

almogbaku avatar chenbachar avatar morxander avatar ndacosta avatar noordawod avatar ranjeevmahtani avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.