Offset Null Entertainment, LLC Software and Graphic Design Solutions


Weekend Learning Android

Last weekend I decided to sit down and learn to program for Android. If you're familiar with C or C++ and object-oriented programming, Android development should be a breeze. I, however, knew nothing of any of these. Fortunately, Dan is an excellent teacher and, while I don't have much experience with "real" programming languages, I often write Perl and PHP at work so I have some very basic understanding of the concepts. Getting into the habit of using strict in Perl (a pragma that makes you delcare your variables in the scope you'll be using it) has been helpful because you have to declare EVERYTHING in Java (the primary language Android SDK uses).

I came across a couple issues installing the SDK and getting Eclipse running for Android, which I'll post later for those seeking help, but the process mildly time consuming and relatively painless.

Data is Porn

Visualizing data is one of my favorite past-times, so when Dan suggested we make a disk map utility app, I nearly soiled myself. Watching him create BlowTorch and seeing the app flourish and grow certainly sparked my interest in Android programming. The potential for a disk map utility on my phone, coupled with animator's block for another personal project, turned that spark into a raging inferno.

At the end of the weekend, I (with tremendous help from Dan) made an app to visualize disk usage on Android devices. Basically, it lays out all the files and folders in the area you scan and displays them based on file size. The larger a file is, the more room it takes up on the screen. Check out the screenshots below:

The first non-linear filesize display algorithm, showing folders only.

The single level recursive display working, showing files within folders and incrimenting colors.

Here files are displayed using an adjusted algorithm with infinite recursion and color coded by extension type.

At first, I arranged files and folders with a fixed width encompassing the entire screen. As I became more comfortable with Android, I began working on recursive algorithms which could display files within folders within folders withi... you get the picture. If you don't, check out the third screenshot above; it's a bit "Inception"-y. I also adjusted the algorithm so the app would prevent file blocks from becoming overly stretched where possible.

Threading for simultaneous work

The initial scan can take a while, especially if you have lots of files on your sd card like me, so I added a progress dialog. This dialog needed to update and display during the scan, so Dan showed me how to load the scanning process to another thread. Adding multiple threads so I can display a progress dialog while scanning my SD card was a lot easier than I thought it'd be; simply spawn a new thread and give it a method to run. Having threads communicate with eachother, on the other hand, is a little trickier. The key to working with threads, as Dan later explained, was writing a Handler class that could accept messages sent by new threads and react accordingly (eg, update the progress bar).

File Handling

Now that every file is displayed properly and I can navigate up and down through folders, I realize I have an Android File Explorer on my hands. In the spirit of BlowTorch's customize-everything-attitude, I figure I should add a customizable intent list so users can adjust file associations based on extension and launch documents in their appropriate apps. The real problem here is knowing what intents other apps use. I suppose I could always crowd source that aspect if users are interested in sharing their findings.

Final thoughts

Maybe it's just all the Long Island talking, but my crash course in Android development was a lot of fun. I'm pretty excited because after a little bit of coding, I now have an app that can visualize local and sdcard storage use and open various filetypes on my phone. There's still a lot I want to do with the app, including adding cooler navigation controls, pinch zooming, spinner directory navigation, user preferences, and maybe even a basic (less visual) file browser.

Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

No trackbacks yet.