FileDocCategorySizeDatePackage
AutoForegroundStateController.javaAPI DocphoneME MR2 API (J2ME)4908Wed May 02 18:00:08 BST 2007com.sun.midp.automation

AutoForegroundStateController

public final class AutoForegroundStateController extends Object implements AutoDisplayControllerListener
Class controlling foreground

Fields Summary
private MIDletProxyList
midletProxyList
MIDlet proxy list reference.
private AutoMIDletInfoList
midletsInfo
List of AutoMIDletInfo for MIDlet's we are interested in
private AutoDisplayController
displayController
Display controller
private MIDletControllerEventProducer
midletControllerEventProducer
Events producer
private static AutoForegroundStateController
stateController
The one and only AutoMIDletStateController instance
Constructors Summary
private AutoForegroundStateController()
Private constructor to prevent direct creation of instances.


                 
      
        midletProxyList = MIDletProxyList.getMIDletProxyList();

        displayController = new AutoDisplayController(midletProxyList);
        displayController.setListener(this);
        midletProxyList.setDisplayController(displayController);

        midletControllerEventProducer =
            AutomationInitializer.getMIDletControllerEventProducer();

        midletsInfo = AutoMIDletInfoList.getMIDletInfoList();
    
Methods Summary
public voidforegroundMIDletChanged(MIDletProxy oldForeground, MIDletProxy newForeground)
Called when foreground MIDlet is about to be changed.

param
oldForeground MIDlet currently in foreground
param
newForeground MIDlet getting foreground


        if (oldForeground != null) {
            AutoMIDletImpl midlet = midletsInfo.findMIDlet(oldForeground);
            if (midlet != null) {
                midlet.stateChanged(AutoMIDletForegroundState.BACKGROUND);
            }
        }

        if (newForeground != null) {
            AutoMIDletImpl midlet = midletsInfo.findMIDlet(newForeground);
            if (midlet != null) {
                midlet.stateChanged(AutoMIDletForegroundState.FOREGROUND);
            }
        }
    
static synchronized com.sun.midp.automation.AutoForegroundStateControllergetForegroundStateController()
Gets AutoMIDletStateController instance.

return
AutoMIDletStateController instance


        if (stateController == null) {
            stateController = new AutoForegroundStateController();
        }

        return stateController;
    
public voidhandleForegroundRequestEvent(int midletSuiteID, java.lang.String midletClassName)
Processes AUTO_FOREGROUND_REQUEST event

param
midletSuiteID MIDlet's suite ID
param
midletClassName MIDlet's class name


        MIDletProxy midletProxy = midletProxyList.findMIDletProxy(
                midletSuiteID, midletClassName);

        if (midletProxy != null) {
            midletProxyList.setForegroundMIDlet(midletProxy);
        }
    
voidswitchTo(AutoMIDletImpl midlet, AutoMIDletForegroundState state)
Initiates switching MIDlet to specified state.

param
midlet AutoMIDletImpl instance representing MIDlet to switch
param
state state to switch to

        MIDletProxy midletProxy = midletsInfo.findMIDletProxy(midlet);
        if (midletProxy != null) {
            if (state == AutoMIDletForegroundState.FOREGROUND) {
                int suiteID = midletProxy.getSuiteId();
                String className = midletProxy.getClassName();

                midletControllerEventProducer.
                    sendSetForegroundByNameRequestEvent(suiteID, className);
            }
        }