X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=javame%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2me%2FZXingMIDlet.java;h=9c9f5a3d00e4c2c08e80efe4671581afb64291ac;hb=4dcf4bb58ba7739c697e2d37b4f49d74f1a2fcb0;hp=a3bfc24f01108bda7db5efe667f4ff1046559be2;hpb=037a09d9c9dee9e16c8ed21270469570d23efa37;p=zxing.git diff --git a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java index a3bfc24f..9c9f5a3d 100644 --- a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java +++ b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java @@ -21,6 +21,7 @@ import com.google.zxing.client.result.EmailAddressResult; import com.google.zxing.client.result.EmailDoCoMoResult; import com.google.zxing.client.result.ParsedReaderResult; import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.UPCParsedResult; import com.google.zxing.client.result.URIParsedResult; import javax.microedition.io.ConnectionNotFoundException; @@ -60,7 +61,7 @@ public final class ZXingMIDlet extends MIDlet { protected void startApp() throws MIDletStateChangeException { try { - player = Manager.createPlayer("capture://video"); + player = createPlayer(); player.realize(); AdvancedMultimediaManager.setZoom(player); videoControl = (VideoControl) player.getControl("VideoControl"); @@ -79,6 +80,23 @@ public final class ZXingMIDlet extends MIDlet { } } + private static Player createPlayer() throws IOException, MediaException { + // Try a workaround for Nokias, which want to use capture://image in some cases + Player player = null; + String platform = System.getProperty("microedition.platform"); + if (platform != null && platform.indexOf("Nokia") >= 0) { + try { + player = Manager.createPlayer("capture://image"); + } catch (MediaException me) { + // if this fails, just continue with capture://video + } + } + if (player == null) { + player = Manager.createPlayer("capture://video"); + } + return player; + } + protected void pauseApp() { if (player != null) { try { @@ -114,8 +132,10 @@ public final class ZXingMIDlet extends MIDlet { private void showOpenURL(String title, final String display, final String uri) { Alert alert = new Alert(title, display, null, AlertType.CONFIRMATION); alert.setTimeout(Alert.FOREVER); - final Command cancel = new Command("Cancel", Command.CANCEL, 1); - alert.addCommand(cancel); + Command yes = new Command("Yes", Command.OK, 1); + alert.addCommand(yes); + Command no = new Command("No", Command.CANCEL, 1); + alert.addCommand(no); CommandListener listener = new CommandListener() { public void commandAction(Command command, Displayable displayable) { if (command.getCommandType() == Command.OK) { @@ -143,7 +163,12 @@ public final class ZXingMIDlet extends MIDlet { } void showError(Throwable t) { - showError(t.getMessage()); + String message = t.getMessage(); + if (message != null && message.length() > 0) { + showError(message); + } else { + showError(t.toString()); + } } void showError(String message) { @@ -170,6 +195,10 @@ public final class ZXingMIDlet extends MIDlet { } 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()); }