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;
}
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();
}
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();
}
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();
}
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();
}
Aggregations