Search in sources :

Example 1 with ScanResult

use of com.codename1.ext.codescan.ScanResult in project CodenameOne by codenameone.

the class BarCodeScanner method startScaning.

private void startScaning(ScanResult callback) {
    this.callback = callback;
    try {
        // Add the listener for scan and cancel
        Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
        Button scanButton = new Button(new Command("Scan") {

            public void actionPerformed(ActionEvent evt) {
                cameraForm.repaint();
                if (snapshotThread != null) {
                    snapshotThread.continueRun();
                }
            }
        });
        Button cancelButton = new Button(new Command("Cancel") {

            public void actionPerformed(ActionEvent evt) {
                if (snapshotThread != null) {
                    snapshotThread.stop();
                    cancelScan();
                }
            }
        });
        cmdContainer.addComponent(scanButton);
        cmdContainer.addComponent(cancelButton);
        cameraForm = new Form();
        cameraForm.setScrollable(false);
        cameraForm.setLayout(new BorderLayout());
        cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
        cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
    } catch (Exception e) {
        // throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
        e.printStackTrace();
    }
    startScan();
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 2 with ScanResult

use of com.codename1.ext.codescan.ScanResult in project CodenameOne by codenameone.

the class ComponentTest method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    hi.show();
    if (System.currentTimeMillis() < 100) {
        QRScanner.scanQRCode(new ScanResult() {

            public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
                Dialog.show("Completed", contents, "OK", null);
            }

            public void scanCanceled() {
                Dialog.show("Cancelled", "Scan Cancelled", "OK", null);
            }

            public void scanError(int errorCode, String message) {
                Dialog.show("Error", message, "OK", null);
            }
        });
    }
}
Also used : ScanResult(com.codename1.ext.codescan.ScanResult) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label)

Aggregations

Form (com.codename1.ui.Form)2 ScanResult (com.codename1.ext.codescan.ScanResult)1 Button (com.codename1.ui.Button)1 Command (com.codename1.ui.Command)1 Container (com.codename1.ui.Container)1 Label (com.codename1.ui.Label)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 BorderLayout (com.codename1.ui.layouts.BorderLayout)1 FlowLayout (com.codename1.ui.layouts.FlowLayout)1