Add sharpening filter to this implementation too
[zxing.git] / javame / src / com / google / zxing / client / j2me / VideoCanvas.java
index d942d06..b775019 100644 (file)
@@ -23,6 +23,9 @@ import javax.microedition.lcdui.Displayable;
 import javax.microedition.lcdui.Graphics;
 
 /**
+ * The main {@link Canvas} onto which the camera's field of view is painted.
+ * This class manages decoding via {@link SnapshotThread}.
+ *
  * @author Sean Owen (srowen@google.com)
  */
 final class VideoCanvas extends Canvas implements CommandListener {
@@ -30,11 +33,14 @@ final class VideoCanvas extends Canvas implements CommandListener {
   private static final Command exit = new Command("Exit", Command.EXIT, 1);
 
   private final ZXingMIDlet zXingMIDlet;
+  private final SnapshotThread snapshotThread;
 
   VideoCanvas(ZXingMIDlet zXingMIDlet) {
     this.zXingMIDlet = zXingMIDlet;
     addCommand(exit);
     setCommandListener(this);
+    snapshotThread = new SnapshotThread(zXingMIDlet);
+    new Thread(snapshotThread).start();
   }
 
   protected void paint(Graphics graphics) {
@@ -42,14 +48,18 @@ final class VideoCanvas extends Canvas implements CommandListener {
   }
 
   protected void keyPressed(int keyCode) {
-    // Use the "FIRE" key as a "take snapshot" key
-    if (FIRE == getGameAction(keyCode)) {
-      SnapshotThread.startThread(zXingMIDlet);
+    // Any valid game key will trigger a capture
+    if (getGameAction(keyCode) != 0) {
+      snapshotThread.continueRun();
+    } else {
+      super.keyPressed(keyCode);
     }
   }
 
   public void commandAction(Command command, Displayable displayable) {
-    if (command.getCommandType() == Command.EXIT || command.getCommandType() == Command.STOP) {
+    int type = command.getCommandType();
+    if (type == Command.EXIT || type == Command.STOP || type == Command.BACK || type == Command.CANCEL) {
+      snapshotThread.stop();
       zXingMIDlet.stop();
     }
   }