From: srowen Date: Fri, 15 Feb 2008 15:15:57 +0000 (+0000) Subject: Progress on a crude Blackberry client -- still needs much polish but basic functional... X-Git-Url: http://git.rot13.org/?p=zxing.git;a=commitdiff_plain;h=55937e92102b86ece5f367d98e44907aa70bd6f1 Progress on a crude Blackberry client -- still needs much polish but basic functionality exists. git-svn-id: http://zxing.googlecode.com/svn/trunk@203 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/build.xml b/build.xml index cda6f787..ad39236a 100644 --- a/build.xml +++ b/build.xml @@ -25,6 +25,7 @@ + @@ -37,6 +38,7 @@ + @@ -55,8 +57,10 @@ - + + + @@ -71,6 +75,7 @@ + @@ -78,6 +83,7 @@ + diff --git a/javame/build.xml b/javame/build.xml index 26929ba7..130eb8bb 100644 --- a/javame/build.xml +++ b/javame/build.xml @@ -78,6 +78,7 @@ fork="true"> + @@ -107,13 +108,14 @@ + - + diff --git a/rim/BarcodeReader.rapc b/rim/BarcodeReader.rapc new file mode 100644 index 00000000..0e653486 --- /dev/null +++ b/rim/BarcodeReader.rapc @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +RIM-COD-Module-Name: BarcodeReader +RIM-COD-Module-Dependencies: net_rim_cldc,net_rim_bbapi_invoke +MIDlet-Jar-Size: 31621 +MIDlet-1: BarcodeReader,,com.google.zxing.client.rim.ZXingUIApp +RIM-COD-Creation-Time: 1203088206 +MIDlet-Jar-URL: BarcodeReader.jar +RIM-COD-URL: BarcodeReader.cod +RIM-COD-SHA1: 82 7e 06 9b 39 6e 8c 49 33 54 37 1d 6d 3d 7b 07 d1 86 c8 d3 +RIM-COD-Size: 56372 +MicroEdition-Configuration: CLDC-1.1 +MIDlet-Version: 0.5 +MIDlet-Name: BarcodeReader +MIDlet-Vendor: ZXing Project +MicroEdition-Profile: MIDP-2.0 +RIM-MIDlet-Flags-1: 0 diff --git a/rim/build.xml b/rim/build.xml index 0e7f71e2..462f6b5a 100644 --- a/rim/build.xml +++ b/rim/build.xml @@ -19,6 +19,7 @@ + @@ -29,29 +30,75 @@ - + - + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + + + + + + + + diff --git a/rim/res/zxing-icon.png b/rim/res/zxing-icon.png new file mode 100644 index 00000000..ee33194c Binary files /dev/null and b/rim/res/zxing-icon.png differ diff --git a/rim/src/com/google/zxing/client/rim/ImageCapturedJournalListener.java b/rim/src/com/google/zxing/client/rim/ImageCapturedJournalListener.java new file mode 100644 index 00000000..229131d4 --- /dev/null +++ b/rim/src/com/google/zxing/client/rim/ImageCapturedJournalListener.java @@ -0,0 +1,50 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.rim; + +import net.rim.device.api.io.file.FileSystemJournal; +import net.rim.device.api.io.file.FileSystemJournalEntry; +import net.rim.device.api.io.file.FileSystemJournalListener; + +/** + * @author Sean Owen (srowen@google.com) + */ +final class ImageCapturedJournalListener implements FileSystemJournalListener { + + private final ZXingMainScreen screen; + private long lastUSN; + + ImageCapturedJournalListener(ZXingMainScreen screen) { + this.screen = screen; + } + + public void fileJournalChanged() { + long nextUSN = FileSystemJournal.getNextUSN(); + for (long lookUSN = nextUSN - 1; lookUSN >= lastUSN; --lookUSN) { + FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); + if (entry == null) { + break; + } + if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED) { + screen.handleFile(entry.getPath()); + } + } + lastUSN = nextUSN; + } + + +} diff --git a/rim/src/com/google/zxing/client/rim/ZXingMainScreen.java b/rim/src/com/google/zxing/client/rim/ZXingMainScreen.java new file mode 100644 index 00000000..9ded1ed6 --- /dev/null +++ b/rim/src/com/google/zxing/client/rim/ZXingMainScreen.java @@ -0,0 +1,119 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.rim; + +import com.google.zxing.MonochromeBitmapSource; +import com.google.zxing.MultiFormatReader; +import com.google.zxing.Reader; +import com.google.zxing.ReaderException; +import com.google.zxing.Result; +import com.google.zxing.client.j2me.LCDUIImageMonochromeBitmapSource; +import net.rim.blackberry.api.invoke.CameraArguments; +import net.rim.blackberry.api.invoke.Invoke; +import net.rim.device.api.system.Characters; +import net.rim.device.api.ui.UiApplication; +import net.rim.device.api.ui.component.Dialog; +import net.rim.device.api.ui.component.LabelField; +import net.rim.device.api.ui.container.MainScreen; + +import javax.microedition.io.Connector; +import javax.microedition.io.file.FileConnection; +import javax.microedition.lcdui.Image; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Sean Owen (srowen@google.com) + */ +final class ZXingMainScreen extends MainScreen { + + private final ZXingUIApp app; + private final ImageCapturedJournalListener captureListener; + + ZXingMainScreen() { + setTitle("Barcode Reader"); + add(new LabelField("ZXing")); + app = (ZXingUIApp) UiApplication.getUiApplication(); + captureListener = new ImageCapturedJournalListener(this); + app.addFileSystemJournalListener(captureListener); + } + + public boolean keyChar(char c, int status, int time) { + if (c == Characters.ENTER) { + Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments()); + return true; + } else { + return super.keyChar(c, status, time); + } + } + + public void close() { + app.removeFileSystemJournalListener(captureListener); + super.close(); + } + + private void showMessage(String msg) { + synchronized (app.getAppEventLock()) { + Dialog.alert(msg); + } + } + + void handleFile(String path) { + if (path.endsWith(".jpg") && path.indexOf("IMG") >= 0) { + app.requestForeground(); + try { + FileConnection file = null; + InputStream is = null; + Image capturedImage; + try { + file = (FileConnection) Connector.open("file://" + path); + is = file.openInputStream(); + capturedImage = Image.createImage(is); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException ioe ) { + // continue + } + } + if (file != null) { + try { + file.close(); + } catch (IOException ioe ) { + // continue + } + } + } + MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage); + Reader reader = new MultiFormatReader(); + Result result = reader.decode(source); + try { + file.delete(); + } catch (IOException ioe) { + // continue + } + showMessage(result.getText()); + } catch (IOException ioe) { + showMessage(ioe.getMessage()); + } catch (ReaderException re) { + showMessage("Sorry, no barcode was found."); + } + } + } + +} diff --git a/rim/src/com/google/zxing/client/rim/ZXingUIApp.java b/rim/src/com/google/zxing/client/rim/ZXingUIApp.java new file mode 100644 index 00000000..08e00601 --- /dev/null +++ b/rim/src/com/google/zxing/client/rim/ZXingUIApp.java @@ -0,0 +1,34 @@ +/* + * Copyright 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.rim; + +import net.rim.device.api.ui.UiApplication; + +/** + * @author Sean Owen (srowen@google.com) + */ +public final class ZXingUIApp extends UiApplication { + + public static void main(String[] args) { + new ZXingUIApp().enterEventDispatcher(); + } + + ZXingUIApp() { + pushScreen(new ZXingMainScreen()); + } + +}