Search in sources :

Example 26 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class DefaultCrashReporter method exception.

/**
 * {@inheritDoc}
 */
public void exception(Throwable t) {
    Preferences.set("$CN1_pendingCrash", true);
    if (promptUser) {
        Dialog error = new Dialog("Error");
        error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        TextArea txt = new TextArea(errorText);
        txt.setEditable(false);
        txt.setUIID("DialogBody");
        error.addComponent(txt);
        CheckBox cb = new CheckBox(checkboxText);
        cb.setUIID("DialogBody");
        error.addComponent(cb);
        Container grid = new Container(new GridLayout(1, 2));
        error.addComponent(grid);
        Command ok = new Command(sendButtonText);
        Command dont = new Command(dontSendButtonText);
        Button send = new Button(ok);
        Button dontSend = new Button(dont);
        grid.addComponent(send);
        grid.addComponent(dontSend);
        Command result = error.showPacked(BorderLayout.CENTER, true);
        if (result == dont) {
            if (cb.isSelected()) {
                Preferences.set("$CN1_crashBlocked", true);
            }
            Preferences.set("$CN1_pendingCrash", false);
            return;
        } else {
            if (cb.isSelected()) {
                Preferences.set("$CN1_prompt", false);
            }
        }
    }
    Log.sendLog();
    Preferences.set("$CN1_pendingCrash", false);
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) TextArea(com.codename1.ui.TextArea) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) Dialog(com.codename1.ui.Dialog) CheckBox(com.codename1.ui.CheckBox) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 27 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_browsercomponent.

private void getComponentAt_int_int_browsercomponent() {
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form mapDemo = new Form("Maps", new LayeredLayout());
    Toolbar.setOnTopSideMenu(true);
    Toolbar tb = new Toolbar();
    mapDemo.setToolbar(tb);
    mapDemo.setTitle("Maps");
    tb.addCommandToSideMenu(new Command("Test") {

        @Override
        public void actionPerformed(ActionEvent e) {
        // testNestedScrollingLabels();
        }
    });
    BrowserComponent mc = new BrowserComponent();
    mapDemo.add(mc);
    mapDemo.show();
    TestUtils.waitForFormTitle("Maps", 2000);
    Component middleComponent = mapDemo.getComponentAt(w / 2, h / 2);
    assertTrue(mc == middleComponent || mc.contains(middleComponent), "Wrong component found in middle. Expected " + mc + " but found " + middleComponent);
    tb.openSideMenu();
    // wait for side menu to open
    TestUtils.waitFor(500);
    Component res = null;
    res = tb.getComponentAt(10, h / 2);
    // System.out.println("tb size = "+tb.getAbsoluteX()+", "+tb.getAbsoluteY()+", "+tb.getWidth()+", "+tb.getHeight());
    // System.out.println("mb size = "+tb.getMenuBar().getAbsoluteX()+", "+tb.getMenuBar().getAbsoluteY()+", "+tb.getMenuBar().getWidth()+", "+tb.getMenuBar().getHeight());
    // System.out.println("res is "+res);
    res = mapDemo.getComponentAt(10, h / 2);
    // Let's find the interaction dialog on the form
    Component interactionDialog = $("*", mapDemo).filter(c -> {
        return c instanceof InteractionDialog;
    }).asComponent();
    assertTrue(((InteractionDialog) interactionDialog).contains(res), "Toolbar is open so getComponentAt() should return something on the toolbar.  But received " + res + ".  Toolbar is " + tb);
}
Also used : Util(com.codename1.io.Util) BoxLayout(com.codename1.ui.layouts.BoxLayout) ActionEvent(com.codename1.ui.events.ActionEvent) NetworkManager(com.codename1.io.NetworkManager) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) NetworkEvent(com.codename1.io.NetworkEvent) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) ConnectionRequest(com.codename1.io.ConnectionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) AbstractTest(com.codename1.testing.AbstractTest) TestUtils(com.codename1.testing.TestUtils) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat) Cookie(com.codename1.io.Cookie) FileSystemStorage(com.codename1.io.FileSystemStorage) IOException(java.io.IOException) ActionListener(com.codename1.ui.events.ActionListener) JSONParser(com.codename1.io.JSONParser) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) InputStreamReader(java.io.InputStreamReader) Style(com.codename1.ui.plaf.Style) Coord(com.codename1.maps.Coord) ToastBar(com.codename1.components.ToastBar) InteractionDialog(com.codename1.components.InteractionDialog) InteractionDialog(com.codename1.components.InteractionDialog) ActionEvent(com.codename1.ui.events.ActionEvent) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 28 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class SignIn method showGoogleUser.

private void showGoogleUser(String token) {
    ConnectionRequest req = new ConnectionRequest();
    req.addRequestHeader("Authorization", "Bearer " + token);
    req.setUrl("https://www.googleapis.com/plus/v1/people/me");
    req.setPost(false);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    NetworkManager.getInstance().addToQueueAndWait(req);
    d.dispose();
    byte[] data = req.getResponseData();
    JSONParser parser = new JSONParser();
    Map map = null;
    try {
        map = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(data), "UTF-8"));
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    String name = (String) map.get("displayName");
    Map im = (Map) map.get("image");
    String url = (String) im.get("url");
    Form userForm = new UserForm(name, (EncodedImage) theme.getImage("user.png"), url);
    userForm.show();
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) InfiniteProgress(com.codename1.components.InfiniteProgress) ByteArrayInputStream(java.io.ByteArrayInputStream) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) JSONParser(com.codename1.io.JSONParser) IOException(java.io.IOException) Map(java.util.Map)

Example 29 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class SignIn method showFacebookUser.

private void showFacebookUser(String token) {
    ConnectionRequest req = new ConnectionRequest();
    req.setPost(false);
    req.setUrl("https://graph.facebook.com/v2.3/me");
    req.addArgumentNoEncoding("access_token", token);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    NetworkManager.getInstance().addToQueueAndWait(req);
    byte[] data = req.getResponseData();
    JSONParser parser = new JSONParser();
    Map map = null;
    try {
        map = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(data), "UTF-8"));
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    String name = (String) map.get("name");
    d.dispose();
    Form userForm = new UserForm(name, (EncodedImage) theme.getImage("user.png"), "https://graph.facebook.com/v2.3/me/picture?access_token=" + token);
    userForm.show();
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) InfiniteProgress(com.codename1.components.InfiniteProgress) ByteArrayInputStream(java.io.ByteArrayInputStream) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) JSONParser(com.codename1.io.JSONParser) IOException(java.io.IOException) Map(java.util.Map)

Example 30 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class Toolbar method createOverflowCommandList.

/**
 * Creates the list component containing the commands within the given
 * vector used for showing the menu dialog
 *
 * @param commands list of command objects
 * @return List object
 */
protected List createOverflowCommandList(Vector commands) {
    List l = new List(commands);
    l.setUIID("CommandList");
    Component c = (Component) l.getRenderer();
    c.setUIID("Command");
    c = l.getRenderer().getListFocusComponent(l);
    c.setUIID("CommandFocus");
    l.setFixedSelection(List.FIXED_NONE_CYCLIC);
    l.setScrollVisible(false);
    ((DefaultListCellRenderer) l.getRenderer()).setShowNumbers(false);
    return l;
}
Also used : DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer) ArrayList(java.util.ArrayList)

Aggregations

Dialog (com.codename1.ui.Dialog)28 Form (com.codename1.ui.Form)23 BorderLayout (com.codename1.ui.layouts.BorderLayout)17 Component (com.codename1.ui.Component)16 ActionEvent (com.codename1.ui.events.ActionEvent)14 Container (com.codename1.ui.Container)13 Style (com.codename1.ui.plaf.Style)12 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)7 IOException (java.io.IOException)7 InfiniteProgress (com.codename1.components.InfiniteProgress)6 Command (com.codename1.ui.Command)6 Label (com.codename1.ui.Label)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ConnectionRequest (com.codename1.io.ConnectionRequest)4 Button (com.codename1.ui.Button)4 CheckBox (com.codename1.ui.CheckBox)4 Painter (com.codename1.ui.Painter)4 TextArea (com.codename1.ui.TextArea)4