Jan 12, 2009

Your screen orientation changes but does your eSWT adjust?

The late editions to the eSWT enabled phones, such as N97 and the 5800, come with a load of features that are significant to mobile UI development. Possibly, the most significant of those features that you should consider in your UI design is the automatic screen orientation changes due to accelerometer.

eSWT implementations do their best to help with the orientation changes. For instance, S60 eSWT implementation resizes the top-level Shells when the UI orientation changes. This in turn causes the eSWT’s layout managers to layout your UI for the new screen orientation. If you are using only top-level Shells and layout managers than it is very likely that your application’s UI will be OK on both orientations.

However, on most occasions, your application is more sophisticated and requires adjusting. Also, it is desirable that your applications is able to take advantage of the new orientation. eSWT includes a bunch of APIs that can help you with that. Screen, which is part of the mobile package of eSWT, provides APIs and events for detecting the orientation changes as they happen. MobileDevice provides a way to get the available Screen(s) on the device.

I have created an example Midlet application that uses these APIs to take better use of the new orientation. Code is available from the Eclipse eRCP CVS. There is also a video of the example running on the S60 FP2 SDK.  As you can see from the video, example application replaces the image with a bigger one and makes more text visible in the landscape orientation and restores it back.



In order to simplify and automate the several tweaks that you may need to do on orientation changes, example code also includes a small framework for handling different states of the UI. A State simply holds a number of property values that is applied to eSWT widgets when the state is activated, and restored when it is deactivated. There is also an OrientationAwareComposite implementation that manages the activation of the State(s) on orientation changes. The future goal is to enable animations when transitioning between states.

Also note that this example is developed using Eclipse MTJ project