Skip to content

sambhav2358/BadgeGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BadgeGenerator

API Latest Version Library Size JitPack GitHub commits GitHub issues Forks Stars

BadgeGenerator is a lightweight Android library that allows developers to create, customize, and display status badges (inspired by Shields.io) directly within their mobile applications.

🌟 Key Features

  • Custom Styles: Support for for-the-badge, plastic, flat, flat-square, and social styles.
  • Logo Support: Integrated support for Simple Icons and custom Base64 logos.
  • Interactive: Built-in support for redirect links on badge clicks.
  • Export Options: Download your generated badges as PNG or SVG files.
  • Smart Conversion: Utility class to convert Bitmaps, Uris, and Files to Base64 strings.
  • Ultra-Lightweight: Total library size is only ~9KB.

πŸ“Ί Demonstration

Sample Preview

Sample.mp4

Video Tutorial

For a step-by-step walkthrough, check out the YouTube Tutorial.
(Note: Video may not cover the latest v2.2 features).


1. Implementation

Add Repository

Add the JitPack repository to your settings.gradle:

dependencyResolutionManagement {
    repositories {
        maven { url '[https://jitpack.io](https://jitpack.io)' }
    }
}

Add Dependency

Add the following to your app-level build.gradle:

dependencies {
    implementation 'com.github.sambhav2358:BadgeGenerator:2.2'
}

Alternatively, you can manually include the .aar file.

2. Usage

XML Implementation

Declare the BadgeView in your layout file:

<com.sambhav2358.badgegeneratorlibrary.BadgeView
    android:id="@+id/badge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:badgeLabel="Status"
    app:badgeMessage="Active"
    app:logoImage="whatsapp"
    app:logoWidth="25"
    app:redirectUrl="[https://github.com](https://github.com)" />

Java Implementation

Configure the badge dynamically through code:

// Basic Configuration
binding.badge.setLabel("Build");
binding.badge.setMessage("Passing");
binding.badge.setColor(BadgeColor.brightGreen);
binding.badge.setType(BadgeType.flat);

// Advanced Customization
binding.badge.setLabelColor("#2F2F2F"); // Set background for the label side
binding.badge.setLogo("android");       // Uses SimpleIcons slugs
binding.badge.setLink("[https://github.com/sambhav2358](https://github.com/sambhav2358)");

3. Customization Options

Supported Badge Styles Style Preview
for-the-badge image
plastic image
flat image
flat-square image
Social image

Working with Logos

You can use standard slugs from Simple Icons or provide your own:

// Using a custom Base64 logo
binding.badge.setCustomLogo(Base64Converter.getBase64FromBitmap(myBitmap));

// Changing logo color and width
binding.badge.setLogoColor(BadgeColor.yellow);
binding.badge.setLogoWidth("30");

4. Exporting & External Loading

Downloading Badges

Save your generated badge directly to the device storage:

// Download as SVG
binding.badge.downloadBadgeSVG(Environment.DIRECTORY_PICTURES);

// Download as PNG
binding.badge.downloadBadgePNG(Environment.DIRECTORY_PICTURES);

Loading via URL

If you already have a Shields.io URL, you can load it directly:

binding.badge.loadFromUrl("[https://img.shields.io/badge/dynamic/json](https://img.shields.io/badge/dynamic/json)?...");

5. Known Limitations

Image Quality: When using non-vector custom logos, converting to SVG is not possible. In these cases, the badge defaults to PNG, which may result in quality loss at higher scales.

XML Colors: Background color modification is currently only supported via Java/Kotlin code.

6. Acknowledgments

Shields.io – For the badge design inspiration.

Picasso & GlideToVectorYou – For image loading.

7. License

This project is open-source and free to use/modify under the MIT License.


Built with ❀️ by Sambhav Khandelwal