2e361dd6fd91a8f880f5e397e92aa1d9e446c155
[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 decode = new Command("Decode", Command.SCREEN, 1);
31   private static final Command exit = new Command("Exit", Command.EXIT, 1);
32
33   private final ZXingMIDlet zXingMIDlet;
34
35   VideoCanvas(ZXingMIDlet zXingMIDlet) {
36     this.zXingMIDlet = zXingMIDlet;
37     addCommand(decode);
38     addCommand(exit);
39     setCommandListener(this);
40   }
41
42   protected void paint(Graphics graphics) {
43     // do nothing
44   }
45
46   protected void keyPressed(int keyCode) {
47     // Use the "FIRE" key as a "take snapshot" key
48     if (FIRE == getGameAction(keyCode)) {
49       SnapshotThread.startThread(zXingMIDlet);
50     }
51   }
52
53   public void commandAction(Command command, Displayable displayable) {
54     if (command.equals(decode)) {
55       SnapshotThread.startThread(zXingMIDlet);
56     } else if (command.equals(exit)) {
57       zXingMIDlet.stop();
58     }
59   }
60 }