FileDocCategorySizeDatePackage
WMAMIDlet.javaAPI DocWireless Messaging API6441Thu Oct 09 23:10:36 BST 2003wmasample

WMAMIDlet

public class WMAMIDlet extends MIDlet implements CommandListener, wmafw.IncomingMessageListener, Runnable
WMAMIDlet.java implement a simple WMA Framework Client.

Fields Summary
private Command
thCmd
/ /** Command for thread processing
private static final int
SELECTION_EMAIL
private static final int
SELECTION_CALENDAR
private static final int
SELECTION_CONTACTS
protected Display
display
/ /** LCDUI Display context
private MainMenuScreen
mainMenu
LCDUI Display context
wmafw.WMAFramework
wmafw
WMAFramework Instance
Constructors Summary
public WMAMIDlet()
Constructor


          
      
    
Methods Summary
private voidcleanUp()
Clean up

        display = null;
        mainMenu = null;
        if (wmafw != null) {
            wmafw.stopFramework();
            wmafw = null;
        }
    
public voidcommandAction(Command c, Displayable d)
Command/button listener

param
c the LCDUI Command to process
param
d the Displayable source of the Command

        Thread th = new Thread(this);
        thCmd = c;
        th.start();
    
public voiddestroyApp(boolean uc)
Destroy state. Release resources (connection, threads, etc).

param
uc If true when this method is called, the MIDlet must cleanup and release all resources. If false the MIDlet may throw MIDletStateChangeException to indicate it does not want to be destroyed at this time.

        cleanUp();
    
public voidonBinaryMessage(java.lang.String from, byte[] message)
New Binary Message Notification Callback.

param
from is the address of the sender
param
message is the received binary message

        if (from != null) mainMenu.setTicker(UIConstants.TXT_NEW_BIN_MSG + from);
    
public voidonTextMessage(java.lang.String from, java.lang.String message)
/ /** New Text Message Notification Callback.

param
from is the address of the sender
param
message is the received text message

        if (from != null) mainMenu.setTicker(UIConstants.TXT_NEW_TEXT_MSG + from);
    
public voidpauseApp()
Paused state. Release resources (connection, threads, etc).

    
public voidrun()
Runnable entry point, controls the application (WMAMIDlet) navigation.

        try {
            if (thCmd == MainMenuScreen.EXIT) {
                cleanUp();
                notifyDestroyed();
            } else if (thCmd == MainMenuScreen.SELECT) {
                int index = mainMenu.getMenuSelection();
                if (index == SELECTION_EMAIL) {
                    if (wmafw != null) wmafw.showInbox(mainMenu.getScreen());
                    mainMenu.setTicker(""); // reset ticker
                } else if (index == SELECTION_CALENDAR) {
                    Alert alert = new Alert(UIConstants.MSG_NI, UIConstants.MSG_CALENDAR_TBI, null, AlertType.INFO);
                    display.setCurrent(alert);
                } else if (index == SELECTION_CONTACTS) {
                    Alert alert = new Alert(UIConstants.MSG_NI, UIConstants.MSG_CONTACTS_TBI, null, AlertType.INFO);
                    display.setCurrent(alert);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("WMAMIDlet.run Exception " + e);
        }
    
public voidstartApp()
Initial state

        try {
            //  Get the LCDI Display context
            if (display == null) {
                display = Display.getDisplay(this);
            }

            //  Initialize the Application's Main Menu
            if (mainMenu == null) {
                mainMenu = new MainMenuScreen(display, this);
            }

            if (mainMenu != null) mainMenu.showMenu();

            //  Get the WMA Framework Singleton Instance
            if (wmafw == null) {
                wmafw = WMAFramework.getInstance(display);
                if (wmafw != null) {
                    wmafw.setIncomingMessageListener(this);
                    wmafw.createServerConnection();
                    mainMenu.setTicker(UIConstants.TXT_ACTIVE_SMSC + wmafw.getSMSC());
                }
            }

        } catch(Exception e) {
            //  If some kind of error ocurred, throw MIDlet exception.
            throw new MIDletStateChangeException(UIConstants.TXT_ERROR_STARTING + e);
        }