Scrounger

Additional

Language
Java
Version
1.0.4 (Oct 10, 2017)
Created
Oct 7, 2017
Updated
Oct 10, 2017
Owner
Scrounger
Contributor
Scrounger
1
Activity
Badge
Generate
Download
Source code

Blurb

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.0.4'
}

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

new CountryPickerListener()

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

new CountryAndCurrenciesPickerListener()

3. Currency

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

new CurrencyPickerListener()

4. Currency and Country

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

new CurrencyAndCountriesPickerListener()

use as fragment (embed in your own activity)

            CountryCurrencyPicker pickerFragment = CountryCurrencyPicker.newInstance(new CountryAndCurrenciesPickerListener() {
                @Override
                public void onSelect(Country country, Currency currency) {
                    Toast.makeText(MainActivity.this,
                            String.format("name: %s\ncurrencySymbol: %s", country.getName(), currency.getSymbol())
                            , Toast.LENGTH_SHORT).show();
                }
            });

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

use as dialog

            CountryCurrencyPicker pickerDialog = CountryCurrencyPicker.newInstance(new CountryAndCurrenciesPickerListener() {
                @Override
                public void onSelect(Country country, Currency currency) {
                    Toast.makeText(MainActivity.this,
                            String.format("name: %s\ncurrencySymbol: %s", country.getName(), currency.getSymbol())
                            , Toast.LENGTH_SHORT).show();

                    DialogFragment dialogFragment =
                            (DialogFragment) getSupportFragmentManager().findFragmentByTag(CountryCurrencyPicker.DIALOG_NAME);
                    dialogFragment.dismiss();
                }
            });

            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

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