2 * Copyright 2007 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.Command;
21 import javax.microedition.lcdui.CommandListener;
22 import javax.microedition.lcdui.Displayable;
23 import javax.microedition.lcdui.Graphics;
26 * The main {@link Canvas} onto which the camera's field of view is painted.
27 * This class manages decoding via {@link SnapshotThread}.
31 final class VideoCanvas extends Canvas implements CommandListener {
33 private static final Command exit = new Command("Exit", Command.EXIT, 1);
35 private final ZXingMIDlet zXingMIDlet;
36 private final SnapshotThread snapshotThread;
38 VideoCanvas(ZXingMIDlet zXingMIDlet) {
39 this.zXingMIDlet = zXingMIDlet;
41 setCommandListener(this);
42 snapshotThread = new SnapshotThread(zXingMIDlet);
43 new Thread(snapshotThread).start();
46 protected void paint(Graphics graphics) {
50 protected void keyPressed(int keyCode) {
51 // Any valid game key will trigger a capture
52 if (getGameAction(keyCode) != 0) {
53 snapshotThread.continueRun();
55 super.keyPressed(keyCode);
59 public void commandAction(Command command, Displayable displayable) {
60 int type = command.getCommandType();
61 if (type == Command.EXIT || type == Command.STOP || type == Command.BACK || type == Command.CANCEL) {
62 snapshotThread.stop();