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

The following examples show how to use com.codename1.ui.Dialog#show() . 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: VideoPlayerSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
void downloadFile(final Form parent) {
    download = new ConnectionRequest("https://www.codenameone.com/files/hello-codenameone.mp4") {
        @Override
        protected void postResponse() {
            
            if(parent != getCurrentForm()) {
                if(!Dialog.show("Download Finished", "Downloading the video completed!\nDo you want to show it now?",
                        "Show", "Later")) {
                    return;
                }
                parent.show();
            }
            playVideo(parent, getAppHomePath() + "hello-codenameone.mp4");
        }
    };
    download.setPost(false);
    download.setDestinationFile(getAppHomePath() + "hello-codenameone.mp4");
    ToastBar.showConnectionProgress("Downloading video", download, null, null);
    addToQueue(download);        
}
 
Example 2
Source File: GlassTutorial.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Install the glass tutorial on a form and seamlessly dismiss it when no longer necessary
 * @param f the form
 */
public void showOn(Form f) {
    Painter oldPane = f.getGlassPane();
    f.setGlassPane(this);
    Dialog dummy = new Dialog() {
        public void keyReleased(int i) {
            dispose();
        }
    };
    int oldTint = f.getTintColor();
    f.setTintColor(0);
    
    dummy.getDialogStyle().setBgTransparency(0);
    dummy.setDisposeWhenPointerOutOfBounds(true);
    dummy.show(0, Display.getInstance().getDisplayHeight() - 2, 0, Display.getInstance().getDisplayWidth() - 2, true, true);
    
    f.setTintColor(oldTint);
    f.setGlassPane(oldPane);
}
 
Example 3
Source File: SocialChat.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
private void listenToMessages() {
    try {
        pb = new Pubnub(PUBNUB_PUB_KEY, PUBNUB_SUB_KEY);
        pb.subscribe(tokenPrefix + uniqueId, new Callback() {
            @Override
            public void successCallback(String channel, Object message, String timetoken) {
                if(message instanceof String) {
                    pendingAck.remove(channel);
                    return;
                }
                Message m = new Message((JSONObject)message);
                pb.publish(tokenPrefix + m.getSenderId(),  "ACK", new Callback() {});
                Display.getInstance().callSerially(() -> {
                    addMessage(m);
                    respond(m);
                });
            }
        });
    } catch(PubnubException err) {
        Log.e(err);
        Dialog.show("Error", "There was a communication error: " + err, "OK", null);
    }
}
 
Example 4
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 5
Source File: Oauth2.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method preforms the actual authentication, this method is a blocking
 * method that will display the user the html authentication pages.
 *
 * @return the method if passes authentication will return the access token
 * or null if authentication failed.
 *
 * @throws IOException the method will throw an IOException if something
 * went wrong in the communication.
 * @deprecated use createAuthComponent or showAuthentication which work
 * asynchronously and adapt better to different platforms
 */
public String authenticate() {

    if (token == null) {
        login = new Dialog();
        boolean i = Dialog.isAutoAdjustDialogSize();
        Dialog.setAutoAdjustDialogSize(false);
        login.setLayout(new BorderLayout());
        login.setScrollable(false);

        Component html = createLoginComponent(null, null, null, null);
        login.addComponent(BorderLayout.CENTER, html);
        login.setScrollable(false);
        login.setDialogUIID("Container");
        login.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300));
        login.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300));
        login.show(0, 0, 0, 0, false, true);
        Dialog.setAutoAdjustDialogSize(i);
    }

    return token;
}
 
Example 6
Source File: WebSocketsSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
void showChat() {
    Form f= new Form("Chat");
    f.setLayout(new BorderLayout());
    
    Container south = new Container();
    final TextField tf = new TextField();
    Button send = new Button(new Command("Send") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (sock.getReadyState() == WebSocketState.OPEN) {
                sock.send(tf.getText());
                tf.setText("");
            } else {
                Dialog.show("", "The socket is not open", "OK", null);
                showLogin();
            }
            
        }
         
    });
    
    chatContainer = new Container();
    chatContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    
    south.addComponent(tf);
    south.addComponent(send);
    f.addComponent(BorderLayout.SOUTH, south);
    f.addComponent(BorderLayout.CENTER, chatContainer);
    f.setFormBottomPaddingEditingMode(true);
    f.show();
    
}
 
Example 7
Source File: IntentIntegrator.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void showDownloadDialog() {
    Dialog d = new Dialog();
    d.setTitle(title);
    if (Dialog.show(title, message, "Yes", "No")) {
        Uri uri = Uri.parse("market://details?id=" + BSSIMPLE_PACKAGE);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        try {
            activity.startActivity(intent);
        } catch (ActivityNotFoundException anfe) {
            // Hmm, market is not installed
            Log.w(TAG, "Android Market is not installed; cannot install Barcode Scanner");
        }
    }

}
 
Example 8
Source File: ConnectionRequest.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles a server response code that is not 200 and not a redirect (unless redirect handling is disabled)
 *
 * @param code the response code from the server
 * @param message the response message from the server
 */
protected void handleErrorResponseCode(int code, String message) {
    if(responseCodeListeners != null) {
        if(!isKilled()) {
            NetworkEvent n = new NetworkEvent(this, code, message);
            responseCodeListeners.fireActionEvent(n);
        }
        return;
    }
    if(failSilently) {
        failureErrorCode = code;
        return;
    }
    
    if(handleErrorCodesInGlobalErrorHandler) {
        if(NetworkManager.getInstance().handleErrorCode(this, code, message)) {
            failureErrorCode = code;
            return;
        }
    }
    
    Log.p("Unhandled error code: " + code + " for " + url);
    if(Display.isInitialized() && !Display.getInstance().isMinimized() &&
            Dialog.show("Error", code + ": " + message, "Retry", "Cancel")) {
        retry();
    } else {
        retrying = false;
        if(!isReadResponseForErrors()){
            killed = true;
        }
    }
}
 
Example 9
Source File: Log.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends the current log to the cloud regardless of the reporting level
 */
private static void sendLogLegacy() {
    try {
        // this can cause a crash
        if(!Display.isInitialized()) {
            return;
        }
        if(!instance.logDirty) {
            return;
        }
        instance.logDirty = false;
        long devId = getUniqueDeviceId();
        if(devId < 0) {
            Dialog.show("Send Log Error", "Device Not Registered: Sending a log from an unregistered device is impossible", "OK", null);
            return;
        }
        ConnectionRequest r = new ConnectionRequest();
        r.setPost(false);
        r.setUrl(Display.getInstance().getProperty("cloudServerURL", "https://codename-one.appspot.com/") + "uploadLogRequest");
        r.setFailSilently(true);
        NetworkManager.getInstance().addToQueueAndWait(r);
        String url = new String(r.getResponseData());
        
        MultipartRequest m = new MultipartRequest();
        m.setUrl(url);
        byte[] read = Util.readInputStream(Storage.getInstance().createInputStream("CN1Log__$"));
        m.addArgument("i", "" + devId);
        m.addArgument("by",Display.getInstance().getProperty("built_by_user", ""));
        m.addArgument("p", Display.getInstance().getProperty("package_name", ""));
        m.addArgument("v", Display.getInstance().getProperty("AppVersion", "0.1"));
        m.addData("log", read, "text/plain");
        m.setFailSilently(true);
        NetworkManager.getInstance().addToQueueAndWait(m);
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
 
Example 10
Source File: Log.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends the current log to the cloud regardless of the reporting level
 */
private static void sendLogImpl(boolean sync) {
    try {
        // this can cause a crash
        if(!Display.isInitialized()) {
            return;
        }
        if(!instance.logDirty) {
            return;
        }
        instance.logDirty = false;
        String devId = getUniqueDeviceKey();
        if(devId == null) {
            if(Display.getInstance().isSimulator()) {
                Dialog.show("Send Log Error", "Device Not Registered: Sending a log from an unregistered device is impossible", "OK", null);
            } else {
                Log.p("Device Not Registered: Sending a log from an unregistered device is impossible");
            }
            return;
        }
        ConnectionRequest r = new ConnectionRequest();
        r.setPost(false);
        MultipartRequest m = new MultipartRequest();
        m.setUrl("https://crashreport.codenameone.com/CrashReporterEmail/sendCrashReport");
        byte[] read = Util.readInputStream(Storage.getInstance().createInputStream("CN1Log__$"));
        m.addArgument("i", "" + devId);
        m.addArgument("u",Display.getInstance().getProperty("built_by_user", ""));
        m.addArgument("p", Display.getInstance().getProperty("package_name", ""));
        m.addArgument("v", Display.getInstance().getProperty("AppVersion", "0.1"));
        m.addData("log", read, "text/plain");
        m.setFailSilently(true);
        if(sync) {
            NetworkManager.getInstance().addToQueueAndWait(m);
        } else {
            NetworkManager.getInstance().addToQueue(m);
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
 
Example 11
Source File: JavascriptScrollingTest.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
protected void onTest() {
	Dialog dlg = new Dialog("Test");
	dlg.setLayout(new BorderLayout());
	TextArea taMsg = new TextArea();
	dlg.add(BorderLayout.CENTER, taMsg);
	Button btnOk = new Button("Ok");
	btnOk.addActionListener(e -> dlg.dispose());
	dlg.add(BorderLayout.SOUTH, btnOk);
	taMsg.setText("This is a test Message");
	taMsg.setGrowLimit(-1);
	taMsg.getAllStyles().setAlignment(TextArea.LEFT);
	dlg.show();

}
 
Example 12
Source File: PushDemo.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
public void registeredForPush(String deviceId) {
    Dialog.show("Push Registered", "Device ID: " + deviceId + "\nDevice Key: " + Push.getPushKey(), "OK", null);
    String k = Push.getPushKey();
    if(k != null) {
        s.findDeviceKey().setText("Device Key: " + k);
    }
    
    Message m = new Message(Push.getPushKey());
    Display.getInstance().sendMessage(new String[] {"[email protected]"}, "Push key", m);
}
 
Example 13
Source File: PushDemo.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void push(String value) {
    Dialog.show("Push Received", value, "OK", null);
}
 
Example 14
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void subscriptionStarted(String sku) {
    Dialog.show("Event Received", "subscriptionStarted for SKU: " + sku, "OK", null);
}
 
Example 15
Source File: SetPageURLHierarchyTest.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form wform = new Form("wform", new BorderLayout());

    final BrowserComponent browser = new BrowserComponent();

    try {

        browser.setURLHierarchy("/Page.html");

    } catch (IOException ex) {

        Dialog.show("Error", "cannot set URL."
                + "\nError: " + ex.toString(), "OK", null);

    }

    wform.addComponent(BorderLayout.CENTER, browser);

    wform.show();
}
 
Example 16
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void paymentFailed(String paymentCode, String failureReason) {
    Dialog.show("Event Received", "paymentFailed: " + failureReason, "OK", null);
}
 
Example 17
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void paymentSucceeded(String paymentCode, double amount, String currency) {
    Dialog.show("Event Received", "paymentSucceeded amount: " + amount, "OK", null);
}
 
Example 18
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void pushRegistrationError(String error, int errorCode) {
    Dialog.show("Error: " + errorCode, error, "OK", null);
}
 
Example 19
Source File: PushDemo.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
public void pushRegistrationError(String error, int errorCode) {
    Dialog.show("Registration Error", "Error " + errorCode + "\n" + error, "OK", null);
}
 
Example 20
Source File: Purchase.java    From CodenameOne with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Open the platform's UI for managing subscriptions.  Currently iOS and Android
 * are the only platforms that support this.  Other platforms will simply display a dialog stating that
 * it doesn't support this feature.  Use the {@link #isManageSubscriptionsSupported() } method to check
 * if the platform supports this feature.
 * 
 * 
 * @param sku Optional sku of product whose subscription you wish to manage.  If left {@literal null}, then
 * the general subscription management UI will be opened.  iOS doesn't support "deep-linking" directly to the 
 * management for a particular sku, so this parameter is ignored there.  If included on Android, howerver, 
 * it will open the UI for managing the specified sku.
 * 
 * @since 6.0
 */
public void manageSubscriptions(String sku) {
    Dialog.show("Not Supported", "This platform doesn't support in-app subscription management. ", "OK", null);
}