Class MorphTransition
- All Implemented Interfaces:
Animation
A transition inspired by the Android L release morph activity effect allowing a set of components in one form/container to morph into another in a different container/form.
Beyond the original position / size morph, this transition can also tween the
opacity, rotation and scale of each morphed target and can morph
arbitrary rendered elements (an Image, a rendered SVG, a snapshot of any
Component, ...) that don't have to be named components living in a Form --
see #morph(MorphElement).
The transition is also scrubbable: instead of letting the framework drive
it from the animation clock you can step it to an arbitrary normalized
position t in [0, 1] with #setProgress(double). Scrubbing is
deterministic (it never reads the wall clock), is repeatable, and can move
backwards, which makes it compose cleanly with a frame-export loop that renders
the same animation at a set of progress fractions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDescribes an arbitrary rendered element that the morph tweens between two states: position, size, opacity, rotation and scale. -
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 MorphTransitioncreate(int duration) Creates a transition with the given duration, this transition should be modified with the builder methods such as morphfloatgetCurrentOpacity(String sourceName) The interpolated opacity (0..1) of a named morph target at the current progress, or1when no opacity tween is registered for that name.floatgetCurrentRotation(String sourceName) The interpolated rotation (degrees) of a named morph target at the current progress, or0when no rotation tween is registered for that name.floatgetCurrentScale(String sourceName) The interpolated scale multiplier of a named morph target at the current progress, or1when no scale tween is registered for that name.doubleReturns the last normalized progress requested through#setProgress(double)(0until the first call).voidCallback thats invoked before a transition begins, the source form may be null for the first form in the application.booleanReturns true once#setProgress(double)has been used to drive this transition manually.booleanReturns the current snapshot-mode setting.morph(MorphTransition.MorphElement element) Morphs an arbitrary rendered element (anImage, a rendered SVG, a snapshot of anyComponent) between two states.Morphs the component with the given source name in the source container hierarchy to the component with the same name in the destination hierarchyMorphs the component with the given source name in the source container hierarchy to the component with the given name in the destination hierarchyTweens the opacity of a named morph target fromfromOpacitytotoOpacity(both in the[0, 1]range) over the course of the transition.voidDraws the animation, within a component the standard paint method would be invoked since it bares the exact same signature.Tweens the rotation of a named morph target fromfromDegreestotoDegreesabout its center.Tweens an extra scale multiplier (about the target center, on top of the interpolated bounds) of a named morph target fromfromScaletotoScale.setProgress(double t) Steps the transition to a normalized progresstin[0, 1]without reading the animation clock.snapshotMode(boolean enabled) Enables the image-snapshot path.Methods inherited from class Transition
cleanSource, getDestination, getSource, hideInterformContainers, init, paintInterformContainers, showInterformContainers
-
Method Details
-
snapshotMode
Enables the image-snapshot path. Each
(source, dest)pair is rendered once into anImageatinitTransition()(clipped to the component's own bounds; off-viewport children do not contribute pixels), then the tween draws those images at the interpolated(x, y, w, h).Use this when:
- The source lives inside a scrolling container whose
scrollX/scrollYwould otherwise leak off-viewport child pixels into the morph (the cross-form morph clipping artifact). - The source has children with dynamic content (a
BrowserComponent, a video frame, a custom-painted background) that should be frozen visually for the duration of the animation. - The source's parent applies a clip that the layered pane wouldn't replicate.
Snapshot mode is also required for the per-named-target
#rotation,#scaleand#opacitytweens to have a visible effect, since those transforms are applied while drawing the captured image.Default is off to preserve back-compat with the legacy live-paint path. Always pair with a screenshot regression test (see
scripts/hellocodenameone/.../MorphTransitionTest).Parameters
enabled:trueto snapshot,falsefor the legacy live-paint mode
Returns
this transition (for chaining with
#morph(String)etc.) - The source lives inside a scrolling container whose
-
isSnapshotMode
public boolean isSnapshotMode()Returns the current snapshot-mode setting. See#snapshotMode(boolean). -
create
Creates a transition with the given duration, this transition should be modified with the builder methods such as morph
Parameters
duration: the duration of the transition
Returns
a new Morph transition instance
-
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
-
morph
Morphs the component with the given source name in the source container hierarchy to the component with the same name in the destination hierarchy
Parameters
cmp: the compoennt name
Returns
this so morph operations can be chained as MorphTransition t = MorphTransition.create(300).morph("a").("c");
-
morph
Morphs the component with the given source name in the source container hierarchy to the component with the given name in the destination hierarchy
Parameters
-
source -
to
Returns
this so morph operations can be chained as MorphTransition t = MorphTransition.create(300).morph("a", "b").("c", "d");
-
-
opacity
Tweens the opacity of a named morph target from
fromOpacitytotoOpacity(both in the[0, 1]range) over the course of the transition. The named target must also be registered with#morph(String)/#morph(String, String). The opacity is applied while drawing the captured snapshot, so this requires#snapshotMode(boolean)to be on to have a visible effect.Parameters
sourceName: the source-side name passed to#morph(String)fromOpacity: the opacity att = 0,0(transparent) to1(opaque)toOpacity: the opacity att = 1
Returns
this transition for chaining
-
rotation
Tweens the rotation of a named morph target from
fromDegreestotoDegreesabout its center. Requires#snapshotMode(boolean)to have a visible effect and an affine-capableGraphics(every modern port); where affine isn't supported the rotation is silently skipped.Parameters
sourceName: the source-side name passed to#morph(String)fromDegrees: rotation in degrees att = 0toDegrees: rotation in degrees att = 1
Returns
this transition for chaining
-
scale
Tweens an extra scale multiplier (about the target center, on top of the interpolated bounds) of a named morph target from
fromScaletotoScale. A value of1leaves the interpolated size unchanged; use this for a "pop" that overshoots the target box. Requires#snapshotMode(boolean)to have a visible effect.Parameters
sourceName: the source-side name passed to#morph(String)fromScale: scale multiplier att = 0toScale: scale multiplier att = 1
Returns
this transition for chaining
-
morph
Morphs an arbitrary rendered element (an
Image, a rendered SVG, a snapshot of anyComponent) between two states. Unlike the named-component morph this does not require the element to be a child of the source / destination form -- the element is drawn as an overlay at the interpolated position, size, opacity, rotation and scale. Multiple elements can be registered and they compose with the named-component morphs.Parameters
element: the element description built viaMorphElement#create
Returns
this transition for chaining
-
setProgress
Steps the transition to a normalized progress
tin[0, 1]without reading the animation clock.0is the source state,1the destination state; intermediate values are eased with the same ease-in-out curve the clock-driven path uses. The call is deterministic, repeatable and may move backwards, so it composes with a frame-export loop that renders the animation at a set of progress fractions:MorphTransition t = MorphTransition.create(600).morph(element); t.init(source, dest); t.initTransition(); for (double f = 0; f <= 1.0; f += 1.0 / frames) { t.setProgress(f); t.paint(frameGraphics); } t.cleanup();#initTransition()must have been invoked first (theAbstractTransitionScreenshotTestharness does this for you). Scrubbing and the clock-drivenanimate()lifecycle are not meant to be mixed on the same instance.Parameters
t: the normalized progress, clamped to[0, 1]
Returns
this transition for chaining
-
getProgress
public double getProgress()Returns the last normalized progress requested through#setProgress(double)(0until the first call). -
isScrubbing
public boolean isScrubbing()Returns true once#setProgress(double)has been used to drive this transition manually. -
getCurrentOpacity
The interpolated opacity (0..1) of a named morph target at the current progress, or1when no opacity tween is registered for that name. Primarily useful for tests / custom rendering. -
getCurrentRotation
The interpolated rotation (degrees) of a named morph target at the current progress, or0when no rotation tween is registered for that name. -
getCurrentScale
The interpolated scale multiplier of a named morph target at the current progress, or1when no scale tween is registered for that name. -
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
-
cleanup
public void cleanup()Optional operation to cleanup the garbage left over by a running transition- Overrides:
cleanupin 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
-