GithubHelp home page GithubHelp logo

jsramraj / flags Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 3.17 MB

Simple no nonsense library for getting flag icon for any country

License: MIT License

Java 100.00%
android flags country jitpack maven android-library

flags's Introduction

Android counter part of the RSFlags iOS library

Lightweight android library for getting flag image for any country

This entire library is only 175 kb. Can you believe that?

Simple, no nonsense, lightweight library for getting flag icon for any country from the two character country code

How this differs from other libraries?

There are plenty of open source libraries available for getting the flag icon. But they all include separate image or vector files for each country (there are more than 250 flags in the world) hence become bulky.

Unlike all the other libraries, this one includes only ONE sprite image which consists of all the icons of all the flags. And the icons are sliced from the sprite image when requested.

Demo

Usage

Simple Use

FlagDrawableProvider flagProvider = new Flags.Builder(context)
											 .build();
BitmapDrawable usFlag = flagProvider.forCountry("US")

That is all

Supply your own source image

By default, the flags library uses a 94 kb sprite image with flag icons with size of 32 x 22.

In some cases, this may not be suitable for you. So you can supply your own sprite image with a higher resolution for cases like that.

This is how you supply your source image. Make sure you also give the correct height and width of flag tiles.

FlagDrawableProvider largeFlagProvider = new Flags.Builder(this)
                .setSourceImage(getImageFromAssetsFile(this, "flags_sprite_big.png"))
                .setTileWidth(320)
                .setTileHeight(220)
                .build();

To create a sprite image with higher resolution, visit the Want high res icons? section

How to include

As a dependency

  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' }
	}
}
  1. Add the dependency
dependencies {
  implementation 'com.github.jsramraj:flags:$version'
}

Just replace the $version with the appropriate version number, for e.g v1.0

Direct include

If, for some reason, you are not okay with adding a entire library, you can still use this by just adding two files into your project.

  • Give this library a star
  • Drag the sprite image that consists of all the flag icons into your project's asset folder
  • Add the Flags class to your project

That is all!!! you are good to go.

Want high res icons?

This library is created to occupy very minimum space. So each flag size is only 32x22. If you want a higher resolution image, all you have to do is give a higher resolution image to this library.

You can use my another tool flag-sprite-creator to create higher resolution sprite image. Find our more about the tool here. The tool is deployed in heroku, you can find it here

License

MIT

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.