Search in sources :

Example 41 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestRecorder method recordingActionPerformed.

// GEN-LAST:event_saveRecordingActionPerformed
private void recordingActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_recordingActionPerformed
    if (isRecording()) {
        Form f = Display.getInstance().getCurrent();
        if (f.getName() != null && f.getTitle().length() > 0) {
            generatedCode += "        waitForFormName(\"" + f.getName() + "\");\n";
        } else {
            if (f.getTitle() != null && f.getTitle().length() > 0) {
                generatedCode += "        waitForFormTitle(\"" + f.getTitle() + "\");\n";
            }
        }
        updateTestCode();
    }
}
Also used : Form(com.codename1.ui.Form)

Example 42 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class GameCanvasImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    captureResponse = response;
    try {
        final Form current = Display.getInstance().getCurrent();
        final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
        RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
        if (record == null) {
            player.cleanup();
            throw new RuntimeException("Capture Audio is not supported on this device");
        }
        final Form cam = new Form();
        cam.setTransitionInAnimator(CommonTransitions.createEmpty());
        cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
        cam.setLayout(new BorderLayout());
        cam.show();
        player.play();
        final Label time = new Label("0:00");
        cam.addComponent(BorderLayout.SOUTH, time);
        cam.revalidate();
        ActionListener l = new ActionListener() {

            boolean recording = false;

            OutputStream out = null;

            String audioPath = null;

            RecordControl record;

            public void actionPerformed(ActionEvent evt) {
                if (!recording) {
                    record = (RecordControl) player.nativePlayer.getControl("RecordControl");
                    recording = true;
                    String type = record.getContentType();
                    String prefix = "";
                    if (type.endsWith("wav")) {
                        prefix = ".wav";
                    } else if (type.endsWith("amr")) {
                        prefix = ".amr";
                    } else if (type.endsWith("3gpp")) {
                        prefix = ".3gp";
                    }
                    audioPath = getOutputMediaFile() + prefix;
                    try {
                        out = FileSystemStorage.getInstance().openOutputStream(audioPath);
                        record.setRecordStream(out);
                        record.startRecord();
                        cam.registerAnimated(new Animation() {

                            long current = System.currentTimeMillis();

                            long zero = current;

                            int sec = 0;

                            public boolean animate() {
                                long now = System.currentTimeMillis();
                                if (now - current > 1000) {
                                    current = now;
                                    sec++;
                                    return true;
                                }
                                return false;
                            }

                            public void paint(Graphics g) {
                                String txt = sec / 60 + ":" + sec % 60;
                                time.setText(txt);
                            }
                        });
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        System.out.println("failed to store audio to " + audioPath);
                    } finally {
                    }
                } else {
                    if (out != null) {
                        try {
                            record.stopRecord();
                            record.commit();
                            out.close();
                            player.cleanup();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    captureResponse.actionPerformed(new ActionEvent(audioPath));
                    current.showBack();
                }
            }
        };
        cam.addGameKeyListener(Display.GAME_FIRE, l);
        cam.addPointerReleasedListener(l);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start camera");
    }
}
Also used : Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) Graphics(com.codename1.ui.Graphics) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Animation(com.codename1.ui.animations.Animation) RecordControl(javax.microedition.media.control.RecordControl)

Example 43 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class GameCanvasImplementation method capturePhoto.

public void capturePhoto(ActionListener response) {
    captureResponse = response;
    final Form current = Display.getInstance().getCurrent();
    final Form cam = new Form();
    cam.setScrollable(false);
    cam.setTransitionInAnimator(CommonTransitions.createEmpty());
    cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
    cam.setLayout(new BorderLayout());
    cam.show();
    String platform = System.getProperty("microedition.platform");
    MMAPIPlayer p = null;
    if (platform != null && platform.indexOf("Nokia") >= 0) {
        try {
            p = MMAPIPlayer.createPlayer("capture://image", null);
        } catch (Throwable e) {
        // Ignore all exceptions for image capture, continue with video capture...
        }
    }
    if (p == null) {
        try {
            p = MMAPIPlayer.createPlayer("capture://video", null);
        } catch (Exception e) {
            // The Nokia 2630 throws this if image/video capture is not supported
            throw new RuntimeException("Image/video capture not supported on this phone");
        }
    }
    final MMAPIPlayer player = p;
    MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
    video.play();
    video.setVisible(true);
    cam.addCommand(new com.codename1.ui.Command("Cancel") {

        public void actionPerformed(ActionEvent evt) {
            if (player != null) {
                player.cleanup();
            }
            captureResponse.actionPerformed(null);
            current.showBack();
        }
    });
    final ActionListener l = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            try {
                cam.removeAll();
                VideoControl cnt = (VideoControl) player.nativePlayer.getControl("VideoControl");
                byte[] pic = cnt.getSnapshot("encoding=jpeg&width=" + current.getWidth() + "&height=" + current.getHeight());
                String imagePath = getOutputMediaFile() + ".jpg";
                OutputStream out = null;
                try {
                    if (pic != null) {
                        out = FileSystemStorage.getInstance().openOutputStream(imagePath);
                        out.write(pic);
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                    System.out.println("failed to store picture to " + imagePath);
                } finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                        player.cleanup();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                    }
                }
                captureResponse.actionPerformed(new ActionEvent(imagePath));
                current.showBack();
            } catch (Throwable ex) {
                ex.printStackTrace();
                System.out.println("failed to take picture");
                current.showBack();
            }
        }
    };
    cam.addGameKeyListener(Display.GAME_FIRE, l);
    Container cn = new Container(new BorderLayout()) {

        public void pointerReleased(int x, int y) {
            l.actionPerformed(null);
        }
    };
    cn.setFocusable(true);
    cn.addComponent(BorderLayout.CENTER, video);
    cam.addComponent(BorderLayout.CENTER, cn);
    cam.revalidate();
// cam.addPointerReleasedListener(l);
}
Also used : Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) OutputStream(java.io.OutputStream) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) BorderLayout(com.codename1.ui.layouts.BorderLayout) com.codename1.ui(com.codename1.ui) ActionListener(com.codename1.ui.events.ActionListener) VideoControl(javax.microedition.media.control.VideoControl)

Example 44 with Form

use of com.codename1.ui.Form 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 45 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class ComboBox method createPopupDialog.

/**
 * Subclasses can override this method to change the creation of the dialog
 *
 * @param l the list of the popup
 * @return a dialog instance
 */
protected Dialog createPopupDialog(List<T> l) {
    Dialog popupDialog = new Dialog(getUIID() + "Popup", getUIID() + "PopupTitle") {

        void sizeChangedInternal(int w, int h) {
            // resize the popup just resize the parent form
            if (getWidth() == w && getHeight() != h) {
                Form frm = getPreviousForm();
                if (frm != null) {
                    frm.sizeChangedInternal(w, h);
                }
                setSize(new Dimension(w, h));
                repaint();
            } else {
                dispose();
            }
        }
    };
    popupDialog.setScrollable(false);
    popupDialog.getContentPane().setAlwaysTensile(false);
    popupDialog.setAlwaysTensile(false);
    popupDialog.getContentPane().setUIID("PopupContentPane");
    popupDialog.setDisposeWhenPointerOutOfBounds(true);
    popupDialog.setTransitionInAnimator(CommonTransitions.createEmpty());
    popupDialog.setTransitionOutAnimator(CommonTransitions.createEmpty());
    popupDialog.setLayout(new BorderLayout());
    popupDialog.addComponent(BorderLayout.CENTER, l);
    return popupDialog;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8