Search in sources :

Example 6 with BoxLayout

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

the class RSSReader method createRendererContainer.

private Container createRendererContainer() {
    Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    entries.setUIID("RSSEntry");
    Label title = new Label();
    title.setName("title");
    title.setUIID("RSSTitle");
    entries.addComponent(title);
    TextArea description = new TextArea(2, 30);
    description.setGrowByContent(false);
    description.setName("details");
    description.setUIID("RSSDescription");
    description.setScrollVisible(false);
    entries.addComponent(description);
    if (iconPlaceholder != null) {
        Container wrap = new Container(new BorderLayout());
        wrap.addComponent(BorderLayout.CENTER, entries);
        Label icon = new Label();
        icon.setIcon(iconPlaceholder);
        icon.setUIID("RSSIcon");
        icon.setName("icon");
        wrap.addComponent(BorderLayout.WEST, icon);
        entries = wrap;
    }
    return entries;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) TextArea(com.codename1.ui.TextArea) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label)

Example 7 with BoxLayout

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

the class Container method calculateLastPaintableOffset.

/**
 * Gets the index of the "last" child component that intersects the given rectangle.  This is
 * only helpful if the components are sorted (e.g. with BoxLayout.Y_AXIS).  If they aren't
 * sorted then this will just return components.size()-1.
 * @param pos The starting position to search.  It is assumed that this starting
 * position is in the visible region.
 * @param clipX1 The left bounds of the region to search.  (0,0) is the top left corner of the container.
 * @param clipY1 The top bounds of the region to search. (0,0) is the top left corner of the container.
 * @param clipX2 The right bounds of the region to search. (0,0) is the top left corner of the container.
 * @param clipY2 The bottom bounds of the region to search. (0,0) is the top left corner of the container.
 * @return The index of the last visible component in this container - or components.size()-1
 */
private int calculateLastPaintableOffset(int pos, int clipX1, int clipY1, int clipX2, int clipY2) {
    final int len = components.size();
    if (pos >= len - 1) {
        // Let's return one less than pos to indicate this
        return len - 1;
    }
    final Layout l = getLayout();
    if (l.getClass() == BoxLayout.class) {
        if (((BoxLayout) l).getAxis() == BoxLayout.Y_AXIS) {
            // Use a binary search to find the first visible
            // Component c = components.get(++pos);
            Component c = null;
            int cy1 = -1;
            final int end = len - 1;
            // This should still be a valid index because
            pos++;
            // we previously checked to see if it was >= len-1
            do {
                c = components.get(pos);
                cy1 = c.getBounds().getY();
            } while (++pos <= end && cy1 <= clipY2);
            return pos - 1;
        }
    }
    return len - 1;
}
Also used : Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 8 with BoxLayout

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

the class MenuBar method adaptTitleLayoutBackCommandStructure.

void adaptTitleLayoutBackCommandStructure() {
    Container t = getTitleAreaContainer();
    if (t.getComponentCount() - componentCountOffset(t) == 3) {
        return;
    }
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        getTitleComponent().getUnselectedStyle().setAlignment(Component.LEFT, true);
    } else {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    }
    t.removeAll();
    t.addComponent(BorderLayout.CENTER, getTitleComponent());
    Container leftContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    Container rightContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    t.addComponent(BorderLayout.EAST, rightContainer);
    t.addComponent(BorderLayout.WEST, leftContainer);
    initTitleBarStatus();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 9 with BoxLayout

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

the class DefaultCrashReporter method exception.

/**
 * {@inheritDoc}
 */
public void exception(Throwable t) {
    Preferences.set("$CN1_pendingCrash", true);
    if (promptUser) {
        Dialog error = new Dialog("Error");
        error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        TextArea txt = new TextArea(errorText);
        txt.setEditable(false);
        txt.setUIID("DialogBody");
        error.addComponent(txt);
        CheckBox cb = new CheckBox(checkboxText);
        cb.setUIID("DialogBody");
        error.addComponent(cb);
        Container grid = new Container(new GridLayout(1, 2));
        error.addComponent(grid);
        Command ok = new Command(sendButtonText);
        Command dont = new Command(dontSendButtonText);
        Button send = new Button(ok);
        Button dontSend = new Button(dont);
        grid.addComponent(send);
        grid.addComponent(dontSend);
        Command result = error.showPacked(BorderLayout.CENTER, true);
        if (result == dont) {
            if (cb.isSelected()) {
                Preferences.set("$CN1_crashBlocked", true);
            }
            Preferences.set("$CN1_pendingCrash", false);
            return;
        } else {
            if (cb.isSelected()) {
                Preferences.set("$CN1_prompt", false);
            }
        }
    }
    Log.sendLog();
    Preferences.set("$CN1_pendingCrash", false);
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) TextArea(com.codename1.ui.TextArea) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) Dialog(com.codename1.ui.Dialog) CheckBox(com.codename1.ui.CheckBox) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 10 with BoxLayout

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

the class SignIn method start.

public void start() {
    // new SignInFormGB(theme).show();
    // if (true) return;
    loginForm = new Form("Sign in Demo");
    loginForm.setLayout(new BorderLayout());
    Container center = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    center.setUIID("ContainerWithPadding");
    Image logo = theme.getImage("CodenameOne.png");
    Label l = new Label(logo);
    Container flow = new Container(new FlowLayout(Component.CENTER));
    flow.addComponent(l);
    center.addComponent(flow);
    final TextField username = new TextField();
    username.setHint("Username");
    final TextField pass = new TextField();
    pass.setHint("Password");
    pass.setConstraint(TextField.PASSWORD);
    center.addComponent(username);
    center.addComponent(pass);
    Button signIn = new Button("Sign In");
    signIn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (username.getText().length() == 0 || pass.getText().length() == 0) {
                return;
            }
            UserForm userForm = new UserForm(username.getText(), (EncodedImage) theme.getImage("user.png"), null);
            userForm.show();
        }
    });
    center.addComponent(signIn);
    loginForm.addComponent(BorderLayout.CENTER, center);
    Container bottom = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Button loginWFace = new Button(theme.getImage("signin_facebook.png"));
    loginWFace.setUIID("LoginButton");
    loginWFace.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            // create your own app identity on facebook follow the guide here:
            // facebook-login.html
            String clientId = "1171134366245722";
            String redirectURI = "http://www.codenameone.com/";
            String clientSecret = "";
            if (clientSecret.length() == 0) {
                System.err.println("create your own facebook app follow the guide here:");
                System.err.println("http://www.codenameone.com/facebook-login.html");
                return;
            }
            Login fb = FacebookConnect.getInstance();
            fb.setClientId(clientId);
            fb.setRedirectURI(redirectURI);
            fb.setClientSecret(clientSecret);
            login = fb;
            fb.setCallback(new LoginListener(LoginListener.FACEBOOK));
            if (!fb.isUserLoggedIn()) {
                fb.doLogin();
            } else {
                showFacebookUser(fb.getAccessToken().getToken());
            }
        }
    });
    Button loginWG = new Button(theme.getImage("signin_google.png"));
    loginWG.setUIID("LoginButton");
    loginWG.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            SignIn.this.doFirebase();
            // create your own google project follow the guide here:
            // http://www.codenameone.com/google-login.html
            String clientId = "555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com";
            String redirectURI = "https://www.codenameone.com/oauth2callback";
            String clientSecret = "650YqplrnAI0KXb9LMUnVNnx";
            if (clientSecret.length() == 0) {
                System.err.println("create your own google project follow the guide here:");
                System.err.println("http://www.codenameone.com/google-login.html");
                return;
            }
            Login gc = GoogleConnect.getInstance();
            gc.setClientId(clientId);
            gc.setRedirectURI(redirectURI);
            gc.setClientSecret(clientSecret);
            gc.setScope("https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file");
            login = gc;
            gc.setCallback(new LoginListener(LoginListener.GOOGLE));
            if (!gc.isUserLoggedIn()) {
                gc.doLogin();
            } else {
                showGoogleUser(gc.getAccessToken().getToken());
            }
        }
    });
    bottom.addComponent(loginWFace);
    bottom.addComponent(loginWG);
    loginForm.addComponent(BorderLayout.SOUTH, bottom);
    loginForm.show();
}
Also used : FlowLayout(com.codename1.ui.layouts.FlowLayout) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) Login(com.codename1.social.Login) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Button(com.codename1.ui.Button) TextField(com.codename1.ui.TextField)

Aggregations

BoxLayout (com.codename1.ui.layouts.BoxLayout)24 BorderLayout (com.codename1.ui.layouts.BorderLayout)16 Container (com.codename1.ui.Container)13 Label (com.codename1.ui.Label)8 Button (com.codename1.ui.Button)7 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Layout (com.codename1.ui.layouts.Layout)6 CheckBox (com.codename1.ui.CheckBox)5 Component (com.codename1.ui.Component)5 Form (com.codename1.ui.Form)5 TextArea (com.codename1.ui.TextArea)5 RadioButton (com.codename1.ui.RadioButton)4 ActionListener (com.codename1.ui.events.ActionListener)4 GridLayout (com.codename1.ui.layouts.GridLayout)4 Dialog (com.codename1.ui.Dialog)3 Image (com.codename1.ui.Image)3 Slider (com.codename1.ui.Slider)3 TextField (com.codename1.ui.TextField)3 ActionEvent (com.codename1.ui.events.ActionEvent)3