use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class CodenameOneImplementation method repaint.
/**
* Invoked to add an element to the paintQueue
*
* @param cmp component or animation to push into the paint queue
*/
public void repaint(Animation cmp) {
synchronized (displayLock) {
for (int iter = 0; iter < paintQueueFill; iter++) {
Animation ani = paintQueue[iter];
if (ani == cmp) {
return;
}
// no need to paint a Component if one of its parent is already in the queue
if (ani instanceof Container && cmp instanceof Component) {
Component parent = ((Component) cmp).getParent();
while (parent != null) {
if (parent == ani) {
return;
}
parent = parent.getParent();
}
}
}
// overcrowding the queue don't try to grow the array!
if (paintQueueFill >= paintQueue.length) {
System.out.println("Warning paint queue size exceeded, please watch the amount of repaint calls");
return;
}
paintQueue[paintQueueFill] = cmp;
paintQueueFill++;
displayLock.notify();
}
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class InfiniteProgress method calcPreferredSize.
/**
* {@inheritDoc}
*/
protected Dimension calcPreferredSize() {
if (animation == null) {
animation = UIManager.getInstance().getThemeImageConstant("infiniteImage");
if (animation == null) {
int size = Display.getInstance().convertToPixels(7, true);
String f = getUIManager().getThemeConstant("infiniteDefaultColor", null);
int color = 0x777777;
if (f != null) {
color = Integer.parseInt(f, 16);
}
FontImage fi = FontImage.createFixed("" + FontImage.MATERIAL_AUTORENEW, FontImage.getMaterialDesignFont(), color, size, size, 0);
animation = fi.toImage();
}
}
if (animation == null) {
return new Dimension(100, 100);
}
Style s = getStyle();
return new Dimension(s.getHorizontalPadding() + animation.getWidth(), s.getVerticalPadding() + animation.getHeight());
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawPullToRefresh.
/**
* {@inheritDoc}
*/
public void drawPullToRefresh(Graphics g, final Component cmp, boolean taskExecuted) {
final Form parentForm = cmp.getComponentForm();
final int scrollY = cmp.getScrollY();
Component cmpToDraw;
if (taskExecuted) {
cmpToDraw = updating;
} else {
if (-scrollY > getPullToRefreshHeight()) {
cmpToDraw = releaseToRefresh;
} else {
cmpToDraw = pullDown;
}
}
if (pull.getComponentAt(0) != updating && cmpToDraw != pull.getComponentAt(0)) {
parentForm.registerAnimated(new Animation() {
int counter = 0;
Image i;
{
i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
if (i == null) {
i = getDefaultRefreshIcon();
}
}
public boolean animate() {
counter++;
if (pull.getComponentAt(0) == releaseToRefresh) {
((Label) releaseToRefresh).setIcon(i.rotate(180 - (180 / 6) * counter));
} else {
((Label) pullDown).setIcon(i.rotate(180 * counter / 6));
}
if (counter == 6) {
((Label) releaseToRefresh).setIcon(i);
((Label) pullDown).setIcon(i.rotate(180));
parentForm.deregisterAnimated(this);
}
cmp.repaint(cmp.getAbsoluteX(), cmp.getAbsoluteY() - getPullToRefreshHeight(), cmp.getWidth(), getPullToRefreshHeight());
return false;
}
public void paint(Graphics g) {
}
});
}
if (pull.getComponentAt(0) != cmpToDraw && cmpToDraw instanceof Label && (pull.getComponentAt(0) instanceof Label)) {
((Label) cmpToDraw).setIcon(((Label) pull.getComponentAt(0)).getIcon());
}
Component current = pull.getComponentAt(0);
if (current != cmpToDraw) {
pull.replace(current, cmpToDraw, null);
}
pull.setWidth(cmp.getWidth());
pull.setX(cmp.getAbsoluteX());
pull.setY(cmp.getY() - scrollY - getPullToRefreshHeight());
pull.layoutContainer();
pull.paintComponent(g);
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class SwipeBackSupport method bind.
/**
* Binds support for swiping to the given forms
*
* @param currentForm the current form
* @param destination the destination form which can be created lazily
*/
protected void bind(final Form currentForm, final LazyValue<Form> destination) {
pointerDragged = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sideSwipePotential) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) > x - initialDragX) {
sideSwipePotential = false;
return;
}
evt.consume();
if (dragActivated) {
currentX = x;
Display.getInstance().getCurrent().repaint();
} else {
if (x - initialDragX > Display.getInstance().convertToPixels(currentForm.getUIManager().getThemeConstant("backGestureThresholdInt", 5), true)) {
dragActivated = true;
destinationForm = destination.get();
startBackTransition(currentForm, destinationForm);
}
}
}
}
};
pointerReleased = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (dragActivated) {
int destNumberX = Display.getInstance().getDisplayWidth();
int incrementsX = Display.getInstance().convertToPixels(3, true);
if (currentX < destNumberX / 2) {
destinationForm = currentForm;
destNumberX = 0;
incrementsX *= -1;
}
final int destNumber = destNumberX;
final int increments = incrementsX;
Display.getInstance().getCurrent().registerAnimated(new Animation() {
public boolean animate() {
currentX += increments;
if (currentX > 0 && currentX >= destNumber || currentX < 0 && currentX <= destNumber) {
currentX = destNumber;
Transition t = destinationForm.getTransitionInAnimator();
destinationForm.setTransitionInAnimator(CommonTransitions.createEmpty());
destinationForm.show();
destinationForm.setTransitionInAnimator(t);
destinationForm = null;
dragActivated = false;
return false;
}
return true;
}
public void paint(Graphics g) {
}
});
}
}
};
pointerPressed = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sideSwipePotential = false;
int displayWidth = Display.getInstance().getDisplayWidth();
sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / currentForm.getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
initialDragX = evt.getX();
initialDragY = evt.getY();
/*if (sideSwipePotential) {
Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
if (c != null && c.shouldBlockSideSwipe()) {
sideSwipePotential = false;
}
}*/
}
};
currentForm.addPointerDraggedListener(pointerDragged);
currentForm.addPointerReleasedListener(pointerReleased);
currentForm.addPointerPressedListener(pointerPressed);
}
use of com.codename1.ui.animations.Animation 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;
}
Aggregations