public final class CommonTransitions

  1. Object
  2. Transition
  3. CommonTransitions

ImplementsAnimation

Contains common transition animations that can be applied to forms & components including the following types:

  • Slide - the exiting form slides out of the screen while the new form slides in (can be vertical or horizontal).

  • Slide Fade - slides the content pane while fading the title. This is the default iOS transition.

  • Cover/Uncover - like slide only one of the forms remains in place while the other moves.

  • Fade - components fade into/out of the screen

  • Timeline - uses an animation image as an alpha mask between the source/destination

The code below demonstrates the common transitions

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();

Slide

Slide Fade

Cover/Uncover

Fade

Fields

public static final int SLIDE_HORIZONTAL = 0Slide the transition horizontally
public static final int SLIDE_VERTICAL = 1Slide the transition vertically

Methods

public static CommonTransitions createEmpty()Creates an empty transition that does nothing.
public static CommonTransitions createSlideFadeTitle(boolean forward, int duration)Creates a slide transition for the body of the form that fades the title in while sliding
public static CommonTransitions createDialogPulsate()Creates a dialog pulsate transition
public static CommonTransitions createFastSlide(int type, boolean forward, int duration)Deprecated Creates a slide transition with the given duration and direction, this differs from the standard slide animation by focusing on speed rather than on minimizing heap usage.
public static CommonTransitions createSlide(int type, boolean forward, int duration)Creates a slide transition with the given duration and direction
public static CommonTransitions createSlide(int type, boolean forward, int duration, boolean drawDialogMenu)Creates a slide transition with the given duration and direction
public static CommonTransitions createCover(int type, boolean forward, int duration)Creates a cover transition with the given duration and direction
public static CommonTransitions createUncover(int type, boolean forward, int duration)Creates a uncover transition with the given duration and direction
public static CommonTransitions createFastSlide(int type, boolean forward, int duration, boolean drawDialogMenu)Deprecated Creates a slide transition with the given duration and direction, this differs from the standard slide animation by focusing on speed rather than on minimizing heap usage This method works by creating two images and sliding them which works much faster for all devices however takes up more ram.
public static CommonTransitions createFade(int duration)Creates a transition for fading a form in while fading out the original form
public static CommonTransitions createTimeline(Image animation)Creates a transition using an animated image object (e.g. timeline object) as an alpha mask between the source/target
public static boolean isDefaultLinearMotion()Indicates whether the motion associated with these transitions by default is linear or spline motion
public static void setDefaultLinearMotion(boolean aDefaultLinearMotion)Indicates whether the motion associated with these transitions by default is linear or spline motion
public boolean isHorizontalSlide()Returns true if this is a horizontal slide transition
public boolean isVerticalSlide()Returns true if this is a vertical slide transition
public boolean isHorizontalCover()Returns true if this is a horizontal cover transition
public boolean isVerticalCover()Returns true if this is a vertical cover transition
public boolean isForwardSlide()Indicates the slide/cover transition direction
public int getTransitionSpeed()Returns the speed of the transition in milliseconds
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 Motion getMotion()Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel
public void setMotion(Motion motion)Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel
public void setMotion(LazyValue<Motion> motion)Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel
public Transition copy(boolean reverse)Create a copy of the transition, usually the transition used is a copy.
public boolean isLinearMotion()Indicates whether the motion associated with this transition is linear or spline motion
public void setLinearMotion(boolean linearMotion)Indicates whether the motion associated with this transition is linear or spline motion

Inherited methods

Field details

SLIDE_HORIZONTAL

public static final int SLIDE_HORIZONTAL = 0
Slide the transition horizontally

See also

SLIDE_VERTICAL

public static final int SLIDE_VERTICAL = 1
Slide the transition vertically

See also

Method details

createEmpty

public static CommonTransitions createEmpty()
Creates an empty transition that does nothing. This has the same effect as setting a transition to null.

Returns

empty transition

createSlideFadeTitle

public static CommonTransitions createSlideFadeTitle(boolean forward, int duration)
Creates a slide transition for the body of the form that fades the title in while sliding

Parameters

forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond

createDialogPulsate

public static CommonTransitions createDialogPulsate()
Creates a dialog pulsate transition

createFastSlide

public static CommonTransitions createFastSlide(int type, boolean forward, int duration)
Deprecated. this is not faster than slide on modern devices, you should use that boolean, int)
Creates a slide transition with the given duration and direction, this differs from the standard slide animation by focusing on speed rather than on minimizing heap usage. This method works by creating two images and sliding them which works much faster for all devices however takes up more ram. Notice that this method of painting doesn’t support various basic CodenameOne abilities such as translucent menus/dialogs etc.

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond

Returns

a transition object

createSlide

public static CommonTransitions createSlide(int type, boolean forward, int duration)
Creates a slide transition with the given duration and direction

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond

Returns

a transition object

createSlide

public static CommonTransitions createSlide(int type, boolean forward, int duration, boolean drawDialogMenu)
Creates a slide transition with the given duration and direction

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond
drawDialogMenu boolean
indicates that the menu (softkey area) of the dialog should be kept during a slide transition. This is only relevant for dialog in/out transitions.

Returns

a transition object

createCover

public static CommonTransitions createCover(int type, boolean forward, int duration)
Creates a cover transition with the given duration and direction

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond

Returns

a transition object

createUncover

public static CommonTransitions createUncover(int type, boolean forward, int duration)
Creates a uncover transition with the given duration and direction

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond

Returns

a transition object

createFastSlide

public static CommonTransitions createFastSlide(int type, boolean forward, int duration, boolean drawDialogMenu)
Deprecated. this is not faster than slide on modern devices, you should use that boolean, int, boolean)
Creates a slide transition with the given duration and direction, this differs from the standard slide animation by focusing on speed rather than on minimizing heap usage This method works by creating two images and sliding them which works much faster for all devices however takes up more ram. Notice that this method of painting doesn’t support various basic CodenameOne abilities such as translucent menus/dialogs etc.

Parameters

type int
type can be either vertically or horizontally, which means the movement direction of the transition
forward boolean
forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.
duration int
represent the time the transition should take in millisecond
drawDialogMenu boolean
indicates that the menu (softkey area) of the dialog should be kept during a slide transition. This is only relevant for dialog in/out transitions.

Returns

a transition object

createFade

public static CommonTransitions createFade(int duration)
Creates a transition for fading a form in while fading out the original form

Parameters

duration int
represent the time the transition should take in millisecond

Returns

a transition object

createTimeline

public static CommonTransitions createTimeline(Image animation)
Creates a transition using an animated image object (e.g. timeline object) as an alpha mask between the source/target

Parameters

animation Image
the image object to execute

Returns

a transition object

isDefaultLinearMotion

public static boolean isDefaultLinearMotion()
Indicates whether the motion associated with these transitions by default is linear or spline motion

Returns

the defaultLinearMotion

setDefaultLinearMotion

public static void setDefaultLinearMotion(boolean aDefaultLinearMotion)
Indicates whether the motion associated with these transitions by default is linear or spline motion

Parameters

aDefaultLinearMotion boolean
the defaultLinearMotion to set

isHorizontalSlide

public boolean isHorizontalSlide()
Returns true if this is a horizontal slide transition

Returns

true if this is a horizontal slide transition

isVerticalSlide

public boolean isVerticalSlide()
Returns true if this is a vertical slide transition

Returns

true if this is a vertical slide transition

isHorizontalCover

public boolean isHorizontalCover()
Returns true if this is a horizontal cover transition

Returns

true if this is a horizontal cover transition

isVerticalCover

public boolean isVerticalCover()
Returns true if this is a vertical cover transition

Returns

true if this is a vertical cover transition

isForwardSlide

public boolean isForwardSlide()
Indicates the slide/cover transition direction

Returns

true for forward

getTransitionSpeed

public int getTransitionSpeed()
Returns the speed of the transition in milliseconds

Returns

The speed of the transition in milliseconds

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

getMotion

public Motion getMotion()
Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel

Returns

the instanceo of the motion class used by this transition

setMotion

public void setMotion(Motion motion)
Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel

Parameters

motion Motion
new instance of the motion class that will be used by the transition

setMotion

public void setMotion(LazyValue<Motion> motion)
Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel

Parameters

motion LazyValue<Motion>
new instance of the motion class that will be used by the transition

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

isLinearMotion

public boolean isLinearMotion()
Indicates whether the motion associated with this transition is linear or spline motion

Returns

the linearMotion

setLinearMotion

public void setLinearMotion(boolean linearMotion)
Indicates whether the motion associated with this transition is linear or spline motion

Parameters

linearMotion boolean
the linearMotion to set