X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=javame%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2me%2FZXingMIDlet.java;fp=javame%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2me%2FZXingMIDlet.java;h=f07d81387f9c56de148ec6df864f57783d0d7dc9;hp=7e8c2bc3bb00f9550c2a38d84598ebae64f495b4;hb=09f9abf90c009a1672088eb54279d9bea43d43be;hpb=e8d7c20c77be36722cb480b8eb80e180e39e55a2 diff --git a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java index 7e8c2bc3..f07d8138 100644 --- a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java +++ b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java @@ -54,6 +54,8 @@ public final class ZXingMIDlet extends MIDlet { private Canvas canvas; private Player player; private VideoControl videoControl; + private Alert confirmation; + private Alert alert; Displayable getCanvas() { return canvas; @@ -94,6 +96,17 @@ public final class ZXingMIDlet extends MIDlet { } catch (MediaException me) { throw new MIDletStateChangeException(me.toString()); } + + // Set up one confirmation and alert object to re-use + confirmation = new Alert(null); + confirmation.setType(AlertType.CONFIRMATION); + confirmation.setTimeout(ALERT_TIMEOUT_MS); + Command yes = new Command("Yes", Command.OK, 1); + confirmation.addCommand(yes); + Command no = new Command("No", Command.CANCEL, 1); + confirmation.addCommand(no); + alert = new Alert(null); + alert.setTimeout(ALERT_TIMEOUT_MS); } private static Player createPlayer() throws IOException, MediaException { @@ -149,12 +162,8 @@ public final class ZXingMIDlet extends MIDlet { // Convenience methods to show dialogs private void showOpenURL(String title, String display, final String uri) { - Alert alert = new Alert(title, display, null, AlertType.CONFIRMATION); - alert.setTimeout(ALERT_TIMEOUT_MS); - Command yes = new Command("Yes", Command.OK, 1); - alert.addCommand(yes); - Command no = new Command("No", Command.CANCEL, 1); - alert.addCommand(no); + confirmation.setTitle(title); + confirmation.setString(display); CommandListener listener = new CommandListener() { public void commandAction(Command command, Displayable displayable) { if (command.getCommandType() == Command.OK) { @@ -171,13 +180,14 @@ public final class ZXingMIDlet extends MIDlet { } } }; - alert.setCommandListener(listener); - showAlert(alert); + confirmation.setCommandListener(listener); + showAlert(confirmation); } private void showAlert(String title, String text) { - Alert alert = new Alert(title, text, null, AlertType.INFO); - alert.setTimeout(ALERT_TIMEOUT_MS); + alert.setTitle(title); + alert.setString(text); + alert.setType(AlertType.INFO); showAlert(alert); } @@ -191,7 +201,10 @@ public final class ZXingMIDlet extends MIDlet { } void showError(String message) { - showAlert(new Alert("Error", message, null, AlertType.ERROR)); + alert.setTitle("Error"); + alert.setString(message); + alert.setType(AlertType.ERROR); + showAlert(alert); } private void showAlert(Alert alert) {