This library creates recognizable images of cute robots from hash values (or basically any other data). It is an adaption of Colin Davis' code at RoboHash.org.
Sometimes is necessary to create a personality for data in your applications. A good example is an avatar for a user that has no photo attached.
See the example project.
// ...
buildscript {
repositories {
jcenter()
}
// ...
}
// ...
dependencies {
compile(group: 'name.neuhalfen.projects.android', name: 'android-robohash', version: '1.0.4', ext: 'aar')
}
- Pass in the hash (or an uuid) of the data you want to 'personalize'.
- Get a stable handle.
- The handle is a 64bit long value suitable to store in a database.
- The handle derivation is pure, that means you always get the same handle(value) for the same input. There are no side effects either.
RoboHash robots = new RoboHash(getContext());
Handle immutableHandle = robots.calculateHandleFromUUID(uuid);
// Maybe persist the handle ...
- Pass in the handle to get the image. Images are currently 300x300 pixels.
// Advice: Keep a global (Application) instance of RoboHash to enable caching.
RoboHash robots = new RoboHash(getContext());
Handle loadedHandle = ...
Bitmap bitmap = robots.imageForHandle(handle);
- Enable caching of calculated robots (advised, when they are used in lists)
RoboHash robots = new RoboHash(getContext());
robots.useCache(mkCache());
// ...
private LruCache<String, Bitmap> mkCache() {
int maxMemory = (int) (Runtime.getRuntime.maxMemory / 1024);
// Use 1/8th of the available memory for this memory cache.
int cacheSize = maxMemory / 8;
LruCache<String, Bitmap> memoryCache = new LruCache<String, Bitmap>(cacheSize) {
public int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount() / 1024;
}
}
}
- Colin Davis -- Wrote the original RoboHash in python
- Set 1 artwork created by Zikri Kader
- Set 2 artwork created by Hrvoje Novakovic
- Set 3 artwork created by Julian Peter Arias
The RoboHash images are available under the CC-BY-3.0 license.
The source code is available under the MIT license.
Either build directly via gradle build
or use the provided Dockerfile + script.
Install the required android-sdk and build with gradle build
. See .travis.yml or the Dockerfile for android SDK dependencies.
You can use Docker or Docker Machine (e.g. on Mac OS) to build the library.
./build_in_docker.sh
takes care of everything.
- Creates an image called
neuhalje/build_robohash:1.0
- Mounts the local directory as
/root/robohash
- Builds everything
This is a reminder to myself:
# local.properties
bintray.user=<bintray user>
bintray.apikey=<bintray api key>
./gradlew bintrayUpload