public class FlipTransition

  1. Object
  2. Transition
  3. FlipTransition

ImplementsAnimation

A Transitions that flips between 2 components/forms using perspective transform where available.

Notice that this looks rather different on devices as perspective transform is available there but isn’t on the simulator.

Toolbar.setGlobalToolbar(true);
Form hi = new Form("Transitions", new BoxLayout(BoxLayout.Y_AXIS));
Style bg = hi.getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0xff0000);
Button showTransition = new Button("Show");
Picker pick = new Picker();
pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip");
pick.setSelectedString("Slide");
TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC);
CheckBox horizontal = CheckBox.createToggle("Horizontal");
pick.addActionListener((e) -> {
    String s = pick.getSelectedString().toLowerCase();
    horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1);
});
horizontal.setSelected(true);
hi.add(showTransition).
    add(pick).
    add(duration).
    add(horizontal);

Form dest = new Form("Destination");
bg = dest.getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0xff);
dest.setBackCommand(
        dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack()));

showTransition.addActionListener((e) -> {
    int h = CommonTransitions.SLIDE_HORIZONTAL;
    if(!horizontal.isSelected()) {
        h = CommonTransitions.SLIDE_VERTICAL;
    }
    switch(pick.getSelectedString()) {
        case "Slide":
            hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
            break;
        case "SlideFade":
            hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
            break;
        case "Cover":
            hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
            break;
        case "Uncover":
            hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
            break;
        case "Fade":
            hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
            break;
        case "Flip":
            hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
            dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
            break;
    }
    dest.show();
});
hi.show();

Constructors

public FlipTransition()Creates a Flip Transition
public FlipTransition(int bgColor)Creates a Flip Transition
public FlipTransition(int bgColor, int duration)Creates a Flip Transition

Methods

public void initTransition()Callback thats invoked before a transition begins, the source form may be null for the first form in the application.
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public void paint(Graphics g)Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.
public void cleanup()Optional operation to cleanup the garbage left over by a running transition
public int getDuration()The duration for the flip transition
public void setDuration(int duration)The duration for the flip transition
public int getBgColor()The background color that is painted behind the flipping effect or -1 to use the paintBackgrounds method instead
public void setBgColor(int bgColor)The background color that is painted behind the flipping effect or -1 to use the paintBackgrounds method instead
public Transition copy(boolean reverse)Create a copy of the transition, usually the transition used is a copy.

Inherited methods

Constructor details

FlipTransition

public FlipTransition()
Creates a Flip Transition

FlipTransition

public FlipTransition(int bgColor)
Creates a Flip Transition

Parameters

bgColor int
the color to paint in the background when the transition paints, use -1 to not paint a background color

FlipTransition

public FlipTransition(int bgColor, int duration)
Creates a Flip Transition

Parameters

bgColor int
the color to paint in the background when the transition paints, use -1 to not paint a background color
duration int
the duration of the transition

Method details

initTransition

public void initTransition()
Callback thats invoked before a transition begins, the source form may be null for the first form in the application.

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

paint

public void paint(Graphics g)
Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.

Parameters

g Graphics
graphics context

cleanup

public void cleanup()
Optional operation to cleanup the garbage left over by a running transition

getDuration

public int getDuration()
The duration for the flip transition

Returns

the duration

setDuration

public void setDuration(int duration)
The duration for the flip transition

Parameters

duration int
the duration to set

getBgColor

public int getBgColor()
The background color that is painted behind the flipping effect or -1 to use the paintBackgrounds method instead

Returns

the bgColor

setBgColor

public void setBgColor(int bgColor)
The background color that is painted behind the flipping effect or -1 to use the paintBackgrounds method instead

Parameters

bgColor int
the bgColor to set

copy

public Transition copy(boolean reverse)
Create a copy of the transition, usually the transition used is a copy.

Parameters

reverse boolean
creates a new transition instance with “reverse” behavior useful for signifying “back” operations

Returns

new transition instance