Search in sources :

Example 46 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class IOSImplementation method openGallery.

@Override
public void openGallery(ActionListener response, int type) {
    if (!isGalleryTypeSupported(type)) {
        throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform.");
    }
    if (!nativeInstance.checkPhotoLibraryUsage()) {
        throw new RuntimeException("Please add the ios.NSPhotoLibraryUsageDescription build hint");
    }
    switch(type) {
        case -9998:
        case Display.GALLERY_ALL_MULTI:
        case Display.GALLERY_IMAGE_MULTI:
        case Display.GALLERY_VIDEO_MULTI:
            gallerySelectMultiple = true;
            break;
        default:
            gallerySelectMultiple = false;
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.openGallery(type);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 47 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class IOSImplementation method updateNativeTextEditorFrame.

private static void updateNativeTextEditorFrame(boolean requestFocus) {
    if (instance.currentEditing != null) {
        TextArea cmp = instance.currentEditing;
        Form form = cmp.getComponentForm();
        if (form == null || form != CN.getCurrentForm()) {
            instance.stopTextEditing();
            return;
        }
        int x = cmp.getAbsoluteX() + cmp.getScrollX();
        int y = cmp.getAbsoluteY() + cmp.getScrollY();
        int w = cmp.getWidth();
        int h = cmp.getHeight();
        String key = LAST_UPDATED_EDITOR_BOUNDS_KEY;
        Rectangle lastUpdatedBounds = (Rectangle) cmp.getClientProperty(key);
        if (lastUpdatedBounds != null) {
            if (lastUpdatedBounds.getX() == x && lastUpdatedBounds.getY() == y && lastUpdatedBounds.getWidth() == w && lastUpdatedBounds.getHeight() == h) {
                return;
            }
            lastUpdatedBounds.setBounds(x, y, w, h);
        } else {
            lastUpdatedBounds = new Rectangle(x, y, w, h);
            cmp.putClientProperty(key, lastUpdatedBounds);
        }
        final Style stl = cmp.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        if (requestFocus) {
            instance.doNotHideTextEditorSemaphore++;
            try {
                instance.currentEditing.requestFocus();
            } finally {
                instance.doNotHideTextEditorSemaphore--;
            }
        }
        x = cmp.getAbsoluteX() + cmp.getScrollX();
        y = cmp.getAbsoluteY() + cmp.getScrollY();
        w = cmp.getWidth();
        h = cmp.getHeight();
        int pt = stl.getPaddingTop();
        int pb = stl.getPaddingBottom();
        int pl = stl.getPaddingLeft(rtl);
        int pr = stl.getPaddingRight(rtl);
        /*
            if(cmp.isSingleLineTextArea()) {
                switch(cmp.getVerticalAlignment()) {
                    case TextArea.CENTER:
                        if(h > cmp.getPreferredH()) {
                            y += (h / 2 - cmp.getPreferredH() / 2);
                        }
                        break;
                    case TextArea.BOTTOM:
                        if(h > cmp.getPreferredH()) {
                            y += (h - cmp.getPreferredH());
                        }
                        break;
                }
            }
            */
        Container contentPane = form.getContentPane();
        if (!contentPane.contains(cmp)) {
            contentPane = form;
        }
        Style contentPaneStyle = contentPane.getStyle();
        int minY = contentPane.getAbsoluteY() + contentPane.getScrollY() + contentPaneStyle.getPaddingTop();
        int maxH = Display.getInstance().getDisplayHeight() - minY - nativeInstance.getVKBHeight();
        if (y < minY) {
            h -= (minY - y);
            y = minY;
        }
        if (h > maxH) {
            // For text areas, we don't want the keyboard to cover part of the
            // typing region.  So we will try to size the component to
            // to only go up to the top edge of the keyboard
            // that should allow the OS to enable scrolling properly.... at least
            // in theory.
            h = maxH;
        }
        if (h < 0) {
            // There isn't room for the editor at all.
            Log.p("No room for text editor.  h=" + h);
            instance.stopTextEditing();
            return;
        }
        if (x < 0 || y < 0 || w <= 0 || h <= 0) {
            instance.stopTextEditing();
            return;
        }
        nativeInstance.resizeNativeTextView(x, y, w, h, pt, pr, pb, pl);
    }
}
Also used : Container(com.codename1.ui.Container) TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style)

Example 48 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class Push method sendPushMessage.

/**
 * Sends a push message and returns true if server delivery succeeded, notice that the
 * push message isn't guaranteed to reach all devices.
 *
 * @param body the body of the message
 * @param deviceKey an optional parameter (can be null) when sending to a specific device
 * @param production whether pushing to production or test/sandbox environment
 * @param googleAuthKey authorization key from the google play store
 * @param iosCertificateURL a URL where you host the iOS certificate for this applications push capabilities.
 * @param iosCertificatePassword the password for the push certificate
 * @param bbUrl the URL to which the push should be submitted when sending a blackberry push for evaluation use https://pushapi.eval.blackberry.com
 * for production you will need to apply at https://cp310.pushapi.na.blackberry.com
 * @param bbApp the application id to authenticate on push for RIM devices
 * @param bbPass the application password credentials authenticate on push for RIM devices
 * @param bbPort the port of the blackberry push
 * @return true if the message reached the Codename One server successfully, this makes no guarantee
 * of delivery.
 * @deprecated this method sends a push using the old push servers which will be retired, you need to switch
 * to the equivalent method that accepts a push token
 */
public static boolean sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort) {
    ConnectionRequest cr = createPushMessage(body, deviceKey, production, googleAuthKey, iosCertificateURL, iosCertificatePassword, bbUrl, bbApp, bbPass, bbPort);
    NetworkManager.getInstance().addToQueueAndWait(cr);
    if (cr.getResposeCode() == 200) {
        return true;
    }
    return false;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 49 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class PushBuilder method build.

/**
 * Builds the payload for this rich push notification.
 * @return The payload that can be passed as the message body to {@link Push}
 */
public String build() {
    StringBuilder sb = new StringBuilder();
    switch(type) {
        case 0:
        case 1:
            sb.append(body);
            break;
        case 2:
            sb.append(metaData);
            break;
        case 3:
            sb.append(metaData).append(";").append(body);
            break;
        case 4:
            sb.append(title).append(";").append(body);
            break;
        case 5:
            sb.append(body);
            break;
        case 6:
        case 100:
            sb.append(badge);
            break;
        case 101:
            sb.append(badge).append(" ").append(body);
            break;
        case 102:
            sb.append(badge).append(";").append(title).append(";").append(body);
            break;
    }
    if (isRichPush()) {
        String b = sb.toString();
        sb.setLength(0);
        Element el = new Element("push");
        el.setAttribute("type", "" + type);
        el.setAttribute("body", b);
        if (category != null) {
            el.setAttribute("category", category);
        }
        if (imageUrl != null) {
            Element imgEl = new Element("img");
            imgEl.setAttribute("src", imageUrl);
            el.addChild(imgEl);
        }
        return el.toString();
    }
    return sb.toString();
}
Also used : Element(com.codename1.xml.Element)

Example 50 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class AndroidImplementation method openGallery.

public void openGallery(final ActionListener response, int type) {
    if (!isGalleryTypeSupported(type)) {
        throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform.");
    }
    if (getActivity() == null) {
        throw new RuntimeException("Cannot open galery in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to browse the photos")) {
        return;
    }
    if (editInProgress()) {
        stopEditing(true);
    }
    final boolean multi;
    switch(type) {
        case Display.GALLERY_ALL_MULTI:
            multi = true;
            type = Display.GALLERY_ALL;
            break;
        case Display.GALLERY_VIDEO_MULTI:
            multi = true;
            type = Display.GALLERY_VIDEO;
            break;
        case Display.GALLERY_IMAGE_MULTI:
            multi = true;
            type = Display.GALLERY_IMAGE;
            break;
        case -9998:
            multi = true;
            type = -9999;
            break;
        default:
            multi = false;
    }
    callback = new EventDispatcher();
    callback.addListener(response);
    Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    if (multi) {
        galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }
    if (type == Display.GALLERY_VIDEO) {
        galleryIntent.setType("video/*");
    } else if (type == Display.GALLERY_IMAGE) {
        galleryIntent.setType("image/*");
    } else if (type == Display.GALLERY_ALL) {
        galleryIntent.setType("image/* video/*");
    } else if (type == -9999) {
        galleryIntent = new Intent();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        } else {
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        }
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
        // set MIME type for image
        galleryIntent.setType("*/*");
        galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(","));
    } else {
        galleryIntent.setType("*/*");
    }
    this.getActivity().startActivityForResult(galleryIntent, multi ? OPEN_GALLERY_MULTI : OPEN_GALLERY);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Aggregations

Component (com.codename1.ui.Component)19 Font (com.codename1.ui.Font)18 Container (com.codename1.ui.Container)15 Form (com.codename1.ui.Form)14 Style (com.codename1.ui.plaf.Style)12 Button (com.codename1.ui.Button)11 Image (com.codename1.ui.Image)11 TextArea (com.codename1.ui.TextArea)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 IOException (java.io.IOException)10 Hashtable (java.util.Hashtable)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)9 Label (com.codename1.ui.Label)8 FileInputStream (java.io.FileInputStream)8 ActionListener (com.codename1.ui.events.ActionListener)7 TextField (com.codename1.ui.TextField)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 EncodedImage (com.codename1.ui.EncodedImage)5