Giter VIP home page Giter VIP logo

android-countries's Introduction

Android-Countries

Provides country codes in accordance with ISO-3166-1 and localized names for each country

Installation

  • Create a new library project from this repository and reference it in your project

Usage

Custom country preference in your PreferenceActivity

Add the following code to your XML for the preferences. The class CountryPreference extends ListPreference and has the same appearance. It ignores the attributes android:entries, android:entryValues, android:defaultValue and android:summary because it comes with its own implementation for those.

Be sure to set android:key to the preference key that you want to store the country code in. For android:title, provide a value from your string resources, for example, which will be used as the preference's caption.

<im.delight.android.countries.CountryPreference
	android:key="country"
	android:title="..."
	android:enabled="true"
	android:selectable="true" />

Retrieving a list of all supported short codes

String[] countryCodes = CountryList.getMachineReadable(context);
// countryCodes now contains "CHN", "IND", "USA", "IDN", "BRA" etc.

Retrieving a list of all supported full names

String[] countryNames = CountryList.getHumanReadable(context);
// countryNames now contains "China", "India", "United States", "Indonesia", "Brazil" etc. (depending on the user's locale)

Getting a country's full name by its short code

String localizedName = Country.getNameByIso3Code(context, "ESP");
// localizedName now contains "Spain" or "España" (etc.) depending on the user's locale

Adding new countries

  1. Create a new entry at the end of the string array countries_list_machine in res/values/short_codes.xml
  2. Add the full name of the country (at least for English) to our platform for managed translations
  3. Create a new entry at the end of the string array countries_list_human in res/values/full_names.xml, referencing the new country_xxx resource that has just been submitted in the step before

Translating country names

If you want to translate existing country names, please do so on our platform for managed translations.

License

Copyright (c) delight.im <[email protected]>

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.

android-countries's People

Contributors

ocram avatar

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.