2 * Copyright 2009 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.j2me;
19 import javax.microedition.lcdui.Canvas;
20 import javax.microedition.lcdui.Font;
21 import javax.microedition.lcdui.Graphics;
22 import javax.microedition.lcdui.Image;
25 * <p>Any professional software renders a "splash" screen which not only looks
26 * great, but also keeps a user entertained (and instantly acknowledging the
27 * user's request to load the application) while important application
28 * background initialisation takes place.</p>
30 * @author Simon Flannery (Ericsson)
32 class SplashThread extends Canvas implements Runnable {
34 private final ZXingMIDlet zXingMIDlet;
35 private final long tout;
36 private final Image image;
39 * Creates a new Splash Canvas with the given Parent Form and self Time out
40 * dismissal. The Time out is described in milliseconds. If the Time out is
41 * assigned Zero, then the Splash Screen will NOT Self dismiss!
43 * When the Splash Screen is dismissed, the splashDone method of the parent form
46 * The Splash screen may be dismissed using any of the following procedures:
47 * (1) The specified timeout has elapsed. (Recommended). If Time out is zero
48 * however, then the timeout is not taken into consideration and the Splash
49 * screen simply waits (forever) until notified (see below)!
50 * (2) By invoking the stop method. (Recommended). This would be used to
51 * prematurely dismiss the splash screen BEFORE timeout has been reached
52 * or if a timeout of Zero was given.
54 * @param parent ZXing MIDlet Parent.
55 * @param timeOut timeout in milliseconds.
56 * @param splashImage image to display.
58 SplashThread(ZXingMIDlet parent, long timeOut, Image splashImage) {
62 setFullScreenMode(true);
63 new Thread(this).start();
67 * Thread Implementation Required. Invoked via calling start method.
68 * DO NOT manually call this method!
74 wait(tout); // Let's wake up
75 } catch (InterruptedException ie) {
76 // will not occur in MIDP, no thread interrupt method
80 zXingMIDlet.splashDone();
84 * Allows Early dismissal of the splash Screen, for example, when all background
85 * initialisations are complete.
88 // Invoke the notify method of the Splash Object ("and the correct thread just
89 // happens to be arbitrarily chosen as the thread to be awakened"), and thus
90 // dismiss the Splash Screen. The current implementation only uses a single
91 // thread, so invoking the notify method should work, however, the
92 // implementation may change in the future. Thus lets' make use of the
93 // notifyAll method of the Splash Object.
95 notifyAll(); // Wake everyone up
100 * Must provide this implementation - used to paint the canvas.
102 * @param g Some Canvas Graphics.
104 public void paint(Graphics g) {
105 int width = getWidth();
106 int height = getHeight();
108 g.setColor(0x00FFFFFF);
109 g.fillRect(0, 0, width, height);
112 g.drawImage(image, width / 2, height / 2, Graphics.VCENTER | Graphics.HCENTER);
115 Font F = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL);
118 g.setColor(0x00000000);
120 String vendor = zXingMIDlet.getAppProperty("MIDlet-Description");
122 if (vendor != null) {
123 g.drawString(vendor, width / 2, height - (height / 8), Graphics.BOTTOM | Graphics.HCENTER);