World Country flags, currency and more - an open source android library for getting country flags and other country attributes

An Android library that contains ‘all’ the flags of the countries of the world
This is to be used for android projects where the developer is interested in
getting the flag of a particular country for any reason.


System requirement


Usage

  1. Add JitPack in your respository build file build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Get the latest commit from the master branch by including
dependencies {
    ...
    implementation 'com.github.blongho:world-country-data:master-SNAPSHOT'
}

Replace master-SNAPSHOT with vXXX for the most stable
version
or any earlier version from releases)

  1. Build your project (and make sure gradle has successfully synced)
    Buid >> Clean Project, Build >> Rebuild Projeect
  1. Load all the flags of the world by calling. Do this once in the
    application context.
World.init(getApplicationContext());

This inititializes the data. All countries are read, and their flags loaded

  1. Get the flag of a country(dynamically)
// Demonstrating with Sweden
//The attribute is case-insensitive "se == SE == sE == Se"

// use alpha2
final int flag = World.getFlagOf("se"); // use "se" or "sE" or "SE" or "Se"

// use alpha3
final int flag = World.getFlagOf("swe");

// Use country name
final int flag = World.getFlagOf("sweden");

// use country name
final int flag = World.getFlagOf(752);

// Set the image of an imageView
final ImageView swedishFlag= (ImageView) findViewById(R.id.flagImageView);
swedishFlag.setImageResource(flag);

/*
The value of flag is either
- the flag of the country if it is loaded in the library
OR
- a demo flag of the globe (This provides a fall-back and help your app not crash due to nullPointerException)
*/
<ImageView android:id="@+id/flagImageId" 
    android:layout_width="@dimens/imageWidth"
    android:layout_height="@dimens/imageHeight"
    android:src="@drawable/se"/> <!-- Sets this image to the Swedish flag -->
// Set the image of an imageView
final ImageView swedishFlag= (ImageView) findViewById(R.id.flagImageView);
swedishFlag.setImageResource(R.drawable.se);
  1. Get a Country with attributes like "id":4,"name":"Afghanistan","alpha2":"af","alpha3":"afg", flag:imageResource"
final Country afghanistan = World.getCountryFrom("af|afg|afghanistan|4");
// Log.d(TAG, afghanistan.toString()); 
  1. Get a list of all the countries with their identifies
final List<Country> countries = World.getAllCountries();
// This list cannot be modified but you can get its contents

Checkout the full documentation from World country data documentation


Demonstrating dynamic retrieval of country flags


<details>
<summary><b>Data sources for the project</b></summary>

All country flags

Most of the flags came from flagpedia.net.
This site does not contain all the countries in the world so some where downloaded
from wikipedia after quering the country name

Countries and their iso alpha values

All country names were download from
GitHub@stafangabos.
These were copied using into the assets directory

Getting different dimensions of the flags

Some guys from Egypt made some awesome App icon generator
which generates android drawables as well as iOS images(if you want) in different dimensions.
It is super fast and can do batch processing of images.
</details>


Contribution guidelines

Please feel free to add more flags or modify any thing that would make this libray more useful.
Follow First contributions instructions
and i will be super happy to merge your pull request.

If you are particularly generous, you can
<a href="https://www.buymeacoffee.com/lKmSQRsaU" title=“Click to buy a cup of coffee for blongho”><img src="https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png" height=“32”></a>


Contact

Feel free to contact me to discuss anything related to development in particular and life in general.

If you use this in your application, please let me know


MIT License <br>
Copyright © 2019 Bernard Che Longho