use of com.codename1.calendar.DeviceCalendar in project CodenameOne by codenameone.
the class DeviceCalendarSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Calendar", BoxLayout.y());
DeviceCalendar dc = DeviceCalendar.getInstance();
if (dc == null) {
hi.add("Device Calendar is null");
hi.show();
return;
}
if (!dc.hasPermissions()) {
hi.add("No Calendar Access Permission");
hi.show();
return;
}
Collection<String> cals = dc.getCalendars();
if (cals == null || cals.isEmpty()) {
hi.add("No Calendars found on the device");
hi.show();
return;
}
int week = 7 * 24 * 60 * 60000;
Date lastWeek = new Date(System.currentTimeMillis() - week);
Date nextWeek = new Date(System.currentTimeMillis() - week);
for (String s : cals) {
Button b = new Button(s);
b.addActionListener(e -> {
String calId = dc.openCalendar(s, false);
Collection<EventInfo> events = dc.getEvents(calId, lastWeek, nextWeek);
Form f = new Form("Events", BoxLayout.y());
for (EventInfo ei : events) {
f.add(new Label(L10NManager.getInstance().formatDateTimeShort(ei.getStartTime()) + ei.getTitle()));
}
f.getToolbar().setBackCommand("", ee -> hi.showBack());
f.show();
});
hi.add(b);
}
hi.show();
}