Thursday, April 30, 2009

MIDP 1.0 still matters

Is it worth to keep a MIDP 1.0 version of your product? I found out that the answer is yes and will share the reasons.
The latest verstion of my chess board - 1.7 - requires MIDP 2.0 and minimum screen resolution of 128x96. The previous version - 1.6 - required the same minimum screen resolution, but MIDP 1.0 instead.
I could delete 1.6 and focus only on newer handsets, but got curious about how many downloads this older version would get against the new one.
GetJar has download stats reports: daily, weekly and monthly. I got daily reports for 1.6 and 1.7 since April, 12 and was surprised to see that MIDP 1.0 downloads were 20% of the total - 389 out of 1889.
Below is a graphic with the daily download evolution of both versions:

Sunday, April 19, 2009

Adding colors

Since MIDP 2.0 it is possible to discover some colors defined by the handset user.
There is a new method Display.getColor(int), the parameter may be one of six public constants from class Display: COLOR_BACKGROUND, COLOR_BORDER, COLOR_FOREGROUND, COLOR_HIGHLIGHTED_BACKGROUND, COLOR_HIGHLIGHTED_FOREGROUND, COLOR_HIGHLIGHTED_BORDER. The return is a valid color to be used with Graphics.setColor(int).
These colors are the same from the handset main screens - the current theme.
To use these colors lets define five more attributes at our CustomImplicitList:
private int backgroundColor = 0xffffff;
private int foregroundColor;
private int backgroundhHighlightColor = 0xffffff;
private int foregroundHighlightColor;
private int borderHighlightColor;
And add setter method for each one of them.
The value used to initiate backgroundColor and backgroundhHighlightColor represents the white color.
Lets say there are two variables: CustomImplicitList list and a Display display.
We are not using COLOR_BORDER because the border of our CustomImplicitList is used only at the selected element.
The last part is to change the paint method of CustomImplicitList:
g.fillRect(0, 0, getWidth(), getHeight());
// ...
for (int i = 0; i < this.items.length; i++) {
if (i == this.selectedIndex) {
g.fillRect(1, y, getWidth() - 3, font.getHeight());
g.drawRect(1, y, getWidth() - 3, font.getHeight());
} else {
g.drawString(this.items[i], getWidth() / 2, y, Graphics.HCENTER Graphics.TOP);
y += font.getHeight();
// it was the last line that could be drawn
if (y + font.getHeight() > height) {
i = this.items.length;