Sunday, September 14, 2008

Porting LWUIT Part I: Basics Of The Porting Layer

This series is intends for hackers who wish to port LWUIT itself, not for developers wishing to port applications written in LWUIT. LWUIT is portable on two fronts, the first allows us to run applications developed in LWUIT in many platforms. The second allows us to adapt LWUIT to additional platforms such as CDC, Android etc...

LWUIT's portability is achieved by abstracting the underlying platform in a porting layer which consists of 3 main classes and a few optional classes: Graphics, Implementation and SystemFont. All of these classes are very system specific and require the porting to additional platforms to take them into account, additionally a port might want to either remove or adapt the classes: MediaComponent, Transition3D, M3G and Log.

Since the other classes in LWUIT make use of these classes all we need to do in order to port LWUIT is create a build.xml file which copies the existing LWUIT code base and deletes these files. We then need to compile with our version of these files that makes use of the new API, e.g. when porting to CDC we no longer have GameCanvas of which the Implementation class derives, so we derive from java.awt.Component which is the closest counterpart.

The implementation class is completely hidden within LWUIT since it contains many hidden implementation details that are subject to change. However, several of its methods are used by LWUIT itself and this allows us to ease the porting work considerably. Since the class is hidden its API isn't "documented" and so it is likely that the task of porting will change in some ways in future versions of LWUIT (e.g. as we add functionality to LWUIT the implementation class would be modified/enhanced).

To understand this better the Implementation class in the Android port is based on the android.view.View class, while the LWUIT Graphics class delegates everything to the android.graphics.Canvas class. In the Java SE port, the implementation class is a JComponent while the Graphics class delegates to the java.awt.Graphics2D class.

4 comments:

  1. Since the original Android port is based on a very old version of LWUIT with completely different porting layer and no open source license I can't open the code.
    I will try to continue this series when I get the chance and include more details.
    If you have specific questions about how to do something in your port just post them here or to the forum and I will try to answer as best as I can.

    ReplyDelete
  2. Understood. Consistent UI on different mobile platform will be a big plus for mobile application. We will post questions on the forum if any. Thanks for your prompt reply!

    ReplyDelete
  3. I've noticed its been a while since this post has been made. I would like to know if their has been any improvements or changes to how LWUIT works on android. We are making use of LWUIT to build our mobile platform and would like to port it to Android.

    ReplyDelete
  4. Hi.i am porting j2me application on the Samsung devices but i faced one very regid behavior of the LWUIT.i repaint the Form then also it display both form old one and overlap new form.how to resolve this?

    ReplyDelete