Archive for category: Android Snippets

Android Snippet: Draw layout to a Bitmap

29 Dec
December 29, 2012

I needed this code for a project, where I needed to capture a certain list item I was rendering into a Bitmap and upload it using Facebook’s SDK.

This snippet basically “screen captures” and draws a certain view and saves it as a Bitmap and is the right way to do this.

Another solution to this is trying to draw everything on Canvas* “manually”, but taking the time to figure out all the bounds and text sizes, and getting the exact positions of things on a canvas sound like a real inconvenience. This makes it the wrong way to do this.

And you’re done!

CardsUI View Library

23 Dec
December 23, 2012

Google’s Now popular Cards UI has everyone in the Android design community excited, including myself.
I developed this for a project I’m working on, and decided to make it abstract and upload it as a library.

You can download the example APK here, or just Clone the library from Bitbucket or from Github, including the example’s app source code and the library’s source code.

It took me a while to get the code together. The view might still be a little flaky from time to time, and the View’s code is NOT well documented, but the example really shows you how simple it is.

Feel welcome to modify any of the code, fork it and pull it.

Layout XML:

Activity Class:

Clone from Bitbucket

Download from GitHub

Android Snippet: Circle Image

20 Dec
December 20, 2012

A few months ago I was working on a project which required me to build a class that would download an image form the web, decode it, crop it, and show it in a circle – with a transparent background behind it, because it had to sit on top of different layout views.

I was only reminded of that seeing Romain Guy‘s blog post regarding images with rounded corners.

The end goal was to show the image just like an ImageView, only in a circle. This required me to extend a View and override the onDraw method to show it.

The circle part was tricky, so I thought I’d share that piece of code…