use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class Display method paintTransitionAnimation.
private void paintTransitionAnimation() {
Animation ani = (Animation) animationQueue.get(0);
if (!ani.animate()) {
animationQueue.remove(0);
if (ani instanceof Transition) {
Form source = (Form) ((Transition) ani).getSource();
restoreMenu(source);
if (animationQueue.size() > 0) {
ani = (Animation) animationQueue.get(0);
if (ani instanceof Transition) {
((Transition) ani).initTransition();
}
} else {
Form f = (Form) ((Transition) ani).getDestination();
restoreMenu(f);
if (source == null || source == impl.getCurrentForm() || source == getCurrent()) {
setCurrentForm(f);
}
((Transition) ani).cleanup();
}
return;
}
}
ani.paint(codenameOneGraphics);
impl.flushGraphics();
if (transitionDelay > 0) {
// flush and so require the painting thread to get CPU too.
try {
synchronized (lock) {
lock.wait(transitionDelay);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class MenuBar method initMenuBar.
/**
* Initialize the MenuBar
*
* @param parent the associated Form
*/
protected void initMenuBar(Form parent) {
this.parent = parent;
selectMenuItem = createMenuSelectCommand();
cancelMenuItem = createMenuCancelCommand();
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
// don't minimize the app if it's a Dialog
minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
menuStyle = manager.getComponentStyle("Menu");
setUIID("SoftButton");
menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
// use the slide transition by default
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
}
menuCellRenderer = lf.getMenuRenderer();
int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
thirdSoftButton = Display.getInstance().isThirdSoftButton();
int commandBehavior = getCommandBehavior();
if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(main);
addComponent(left);
} else {
addComponent(left);
addComponent(main);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
setLayout(new GridLayout(1, 2));
soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[0];
right = soft[1];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(left);
} else {
addComponent(left);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[0];
soft[0] = soft[1];
soft[1] = b;
}
}
// It doesn't make sense for softbuttons to have ... at the end
for (int iter = 0; iter < soft.length; iter++) {
soft[iter].setEndsWith3Points(false);
}
} else {
// special case for touch screens we still want the 3 softbutton areas...
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
addComponent(left);
addComponent(main);
addComponent(right);
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
soft = new Button[] { createSoftButton("SoftButtonCenter") };
}
}
softCommand = new Command[soft.length];
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class Toolbar method showOverflowMenu.
/*
* A Overflow Menu is implemented as a dialog, this method allows you to
* override the dialog display in order to customize the dialog menu in
* various ways
*
* @param menu a dialog containing Overflow Menu options that can be
* customized
* @return the command selected by the user in the dialog
*/
protected Command showOverflowMenu(Dialog menu) {
Form parent = sideMenu.getParentForm();
int height;
int marginLeft;
int marginRight = 0;
Container dialogContentPane = menu.getDialogComponent();
marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
marginLeft = Math.max(0, marginLeft);
if (parent.getSoftButtonCount() > 1) {
height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
} else {
height = parent.getHeight() - dialogContentPane.getPreferredH();
}
height = Math.max(0, height);
int th = getHeight();
Transition transitionIn;
Transition transitionOut;
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
if (transitionIn instanceof BubbleTransition) {
((BubbleTransition) transitionIn).setComponentName("OverflowButton");
}
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createEmpty();
transitionOut = CommonTransitions.createEmpty();
}
menu.setTransitionInAnimator(transitionIn);
menu.setTransitionOutAnimator(transitionOut);
if (isRTL()) {
marginRight = marginLeft;
marginLeft = 0;
}
int tint = parent.getTintColor();
parent.setTintColor(0x00FFFFFF);
parent.tint = false;
boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
int topPadding = 0;
Component statusBar = ((BorderLayout) getLayout()).getNorth();
if (statusBar != null) {
topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
}
if (showBelowTitle) {
topPadding = th;
}
Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
parent.setTintColor(tint);
return r;
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class CommonTransitions method paintCoverAtPosition.
private void paintCoverAtPosition(Graphics g, int slideX, int slideY) {
Component source = getSource();
// if this is the first form we can't do a slide transition since we have no source form
if (source == null) {
return;
}
Component dest = getDestination();
int w = source.getWidth();
int h = source.getHeight();
if (slideType == SLIDE_HORIZONTAL) {
h = 0;
} else {
w = 0;
}
boolean dir = forward;
if (dest != null && dest.getUIManager().getLookAndFeel().isRTL()) {
dir = !dir;
}
if (dir) {
w = -w;
h = -h;
} else {
slideX = -slideX;
slideY = -slideY;
}
g.setClip(source.getAbsoluteX() + source.getScrollX(), source.getAbsoluteY() + source.getScrollY(), source.getWidth(), source.getHeight());
// dialog animation is slightly different...
if (source instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, dest, 0, 0);
}
paint(g, source, -slideX, -slideY);
return;
}
if (dest instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, source, 0, 0);
}
paint(g, dest, -slideX - w, -slideY - h);
return;
}
if (transitionType == TYPE_UNCOVER) {
paint(g, dest, 0, 0);
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, slideX + w, slideY + h);
} else {
g.drawImage(buffer, slideX + w, slideY + h);
}
} else {
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, 0, 0);
} else {
g.drawImage(buffer, 0, 0);
}
paint(g, dest, slideX + w, slideY + h);
}
}
use of com.codename1.ui.animations.Transition in project CodenameOne by codenameone.
the class XYMultiSeriesTransition method getBuffer.
/**
* Gets the buffer/cache for values. Values set in the buffer will be applied
* to the target dataset when the transition takes place.
* @return
*/
public XYMultipleSeriesDataset getBuffer() {
if (datasetCache == null) {
datasetCache = new XYMultipleSeriesDataset();
for (int i = 0; i < dataset.getSeriesCount(); i++) {
datasetCache.addSeries(new XYSeries(dataset.getSeriesAt(i).getTitle()));
}
seriesTransitions = new XYSeriesTransition[dataset.getSeries().length];
int tlen = seriesTransitions.length;
for (int i = 0; i < tlen; i++) {
seriesTransitions[i] = new XYSeriesTransition(getChart(), dataset.getSeriesAt(i));
seriesTransitions[i].setBuffer(datasetCache.getSeriesAt(i));
}
}
return datasetCache;
}
Aggregations