CountryCurrencyPicker is an android picker library for country and / or currency

Overview

Country and Currency Picker for Android

CountryCurrencyPicker is an android picker library for country and / or currency. You can implement it as fragment or dialog. It offers the option to search for country values and / or currency values.
Inspired by country-picker-android and currency-picker-android

Requirements

min. Android API 19 (KitKat)

Integration

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
        compile 'com.github.scrounger:countrycurrencypicker:1.1.1'
}

How to use

The library provides 4 different listener that defines which picker will start

1. Country

Showing all available countries in local language, searching only for country names is possible

PickerType.COUNTRY

2. Country and Currency

Showing all available countries with their currency in local language, searching for country names, currency names and currency symbols is possible

PickerType.COUNTRYandCURRENCY

3. Currency

Showing all available currencies in local language, searching only for currency names and currency symbols is possible

PickerType.CURRENCY

4. Currency and Country

Showing all available currencies with their countries in local language, searching for currency names, currency symbols and countries is possible

PickerType.CURRENCYandCOUNTRY

use as fragment (embed in your own activity)

            CountryCurrencyPicker pickerFragment = CountryCurrencyPicker.newInstance(PickerType.COUNTRY, new CountryCurrencyPickerListener() {
                @Override
                public void onSelectCountry(Country country) {
                    if (country.getCurrency() == null) {
                        Toast.makeText(MainActivity.this,
                                String.format("name: %s\ncode: %s", country.getName(), country.getCode())
                                , Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(MainActivity.this,
                                String.format("name: %s\ncurrencySymbol: %s", country.getName(), country.getCurrency().getSymbol())
                                , Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onSelectCurrency(Currency currency) {

                }
            });

            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, pickerFragment).commit();

use as dialog

            CountryCurrencyPicker pickerDialog = CountryCurrencyPicker.newInstance(PickerType.COUNTRYandCURRENCY, new CountryCurrencyPickerListener() {
                @Override
                public void onSelectCountry(Country country) {

                }

                @Override
                public void onSelectCurrency(Currency currency) {
                    if (currency.getCountries() == null) {
                        Toast.makeText(MainActivity.this,
                                String.format("name: %s\nsymbol: %s", currency.getName(), currency.getSymbol())
                                , Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(MainActivity.this,
                                String.format("name: %s\ncurrencySymbol: %s\ncountries: %s", currency.getName(), currency.getSymbol(), TextUtils.join(", ", currency.getCountriesNames()))
                                , Toast.LENGTH_SHORT).show();
                    }
                }
            });

            pickerDialog.show(getSupportFragmentManager(), CountryCurrencyPicker.DIALOG_NAME);

dialog title

Show and set up a dialog title. Dialog style can be changed by overriding the style attribute (see Customization)

            pickerDialog.setDialogTitle(getString(R.string.country_currency_dialog_title));

For more examples take a look into MainActivity.java

Customization

To customize the style you can override the layout files or just override the styles of library in your project

false ">
<resources>

    <!-- Style for use as Dialog-->
    <style name="countryCurrencyPicker_dialog" parent="@style/Theme.AppCompat.Light.Dialog">
        <item name="android:windowNoTitle">false</item>
    </style>


    <!-- Styles for recyclerView row-->
    <style name="countryCurrencyPicker_row_item_container">
        <item name="android:paddingBottom">2dp</item>
        <item name="android:paddingTop">2dp</item>
        <item name="android:paddingStart">8dp</item>
        <item name="android:paddingEnd">8dp</item>
        <item name="android:foreground">?attr/selectableItemBackground</item>
    </style>

    <style name="countryCurrencyPicker_row_item_icon_flag">
        <item name="android:layout_width">48dp</item>
        <item name="android:layout_height">48dp</item>
    </style>

    <style name="countryCurrencyPicker_row_item_txt_container">
        <!--Style for container with title and subTitle-->
        <item name="android:layout_marginStart">10dp</item>
        <item name="android:layout_marginEnd">10dp</item>
    </style>

    <style name="countryCurrencyPicker_row_item_txt_title">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:maxLines">1</item>
        <item name="android:ellipsize">end</item>
        <item name="android:textColor">#0277bd</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>

    <style name="countryCurrencyPicker_row_item_txt_subtitle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:ellipsize">end</item>
        <item name="android:textColor">@android:color/secondary_text_dark</item>
        <item name="android:textStyle">italic</item>
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>

    <style name="countryCurrencyPicker_row_item_txt_code_or_symbol">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:maxLines">1</item>
        <item name="android:textStyle">bold</item>
        <item name="android:minWidth">30dp</item>
        <item name="android:gravity">center</item>
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>

</resources>

Button

Since version 1.1.0 the library provides Buttons that can be used directly in xml layout files. Button shows the countryName and the countryFlag. On click it opens the picker dialog.

">
    <com.scrounger.countrycurrencypicker.library.Buttons.CountryCurrencyButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:country_code="US"
        app:show_currency="true" />

You can set country_code and show_currency directly in the xml layout file. Or define it befor you initialize the button, for example in the create method:

        CountryCurrencyButton button = (CountryCurrencyButton) findViewById(R.id.button);
        button.setOnClickListener(this);
        button.setCountry("DE");
        button.setShowCurrency(false);

To receive the selected country, just use the CountryCurrencyPickerListener as button.setOnClickListener() listener:

        CountryCurrencyButton button = (CountryCurrencyButton) findViewById(R.id.button);
        button.setOnClickListener(new CountryCurrencyPickerListener() {
            @Override
            public void onSelectCountry(Country country) {
                if (country.getCurrency() == null) {
                    Toast.makeText(MainActivity.this,
                            String.format("name: %s\ncode: %s", country.getName(), country.getCode())
                            , Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this,
                            String.format("name: %s\ncurrencySymbol: %s", country.getName(), country.getCurrency().getSymbol())
                            , Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onSelectCurrency(Currency currency) {

            }
        });

License

Copyright (C) 2017 Scrounger

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.

Comments
  • Compilation issues -

    Compilation issues - "dependency resolution errors."

    When I add this library to my Android project, the compilation issues are as follow:

    Duplicate class org.intellij.lang.annotations.Flow found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.Identifier found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$AdjustableOrientation found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$BoxLayoutAxis found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$CalendarMonth found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$CursorType found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$FlowLayoutAlignment found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$FontStyle found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$HorizontalAlignment found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$InputEventMask found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$ListSelectionMode found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$PatternFlags found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$TabLayoutPolicy found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$TabPlacement found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderJustification found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderTitlePosition found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.JdkConstants$TreeSelectionMode found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.Language found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.MagicConstant found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.Pattern found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.PrintFormat found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.PrintFormatPattern found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.RegExp found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.intellij.lang.annotations.Subst found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.Contract found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.Nls found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.NonNls found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.NotNull found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.Nullable found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.PropertyKey found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    Duplicate class org.jetbrains.annotations.TestOnly found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-15.0 (org.jetbrains:annotations-java5:15.0)
    
    Go to the documentation to learn how to Fix dependency resolution errors.
    
    
    opened by RahulSDeshpande 0
  • Cant manipulate text in button

    Cant manipulate text in button

    Is there a way i can manipulat the string of the button? Make it visible/invisible or concanate a string to the country name? Great library btw.Thanks

    opened by DarkZaidOne 0
  • Bug

    Bug

    When you open currency list or even county, try to lock your phone and unlock it and see whats happening. In my case when I do that exits from current activity.

    opened by eniz1806 0
  • In Androidx cannot be cast to androidx.appcompat.app.AppCompatActivity

    In Androidx cannot be cast to androidx.appcompat.app.AppCompatActivity

    it was working before but suddenly stopped. Now When i click the CountryCurrencyButton instead of getting Dialog With Countries Spinner,App Stopped with this error.

    currency

    opened by niyonkuruelisa 0
  • App Crashes with 'Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: _SP'

    App Crashes with 'Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: _SP'

    Hi, I have used the exact code which you have provided on Github. Still , the app crashes when i chose " Currency and Countries Dialog" from the menu option. Below is the error it shows -

    12-25 21:45:40.407 22599-22653/example.example.com.currencylib E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: example.example.com.currencylib, PID: 22599 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: _SP at java.util.Currency.getInstance(Currency.java:139) at com.scrounger.countrycurrencypicker.library.Currency.getCurrency(Currency.java:123) at com.scrounger.countrycurrencypicker.library.Country.getCountryWithCurrency(Country.java:140) at com.scrounger.countrycurrencypicker.library.Country.listAllWithCurrencies(Country.java:177) at com.scrounger.countrycurrencypicker.library.Currency.getCurrencyWithCountries(Currency.java:151) at com.scrounger.countrycurrencypicker.library.Currency.listAllWithCountries(Currency.java:201) at com.scrounger.countrycurrencypicker.library.CountryCurrencyPicker$FilterListAsync.doInBackground(CountryCurrencyPicker.java:218) at com.scrounger.countrycurrencypicker.library.CountryCurrencyPicker$FilterListAsync.doInBackground(CountryCurrencyPicker.java:197) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764) 

    opened by shwtnk7 1
Releases(1.1.1)
Owner
scrounger
scrounger
Facebook-Styled-Image-Picker - Facebook Styled Image Picker

Facebook-Styled-Image-Picker Facebook Styled Gallery Files picker. One or multip

Hashim Tahir 11 Sep 27, 2022
A customizable, easy-to-use, and functional circular time range picker library for Android

A customizable, easy-to-use, and functional circular time range picker library for Android. Use this library to mimic Apple's iOS or Samsung's bedtime picker.

Joery Droppers 251 Dec 30, 2022
Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal.

About Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal. Gradle Sample Default Item size Unfocused count

null 6 Dec 22, 2022
Nepali Date Picker library in Jetpack compose for android with Date conversion from BS to AD and vice-versa

Nepali Date picker Converter - Re in Compose This is a re-work of Nepali Date Picker Converter in jetpack compose and kotlin. English Locale Nepali Lo

Kiran Gyawali 4 Dec 23, 2022
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
[NO LONGER MAINTAINED] Android library for better Picker DialogFragments

/!\ This Project is no longer maintained /!\ DialogFragments modeled after the AOSP Clock and Calendar apps to improve UX for picking time, date, numb

Code-Troopers 2.7k Dec 29, 2022
Alwan 🎨 is an Android Jetpack Compose color picker library.

Alwan Alwan is an Android Jetpack Compose color picker library. Preview Recording.mp4 Download Gradle: dependencies { implementation 'com.raedapps:a

Raed Mughaus 6 Sep 16, 2022
Android time range picker

TimeRangePicker TimeRangePicker is a library which can be used to select a time range. WARNING Requires android-support-v4 Description This library pr

Titto Jose 422 Nov 10, 2022
A date time range picker for android written in Kotlin

DateTimeRangePicker A date time range picker for android Usage Firstly, grab latest release of the library via JitPack. And note that, it utilizes Jod

SkedGo 501 Dec 31, 2022
A material Date Range Picker based on wdullaers MaterialDateTimePicker

Material Date and Time Picker with Range Selection Credits to the original amazing material date picker library by wdullaer - https://github.com/wdull

Supratim 1.3k Dec 14, 2022
A material Date Range Picker based on wdullaers MaterialDateTimePicker

Material Date and Time Picker with Range Selection Credits to the original amazing material date picker library by wdullaer - https://github.com/wdull

Supratim 1.3k Dec 14, 2022
Simplge ImageGallery Picker

SimpleImagePicker add camera and files permissions to manifest file <uses-permission android:name="android.permission.CAMERA" /> <uses-permiss

null 0 Nov 27, 2021
Time-DatePicker - A Simple Time Date Picker With Kotlin

Time-DatePicker Time.DatePicker.mp4

Faysal Hossain 0 Jan 19, 2022
A simple compose weight picker drawn with canvas.

CanvasWeightPicker A simple compose weight picker drawn with canvas. Features Drag scale to select weight Haptic feedback on weight selected Video of

Timothy Serem 5 Dec 2, 2022
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Android Week View Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling. Fea

Raquib-ul Alam (Kanak) 3.4k Jan 3, 2023
An android library which provides a compact calendar view much like the one used in google calenders.

CompactCalendarView CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar clas

SundeepK 1.5k Dec 9, 2022
FlipTimerView library for Android

FlipTimerView Preview FlipTimerView library for Android Getting started Add it in your root build.gradle at the end of repositories: allprojects { re

Anu S Pillai 314 Dec 28, 2022
Jetlime - A simple library for TimeLine view in Android

JetLime ⏱️ A simple yet highly customizable library for showing a TimeLine view

Pushpal Roy 107 Dec 6, 2022
JetCalendarView - A calendar library for Jetpack Compose

JetCalendar WIP 2022 Hit Refresh! Calendar view ❤️ Jetpack Compose License Copyr

Anmol Verma 8 Aug 17, 2022