Facebook's device year class

Some folks like to call it fragmentation, others call it choice, but by any name there are certainly a lot of different Android phones. Building applications that need to work with all of them is no easy task. You have wildly different hardware configurations that make for a big difference in performance, and even though one apk file can work on every one of them, there's still the issue of needing an app to run smoothly on low-end devices without sacrificing features on high-end devices. When you're talking about an app as popular as Facebook, this can quickly become a nightmare for the folks doing the coding.

Facebook showed everyone at the Big Android Meat and Greet a new solution that's simple — the Device Year Class component.

Facebook's developers describe this new software component like this:

Device Year Class is an Android library that implements a simple algorithm that maps a device's RAM, CPU cores, and clock speed to the year where those combination of specs were considered high end. This allows a developer to easily modify application behavior based on the capabilities of the phone's hardware.

The library doesn't alter any behavior in the application. It returns a value (expressed as a year) that's stored in the code for times when a developer needs to change the way an app works to tailor the experience to a particular type of hardware. This means a dev can write an app with fancy animations and transitions that will play as intended when running on something like a Galaxy Note 4, but not use the eye-candy when the app is running on something like a Moto E. As you can imagine, this sort of control on an app like Facebook — which is installed on millions and millions of different phones — can and will make for a better experience for just about everyone. And it's easy to implement. From the documentation on GitHub:

if (year >= 2013) {
    // Do advanced animation
} else if (year > 2010) {
    // Do simple animation
} else {
    // Phone too slow, don't do any animations

Best of all, the library is open-sourced under the BSD software license (the same license Google uses for the Android source) and is available for every developer to use free of charge.

We know this isn't magic, and it's likely that most developers working on big projects have some sort of method to handle different hardware configurations. What the device year class does is provide a simple and "elegant" solution to a big problem, and anyone can use it.

Device Year Class' GitHub page