How to fix the screen orientation to landscape or portrait? This feature is implemented on MIDP UIs using a Nokia specific Midlet Jad attribute Nokia-MIDlet-App-Orientation. eSWT does not make use of the any of the Jad attributes that are present on the MIDP platform. Instead it provides APIs that enables developers to achieve the same results. This also allows eSWT applications to be easily portable between runtimes. eSWT’s way for achieving fixed screen orientation is using the Screen API. Here is a short snippet that fixes the orientation to portrait for all available screens.
A good thing to remember is some devices may actually plug new screens, for the best results it is a good idea to listen for Screen changes using the listeners from MobileDevice APIs.1: Screen[] screens = MobileDevice.getMobileDevice().getScreens();2: for (int i = 0; i < screens.length; i++) {3: screens[i].setOrientation(Screen.PORTRAIT);4: }
How to put an eSWT application to background? On mobile platforms that support background applications MIDP developers achieve sending the application to background by removing the current Displayable. Here is an entry that explains how it is done on MIDP LCDUI. The same can be achieved for eSWT applications by setting the active Shell to minimized. Here is how.
The example snippet takes into account that you may actually have more than one top-level Shell, which the second one may get active once the currently active one is minimized.1: Shell activeShell = display.getActiveShell();2: while(activeShell != null ){3: activeShell.setMinimized(true);
4: activeShell = display.getActiveShell();5: }
I will try to make more of similar kind of posts in the future. Please do comment if you have any suggestions for content. And of course. I continue to keep an eye on the Nokia forums and Eclipse discussion boards.