- private static class VideoCanvas extends Canvas {
- protected void paint(Graphics graphics) {
- // do nothing
- }
- }
-
- 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);
+ /// TODO this whole bit needs to be merged with the code in core-ext -- this is messy and duplicative
+
+ void handleDecodedText(String text) {
+ // This is a crude imitation of the code found in module core-ext, which handles the contents
+ // in a more sophisticated way. It can't be accessed from JavaME just yet because it relies
+ // on URL parsing routines in java.net. This should be somehow worked around: TODO
+ // For now, detect URLs in a simple way, and treat everything else as text
+ if (text.startsWith("http://") || text.startsWith("https://")) {
+ showOpenURL(text);
+ } else if (text.startsWith("HTTP://") || text.startsWith("HTTPS://")) {
+ showOpenURL(decapitalizeProtocol(text));
+ } else if (text.startsWith("URL:")) {
+ showOpenURL(decapitalizeProtocol(text.substring(4)));
+ } else if (text.startsWith("MEBKM:")) {
+ int urlIndex = text.indexOf("URL:", 6);
+ if (urlIndex >= 6) {
+ String url = text.substring( urlIndex + 4);
+ int semicolon = url.indexOf((int) ';');
+ if (semicolon >= 0) {
+ url = url.substring(0, semicolon);