MotionScene

public class MotionScene
extends Object

java.lang.Object
   ↳ androidx.constraintlayout.motion.widget.MotionScene


The information to transition between multiple ConstraintSets This Class is meant to be used from XML

Summary

Nested classes

class MotionScene.Transition

Transition defines the interaction from one state to another. 

Constants

int LAYOUT_HONOR_REQUEST

int LAYOUT_IGNORE_REQUEST

String TAG

int UNSET

Public constructors

MotionScene(MotionLayout layout)

Create a motion scene.

Public methods

void addOnClickListeners(MotionLayout motionLayout, int currentState)
void addTransition(MotionScene.Transition transition)

Add a transition to the motion scene.

boolean applyViewTransition(int viewTransitionId, MotionController motionController)
MotionScene.Transition bestTransitionFor(int currentState, float dx, float dy, MotionEvent lastTouchDown)
void disableAutoTransition(boolean disable)

this allow disabling autoTransitions to prevent design surface from being in undefined states

void enableViewTransition(int id, boolean enable)
int gatPathMotionArc()
ConstraintSet getConstraintSet(Context context, String id)
int[] getConstraintSetIds()
ArrayList<MotionScene.Transition> getDefinedTransitions()
int getDuration()

Get Duration of the current transition.

Interpolator getInterpolator()
void getKeyFrames(MotionController motionController)

provides the key frames & CycleFrames to the motion view to

float getPathPercent(View view, int position)
float getStaggered()

Get the staggered value of the current transition.

MotionScene.Transition getTransitionById(int id)
List<MotionScene.Transition> getTransitionsWithState(int stateId)
boolean isViewTransitionEnabled(int id)
int lookUpConstraintId(String id)

Used at design time

String lookUpConstraintName(int id)

used at design time

void removeTransition(MotionScene.Transition transition)

Remove the transition with the matching id from the motion scene.

void setConstraintSet(int id, ConstraintSet set)

Maps the Constraint set to the id.

void setDuration(int duration)

Sets the duration of the current transition or the default if there is no current transition

void setKeyframe(View view, int position, String name, Object value)
void setRtl(boolean rtl)
void setTransition(MotionScene.Transition transition)

Set the transition to be the current transition of the motion scene.

static String stripID(String id)
boolean validateLayout(MotionLayout layout)
void viewTransition(int id, View... view)

Protected methods

void onLayout(boolean changed, int left, int top, int right, int bottom)

Inherited methods

Constants

LAYOUT_HONOR_REQUEST

public static final int LAYOUT_HONOR_REQUEST

Constant Value: 1 (0x00000001)

LAYOUT_IGNORE_REQUEST

public static final int LAYOUT_IGNORE_REQUEST

Constant Value: 0 (0x00000000)

TAG

public static final String TAG

Constant Value: "MotionScene"

UNSET

public static final int UNSET

Constant Value: -1 (0xffffffff)

Public constructors

MotionScene

public MotionScene (MotionLayout layout)

Create a motion scene.

Parameters
layout MotionLayout: Motion layout to which the scene will be set.

Public methods

addOnClickListeners

public void addOnClickListeners (MotionLayout motionLayout, 
                int currentState)

Parameters
motionLayout MotionLayout

currentState int

addTransition

public void addTransition (MotionScene.Transition transition)

Add a transition to the motion scene. If a transition with the same id already exists in the scene, the new transition will replace the existing one.

Parameters
transition MotionScene.Transition

Throws
IllegalArgumentException if the transition does not have an id.

applyViewTransition

public boolean applyViewTransition (int viewTransitionId, 
                MotionController motionController)

Parameters
viewTransitionId int

motionController MotionController

Returns
boolean

bestTransitionFor

public MotionScene.Transition bestTransitionFor (int currentState, 
                float dx, 
                float dy, 
                MotionEvent lastTouchDown)

Parameters
currentState int

dx float

dy float

lastTouchDown MotionEvent

Returns
MotionScene.Transition

disableAutoTransition

public void disableAutoTransition (boolean disable)

this allow disabling autoTransitions to prevent design surface from being in undefined states

enableViewTransition

public void enableViewTransition (int id, 
                boolean enable)

Parameters
id int

enable boolean

gatPathMotionArc

public int gatPathMotionArc ()

Returns
int

getConstraintSet

public ConstraintSet getConstraintSet (Context context, 
                String id)

Parameters
context Context

id String

Returns
ConstraintSet

getConstraintSetIds

public int[] getConstraintSetIds ()

Returns
int[]

getDefinedTransitions

public ArrayList<MotionScene.Transition> getDefinedTransitions ()

Returns
ArrayList<MotionScene.Transition>

getDuration

public int getDuration ()

Get Duration of the current transition.

Returns
int duration in milliseconds

getInterpolator

public Interpolator getInterpolator ()

Returns
Interpolator

getKeyFrames

public void getKeyFrames (MotionController motionController)

provides the key frames & CycleFrames to the motion view to

getPathPercent

public float getPathPercent (View view, 
                int position)

Parameters
view View

position int

Returns
float

getStaggered

public float getStaggered ()

Get the staggered value of the current transition. Will default to 0 staggered if there is no current transition.

Returns
float

getTransitionById

public MotionScene.Transition getTransitionById (int id)

Parameters
id int

Returns
MotionScene.Transition

getTransitionsWithState

public List<MotionScene.Transition> getTransitionsWithState (int stateId)

Parameters
stateId int

Returns
List<MotionScene.Transition>

isViewTransitionEnabled

public boolean isViewTransitionEnabled (int id)

Parameters
id int

Returns
boolean

lookUpConstraintId

public int lookUpConstraintId (String id)

Used at design time

Returns
int

lookUpConstraintName

public String lookUpConstraintName (int id)

used at design time

Parameters
id int

Returns
String

removeTransition

public void removeTransition (MotionScene.Transition transition)

Remove the transition with the matching id from the motion scene. If no matching transition is found, it does nothing.

Parameters
transition MotionScene.Transition

Throws
IllegalArgumentException if the transition does not have an id.

setConstraintSet

public void setConstraintSet (int id, 
                ConstraintSet set)

Maps the Constraint set to the id.

Parameters
id int: - unique id to represent the ConstraintSet

set ConstraintSet: - ConstraintSet to be represented with the id.

setDuration

public void setDuration (int duration)

Sets the duration of the current transition or the default if there is no current transition

Parameters
duration int: in milliseconds

setKeyframe

public void setKeyframe (View view, 
                int position, 
                String name, 
                Object value)

Parameters
view View

position int

name String

value Object

setRtl

public void setRtl (boolean rtl)

Parameters
rtl boolean

setTransition

public void setTransition (MotionScene.Transition transition)

Set the transition to be the current transition of the motion scene.

Parameters
transition MotionScene.Transition: a transition to be set. The transition must exist within the motion scene. (e.g. addTransition(Transition))

stripID

public static String stripID (String id)

Parameters
id String

Returns
String

validateLayout

public boolean validateLayout (MotionLayout layout)

Parameters
layout MotionLayout

Returns
boolean true if the layout is valid for the scene. False otherwise. Use it for the debugging purposes.

viewTransition

public void viewTransition (int id, 
                View... view)

Parameters
id int

view View

Protected methods

onLayout

protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int