2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.client.j2me;
\r
19 import javax.microedition.lcdui.Canvas;
\r
20 import javax.microedition.lcdui.Command;
\r
21 import javax.microedition.lcdui.CommandListener;
\r
22 import javax.microedition.lcdui.Displayable;
\r
23 import javax.microedition.lcdui.Graphics;
\r
26 * The main {@link Canvas} onto which the camera's field of view is painted.
\r
27 * This class manages decoding via {@link SnapshotThread}.
\r
30 * @author Simon Flannery
\r
32 final class VideoCanvas extends Canvas implements CommandListener {
\r
34 private static final Command exit = new Command("Exit", Command.EXIT, 1);
\r
35 private static final Command history = new Command("History", Command.ITEM, 0);
\r
37 private final ZXingMIDlet zXingMIDlet;
\r
38 private final SnapshotThread snapshotThread;
\r
40 VideoCanvas(ZXingMIDlet zXingMIDlet) {
\r
41 this.zXingMIDlet = zXingMIDlet;
\r
43 addCommand(history);
\r
44 setCommandListener(this);
\r
45 snapshotThread = new SnapshotThread(zXingMIDlet);
\r
46 new Thread(snapshotThread).start();
\r
49 protected void paint(Graphics graphics) {
\r
53 protected void keyPressed(int keyCode) {
\r
54 // Any valid game key will trigger a capture
\r
55 if (getGameAction(keyCode) != 0) {
\r
56 snapshotThread.continueRun();
\r
58 super.keyPressed(keyCode);
\r
62 public void commandAction(Command command, Displayable displayable) {
\r
63 int type = command.getCommandType();
\r
64 if (command == history) {
\r
65 zXingMIDlet.historyRequest();
\r
66 } else if (type == Command.EXIT || type == Command.STOP || type == Command.BACK || type == Command.CANCEL) {
\r
67 snapshotThread.stop();
\r