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();
}
}
});
}
}
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;
}
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;
}
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);
}
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;
}
Aggregations