Search in sources :

Example 1 with CodenameOneImplementation

use of com.codename1.impl.CodenameOneImplementation in project CodenameOne by codenameone.

the class ConnectionRequest method initConnection.

/**
 * Invoked to initialize HTTP headers, cookies etc.
 *
 * @param connection the connection object
 */
protected void initConnection(Object connection) {
    timeSinceLastUpdate = System.currentTimeMillis();
    CodenameOneImplementation impl = Util.getImplementation();
    impl.setPostRequest(connection, isPost());
    if (getUserAgent() != null) {
        impl.setHeader(connection, "User-Agent", getUserAgent());
    }
    if (getContentType() != null) {
        // UWP will automatically filter out the Content-Type header from GET requests
        // Historically, CN1 has always included this header even though it has no meaning
        // for GET requests.  it would be be better if CN1 did not include this header
        // with GET requests, but for backward compatibility, I'll leave it on as
        // the default, and add a property to turn it off.
        // -- SJH Sept. 15, 2016
        boolean shouldAddContentType = contentTypeSetExplicitly || Display.getInstance().getProperty("ConnectionRequest.excludeContentTypeFromGetRequests", "true").equals("false");
        if (isPost() || (getHttpMethod() != null && !"get".equals(getHttpMethod().toLowerCase()))) {
            shouldAddContentType = true;
        }
        if (shouldAddContentType) {
            impl.setHeader(connection, "Content-Type", getContentType());
        }
    }
    if (chunkedStreamingLen > -1) {
        impl.setChunkedStreamingMode(connection, chunkedStreamingLen);
    }
    if (!post && (cacheMode == CachingMode.MANUAL || cacheMode == CachingMode.SMART)) {
        String msince = Preferences.get("cn1MSince" + createRequestURL(), null);
        if (msince != null) {
            impl.setHeader(connection, "If-Modified-Since", msince);
        } else {
            String etag = Preferences.get("cn1Etag" + createRequestURL(), null);
            if (etag != null) {
                impl.setHeader(connection, "If-None-Match", etag);
            }
        }
    }
    if (userHeaders != null) {
        Enumeration e = userHeaders.keys();
        while (e.hasMoreElements()) {
            String k = (String) e.nextElement();
            String value = (String) userHeaders.get(k);
            impl.setHeader(connection, k, value);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 2 with CodenameOneImplementation

use of com.codename1.impl.CodenameOneImplementation in project CodenameOne by codenameone.

the class Component method setScrollY.

/**
 * Indicates the X position of the scrolling, this number is relative to the
 * component position and so a position of 0 would indicate the x position
 * of the component.
 *
 * @param scrollY the Y position of the scrolling
 */
protected void setScrollY(int scrollY) {
    if (this.scrollY != scrollY) {
        CodenameOneImplementation ci = Display.impl;
        if (ci.isAsyncEditMode() && ci.isEditingText()) {
            Component editingText = ci.getEditingText();
            if (editingText != null && this instanceof Container && ((Container) this).contains(editingText)) {
                ci.hideTextEditor();
            }
        }
    }
    // the setter must always update the value regardless...
    int scrollYtmp = scrollY;
    if (!isSmoothScrolling() || !isTensileDragEnabled()) {
        Form parentForm = getComponentForm();
        int v = getInvisibleAreaUnderVKB();
        int h = getScrollDimension().getHeight() - getHeight() + v;
        scrollYtmp = Math.min(scrollYtmp, h);
        scrollYtmp = Math.max(scrollYtmp, 0);
    }
    if (isScrollableY()) {
        if (Form.activePeerCount > 0) {
            onParentPositionChange();
        }
        repaint();
    }
    if (scrollListeners != null) {
        scrollListeners.fireScrollEvent(this.scrollX, scrollYtmp, this.scrollX, this.scrollY);
    }
    this.scrollY = scrollYtmp;
    onScrollY(this.scrollY);
}
Also used : Point(com.codename1.ui.geom.Point) CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 3 with CodenameOneImplementation

use of com.codename1.impl.CodenameOneImplementation in project CodenameOne by codenameone.

the class Container method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    if (enableLayoutOnPaint) {
        layoutContainer();
    }
    g.translate(getX(), getY());
    int size = components.size();
    int startIter = 0;
    if (size >= 30) {
        int clipX1 = g.getClipX();
        int clipX2 = g.getClipX() + g.getClipWidth();
        int clipY1 = g.getClipY();
        int clipY2 = g.getClipY() + g.getClipHeight();
        startIter = calculateFirstPaintableOffset(clipX1, clipY1, clipX2, clipY2);
        if (startIter < 0) {
            // There was no efficient way to calculate the offset
            startIter = 0;
        } else if (startIter < size) {
            // There was an efficient way to calculate the offset so we
            // will continue this approach
            size = calculateLastPaintableOffset(startIter, clipX1, clipY1, clipX2, clipY2) + 1;
        }
    }
    CodenameOneImplementation impl = Display.impl;
    if (dontRecurseContainer) {
        for (int iter = startIter; iter < size; iter++) {
            Component cmp = components.get(iter);
            if (cmp.getClass() == Container.class) {
                paintContainerChildrenForAnimation((Container) cmp, g);
            } else {
                cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
            }
        }
    } else {
        for (int iter = startIter; iter < size; iter++) {
            Component cmp = components.get(iter);
            cmp.paintInternal(impl.getComponentScreenGraphics(this, g), false);
        }
    }
    int tx = g.getTranslateX();
    int ty = g.getTranslateY();
    g.translate(-tx, -ty);
    if (sidemenuBarTranslation > 0) {
        g.translate(sidemenuBarTranslation, 0);
        paintGlass(g);
        paintTensile(g);
        g.translate(-sidemenuBarTranslation, 0);
    } else {
        paintGlass(g);
        paintTensile(g);
    }
    g.translate(tx, ty);
    g.translate(-getX(), -getY());
}
Also used : CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 4 with CodenameOneImplementation

use of com.codename1.impl.CodenameOneImplementation in project CodenameOne by codenameone.

the class Display method init.

/**
 * This is the INTERNAL Display initialization method, it will be removed in future versions of the API.
 * This method must be called before any Form is shown
 *
 * @param m platform specific object used by the implementation
 * @deprecated this method is invoked internally do not invoke it!
 */
public static void init(Object m) {
    if (!INSTANCE.codenameOneRunning) {
        INSTANCE.codenameOneRunning = true;
        INSTANCE.displayInitTime = System.currentTimeMillis();
        // restore menu state from previous run if exists
        int commandBehaviour = COMMAND_BEHAVIOR_DEFAULT;
        if (INSTANCE.impl != null) {
            commandBehaviour = INSTANCE.impl.getCommandBehavior();
        }
        INSTANCE.impl = (CodenameOneImplementation) ImplementationFactory.getInstance().createImplementation();
        INSTANCE.impl.setDisplayLock(lock);
        INSTANCE.impl.initImpl(m);
        INSTANCE.codenameOneGraphics = new Graphics(INSTANCE.impl.getNativeGraphics());
        INSTANCE.codenameOneGraphics.paintPeersBehind = INSTANCE.impl.paintNativePeersBehind();
        INSTANCE.impl.setCodenameOneGraphics(INSTANCE.codenameOneGraphics);
        // only enable but never disable the third softbutton
        if (INSTANCE.impl.isThirdSoftButton()) {
            INSTANCE.thirdSoftButton = true;
        }
        if (INSTANCE.impl.getSoftkeyCount() > 0) {
            MenuBar.leftSK = INSTANCE.impl.getSoftkeyCode(0)[0];
            if (INSTANCE.impl.getSoftkeyCount() > 1) {
                MenuBar.rightSK = INSTANCE.impl.getSoftkeyCode(1)[0];
                if (INSTANCE.impl.getSoftkeyCode(1).length > 1) {
                    MenuBar.rightSK2 = INSTANCE.impl.getSoftkeyCode(1)[1];
                }
            }
        }
        MenuBar.backSK = INSTANCE.impl.getBackKeyCode();
        MenuBar.backspaceSK = INSTANCE.impl.getBackspaceKeyCode();
        MenuBar.clearSK = INSTANCE.impl.getClearKeyCode();
        INSTANCE.PATHLENGTH = INSTANCE.impl.getDragPathLength();
        INSTANCE.dragPathX = new float[INSTANCE.PATHLENGTH];
        INSTANCE.dragPathY = new float[INSTANCE.PATHLENGTH];
        INSTANCE.dragPathTime = new long[INSTANCE.PATHLENGTH];
        com.codename1.util.StringUtil.setImplementation(INSTANCE.impl);
        com.codename1.io.Util.setImplementation(INSTANCE.impl);
        // generally its probably a bug but we can let it slide...
        if (INSTANCE.edt == null) {
            INSTANCE.touchScreen = INSTANCE.impl.isTouchDevice();
            // initialize the Codename One EDT which from now on will take all responsibility
            // for the event delivery.
            INSTANCE.edt = new CodenameOneThread(new RunnableWrapper(null, 3), "EDT");
            INSTANCE.impl.setThreadPriority(INSTANCE.edt, INSTANCE.impl.getEDTThreadPriority());
            INSTANCE.edt.start();
        }
        INSTANCE.impl.postInit();
        INSTANCE.setCommandBehavior(commandBehaviour);
    } else {
        INSTANCE.impl.confirmControlView();
    }
}
Also used : CodenameOneThread(com.codename1.impl.CodenameOneThread)

Example 5 with CodenameOneImplementation

use of com.codename1.impl.CodenameOneImplementation in project CodenameOne by codenameone.

the class Image method rotate.

/**
 * Returns an instance of this image rotated by the given number of degrees. By default 90 degree
 * angle divisions are supported, anything else is implementation dependent. This method assumes
 * a square image. Notice that it is inefficient in the current implementation to rotate to
 * non-square angles,
 * <p>E.g. rotating an image to 45, 90 and 135 degrees is inefficient. Use rotatate to 45, 90
 * and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.
 *
 * @param degrees A degree in right angle must be larger than 0 and up to 359 degrees
 * @return new image instance with the closest possible rotation
 */
public Image rotate(int degrees) {
    CodenameOneImplementation i = Display.impl;
    if (i.isRotationDrawingSupported()) {
        if (degrees >= 90) {
            int newTransform = 0;
            if (transform != 0) {
                newTransform = (transform + degrees) % 360;
            } else {
                newTransform = degrees % 360;
            }
            degrees %= 90;
            newTransform -= degrees;
            if (degrees != 0) {
                Image newImage = new Image(Display.impl.rotate(image, degrees));
                newImage.transform = newTransform;
                return newImage;
            } else {
                Image newImage = new Image(image);
                newImage.transform = newTransform;
                return newImage;
            }
        }
        if (degrees != 0) {
            return new Image(Display.impl.rotate(image, degrees));
        }
        return this;
    } else {
        return new Image(Display.impl.rotate(image, degrees));
    }
}
Also used : CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Aggregations

CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)9 Point (com.codename1.ui.geom.Point)3 IOException (java.io.IOException)2 CodenameOneThread (com.codename1.impl.CodenameOneThread)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1