MotionEffect

public class MotionEffect
extends View implements MotionHelperInterface

java.lang.Object
   ↳ android.view.View
     ↳ androidx.constraintlayout.helper.widget.MotionEffect


MotionHelper that automatically inserts keyframes for views moving in a given direction, out of:

  • NORTH
  • SOUTH
  • EAST
  • WEST
By default, will pick the opposite of the dominant direction (e.g. elements /not/ moving in the dominant direction will have the keyframes inserted).

Summary

Constants

int AUTO

int EAST

int NORTH

int SOUTH

String TAG

int WEST

Inherited constants

Fields

protected HashMap<Integer, String> mMap

protected View[] views

Inherited fields

Public constructors

MotionEffect(Context context)
MotionEffect(Context context, AttributeSet attrs)
MotionEffect(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

void addView(View view)

Add a view to the helper.

boolean containsId(int id)
float getProgress()
int[] getReferencedIds()

Helpers typically reference a collection of ids

int indexFromId(int id)
boolean isDecorator()
void loadParameters(ConstraintSet.Constraint constraint, HelperWidget child, ConstraintLayout.LayoutParams layoutParams, SparseArray<ConstraintWidget> mapIdToWidget)
void onFinishedMotionScene(MotionLayout motionLayout)

This is called after motionLayout read motionScene and assembles all constraintSets

void onPostDraw(Canvas canvas)
void onPreDraw(Canvas canvas)
void onPreSetup(MotionLayout motionLayout, HashMap<ViewMotionController> controllerMap)

Called after motionController is populated with start and end and keyframes.

void onTransitionChange(MotionLayout motionLayout, int startId, int endId, float progress)

Called when a drawer's position changes.

void onTransitionCompleted(MotionLayout motionLayout, int currentId)

Called when a drawer has settled completely a state.

void onTransitionStarted(MotionLayout motionLayout, int startId, int endId)

Called when a drawer is about to start a transition.

void onTransitionTrigger(MotionLayout motionLayout, int triggerId, boolean positive, float progress)

Call when a trigger is fired

int removeView(View view)

Remove a given view from the helper.

void resolveRtl(ConstraintWidget widget, boolean isRtl)
void setProgress(float progress)
void setReferencedIds(int[] ids)

Helpers typically reference a collection of ids

void setTag(int key, Object tag)
void updatePostConstraints(ConstraintLayout container)
void updatePreDraw(ConstraintLayout container)
void updatePreLayout(ConstraintWidgetContainer container, Helper helper, SparseArray<ConstraintWidget> map)

Protected methods

View[] getViews(ConstraintLayout layout)
void onAttachedToWindow()

Inherited methods

Constants

AUTO

public static final int AUTO

Constant Value: -1 (0xffffffff)

EAST

public static final int EAST

Constant Value: 2 (0x00000002)

NORTH

public static final int NORTH

Constant Value: 0 (0x00000000)

SOUTH

public static final int SOUTH

Constant Value: 1 (0x00000001)

TAG

public static final String TAG

Constant Value: "FadeMove"

WEST

public static final int WEST

Constant Value: 3 (0x00000003)

Fields

mMap

protected HashMap<Integer, String> mMap

views

protected View[] views

Public constructors

MotionEffect

public MotionEffect (Context context)

Parameters
context Context

MotionEffect

public MotionEffect (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MotionEffect

public MotionEffect (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

addView

public void addView (View view)

Add a view to the helper. The referenced view need to be a child of the helper's parent. The view also need to have its id set in order to be added.

containsId

public boolean containsId (int id)

Parameters
id int

Returns
boolean

getProgress

public float getProgress ()

Returns
float

getReferencedIds

public int[] getReferencedIds ()

Helpers typically reference a collection of ids

Returns
int[] ids referenced

indexFromId

public int indexFromId (int id)

Parameters
id int

Returns
int

isDecorator

public boolean isDecorator ()

Returns
boolean

loadParameters

public void loadParameters (ConstraintSet.Constraint constraint, 
                HelperWidget child, 
                ConstraintLayout.LayoutParams layoutParams, 
                SparseArray<ConstraintWidget> mapIdToWidget)

Parameters
constraint ConstraintSet.Constraint

child HelperWidget

layoutParams ConstraintLayout.LayoutParams

mapIdToWidget SparseArray

onFinishedMotionScene

public void onFinishedMotionScene (MotionLayout motionLayout)

This is called after motionLayout read motionScene and assembles all constraintSets

onPostDraw

public void onPostDraw (Canvas canvas)

Parameters
canvas Canvas

onPreDraw

public void onPreDraw (Canvas canvas)

Parameters
canvas Canvas

onPreSetup

public void onPreSetup (MotionLayout motionLayout, 
                HashMap<ViewMotionController> controllerMap)

Called after motionController is populated with start and end and keyframes.

onTransitionChange

public void onTransitionChange (MotionLayout motionLayout, 
                int startId, 
                int endId, 
                float progress)

Called when a drawer's position changes.

Parameters
motionLayout MotionLayout: The TransitionLayout view that was moved

startId int: the id of the start state (or ConstraintSet). Will be -1 if unknown.

endId int: the id of the end state (or ConstraintSet).

progress float: The progress on this transition, from 0 to 1.

onTransitionCompleted

public void onTransitionCompleted (MotionLayout motionLayout, 
                int currentId)

Called when a drawer has settled completely a state. The TransitionLayout is interactive at this point.

Parameters
motionLayout MotionLayout: Drawer view that is now open

currentId int: the id it has reached

onTransitionStarted

public void onTransitionStarted (MotionLayout motionLayout, 
                int startId, 
                int endId)

Called when a drawer is about to start a transition. Note. startId may be -1 if starting from an "undefined state"

Parameters
motionLayout MotionLayout: The TransitionLayout view that was moved

startId int: the id of the start state (or ConstraintSet). Will be -1 if unknown.

endId int: the id of the end state (or ConstraintSet).

onTransitionTrigger

public void onTransitionTrigger (MotionLayout motionLayout, 
                int triggerId, 
                boolean positive, 
                float progress)

Call when a trigger is fired

Parameters
triggerId int: The id set set with triggerID

positive boolean: for positive transition edge

removeView

public int removeView (View view)

Remove a given view from the helper.

Returns
int index of view removed

resolveRtl

public void resolveRtl (ConstraintWidget widget, 
                boolean isRtl)

Parameters
widget ConstraintWidget

isRtl boolean

setProgress

public void setProgress (float progress)

Parameters
progress float

setReferencedIds

public void setReferencedIds (int[] ids)

Helpers typically reference a collection of ids

Parameters
ids int

Returns
void ids referenced

setTag

public void setTag (int key, 
                Object tag)

Parameters
key int

tag Object

updatePostConstraints

public void updatePostConstraints (ConstraintLayout container)

Parameters
container ConstraintLayout

updatePreDraw

public void updatePreDraw (ConstraintLayout container)

Parameters
container ConstraintLayout

updatePreLayout

public void updatePreLayout (ConstraintWidgetContainer container, 
                Helper helper, 
                SparseArray<ConstraintWidget> map)

Parameters
container ConstraintWidgetContainer

helper Helper

map SparseArray

Protected methods

getViews

protected View[] getViews (ConstraintLayout layout)

Parameters
layout ConstraintLayout

Returns
View[]

onAttachedToWindow

protected void onAttachedToWindow ()