Java Code Examples for com.codename1.ui.Dialog#dispose()

The following examples show how to use com.codename1.ui.Dialog#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
ActionListener createDetailsButtonActionListener(final long imageId) {
    return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                InfiniteProgress ip = new InfiniteProgress();
                Dialog dlg = ip.showInifiniteBlocking();
                try {
                    String[] data = WebServiceProxy.getPhotoDetails(imageId);
                    String s = "";
                    for(String d : data) {
                        s += d;
                        s += "\n";
                    }
                    dlg.dispose();
                    Dialog.show("Data", s, "OK", null);
                } catch(IOException err) {
                    dlg.dispose();
                    Dialog.show("Error", "Error connecting to server", "OK", null);
                }
            }
        };
}
 
Example 2
Source File: SignIn.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: SignIn.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: SignIn.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: SignIn.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 6
Source File: FullScreenAdService.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoked on application startup, this code will download an ad or timeout 
 */
public void showWelcomeAd() {
    if(!UIManager.getInstance().wasThemeInstalled()) {
        if(Display.getInstance().hasNativeTheme()) {
            Display.getInstance().installNativeTheme();
        }
    }
    ConnectionRequest r = createAdRequest();
    r.setPriority(ConnectionRequest.PRIORITY_HIGH);
    r.setTimeout(timeout);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog ipDialog = ip.showInifiniteBlocking();
    NetworkManager.getInstance().addToQueueAndWait(r);
    if(failed()) {
        ipDialog.dispose();
        if(!allowWithoutNetwork) {
            ipDialog.dispose();
            Dialog.show("Network Error", "Please try again later", "Exit", null);
            Display.getInstance().exitApplication();
        } else {
            return;
        }
    }
    Component c = getPendingAd();
    if(c != null) {
        Form adForm = new AdForm(c);
        adForm.setTransitionInAnimator(CommonTransitions.createEmpty());
        adForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
        adForm.show();
    }
}
 
Example 7
Source File: Util.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private static boolean downloadUrlTo(String url, String fileName, boolean showProgress, boolean background, boolean storage, ActionListener callback) {
    ConnectionRequest cr = new ConnectionRequest();
    cr.setPost(false);
    cr.setFailSilently(true);
    cr.setReadResponseForErrors(false);
    cr.setDuplicateSupported(true);
    cr.setUrl(url);
    if(callback != null) {
        cr.addResponseListener(callback);
    }
    if(storage) {
        cr.setDestinationStorage(fileName);
    } else {
        cr.setDestinationFile(fileName);
    }
    if(background) {
        NetworkManager.getInstance().addToQueue(cr);
        return true;
    } 
    if(showProgress) {
        InfiniteProgress ip = new InfiniteProgress();
        Dialog d = ip.showInifiniteBlocking();
        NetworkManager.getInstance().addToQueueAndWait(cr);
        d.dispose();
    } else {
        NetworkManager.getInstance().addToQueueAndWait(cr);
    }
    int rc = cr.getResponseCode();
    return rc == 200 || rc == 201;
}
 
Example 8
Source File: Oauth2.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method shows an authentication for login form
 *
 * @param al a listener that will receive at its source either a token for
 * the service or an exception in case of a failure
 * @return a component that should be displayed to the user in order to
 * perform the authentication
 */
public void showAuthentication(final ActionListener al) {
    
    if (useBrowserWindow) {
        final BrowserWindow win = new BrowserWindow(buildURL());
        win.setTitle("Login");
        win.addLoadListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                String url = (String)evt.getSource();
                if (url.startsWith(redirectURI)) {
                    win.close();
                    handleURL((String)evt.getSource(), null, al, null, null, null);
                }    
            }
        });

        win.show(); 
        return;
        
    }
    
    final Form old = Display.getInstance().getCurrent();
    InfiniteProgress inf = new InfiniteProgress();
    final Dialog progress = inf.showInifiniteBlocking();
    Form authenticationForm = new Form("Login");
    authenticationForm.setScrollable(false);
    if (old != null) {
        Command cancel = new Command("Cancel") {
            public void actionPerformed(ActionEvent ev) {
                if (Display.getInstance().getCurrent() == progress) {
                    progress.dispose();
                }
                old.showBack();
            }
        };
        if (authenticationForm.getToolbar() != null){
            authenticationForm.getToolbar().addCommandToLeftBar(cancel);
        } else {
            authenticationForm.addCommand(cancel);
        }
        authenticationForm.setBackCommand(cancel);
    }
    authenticationForm.setLayout(new BorderLayout());
    authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}