Skip to content

New animation framework #1615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CodenameOne/src/com/codename1/io/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,9 @@ public int getTimeout() {
}

/**
* Adds a generic listener to a network error that is invoked before the exception is propogated.
* Adds a generic listener to a network error that is invoked before the exception is propagated.
* Notice that this doesn't apply to server error codes!
* Consume the event in order to prevent it from propogating further.
* Consume the event in order to prevent it from propagating further.
*
* @param e callback will be invoked with the Exception as the source object
*/
Expand Down
110 changes: 110 additions & 0 deletions CodenameOne/src/com/codename1/ui/AnimationManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/

package com.codename1.ui;

import com.codename1.io.Util;
import com.codename1.ui.animations.ComponentAnimation;
import java.util.ArrayList;

/**
* Animation manager concentrates all of the animations for a given form into a single place that allows us
* to manage all mutations to a Form in a way the prevents collisions between mutations. The one type of
* animation that isn't handled by this class is the form level transition, replace transitions are handled by this class.
*
* @author Shai Almog
*/
public final class AnimationManager {
private final Form parentForm;
private ArrayList<ComponentAnimation> anims = new ArrayList<ComponentAnimation>();

AnimationManager(Form parentForm) {
this.parentForm = parentForm;
}

/**
* Returns true if an animation is currently in progress
* @return true if an animation is currently in progress
*/
public boolean isAnimating() {
return anims.size() > 0;
}

void updateAnimations() {
if(anims.size() > 0) {
ComponentAnimation c = anims.get(0);
if(c.isInProgress()) {
c.updateAnimationState();
} else {
c.updateAnimationState();
anims.remove(c);
}
}
}

void flush() {
while(anims.size() > 0) {
anims.get(0).flush();
anims.remove(0);
}
}

/**
* Adds the animation to the end to the animation queue
* @param an the animation object
*/
public void addAnimation(ComponentAnimation an) {
anims.add(an);
Display.getInstance().notifyDisplay();
}

/**
* Adds the animation to the end of the animation queue and blocks the current thread until the animation
* completes
* @param an the animation to perform
*/
public void addAnimationAndBlock(final ComponentAnimation an) {
final Object LOCK = new Object();
an.setNotifyLock(LOCK);
addAnimation(an);
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
while(an.isInProgress()) {
Util.wait(LOCK, 50);
}
}
});
}


/**
* Adds the animation to the end to the animation queue
* @param an the animation object
* @param callback invoked when the animation completes
*/
public void addAnimation(ComponentAnimation an, Runnable callback) {
an.setOnCompletion(callback);
addAnimation(an);
Display.getInstance().notifyDisplay();
}
}
12 changes: 12 additions & 0 deletions CodenameOne/src/com/codename1/ui/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,18 @@ private Motion getAnimationMotion() {
return animationMotion;
}

/**
* Returns the animation manager of the parent form or null if this component isn't currently associated with a form
* @return the animation manager instance
*/
public AnimationManager getAnimationManager() {
Form f = getComponentForm();
if(f == null) {
return null;
}
return f.getAnimationManager();
}

/**
* Scroll animation speed in milliseconds allowing a developer to slow down or accelerate
* the smooth animation mode
Expand Down
Loading