Tuesday, June 13, 2006

J2ME Bug: mapped SoftKey values

Description: In some Motorola handsets, J2ME application running Canvas does not seem to respond when the left, middle or right soft key is pressed.

Affects: Motorola V3, V3x, SLVR L6 (only tested on these)

Workaround: In your code, expect the values of left, middle, and right soft key press to be -21, -23, -22, instead of the original 21, 23, 22.

In J2ME Polish, change the affected devices specification in devices.xml to have these extra capability parameters as described here.

Monday, June 12, 2006

Unexpected joy

The house where I stay is crazy about soccer. The landlady subscribed to cable TV just to watch World Cup matches. So tonight I arrived home when half of Japan-Australia first match was over, with Japan leading 1-0. Not understanding the point of soccer, I read a book next to three excited girls glued to the TV set, and blurted a memorable line:

Girls, where's the ad?

When the match seemed to almost end with a Japan win, you could see anxiety grew in the Australian fans' faces. But the Australian team itself didn't seem fazed at all. In fact, they scored three goals in the last six minutes. Isn't it fantastic, a team that looked like it's a goner (they didn't score a single goal in the last 32 years), rose from the dead to victory?

(What happened aferwards was interesting; because my friend emphatizes too much with any losing team and accused me of not sympathizing with her 'side'. But that's for another topic of "What can happen to you if you are not allowed to express joy when your team wins")

The only thing I 'like' about soccer is that determined seeking to score goals and that earnest joy when they are beget. Another thing is that, this is a game that gives both teams a chance to win til the very last minute, the very last second. What an unexpected joy it is to see hope born!

Kinda remind me that for grace is like that; it comes in the least expected moments and for some people, it literally snatches them from the jaws of Hell moments before death... like this lucky creature here.

 

UPDATE: My friend Vergel writes a classy commentary live for the World Cup series. You can read his writings on your cellphone by downloading this free mobile application here.

Saturday, June 10, 2006

God's eye candy today

While strolling outside a church's meeting room today, I saw a tree with beautiful leaves. I don't know what it's called, but it sure made my day! How great He is who made them!

 

PS: Picture quality was degraded due to MMS size limitation (original resolution: 1280x960, reduced to 640x480)

Ultimate weight-loss activity

I bought a little drawer set made of wooden frames and cardboard boxes this morning, in an effort to combat mess. When I came back tonight from the Choice reflection day, I sat down to assemble its parts together.

Being the eldest daughter in a family with no sons, I grew up as my dad's assistant handyman. I guess I'm out of practice, because I'm totally drained and my arms are still shaking after taming the imperfect holes with wooden plugs and screwdrivers and L-wrench. Some pictures to entertain the idle visitor: (Sorry, no picture of the parts before assembly!)

This is the trickiest part: putting together the drawer handles!
 

For anyone who wants to burn serious calories to lose weight: purchase a small furniture from IKEA, assemble it yourself, feel the hunger in your rumbling tummy and enjoy! My thumbs are now bright-red. Hope this little baby brings order to my room. Have a good weekend.

Friday, June 09, 2006

J2ME Polish: obfuscator bug

This bug has been the bane of my life for the past few weeks. To a non-IT person (that's a lot of you and I, before my company started), it might have seemed strange to want to obfuscate anything!

The American Heritage® Dictionary defines obfuscate as:
1. To make so confused or opaque as to be difficult to perceive or understand
2. To render indistinct or dim; darken

For people who gets irked when their code gets lifted, obfuscation can be done on their codebase. In J2ME, obfuscation helps to reduce the final JAR size by eliminating classes which have been declared but never referenced, at the same time renaming classes to one-letter or two-letter names, thus 'obfuscating' it for the code thief. It is a nearly standard practice, and I would like to document my little tête-à-tête (or a wrestle?) for others whose search take them here.

Description: J2ME Polish v1.2.4 seems to have a problem obfuscating code which contains the javax.microedition.media.Manager class.

Should we abandon Polish? What if your codebase has grown dependent on Polish? What if, worse, you've fallen in love with Polish' elegant UI? Both were true for me. So here's what I did:

1. Don't obfuscate
No go. I absolutely need two library JARs, one for floating-point-decoding operation (33KB), the other for xml parsing (kxml2-min.jar—18KB). Total JAR size was 295KB. Costs a bomb to download OTA. How can we ever hope anyone would download it to their phone?

2. Manually prune my code & optimize images
Eclipse helps me to see what methods and variables are not being used. I also renamed packages, methods, variables and packages to use shorter names while trying to remember their mnemonics! Basically, all the 'good programming practices' taught in school have to be thrown out of the window when it comes to making lean codes for mobile phones. I only have two 1-KB image files. My effort reduced the JAR size to 188KB.

3. Attempt to implement my UI using Canvas
This took me two days: euphoria and dypshoria took turns when it worked smoothly on Nokia 6230i and then I realized I might have to provision customization for every single phone model!

4. Attempt to fix it
I suspected this bug might be due to two JAR files used by J2ME Polish containing the Manager class in the same package javax.microedition.media. So I bravely combined the two JAR files and replaced the Manager class in Polish' JAR files with the original Sun Wireless Toolkit's. Didn't work.

5. Use Proguard's parameters in J2ME Polish
I tried introducing some parameters "-dontskipnonpubliclibraryclasses", "-dontusemixedcaseclassnames" and "-keep" on the Manager class, in the obfuscator element of the build.xml file. Didn't get past step one, because it requires me to overwrite a Polish obfuscator class.

6. Upgrade to J2ME Polish v1.3-beta4
Not only this version doesn't solve the problem, it introduces new bugs for the function Display.setCurrent(Alert, Displayable)

7. Use alternative obfuscators
Jode, or Retroguard both didn't work with v1.2.4 and v1.3-beta4.

8. Upgrade to ProGuard v3.4 or v3.6
Didn't work. These two versions are not backward-compatible with the calls that Polish v1.2.4 make.

9. Finally, (THIS WORKED!) Obfuscate outside J2ME Polish
I compiled the JARs in Polish for some fifty phone models without obfuscation. Open them using other Wireless Toolkits (Sun's, Siemens' or Sony Ericssons'), attach the source and the library JARs independently, rebuild with obfuscation (Proguard v3.2—same version as what Polish uses)! Smooth as butter. Extra patience required.

RESULT: Final JAR sizes are between 95KB to 106KB (depending on device models).

Talk about dismantling the whole building just to fix a little plumbing problem. What one wouldn't do for something one loves... Hope this helps, folks!

Thursday, June 08, 2006

Pentecost & Holy Trinity

As Trinity Sunday approaches, the Church reflects on unity of the 'visible'—aspiring after the ultimate unity of the Holy Trinity. In last night's prayer meeting we discussed how sometimes it is hard to see unity, harder still to promote it! Today I found the Pope's homily at Vespers, on the eve of Pentecost. What a wonderful teacher we have in him! Read it for yourself, and may you grow in the love of our Triune God!

Wednesday, June 07, 2006

J2ME: Golden bug

I have exactly 13 days to release my company's app (and the other company's app too). After playing around with the look-n-feel, and running it hard to slim down the JAR file size, I finally got to look at the part that reads from the mobile phone's filesystem. At first, the bug's behavior is hardly noticeable underneath all those J2ME midlet permission pop-ups (one for every file listed).

Description:
On most Java MIDP2.0 phones supporting JSR-75 (FileConnection API), the following call should return the directory names requested:
System.getProperty("fileconn.dir.photos")
should return
"file:///c:/pictures/"(or something equivalent applicable to the handset make).
Similarly other getProperty calls to "fileconn.dir.tones", "fileconn.dir.videos", should return ringtones' and videos' respective folders.

On Sony Ericsson's models K750, W800 series and possibly its entire Java Platform 6 family, this call fails—returns nothing basically. The root cause of this was simple:

Cause
“fileconn.dir.xxx” has accidentally been misspelled as “filconn.dir.xxx” in those phones' Java API implementation.

Link here

Many programmers, especially those new to J2ME, spent countless hours of near despair wondering what on earth happened, or did not happen, on that tiny machine. Despair no more!

Tuesday, June 06, 2006

Elsewhere on the blogosphere...

1. 06-06-06: Back to work—good day for me—all tests clear! Evening spent at my company's new office. Not seen anything unusual this day. Besides, in a hundred years, we will get 06-06-06 again!

2. Roundup on Pentecost celebrations
Reflecting on the Holy Spirit's gifts
Some crazy rainbow sashers denied communion: someone distributed the Host to them illegally.

This brings to the point of liturgical practices: I haven't been in the Church long enough to know what proper liturgies should be. My experience of being denied Communion on the tongue (the excuse being to curb the spread of Hand-Foot-Mouth disease—which doesn't happen in Singapore where no cattle grazes) was the furthest extent of my disturbance. Bad taste in music is next, but I will even say sometimes it can be tolerated with a thought to charity.

Some of the hardcore traditionalists like Gerard have either really experienced banal liturgies or are just plain cranky :) One of them suggested that in a traditional Novus Ordo mass or Tridentine Mass everyone would take the Lord reverently (while kneeling, on the tongue) no one would take the Host and break it and give it to those who protest the Church's teachings (and by definition, not in Communion).

Without going into 'liturgy' and definitions, my take on the Mass is that it should be carried out as reverently as possible. Certainly there are times when the Spirit infuse some of our parish members to express themselves more 'joyfully' than others, but Fear of the Lord should always guide liturgists. After all, they do not celebrate liturgies to showcase their 'talents' but also for their fellow parishioners. More often than not, unnecessary embellishment to the Mass (in the name of local culture) rather lessens than magnifies the solemnity given to the occasion.

Our pope BXVI, while a Cardinal, wrote ever so eloquently:

"I am convinced that the crisis in the Church that we are experiencing today is to a large extent due to the disintegration of the liturgy, which at times has even come to be a matter of indifference whether or not God exists and whether or not He speaks to us and hears us. But when the community of faith, the worldwide unity of the living Christ are no longer visible in the liturgy, where else then, is the Church to become visible on her spiritual essence? Then the community is celebrating only itself, an activity that is utterly fruitless."

Sunday, June 04, 2006

Feast of Pentecost

Veni Sanctus Spiritus!
Sine tuo numine,
nihil est in homine,
nihil est innoxium.

After nine days of praying the Novena to the Holy Spirit, Pentecost is finally here! Rejoice!

Mens sana in corpore sano: I'm not fit to write anything this weekend. Wishing all of you a blessed Pentecost and a renewed spirit!

Friday, June 02, 2006

J2ME references

This week I've been grappling at low-level firefighting on the J2ME mobile platform. One of the most frustrating things I encountered is finding similar problem being reported in the various forums, but not the followup!

So here are some reference for those who stumble here through late-night Google search:

For newbies who get frustrated by JSR-135 non-compliant implementation in Nokia phones: theory vs. practice
Mobile Media API Support In Nokia Devices

For those who find their JARs too big / want to 'hide' their code so that codelifters have to work a little harder:
Obfuscators: Proguard, Retroguard, Jode, etc.

For those who want to 'polish' up their clunky app:
J2ME Polish—be warned, there may be some problem using J2ME Polish with Obfuscators!

Update: Will post more on my wrestling match with J2ME-Polish and Proguard later. Down and out for the week.