001: /*
002: *
003: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: package com.sun.mmedia;
027:
028: import java.util.Vector;
029: import com.sun.midp.midlet.*;
030: import com.sun.midp.main.MIDletSuiteLoader;
031:
032: /**
033: * Tunnel between media and lcdui
034: * This is a singleton object per JVM
035: */
036: public final class MediaTunnel {
037:
038: /* Playable from background? */
039: public final static int PLAYABLE_FROM_BACKGROUND = 1;
040:
041: private static MediaTunnel instance;
042: private Vector map;
043: private boolean hasForeground = true;
044:
045: private MediaTunnel() {
046: }
047:
048: /**
049: * Is this midlet background playable?
050: */
051: public boolean isBackPlayable() {
052: return false;
053: }
054:
055: /**
056: * Get media tunnel singleton object
057: */
058: public static MediaTunnel getInstance() {
059: if (instance == null) {
060: instance = new MediaTunnel();
061: }
062: return instance;
063: }
064:
065: /**
066: * Register media event consumer
067: *
068: * @retval true if the current status is in foreground
069: * @retval false if the current status is in background
070: */
071: public synchronized boolean registerMediaEventConsumer(
072: MediaEventConsumer consumer) {
073: if (map == null) {
074: map = new Vector(5);
075: }
076:
077: if (false == map.contains(consumer)) {
078: map.addElement(consumer);
079: }
080:
081: return hasForeground;
082: }
083:
084: /**
085: * Register media event consumer
086: *
087: * @retval true if the current status is in foreground
088: * @retval false if the current status is in background
089: */
090: public synchronized void unregisterMediaEventConsumer(
091: MediaEventConsumer consumer) {
092: if (map == null) {
093: return;
094: }
095:
096: if (true == map.contains(consumer)) {
097: map.removeElement(consumer);
098: }
099: }
100:
101: /**
102: * Notify media event consumer about the switch to foreground
103: */
104: public synchronized void callForegroundEventHandler() {
105: if (map == null) {
106: return;
107: }
108:
109: int size = map.size();
110: hasForeground = true;
111:
112: for (int i = 0; i < size; ++i) {
113: MediaEventConsumer c = (MediaEventConsumer) map
114: .elementAt(i);
115: c.handleMediaForegroundNotify();
116: }
117: }
118:
119: /**
120: * Notify media event consumer about the switch to background
121: */
122: public synchronized void callBackgroundEventHandler() {
123: if (map == null) {
124: return;
125: }
126:
127: int size = map.size();
128: hasForeground = false;
129:
130: for (int i = 0; i < size; ++i) {
131: MediaEventConsumer c = (MediaEventConsumer) map
132: .elementAt(i);
133: c.handleMediaBackgroundNotify();
134: }
135: }
136: }
|