Category: Apps

True Colours, or the quest of comparing two colors


I’ve started a few months ago to work on an application called Eternal Minis. It’s a social network where warmongers can share their painted miniatures. If you don’t understand what I’m talking about, check out Wikipedia.

Anyway, the app allows users to add paints they’ve used to a posted minis. It’s a very interesting information if you want to learn how someone has painted a specific color effect. However, it can be a bit tedious to add all the colors you’ve used, especially when there are dozens of them! My idea was to help the user by suggesting the first color. Maybe it’d help him start, and he’ll keep adding other paints after that.


Color distance

My first idea was to vectorize the RGB components of a color picked on the photo (using Palette), and then make a distance calculation between this color and the predefined paints included in the app. Even if it may sound like a good idea, a short distance between RGB components might not be really relevant.

So I started to search for some actual color comparison algorithms. What I found is that you can calculate an Euclidian distance between two colors, from actually any format. So you can do the following with RGB components.

An Euclidian formula with 3 dimensions, courtesy of Wikipedia
An Euclidian formula with 3 dimensions, courtesy of Wikipedia


However, RGB components, even if they’re great for computers, may not be very relevant for how humans perceive colors. Actually, if you take a look at the Wikipedia article on Color difference, you can read about the work of International Commission on Illumination (CIE). the CIE76 formula for color distance looks like this:

Looks familiar, right?
Looks familiar, right?

You’ll notice that the color components are called L, a and b. It’s because the CIE colors are defined with the Lab color space, which is trying to approximate how humans perceive colors.

So we can easily convert RGB colors to the Lab space, and then use the Euclidian distance to find a relevant color from a mini picture!


Make the robots working!

As an Android developer, the good news is: Google has already made all the heavy stuff. The ColorUtils class has a method RGBToLAB (which returns an array with Lab components), and a distanceEuclidian method has well.

So, all you have to do is to pick a color using Palette, and make the comparison with ColorUtils.

What I actually do in Eternal Minis is loop over all vibrant colors in all swatches, and then keep the color with the lowest distance to any paint color included in the app. Then I suggest the user to add the found paint. And here’s the result:

Final result
The final result


So what’s next?

The approximation works fairly well, but there are a lot of things to consider outside the color comparison. Photos are often taken with a white or black background, so you don’t want to suggest this color to your user for example. So there is still a lot of work to ease the life of painters!

Google I/O: I was here

Even if I haven’t posted about it (except if you follow me on Twitter), I was at Google I/O this year, thanks to my company. And it was awesome, as you can expect. I’ve met a lot of people, see some great conferences, and I’ve came back with tons of new ideas.

I’m especially pleased with their work on Firebase (except for this annoying push notification bug). And I really want to try Google Home (who wouldn’t?).

Here is the top 5 of the conferences I’ve seen. Enjoy!

You also have to see this one. It’s not your usual I/O conference. You’ll thank me 🙂

How Realm has reconciliated me with mobile databases

Realms of Chaos

I’ve been developing Android apps for few years now, and even if I’m a huge fan of what the platform offers to developers, one thing has always bothered me: Databases.

I come from the web world, where you have very powerful ORMs (like Hibernate, Entity Framework…). And when you arrive to Android, what you have is… SQLite. Hard to use, painful to work with… It’s such a mess that I’ve avoided it as much as possible. Then came ORMs for Android, like ORMLite, GreenDAO, ActiveAndroid…

I had the occasion to work with most of them, and even if some are better than others, globally, they’re really, really not efficient enough. At least in my opinion. Models generation, data migrations, APIs… Most of these things are hard to work with when it comes to Android ORMs.

Here comes Realm

Then came Realm. A promising database with a nice APIs and a SQLite-like performance (or even better). It’s actually a whole new DBMS, written in C++, and available on iOS (Swif/Objective C) and Android. Besides being really fast, Realm offers an API so nice it reminds me my good old Entity Framework.

They present their product better than me, so go visit heir website:

It’s pretty easy to setup, and you can start making your entities in a minute. And if you doubt about speed, know that not so long ago, your data manipulation and reading had to be done on the same thread. But from what I’ve experienced, it had no major performance impact (and Joaquim Verges, creator of Falcon Pro, has the same conclusion: Don’t worry, if you still want to read data in a background thread and display them in the UI thread (which is probably a good idea, or an absolute requirement, depending on how you see things), Realm is now offering async methods for data manipulation!

Why is it so great?

Even if Realm has been around for several years, I haven’t tried it until recently (even if I was keeping an eye on it). After all, the Android version hasn’t reached the 1.0 version!

I’ve started to use it on Condor, a Twitter client app I’ve made last summer, and to be honest, I was impressed. Since then, I’ve used it on Astonishing Comic Reader, powering some very, very huge collections of books, without any problem. And I’m basically planning to add it to use it in all my future projects.

So it’s just the most perfect library in the world?
Actually not. It has some flaws. After all, it’s still in beta.
The brand new async methods seems not that stable, at least for now ( One of my colleagues had a severe bug which stucked him for a day or so). Some parts are also a bit tedious to use, like the Realm migration API. It’s changed recently, and it’s much better, but I feel like there’s still room for improvement. But anyway, I still consider it’s one of the best libraries you can find on Android.

What are you waiting for?

Seriously, go try it. Copy/paste the Gradle dependency line, and start to play with those RealmObject. I’m sure you’ll be quickly convinced!

From Nice To Astonishing

I was in Paris two weeks ago for the 2015 edition of the Droidcon Paris. As usual, I’ve met great people and assisted to some very nice conferences.

I also had the opportunity to present a new talk, focused on app design. Mainly inspired by the great book About Face by Alan Cooper, it’s full of advices about how to make your app even better.

Slides are available on Slideshare, so enjoy, and make your apps astonishing!

Building the astonishing: useful Android libraries for developers

When you’re developing an Android app, you can of course build everything from scratch, or use some of the thousands available open-source libraries. It’ll save you a lot of time, and often let you use complex UI animations, components, or algorithms, which you wouldn’t be able to code from scratch (or not without a lot of time). I even know some people who’d like to use nothing but libraries to build their app.

Since I’ve used a lot of libraries for Astonishing Comic Reader, I’ve decided to write this article, and talk about some of the most useful ones.


Support libraries

First of all, I’d like to quickly talk about support libraries. There are a lot of them out there, and even if new releases often come with bugs (especially Appcompat, or the brand new design support library), you have to use (some of) them. Even if you don’t require an API level 4 support, the support v4 library contains very useful stuff like fragments or retro-compatible animations. Just take a look at the revisions list.



Android annotations

Android annotations (AA) is one of my favorite Android libraries since I’ve started to develop on this platform. It simplifies your code by generating a lot of boilerplate code, like views injection, background threads, intents building, custom views, preferences, Rest API calls… Well, it does it almost all. Just take a look at the official cookbook, you’ll see what I mean.

AA actually generates subclasses from annotations, where all the code you don’t want to write is. For example, if you want to use AA on a specific activity class called MyActivity, you’re using annotations like @EActivity (to declare that your class will use AA annotations) and @ViewById (to avoid the boring findViewById). At compilation, a class called MyActivity_ (notice the “_” symbol) is generated. This is this class that you’ll declare in your manifest, and use to build intents.

AA really makes your life easier, on a lot of things. Maybe too much things, and that’s one of its flaws. It quickly creates a very strong dependency between your code and the library, and removing it might be a pain. But if you want to replace all these features with other libraries, you can start with things like Dagger and Butterknife.

The other major flaw is that it creates a lot of new subclasses (actually, one per annotated classes). Then, it almost doubles the number of methods in your code, which might dramatically lead you to the unpopular multidex error. Keep it in mind if you want to use it.


Square one

Square is an American company specialized in mobile payments. But their talented developers have developed some of the most popular Android libraries, including Otto, Dagger, Retrofit, Picasso… I’ll talk about some of them here, but you can check the complete list here.



Otto is an event bus library. Basically, it allows you to send messages across the different components of your application. And trust me, that’s sometimes very, very useful. You can for example send objects from a fragment to another or notify an activity from a custom view. It’s not a must-have in all your projects, and you should be careful about overusing it.

In ACR, I use Otto to synchronize the zoom level between the pager’s page, or to notify the view that suggestions have been loaded. You can also use it to send events about network operations, or database data retrieving.

There is a very good alternative to Otto called EventBus. I’m not very fond of it, but it has some very convenient features, like managing events trough inheritance, which Otto doesn’t.



Retrofit is a REST client library for Android which clearly eases your work with web services.

The only things you have to do is to declare an interface, containing all your API endpoints (annotated with things like @GET or @Query), and use this interface to declare a RestAdapter and a service class, which is basically your interface implementation.

What I like with Retrofit is that it’s very, very easy to use, and it’ll clearly change your life. It allows you to simply declare your endpoints, or customize them with annotations. It automatically parses you results using Gson, but you can use a custom converter if you want (XML parser for example). Easy setup, great default behaviour, and advanced customization if needed. What else?



I’ll probably write another article about image libraries, since image processing is at the core of ACR, but I got to talk about Picasso. Yes, it’s another library by Square, designed to ease image downloading and manipulation. The goal is to let developers easily display images from the Internet, and automatically handle things like cache, network failures, placeholders etc.

I’ve seen on a Google + poll that a lot of developers don’t use any library to manage images. If you don’t, do it. Right now.  Even if you’ve your own library for that. If you don’t want Picasso, you can pick something like Universal Image Loader, Glide or even Fresco. Each of these libraries have been developed, tested and improved by thousands of fellow developers. And they clearly ease your life!


JSON processing

JSON processing is nowadays a very easy task in most cases. You probably all know Gson, the Google library to parse JSON. There are alternatives like Jackson, or the new player in town: Moshi (also by Square).


Finding new libraries

Finding new Android libraries is easy: just use Google. But if you want to do it the right way, there are a lot of websites out there which are referencing new libraries each day. My favorite one is Android arsenal, but you can also visit AndroidLibs or directly test libraries on your mobile with Libraries for developers.