Monday, July 12, 2010

Android SharedPreference Read-Once Gotcha

I use SharedPreferences in a horrible way.  I use it to store application data. It's much easier to use a key/value store than a SQLite DB or writing to a file.  

Because SharedPreferences are stored in the /data/data directory they can't be reached without root for saving.  To fix this I store a copy of the file on the /sdcard.  On start up I copy the "public" version over the /data/data private file.  (This has the side effect of allowing modification of the data and reloading by editing the file when attached to a computer)

The problem is that when you call getSharedPreferences you always get the same instance back. It doesn't reload the file.  This was an issue for me because I was using that to create the /data/data file if it didn't exist, copy the /sdcard file over and then tried to reload by calling it again.  

To fix the problem I had to check if the /data/data file existed during the copy operation and create through java.io.File methods first, then copy, then call getSharedPreferences.

Sunday, July 11, 2010

Drop And Give Me Twenty! v2.0

Just pushed version 2.0 to the market!  Added a lot of user requested features:

  • Reset
  • Manually change your level and day/week
  • Manual entry (It's more of a stopwatch mode)
  • Sound on/off
  • Minor updates to the Progress chart to make it more flexable
I don't know which is more nerve wracking, the update because I can destroy data now or the initial release due to the unknown.

Tuesday, June 15, 2010

First Android app published!

Last night I finished up version 1.0 of my 100 pushup app for Android and published it to the market. You can search for DGMT to install.
I hope to add a few more things to finish up. I want to add a proximity counter for those who don't want to touch the screen with their nose.  An editor for the exercises. Better graphing through custom coding instead of using a library. And in the far future uploading data to a web app for generating custom workouts for your skill level based on others like you.
(Use Barcode Scanner on this QR code for a direct link to my app in the market.)

Tuesday, November 24, 2009

Android Prototyping Templates

I couldn't find much in the way of Android prototyping tools on the internet so I decided to create one of my own.

This is for hand sketching ideas out. When printed on 8.5x11 it comes out almost the exact size of the G1 screen.

Wednesday, March 4, 2009

Why I love my MacBook

One of the most under publicized features of the Intel (maybe older?) MacBooks and MacBook Pros is the multi-touch trackpad. First off it has a much larger area than any PC laptop I've had which makes for less drag-lift-move-drag motions. Second the acceleration and resolution are perfect out of the box. Third double tap right click and double finger scrolling ANYWHERE on the pad makes things so much better.

How much better? I like the trackpad so much that reaching over to use the attached mouse is a hassle. I thought I'd never say anything like that. As far as other trackpads are concerned, I'd rather spend a half hour getting a mouse even for 5 minutes of use. They're just that bad.

Its just another example of Apple's attention to details that makes them a much better experience.

Monday, December 29, 2008

T-Mobile's Android root runs shallow

T-Mobile's only Android device, the G1, isn't as open as you would think. The device lacks root access and the bootloader requires a signed image. Older versions of the OS have had a successful jailbreak but the most recent (R30) over the air firmware upload "fixed" that.

I jumped on the G1 bandwagon the day after it was announced hoping that it would live up to the openness Android was claiming. To be fair, the SDK does allow access to quite a bit more than the iPhone's SDK does which makes for some interesting applications not do able on the iPhone (for now). But the Google/T-Mobile team has stopped a bit short when it comes to moving from one Android device to another. There's no desktop client nor is there a backup/restore client! Think about that for a moment. When the time comes that you have the option to move to another Android device or, as in my case, have to replace your current one you're out of luck.

I searched the internet and even posted in a few google read forums (groups.google.com/groups/android-developers, forums.t-mobile.com) about how to move from one to the other. I read about the jailbreaking < R30 and the R30 hacked image if you already were jailbroken. I was told that it's T-Mobile's fault and to stop complaining. I was even told by one person that they clear their phone all the time for app testing and it only takes about 10-15 minutes and isn't a big deal. That person obviously isn't really using their phone.

T-Mobile customer support isn't much better either. They say you just have to download the applications again from the market and accept the data loss or they'll tell you about the jailbreak and how R30 shut it down and it's "impossible" to hack this new version. When you try to tell them that you want T-Mobile to provide root access or unlock the boot loader they tell you that Google writes the code and HTC makes the phone. They have nothing to do with it. This is a lack of understanding on the support staff's part. Google writes the base code, but it's modified for T-Mobile and only runs as a signed image.

Basically it seems that what's happening is that Google released some software prematurely as usual with their code but this is a very different case than the web were only the Google devoted will pick up the software before it's ready for prime time. T-Mobile pushed out the G1 as a iPhone replacement when it is not because of the build quality, the hardware itself and the premature OS. Now that they actually have real users with real problems that should have been caught long before in acceptance testing, they just want to ignore them. And they'll be able to because most people using the G1 won't know any better. There's always the Google apologists (and in some cases the Android devs themselves) that will say it's not their problem. There's no way to actually get in contact with someone who actually knows something about this level of detail about the G1 at T-Mobile. And finally, we already paid and signed a contract and are well past the 14 day return period. So the only way out is to pay more money to T-Mobile.

For anyone out there looking to develop on Android and the G1, PLEASE, PLEASE just spend the extra money on the Google Dev Phone 1 (http://code.google.com/android/dev-devices.html).

  • No Contract

  • No $18/$36 upgrade/activation fee (which is a whole different kind of BS)

  • Full Control of your phone. Add new images. Root access.

To me this is what the G1 should have been. This is what Android was to represent.

Sunday, October 12, 2008

Firebug Console for power users == REPL

There have been many, many posts through out the internet explaining why Firebug is the greatest thing ever for the web developer from the CSS editor to the AJAX transmission viewer to the javascript debugger. I'm going to throw one more thing in; javascript REPL.


REPL stands for Read, Evaluate, Print, Loop for those that don't know and basically means it's an interactive shell into your program. Most of us know about the console in Firebug but how many know about the power it gives? When you open Firebug the console tab is selected by default. You may know this as the place those console.log() messages go. At the bottom is a blank line denoted by ">>>", this is the interactive part. You can execute a line of javascript here. If you click the circle with the up arrow on the right you open the multiline console. I recommend this as the way to go. You can write multiple lines, such as functions, and execute with ctrl-enter or command-enter.


Anyway, back to that REPL. The console lets you interact with any loaded javascript on the page. You can change global variables, call functions, pretty much anything javascripty. This is where the power comes in. You can define functions meaning you can redefine functions! And it'll work when some element or function on the page calls it.


Imagine for a moment that your trying to create a new function or debug a function on your production server where you have to interact with the real data. You can't just change the code, check it in, build and deploy each time due to various issues like time and the client noticing the site going up and down. What you can do, and what I had to do recently, is open the console, paste in the fixes to the definition of the function, evaluate it, and then go about interacting with the page. It becomes a much faster solution that has a couple of benefits.

  1. No redeploy until you know it works
  2. Don't have to worry about anyone else getting in there and using your code while you're testing it out
  3. Interaction with the real problem, with the real data causing it.


If you go about writing your javascript code with the console in mind there are some great uses for it.

  • Have your logging statements controlled by a global variable. On the page it's false and not printing. When you need to see what's going on in Production or some other uncontrolled by you environment, just change that variable to true and you get your logging.
  • Fire functions and events while developing so you don't have to keep reloading the page and waiting for template recompiles. I like to use this when writing something with AJAX calls while working on the backend. I create a refresh() method ,that is the initial loader on the page anyway, and call it from the console.
  • Last, but not least, a personal favorite, testing out javascript expressions. We all have been there where you can't remember exactly how substring() works and you'd just like to try on the page instead of googling it and then interpreting what you find to fit your scenario. I use this all the time for things like figuring out a complex Prototype.js expression on the page to see how it works and tweet it before putting it on the page for real and going through the refresh cycle. In fact I'd go as far to say it'd be very, very hard to do without and I'm starting to wish for one in Java (aside from things like groovysh and jirb)

I hope this opens up some options and makes life easier for you developers out there. At least when working in Firefox. Firebug does have the downside of making you feel that much more helpless when you have some stupid IE bug.