Skip to content

bastienpaulfr/AndroidCountries

Repository files navigation

Download Build Status

AndroidCountries

Countries resources for Android

Set Up

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

For country data

dependencies {
    implementation 'com.github.bastienpaulfr.AndroidCountries:countries:0.1.4'
}

For flag resources

dependencies {
    implementation 'com.github.bastienpaulfr.AndroidCountries:flags:0.1.4'
}

Presentation

Country data

Data is gotten from https://restcountries.eu/

Data is stored in a json file. This file is parsed during the first access to data.

// Create a countryManager
val countryManager = CountryManager(context) // Context is used for accessing to raw resource where json file is stored.

// getting the full list of countries
val countries: Collection<Country> = countryManager.countries

// Getting a country by name
val france: Country = countryManager.countryByName["France"]

//Getting a country vy alpha3 code
val france: Country = countryManager.countryByAlpha3Code["FRA"]

//Getting a country vy alpha2 code
val france: Country = countryManager.countryByAlpha2Code["FR"]

Flags

The flags are named by their 2-letter ISO-3166 country code, except for the constituent countries of Great Britain which have 6-letter codes "GB-ENG" etc).

Kosovo uses the user-assigned country code XK, which is not part of the ISO standard, but in use by several multinational organizations.

Flags are standard resources. Name of resource is ic_{2-letter ISO-3166 country code}

For example :

val resId = R.drawable.ic_fr

SVG counterpart of drawable resource is in data/svg folder

Logs

This library uses SLF4J for logging. Please use android binding to log into logcat. More info on Android binding

dependencies {
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-android
    implementation 'org.slf4j:slf4j-android:1.7.30'
}

You can also bind SLF4J to timber. In this case please use this dependency

dependencies {
    implementation 'com.arcao:slf4j-timber:3.1'
}

To activate verbose logging, please add this into your code :

LogDefines.setVerbose(true);

Sometimes, it can have log for profiling, in this case, to activate them please add this in code :

LogDefines.setProfile(true);

One TAG is used for all logging from lib : AndroidCountries. It would be easy to filter on this tag if you want to disable all logging from lib. Filtering can be done with Timber and a Tree from Treessence

dependencies {
    implementation 'com.github.bastienpaulfr:Treessence:1.0.5'
}

License

Flag pictures

The source files were taken from Wikipedia and are not under copyright protection since flags are effectively in public domain.

Code

Copyright (C) 2020 Bastien Paul

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.

About

Make country information to Android applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published