001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package com.sun.perseus.demo;
033:
034: import java.io.InputStream;
035: import java.io.IOException;
036:
037: import javax.microedition.midlet.MIDlet;
038:
039: import javax.microedition.lcdui.Canvas;
040: import javax.microedition.lcdui.Display;
041: import javax.microedition.lcdui.Displayable;
042:
043: import javax.microedition.m2g.SVGImage;
044: import javax.microedition.m2g.SVGAnimator;
045:
046: import com.sun.svg.component.LoadingScreen;
047: import com.sun.svg.util.DefaultSVGAnimator;
048:
049: public class ContactListMidlet extends MIDlet implements
050: LoadingScreen.Listener {
051: /**
052: * List of skins
053: */
054: private static final String[] SKIN_DIRS = { "/skin1", "/skin2" };
055:
056: /**
057: * List of skin file sizes
058: */
059: private static final int[] SKINS_SIZES = { 38000, 38000 };
060:
061: /**
062: * This contact list's skin index.
063: */
064: private final int skinIndex;
065:
066: private final Display display;
067:
068: private ContactListScreen contactListScreen;
069:
070: private boolean loading;
071:
072: /** Creates a new instance of ContactListMidlet */
073: protected ContactListMidlet(int skinIndex) {
074: this .skinIndex = skinIndex;
075: this .display = Display.getDisplay(this );
076: }
077:
078: synchronized public void startApp() {
079: if ((contactListScreen == null) && (!loading)) {
080: InputStream imageStream = ContactListMidlet.class
081: .getResourceAsStream(SKIN_DIRS[skinIndex]
082: + "/loadScreen.svg");
083: if (imageStream == null) {
084: destroyApp(false);
085: notifyDestroyed();
086: return;
087: }
088: SVGImage loadingImage;
089: try {
090: try {
091: loadingImage = (SVGImage) SVGImage.createImage(
092: imageStream, null);
093: } finally {
094: try {
095: imageStream.close();
096: } catch (IOException e) {
097: // ignore
098: }
099: }
100: } catch (IOException e) {
101: destroyApp(false);
102: notifyDestroyed();
103: return;
104: }
105:
106: SVGAnimator loadingAnimator = DefaultSVGAnimator
107: .createAnimator(loadingImage);
108: Canvas loadingCanvas = (Canvas) loadingAnimator
109: .getTargetComponent();
110: display.setCurrent(loadingCanvas);
111:
112: // start the loading of the contact list svg file
113: new LoadingScreen(loadingAnimator, loadingImage,
114: SKIN_DIRS[skinIndex] + "/list.svg",
115: SKINS_SIZES[skinIndex], this );
116:
117: loading = true;
118: }
119: }
120:
121: synchronized public void svgImageLoaded(SVGImage svgImage) {
122: SVGAnimator contactListAnimator = DefaultSVGAnimator
123: .createAnimator(svgImage);
124: ContactListSource contactListSource = new ContactListSource();
125: Canvas contactListCanvas = (Canvas) contactListAnimator
126: .getTargetComponent();
127: display.setCurrent(contactListCanvas);
128:
129: contactListScreen = new ContactListScreen(contactListAnimator,
130: svgImage, contactListSource);
131:
132: loading = false;
133: }
134:
135: public void pauseApp() {
136: }
137:
138: public void destroyApp(boolean unconditional) {
139: }
140: }
|