lelloman/android-identicons


Simple implementation of Identicons in android

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.lelloman:android-identicons:v12'
	}
	dependencies {
		implementation("com.github.lelloman:android-identicons:v12")
	}
	<dependency>
	    <groupId>com.github.lelloman</groupId>
	    <artifactId>android-identicons</artifactId>
	    <version>v12</version>
	</dependency>

                            
    libraryDependencies += "com.github.lelloman" % "android-identicons" % "v12"
        
        

                            
    :dependencies [[com.github.lelloman/android-identicons "v12"]]
        
        

Readme


android-identicons

An Android library for generating Identicons — unique, deterministic visual identifiers derived from hash values. Supports both traditional XML Views and Jetpack Compose.

Two styles are available:

  • Classic — a 3x3 grid with 37 possible geometric shapes per tile (9 for the central one), with per-tile rotation and color derived from the hash.
  • GitHub-style — a 5x5 grid with binary on/off tiles and mirror symmetry, similar to GitHub's default avatars.

identicons

identicons

Setup

The library is distributed via JitPack. Min SDK is 21.

In your settings.gradle.kts, add the JitPack repository:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven("https://jitpack.io")
    }
}

In your module's build.gradle.kts:

implementation("com.github.lelloman:android-identicons:v12")

Usage

Jetpack Compose

import com.lelloman.identicon.compose.ClassicIdenticon
import com.lelloman.identicon.compose.GithubIdenticon

// hash is a ByteArray (e.g. from MD5, SHA, or any byte source)
ClassicIdenticon(
    hash = myHash,
    modifier = Modifier.size(96.dp)
)

GithubIdenticon(
    hash = myHash,
    modifier = Modifier.size(96.dp)
)

XML Views

<com.lelloman.identicon.view.ClassicIdenticonView
    android:layout_width="96dp"
    android:layout_height="96dp"
    app:hash="1867167182" />

<com.lelloman.identicon.view.GithubIdenticonView
    android:layout_width="96dp"
    android:layout_height="96dp"
    app:hash="654984321" />

The hash XML attribute accepts an integer, which is internally converted to a ByteArray via MD5. You can also set the hash programmatically:

identiconView.hash = myByteArrayHash

Drawables

For custom rendering you can use the drawable classes directly:

val drawable = ClassicIdenticonDrawable(width, height, hash)
drawable.draw(canvas)

How it works

The input ByteArray is interpreted bit by bit to determine tile shapes, rotations, inversion flags, and the foreground color. When an Int is used (e.g. from the XML attribute), it is first hashed with MD5 to produce a 16-byte array, expanding the visual space.


They can also make good textures for hum carpets, or tiles for the bathroom

carpet1 carpet2 carpet3