×

Adding orientation support

Series 40 full touch platform supports Orientation API.

Nokia-MIDlet-App-Orientation JAD attribute

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

Implement and register the OrientationListener

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.

High-level UI

When the orientation changes, high-level UI components are re-initialized to reflect the new UI orientation.

Low-level UI

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());
	}
}

Last updated 9 October 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×