Android APIs
public abstract class

SharedElementCallback

extends Object
java.lang.Object
   ↳ android.support.v4.app.SharedElementCallback

Class Overview

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

Summary

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)
void onMapSharedElements(List<String> names, Map<StringView> 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)
Called after the end state is set for the shared element, but before the end state is captured by the shared element transition.
void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots)
Called immediately after the start state is set for the shared element.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SharedElementCallback ()

Public Methods

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 The shared element View to create a snapshot for.
viewToGlobalMatrix A matrix containing a transform from the view to the screen coordinates.
screenBounds The bounds of shared element in screen coordinate space. This is the bounds of the view with the viewToGlobalMatrix applied.

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 onSharedElementStart(java.util.List, java.util.List, java.util.List) and onSharedElementEnd(java.util.List, java.util.List, java.util.List). The returned View will be sized and positioned after this call so that it is ready to be added to the decor View's overlay.

This is not called for Fragment Transitions.

Parameters
context The Context used to create the snapshot View.
snapshot The Parcelable returned by onCaptureSharedElementSnapshot(android.view.View, android.graphics.Matrix, android.graphics.RectF).
Returns

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

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

Parameters
names The names of all shared elements transferred from the calling Activity or Fragment in the order they were provided.
sharedElements The mapping of shared element names to Views. The best guess will be filled into sharedElements based on the transitionNames.

public void onRejectSharedElements (List<View> rejectedSharedElements)

Called after onMapSharedElements(java.util.List, java.util.Map) when transferring shared elements in. Any shared elements that have no mapping will be in rejectedSharedElements. The elements remaining in rejectedSharedElements will be transitioned out of the Scene. If a View is removed from rejectedSharedElements, it must be handled by the SharedElementListener.

Views in rejectedSharedElements will have their position and size set to the position of the calling shared element, relative to the Window decor View and contain snapshots of the View from the calling Activity or Fragment. This view may be safely added to the decor View's overlay to remain in position.

This method is not called for Fragment Transitions. All rejected shared elements will be handled by the exit transition.

Parameters
rejectedSharedElements Views containing visual information of shared elements that are not part of the entering scene. These Views are positioned relative to the Window decor View. A View removed from this list will not be transitioned automatically.

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

Called after the end state is set for the shared element, but before the end state is captured by the shared element transition.

Any customization done in onSharedElementStart(java.util.List, java.util.List, java.util.List) may need to be modified to the final state of the shared element if it is not automatically corrected by layout. For example, rotation or scale will not be affected by layout and if changed in onSharedElementStart(java.util.List, java.util.List, java.util.List), it will also have to be set here again to correct the end state.

Parameters
sharedElementNames The names of the shared elements that were accepted into the View hierarchy.
sharedElements The shared elements that are part of the View hierarchy.
sharedElementSnapshots The Views containing snap shots of the shared element from the launching Window. These elements will not be part of the scene, but will be positioned relative to the Window decor View. This list will be null for Fragment Transitions.

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

Called immediately after the start state is set for the shared element. The shared element will start at the size and position of the shared element in the launching Activity or Fragment.

Parameters
sharedElementNames The names of the shared elements that were accepted into the View hierarchy.
sharedElements The shared elements that are part of the View hierarchy.
sharedElementSnapshots The Views containing snap shots of the shared element from the launching Window. These elements will not be part of the scene, but will be positioned relative to the Window decor View. This list is null for Fragment Transitions.