Giter VIP home page Giter VIP logo

phonemoji's Introduction

Maven Central Build Status ktlint

โ˜ phonemoji

Phonemoji provides a flexible text input field implementation that formats international phone numbers as you type and displays the flag of the country that matches the number's country code. It's powered by libphonenumber (or its Android port to be more precise), compatible with Material Components, and based on PhoneNumberFormattingTextWatcher.

demo

๐Ÿ™ƒ Flags are emoji, so no extra resources are required. Also, they look cute.

๐Ÿ‘‰ Flags are not tappable -- there's no list with all the country codes or anything like that.

๐Ÿšฉ The flag is updated as the phone number is entered and formatted. It updates as soon as the country code is identified, and it only changes again if a different valid country code is entered.

โž• It only supports international numbers, so the plus sign is always there and can't be removed. It's still part of the input, though, so you can still move the cursor before the sign. If you do that and input a character, the input will be entered after the plus sign.

Download

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.fredporciuncula:phonemoji:1.5.2'
}

Usage

The library offers a TextInputEditText and a TextInputLayout implementation. When you put them together, the TextInputLayout renders the flag as a startIconDrawable based on the TextInputEditText input:

<com.fredporciuncula.phonemoji.PhonemojiTextInputLayout
  style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="@string/phone_number"
  >

  <com.fredporciuncula.phonemoji.PhonemojiTextInputEditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

</com.fredporciuncula.phonemoji.PhonemojiTextInputLayout>

  • The flag visibility and size can be set with the attributes phonemoji_showFlag and phonemoji_flagSize.
  • The field is never empty. By default, it starts with +XX, where XX is the country calling code for the network country (from TelephonyManager) or for the country from the default Locale in case the network country doesn't resolve to a valid country code.
  • The initial country code can also be set with the attributes phonemoji_initialRegionCode (e.g. US for 1) and phonemoji_initialCountryCode (e.g. 1 for the US) or through setRegionCode() and setCountryCode().

If you don't want to work with a TextInputLayout, or if you don't want to render the flag as the start icon there, you can use a PhonemojiFlagTextView to render the flag anywhere you place it. You can "connect" it with the TextInputEditText by referencing it in the phonemoji_flagFor attribute like this:

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  >

  <com.fredporciuncula.phonemoji.PhonemojiFlagTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="16sp"
    app:phonemoji_flagFor="@id/phonemojiTextInputEditText"
    />

  <com.fredporciuncula.phonemoji.PhonemojiTextInputEditText
    android:id="@+id/phonemojiTextInputEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:phonemoji_initialRegionCode="BR"
    />

</LinearLayout>

๐Ÿ™†โ€โ™‚๏ธ

Data binding

If you're planning to use data binding, don't use the text property directly like this:

android:text="@{user.phoneNumber}"

Instead, use internationalPhoneNumber to make sure the input will always be formatted properly:

internationalPhoneNumber="@{user.phoneNumber}"

Startup

The library initializes itself using the App Startup library. In general, this isn't important for consumers, and it just means you can use the library without worrying about any initialization logic. But it also means the library depends on App Startup in order to work properly, so if you disable it for any reason, the library will crash.

phonemoji's People

Contributors

ketankmr avatar tfcporciuncula avatar themaharshpatel 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

Watchers

 avatar  avatar

phonemoji's Issues

How to use the source files in my project without Maven

Great work, congratulation....
Do you have any guide on how to use the source files of your project in my project without adding the dependency from Maven ?

dependencies {
implementation 'com.fredporciuncula:phonemoji:1.5.1'
}

I would like to minimize the use of Maven for my project...๐Ÿ˜‰

Fatal Exception: java.lang.IllegalStateException: View referenced in flagFor isn't a PhonemojiTextInputEditText

This is crash I'm getting for many devices.

Fatal Exception: java.lang.IllegalStateException: View referenced in flagFor isn't a PhonemojiTextInputEditText
at com.fredporciuncula.phonemoji.PhonemojiFlagTextView.watchPhoneNumber(PhonemojiFlagTextView.kt:47)
at com.fredporciuncula.phonemoji.PhonemojiFlagTextView.onAttachedToWindow(PhonemojiFlagTextView.kt:42)
at android.view.View.dispatchAttachedToWindow(View.java:20874)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.addViewInner(ViewGroup.java:5293)
at android.view.ViewGroup.addView(ViewGroup.java:5076)
at android.view.ViewGroup.addView(ViewGroup.java:5016)
at androidx.fragment.app.FragmentStateManager.addViewToContainer(FragmentStateManager.java:833)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2180)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:978)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loopOnce(Looper.java:238)
at android.os.Looper.loop(Looper.java:357)
at android.app.ActivityThread.main(ActivityThread.java:8089)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)

XML Code :

            <com.fredporciuncula.phonemoji.PhonemojiFlagTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_medium"
                android:gravity="center"
                android:textSize="@dimen/sp_18"
                app:phonemoji_flagFor="@id/etPhoneNumber" />

            <com.fredporciuncula.phonemoji.PhonemojiTextInputEditText
                android:id="@+id/etPhoneNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_medium"
                android:background="@null"
                android:fontFamily="@font/lato_bold"
                android:hint="@string/enter_mobile_hint"
                android:imeOptions="actionDone"
                android:textColor="@color/text_black"
                android:textColorHint="@color/stroke_color"
                android:textSize="@dimen/sp_18" />

        </LinearLayout>

RTL support

Seems like right to left is not supported when switching the language in a localized application.

Layout rendering Error in Android Studio Dolphin | 2021.3.1 Patch 1

I dont understand how to fix it and it breaks the layout of the view

	at com.fredporciuncula.phonemoji.PhonemojiTextInputLayout.watchPhoneNumber(PhonemojiTextInputLayout.kt:51)
	at com.fredporciuncula.phonemoji.PhonemojiTextInputLayout.onAttachedToWindow(PhonemojiTextInputLayout.kt:46)
	at android.view.View.dispatchAttachedToWindow(View.java:20753)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
	at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:58)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:366)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:717)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:873)
	at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:192)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Databinding: java.lang.IndexOutOfBoundsException if android:text is null or length < 3

There is an Issue if one is databinding the android:text property, where the given String length is less than 3 in com.tfcporciuncula.phonemoji.PhonemojiTextInputEditText

<com.tfcporciuncula.phonemoji.PhonemojiTextInputEditText android:id="@+id/profile_edit_phone_input" android:layout_width="match_parent" android:layout_height="wrap_content" android:imeOptions="actionNext" android:inputType="text" android:maxLines="1" android:paddingEnd="42dp" android:scrollHorizontally="true" android:text="@{user.general.phone}" tools:text="Telefon" />

user.general.phone is null in this case.

workaround: check if text is null, empty or less than 3 and set it with any text > 3

i.e.: android:text="@{user.general.phone.length > 3 ? user.general.phone : +43}"

java.lang.IndexOutOfBoundsException: setSpan (3 ... 3) ends beyond length 1
        at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1327)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:688)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
        at android.text.Selection.setSelection(Selection.java:93)
        at android.text.Selection.setSelection(Selection.java:77)
        at android.text.Selection.setSelection(Selection.java:152)
        at android.widget.EditText.setSelection(EditText.java:136)
        at com.tfcporciuncula.phonemoji.PhonemojiTextInputEditText$setCountryCode$1.run(PhonemojiTextInputEditText.kt:82)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:220)
        at android.app.ActivityThread.main(ActivityThread.java:6929)
        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:870)

nevertheless this is a very cool Component! Good work!

[BUG] - flag is not updated on specific usecase

In the sample project on line 144:

<com.tfcporciuncula.phonemoji.PhonemojiTextInputEditText
          android:id="@+id/secondParentlessTextInputEditText"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingStart="28dp"
          app:phonemoji_initialRegionCode="JP" //FR
          tools:ignore="RtlSymmetry"
          />

if i replace JP by FR and i launch the app and then I delete the last character (a '3') (from right to left) and i put another letters, it not update the flags and the format. It will only update the format if i delete the 2 characters (the two '3')

After digging it, it seems that if we fill default initialregion code and country so the bug is not here. Seems to be when its autodetected when no default value is filled

Please help me to solve this error

Failed to transform 'C:\Users\MOHSEN.gradle\caches\modules-2\files-2.1\com.fredporciuncula\phonemoji\1.2.0\604184735c49475e4d56eb42c5ee0b1ada7ff7df\phonemoji-1.2.0.aar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)

Problems with Layout preview in Android Studio

Environment: Android Studio Flamingo | 2022.2.1 Patch 1

Hello, I am using your amazing library, but I get this error when working with the layout preview in Android Studio. Is there anything we can do for it?
The library works okay at runtime ๐Ÿ˜.

image

java.lang.IllegalStateException: PhoneNumberUtil instance hasn't been initialized.
at com.fredporciuncula.phonemoji.internal.PhoneNumberUtilInstanceProvider.get(PhoneNumberUtilInstanceProvider.kt:13)
at com.fredporciuncula.phonemoji.PhonemojiTextInputEditText.(PhonemojiTextInputEditText.kt:22)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:351)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:200)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:161)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:294)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:426)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:437)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:341)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1127)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:353)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:450)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:122)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:884)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:195)
at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:293)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)

Document the use of `androidx.startup` explicitly

I'm using this library and was completely unaware that it uses androidx.startup.Initializer to initialize the PhoneNumberUtil instance. Since I was not using the androidx.startup anywhere in my app, I went ahead disabling the same while following the WorkManger: Custom Configuration guide, which resulted in an app crash due to IllegalStateException raised here

it's pretty neat that library takes care of initialization itself ๐Ÿ‘
(No more "put these lines in your Application's onCreate()" instructions ๐Ÿ™‚)

and documenting the same would make it even clearer.

MavenCentral migration problems

I can`t migrate to maven central because your library used "libphonenumberAndroid" - 8.12.16 just update it to the latest, today is 8.12.33, to solve this problem

Default Country Code is not set in the TextField

As per the documentation, field is never empty and default text is "+XX" where is the country code, either received from attributes or resolved with TelephonyManager. I'm using the PhonemojiTextInputLayout and PhonemojiTextInputEditText, but in my case, only the country flag is set as expected and the TextField only has "+" sign.

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.