Search in sources :

Example 16 with Layout

use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.

the class IOSImplementation method foldKeyboard.

public static void foldKeyboard() {
    if (instance.isAsyncEditMode()) {
        final Component cmp = Display.getInstance().getCurrent().getFocused();
        instance.callHideTextEditor();
        nativeInstance.foldVKB();
        // after folding the keyboard the screen layout might shift
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                if (cmp != null) {
                    Form f = Display.getInstance().getCurrent();
                    if (f == cmp.getComponentForm()) {
                        cmp.requestFocus();
                    }
                    if (nativeInstance.isAsyncEditMode() && f.isFormBottomPaddingEditingMode() && getRootPane(f).getUnselectedStyle().getPaddingBottom() > 0) {
                        getRootPane(f).getUnselectedStyle().setPadding(Component.BOTTOM, 0);
                        f.forceRevalidate();
                        return;
                    }
                    // revalidate even if we transition to a different form since the
                    // spacing might have remained during the transition
                    f.revalidate();
                }
            }
        });
    }
}
Also used : Form(com.codename1.ui.Form) BrowserComponent(com.codename1.ui.BrowserComponent) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 17 with Layout

use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.

the class Container method animateHierarchy.

/**
 * Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
 *
 * @param duration the duration in milliseconds for the animation
 */
private ComponentAnimation animateHierarchy(final int duration, boolean wait, int opacity, boolean add) {
    setShouldCalcPreferredSize(true);
    enableLayoutOnPaint = false;
    dontRecurseContainer = true;
    Vector comps = new Vector();
    findComponentsInHierachy(comps);
    final int componentCount = comps.size();
    int[] beforeX = new int[componentCount];
    int[] beforeY = new int[componentCount];
    int[] beforeW = new int[componentCount];
    int[] beforeH = new int[componentCount];
    final Motion[] xMotions = new Motion[componentCount];
    final Motion[] yMotions = new Motion[componentCount];
    final Motion[] wMotions = new Motion[componentCount];
    final Motion[] hMotions = new Motion[componentCount];
    for (int iter = 0; iter < componentCount; iter++) {
        Component current = (Component) comps.elementAt(iter);
        beforeX[iter] = current.getX();
        beforeY[iter] = current.getY();
        beforeW[iter] = current.getWidth();
        beforeH[iter] = current.getHeight();
    }
    layoutContainer();
    for (int iter = 0; iter < componentCount; iter++) {
        Component current = (Component) comps.elementAt(iter);
        xMotions[iter] = createAnimateMotion(beforeX[iter], current.getX(), duration);
        yMotions[iter] = createAnimateMotion(beforeY[iter], current.getY(), duration);
        wMotions[iter] = createAnimateMotion(beforeW[iter], current.getWidth(), duration);
        hMotions[iter] = createAnimateMotion(beforeH[iter], current.getHeight(), duration);
        xMotions[iter].start();
        yMotions[iter].start();
        wMotions[iter].start();
        hMotions[iter].start();
        current.setX(beforeX[iter]);
        current.setY(beforeY[iter]);
        current.setWidth(beforeW[iter]);
        current.setHeight(beforeH[iter]);
    }
    MorphAnimation a = new MorphAnimation(this, duration, new Motion[][] { xMotions, yMotions, wMotions, hMotions });
    setAnimOpacity(opacity, 255, a, componentCount, duration);
    a.animatedComponents = comps;
    if (add) {
        if (wait) {
            getAnimationManager().addAnimationAndBlock(a);
        } else {
            getAnimationManager().addAnimation(a);
        }
    }
    return a;
}
Also used : Motion(com.codename1.ui.animations.Motion) Vector(java.util.Vector)

Example 18 with Layout

use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.

the class Container method calculateFirstPaintableOffset.

/**
 * Efficiently finds the first child component that is visible in the specified
 * bounds.
 * <p>This is only really helpful if the child components are sorted
 * in some way so that we can quickly (with a binary search) find the first
 * visible component.  E.g. In BoxLayout.Y_AXIS, the components are arranged
 * vertically in order of their index so we can use a binary search to find
 * the first visible element.  For most other layout managers we can't as easily
 * do a sort like this.</p>
 *
 * <p>If the layout manager doesn't allow for a binary search, then this will
 * just return 0 (meaning that you need to scan the children from the beginning
 * to find visible children).</p>
 *
 * <p>After you obtain this value, use the {@link #calculateLastPaintableOffset(int, int, int, int, int) } method
 * to get the end of the visible region.</p>
 *
 * <p>The motivation for this is to try to improve performance in places where the container
 * has many (say 2500) children, and most of them aren't actually visible.</p>
 *
 * @param clipX1 Left bounds of region to check.  (0,0) is the top left corner of this component.
 * @param clipY1 Top bounds of region to check.  (0,0) is top left corner of this component.
 * @param clipX2 Right bounds of region to check.  (0,0) is top left corner of this component.
 * @param clipY2 Bottom bounds of region to check.  (0,0) is top left corner of this component.
 * @return The index within the "components" array where the first child that intersects the provided
 * clip occurs, or -1 if there is no "fast" way to find it.  If there was a fast way to do it, but no visible
 * components were found, then this will return components.size().
 *
 * @see #calculateLastPaintableOffset(int, int, int, int, int)
 */
private int calculateFirstPaintableOffset(int clipX1, int clipY1, int clipX2, int clipY2) {
    int len = components.size();
    Layout l = getLayout();
    if (l.getClass() == BoxLayout.class) {
        if (((BoxLayout) l).getAxis() == BoxLayout.Y_AXIS) {
            // Use a binary search to find the first visible
            int startPos = binarySearchFirstIntersectionY(clipY1, clipY2, 0, len);
            if (startPos >= 0) {
                return startPos;
            } else {
                return len;
            }
        }
    }
    return -1;
}
Also used : Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 19 with Layout

use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.

the class Dialog method initImpl.

private void initImpl(String dialogUIID, String dialogTitleUIID, Layout lm) {
    super.getContentPane().setUIID(dialogUIID);
    super.getTitleComponent().setText("");
    super.getTitleComponent().setVisible(false);
    super.getTitleArea().setVisible(false);
    super.getTitleArea().setUIID("Container");
    lockStyleImages(getUnselectedStyle());
    titleArea.setVisible(false);
    if (lm != null) {
        dialogContentPane = new Container(lm);
    } else {
        dialogContentPane = new Container();
    }
    dialogContentPane.setUIID("DialogContentPane");
    dialogTitle = new Label("", dialogTitleUIID);
    super.getContentPane().setLayout(new BorderLayout());
    super.getContentPane().addComponent(BorderLayout.NORTH, dialogTitle);
    super.getContentPane().addComponent(BorderLayout.CENTER, dialogContentPane);
    super.getContentPane().setScrollable(false);
    super.getContentPane().setAlwaysTensile(false);
    super.getStyle().setBgTransparency(0);
    super.getStyle().setBgImage(null);
    super.getStyle().setBorder(null);
    setSmoothScrolling(false);
    deregisterAnimated(this);
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 20 with Layout

use of com.codename1.ui.layouts.Layout in project CodenameOne by codenameone.

the class ResetableTextWatcher method endEditing.

/**
 * Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call
 * to 'edit' to return.
 */
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
    // }
    if (!mIsEditing || mEditText == null) {
        return;
    }
    // SJH: Setting visibility GONE causes a size change event to be fired even when the
    // input mode is adjustPan.  This causes problems and glitches with the layout because we
    // have to guess if a resize even is accurate or not.
    // setVisibility(GONE);
    mLastEndEditReason = reason;
    // If the IME action is set to NEXT, do not hide the virtual keyboard
    boolean isNextActionFlagSet = ((mEditText.getImeOptions() & 0xf) == EditorInfo.IME_ACTION_NEXT);
    boolean leaveKeyboardShowing = impl.isAsyncEditMode() || (reason == REASON_IME_ACTION) && isNextActionFlagSet || forceVKBOpen;
    if (forceVKBClose) {
        leaveKeyboardShowing = false;
    }
    if (!leaveKeyboardShowing || actionCode == EditorInfo.IME_ACTION_DONE || actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        showVirtualKeyboard(false);
    }
    // Get rid of flags
    int imo = mEditText.getImeOptions() & 0xf;
    if (reason == REASON_IME_ACTION && mEditText.mTextArea instanceof TextField && ((TextField) mEditText.mTextArea).getDoneListener() != null && (actionCode == EditorInfo.IME_ACTION_DONE) || actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        ((TextField) mEditText.mTextArea).fireDoneEvent();
    }
    // Call this in onComplete instead
    // mIsEditing = false;
    mLastEditText = mEditText;
    removeView(mEditText);
    Component editingComponent = mEditText.mTextArea;
    mEditText.removeTextChangedListener(mEditText.mTextWatcher);
    mEditText = null;
    if (impl.isAsyncEditMode()) {
        Runnable onComplete = (Runnable) editingComponent.getClientProperty("android.onAsyncEditingComplete");
        editingComponent.putClientProperty("android.onAsyncEditingComplete", null);
        if (onComplete != null) {
            Display.getInstance().callSerially(onComplete);
        }
    }
    waitingForSynchronousEditingCompletion = false;
}
Also used : TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component) Paint(android.graphics.Paint)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)9 Layout (com.codename1.ui.layouts.Layout)8 BoxLayout (com.codename1.ui.layouts.BoxLayout)7 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)7 Component (com.codename1.ui.Component)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)5 Container (com.codename1.ui.Container)4 TableLayout (com.codename1.ui.table.TableLayout)4 Form (com.codename1.ui.Form)3 TextArea (com.codename1.ui.TextArea)3 Dimension (com.codename1.ui.geom.Dimension)3 ArrayList (java.util.ArrayList)3 Button (com.codename1.ui.Button)2 CheckBox (com.codename1.ui.CheckBox)2 Dialog (com.codename1.ui.Dialog)2 Label (com.codename1.ui.Label)2 List (com.codename1.ui.List)2 RadioButton (com.codename1.ui.RadioButton)2 Slider (com.codename1.ui.Slider)2 Tabs (com.codename1.ui.Tabs)2