×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Switching Screen

    Hi,

    I have a problem of displaying graphic (Canvas) triggered by switching screen (Nokia E90). As you know, the Nokia E90 has two screens. When the user switch screen, the canvas does not fresh accordingly.
    If user open the app in each screen, the display is alright.

    If you know how to refresh the screen in this case, plz share with me.

    Thank you
    ---Knowledge sharing is power---

    Hans

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Switching Screen

    Hi Hans,

    when using Canvas objects, you must manually manage those size changes using Canvas sizeChanged() method:

    http://java.sun.com/javame/reference...nged(int, int)

    This method is automatically called when a display size change occurrs (e.g.: a Canvas set to full screen, or, in your case, the change of display), but you should override and implement it to allow your canvas to adapt to the new display size.

    Hope it helps,
    Pit

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: Switching Screen

    Hi, Jappit

    Thanks for reply. I will try it.

    Rgds
    ---Knowledge sharing is power---

    Hans

  4. #4
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: Switching Screen

    Hi, Jappit

    The sizeChanged() seems not work with switching screen..

    Maybe i give mycode, you can help me to understand what the problem is.

    Thank Jappit

    public DrawSmt Extends Canvas{

    private int w=getWidth();
    private int h=getHeight();
    ////////

    public void sizeChanged(int w, int h){
    this.w=w;
    this.h=h;
    repaint();
    }

    public void paint(Graphics g){
    g.setGrayScale (255);
    g.setColor(0, 0, 0);
    g.fillRect (0, 0, w, h);

    scalableGraphics.bindTarget( g );
    //draw accordingly to w, h here.........
    scalableGraphics.releaseTarget();
    }

    }
    ---Knowledge sharing is power---

    Hans

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Barcelona, Spain
    Posts
    55

    Re: Switching Screen

    What I usually do is checking for the width / height at each paint .. just in case.

    Code:
       public void paint(Graphics g) {
          int w = getWidth();
          int h = getHeight();
    
          g.setGrayScale (255);
          g.setColor(0, 0, 0);
          g.fillRect (0, 0, w, h);
    
          scalableGraphics.bindTarget( g );
          //draw accordingly to w, h here.........
          scalableGraphics.releaseTarget();
       }

  6. #6
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Switching Screen

    Hi Hans,

    I'll try to test your code directly on a E90 device asap and let you know my results. Meanwhile, the approach proposed by rrafols is surely a good workaround (even if you don't get a direct notify when a display size change event occurrs).

    Pit

  7. #7
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: Switching Screen

    Hi,

    Thank you all. I understand that checking w, h frequently should be a workaround but it is not applicable with my app.
    Thanks Jappit, I will wait for your result.

    Thanks again
    ---Knowledge sharing is power---

    Hans

  8. #8
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Barcelona, Spain
    Posts
    55

    Re: Switching Screen

    I tried the following code on a E90 and it works properly:

    This is the main midlet:

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class MainApp extends MIDlet {
    
        private MainCanvas mc = null;
    
        public MainApp() {
            mc = new MainCanvas();
        }
    
        public void startApp() {
            Display.getDisplay(this).setCurrent(mc);
        }
    
        public void pauseApp() {}
    
        public void destroyApp(boolean unconditional) {}
    }
    And this is the canvas class:

    Code:
    import java.util.Vector;
    import javax.microedition.lcdui.*;
    
    public class MainCanvas extends Canvas {
    
        private Vector listStr = null;
    
        public MainCanvas() {
            listStr = new Vector();
        }
    
        public void paint(Graphics g) {
            listStr.addElement("repaint");
    
            int w = getWidth();
            int h = getHeight();
    
            g.setColor(0);
            g.fillRect(0, 0, w, h);
            g.setColor(0xffffff);
    
            g.drawString("w: " + w + " h: " + h, 0, 0, Graphics.TOP|Graphics.LEFT);
            for(int i = 0;i < listStr.size(); i++) {
                g.drawString((String) listStr.elementAt(i), 0, (i + 1) * 12 , Graphics.TOP|Graphics.LEFT);
            }
        }
    
        protected void sizeChanged(int w, int h) {
            listStr.addElement("sizechanged: " + w + ", " + h);
        }
    }
    I started the midlet in the small screen and then switched over the big screen and I get the following output:

    Before switching to the big screen:

    w: 240 h: 235
    repaint

    and after switching:

    w: 800 h: 284
    repaint (<-- this is the previous one)
    sizechanged: 800, 284
    repaint

    if I switch again to the small screen, the application is put in background, but when I put it again in foreground I get another sizechanged event of 240,235 and two repaint events (the first one will be issued after the call to sizeChanged, and the other when I put the application in foreground).

    If everytime the device does a screen switching calls the repaint method, checking width and height in your paint method should also work properly.

  9. #9
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: Switching Screen

    Hi, rrafols

    Thanks for reply. Yes, if we change w, h in paint() like this, it should work well.

    But my app, i did not check w, h in paint(), rather, i just want to wait for sizeChanged() to reset. Seem to me that this event is triggered by paint()..so it cannot work.
    ---Knowledge sharing is power---

    Hans

  10. #10
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Barcelona, Spain
    Posts
    55

    Re: Switching Screen

    Sorry tieutue but I don't understand the exact problem.

    If you don't want to check the width/height on the paint method, you could change the previous code to:

    Code:
        int w = 0;
        int h = 0;
    
        public MainCanvas() {
            listStr = new Vector();
            w = getWidth();
            h = getHeight();
        }
    
        public void paint(Graphics g) {
            listStr.addElement("repaint");
    
            g.setColor(0);
            g.fillRect(0, 0, w, h);
            g.setColor(0xffffff);
    
            g.drawString("w: " + w + " h: " + h, 0, 0, Graphics.TOP|Graphics.LEFT);
            for(int i = 0;i < listStr.size(); i++) {
                g.drawString((String) listStr.elementAt(i), 0, (i + 1) * 12 , Graphics.TOP|Graphics.LEFT);
            }
        }
    
        protected void sizeChanged(int w, int h) {
            listStr.addElement("sizechanged: " + w + ", " + h);
            this.w = w;
            this.h = h;
        }

  11. #11
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Switching Screen

    Hi Hans,

    I've checked on a Nokia E90, and sizeChanged gets correctly called when the display is changed.. this is the code I used:
    Code:
    public class MyCanvas extends Canvas
    {
    	int h = 0;
    	int w = 0;
    	int counter = 0;
    
    	protected void paint(Graphics g)
    	{
    		g.setColor(0xffffff);
    		g.fillRect(0, 0, getWidth(), getHeight());
    		
    		g.setColor(0x000000);
    		g.drawString("PROP: " + w + ", " + h + ", " + counter, 2, 2, Graphics.LEFT | Graphics.TOP);
    	}
    	protected void sizeChanged(int w, int h)
    	{
    		this.w = w;
    		this.h = h;
    		
    		counter++;
    		
    		repaint();
    	}
    
    }
    Pit

  12. #12
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Barcelona, Spain
    Posts
    55

    Re: Switching Screen

    Even that repaint call in the sizeChanged method is not necessary. It gets called automatically as the screen is switched.

  13. #13
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Switching Screen

    Right rrafols, thanks for the correction

  14. #14
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Singapore
    Posts
    167

    Re: Switching Screen

    Hi,

    Thanks guy. I also think it should work. Actually, I dont have device..it is our clients help to test. Probably they use our older verion.

    Anyway, thank you alot. I've learnt alot from you guys.
    ---Knowledge sharing is power---

    Hans

Similar Threads

  1. Problem with E90 and secondary screen
    By Tatanka.nbr1 in forum Symbian
    Replies: 5
    Last Post: 2008-06-27, 10:01
  2. Data structure for screen switching
    By soku123 in forum Mobile Java General
    Replies: 3
    Last Post: 2007-10-11, 04:25
  3. Detecting automatic screen switching
    By AcCarbon in forum Symbian User Interface
    Replies: 8
    Last Post: 2006-10-09, 15:28
  4. programmatically switching to the Standby screen
    By kernj in forum Symbian User Interface
    Replies: 1
    Last Post: 2006-08-24, 05:22
  5. UI: Full Screen Mode
    By GENERAL_INFO in forum Symbian User Interface
    Replies: 3
    Last Post: 2004-11-22, 06:27

Posting Permissions

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