Skip to content

Posts from the ‘Learning Log’ Category

31
Aug

Working With Stateful ListView

What is Stateful ListView?

It’s not a coined term, but it’s obvious. Stateful ListView is a listview whose items change according to its state.the state is usually maintained by a custom ListAdapter.

Why would I need it?

I don’t know. But, I can tell you why did I need it. In my Birthdays application, I wanted to have a “Batch Edit” mode. When activated, it should allow users to mark multiple items using checkboxes. That means these checkboxes weren’t part of my “Standard” mode. I didn’t want to create whole new activity just to add a checkbox. So, I decided to have the checkbox in the hidden state by default. I wanted to somehow loop through all the items and make it visible.

Sounds pretty easy. What’s the problem?

The first one isn’t actually a problem. It is because of the way Android is designed. The ListView doesn’t load all the item at once to optimize memory management. Only visible items are loaded. So, one can’t exactly loop through all the items because they don’t exist. If you change only visible items, newly rendered items after scrolling don’t have the change. The new items are rendered by executing ListAdapter.getView() for each item. So, maintaining the state inside the adapter solves the issue.

Now all the new items are being rendered correctly but, it won’t change the already rendered (visible) items. To solve this, I combined the above two techniques – maintaining the state inside the ListAdapter for items not yet rendered and looping through all the visible items and changing them. This introduces another issue that consumed more time in identification and resolution then before.

Basically, if user switches between modes when the ListView is being scrolled, Android VM will throw NullPointerException because the requested ListItem doesn’t exist in the view.

What did you do?

The cause of this was the loop where I was trying to modify the items. When the function was being invoked, because of the still-scrolling ListView, indexes of visible ListItems changed and they were no longer available. I had to remove it for starters. Now, what I needed was a strategy to make the checkboxes visible for already rendered items. After a little bit of searching I found out that by calling Adapter.notifyDataSetChanged() I can re-render visible ListItem views. If anybody has an improved strategy to implement the scenario, please comment below. I will update the post accordingly.

The source code for Birthdays application I mentioned above can be accessed via Github.

19
Aug

Birthdays Released on Android Market

Yesterday, I released my first Android application on Android Market – Birthdays. It is a birthday reminder application which syncs all your contacts’ birthdays to your calendar.

One can say that I’m a forgetful person and while there are some advantages of this situation, I often forget birthdays of people who matter. As a solution to this, I started maintaining birthdate of a person into his/her contact. Back then, I had just bought an iPhone and I was pleased that it had a “Birthday” field in the address book. I didn’t hesitate paying $0.99 for a birthday reminder app which didn’t exactly “remind” me (iPhone didn’t support Push notifications or Calendar sync back then).To be exact, it helped only a little if at all.

In the same time period, I was also excited about Android as a development platform. When I got my first Android device, I tried out a few birthday reminder apps already available. Most of them didn’t work as I expected them to. While some did, they relied on a background service for notifications which will keep running at all times. So, I decided to start the development of yet another birthday reminder application which will get the job done while not being a resource-hog. While the journey of the development was quite educational, it was easier than I initially thought (probably because of a slight change in my job description). I still can’t believe it took me a year to develop and publish my first “real” application.

So, what’s next? The application is still very basic. I am going to explore android SDK some more by adding new features like facebook sync, two-way contact sync etc. I have had a lot of help from Android developer community so, I am going to write a few blog posts explaining some issues I faced in the development of this application as my contribution. I am also planning to open the source to public as soon as I am done with implementing all the features I have in my mind. The application source can be accessed from Github.

QR Code
If you haven’t yet tried it, give it a spin by downloading it from the Market. Do provide your feedback via comments below so that I can improve it further and make it more user-friendly.

A feature suggestion is also welcome. I will implement it as I get time to spare.

Note: Because of a major bug, all the calendar events created by Birthdays are being removed by Android upon reboot. I am working on an alternate way to sync the calendar. Please bear with me until I release a fix.

Changelog:

Birthdays v1.2 R6 (September 20, 2010):

  • Fixed the “Invalid Birthday” issue
  • Fixed crashes on Droid X
  • Corrected calendar event dates
  • Better calendar cleanup
  • A few minor bugfixes

Birthdays v1.1.beta (August 21, 2010):

  • Fixed the crash for non-HTC devices

Birthdays v1.0.beta (August 18, 2010):

  • Initial release
7
Aug

Installing Redmine 1.0 on Mac OS X Snow Leopard

I have been a great fan of Redmine since I came to know about it back in 2008. I have been using it ever since to track my personal as well as professional projects. I had an installation of good old Redmine 0.8.6 on my Snow Leopard and I decided to upgrade it to 1.0 RC. As always, installation was not so smooth for me, but I managed to do it and here’s how.

I followed Redmine Upgrade Instructions initially, which required me to upgrade to Rails v2.3.5 from v2.2.2 with all dependencies. Thanks to awesome rubygems, it was a cakewalk. But, I made a rookie mistake there. Instead of installing them in system path using sudo, I installed them in user directory (~/.gem). To check your gem installation location, you can execute gem list -d. Anyway, it eventually led to an error “Missing the Rails gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed” . This was very confusing as Rails 2.3.5 was already installed and upon executing rails -v, it displayed Rails 2.3.5. I had to uninstall Rails 2.3.5 and all the dependencies from user directory and reinstall them in system path using sudo.

Second challenge was to make Rails 2.3.5 work with mysql. As I was using default mysql installation in snow leopard, which happens to be a 32-bit one, I was not able to install mysql gem for ruby. After a little bit of googling, I found out that I had to download and install 64-bit MySQL in order to compile 64-bit gem. So, I installed new MySQL instance, migrated all my data from the older instance and then installed mysql gem. And I finally got the new Redmine installation got up and running on apache.

I wish I can have the wordpress-like automated upgrade mechanism in Redmine.

15
Jun

Rooting HTC Desire: The Hard Way

There are many HTC Desire Rooting tutorials and step-by-step guides out there. Best ones amongst them are probably this and this. There are easier methods like this, but I prefer simpler over easier (Yup, I’m too lazy to burn a CD. I’d rather do it without rebooting :P ). Before proceeding with the process I followed, I should mention that my HTC Desire is Singapore/Unlocked version which comes with RUU_Bravo_hTC_Asia_WWE_1.19.707.7_Radio_32.36.00.2 8U_4.06.00.02_2_release_126179_signed.exe ROM by default.

I primarily used Snow Leopard for this process (I had to use windows to make GoldCard). Following the above mentioned xda-developers guide pretty much did it. As it mentions, even I don’t have a branded (career locked) ROM, I needed a GoldCard to make it work (I came to know that after couple of failed attempts :P ). Anyway, following the guide for Mac OS X, everything else worked perfectly till the time came to restart device in recovery mode and flash update.zip from SD card. It failed to flash it because image verification failed. So, after spending some time on internet trying to find a solution, I finally found one. I found a way to enter a custom flasher menu in recovery mode by executing recovery-mac.sh (Which loads the green menu mentioned here). It took me a while to figure out that this menu doesn’t operate with volume up/down like the bootloader. So, here is the tip – The green recovery menu can be navigated using optical trackball; so it’s not stuck or frozen :P

So, finally I have my HTC Desire rooted. First thing I did was to get rid of the stock ROM. I took the Red Pill (Pays-ROM 2.0) and installed the ROM. Let’s see if I can find any difference in speed and battery usage.

Update: My desire keeps restarting if I click on new text message notification (More on that here). So, reverting back to the stock ROM for now. I hope I can work on my own ROM soon enough before I lose interest or I find a perfect ROM :)

15
May

Back from Hibernation with a Bang!!!

As you can probably notice, I am not what you can call a “Regular Blogger”. Mostly, I am too lazy to write a whole post that’s probably not going to be read by anybody.

Anyway, today’s different story. It doesn’t matter if anybody is going to read it. I just want to remember this day. So, the background story goes like this:

I decided to leave my current job at Infosys about three months ago. I knew what I have to do but, I wasn’t sure whether now was the right time. In short, one could say I resigned without having another job or even a concrete plan for future. Until today, I wasn’t sure if I wanted to leave the secure job and comfortable life I am living here for greater stress, lesser money and no comfort. As I said, this was the case until today. Today is the day I realized why am I doing this. I am as sure of doing this as one can be.

I still have one and a half month before I set my sails for more adventurous journey. But, as they say, half the battle is won if you are really determined to win it. So, regardless of whether I meet my expectations, I want to remember this day when I won half the battle :)

20
Feb

The Continuous BIOS Beep Crisis

I have faced a weird BIOS issue today. Apparently, I was cleaning up the dust on my CPU heatsink. When I booted my machine after I was finished, first it started with single beep immediately followed by a never-ending beep. My machine started without any glitch but the beep sound won’t stop. BTW, I am running a Intel C2D E8400 on Gigabyte EP45C-DS3R.

So, I immediately checked my CPU and system temperatures. They were normal. Even tried finding similar issue (and a solution) on the web with no luck. As my system was working perfectly, I decided to go ahead and remove the detachable BIOS speaker. But, the problem here was not solved; I’ve just found a way around it. I couldn’t resist myself and dug deeper to find an explanation of this unusual (and undocumented) behavior. After spending some time, I noticed that my CPU fan was running but, in BIOS Monitor, the CPU Fan speed was zero.

Looks like it is a built-in warning to notify that CPU Fan is not running. Disabling the CPU Fan Monitoring in BIOS did the trick. That left me wondering how did I fry my CPU Fan Censor when cleaning it? Anyway, glad that all is well again. :)

12
Aug

Android Development For Beginners

Just started playing with Android SDK 1.5r3 a couple of days ago. I went through some architecture videos, Hello World and Notepad tutorials. In my opinion, the API is still not mature enough but, it holds much potential. I don’t own an Android handset and the emulator doesn’t provide all the applications but, I came to know from some blog posts that built-in Apps are pretty basic and they drastically need improvement.

I was planning to develop a series of basic applications (similar to what AppsAmuck is for iPhone) which could help other newbie Android developers like me to learn things faster. Then, I came across blog of bakhtiyor, who has already made a similar effort. I will go through these applications this weekend and probably add couple of new apps to the list.

Update: I already started a couple of applications but, couldn’t get time to complete them. I wish to resume the development as soon as I can.

28
Jul

Cydia crashing on startup

I was just updating some applications through cydia the other day and my wifi connection went down while update was in progress (damn power outs… yeah, we still have a lot of them in India).

Now, after the incident, whenever I tried to open Cydia, it crashed while loading database. I tried rebooting the device a couple of times with no luck. Still Cydia kept crashing. I googled a bit about cydia startup crashes. Most of them were from much older OS (v1.1 really seems much older compared to v3.0 installed on my iPhone) and remaining solutions didn’t work for me.

Now, having your jailbroken iPhone with Cydia not working is pretty bad. So, I kept searching and I found out that Cydia writes a log file at /tmp/cydia.log. I opened that file using mobile terminal (also can be done via SSH) and there it was. One package was corrupted (Error message being “Unable to parse package file /var/lib/apt/lists/ ). I just removed the corrupted package file from specified location and voila. Cydia is now working as it was previously :)

Hope it helps…

21
Jun

iPhone ID3 tag editor

Just got myself an iPhone 3G yesterday. I have already jailbroken it to try out some interesting applications. I got to say, it’s pretty amazing. I just xould not believe that I can get a full-fledged terminal on a smartphone device. (I owned a Windows Mobile PPC prviously). And now I got all sort of development and networking tools installed on my iPhone. :D

Now, thing is, I copied over some music to my iPhone. Some of the songs didn’t have proper ID3 tags so, I thought I should edit them. After all these amazing application found on the platform, I was hoping to get an ID3 tag editor. But, unfortunately I didn’t. So, I thought why not develop it myself?

I am already learning objective-c programming. So, this will be kind of an excercise for me.

I will be coming with the ID3 editor soon.

Update: This application is delayed because modifying iTunes synced mp3 files on phone causes problem while syncing to iTunes.