Search in sources :

Example 51 with Component

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

the class Oauth2 method showAuthentication.

/**
 * 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(ActionListener al) {
    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));
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) InfiniteProgress(com.codename1.components.InfiniteProgress) Command(com.codename1.ui.Command) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 52 with Component

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

the class Oauth2 method createLoginComponent.

private Component createLoginComponent(final ActionListener al, final Form frm, final Form backToForm, final Dialog progress) {
    String URL = oauth2URL + "?client_id=" + clientId + "&redirect_uri=" + Util.encodeUrl(redirectURI);
    if (scope != null) {
        URL += "&scope=" + scope;
    }
    if (clientSecret != null) {
        URL += "&response_type=code";
    } else {
        URL += "&response_type=token";
    }
    if (additionalParams != null) {
        Enumeration e = additionalParams.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String val = additionalParams.get(key).toString();
            URL += "&" + key + "=" + val;
        }
    }
    DocumentInfo.setDefaultEncoding(DocumentInfo.ENCODING_UTF8);
    final WebBrowser[] web = new WebBrowser[1];
    web[0] = new WebBrowser() {

        @Override
        public void onLoad(String url) {
            handleURL(url, this, al, frm, backToForm, progress);
        }

        public void onStart(String url) {
        }
    };
    web[0].setURL(URL);
    return web[0];
}
Also used : Enumeration(java.util.Enumeration) WebBrowser(com.codename1.components.WebBrowser)

Example 53 with Component

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

the class ImageDownloadService method createImageToFileSystem.

/**
 * Constructs an image request that will automatically populate the given list
 * when the response arrives, it will cache the file locally as a file
 * in the file storage.
 * This assumes the GenericListCellRenderer style of
 * list which relies on a map based model approach.
 *
 * @param url the image URL
 * @param targetList the list that should be updated when the data arrives
 * @param targetOffset the offset within the list to insert the image
 * @param targetKey the key for the map in the target offset
 * @param destFile local file to store the data into the given path
 */
private static void createImageToFileSystem(final String url, final Component targetList, final ListModel targetModel, final int targetOffset, final String targetKey, final String destFile, final Dimension toScale, final byte priority, final Image placeholderImage, final boolean maintainAspectRatio) {
    if (Display.getInstance().isEdt()) {
        Display.getInstance().scheduleBackgroundTask(new Runnable() {

            public void run() {
                createImageToFileSystem(url, targetList, targetModel, targetOffset, targetKey, destFile, toScale, priority, placeholderImage, maintainAspectRatio);
            }
        });
        return;
    }
    // image not found on cache go and download from the url
    ImageDownloadService i = new ImageDownloadService(url, targetList, targetOffset, targetKey);
    i.targetModel = targetModel;
    i.maintainAspectRatio = maintainAspectRatio;
    Image im = cacheImage(null, false, destFile, toScale, placeholderImage, maintainAspectRatio);
    if (im != null) {
        i.setEntryInListModel(targetOffset, im);
        targetList.repaint();
        return;
    }
    i.cacheImages = true;
    i.destinationFile = destFile;
    i.toScale = toScale;
    i.placeholder = placeholderImage;
    i.setPriority(priority);
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}
Also used : EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Example 54 with Component

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

the class ImageDownloadService method postResponse.

/**
 * {@inheritDoc}
 */
protected void postResponse() {
    // trigger an exception in case of an invalid image
    result.getWidth();
    Image image = result;
    if (toScale != null && toScale.getWidth() != image.getWidth() && toScale.getHeight() != image.getHeight()) {
        image = scaleImage(image, toScale, maintainAspectRatio);
    }
    final Image i = image;
    if (parentLabel != null) {
        final Dimension pref = parentLabel.getPreferredSize();
        if (parentLabel.getComponentForm() != null) {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (isDownloadToStyles()) {
                        parentLabel.getUnselectedStyle().setBgImage(i);
                        parentLabel.getSelectedStyle().setBgImage(i);
                        parentLabel.getPressedStyle().setBgImage(i);
                    } else {
                        parentLabel.setIcon(i);
                    }
                    Dimension newPref = parentLabel.getPreferredSize();
                    // sized image in place or has a hardcoded preferred size.
                    if (pref.getWidth() != newPref.getWidth() || pref.getHeight() != newPref.getHeight()) {
                        parentLabel.getComponentForm().revalidate();
                    }
                }
            });
        } else {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    if (isDownloadToStyles()) {
                        parentLabel.getUnselectedStyle().setBgImage(i);
                        parentLabel.getSelectedStyle().setBgImage(i);
                        parentLabel.getPressedStyle().setBgImage(i);
                    } else {
                        parentLabel.setIcon(i);
                    }
                }
            });
        }
        parentLabel.repaint();
        return;
    } else {
        if (targetList != null) {
            setEntryInListModel(targetOffset, image);
            // revalidate only once to avoid multiple revalidate refreshes during scroll
            if (targetList.getParent() != null) {
                if (alwaysRevalidate) {
                    targetList.getParent().revalidate();
                } else {
                    if (targetList.getClientProperty("$imgDSReval") == null) {
                        targetList.putClientProperty("$imgDSReval", Boolean.TRUE);
                        targetList.getParent().revalidate();
                    } else {
                        targetList.repaint();
                    }
                }
            }
        }
    }
    // if this is a list cell renderer component
    fireResponseListener(new NetworkEvent(this, result));
}
Also used : NetworkEvent(com.codename1.io.NetworkEvent) Dimension(com.codename1.ui.geom.Dimension) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Example 55 with Component

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

the class CodenameOneInputConnection method commitText.

@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            TextField t = (TextField) txtCmp;
            String textFieldText = t.getText();
            int cursorPosition = t.getCursorPosition();
            StringBuilder sb = new StringBuilder(textFieldText);
            if (text.equals("\n")) {
            // System.out.println("hello backslash");
            }
            if (composingText.length() > 0) {
                if (text.equals(" ")) {
                    return commitText(composingText + " ", newCursorPosition);
                }
                sb.replace(sb.length() - composingText.length(), sb.length(), text.toString());
                composingText = "";
            } else {
                sb.insert(cursorPosition, text);
            }
            t.setText(sb.toString());
            t.setCursorPosition(cursorPosition + text.length());
            updateExtractedText();
        }
    }
    return super.commitText(text, newCursorPosition);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Aggregations

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13