BlackBall

I released my first commercial application for the BlackBerry a few days ago. It’s called BlackBall and is an application that allows you to filter or block incoming calls based on a specific blacklist that you maintain. It’s on an introductory offer at $0.99 until the end of January 2010, so check it out and grab a copy if you find it useful.

Emulating the BlackBerry Phone Call Log Field

While writing an application for the BlackBerry, I wanted to emulate the layout of the Phone Log.  Typically, this looks like a set of rows laid out in a two-column or multi-column format.  Since there was no available field to achieve this, I had to write my own.  The way I did it was to override the drawListRow method in an ObjectListField.  One thing you can notice in your BlackBerry call log screen is that the last 10 characters are always reserved and never appear as an ellipsis.  The last 10 characters are usually formatted thusly:

[Call Attribute: upto 4 characters][Date or Time: upto 6 characters]

Some examples of these are:


(W) 9:58p
(W2)11:22p
(H) 01/09

You will see in example 2 above, that all 10 characters are used up.  After I figured this out, the rest was pretty straightforward.  Here is the source code to my Field called PhoneNumberListField.

import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ObjectListField;

public class PhoneNumberListField extends ObjectListField
{

	public PhoneNumberListField()
        {
     	    super();
        }

	public PhoneNumberListField(long style)
        {
     	    super(style);
        }

        public void drawListRow(ListField listField, Graphics graphics,
        		int index, int y, int width)
        {

        	String tmpCol1 = (String) this.get(listField, index);
        	String col1 = tmpCol1.substring(0, (tmpCol1.length() - 10));
        	String col2 = tmpCol1.substring(tmpCol1.length()-10);

        	int col2Size = this.getFont().getAdvance(col2);
                int col1Size = width - col2Size;

        	int col1Start = 0;
        	int col2Start = (width - col2Size);

        	graphics.drawText(col1, col1Start, y, DrawStyle.ELLIPSIS, col1Size);

        	graphics.drawText(col2, col2Start, y, DrawStyle.HDEFAULT, col2Size);

        }

}

How to implement

You first create an array of Strings.  This array can contain phone numbers or a combination of First Name, Last Name together with the phone attribute like (W), (H) for Work and Home numbers respectively.  The last field will be the date or time.  I check the time of the call to see if it is older than 24 hours.  If it is, I use the date.  The format for the time is “h:mma” and for date it is “MM/dd”.  You can format these using SimpleDateFormat.

The full list of BlackBerry Attributes are represented as follows:

Home: (H)
Work: (W)
Mobile: (M)
Pager: (P)
Fax: (F)
Other: (O)
Work2: (W2)
Home2: (H2)

The attribute constants can be found in the BlackBerryContact Interface.  A typical array of mine would look like this:


String[] numList = {“Sheran Gunasekera (W) 09/09”, “Scott Mosier (M) 9:39a”,
“Kevin Smith (M)10:39p”, “+12120031337     10:04p};

Then, if I want to place this field on my MainScreen, I do this:

PhoneNumberListField numbers = new PhoneNumberListField();
numbers.setEmptyString(“*** No Calls Yet ***”, DrawStyle.HCENTER);
numbers.set(numList);
add(numbers);

This is what it looks like:

PhoneNumberListField

PhoneNumberListField

Installing the JDE Plugin 5.0.0 for Eclipse

topleftI wanted to try out the new Eclipse JDE plugin with OS 5.0.0 so I downloaded the ZIP file from the BlackBerry developer website and tried to install it on my Eclipse.

Towards the very end of the installation, I received some error messages. They looked something like this:

An error occurred while collecting items to be installed
  No repository found containing: net.rim.eide/osgi.bundle/1.0.0.67
  No repository found containing: net.rim.eide.bootstrapper/osgi.bundle/1.0.0.67
  No repository found containing: net.rim.eide.preprocessing.hook/osgi.bundle/1.0.0.67

Quite annoying since it took me a long time to download the JDE ZIP file thanks to a slow Internet connection.  After a little bit of digging, I figured out that the three components I was missing were indeed not in the ZIP file that I had downloaded.  So rather than downloading the whole new ZIP file again, I thought I’d try another approach.

I went into the Eclipse Software Updates menu: Help->Software Updates and added the update site “http://www.blackberry.com/go/eclipseUpdate”.  I then refreshed the repository and looked for Plugin verison 5.0.0, highlighted the relevant checkboxes and clicked install.  Sure enough, Eclipse dutifully fetched the three missing bundles from RIM’s update site and finished off my installation.  I’m playing with OS 5.0 as I write this.