001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.main;
028:
029: /**
030: * IndicatorManager is a singleton class that controls the home icon
031: * status in status bar.
032: */
033: public class IndicatorManager implements MIDletProxyListListener {
034:
035: /** singleton variable */
036: private static IndicatorManager singleton;
037:
038: /** boolean flag that indicated home icon status */
039: private static boolean homeIconState;
040:
041: /** Internal midletProxyList that is used to add listener */
042: private static MIDletProxyList midletProxyList;
043:
044: /**
045: * Native method to toggle the home icon
046: *
047: * @param isHomeOn : boolean flag to indicate status of home icon
048: *
049: */
050: private static native void toggleHomeIcon0(boolean isHomeOn);
051:
052: /**
053: * IndicatorManager is a singleton.
054: */
055: private IndicatorManager() {
056: }
057:
058: /**
059: * A static method that initialize singleton IndicatorBar class
060: *
061: * @param theMidletProxyList a reference to the MIDlet proxy list
062: */
063: public static void init(MIDletProxyList theMidletProxyList) {
064: if (singleton == null) {
065: midletProxyList = theMidletProxyList;
066: singleton = new IndicatorManager();
067: midletProxyList.addListener(singleton);
068: }
069: }
070:
071: /**
072: * This method is called whenever home icon needs to be
073: * turned on/off
074: *
075: * @param newHomeIconState boolean flag to indicate status of home icon
076: */
077: private static void setHomeIconState(boolean newHomeIconState) {
078: if (homeIconState != newHomeIconState) {
079: homeIconState = newHomeIconState;
080: toggleHomeIcon0(homeIconState);
081: }
082: }
083:
084: /**
085: * This function is public so that unit test can refer it
086: *
087: * @return state of the home icon
088: */
089: public static boolean getHomeIconState() {
090: return homeIconState;
091: }
092:
093: /**
094: * Called when a MIDlet is added to the list.
095: *
096: * @param midlet The proxy of the MIDlet being added
097: */
098: public void midletAdded(MIDletProxy midlet) {
099: // IndicatorManager does not care if midlet is added
100: }
101:
102: /**
103: * Called when a MIDlet is removed from the list.
104: *
105: * @param midlet The proxy of the MIDlet being removed
106: */
107: public void midletRemoved(MIDletProxy midlet) {
108: setHomeIconState(midletProxyList.isAlertWaitingInBackground());
109: }
110:
111: /**
112: * Called when the state of a MIDlet in the list is updated.
113: *
114: * @param midlet The proxy of the MIDlet being updated
115: * @param fieldId code for which field of the proxy was updated
116: */
117: public void midletUpdated(MIDletProxy midlet, int fieldId) {
118: setHomeIconState(midletProxyList.isAlertWaitingInBackground());
119: }
120:
121: /**
122: * Called when error occurred while starting a MIDlet object.
123: *
124: * @param externalAppId ID assigned by the external application manager
125: * @param suiteId Suite ID of the MIDlet
126: * @param className Class name of the MIDlet
127: * @param errorCode start error code
128: * @param errorDetails start error details
129: */
130: public void midletStartError(int externalAppId, int suiteId,
131: String className, int errorCode, String errorDetails) {
132: }
133:
134: }
|