2 * Copyright 2008 Google Inc.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.client.rim;
\r
19 import com.google.zxing.MonochromeBitmapSource;
\r
20 import com.google.zxing.MultiFormatReader;
\r
21 import com.google.zxing.Reader;
\r
22 import com.google.zxing.ReaderException;
\r
23 import com.google.zxing.Result;
\r
24 import com.google.zxing.client.j2me.LCDUIImageMonochromeBitmapSource;
\r
25 import net.rim.blackberry.api.invoke.CameraArguments;
\r
26 import net.rim.blackberry.api.invoke.Invoke;
\r
27 import net.rim.device.api.system.Characters;
\r
28 import net.rim.device.api.ui.UiApplication;
\r
29 import net.rim.device.api.ui.component.Dialog;
\r
30 import net.rim.device.api.ui.component.LabelField;
\r
31 import net.rim.device.api.ui.container.MainScreen;
\r
33 import javax.microedition.io.Connector;
\r
34 import javax.microedition.io.file.FileConnection;
\r
35 import javax.microedition.lcdui.Image;
\r
36 import java.io.IOException;
\r
37 import java.io.InputStream;
\r
40 * @author Sean Owen (srowen@google.com)
\r
42 final class ZXingMainScreen extends MainScreen {
\r
44 private final ZXingUIApp app;
\r
45 private final ImageCapturedJournalListener captureListener;
\r
48 setTitle("Barcode Reader");
\r
49 add(new LabelField("ZXing"));
\r
50 app = (ZXingUIApp) UiApplication.getUiApplication();
\r
51 captureListener = new ImageCapturedJournalListener(this);
\r
52 app.addFileSystemJournalListener(captureListener);
\r
55 public boolean keyChar(char c, int status, int time) {
\r
56 if (c == Characters.ENTER) {
\r
57 Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
\r
60 return super.keyChar(c, status, time);
\r
64 public void close() {
\r
65 app.removeFileSystemJournalListener(captureListener);
\r
69 private void showMessage(String msg) {
\r
70 synchronized (app.getAppEventLock()) {
\r
75 void handleFile(String path) {
\r
76 if (path.endsWith(".jpg") && path.indexOf("IMG") >= 0) {
\r
77 app.requestForeground();
\r
79 FileConnection file = null;
\r
80 InputStream is = null;
\r
81 Image capturedImage;
\r
83 file = (FileConnection) Connector.open("file://" + path);
\r
84 is = file.openInputStream();
\r
85 capturedImage = Image.createImage(is);
\r
90 } catch (IOException ioe ) {
\r
97 } catch (IOException ioe ) {
\r
102 MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage);
\r
103 Reader reader = new MultiFormatReader();
\r
104 Result result = reader.decode(source);
\r
107 } catch (IOException ioe) {
\r
110 showMessage(result.getText());
\r
111 } catch (IOException ioe) {
\r
112 showMessage(ioe.getMessage());
\r
113 } catch (ReaderException re) {
\r
114 showMessage("Sorry, no barcode was found.");
\r