J2ME Polish 2.0 Beta 3: ScreenInfo Revisited

March 16, 2007 · Print This Article

I thought I’d revisit Polish’s handy ScreenInfo class, as it is working as intended out-of-the-box in the beta 3 release (earlier post here).

In my current application, I’m using it a bit differently than I did before, combining it with a Timer to remove the ScreenInfo element after a specified amount of time.

As before, add the corresponding variable declaration to your build.xml file:

<variable name=”polish.ScreenInfo.enable” value=”true” />

You can also style this element in polish.css by using the “screeninfo” predefined style.

In the code sample below, I’m using images and determining margins at runtime, so I’m not utilizing this element, but it’s a quick way to add default styling and positioning.

screeninfo {
margin-top: 10
margin-left: 10;
}

A sample class file is below. In my implementation, I query for the canvas height and width during start-up (and I’d recommend you do something similar), but below is a quick and dirty way to accomplish roughly the same thing. This example could also be improved by accounting for multiple elements and related details.

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Timer;
import java.util.TimerTask;
import de.enough.polish.ui.ScreenInfo;

public class MyMidlet extends MIDlet {
public Display display;
private List mainMenu;
private Timer timer;

public MyMidlet() {
//your constructor code here
}

public void startApp() { }
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
public static void quitApp() { }

public void showScreenInfo(int icon, long timeout) {
String imagePath = null;
switch(icon) {
case 1:
imagePath = “/si_mail.png”;
break;
case 2:
imagePath = “/si_sync.png”;
break;
default:
//
}

ScreenInfo.setImage(loadImage(imagePath));

//#ifdef polish.FullCanvasSize:defined
//#= int width = ${polish.FullCanvasWidth};
//#else
int width = 176;
//#endif

ScreenInfo.setPosition(width-32, 1);
ScreenInfo.setVisible(true);

timer = new Timer();
timer.schedule(new InfoTimer(), timeout);
}

public void removeScreenInfo() {
ScreenInfo.setVisible(false);
}

class InfoTimer extends TimerTask {
public void run(){
removeScreenInfo();
}
}
}

For more information, you can check out the Polish documentation related to ScreenInfo: Overview | JavaDoc

Comments

5 Responses to “J2ME Polish 2.0 Beta 3: ScreenInfo Revisited”

  1. Renato Bonicio on January 21st, 2008 9:20 am

    Hi!!

    I´m trying to do something similar to “WaitScreen” from NetBeans but i can´t

    When a use waitscreen (without j2me polish), after accepts a HTTP connection, the waitscreen is shown.

    Using J2me Polish + Screeninfo the “Permission for connect” Screen stays there until the connection is finished.

    To the user it looks like a “crash”.

    Please Help me!

    ** Please reply my question to renatobonicio@gmail.com

    Thanks,

    Renato Bonicio, Brazil

  2. Joe Fission on January 21st, 2008 9:50 am

    You’re placing this in a separate thread, yes?

  3. Renato Bonicio on January 21st, 2008 11:38 am

    I have placed the code in a method called by the commandAction.

    I turn the screeninfo visible

    i call the httpconnection

    I turn the screeninfo visible (false)

    the screeninfo only appears after all the conection.. what´s wrong? sorry i don´t have much experience with polish.

    Thanks!

  4. Joe Fission on January 21st, 2008 4:57 pm

    First and foremost, make sure your network connection happens in a separate thread. Unless you utilize a thread, the UI thread has to wait for the connection method to complete before it can repaint.

    How I would approach it if you only have one connection method: In commandAction, call your method. That method should create a class that implements Runnable, and that class should do the network work and paint the screen info.

    If you have more than one connection method, create your own web connection class (abstract perhaps) and extend it for each web connection you want to make. That way you only have one copy of web connection code for all connection methods.

    Shaun

  5. a4820557 on November 2nd, 2011 11:32 am

    I’ve said that least 4820557 times. The problem this like that is they are just too compilcated for the average bird, if you know what I mean

Got something to say?