Category: Android

Anonypic and Microphone source drop

Posted by – 2011/01/03

Since I’ve not updated these two Android projects in a while, at risk of total future embarrassment (I’m still a Java newbie) I’ve decided to dump the source code on GitHub so others can make use of it. Details are on the Anonypic and Microphone project pages.

If you fix any bugs, please send a pull request and I’ll do my best to merge them in, but keep in mind this is also my first attempt at using git; expect schoolboy errors there too!

Rainwatch featured on Android Market

Posted by – 2010/09/09

Sometime yesterday my app Rainwatch was added to the “top free” list on the Android Marketplace, showing in 5th position in the News and Weather section. This is strange because it’s only 32nd in the “top free” list on the market on Android devices, but hey, I’m not complaining!

I guess I’d better make a promotional image for Market and update the screenshots so they actually look like recent versions of the app!

Float.parseFloat is slow

Posted by – 2010/08/27

While profiling some loader code and expecting to see performance issues with my regular expressions, I found that ~60% of my time was actually spent converting String variables to floats. It turns out that the slow bit lives inside Float.parseFloat, where it calls String.toLowerCase every single time just in case this string is a hex float, a very rare type of float which I had never seen before. I logged this with Apache, but as I can’t ship a custom ROM with my SVG parser I decided to replace it.
Here’s the results from some tests of 3896 calls to parseFloat on my Nexus One:

  • a) Using Float.parseFloat(String): 1516.449ms
  • b) My own parseFloat(String): 654.882ms
  • c) …and my own isDigit(char): 449.622
  • d) …and isDigit written inline: 295.865ms
  • e) …copying the string into a char buffer and avoiding all string access and method calls: 254.527ms (112ms spent copying the characters!)

So in theory, if the method took a character buffer and length it could be as short as 135ms, over ten times faster than Float.parseFloat. I’m currently using option d as gives a nice performance gain without breaking my design, but when performance tuning the entire API later this may see some huge changes. Here’s the function I cooked up:

public static float parseFloat(String f) {
	final int len   = f.length();
	float     ret   = 0f;         // return value
	int       pos   = 0;          // read pointer position
	int       part  = 0;          // the current part (int, float and sci parts of the number)
	boolean   neg   = false;      // true if part is a negative number
	// find start
	while (pos < len && (f.charAt(pos) < '0' || f.charAt(pos) > '9') && f.charAt(pos) != '-' && f.charAt(pos) != '.')
	// sign
	if (f.charAt(pos) == '-') { 
		neg = true; 
	// integer part
	while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0'))
		part = part*10 + (f.charAt(pos++) - '0');
	ret = neg ? (float)(part*-1) : (float)part;
	// float part
	if (pos < len && f.charAt(pos) == '.') {
		int mul = 1;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos) - '0'); 
			mul*=10; pos++;
		ret = neg ? ret - (float)part / (float)mul : ret + (float)part / (float)mul;
	// scientific part
	if (pos < len && (f.charAt(pos) == 'e' || f.charAt(pos) == 'E')) {
		neg = (f.charAt(pos) == '-'); pos++;
		part = 0;
		while (pos < len && !(f.charAt(pos) > '9' || f.charAt(pos) < '0')) {
			part = part*10 + (f.charAt(pos++) - '0'); 
		if (neg)
			ret = ret / (float)Math.pow(10, part);
			ret = ret * (float)Math.pow(10, part);
	return ret;

This is of course a very crude method, it requires a well-formed number and will return 0 or partial numbers instead of raising exceptions, it doesn’t work with hex floats or parse NaNs or Infinity and it doesn’t use doubles internally so the accuracy is not perfect. It does however work for my purposes, so I thought I’d share it with the Internet.

Microphone for Android

Posted by – 2010/08/22

So, my 4th Android app is out, a simple mic which you can plug into your computer. It’s got quite a slating on the Android Market because of its latency, the problem is that there’s quite large minimum values on the buffer size for accessing input and output buffers, there’s no way to reduce this latency below the ~300ms which it currently has. Hopefully AOSP will address this eventually, paving way for realtime audio applications.

Adventures in Android

Posted by – 2010/08/17

Since getting myself a Google Nexus One I’ve decided to do a bit of Android development. My first impressions with the platform weren’t really that good, but I’m beginning to get the hang of it now.

My main problem is that Java is a horribly verbose and restrictive language. To do the simplest things you need to implement at least three interfaces and extend a couple of abstract classes (after reading the documentation for each of them and their alternatives of course). Something which could be written in Python in three lines of code and two minutes takes fifty lines and twenty minutes in Java. Perhaps that’s just me, maybe I’ve been spoiled by dynamic languages and expect to be able to do things a hundred different ways by just typing whatever comes to mind, rather than carefully considering the available options and planning every step of my app. In my short journey through Java development I’ve suffered a lot of pain because I make assumptions and choose a design pattern which is incompatible some point later down the line, so I end up refactoring everything ten times before I even get a working prototype. I’m slowly learning not to fly by the seat of my pants (even if it is the most fun way to fly) and perhaps that’s a good thing.

My other gripe is the UI editor and XML format, their steep learning curve makes the design stage a huge time sink. I’ve now spent a fair bit of time banging my head off my keyboard while attempting to make the simplest of interface, which still don’t look like they do on paper, but I think I’m getting the hang of it.

Anyhow, so far I’ve managed to knock out 3 applications which are available in the Android marketplace:


This little app just adds an extra option to your share menu, and will upload an image to, the anonymous image sharing service by the creators of The Pirate Bay. Images have their EXIF data removed, so you can share images without leaving a trail of metadata leading back to your phone.


Rainwatch is an alternative viewer for the BBC’s Maps Presenter, the Flash application available on their weather site. It’s far from complete but is good enough to predict the weather, so I’m quite happy with it (as are my 1500 active users)

MC Mail

MC Mail, or Missed Call Mailer is a little app which sends you an email when you get a missed call. The back-end is written in PHP and MySQL, the front-end is mostly just a service which monitors your call log. Useful if you’re a hospital or call centre worker who has access to email but can’t use a phone in work, or if you always forget your phone. It usually only works while the phone is in silent mode.

Next steps?

I’ll make a couple more apps and maybe a game, then learn the Native Development Kit and port Irrlicht using Christian’s OpenGL ES driver. I haven’t done any Irrlicht code in ages, so that’s certainly on the agenda.