Search in sources :

Example 1 with DeviceCalendar

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();
}
Also used : EventInfo(com.codename1.calendar.EventInfo) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Label(com.codename1.ui.Label) DeviceCalendar(com.codename1.calendar.DeviceCalendar) Date(java.util.Date)

Aggregations

DeviceCalendar (com.codename1.calendar.DeviceCalendar)1 EventInfo (com.codename1.calendar.EventInfo)1 Button (com.codename1.ui.Button)1 Form (com.codename1.ui.Form)1 Label (com.codename1.ui.Label)1 Date (java.util.Date)1