Making My Own Android Clock AppWidget

So I am super OCD about the clock on my home screen. The Android lock screen is basically unchangeable outside of modifying your system files. Sure you can buy Widgetlocker or Lockbot off the market but I dislike the fact that all they really do is cover up your actual lock screen with another activity. I couldn’t say the actual battery drain this puts on my phone, but regardless I dislike it.

I actually like the default clock widget that appears on the lock screen. I think the font is good and the information it shows terse and clean. What I don’t like is how seemingly nobody on the android market has created a replica of this clock. I found one with the right font but no date. I found one with the same style but the size wasn’t right. I want a clock app widget that is identical, down to the pixel, to the lock screen default clock. The ideal behavior is for me to slide and unlock the phone, and for me to see no change other than the slider disappearing, the bottom icons to appear, and the screen brightens.

Android programming is annoying because so much stuff is confusing. Every thing has it’s own name (contexts, activites, intents, widgets, etc) and all the documentation is heavily saturated with this terminology. The problem is that reading the documentation is difficult, when you aren’t totally familiar with what each thing is. I honestly still don’t fully know what a context is. I also don’t understand why their memory management/garbage collection is so confusing. Apparently it is super easy to leak a context if you accidentally leave a reference to it somewhere in your background services. Every time you open and close applications and such, it destroys the old one and creates a new one from scratch. Thus, contrary to what I’ve learned the past 5 years of programming, it’s almost better to declare things temporarily and allow them to be destroyed. You want to avoid long running things because sooner or later, you will lose track and it will lead to a memory leak. This just boggles my mind, because I’ve always learned to try and reuse things in order to reduce the overhead of creation. I guess this is the pain of switching from C to Java.

I spent maybe 3 nights trying to get my clock widget set up. The thing that boggles my mind about app widgets (the things you drag onto your homescreen in android) is the onUpdate() method. Apparently onUpdate() can be called periodically, but it is also where they tell you to initialize everything about your app widget. This means that if you initialize a new variable, and then the update happens again, you’ll have to instances of that variable running. What’s worse is if you place multiple instances of your app widget on the home screen and then delete one, the variables you created don’t also get deleted. They seem to persist until you completely restart the phone or force kill it.

Anyway, here is my final clock. It’s about as lightweight as you can get. It updates whenever there is a time change signal, which occurs every minute. Unlocking the phone is practically seamless. The problem is that because they dim the lock screen, whenever you unlock the screen gets super bright and it makes it seem like everything changed. Nothing I can really do about that. Secondly, I’m about 99% sure that the wallpaper on the lock screen is 1 or 2 pixels shifted right. Maybe I’m just going insane.

Now I need to let it run for a while to make sure it doesn’t crash.

Living on the Edge

I bought a HTC Thunderbolt because I get $150 off a phone from work and the offer was expiring soon. This is a pretty big step for me, considering I’ve been using a LG VX8300 flip phone from 2005.

And so being that I just love adb shell, I decided to root my phone the moment I booted and connected to Verizon. The process is a long series of adb commands. There is a potential to brick your phone, and if not that, mess it up into a state that would require a lot of troubleshooting to recover from. I realize now that I probably should not have started this process 5 hours before I have to drive to the airport to fly back to Pittsburgh.

Luckily for me, everything went correctly and I now have a rooted Thunderbolt. First agenda of business, removing BitBop. What the hell is BitBop? Get that shit out of my technique.