use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class LookAndFeel method getTransitionConstant.
private Transition getTransitionConstant(Transition t, String constant, String slideDir, int speed, boolean forward) {
Image img = manager.getThemeImageConstant(constant + "Image");
if (img != null) {
return CommonTransitions.createTimeline(img);
}
String val = manager.getThemeConstant(constant, null);
if (val == null) {
return t;
}
if (val.equalsIgnoreCase("empty")) {
return CommonTransitions.createEmpty();
}
if (val.equalsIgnoreCase("slide")) {
if (slideDir.equalsIgnoreCase("horizontal")) {
return CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
} else {
return CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, forward, speed);
}
}
if (val.equalsIgnoreCase("cover")) {
if (slideDir.equalsIgnoreCase("horizontal")) {
return CommonTransitions.createCover(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
} else {
return CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, forward, speed);
}
}
if (val.equalsIgnoreCase("uncover")) {
if (slideDir.equalsIgnoreCase("horizontal")) {
return CommonTransitions.createUncover(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
} else {
return CommonTransitions.createUncover(CommonTransitions.SLIDE_VERTICAL, forward, speed);
}
}
if (val.equalsIgnoreCase("fslide")) {
if (slideDir.equalsIgnoreCase("horizontal")) {
return CommonTransitions.createFastSlide(CommonTransitions.SLIDE_HORIZONTAL, forward, speed);
} else {
return CommonTransitions.createFastSlide(CommonTransitions.SLIDE_VERTICAL, forward, speed);
}
}
if (val.equalsIgnoreCase("fade")) {
return CommonTransitions.createFade(speed);
}
if (val.equalsIgnoreCase("slidefade")) {
return CommonTransitions.createSlideFadeTitle(forward, speed);
}
if (val.equalsIgnoreCase("pulse")) {
return CommonTransitions.createDialogPulsate();
}
if (val.equalsIgnoreCase("bubble")) {
BubbleTransition transition = new BubbleTransition(speed);
transition.setRoundBubble(false);
return transition;
}
return t;
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class LazyValueC method showContainerImpl.
private Container showContainerImpl(String resourceName, Command sourceCommand, Component sourceComponent, boolean forceBack) {
if (sourceComponent != null) {
Form currentForm = sourceComponent.getComponentForm();
// avoid the overhead of searching if no embedding is used
if (currentForm.getClientProperty(EMBEDDED_FORM_FLAG) != null) {
Container destContainer = sourceComponent.getParent();
while (!(destContainer instanceof EmbeddedContainer || destContainer instanceof Form)) {
// race condition, container was already removed by someone else
if (destContainer == null) {
return null;
}
destContainer = destContainer.getParent();
}
if (destContainer instanceof EmbeddedContainer) {
Container cnt = createContainer(fetchResourceFile(), resourceName, (EmbeddedContainer) destContainer);
if (cnt instanceof Form) {
// Form f = (Form)cnt;
// cnt = formToContainer(f);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
Component fromCmp = destContainer.getComponentAt(0);
// This seems to be no longer necessary now that we have the replaceAndWait version that drops events
// block the user from the ability to press the button twice by mistake
// fromCmp.setEnabled(false);
boolean isBack = forceBack;
Transition t = fromCmp.getUIManager().getLookAndFeel().getDefaultFormTransitionOut();
if (forceBack) {
initBackContainer(cnt, destContainer.getComponentForm(), getFormNavigationStackForComponent(sourceComponent));
t = t.copy(true);
} else {
if (sourceCommand != null) {
if (t != null && backCommands != null && backCommands.contains(sourceCommand) || Display.getInstance().getCurrent().getBackCommand() == sourceCommand) {
isBack = true;
t = t.copy(true);
}
}
}
// create a back command if supported
String commandAction = cnt.getName();
Vector formNavigationStack = getFormNavigationStackForComponent(fromCmp);
if (formNavigationStack != null && !isBack && allowBackTo(commandAction) && !isSameBackDestination((Container) fromCmp, cnt)) {
// trigger listener creation if this is the only command in the form
getFormListenerInstance(destContainer.getComponentForm(), null);
formNavigationStack.addElement(getContainerState((com.codename1.ui.Container) fromCmp));
}
beforeShowContainer(cnt);
destContainer.replaceAndWait(fromCmp, cnt, t, true);
postShowContainer(cnt);
return cnt;
} else {
Container cnt = createContainer(fetchResourceFile(), resourceName);
showForm((Form) cnt, sourceCommand, sourceComponent);
return cnt;
}
}
}
Container cnt = createContainer(fetchResourceFile(), resourceName);
if (cnt instanceof Form) {
showForm((Form) cnt, sourceCommand, sourceComponent);
} else {
Form f = new Form();
f.setLayout(new BorderLayout());
f.addComponent(BorderLayout.CENTER, cnt);
f.setName("Form" + cnt.getName());
showForm(f, sourceCommand, sourceComponent);
}
return cnt;
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class Tree method collapseNode.
private void collapseNode(Component c, Transition t) {
Container lead = c.getParent().getLeadParent();
if (lead != null) {
c = lead;
}
c.putClientProperty(KEY_EXPANDED, null);
setNodeIcon(folder, c);
Container p = c.getParent();
for (int iter = 0; iter < p.getComponentCount(); iter++) {
if (p.getComponentAt(iter) != c) {
if (t == null) {
p.removeComponent(p.getComponentAt(iter));
// there should only be one container with all children
break;
} else {
Label dummy = new Label();
p.replaceAndWait(p.getComponentAt(iter), dummy, t, true);
p.removeComponent(dummy);
}
}
}
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class SwipeBackSupport method startBackTransition.
void startBackTransition(final Form currentForm, Form destination) {
final Transition t = destination.getTransitionOutAnimator().copy(true);
if (t instanceof CommonTransitions) {
Transition originalTransition = currentForm.getTransitionOutAnimator();
currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
Form blank = new Form() {
protected boolean shouldSendPointerReleaseToOtherForm() {
return true;
}
};
blank.addPointerDraggedListener(pointerDragged);
blank.addPointerReleasedListener(pointerReleased);
blank.addPointerPressedListener(pointerPressed);
blank.setTransitionInAnimator(CommonTransitions.createEmpty());
blank.setTransitionOutAnimator(CommonTransitions.createEmpty());
blank.show();
currentForm.setTransitionOutAnimator(originalTransition);
((CommonTransitions) t).setMotion(new LazyValue<Motion>() {
public Motion get(Object... args) {
return new ManualMotion(((Integer) args[0]).intValue(), ((Integer) args[1]).intValue(), ((Integer) args[2]).intValue());
}
});
t.init(currentForm, destination);
t.initTransition();
blank.setGlassPane(new Painter() {
public void paint(Graphics g, Rectangle rect) {
t.animate();
t.paint(g);
}
});
}
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class PickMIDlet method startMIDlet.
public static void startMIDlet(Hashtable themeHash) {
Accessor.setTheme(themeHash);
Preferences pref = Preferences.userNodeForPackage(ResourceEditorView.class);
String jar = pref.get("jar", null);
String midlet = pref.get("midlet", null);
if (jar != null && midlet != null) {
File jarFile = new File(jar);
if (jarFile.exists()) {
try {
URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jarFile.toURI().toURL() }, PickMIDlet.class.getClassLoader());
StringTokenizer tokenizer = new StringTokenizer((String) midlet, " ,");
String s = tokenizer.nextToken();
while (tokenizer.hasMoreTokens()) {
s = tokenizer.nextToken();
}
Class cls = cl.loadClass(s);
JavaSEPortWithSVGSupport.setClassLoader(cls);
EditableResources.setResourcesClassLoader(cls);
Accessor.setTheme(themeHash);
Object app = cls.newInstance();
JarFile zip = new JarFile(jarFile);
Attributes m = zip.getManifest().getMainAttributes();
cls.getDeclaredMethod("init", new Class[] { Object.class }).invoke(app, new Object[] { null });
cls.getDeclaredMethod("start", new Class[0]).invoke(app, new Object[0]);
// there might be an ongoing transition and the form.show() method is serial
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (Display.getInstance().getCurrent() != null) {
Display.getInstance().getCurrent().refreshTheme();
return;
} else {
new Thread() {
public void run() {
try {
sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Display.getInstance().callSerially(this);
}
}.start();
}
}
});
return;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
JavaSEPortWithSVGSupport.setClassLoader(PickMIDlet.class);
LiveDemo l = new LiveDemo();
l.init(null);
l.start();
Accessor.setTheme(themeHash);
Form current = Display.getInstance().getCurrent();
if (current != null) {
current.refreshTheme();
}
}
Aggregations