Giter Site home page Giter Site logo

intlphoneinput's Introduction

International Phone Input

Android Arsenal

If you can contrinute and help, please visit this link

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. 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 aorobator avatar ashishgkwd534 avatar chenbachar avatar iamdarush avatar j1gs4w avatar morxander avatar ndacosta avatar noordawod avatar ranjeevmahtani avatar simllll avatar vmuneeb 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

intlphoneinput's Issues

making app crash

hi,

When we select Saintbarthelemy, it has country code +590, which same as some other countries like Saint Martin. so This code decides the country code upon format of remaining number. if that number is invalid then this
String region = mPhoneUtil.getRegionCodeForNumber(phoneNumber);
returns null.
upon next line
int countryIdx = mCountries.indexOfIso(region);
in indexOfIso method .. toUpperCase is being called upon region which produces null pointer exception.
image

Pardon me if anything is wrong with creating this issue

Thanks

ArrayIndexOutOfBoundsException @ IntlPhoneInput.setEmptyDefault():164

Stack trace:

Caused by java.lang.ArrayIndexOutOfBoundsExceptionlength=303; index=-1 Raw Text
--
  | java.util.ArrayList.get (ArrayList.java:310)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setEmptyDefault (IntlPhoneInput.java:164)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setEmptyDefault (IntlPhoneInput.java:172)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setDefault (IntlPhoneInput.java:150)
  | net.rimoto.intlphoneinput.IntlPhoneInput.init (IntlPhoneInput.java:92)
  | net.rimoto.intlphoneinput.IntlPhoneInput.<init> (IntlPhoneInput.java:64)

Error Hint Color

   int color = a.getColor(R.styleable.IntlPhoneInput_textColor, -1);
    if (color != -1) {
        mPhoneEdit.setTextColor(color);
    }
    int hintColor = a.getColor(R.styleable.IntlPhoneInput_textColorHint, -1);
    if (hintColor != -1) {
        mPhoneEdit.setHintTextColor(color);
    }
    a.recycle();

should be hint color

Preview mode for layout preview in IDE

I just created a new project compileSdkVersion 23 and minSdkVersion 15. Added the dependency at gradle and Added the XML to the activity_main default layout and the following error appears:

java.lang.ClassNotFoundException: android.telephony.PhoneNumberFormattingTextWatcher...

Is it just me?

EDIT: It does compile and works fine, but is there a way i can preview it?

IllegalArgumentException: bitmap size exceeds 32 bits

I came across with the following error

java.lang.IllegalArgumentException: bitmap size exceeds 32 bits
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:939)
at android.graphics.Bitmap.createBitmap(Bitmap.java:895)
at android.view.View.buildDrawingCache(View.java:15224)
at android.view.View.updateDisplayListIfDirty(View.java:14980)

Please, advice

Width popup

Hi, I found that devices with small displays sometimes are too small to show flag + text + extention:

Any tips to fix this?

image

Set empty phone number

Hi,

I'm not able to set an empty phone number and show the hint.
I've tried to change it with the function setEmptyDefault("ES") but it is only changing the flag. I've tried too with setNumber() but if the phone number is not valid it shows my own phone number.

The only way to show the hint and the input number to empty is removing the permission android.permission.READ_PHONE_STATE . In this case, the input is always empty.

It is possible to start an activity with the input empty and showing the hint?

any way to specify country code?

i can use but seems country code will base on phone language
how can we set to predefined country code?

i cannot see any setCountryCode() method

IntlPhoneInput.init() chrashes

Hi, I am getting this errror for some devices:

Caused by java.lang.ArrayIndexOutOfBoundsException
--
  | java.util.ArrayList.get (ArrayList.java:413)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setEmptyDefault (IntlPhoneInput.java:164)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setEmptyDefault (IntlPhoneInput.java:172)
  | net.rimoto.intlphoneinput.IntlPhoneInput.setDefault (IntlPhoneInput.java:150)
  | net.rimoto.intlphoneinput.IntlPhoneInput.init (IntlPhoneInput.java:92)
  | net.rimoto.intlphoneinput.IntlPhoneInput.<init> (IntlPhoneInput.java:64)

Invalid phone number

Some of the Indian numbers we are using are giving us an invalid phone number.

Basically the +91 861 822 5265

Depricated

IntlPhoneInput.java:

this call Relative layout or something deprecated
Please solve this

Call for maintainers

Hey guys,
As some of you might notice, I don't have much time for this project at the moment (especially since I'm not using it actively for a while).

If any of you can take ownership, I'll be happy to grant the relevant permissions.
~ Almog

Edit text background

First of all great work .. Can you please add a method to change bg of edit text.

Why default country not selected ?

Hello, I just starting using this library but it not find my local country.
I'm use that: <uses-permission android:name="android.permission.READ_PHONE_STATE"/> but nothing change.
What shall I do to make it select and put my country phone indicator in the Edittext ?

Thanks.

Getting Inflate Exception while adding net.rimoto.intlphoneinput.IntlPhoneInput to layout xml

Hi -

I am adding <net.rimoto.intlphoneinput.IntlPhoneInput> view in my layout file as below.
<net.rimoto.intlphoneinput.IntlPhoneInput
android:id="@+id/intlphone_input_phonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_phonenumber" />
However, I am getting "android.view.InflateException: Binary XML file line #: Error inflating class net.rimoto.intlphoneinput.IntlPhoneInput" exception while running on device.

So, anybody could you please check this and provide me the solution.

Data binding

Hi!
Using EditText I can bind my object directly like android:text="@={user.phoneNumber}"
But IntlPhoneInput doesn't have this attribute.
How can I bind my data using your lib?

Thanks in advance.

App Crashes when clicking on Flag image to select country

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference at net.rimoto.intlphoneinput.CountrySpinnerAdapter.getDropDownView(CountrySpinnerAdapter.java:47) at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:1007) at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:1003) at android.widget.AbsListView.obtainView(AbsListView.java:2454) at android.widget.DropDownListView.obtainView(DropDownListView.java:305) at android.widget.ListView.measureHeightOfChildren(ListView.java:1417) at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1280) at android.widget.ListPopupWindow.show(ListPopupWindow.java:632) at android.widget.Spinner$DropdownPopup.show(Spinner.java:1269) at android.widget.Spinner.performClick(Spinner.java:792) at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:448) at android.view.View.performClickInternal(View.java:7236) at android.view.View.access$3600(View.java:801) at android.view.View$PerformClick.run(View.java:27896) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7397) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:920) E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference at net.rimoto.intlphoneinput.CountrySpinnerAdapter.getDropDownView(CountrySpinnerAdapter.java:47) at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:1007) at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:1003) at android.widget.AbsListView.obtainView(AbsListView.java:2454) at android.widget.DropDownListView.obtainView(DropDownListView.java:305) at android.widget.ListView.measureHeightOfChildren(ListView.java:1417) at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1280) at android.widget.ListPopupWindow.show(ListPopupWindow.java:632) at android.widget.Spinner$DropdownPopup.show(Spinner.java:1269) at android.widget.Spinner.performClick(Spinner.java:792) at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:448) at android.view.View.performClickInternal(View.java:7236) at android.view.View.access$3600(View.java:801) at android.view.View$PerformClick.run(View.java:27896) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214)

#Tested on Android 10

Last instance override the values of all other instance

hi,

When we create more then one instance of IntlPhoneInput on same screen, fill the values then go to next activity and come back, the value of last instance override all above instance.

Reason my TL found is that same Id is assigned to all of the instances. so value of last instance is retained and prefill all other instances when we come back.

thanks

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.