This document discusses building native mobile apps for all platforms using Codename One. Codename One is an open source tool that allows developers to write Java code once and deploy to multiple platforms including iOS, Android and Windows Phone. It provides GUI components, theme support, localization tools and abstracts away differences between devices. The document demonstrates how to generate a sample project, make simple UI modifications, add a camera capture feature, and install the app on devices. It concludes with pointers for additional Codename One resources.
2. Introduction
Devices
Codename One
Application
Deployment
Questions
Who Am I?
Shai Almog
shai@codenameone.com
Co-founder & CEO of Codename One
JavaOne Rockstar, DZone MVB, JavaZone top speaker…
Worked on mobile development tools since the 90’s at Sun
Member of original WTK team, co-creator of LWUIT project
Worked with Sun/Oracle, IBM, DoCoMo, Nokia, Samsung,
Verizon, Sprint, Vodafone, Sony Ericsson and more
Open source hacker, Java developer since 96
Over 20 years of professional software development
experience
5. Introduction
Devices
Codename One
Application
Deployment
Questions
What Is Codename One
• Open source - Java for all devices
• Supports iOS, Android & Windows Phone
• Integrates with Eclipse, NetBeans & IntelliJ
• GUI builder, theme editor, localization tools
• API abstracting device
• Designed for Tablets/Phones
• Cloud based compilation
19. Introduction
Devices
Codename One
Application
Deployment
Questions
Generated Project Starting Point
Form hi = new Form("Rounder");
hi.setLayout(new BorderLayout());
final Label picture = new Label("");
picture.getUnselectedStyle().setPadding(0, 0, 0, 0);
picture.getUnselectedStyle().setMargin(0, 0, 0, 0);
hi.addComponent(BorderLayout.CENTER, picture);
hi.addCommand(new Command("Picture") {
public void actionPerformed(ActionEvent evt) {
captureRoundImage(picture);
}
});
hi.show();
20. Introduction
Devices
Codename One
Application
Deployment
Questions
Generated Project Starting Point
Form hi = new Form("Rounder");
hi.setLayout(new BorderLayout());
final Label picture = new Label("");
picture.getUnselectedStyle().setPadding(0, 0, 0, 0);
picture.getUnselectedStyle().setMargin(0, 0, 0, 0);
hi.addComponent(BorderLayout.CENTER, picture);
hi.addCommand(new Command("Picture") {
public void actionPerformed(ActionEvent evt) {
captureRoundImage(picture);
}
});
hi.show();
Changed Title
Set Layout
Removed
Spacing From
Label
Command
handles menu
functionality
21. Introduction
Devices
Codename One
Application
Deployment
Questions
Generated Project Starting Point
Form hi = new Form("Rounder");
hi.setLayout(new BorderLayout());
final Label picture = new Label("");
picture.getUnselectedStyle().setPadding(0, 0, 0, 0);
picture.getUnselectedStyle().setMargin(0, 0, 0, 0);
hi.addComponent(BorderLayout.CENTER, picture);
hi.addCommand(new Command("Picture") {
public void actionPerformed(ActionEvent evt) {
captureRoundImage(picture);
}
});
hi.show();
Changed Title
Set Layout
Removed
Spacing From
Label
Command
handles menu
functionality
23. Introduction
Devices
Codename One
Application
Deployment
Questions
private void captureRoundImage(Label result) {
try {
int width = Display.getInstance().getDisplayWidth();
Image capturedImage =
Image.createImage(Capture.capturePhoto(width, -1));
Image roundMask =
Image.createImage(width, capturedImage.getHeight(),
0xff000000);
Graphics gr = roundMask.getGraphics();
gr.setColor(0xffffff);
gr.fillArc(0, 0, width, width, 0, 360);
Object mask = roundMask.createMask();
capturedImage = capturedImage.applyMask(mask);
result.setIcon(capturedImage);
} catch(IOException err) {
err.printStackTrace();
}
}
Generated Project Starting Point
Capture
a picture at
device width
with aspect
ratio
Create an
image we can
modify into a
mask
Apply the
mask to the
captured image
and set to
label
24. Introduction
Devices
Codename One
Application
Deployment
Questions
private void captureRoundImage(Label result) {
try {
int width = Display.getInstance().getDisplayWidth();
Image capturedImage =
Image.createImage(Capture.capturePhoto(width, -1));
Image roundMask =
Image.createImage(width, capturedImage.getHeight(),
0xff000000);
Graphics gr = roundMask.getGraphics();
gr.setColor(0xffffff);
gr.fillArc(0, 0, width, width, 0, 360);
Object mask = roundMask.createMask();
capturedImage = capturedImage.applyMask(mask);
result.setIcon(capturedImage);
} catch(IOException err) {
err.printStackTrace();
}
}
Generated Project Starting Point
Capture
a picture at
device width
with aspect
ratio
Create an
image we can
modify into a
mask
Apply the
mask to the
captured image
and set to
label