Search in sources :

Example 31 with Label

use of com.codename1.rad.models.Property.Label 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)

Example 32 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class DragFinishedListenerTest3056 method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Container cnt = new Container();
    Label imageLbl = new Label();
    FontImage.setMaterialIcon(imageLbl, FontImage.MATERIAL_3D_ROTATION, 10);
    cnt.add(imageLbl);
    cnt.add(new Label("Another label in the container"));
    imageLbl.setDraggable(true);
    boolean isTest = true;
    if (!isTest) {
        cnt.putClientProperty("isTest", false);
    } else {
        cnt.putClientProperty("isTest", true);
    }
    cnt.setLeadComponent(imageLbl);
    cnt.setDraggable(true);
    imageLbl.addPointerDraggedListener((evt) -> {
        System.out.println("in drag");
    });
    imageLbl.addDragFinishedListener((evt) -> {
        System.out.println("Drag finished");
    });
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(cnt);
    hi.show();
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label)

Example 33 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class DraggableTabsSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Tabs", new BorderLayout());
    Tabs t = new Tabs();
    t.addTab("T1", new Label("Tab 1"));
    t.addTab("T2", new Label("Tab 2"));
    t.addTab("T3", new Label("Tab 3"));
    t.addTab("T4", new Label("Tab 4"));
    Container tabsC = t.getTabsContainer();
    tabsC.setDropTarget(true);
    for (Component c : tabsC) {
        c.setDraggable(true);
        c.addDropListener(e -> {
            e.consume();
            Component dragged = c;
            int x = e.getX();
            int y = e.getY();
            int i = tabsC.getComponentIndex(dragged);
            if (i > -1) {
                Component dest = tabsC.getComponentAt(x, y);
                if (dest != dragged) {
                    Component source = t.getTabComponentAt(i);
                    int destIndex = tabsC.getComponentIndex(dest);
                    if (destIndex > -1 && destIndex != i) {
                        String title = t.getTabTitle(i);
                        t.removeTabAt(i);
                        if (destIndex > i) {
                            t.insertTab(title, null, source, destIndex - 1);
                        } else {
                            t.insertTab(title, null, source, destIndex);
                        }
                    }
                }
                tabsC.animateLayout(400);
            }
        });
    }
    hi.add(CENTER, t);
    hi.show();
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) Tabs(com.codename1.ui.Tabs) Component(com.codename1.ui.Component)

Example 34 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class ButtonLongPointerPress method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    Button b = new Button("Long Press Me") {

        @Override
        public void longPointerPress(int x, int y) {
            System.out.println("Long pointer press received");
        }
    };
    hi.add(b);
    hi.show();
}
Also used : Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Label(com.codename1.ui.Label)

Example 35 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class VideoTransition method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", new BorderLayout());
    Button swap = new Button("Swap");
    Container theCnt = new Container(new LayeredLayout());
    Label imageLabel = new Label();
    $(imageLabel).selectAllStyles().setBgColor(0).setBgTransparency(255);
    MediaPlayer mediaPlayer = new MediaPlayer();
    $(mediaPlayer).selectAllStyles().setBgColor(0).setBgTransparency(255);
    swap.addActionListener(e -> {
        if (image == null) {
            image = Util.downloadImageToStorage("https://www.codenameone.com/img/uber-skin.png", "uber-skin.png").get();
            imageLabel.setIcon(image.scaled(CN.getDisplayWidth(), CN.getDisplayHeight()));
        }
        if (!mediaLoaded) {
            try {
                mediaPlayer.setDataSource("https://upload.wikimedia.org/wikipedia/commons/b/b3/Big_Buck_Bunny_Trailer_400p.ogv", null);
            } catch (IOException ex) {
                Log.e(ex);
            }
            mediaLoaded = true;
        }
        if (theCnt.getComponentCount() == 0) {
            theCnt.add(mediaPlayer);
            mediaPlayer.getMedia().play();
            hi.revalidateWithAnimationSafety();
        } else if (theCnt.contains(mediaPlayer) && !theCnt.contains(imageLabel)) {
            imageLabel.getAllStyles().setOpacity(0);
            imageLabel.getAllStyles().setBgTransparency(0);
            theCnt.add(imageLabel);
            theCnt.revalidateWithAnimationSafety();
            fadeIn(imageLabel, 500).ready(res -> {
                mediaPlayer.getMedia().pause();
                mediaPlayer.remove();
                hi.revalidateWithAnimationSafety();
            });
        } else if (theCnt.contains(imageLabel) && !theCnt.contains(mediaPlayer)) {
            theCnt.addComponent(0, mediaPlayer);
            mediaPlayer.getMedia().play();
            fadeOut(imageLabel, 500).ready(res -> {
                imageLabel.remove();
                theCnt.revalidateWithAnimationSafety();
            });
        }
    });
    hi.add(BorderLayout.NORTH, swap);
    hi.add(BorderLayout.CENTER, theCnt);
    hi.show();
}
Also used : Util(com.codename1.io.Util) Toolbar(com.codename1.ui.Toolbar) BoxLayout(com.codename1.ui.layouts.BoxLayout) Motion(com.codename1.ui.animations.Motion) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) Timer(java.util.Timer) Form(com.codename1.ui.Form) Container(com.codename1.ui.Container) NetworkEvent(com.codename1.io.NetworkEvent) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) Display(com.codename1.ui.Display) Label(com.codename1.ui.Label) Button(com.codename1.ui.Button) Component(com.codename1.ui.Component) CN(com.codename1.ui.CN) AsyncResource(com.codename1.util.AsyncResource) MediaManager(com.codename1.media.MediaManager) MediaPlayer(com.codename1.components.MediaPlayer) Image(com.codename1.ui.Image) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) Media(com.codename1.media.Media) UIManager(com.codename1.ui.plaf.UIManager) Dialog(com.codename1.ui.Dialog) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Label(com.codename1.ui.Label) IOException(java.io.IOException) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) MediaPlayer(com.codename1.components.MediaPlayer)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)95 Button (com.codename1.ui.Button)50 BorderLayout (com.codename1.ui.layouts.BorderLayout)50 Container (com.codename1.ui.Container)49 Component (com.codename1.ui.Component)27 SpanLabel (com.codename1.components.SpanLabel)26 Style (com.codename1.ui.plaf.Style)24 BoxLayout (com.codename1.ui.layouts.BoxLayout)19 TextArea (com.codename1.ui.TextArea)18 ActionEvent (com.codename1.ui.events.ActionEvent)18 IOException (java.io.IOException)18 Image (com.codename1.ui.Image)17 Dimension (com.codename1.ui.geom.Dimension)16 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)15 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)15 Toolbar (com.codename1.ui.Toolbar)13 FlowLayout (com.codename1.ui.layouts.FlowLayout)12 EncodedImage (com.codename1.ui.EncodedImage)11