Pages

Thursday, January 17, 2013

When In Doubt, Find A Library.

So libraries are pretty important while doing Android development, and finding good libraries can make your life easier and your development go smoother. There are tons of libraries available now that Android has taken off, so this post will outline a few of the libraries used by myself, and other developers at WillowTree.

Basic Stuff You Should Already Be Using

  • ActionBarSherlock: There's no reason why, with Gingerbread still sucking up almost half of the android devices in the market, you shouldn't use ActionBarSherlock. As the name suggests, it's a library that brings the native Action Bar (which you should be using in most of your apps, since it's pretty central to the new design language of Android) down to 2.x. The best part? It's API is similar to the native Action Bar, so when that magic day comes that we can actual set minSDK to 4.0 and not miss half the market, it'll be easy to get rid of it. Also, it's cake to drop in if you use Maven, since it's already on Maven Central. 
Example ActionBar Using ActionBarSherlock

  • NineOldAndroids: Similar to ActionBarSherlock, NOA is a library to bring some newer API functionality to older platforms. Specifically, animations. NOA brings the 3.0+ style animation framework down to the older versions (hence, nine old androids).  There are still some limitations (click targets and such not moving), but in all it works wonderfully. 
  • ViewPagerIndicator: So this is looking like a Jake Wharton fanclub post, but frankly, he makes outstanding libraries. ViewPagerIndicator is a library to provide a visual clue at to what and how many items are in a ViewPager. There are a few styles available, like tabs, titles, icons, and such, for those who are looking for a different look. It's also highly styleable, so you can make it look however your little heart desires. It's a library that is simple to use, and make it easier for users to know when they can scroll through a ViewPager, and what each page contains. 
ViewPagerIndicator can help your users know they can swipe left or right on a piece of content.

Making Your Life Easier

  • RoboGuice: There's a handful of "It should work like that out of the box" moments I've had, and starting to use RoboGuice in my projects was one of them. This library lets you inject stuff (views, objects, resources, etc) and does wonders on cleaning up your code. No more findViewById or fetching System Services by hand. Just @Inject (or @InjectView for views) them and be done with it. There's a lot that we use RoboGuice for and this is really just scraping the top to get the most obvious uses.
Some View Injection with RoboGuice

  • Gson: Working with Json is pretty much a given when building a mobile app, and behold! There are libraries to help you with that! Gson can work some magic on deserializing json feeds into objects, as well as serializing objects for persistence or even to pass between activities. It's easy to use and flexible, and makes life working with Json worlds easier. 
Gson Deserializing makes life that much easier

  • JodaTime: Working with date and time in Android can be a pain at times, and JodaTime takes some of that pain away. It's straightforward (.getYear().. getDayOfWeek(), can't get much more straightforward than that) and works well with Android. It's also well tested, and has been around since the silent film era (2002, practically the same thing). That said, there may even be some System methods that could be of use, if you didn't know about them...  
  • OAK Android Kit: Self-promotion time! Well, I guess not so much self, as WillowTree. We open sourced a library full of useful goodies that we tend to always need in-house. TextViewWithFont makes applying custom fonts to TextViews easier than it should be. CancelEditText makes it easy to make an EditText with built in clear buttons. There's a ViewPager with built for use in SlidingMenus. SectionListView, for having sections with floating headers in Lists. There's ImageViews with built in pinch/zoom, as well as a ViewPager for easily making a gallery for those ImageViews. There's some NFC helper classes, as well as easy to use HttpUrlConnection helper class that handles Http Response caching. Essentially, it has a lot of stuff that, while in the process of making app, WillowTree Apps has always needed. 
  • Crittercism: Crittercism is an analytics and crash reporting library. You have to sign up for their service, but it helps to stay on top of any crashes that may pop up, giving you a full stacktrace and diagnostics for easier troubleshooting. 
  • DragSortListView: ListViews that are draggable to sort or remove items. It's a feature that can be a pain to implement yourself. This library really makes it pretty easy. 
  • Crouton: Crouton is a library that brings more modern, context-specific Toast messaging. Toasts are nice and all, but can be confusing for users. Crouton fixes that and brings along a nicer look as well. 
Croutons in action

  • SlidingMenu: Sliding Menus. Some people like them, some don't. I happen to love them, because it puts navigation out of the way, to make room for more content, while still being easy to access. Regardless, it's become a fairly common design pattern on Android, so why not use a library that's well supported and easy to implement? Jfeinsteins SlidingMenu tends to be the version that the developers at WillowTree Apps use, but there are others, such as SimonVT's version. I've used both, and prefer SlidingMenu, but they're both really great.   
Verge's SlidingMenu


So there you have it. 

Some useful libraries to help make development a little easier. Libraries can mean the difference between pulling your hair out and enjoying making apps. If you have any other libraries you use all the time on Android, feel free to bring them up in the comments! Also, if you have any requests for tutorials or examples of stuff feel free to let me know, and I can cover it later.


Updates!: Seems like I missed the newer notifications is the new r11 support library, and Jake Whartons NotificationCompat2 is deprecated. I've removed it.