# Class CommonTransitions

java.lang.Object
com.codename1.ui.animations.Transition
com.codename1.ui.animations.CommonTransitions

All Implemented Interfaces:
  `Animation`

public final class CommonTransitions extends Transition

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

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `SLIDE_HORIZONTAL`
  Slide the transition horizontally
  `static final int`
  `SLIDE_VERTICAL`
  Slide the transition vertically

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `animate()`
  Allows the animation to reduce "repaint" calls when it returns false.
  `void`
  `cleanup()`
  Optional operation to cleanup the garbage left over by a running transition
  `Transition`
  `copy(boolean reverse)`
  Create a copy of the transition, usually the transition used is a copy.
  `static CommonTransitions`
  `createCover(int type, boolean forward, int duration)`
  Creates a cover transition with the given duration and direction
  `static CommonTransitions`
  `createDialogPulsate()`
  Creates a dialog pulsate transition
  `static CommonTransitions`
  `createEmpty()`
  Creates an empty transition that does nothing.
  `static CommonTransitions`
  `createFade(int duration)`
  Creates a transition for fading a form in while fading out the original form
  `static CommonTransitions`
  `createFastSlide(int type, boolean forward, int duration)`
  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.
  `static CommonTransitions`
  `createFastSlide(int type, boolean forward, int duration, boolean drawDialogMenu)`
  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.
  `static CommonTransitions`
  `createSlide(int type, boolean forward, int duration)`
  Creates a slide transition with the given duration and direction
  `static CommonTransitions`
  `createSlide(int type, boolean forward, int duration, boolean drawDialogMenu)`
  Creates a slide transition with the given duration and direction
  `static CommonTransitions`
  `createSlideFadeTitle(boolean forward, int duration)`
  Creates a slide transition for the body of the form that fades the title in while sliding
  `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
  `static CommonTransitions`
  `createUncover(int type, boolean forward, int duration)`
  Creates a uncover transition with the given duration and direction
  `Motion`
  `getMotion()`
  Motion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feel
  `int`
  `getTransitionSpeed()`
  Returns the speed of the transition in milliseconds
  `void`
  `initTransition()`
  Callback thats invoked before a transition begins, the source form may be null for the first form in the application.
  `static boolean`
  `isDefaultLinearMotion()`
  Indicates whether the motion associated with these transitions by default is linear or spline motion
  `boolean`
  `isForwardSlide()`
  Indicates the slide/cover transition direction
  `boolean`
  `isHorizontalCover()`
  Returns true if this is a horizontal cover transition
  `boolean`
  `isHorizontalSlide()`
  Returns true if this is a horizontal slide transition
  `boolean`
  `isLinearMotion()`
  Indicates whether the motion associated with this transition is linear or spline motion
  `boolean`
  `isVerticalCover()`
  Returns true if this is a vertical cover transition
  `boolean`
  `isVerticalSlide()`
  Returns true if this is a vertical slide transition
  `void`
  `paint(Graphics g)`
  Draws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.
  `static void`
  `setDefaultLinearMotion(boolean aDefaultLinearMotion)`
  Indicates whether the motion associated with these transitions by default is linear or spline motion
  `void`
  `setLinearMotion(boolean linearMotion)`
  Indicates whether the motion associated with this transition is linear or spline motion
  `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
  `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

  ### Methods inherited from class Transition

  `cleanSource, getDestination, getSource, hideInterformContainers, init, paintInterformContainers, showInterformContainers`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SLIDE_HORIZONTAL

    public static final int SLIDE_HORIZONTAL

    Slide the transition horizontally

    ###### See also

    - #createSlide
    See Also:
      - Constant Field Values

  - ### SLIDE_VERTICAL

    public static final int SLIDE_VERTICAL

    Slide the transition vertically

    ###### See also

    - #createSlide
    See Also:
      - Constant Field Values

- ## 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`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: 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)

    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`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: represent the time the transition should take in millisecond

    ###### Returns

    a transition object

    ###### Deprecated

    this is not faster than slide on modern devices, you should use that `boolean, int)`

  - ### createSlide

    public static CommonTransitions createSlide(int type, boolean forward, int duration)

    Creates a slide transition with the given duration and direction

    ###### Parameters

    - `type`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: 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`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: represent the time the transition should take in millisecond

    - `drawDialogMenu`: @param drawDialogMenu 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`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: 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`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: 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)

    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`: @param type type can be either vertically or horizontally, which means the movement direction of the transition

    - `forward`: @param forward forward is a boolean value, represent the directions of switching forms, for example for a horizontally type, true means horizontally movement to right.

    - `duration`: represent the time the transition should take in millisecond

    - `drawDialogMenu`: @param drawDialogMenu 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

    ###### Deprecated

    this is not faster than slide on modern devices, you should use that `boolean, int, boolean)`

  - ### createFade

    public static CommonTransitions createFade(int duration)

    Creates a transition for fading a form in while fading out the original form

    ###### Parameters

    - `duration`: 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`: 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`: 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.
    Overrides:
      `initTransition` in class `Transition`

  - ### 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

    Specified by:
      `animate` in interface `Animation`
    Specified by:
      `animate` in class `Transition`

  - ### 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 context
    Specified by:
      `paint` in interface `Animation`
    Specified by:
      `paint` in class `Transition`

  - ### cleanup

    public void cleanup()
    Optional operation to cleanup the garbage left over by a running transition
    Overrides:
      `cleanup` in class `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`: 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`: 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`: @param reverse creates a new transition instance with "reverse" behavior useful for signifying "back" operations

    ###### Returns

    new transition instance

    Overrides:
      `copy` in class `Transition`

  - ### 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`: the linearMotion to set