Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2008

    Stop Switching from Portrait to Landscape mode

    Hello All,

    I have developed a J2ME application using Canvas and am testing this on Nokia E66.
    I am seeing a strange behavior, when I tilt my phone, the application changes from portrait mode to landscape mode. This is causing a problem in my applicationbecause it automatically orients itself in the landscape mode.
    I want to know a way so that I can prevent my application from changing the orientation.

    I think the JAD property "Nokia-MIDlet-Canvas-Scaling-Orientation-Switch" could be used for 3rd Edition FP 2 devices, but Nokia E66 is a 3rd Edition FP 1 device.

    Is there any solution for this type of device?

  2. #2
    Regular Contributor
    Join Date
    Oct 2005

    Re: Stop Switching from Portrait to Landscape mode

    Dear Ashish,
    for switching between landscape mode and posrtrait mode there is function automatically called named sizechanged in canvas calls.
    you can override it and repaint your screen again as you want.

    Wael Nabil
    Product Manager
    CITGlobal MOBiDIV

  3. #3
    Nokia Developer Expert
    Join Date
    Mar 2003

    Re: Stop Switching from Portrait to Landscape mode


    The attribute you mentioned is only meant to be used together with Nokia-MIDlet-Original-Display-Size and it's not for what you are seeking. The Nokia-MIDlet-Original-Display-Size was introduced in 3rd ed. and the one you mentioned (Nokia-MIDlet-Canvas-Scaling-Orientation-Switch) got introduced in 3rd ed fp2.

    There's currently no way to force certain orientation for S60 Java applications using LCDUI. (New eSWT UI API allows app to control the orientation programmatically via org.eclipse.ercp.swt.mobile.Screen setOrientation method.) LCDUI application, however, quite easily can do that in their own painting logic so that they just turn the painting 90 degrees themselves depending on the orientation got from sizeChanged.

    We have also identified that orientation forcing for java applications is a wanted feature so we are seeking to add this feature in S60 Java platform future releases.

    Since you got confused of the attribute let me explain more what they are about:

    "Nokia-MIDlet-Original-Display-Size" is used for a midlet that is supporting only a certain resolution. I.e. MIDlet's Canvas graphics is designed for a single specific resolution and midlet breaks in some other. That said, I must say that a "proper" MIDlet is designed to be scalable and it will scale it's graphics according to sizeChanged(int width, int height) callback from device.

    So if MIDlet isn't scalable and supports a single resolution it can help devices that are running it to let it know the resolution it was designed to. MIDP standard does not have this kind of functionality for a MIDlet to indicate it's design resolution (MIDP standard's stand in this is simply that all MIDlets should be scalable so that they work in all MIDP devices). But since we saw that there's anyway MIDlets which aren't scalable, Nokia has added the Nokia-MIDlet-Original-Display-Size attribute. Nokia device's Java implementation will use the attribute to decide if it can upscale the MIDlet defined resolution to the resolution a device has where MIDlet is being executed in. I.e. its mostly valuable when the device has larger resolution than the MIDlet indicates, but there's also other use cases e.g. if for a performance reason one wants to use smaller resolution (all the performance hungry graphics rendering operations done in smaller resolution but then the end result is simply scaled to match the devices resolution).

    The new 3rd ed fp 2 attribute named Nokia-MIDlet-Canvas-Scaling-Orientation-Switch is used always together with the original size attribute, and it is only needed if a MIDlet both is designed for a single specific resolution but can also support the resolution both in portrait and landscape orientations. If Nokia-MIDlet-Canvas-Scaling-Orientation-Switch is not set to true or left undefined the device tries to match the Nokia-MIDlet-Original-Display-Size defined resolution exactly in the defined orientation both in device's landscape and portrait modes.

    It should be also noted that current behavior in the canvas scaling feature is that if device founds out that it would need to _downscale_ from the original size attribute's defined resolution to match device's resolution it simply turns off the scaling completely and gives device's display resolution for the MIDlet. However, we are also looking on changing this behavior in future so that downscaling would be done as it would be more intuitive. Also it should be noted that these both attributes are only valid for full screen Canvas - not to normal mode Canvas nor any other displayable type.

    More info from Java Developer's Library:


    Wiki topic:

    From S60 Java team
    Last edited by Aleksi; 2008-09-19 at 19:59.

  4. #4
    Registered User
    Join Date
    Jun 2009

    Re: Stop Switching from Portrait to Landscape mode

    Quote Originally Posted by Aleksi View Post
    There's currently no way to force certain orientation for S60 Java applications using LCDUI.
    Here's how I work around it. Draw the screen to an offscreen image and then rotate it. Have to adjust pointer events and arrow keys too.

    public class BaseScreen extends FullCanvas{
      private static Image offscreenImage = null;
      public BaseScreen(String id) {
        if (offscreenImage == null) {
          offscreenImage = Image.createImage(Math.min(getWidth(), getHeight()), Math.max(getWidth(), getHeight()));
     public void paint(Graphics g) {
        if (getWidth() > getHeight()) {
          Image rotated = Image.createImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), Sprite.TRANS_ROT270);
          g.drawImage(rotated, 0, 0, Graphics.TOP | Graphics.LEFT);
        } else {
      private void old_paint(Graphics g) {
        g.fillRect(0, 0, getWidth(), getHeight());
      public void pointerPressed(int x, int y) {
        int xAdjusted = x, yAdjusted = y;
        if (getWidth() > getHeight()) {
          xAdjusted = getHeight() - y; 
          yAdjusted = x;
        handleEvent(xAdjusted, yAdjusted);

  5. #5
    Regular Contributor
    Join Date
    Jul 2008
    Faridabad(Delhi NCR)

    Re: Stop Switching from Portrait to Landscape mode

    Hey if you want to stop switching you can do one thing use size changed() method this is called when your screen size change i mean when your change Portrait to Landscape mode or Landscape to Portrait mode>put One alert when its change and user cant click on oh command you put in which alert until he switch to original mode which your application want
    Anshu Chauhan
    J2me Developer

  6. #6
    Regular Contributor
    Join Date
    Jun 2008

    Thumbs up Re: Stop Switching from Portrait to Landscape mode

    Well u can continuously check the height and width of device by using getWidth() and getHeight(). As these method gives u changed value then show some alerts etc as suggested by anshu or u can set some other screen like Form or some canvas with some information to user..

    Is this makes some sense to u..

Similar Threads

  1. switching back to portrait mode column list box not displayed..
    By Rajani_sp in forum Symbian User Interface
    Replies: 0
    Last Post: 2007-12-06, 10:59
  2. skinning in landscape mode.
    By ravinder007 in forum Symbian
    Replies: 0
    Last Post: 2007-01-24, 11:01
  3. Skinning in landscape mode.
    By ravinder007 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2007-01-11, 10:24
  4. Problem switching between portrait and landscape
    By Tatanka.nbr1 in forum Symbian
    Replies: 0
    Last Post: 2006-05-16, 19:00
  5. Nokia N90 Portrait to Landscape Mode
    By alokkumarsingh in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-12-14, 13:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts