SharedElementCallback

public abstract class SharedElementCallback
extends Object

java.lang.Object
   ↳ androidx.core.app.SharedElementCallback


Listener provided in Activity.setEnterSharedElementCallback(SharedElementCallback) and Activity.setExitSharedElementCallback(SharedElementCallback) to monitor the Activity transitions. The events can be used to customize Activity Transition behavior.

Summary

Nested classes

interface SharedElementCallback.OnSharedElementsReadyListener

Listener to be called after SharedElementCallback.onSharedElementsArrived(List, List, OnSharedElementsReadyListener) when the shared elements are ready to be hidden in the source Activity and shown in the destination Activity. 

Public constructors

SharedElementCallback()

Public methods

Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds)

Creates a snapshot of a shared element to be used by the remote Activity and reconstituted with onCreateSnapshotView(android.content.Context, android.os.Parcelable).

View onCreateSnapshotView(Context context, Parcelable snapshot)

Reconstitutes a snapshot View from a Parcelable returned in onCaptureSharedElementSnapshot(android.view.View, android.graphics.Matrix, android.graphics.RectF) to be used in onSharedElementStart(java.util.List, java.util.List, java.util.List) and onSharedElementEnd(java.util.List, java.util.List, java.util.List).

void onMapSharedElements(List<String> names, Map<String, View> sharedElements)

Lets the SharedElementCallback adjust the mapping of shared element names to Views.

void onRejectSharedElements(List<View> rejectedSharedElements)

Called after onMapSharedElements(java.util.List, java.util.Map) when transferring shared elements in.

void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)

In Activity Transitions, onSharedElementEnd is called immediately before capturing the end of the shared element state on enter and reenter transitions and immediately before capturing the start of the shared element state for exit and return transitions.

void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)

In Activity Transitions, onSharedElementStart is called immediately before capturing the start of the shared element state on enter and reenter transitions and immediately before capturing the end of the shared element state for exit and return transitions.

void onSharedElementsArrived(List<String> sharedElementNames, List<View> sharedElements, SharedElementCallback.OnSharedElementsReadyListener listener)

Called during an Activity Transition when the shared elements have arrived at the final location and are ready to be transferred.

Inherited methods

Public constructors

SharedElementCallback

public SharedElementCallback ()

Public methods

onCaptureSharedElementSnapshot

public Parcelable onCaptureSharedElementSnapshot (View sharedElement, 
                Matrix viewToGlobalMatrix, 
                RectF screenBounds)

Creates a snapshot of a shared element to be used by the remote Activity and reconstituted with onCreateSnapshotView(android.content.Context, android.os.Parcelable). A null return value will mean that the remote Activity will have a null snapshot View in onSharedElementStart(java.util.List, java.util.List, java.util.List) and onSharedElementEnd(java.util.List, java.util.List, java.util.List).

This is not called for Fragment Transitions.

Parameters
sharedElement View: The shared element View to create a snapshot for.

viewToGlobalMatrix Matrix: A matrix containing a transform from the view to the screen coordinates.

screenBounds RectF: The bounds of shared element in screen coordinate space. This is the bounds of the view with the viewToGlobalMatrix applied.

Returns
Parcelable A snapshot to send to the remote Activity to be reconstituted with onCreateSnapshotView(android.content.Context, android.os.Parcelable) and passed into onSharedElementStart(java.util.List, java.util.List, java.util.List) and onSharedElementEnd(java.util.List, java.util.List, java.util.List).

onCreateSnapshotView

public View onCreateSnapshotView (Context context, 
                Parcelable snapshot)

Reconstitutes a snapshot View from a Parcelable returned in onCaptureSharedElementSnapshot(android.view.View, android.graphics.Matrix, android.graphics.RectF) to be used in onSharedElem