Sunday 27 February 2011

Android Developing: Magic life/poison counter

After years of having a fairly old mobile phone, I got a new one last week; HTC Desire Z. It has a keyboard which is handy (I've tried using the touch screen keyboard too, I prefer the physical one), and is defiantly a step up from the second-hand-off-my-cousin phone I previously had. 


I've spent a minimal amount of time looking over some of the applications on the android marketplace, I looked over some Magic: The Gathering life keeping apps, and eventually found one that was free, and didn't have ads (which apparently a lot of free apps do have): Life Counter. I was extra impressed as it was an open source app, so installed it and used it against a game or so with Liz, and it was quite handy, a low number of features, but all that was needed to help me keep the score. 


Well, almost everything...

...one of the features it was missing was a way to keep track of someone's poison counter total (particularly important with infect in the current block). I had started off by just setting my life total to 0 when playing against Liz playing infect, which seemed to do, but it would be a useful feature to have the ability to have both.  


As luck would have it, the handy app I was using was open source (GPL), so I went along and downloaded the source code to have a look. I'd not done any android development before, but knew that it was done either in Java or a Java type language, which is what I am most fluent in. With no idea of whether I would be able to actually understand anything well enough to do anything useful, I downloaded the various required bits (android software development kit) and had a look. 


I started off looking over the code base first, and tried making a few changes to see if what I wanted could be done. I got the emulator working to try out some changes, but it didn't seem to be working very well, so started again from the original code, with a couple of nuggets of experience to start again. This time I went about duplicating a few classes instead (there were a few for life tracking and layout, I duplicated them for poison tracking and layout). Made some changes, and had a look into an extra folder that had a load of xml files in it, which looked like they were determining the layout of various components, so added some of the new poison related classes to it. After a little bit of trial and error (I probably should have read more about how it all works before starting, but think its more constructive and informative to learn by doing as opposed to reading), I had an extra column added for poison tracking, success! 


Some fixing of problems later, and I had an extra poison column for each player (the application supports 1 to 4 players). I was having a little bit of trouble linking in memory the two columns, which meant I wouldn't be able to get the player name and gradient information, but as I was doubling the number of columns, I wouldn't be adding the name anyway. Also, I thought it would look a bit strange to have two identical columns for one player, so set each poison column to be the same colour (and changed the rounding of the corners, just for a little bit more differentiation). 


A little bit of testing (and fixing after various problems) later, I made the buttons a little smaller; as there was more on the screen, they were taking over the life history, so made them fractionally smaller to combat this. I also added some 'ichor' to the Life Counter icon (mainly so I would be able to tell my development app from the original one). I renamed the application too for the same reason. 


And so, the Life & Poison Counter app was completed. 




By Saturday evening, I had gotten the extra features I wanted, and it all seemed to be working fine. Had a bit of trouble getting it onto my phone to test it there, but left that for the morning. Today (Sunday), I was mainly messing around with installing and reinstalling a synch program for the phone. Then I think it was having trouble because I had renamed it in some places, but not everywhere, so looked and fully renamed things, checked it was working on the emulator again, and uploaded it, and it worked this time. I tested it on the phone and was happy, so looking into uploading the source changes somewhere. 


I went back to the original repository (github) to fork the original project and upload my changes, but had problems get git to work properly with eclipse (what I was using to develop the software), so went over to sourceforge and created a new project there and managed to upload all the files with little problem. 


I had a look into actually uploading the application onto the Android Marketplace, but a developers fee was required first (only $25, which is £15, so I might do another day), so decided to leave it for now (the file required to install the application manually is available on the sourceforge site). 


The source code for the app is available on the sourceforge page. The apk file to install (and a zip file of the project) is also available on this sourceforge page


In summary, it was a fairly fun weekend, I think I learn a little bit about the android development, enough to extend some functionality on an existing app anyway, but we all start somewhere ;)


Oh, the additions to the app add on extra columns so it looks like this:



No comments:

Post a Comment