• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android Kotlin library to parse and format international phone numbers. Country code picker.

PhoneNumberKit

Android Kotlin library to parse and format international phone numbers. Based on Google's libphonenumber library.

Features

Features
☎️ Validate, normalize and extract the elements of any phone number string.
🎯 Convert raw phone number to formatted phone number string.
πŸ” Automatically detects country flag of the phone number.
πŸ”– Country code selection bottom sheet.
πŸ“Œ Convert country codes to country names and vice versa.
πŸ‡ΉπŸ‡· Get country flag icon for given iso2 code.

Usage

Create a phoneNumberKit instance and attach it to an editTextLayout. That's all you have to do.

val phoneNumberKit = PhoneNumberKit.Builder(this)
    .setIconEnabled(true)
    .admitCountries(listOf("tr", "ca", "de")) // List only those county formats
    .excludeCountries(listOf("tr", "ca")) // Exclude those county formats
    .build()

phoneNumberKit.attachToInput(textField, "tr")
// OR
phoneNumberKit.attachToInput(textField, 1)

To setup with country code selection bottom sheet

phoneNumberKit.setupCountryPicker(this) // Requires activity context

To get an example phone number for given iso2 code

val exampleNumber = phoneNumberKit.getExampleNumber("tr")

To parse raw text to phone number and receive country code, national number

val parsedNumber = phoneNumberKit.parsePhoneNumber(
    number = "1266120000",
    defaultRegion = "us"
)

parsedNumber?.nationalNumber
parsedNumber?.countryCode
parsedNumber?.numberOfLeadingZeros

To convert raw text to formatted phone number string

val formattedNumber = phoneNumberKit.formatPhoneNumber(
    number = "1266120000",
    defaultRegion = "us"
)

To receive a country flag icon for given iso2 code

val flag = phoneNumberKit.getFlagIcon("ca")

Usage with Custom Item Layout

Add your custom item layout resource as a parameter

phoneNumberKit.setupCountryPicker(this, R.layout.my_item_layout, searchEnabled = true)

You need to use below view ids in your layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingVertical="12dp"
    android:paddingHorizontal="18dp"
    android:clickable="true"
    android:focusable="true"
    android:background="?android:attr/selectableItemBackground">

    <ImageView
        android:id="@+id/imageViewFlag"
        android:layout_width="22dp"
        android:layout_height="22dp" />

    <TextView
        android:id="@+id/textViewName"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:singleLine="true"
        android:maxLines="1"
        android:ellipsize="end"
        android:textSize="16sp"
        android:textColor="#232425" />

    <TextView
        android:id="@+id/textViewCode"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="#838383" />

</LinearLayout>

Demo

Country Code Picker Format Example Format Example

Installation

Follow me on Twitter @ibrahimsn98

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.ibrahimsn98:PhoneNumberKit:2.0.6'
}

Checklist

  • Search for country codes
  • Custom list item layout support
  • Better performance with coroutines
  • Phone number validation indicator
  • Dark theme
  • Tests

Conception

License

PhoneNumberKit is available under the Apache license. See the LICENSE file for more info.

More Repositories

1

SmoothBottomBar

A lightweight Android material bottom navigation bar library
Kotlin
1,888
star
2

android-particles

A lightweight Particle Animation Library for Android
Kotlin
423
star
3

speedometer

A lightweight circular indicator view library for Android
Kotlin
262
star
4

web-dev-tools-android

Sample Android Application - MVVM, Clean Architecture, Modularization, Repository Pattern
Kotlin
260
star
5

NiceBottomBar

A lightweight Android material bottom navigation bar library
Kotlin
186
star
6

taskprogressview

A lightweight task progress calendar view library for Android
Kotlin
128
star
7

android-mvvm-dagger-2-rxjava-example

Sample Android Application - MVVM, Dagger 2, RxJava, Retrofit
Java
113
star
8

Freya

A lightweight, simplified form validation library for Android
Kotlin
88
star
9

CirclesLoadingView

Android Google Style Loading Animation Library (Needs performance optimizations!!)
Kotlin
84
star
10

live-preferences

Live Shared Preferences library for Android
Kotlin
72
star
11

achilles

A Simple Retrofit Inspired Android Websocket Client (In Development)
Kotlin
43
star
12

android-eth-wallet

Android cryptocurrency wallet app with clean architecture
Kotlin
37
star
13

android-datausage

An Android library to monitor cellular and wifi data usage easily
Kotlin
30
star
14

blockchain-in-go

A basic blockchain implementation in Golang
Go
21
star
15

android-live-broadcasts

Live broadcast receiver library for Android
Kotlin
21
star
16

sdwebui-kotlin

Kotlin API client for AUTOMATIC1111/stable-diffusion-webui
Kotlin
17
star
17

InputValidator

A Lightweight input validation library for Android
Kotlin
9
star
18

android-preference-editor

Edit the preferences of the Android applications
Python
5
star
19

gradle-maven-publish-example

Kotlin
4
star
20

aucc-game

Cyber security quiz game
Kotlin
4
star
21

github-explorer

A startup page Chrome extension which shows GitHub repositories that are related with your interests
JavaScript
4
star
22

yazgig

JavaScript
1
star
23

maven-version-fetcher

Go
1
star
24

pocketmine-mp-worldguard-plugin

Minecraft PE - PocketMine-MP-WorldGuard-Plugin
PHP
1
star
25

opencv-trials

Python
1
star
26

intellij-idea-plugin-trial

first intellij idea plugin
1
star