Search in sources :

Example 31 with Result

use of com.codename1.rad.processing.Result in project CodenameOne by codenameone.

the class HTMLComponent method animate.

public boolean animate() {
    boolean result = super.animate();
    if (marqueeMotion == null) {
        return result;
    }
    for (Enumeration e = marqueeComponents.elements(); e.hasMoreElements(); ) {
        Component cmp = (Component) e.nextElement();
        cmp.setX(marqueeMotion.getValue());
    }
    if (marqueeMotion.isFinished()) {
        int dir = getUIManager().getLookAndFeel().isRTL() ? 1 : -1;
        marqueeMotion = Motion.createLinearMotion(dir * -HTMLComponent.this.getWidth(), dir * HTMLComponent.this.getWidth(), MARQUEE_DELAY);
        marqueeMotion.start();
    }
    return true;
}
Also used : Enumeration(java.util.Enumeration) Component(com.codename1.ui.Component)

Example 32 with Result

use of com.codename1.rad.processing.Result in project CodenameOne by codenameone.

the class SSLCertificatePinningSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World");
    hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    CheckBox allowConnectionsCb = new CheckBox("Allow Connections");
    allowConnectionsCb.setSelected(true);
    allowConnectionsCb.addActionListener(e -> {
        allowConnections = allowConnectionsCb.isSelected();
    });
    hi.add(allowConnectionsCb);
    allowConnections = allowConnectionsCb.isSelected();
    $(hi).append($(new Button("Test Build Request Body")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void buildRequestBody(OutputStream os) throws IOException {
                PrintStream ps = new PrintStream(os);
                ps.print("Key1=Val1");
            }

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://weblite.ca/tmp/postecho.php");
        req.setPost(true);
        req.setHttpMethod("POST");
        req.addArgument("SomeKey", "SomeValue");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueueAndWait(req);
        if (req.getResponseCode() == 200) {
            try {
                String resp = new String(req.getResponseData(), "UTF-8");
                String expected = "Post received:\n" + "Array\n" + "(\n" + "    [Key1] => Val1\n" + ")";
                String passFail = resp.trim().equals(expected.trim()) ? "Test Passed." : "Test Failed";
                // String expected = ""
                // resp += "\nExpected: "
                $(".result", hi).setText(passFail + "\nReceived:\n---------\n" + resp + "\n-----------\nExpected:\n----------\n" + expected + "\n---------\n");
            } catch (Exception ex) {
                Log.e(ex);
            }
        } else {
            $(".result", hi).setText("Request failed: " + req.getResponseErrorMessage());
        }
    }).asComponent());
    $(hi).append($(new Button("Test Post")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://weblite.ca/tmp/postecho.php");
        req.setPost(true);
        req.setHttpMethod("POST");
        req.addArgument("SomeKey", "SomeValue");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueueAndWait(req);
        if (req.getResponseCode() == 200) {
            try {
                String resp = new String(req.getResponseData(), "UTF-8");
                String expected = "Post received:\n" + "Array\n" + "(\n" + "    [SomeKey] => SomeValue\n" + ")";
                String passFail = resp.trim().equals(expected.trim()) ? "Test Passed." : "Test Failed";
                // String expected = ""
                // resp += "\nExpected: "
                $(".result", hi).setText(passFail + "\nReceived:\n---------\n" + resp + "\n-----------\nExpected:\n----------\n" + expected + "\n---------\n");
            } catch (Exception ex) {
                Log.e(ex);
            }
        } else {
            $(".result", hi).setText("Request failed: " + req.getResponseErrorMessage());
        }
    }).asComponent());
    $(hi).append($(new Button("Test SSL Certs")).addActionListener(e -> {
        ConnectionRequest req = new ConnectionRequest() {

            @Override
            protected void checkSSLCertificates(ConnectionRequest.SSLCertificate[] certificates) {
                /*
                            StringBuilder sb = new StringBuilder();
                            for (SSLCertificate cert : certificates) {
                                System.out.println("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey());
                                sb.append("Encoding: "+cert.getCertificteAlgorithm()+"; Certificate: "+cert.getCertificteUniqueKey()).append("\n");
                            }
                            
                            $(()->{
                                $("TextArea")
                                        .setText(sb.toString())
                                        .getComponentForm()
                                        .revalidate();
                                
                            });
                                    */
                if (!trust(certificates)) {
                    this.kill();
                }
            }

            @Override
            protected void handleException(Exception err) {
                err.printStackTrace();
            }

            @Override
            protected void handleErrorResponseCode(int code, String message) {
                // To change body of generated methods, choose Tools | Templates.
                super.handleErrorResponseCode(code, message);
            }
        };
        req.setCheckSSLCertificates(true);
        req.setUrl("https://confluence.atlassian.com/kb/unable-to-connect-to-ssl-services-due-to-pkix-path-building-failed-779355358.html");
        // NetworkManager.getInstance().addErrorListener(ne-> {
        // ne.getError().printStackTrace();
        // });
        // NetworkManager.getInstance().
        NetworkManager.getInstance().addToQueue(req);
    }).asComponent()).append($(new TextArea()).each(c -> {
        TextArea ta = (TextArea) c;
        ta.setRows(10);
    }).addTags("result").selectAllStyles().setFgColor(0x0).asComponent());
    hi.show();
}
Also used : OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Resources(com.codename1.ui.util.Resources) NetworkManager(com.codename1.io.NetworkManager) IOException(java.io.IOException) Form(com.codename1.ui.Form) Log(com.codename1.io.Log) NetworkEvent(com.codename1.io.NetworkEvent) UIManager(com.codename1.ui.plaf.UIManager) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) ConnectionRequest(com.codename1.io.ConnectionRequest) Dialog(com.codename1.ui.Dialog) Display(com.codename1.ui.Display) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) CN(com.codename1.ui.CN) TextArea(com.codename1.ui.TextArea) CheckBox(com.codename1.ui.CheckBox) PrintStream(java.io.PrintStream) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) BoxLayout(com.codename1.ui.layouts.BoxLayout) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ConnectionRequest(com.codename1.io.ConnectionRequest) Button(com.codename1.ui.Button) CheckBox(com.codename1.ui.CheckBox)

Example 33 with Result

use of com.codename1.rad.processing.Result in project CodenameOne by codenameone.

the class ShapeDonutSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.getContentPane().getStyle().setBgPainter(new Painter() {

        @Override
        public void paint(Graphics g, Rectangle rect) {
            GeneralPath p = new GeneralPath();
            p.setRect(new Rectangle(rect.getX() + 10, rect.getY() + 10, rect.getWidth() - 20, rect.getHeight() - 20), null);
            // Since default winding rule is EVEN_ODD, when we fill a shape with a closed circle inside a
            // rectangle, it will result in the circle being subtracted from the rect.
            p.arc(rect.getX() + 30, rect.getY() + 30, rect.getWidth() - 60, rect.getHeight() - 60, 0, Math.PI * 2);
            g.setColor(0x0000ff);
            g.fillShape(p);
        }
    });
    hi.show();
}
Also used : Graphics(com.codename1.ui.Graphics) GeneralPath(com.codename1.ui.geom.GeneralPath) Form(com.codename1.ui.Form) Painter(com.codename1.ui.Painter) Rectangle(com.codename1.ui.geom.Rectangle)

Example 34 with Result

use of com.codename1.rad.processing.Result in project CodenameOne by codenameone.

the class LocationSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Button checkIfDetectionAvailable = new Button("Check if GPS Detection Available");
    checkIfDetectionAvailable.addActionListener(e -> {
        String message = LocationManager.getLocationManager().isGPSDetectionSupported() ? "GPS Detection IS supported" : "GPS Detection is NOT supported";
        Dialog.show("GPS Detection Result", message, "OK", null);
    });
    Button isGPSEnabled = new Button("GPS Status");
    isGPSEnabled.addActionListener(e -> {
        String message = LocationManager.getLocationManager().isGPSEnabled() ? "GPS IS enabled" : "GPS is NOT enabled";
        Dialog.show("GPS Enabled?", message, "OK", null);
    });
    Button getLocation = new Button("Get Location");
    getLocation.addActionListener(e -> {
        Location loc = LocationManager.getLocationManager().getCurrentLocationSync(3000);
        String message = loc != null ? "Location is " + loc : "Location not found";
        Dialog.show("Location", message, "OK", null);
    });
    hi.addAll(checkIfDetectionAvailable, isGPSEnabled, getLocation);
    hi.show();
}
Also used : Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Location(com.codename1.location.Location)

Example 35 with Result

use of com.codename1.rad.processing.Result in project CodenameOne by codenameone.

the class NativeControlsSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    if (false) {
        webviewLoginTest();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    Label result = new Label();
    NSelect<String> select = new NSelect<>();
    $(select).selectAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 4f)).setFgColor(0xff0000).setBgColor(0x00ff00);
    select.setOptions("Red", "Green", "Blue", "Orange");
    select.addSelectionListener((i1, i2) -> {
        result.setText(select.getOption(select.getSelectedIndex()));
        hi.revalidateWithAnimationSafety();
    });
    hi.add(result);
    hi.add(select);
    hi.add("Text fields");
    hi.add("Username:");
    NTextField tf1 = new NTextField(TextField.USERNAME);
    System.out.println("Setting font to main light 15mm");
    tf1.getAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_LIGHT, 15f));
    System.out.println("Finished setting font");
    tf1.getAllStyles().setFgColor(0x003300);
    tf1.getAllStyles().setBgTransparency(255);
    tf1.getAllStyles().setBgColor(0xcccccc);
    tf1.getAllStyles().setAlignment(CENTER);
    hi.add(tf1);
    hi.add("Password:");
    NTextField tf2 = new NTextField(TextField.PASSWORD);
    hi.add(tf2);
    hi.add("Email:");
    NTextField emailField = new NTextField(TextField.EMAILADDR);
    hi.add(emailField);
    tf1.addActionListener(e -> {
    // tf2.setText(tf1.getText());
    });
    tf1.addChangeListener(e -> {
        result.setText(tf1.getText());
        hi.revalidateWithAnimationSafety();
    });
    tf2.addActionListener(e -> {
        Log.p("Action listener fired on password field");
        result.setText(tf2.getText());
        hi.revalidateWithAnimationSafety();
    });
    tf2.addDoneListener(e -> {
        Log.p("Done was clicked!!!");
    });
    hi.add(new TextField("LW field 1"));
    hi.add(new TextField("LW field 2"));
    hi.add(new TextField("LW field 3"));
    Button submit = new Button("Login");
    submit.addActionListener(e -> {
        Form f = new Form("Logged In", BoxLayout.y());
        Toolbar tb = new Toolbar();
        f.setToolbar(tb);
        tb.setBackCommand(new Command("") {

            @Override
            public void actionPerformed(ActionEvent e) {
                hi.showBack();
            }
        });
        f.add("Logged In!!!");
        f.show();
    });
    hi.add(submit);
    hi.show();
}
Also used : NSelect(com.codename1.nui.NSelect) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent) Label(com.codename1.ui.Label) TextField(com.codename1.ui.TextField) NTextField(com.codename1.nui.NTextField) NTextField(com.codename1.nui.NTextField) Toolbar(com.codename1.ui.Toolbar)

Aggregations

IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 Form (com.codename1.ui.Form)12 Button (com.codename1.ui.Button)11 Map (java.util.Map)9 Date (java.util.Date)8 HashMap (java.util.HashMap)8 Label (com.codename1.ui.Label)7 BorderLayout (com.codename1.ui.layouts.BorderLayout)7 List (java.util.List)7 Container (com.codename1.ui.Container)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 OutputStream (java.io.OutputStream)6 JSONParser (com.codename1.io.JSONParser)5 Result (com.codename1.rad.processing.Result)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 File (java.io.File)5 Cursor (com.codename1.db.Cursor)4 ConnectionRequest (com.codename1.io.ConnectionRequest)4 Entity (com.codename1.rad.models.Entity)4