- private class VideoCanvas extends Canvas implements CommandListener {
- private final Command decode = new Command("Decode", Command.SCREEN, 1);
- private final Command exit = new Command("Exit", Command.EXIT, 1);
- private VideoCanvas() {
- addCommand(decode);
- addCommand(exit);
- setCommandListener(this);
- }
- protected void paint(Graphics graphics) {
- // do nothing
- }
- protected void keyPressed(int keyCode) {
- if (FIRE == getGameAction(keyCode)) {
- new SnapshotThread().start();
- }
- }
- public void commandAction(Command command, Displayable displayable) {
- if (command.equals(decode)) {
- new SnapshotThread().start();
- } else if (command.equals(exit)) {
- destroyApp(false);
- notifyDestroyed();
- }
- }
- }
-
- // TODO make sure we do not start two threads at once
- private class SnapshotThread extends Thread {
- public void run() {
- try {
- player.stop();
- byte[] snapshot = videoControl.getSnapshot(null);
- Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
- MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage);
- Reader reader = new MultiFormatReader();
- Result result = reader.decode(source);
- showAlert("Barcode detected", result.getText());
- } catch (ReaderException re) {
- showError(re);
- } catch (MediaException me) {
- showError(me);
- } catch (Throwable t) {
- showError(t);
- } finally {
- try {
- player.start();
- } catch (MediaException me) {
- // continue?
- showError(me);
- }
- }
-
+ void handleDecodedText(String text) {
+ ParsedReaderResult result = ParsedReaderResult.parseReaderResult(text);
+ ParsedReaderResultType type = result.getType();
+ if (type.equals(ParsedReaderResultType.URI)) {
+ String uri = ((URIParsedResult) result).getURI();
+ showOpenURL("Open web page?", uri, uri);
+ } else if (type.equals(ParsedReaderResultType.BOOKMARK)) {
+ String uri = ((BookmarkDoCoMoResult) result).getURI();
+ showOpenURL("Open web page?", uri, uri);
+ } else if (type.equals(ParsedReaderResultType.EMAIL)) {
+ String email = ((EmailDoCoMoResult) result).getTo();
+ showOpenURL("Compose e-mail?", email, "mailto:" + email);
+ } else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) {
+ String email = ((EmailAddressResult) result).getEmailAddress();
+ showOpenURL("Compose e-mail?", email, "mailto:" + email);
+ } else if (type.equals(ParsedReaderResultType.UPC)) {
+ String upc = ((UPCParsedResult) result).getUPC();
+ String uri = "http://www.upcdatabase.com/item.asp?upc=" + upc;
+ showOpenURL("Look up UPC?", upc, uri);
+ } else {
+ showAlert("Barcode detected", result.getDisplayResult());