Finally, much better support for auto-focus, other UI fixes. Now requires JSR-234.
[zxing.git] / javame / src / com / google / zxing / client / j2me / VideoCanvas.java
1 /*
2  * Copyright 2007 Google Inc.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.j2me;
18
19 import javax.microedition.lcdui.Canvas;
20 import javax.microedition.lcdui.Command;
21 import javax.microedition.lcdui.CommandListener;
22 import javax.microedition.lcdui.Displayable;
23 import javax.microedition.lcdui.Graphics;
24
25 /**
26  * @author Sean Owen (srowen@google.com)
27  */
28 final class VideoCanvas extends Canvas implements CommandListener {
29
30   private static final Command exit = new Command("Exit", Command.EXIT, 1);
31
32   private final ZXingMIDlet zXingMIDlet;
33
34   VideoCanvas(ZXingMIDlet zXingMIDlet) {
35     this.zXingMIDlet = zXingMIDlet;
36     addCommand(exit);
37     setCommandListener(this);
38   }
39
40   protected void paint(Graphics graphics) {
41     // do nothing
42   }
43
44   protected void keyPressed(int keyCode) {
45     // Use the "FIRE" key as a "take snapshot" key
46     if (FIRE == getGameAction(keyCode)) {
47       SnapshotThread.startThread(zXingMIDlet);
48     }
49   }
50
51   public void commandAction(Command command, Displayable displayable) {
52     if (command.getCommandType() == Command.EXIT || command.getCommandType() == Command.STOP) {
53       zXingMIDlet.stop();
54     }
55   }
56 }