Skip to content

Instantly share code, notes, and snippets.

@codenameone
codenameone / BubbleSample.java
Created March 21, 2016 18:01
Sample code for the new BubbleTransition effect in Codename One
Form hi = new Form("Bubble");
Button showBubble = new Button("+");
showBubble.setName("BubbleButton");
Style buttonStyle = showBubble.getAllStyles();
buttonStyle.setBorder(Border.createEmpty());
buttonStyle.setFgColor(0xffffff);
buttonStyle.setBgPainter((g, rect) -> {
g.setColor(0xff);
int actualWidth = rect.getWidth();
int actualHeight = rect.getHeight();
@codenameone
codenameone / FloatingHintSample.java
Created March 17, 2016 14:59
Codename Ones FloatingHint animates the text components hint label into a component title on top while editing
Form hi = new Form("Floating Hint", BoxLayout.y());
TextField first = new TextField("", "First Field");
TextField second = new TextField("", "Second Field");
hi.add(new FloatingHint(first)).
add(new FloatingHint(second)).
add(new Button("Go"));
hi.show();
@codenameone
codenameone / FontCatalog.java
Last active July 8, 2020 09:57
A sample for Font usage in Codename One that goes over all of the "big pieces" in Codename One fonts to display a large catalog of "whats available"
private Label createForFont(Font fnt, String s) {
Label l = new Label(s);
l.getUnselectedStyle().setFont(fnt);
return l;
}
public void showForm() {
GridLayout gr = new GridLayout(5);
gr.setAutoFit(true);
Form hi = new Form("Fonts", gr);
@codenameone
codenameone / ShapeSample.java
Created March 17, 2016 05:43
Usage of the Shape drawing API in Codename One and GeneralPath
Form hi = new Form("Shape");
// We create a 50 x 100 shape, this is arbitrary since we can scale it easily
GeneralPath path = new GeneralPath();
path.moveTo(20,0);
path.lineTo(30, 0);
path.lineTo(30, 100);
path.lineTo(20, 100);
path.lineTo(20, 15);
path.lineTo(5, 40);
@codenameone
codenameone / CanExecuteSample.java
Last active July 8, 2020 09:57
Demonstrates the Codname One canExecute and Execute API's of Display
Boolean can = Display.getInstance().canExecute("imdb:///find?q=godfather");
if(can != null && can) {
Display.getInstance().execute("imdb:///find?q=godfather");
} else {
Display.getInstance().execute("http://www.imdb.com");
}
@codenameone
codenameone / PullToRefreshSample.java
Created March 6, 2016 12:34
Usage of the pull to refresh feature of Codename One
Form hi = new Form("Pull To Refresh", BoxLayout.y());
hi.getContentPane().addPullToRefresh(() -> {
hi.add("Pulled at " + L10NManager.getInstance().formatDateTimeShort(new Date()));
});
hi.show();
@codenameone
codenameone / CaptureAudioSample.java
Created March 5, 2016 19:01
Demonstrates capturing of audio files and their playback using the Codename One API
Form hi = new Form("Capture", BoxLayout.y());
hi.setToolbar(new Toolbar());
Style s = UIManager.getInstance().getComponentStyle("Title");
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_MIC, s);
FileSystemStorage fs = FileSystemStorage.getInstance();
String recordingsDir = fs.getAppHomePath() + "recordings/";
fs.mkdir(recordingsDir);
try {
for(String file : fs.listFiles(recordingsDir)) {
@codenameone
codenameone / LocationListenerSample.java
Last active July 8, 2020 09:57
LocationListener sends events about location updates to a Codename One application that is currently in the forground
public MyListener implements LocationListener {
public void locationUpdated(Location location) {
// update UI etc.
}
public void providerStateChanged(int newState) {
// handle status changes/errors appropriately
}
}
LocationManager.getLocationManager().setLocationListener(new MyListener());
Location position = LocationManager.getLocationManager().getCurrentLocationSync();
@codenameone
codenameone / GeofenceListenerImpl.java
Last active June 4, 2021 15:06
Sample usage of the Codename One geofence API to track location
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
}
@Override
public void onEntered(String id) {
if(Display.getInstance().isMinimized()) {
Display.getInstance().callSerially(() -> {
Dialog.show("Welcome", "Thanks for arriving", "OK", null);