Series 40 full touch platform supports Orientation API.
If you want to adjust your MIDlet UI orientation whenever the display orientation changes, add the following JAD attribute:
Nokia-MIDlet-App-Orientation: manual
If
only the value manual
is assigned, the application
can be launched in portrait or landscape mode depending on the orientation
of the device when launching the application.
If you want the
MIDlet UI orientation to be always locked to portrait or landscape,
instead of the value manual
, you can set one of the
following values:
Nokia-MIDlet-App-Orientation: portrait
Nokia-MIDlet-App-Orientation: landscape
You have to register
an OrientationListener
and implement it to adjust
the UI orientation. For more details on OrientationListener and using
theOrientation API, see Adjusting device's orientation.
class myClass extends MIDlet implements OrientationListener { public void startApp(){ Orientation.addOrientationListener(this); } }
The displayOrientationChanged
method is called
when display's orientation changes.
The Orientation.setAppOrientation
method sets
the application’s UI orientation.
The Java platform then calls the sizeChanged()
method on the current displayable.
public void displayOrientationChanged( int newDisplayOrientation ){ Orientation.setAppOrientation(newDisplayOrientation); }
Note: If you use only the JAD attribute and do not implement the
OrientationListener
, your MIDlet can compile
with older SDKs too. In this case, the MIDlet is not dynamically rotated,
and keeps the orientation it had in the start-up.When the orientation changes, high-level UI components are re-initialized to reflect the new UI orientation.
After the UI orientation has changed, all previously
acquired Graphics objects are considered invalid and must no longer
be used. Applications using low-level UI components, for example Canvas
or GameCanvas
, should block until
the sizeChanged
method has been called and then call
the getGraphics
method.
class myClass extends GameCanvas implements OrientationListener { Graphics g; public myClass () { super(false); Orientation.addOrientationListener(this); g = getGraphics(); render(); flushGraphics(); } // called when display orientation changes public void displayOrientationChanged( int newDisplayOrientation ){ Orientation.setAppOrientation(newDisplayOrientation); } spublic void sizeChanged(int x, int y) { g = getGraphics(); render(); flushGraphics(); } protected void render() { g.setColor(0xff0000); g.fillRect(0, 0, getWidth(), getHeight()); } }