Class CommonTransitions
- All Implemented Interfaces:
Animation
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
FieldsModifier and TypeFieldDescriptionstatic final intSlide the transition horizontallystatic final intSlide the transition vertically -
Method Summary
Modifier and TypeMethodDescriptionbooleananimate()Allows the animation to reduce "repaint" calls when it returns false.voidcleanup()Optional operation to cleanup the garbage left over by a running transitioncopy(boolean reverse) Create a copy of the transition, usually the transition used is a copy.static CommonTransitionscreateCover(int type, boolean forward, int duration) Creates a cover transition with the given duration and directionstatic CommonTransitionsCreates a dialog pulsate transitionstatic CommonTransitionsCreates an empty transition that does nothing.static CommonTransitionscreateFade(int duration) Creates a transition for fading a form in while fading out the original formstatic CommonTransitionscreateFastSlide(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 CommonTransitionscreateFastSlide(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 CommonTransitionscreateSlide(int type, boolean forward, int duration) Creates a slide transition with the given duration and directionstatic CommonTransitionscreateSlide(int type, boolean forward, int duration, boolean drawDialogMenu) Creates a slide transition with the given duration and directionstatic CommonTransitionscreateSlideFadeTitle(boolean forward, int duration) Creates a slide transition for the body of the form that fades the title in while slidingstatic CommonTransitionscreateTimeline(Image animation) Creates a transition using an animated image object (e.g. timeline object) as an alpha mask between the source/targetstatic CommonTransitionscreateUncover(int type, boolean forward, int duration) Creates a uncover transition with the given duration and directionMotion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feelintReturns the speed of the transition in millisecondsvoidCallback thats invoked before a transition begins, the source form may be null for the first form in the application.static booleanIndicates whether the motion associated with these transitions by default is linear or spline motionbooleanIndicates the slide/cover transition directionbooleanReturns true if this is a horizontal cover transitionbooleanReturns true if this is a horizontal slide transitionbooleanIndicates whether the motion associated with this transition is linear or spline motionbooleanReturns true if this is a vertical cover transitionbooleanReturns true if this is a vertical slide transitionvoidDraws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.static voidsetDefaultLinearMotion(boolean aDefaultLinearMotion) Indicates whether the motion associated with these transitions by default is linear or spline motionvoidsetLinearMotion(boolean linearMotion) Indicates whether the motion associated with this transition is linear or spline motionvoidMotion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feelvoidMotion represents the physical movement within a transition, it can be replaced by the user to provide a more appropriate physical feelMethods inherited from class Transition
cleanSource, getDestination, getSource, hideInterformContainers, init, paintInterformContainers, showInterformContainers
-
Field Details
-
SLIDE_HORIZONTAL
public static final int SLIDE_HORIZONTALSlide the transition horizontally
See also
- #createSlide
- See Also:
-
SLIDE_VERTICAL
public static final int SLIDE_VERTICALSlide the transition vertically
See also
- #createSlide
- See Also:
-
-
Method Details
-
createEmpty
Creates an empty transition that does nothing. This has the same effect as setting a transition to null.
Returns
empty transition
-
createSlideFadeTitle
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
Creates a dialog pulsate transition -
createFastSlide
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
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
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
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
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
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:
initTransitionin classTransition
-
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.Displayclass.Returns
true if a repaint is desired or false if no repaint is necessary
- Specified by:
animatein interfaceAnimation- Specified by:
animatein classTransition
-
paint
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:
paintin interfaceAnimation- Specified by:
paintin classTransition
-
cleanup
public void cleanup()Optional operation to cleanup the garbage left over by a running transition- Overrides:
cleanupin classTransition
-
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
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
-
copy
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:
copyin classTransition
-
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
-