Share

engineering

5min read

Implementing Material Design Outside of Android Lollipop

Implementing Material Design Outside of Android Lollipop

What is Android Material Design?

Material Design (MD) is the new design language for Android Lollipop and Android M. It focuses on bold colors, typography and animations. It keeps layouts clean, simple and consistent. It replicates real world’s things like ink and paper, so users intuitively know how to interact with applications. Shadows, touch feedback and animations are used to show relations between objects, widgets and screens. Well, maybe Material Design is not really new – but the thing is, only 12% of Android phones have Lollipop installed.

Android Material Design is just a concept, so there’s no exact implementation ready for use. Android 5.0 adds a good number of useful APIs, but none of them are available for older devices which makes using MD really difficult. When making a new Android app, we aim at having as many users as possible. More than 80% of total users is a satisfying number, but it means that we have to support Android 4.1. Covering 95% of users would include Android 2.3 as well, which is really old and won’t work well with MD concepts! When facing that problem in our project for GigTown we came up with our own solution. Keep reading to find out more.

Modern UI

We started with workflows, artworks and a working iOS app. GigTown’s UI is prepared in a modern way. There’s a vibrant orange primary color used across the app. All Android Material Design icons have basic shapes and use only one color. Surfaces are flat and simple.

GigTown's UI

As for Android, we decided to make the UI compliant with Material Design guidelines. We had to add shadows and ripples, add an accent color, remove iOS search bars and select primary actions for floating action buttons. We also had to prepare several custom widgets, unique for our project, like a ribbon, a collapsible header or a player notification.

Implementation

When we started working on the GigTown app, the Design Support Library was nowhere in sight yet. When it was released, we quickly realized that the key material features, like shadows, rounded corners, ripples, and vector graphics, were missing. We wanted to have animations and new components as well. To decide what we want to do with this further, I referred to the project I was working on in the meantime - a Material Design implementation for older devices called Carbon. I had only an old Galaxy S phone with Gingerbread on board. It was nowhere close to MD, but I really liked the new look and wanted it badly on my phone. It was also really good feeling to push the limits and prove that it’s possible. We decided to go with third party libraries and a bit of custom UI based on Carbon.

Vector graphics

While working on GigTown, we faced many challenges related to UI. We had to figure out how to prepare icons for all densities and states while doing as little as possible. We had all icons in Adobe Illustrator format, so the easiest way was to export them as PNGs. But come on, we’re in the 21st century, nobody wants to make a living from exporting icons! Android Lollipop offers SVG rendering, why wouldn’t we do that on Ice Cream Sandwich?

GigTown logo

Using AndroidSVG we were able to load SVGs and render to bitmaps from Android code. Then we could use that bitmaps with simple ImageViews. Such approach fits nicely into the existing drawing pipeline, hardware acceleration works with existing components and gives pixel-perfect results for a very little cost. The code itself is simple:

try {
	svg = SVG.getFromResource(getContext(), svgId);	// load
} catch (SVGParseException e) {
	// handle the exception
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
svg.setDocumentWidth(width);
svg.setDocumentHeight(height);
svg.renderToCanvas(canvas);	// render
setImageBitmap(bitmap);

All SVGs were white so we could easily create pressed and disabled states using color filters.

Shadows and outlines

The theory behind drawing Material shadows is straightforward. All views are flat and simple, so it’s possible to approximate shadows with blurred, black shapes. Here are the steps: Draw a view to a bitmap. Use a filter to make it black. Blur that bitmap. You can use ScriptIntrisincBlur. Draw the blurred bitmap on the screen. Draw the view. Pretty easy, huh? The only problem with such algorithm is that you would have to override all views and layouts. There’s no way of doing that in a generic way. From the other hand all Android widgets are precompiled and held on each device. That’s why Google doesn’t have any way to replace them on older systems.

Toolbar view

Carbon overrides most components, so we could reuse them as base classes for our views. The only inconvenience was that we had to explicitly specify each namespace in each layout.

Ripple touch feedback

The Material touch feedback on Lollipop is implemented as a Drawable, which makes a lot of sense. It’s a very simple animation of a growing circle. Unfortunately RippleDrawable makes use of the new drawing thread, which is available only on Lollipop and M. It’s neccessary to reach the desired level of animation smoothnes in parallel to heavy computations. There’s no way to overcome that.

Transitions

Durning GigTown development we prototyped a lot. Some ideas went great, while others were very hard to implement. One of them was the transition animation. If there’s a thing common to two screens and there’s a connection between them, it should be shown by a transition. Even though the idea seems to be simple, the implementation is difficult due to the following: Activities don’t share information about layouts, so translating views from point A to point B becomes very complex. Activity lifecycle forces us to move the animation to the second Activity’s running state. Activities need time to create themselves, so transitions freeze for a noticable amount of time. After two weeks of trying we decided to drop transitions due to implementation difficulties and performance issues. Not all material features can be backported and that was a very important lesson to learn for us.

Conclusion

Material Design can be used for really old Android versions as long as the device is powerful enough to run it and the application is well prepared. A few things work well only on Lollipop due to specific, system-level features, but can be run with small changes on older versions as well. In addition, with Material Design, designers can easily cooperate with programmers, as changing themes is as easy as changing the app’s leading color. Using AndroidSVG, Carbon, Picasso and Google assets we were able to make GigTown’s UI really cool.

Resources

You can find all UI-related libraries and resources we used under the following links:

Carbon Material Design implementation for all Android versions back to Froyo. Offers animated shadows, ripples, lots of widgets, and more.

AndroidSVG Easy SVG loading and rendering for android with support for SVG 1.1 and 1.2 Tiny specifications.

Picasso Very simple, yet powerful image loading library by Square.

Material Design Icons Repository with all official material icons in vector and bitmap formats.

Share

Marcin

Senior Software Engineer

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!

Did you enjoy the read?

If you have any questions, don’t hesitate to ask!