public abstract class BaseNavigationalTransition<T extends BaseNavigationalTransition> extends Object
Transitions
framework to simplify and also to made transitioning between two Activities
independent from the current Android version, that is, to hide such transitions implementation
from the context where it is used.
A specific navigational transition implementation may be associated with its corresponding activity
class that can be supplied to BaseNavigationalTransition(Class) constructor. This class
is used to create an instance of Intent that will be by default started whenever start(Activity)
is invoked. Both onStart(Activity) and onFinish(Activity) methods cen be overridden
by a specific transition implementations to match theirs specific needs.
public abstract class DetailTransition extends BaseNavigationalTransition {
DetailTransition() {
super(DetailActivity.class);
}
@NonNull
public static DetailTransition get() {
return UiConfig.MATERIAL_SUPPORT ? new MaterialTransition() : new DefaultTransition();
}
@Override
public Intent createIntent(@NonNull Activity caller) {
final Intent intent = super.createIntent(caller);
// ... put here any extras that need to be delivered to the called activity
return intent;
}
static final class DefaultTransition extends DetailTransition {
@Override
protected void onStart(@NonNull Activity caller) {
super.onStart(caller);
// ... change activities with custom window animation
WindowTransition.overrideStart(caller);
}
@Override
protected void onFinish(@NonNull Activity caller) {
super.onFinish(caller);
// ... change activities without animation
caller.overridePendingTransition(0, 0);
}
}
// ... other implementations specific for a different platform versions
static final class MaterialTransition extends DetailTransition {
@Override
protected void onStart(@NonNull Activity caller) {
// ... made some modifications to the caller's UI (if necessary) before the transitions
// ... are triggered.
super.onStart(caller);
}
@Override
protected void onFinish(@NonNull Activity caller) {
super.onFinish(caller);
// ... no need to override in most cases
}
}
}
| Modifier and Type | Field and Description |
|---|---|
static boolean |
MATERIAL_SUPPORT
Boolean flag indicating whether the current Android device can run Material Design like navigational
transition (i.
|
protected Class<? extends android.app.Activity> |
mClassOfTransitionActivity
Class of activity that should be started as new Intent whenever this navigational transition
is started via
start(Activity). |
static int |
RC_NONE
Flag determining that no request code has been specified for a specific navigational transition.
|
| Constructor and Description |
|---|
BaseNavigationalTransition()
Creates a new instance of NavigationalTransition without transition activity class.
|
BaseNavigationalTransition(Class<? extends android.app.Activity> classOfTransitionActivity)
Creates a new instance of NavigationalTransition with the specified class of transition activity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
allowEnterTransitionOverlap()
Returns boolean flag indicating whether enter transition may overlap or not.
|
T |
allowEnterTransitionOverlap(boolean allow)
Specifies a boolean flag to be set to a window of an incoming activity in order to
indicate whether enter transition may overlap or not.
|
boolean |
allowReturnTransitionOverlap()
Returns boolean flag indicating whether return transition may overlap or not.
|
T |
allowReturnTransitionOverlap(boolean allow)
Specifies a boolean flag to be set to a window of an incoming activity in order to
indicate whether return transition may overlap or not.
|
void |
configureIncomingTransitions(android.app.Activity activity)
Performs configuration of the given activity's window by attaching to it enter
and return transitions (those for shared elements including) specified for this navigational
transition.
|
void |
configureOutgoingTransitions(android.app.Activity activity)
Performs configuration of the given activity's window by attaching to it reenter
and exit transitions (those for shared elements including) specified for this navigational
transition.
|
void |
configureTransitions(android.app.Activity activity)
This method groups calls to
configureIncomingTransitions(Activity) and
configureOutgoingTransitions(Activity) into one call. |
void |
configureTransitionsOverlapping(android.app.Activity activity)
Deprecated.
Use
configureIncomingTransitions(Activity) instead. |
android.content.Intent |
createIntent(android.app.Activity caller)
Creates an intent that can be used to start activity for which is this transition created.
|
android.transition.Transition |
enterTransition()
Returns enter transition for the incoming activity.
|
T |
enterTransition(android.transition.Transition transition)
Specifies enter transition to be attached to a window of an incoming activity.
|
android.transition.Transition |
exitTransition()
Returns exit transition for the outgoing activity.
|
T |
exitTransition(android.transition.Transition transition)
Specifies exit transition to be attached to a window of an outgoing activity whenever
start(Activity) is invoked. |
void |
finish(android.app.Activity caller)
Finishes the given caller activity in order to run its exit transitions.
|
protected void |
finishCaller(android.app.Activity caller)
Finishes the specified caller activity either via
Activity.finishAfterTransition()
or via Activity.finish() depending on the current API capabilities. |
protected void |
finishCallerDelayed(android.app.Activity caller,
long delay)
Like
finishCaller(Activity) but this will postpone the finishing by the requested
delay. |
android.transition.Transition |
inflateTransition(android.content.Context context,
int resource)
Inflates a new instance of Transition from the specified resource.
|
android.transition.TransitionManager |
inflateTransitionManager(android.content.Context context,
int resource,
android.view.ViewGroup sceneRoot)
Inflates a new instance of TransitionManager from the specified resource.
|
android.os.Bundle |
intentExtras()
Returns the bundle with extras for the incoming activity.
|
T |
intentExtras(android.os.Bundle extras)
Specifies a bundle with extras for the incoming activity.
|
android.app.ActivityOptions |
makeSceneTransitionAnimation(android.app.Activity caller)
Creates a new instance of ActivityOptions for the specified caller activity.
|
protected void |
onFinish(android.app.Activity caller)
Invoked whenever
finish(Activity) is called. |
protected void |
onFinishCaller(android.app.Activity caller)
Invoked whenever
finishCaller(Activity) or finishCallerDelayed(Activity, long)
is called. |
protected void |
onStart(android.app.Activity caller)
Invoked whenever
start(Activity) is called. |
android.transition.Transition |
reenterTransition()
Returns reenter transition for the outgoing activity.
|
T |
reenterTransition(android.transition.Transition transition)
Specifies reenter transition to be attached to a window of an outgoing activity whenever
start(Activity) is invoked. |
int |
requestCode()
Returns the request code specified via
requestCode(int). |
T |
requestCode(int requestCode)
Specifies a request code that should be used to start activity specific for this navigational
transition for result.
|
android.transition.Transition |
returnTransition()
Returns return transition for the incoming activity.
|
T |
returnTransition(android.transition.Transition transition)
Specifies return transition to be attached to a window of an incoming activity.
|
T |
sharedElement(android.view.View element,
String elementName)
Adds shared element that should be transferred to the transitioning (called) activity via
ActivityOptions as Bundle. |
android.transition.Transition |
sharedElementEnterTransition()
Returns shared element enter transition for the incoming activity.
|
T |
sharedElementEnterTransition(android.transition.Transition transition)
Specifies enter transition for shared element to be attached to a window of an incoming
activity.
|
android.transition.Transition |
sharedElementExitTransition()
Returns shared element exit transition for the outgoing activity.
|
T |
sharedElementExitTransition(android.transition.Transition transition)
Specifies exit transition for shared element to be attached to a window of an outgoing
activity whenever
start(Activity) is invoked. |
android.transition.Transition |
sharedElementReenterTransition()
Returns shared element reenter transition for the outgoing activity.
|
T |
sharedElementReenterTransition(android.transition.Transition transition)
Specifies reenter transition for shared element to be attached to a window of an outgoing
activity whenever
start(Activity) is invoked. |
android.transition.Transition |
sharedElementReturnTransition()
Returns shared element return transition for the incoming activity.
|
T |
sharedElementReturnTransition(android.transition.Transition transition)
Specifies return transition for shared element to be attached to a window of an incoming
activity.
|
List<android.util.Pair<android.view.View,String>> |
sharedElements()
Returns a list of all shared elements specified for this navigational transition.
|
T |
sharedElements(android.util.Pair<android.view.View,String>... elements)
Bulk method for adding shared element pairs into this navigational transition.
|
boolean |
sharedElementsUseOverlay()
Returns boolean flag indicating whether shared elements should use overlay or not.
|
T |
sharedElementsUseOverlay(boolean useOverlay)
Specifies a boolean flag to be set to a window of an incoming or outgoing activity
in order to indicate whether shared elements should use overlay or not.
|
android.util.Pair<android.view.View,String> |
singleSharedElement()
Returns the single shared element at the
0 position among the current shared elements. |
void |
start(android.app.Activity caller)
Starts this navigational transition using the given caller activity with transitions
and shared elements that are configured for the activity via
configureOutgoingTransitions(Activity). |
public static final boolean MATERIAL_SUPPORT
public static final int RC_NONE
protected final Class<? extends android.app.Activity> mClassOfTransitionActivity
start(Activity).public BaseNavigationalTransition()
public BaseNavigationalTransition(Class<? extends android.app.Activity> classOfTransitionActivity)
classOfTransitionActivity - The activity class that should be used to create a new Intent
that to be started whenever start(Activity) is called
upon this navigational transition.public T intentExtras(android.os.Bundle extras)
Intent via Intent.putExtras(Bundle) when it is
created via createIntent(Activity).extras - The desired bundle with extras. May be null to clear the current one.intentExtras()public android.os.Bundle intentExtras()
This will be either bundle specified via intentExtras(Bundle) or created by default
when this method is called for the first time.
intentExtras(Bundle)public T requestCode(int requestCode)
Default value: RC_NONE
requestCode - The desired request code. Can be RC_NONE to not start activity
for result.requestCode(),
Activity.startActivityForResult(Intent, int),
Activity.startActivityForResult(Intent, int, Bundle),
Fragment.startActivityForResult(Intent, int)public int requestCode()
requestCode(int).RC_NONE by default.public T enterTransition(android.transition.Transition transition)
enterTransition(),
Window.setEnterTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)public android.transition.Transition enterTransition()
enterTransition(Transition) or null by
default.public T reenterTransition(android.transition.Transition transition)
start(Activity) is invoked.reenterTransition(),
Window.setReenterTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)public android.transition.Transition reenterTransition()
reenterTransition(Transition) or null by
default.public T returnTransition(android.transition.Transition transition)
returnTransition(),
Window.setReturnTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)public android.transition.Transition returnTransition()
returnTransition(Transition) or null by
default.public T exitTransition(android.transition.Transition transition)
start(Activity) is invoked.exitTransition(),
Window.setExitTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)public android.transition.Transition exitTransition()
exitTransition(Transition) or null by
default.public T allowEnterTransitionOverlap(boolean allow)
Default value: false
allowEnterTransitionOverlap(),
Window.setAllowEnterTransitionOverlap(boolean),
configureIncomingTransitions(Activity)public boolean allowEnterTransitionOverlap()
True if overlapping of enter transition is enabled, false otherwise.public T allowReturnTransitionOverlap(boolean allow)
Default value: false
allowReturnTransitionOverlap(),
Window.setAllowReturnTransitionOverlap(boolean),
configureIncomingTransitions(Activity)public boolean allowReturnTransitionOverlap()
True if overlapping of return transition is enabled, false otherwise.public T sharedElementEnterTransition(android.transition.Transition transition)
sharedElementEnterTransition(),
Window.setSharedElementEnterTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)public android.transition.Transition sharedElementEnterTransition()
sharedElementEnterTransition(Transition)
or null by default.public T sharedElementReenterTransition(android.transition.Transition transition)
start(Activity) is invoked.sharedElementReenterTransition(),
Window.setSharedElementReenterTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)public android.transition.Transition sharedElementReenterTransition()
sharedElementReenterTransition(Transition)
or null by default.public T sharedElementReturnTransition(android.transition.Transition transition)
sharedElementReturnTransition(),
Window.setSharedElementReturnTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)public android.transition.Transition sharedElementReturnTransition()
sharedElementReturnTransition(Transition)
or null by default.public T sharedElementExitTransition(android.transition.Transition transition)
start(Activity) is invoked.sharedElementExitTransition(),
Window.setSharedElementExitTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition sharedElementExitTransition()
sharedElementExitTransition(Transition)
or null by default.public T sharedElementsUseOverlay(boolean useOverlay)
Default value: false
sharedElementsUseOverlay(),
Window.setSharedElementsUseOverlay(boolean),
configureIncomingTransitions(Activity),
configureOutgoingTransitions(Activity)public boolean sharedElementsUseOverlay()
True if shared elements will use overlay, false otherwise.sharedElementsUseOverlay(boolean)public android.transition.Transition inflateTransition(android.content.Context context,
int resource)
Note, that for pre LOLLIPOP Android
versions this method does nothing and returns null.
context - Context used to inflate the desired transition.resource - Resource id of the desired transition to inflate.inflateTransitionManager(Context, int, ViewGroup)public android.transition.TransitionManager inflateTransitionManager(android.content.Context context,
int resource,
android.view.ViewGroup sceneRoot)
Note, that for pre LOLLIPOP Android
versions this method does nothing and returns null.
context - Context used to inflate the desired transition.resource - Resource id of the desired transition manager to inflater.sceneRoot - Root view for the scene with which will the manager operate.inflateTransition(Context, int)@SafeVarargs public final T sharedElements(android.util.Pair<android.view.View,String>... elements)
elements - The desired shared elements pairs.sharedElement(View, String)public T sharedElement(android.view.View element, String elementName)
ActivityOptions as Bundle.
All shared elements and their names added into this navigational transition will be bundled
from ActivityOptions created via makeSceneTransitionAnimation(Activity) and transferred
to the called activity whenever start(Activity) is called.
Note, that each shared element must have a unique name.
element - The view to be shared via transition.elementName - The name of the shared element.sharedElements(Pair[]),
makeSceneTransitionAnimation(Activity)public List<android.util.Pair<android.view.View,String>> sharedElements()
null if there are no shared elements specified.sharedElements(Pair[]),
sharedElement(View, String),
singleSharedElement()public android.util.Pair<android.view.View,String> singleSharedElement()
0 position among the current shared elements.
This method may be used to obtain a single shared element when there is specified only one for this navigational transition.
null if there are no shared elements specified.sharedElements(),
sharedElement(View, String)public void start(android.app.Activity caller)
configureOutgoingTransitions(Activity).caller - The activity that will be used to create and start an Intent created via
createIntent(Activity).protected void onStart(android.app.Activity caller)
start(Activity) is called.
Default implementation starts an Intent created via createIntent(Activity) using
the given caller activity via Activity.startActivity(Intent) for the pre LOLLIPOP
Android versions and for the post LOLLIPOP via Activity.startActivity(Intent, Bundle)
where will be passed Bundle created from ActivityOptions that has been requested via
makeSceneTransitionAnimation(Activity).
If there was specified some requestCode() the intent will be started via
Activity.startActivityForResult(Intent, int) for the pre LOLLIPOP Android versions
and for the post LOLLIPOP via Activity.startActivityForResult(Intent, int, Bundle).
Note, that the specified caller activity has already attached transitions to its
window, that has been specified for this navigational transition via one of set...Transition(...)
methods.
caller - The caller activity that requested start of this navigational transition.onFinish(Activity)protected void finishCallerDelayed(android.app.Activity caller,
long delay)
finishCaller(Activity) but this will postpone the finishing by the requested
delay.caller - The caller activity to finish.delay - The desired delay after which to finish the caller activity.protected void finishCaller(android.app.Activity caller)
Activity.finishAfterTransition()
or via Activity.finish() depending on the current API capabilities.caller - The caller activity to finish.protected void onFinishCaller(android.app.Activity caller)
finishCaller(Activity) or finishCallerDelayed(Activity, long)
is called.
Default implementation finishes the caller activity either via Activity.finishAfterTransition()
or via Activity.finish() depending on the current API capabilities.
caller - The caller activity to finish.@Deprecated public void configureTransitionsOverlapping(android.app.Activity activity)
configureIncomingTransitions(Activity) instead.Specifies a boolean flags for a window of the specified activity determining whether an enter or return transition can overlap or not based on the requested values for this navigational transition.
Note, that for pre LOLLIPOP Android
versions this method does nothing.
activity - The activity for which window to specify whether an enter or return transition
can overlap or not.Window.setAllowEnterTransitionOverlap(boolean),
Window.setAllowReturnTransitionOverlap(boolean)public void configureTransitions(android.app.Activity activity)
configureIncomingTransitions(Activity) and
configureOutgoingTransitions(Activity) into one call.activity - The activity of which window transitions to configure.public void configureIncomingTransitions(android.app.Activity activity)
This method should be called from Activity.onCreate(Bundle) by the activity to which
is the calling activity transitioning. See also configureOutgoingTransitions(Activity).
Note, that for pre LOLLIPOP Android versions this
method does nothing.
activity - The activity of which window transitions to configure.Window.setEnterTransition(Transition),
Window.setReturnTransition(Transition),
Window.setSharedElementEnterTransition(Transition),
Window.setSharedElementReturnTransition(Transition),
Window.setAllowEnterTransitionOverlap(boolean),
Window.setAllowReturnTransitionOverlap(boolean)public void configureOutgoingTransitions(android.app.Activity activity)
This method is by default invoked whenever start(Activity) is called for this
navigational transition. Its counterpart, configureIncomingTransitions(Activity),
should be called by the activity to which is the calling activity transitioning.
Note, that for pre LOLLIPOP Android versions this
method does nothing.
activity - The activity of which window transitions to configure.Window.setReenterTransition(Transition),
Window.setExitTransition(Transition),
Window.setSharedElementReenterTransition(Transition),
Window.setSharedElementExitTransition(Transition)public android.app.ActivityOptions makeSceneTransitionAnimation(android.app.Activity caller)
Note, that for pre LOLLIPOP Android
versions this method does nothing and returns null.
caller - The activity for which to create the ActivityOptions.public android.content.Intent createIntent(android.app.Activity caller)
caller - Activity to be used as context when creating the requested intent.null it this navigational transition has no class of transition
activity specified.public void finish(android.app.Activity caller)
caller - The activity that should be finished and of which exit transitions should be started.start(Activity)protected void onFinish(android.app.Activity caller)
finish(Activity) is called.
Default implementation finishes the given caller activity for the pre LOLLIPOP Android versions
via Activity.finish() and for the post LOLLIPOP via Activity.finishAfterTransition().
Derived classes can override this method in order to run custom window transitions for the
pre LOLLIPOP Android versions via Activity.overridePendingTransition(int, int).
caller - The activity that requested its finish via this navigational transition.onStart(Activity)