Search in sources :

Example 61 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Toolbar method constructOnTopSideMenu.

private void constructOnTopSideMenu() {
    if (sidemenuDialog == null) {
        permanentSideMenuContainer = constructSideNavigationComponent();
        final Form parent = getComponentForm();
        parent.addPointerPressedListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                if (Display.getInstance().getImplementation().isScrollWheeling()) {
                    return;
                }
                if (sidemenuDialog.isShowing()) {
                    if (evt.getX() > sidemenuDialog.getWidth()) {
                        parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
                        closeSideMenu();
                        evt.consume();
                    } else {
                        if (evt.getX() + Display.getInstance().convertToPixels(8) > sidemenuDialog.getWidth()) {
                            parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
                        } else {
                            parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
                        }
                        if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
                            evt.consume();
                        }
                    }
                } else {
                    int displayWidth = Display.getInstance().getDisplayWidth();
                    final int sensitiveSection = displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
                    if (evt.getX() < sensitiveSection) {
                        parent.putClientProperty("cn1$sidemenuCharged", Boolean.TRUE);
                        evt.consume();
                    } else {
                        parent.putClientProperty("cn1$sidemenuCharged", Boolean.FALSE);
                        permanentSideMenuContainer.pointerPressed(evt.getX(), evt.getY());
                    }
                }
            }
        });
        parent.addPointerDraggedListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                if (Display.getInstance().getImplementation().isScrollWheeling()) {
                    return;
                }
                Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuCharged");
                if (b != null && b.booleanValue()) {
                    parent.putClientProperty("cn1$sidemenuActivated", Boolean.TRUE);
                    showOnTopSidemenu(evt.getX(), false);
                    evt.consume();
                } else {
                    if (sidemenuDialog.isShowing()) {
                        permanentSideMenuContainer.pointerDragged(evt.getX(), evt.getY());
                        evt.consume();
                    }
                }
            }
        });
        parent.addPointerReleasedListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                if (Display.getInstance().getImplementation().isScrollWheeling()) {
                    return;
                }
                Boolean b = (Boolean) parent.getClientProperty("cn1$sidemenuActivated");
                if (b != null && b.booleanValue()) {
                    parent.putClientProperty("cn1$sidemenuActivated", null);
                    if (evt.getX() < parent.getWidth() / 4) {
                        closeSideMenu();
                    } else {
                        showOnTopSidemenu(-1, true);
                    }
                    evt.consume();
                } else {
                    if (sidemenuDialog.isShowing()) {
                        if (!isComponentInOnTopSidemenu(parent.getComponentAt(evt.getX(), evt.getY()))) {
                            evt.consume();
                        }
                        permanentSideMenuContainer.pointerReleased(evt.getX(), evt.getY());
                    }
                }
            }
        });
        sidemenuDialog = new InteractionDialog(new BorderLayout());
        sidemenuDialog.setFormMode(true);
        sidemenuDialog.setUIID("Container");
        sidemenuDialog.setDialogUIID("Container");
        sidemenuDialog.getTitleComponent().remove();
        sidemenuDialog.add(BorderLayout.CENTER, permanentSideMenuContainer);
        if (sidemenuSouthComponent != null) {
            sidemenuDialog.add(BorderLayout.SOUTH, sidemenuSouthComponent);
        }
        float size = 4.5f;
        try {
            size = Float.parseFloat(getUIManager().getThemeConstant("menuImageSize", "4.5"));
        } catch (Throwable t) {
            Log.e(t);
        }
        if (!parent.getUIManager().isThemeConstant("hideLeftSideMenuBool", false)) {
            Image i = (Image) parent.getUIManager().getThemeImageConstant("sideMenuImage");
            if (i != null) {
                Command cmd = addCommandToLeftBar("", i, new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        if (sidemenuDialog.isShowing()) {
                            closeSideMenu();
                            return;
                        }
                        showOnTopSidemenu(-1, false);
                    }
                });
                Image p = (Image) parent.getUIManager().getThemeImageConstant("sideMenuPressImage");
                if (p != null) {
                    findCommandComponent(cmd).setPressedIcon(p);
                }
            } else {
                addMaterialCommandToLeftBar("", FontImage.MATERIAL_MENU, size, new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        if (sidemenuDialog.isShowing()) {
                            closeSideMenu();
                            return;
                        }
                        showOnTopSidemenu(-1, false);
                    }
                });
            }
        }
    }
}
Also used : InteractionDialog(com.codename1.components.InteractionDialog) ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 62 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Form method pointerDragged.

/**
 * {@inheritDoc}
 */
public void pointerDragged(int x, int y) {
    // disable the drag stop flag if we are dragging again
    boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
    if (dragStopFlag) {
        pointerPressed(x, y);
    }
    autoRelease(x, y);
    if (pointerDraggedListeners != null) {
        ActionEvent av = new ActionEvent(this, ActionEvent.Type.PointerDrag, x, y);
        pointerDraggedListeners.fireActionEvent(av);
        if (av.isConsumed()) {
            return;
        }
    }
    rippleMotion = null;
    if (dragged != null) {
        dragged.pointerDragged(x, y);
        return;
    }
    if (pressedCmp != null && pressedCmp.isStickyDrag()) {
        stickyDrag = pressedCmp;
    }
    if (stickyDrag != null) {
        stickyDrag.pointerDragged(x, y);
        repaint();
        return;
    }
    Container actual = getActualPane(formLayeredPane, x, y);
    if (x < actual.getX()) {
        // special case for sidemenu
        Component cmp = ((BorderLayout) super.getLayout()).getWest();
        if (cmp != null) {
            cmp = ((Container) cmp).getComponentAt(x, y);
            while (cmp != null && cmp.isIgnorePointerEvents()) {
                cmp = cmp.getParent();
            }
            if (cmp != null && cmp.isEnabled()) {
                cmp.pointerDragged(x, y);
                cmp.repaint();
                if (cmp == pressedCmp && cmp.isStickyDrag()) {
                    stickyDrag = cmp;
                }
            }
        }
        return;
    }
    Component cmp = actual.getComponentAt(x, y);
    while (cmp != null && cmp.isIgnorePointerEvents()) {
        cmp = cmp.getParent();
    }
    if (cmp != null) {
        if (!isScrollWheeling && cmp.isFocusable() && cmp.isEnabled()) {
            setFocused(cmp);
        }
        cmp.pointerDragged(x, y);
        cmp.repaint();
        if (cmp == pressedCmp && cmp.isStickyDrag()) {
            stickyDrag = cmp;
        }
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 63 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class SideMenuBar method validateCommandPlacement.

private void validateCommandPlacement(String placement) {
    if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
        ((BorderLayout) getTitleAreaContainer().getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        if (!(getTitleComponent() instanceof Button)) {
            Button b = new Button(parent.getTitle());
            b.setUIID("Title");
            parent.setTitleComponent(b);
            b.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    openMenu(COMMAND_PLACEMENT_VALUE_TOP);
                }
            });
        }
        return;
    }
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        if (rightSideButton != null && rightSideButton.getParent() != null) {
            return;
        }
        rightSideButton = new Button();
        rightSideButton.setUIID("MenuButtonRight");
        UIManager uim = parent.getUIManager();
        Image i = (Image) uim.getThemeImageConstant("rightSideMenuImage");
        if (i != null) {
            rightSideButton.setIcon(i);
        } else {
            FontImage.setMaterialIcon(rightSideButton, FontImage.MATERIAL_MENU);
        }
        Image p = (Image) uim.getThemeImageConstant("rightSideMenuPressImage");
        if (p != null) {
            rightSideButton.setPressedIcon(p);
        }
        rightSideButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                openMenu(COMMAND_PLACEMENT_VALUE_RIGHT);
            }
        });
        Container ta = getTitleAreaContainer();
        ta.addComponent(BorderLayout.EAST, rightSideButton);
        ta.revalidate();
        return;
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) UIManager(com.codename1.ui.plaf.UIManager)

Example 64 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class AndroidImplementation method captureAudio.

public void captureAudio(final ActionListener response) {
    if (!checkForPermission(Manifest.permission.RECORD_AUDIO, "This is required to record the audio")) {
        return;
    }
    try {
        final Form current = Display.getInstance().getCurrent();
        final File temp = File.createTempFile("mtmp", ".3gpp");
        temp.deleteOnExit();
        if (recorder != null) {
            recorder.release();
        }
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
        recorder.setOutputFile(temp.getAbsolutePath());
        final Form recording = new Form("Recording");
        recording.setTransitionInAnimator(CommonTransitions.createEmpty());
        recording.setTransitionOutAnimator(CommonTransitions.createEmpty());
        recording.setLayout(new BorderLayout());
        recorder.prepare();
        recorder.start();
        final Label time = new Label("00:00");
        time.getAllStyles().setAlignment(Component.CENTER);
        Font f = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);
        f = f.derive(getDisplayHeight() / 10, Font.STYLE_PLAIN);
        time.getAllStyles().setFont(f);
        recording.addComponent(BorderLayout.CENTER, time);
        recording.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) {
                int seconds = sec % 60;
                int minutes = sec / 60;
                String secStr = seconds < 10 ? "0" + seconds : "" + seconds;
                String minStr = minutes < 10 ? "0" + minutes : "" + minutes;
                String txt = minStr + ":" + secStr;
                time.setText(txt);
            }
        });
        Container south = new Container(new com.codename1.ui.layouts.GridLayout(1, 2));
        Command cancel = new Command("Cancel") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(null);
            }
        };
        recording.setBackCommand(cancel);
        south.add(new com.codename1.ui.Button(cancel));
        south.add(new com.codename1.ui.Button(new Command("Save") {

            @Override
            public void actionPerformed(ActionEvent evt) {
                if (recorder != null) {
                    recorder.stop();
                    recorder.release();
                    recorder = null;
                }
                current.showBack();
                response.actionPerformed(new ActionEvent(temp.getAbsolutePath()));
            }
        }));
        recording.addComponent(BorderLayout.SOUTH, south);
        recording.show();
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start audio recording");
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) IOException(java.io.IOException) Font(com.codename1.ui.Font) Paint(android.graphics.Paint) BorderLayout(com.codename1.ui.layouts.BorderLayout) com.codename1.ui(com.codename1.ui) Animation(com.codename1.ui.animations.Animation) MediaRecorder(android.media.MediaRecorder) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 65 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class SMSShare method share.

/**
 * {@inheritDoc}
 */
public void share(final String toShare) {
    final Form currentForm = Display.getInstance().getCurrent();
    final Form contactsForm = new Form("Contacts");
    contactsForm.setScrollable(false);
    contactsForm.setLayout(new BorderLayout());
    contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
    contactsForm.show();
    Display.getInstance().startThread(new Runnable() {

        public void run() {
            String[] ids = ContactsManager.getAllContacts();
            if (ids == null || ids.length == 0) {
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
                        currentForm.showBack();
                    }
                });
                return;
            }
            ContactsModel model = new ContactsModel(ids);
            final List contacts = new List(model);
            contacts.setRenderer(createListRenderer());
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    contacts.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            final ShareForm[] f = new ShareForm[1];
                            final Hashtable contact = (Hashtable) contacts.getSelectedItem();
                            f[0] = new ShareForm(contactsForm, "Send SMS", (String) contact.get("phone"), toShare, new ActionListener() {

                                public void actionPerformed(ActionEvent evt) {
                                    try {
                                        Display.getInstance().sendSMS(f[0].getTo(), f[0].getMessage());
                                    } catch (IOException ex) {
                                        Log.e(ex);
                                        System.out.println("failed to send sms to " + (String) contact.get("phone"));
                                    }
                                    finish();
                                }
                            });
                            f[0].show();
                        }
                    });
                    contactsForm.addComponent(BorderLayout.CENTER, contacts);
                    Command back = new Command("Back") {

                        public void actionPerformed(ActionEvent evt) {
                            currentForm.showBack();
                        }
                    };
                    contactsForm.addCommand(back);
                    contactsForm.setBackCommand(back);
                    contactsForm.revalidate();
                }
            });
        }
    }, "SMS Thread").start();
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) IOException(java.io.IOException) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ContactsModel(com.codename1.contacts.ContactsModel)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4