midletproxy.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 606 行 · 第 1/2 页
JAVA
606 行
* is false */ void setWantsForeground(boolean newWantsForeground, boolean isAlert) { wantsForegroundState = newWantsForeground; if (newWantsForeground) { requestedForeground = true; alertWaiting = isAlert; } else { alertWaiting = false; } } /** * Check if the MIDlet want's its Display in the foreground. * * @return true if the MIDlet want's its Display in the foreground */ public boolean wantsForeground() { return wantsForegroundState; } /** * Check if the MIDlet has not created its display. * * @return true if the MIDlet has no display. */ public boolean noDisplay() { return numOfDisplays == 0; } /** * Check if the MIDlet has not set a displayable in its display. * Used by foreground selector to determine if the MIDlet it is * about to put in the foreground will draw the screen. * * @return true if the MIDlet has no displayable. */ public boolean noDisplayable() { return !requestedForeground; } /** * Set the proxy of the display that is preempting this MIDlet. * * @param preemptingDisplay the preempting display */ void setPreemptingDisplay(MIDletProxy preemptingDisplay) { // Turn on the user notification status for this proxy if (preemptingDisplay != null) { alertWaiting = true; } else { if (preempting != null) { /* * There could be a proxy timer waiting to destroy the * isolate if the user ended the alert with the end MIDlet * button, so cancel the timer. */ preempting.setTimer(null); } alertWaiting = false; } preempting = preemptingDisplay; } /** * Get the proxy of the display that is preempting this MIDlet. * * @return the preempting display */ MIDletProxy getPreemptingDisplay() { return preempting; } /** * Set the proxy of the MIDlet that should get the foreground * after preempting is done. * * @param preemptedDisplay the preempted display */ void setPreemptedMidlet(MIDletProxy preemptedDisplay) { preempted = preemptedDisplay; } /** * Get the proxy of the MIDlet that should get the foreground * after preempting is done. * * @return the preempted display or null for none */ MIDletProxy getPreemptedMidlet() { return preempted; } /** * Called to determine if alert is waiting for the foreground. * * @return true if an alert of the MIDlet is waiting in background. */ public boolean isAlertWaiting() { return alertWaiting; } /** * Asynchronously change the MIDlet's state to active. * * This method does NOT change the state in the proxy, but * sends a activate MIDlet event to the MIDlet's Display. * The state in the proxy is only update when the MIDlet sends * a MIDlet activated event to the proxy list. */ public void activateMidlet() { if (midletState != MIDLET_DESTROYED) { wasNotActive = false; midletEventProducer.sendMIDletActivateEvent(isolateId, className); } } /** * Asynchronously change the MIDlet's state to paused. * * This method does NOT change the state in the proxy, but * sends a pause MIDlet event to the MIDlet's Display. * The state in the proxy is only update when the MIDlet sends * a MIDlet paused event to the proxy list. */ public void pauseMidlet() { if (midletState != MIDLET_DESTROYED) { midletEventProducer.sendMIDletPauseEvent(isolateId, className); } } /** * Terminates ther MIDlet if it is neither paused nor destroyed. */ public void terminateNotPausedMidlet() { if (midletState != MIDLET_DESTROYED && midletState != MIDLET_PAUSED) { MIDletProxyUtils.terminateMIDletIsolate(this, parent); } } /** * Asynchronously change the MIDlet's state to destroyed. * * This method does NOT change the state in the proxy, but * sends request to destroy MIDlet event to the AMS. * The state in the proxy is only update when the MIDlet sends * a MIDlet destroyed event to the proxy list. */ public void destroyMidlet() { if (midletState != MIDLET_DESTROYED) { if (getTimer() != null) { // A destroy MIDlet event has been sent. return; } MIDletDestroyTimer.start(this, parent); midletEventProducer.sendMIDletDestroyEvent(isolateId, className); } } /** Process a MIDlet destroyed notification. */ void destroyedNotification() { setTimer(null); setMidletState(MIDLET_DESTROYED); } /** * Notify the midlet's display of a foreground change. Called by * the MIDlet proxy list to notify the old and new foreground displays * of a foreground change. * * @param hasForeground true if the target is being put in the foreground */ void notifyMIDletHasForeground(boolean hasForeground) { if (hasForeground) { alertWaiting = false; for (int i = displayIds.length; --i >= 0;) { foregroundEventProducer.sendDisplayForegroundNotifyEvent( isolateId, displayIds[i]); } } else { for (int i = displayIds.length; --i >= 0;) { foregroundEventProducer.sendDisplayBackgroundNotifyEvent( isolateId, displayIds[i]); } } } /** * Sets the timer object * * @param t Timer object */ void setTimer(Timer t) { proxyTimer = t; } /** * Gets the timer object * * @return Timer */ Timer getTimer() { return proxyTimer; } /** * Set the boolean attribute in the attributes' cache to true. * * The method is used to cache run time extended MIDlet attribute for better * performance. Default value for an atrribute is false. * * @param attribute extended MIDlet attribute, the valid values are: * MIDLET_BACKGROUND_PAUSE, MIDLET_NO_EXIT and * MIDLET_LAUNCH_BG * * @see #getExtendedAttribute */ void setExtendedAttribute(byte attribute) { extendedAttributes |= attribute; } /** * Retrives the boolean attribute from the attributes' cache. * * @param attribute extended MIDlet attribute, the valid values are: * MIDLET_BACKGROUND_PAUSE, MIDLET_NO_EXIT and * MIDLET_LAUNCH_BG * * @return If setExtendedAttribute was called for the attribute return true, * false otherwise. * * @see #setExtendedAttribute */ public boolean getExtendedAttribute(byte attribute) { return (extendedAttributes & attribute) != 0; } /** * Print the state of the proxy. * * @return printable representation of the state of this object */ public String toString() { String displays = ""; for (int i = 0; i < numOfDisplays; i++) { displays += displayIds[i]; if (i < numOfDisplays - 1) { displays += ", "; } } return "MIDletProxy: suite id = " + suiteId + "\n class name = " + className + "\n display name = " + displayName + "\n isolate id = " + isolateId + ", number of displays = " + numOfDisplays + ", display ids = " + displays + ", midlet state = " + midletState + ", wantsForeground = " + wantsForegroundState + ", requestedForeground = " + requestedForeground + "\n alertWaiting = " + alertWaiting; }}/** * If the MIDlet is hanging this class will start a * timer and terminate the MIDlet when the timer * expires. The timer will not work in SVM mode. */class MIDletDestroyTimer { /** Timeout to let MIDlet destroy itself. */ private static final int TIMEOUT = 1000 * Configuration.getIntProperty("destoryMIDletTimeout", 5); /** * Starts timer for the specified MIDlet (proxy) . * * @param mp MIDletProxy to terminate if not destroyed in time * @param mpl the MIDletProxyList */ static void start(final MIDletProxy mp, final MIDletProxyList mpl) { Timer timer = new Timer(); mp.setTimer(timer); TimerTask task = new TimerTask() { /** Terminates MIDlet isolate and updates the proxy list. */ public void run() { if (mp.getTimer() != null) { MIDletProxyUtils.terminateMIDletIsolate(mp, mpl); } cancel(); } }; timer.schedule(task, TIMEOUT); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?