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() |
T |
allowEnterTransitionOverlap(boolean allow)
Specifies a boolean flag to be set to a window of the caller activity whenever
start(Activity) is invoked. |
boolean |
allowReturnTransitionOverlap() |
T |
allowReturnTransitionOverlap(boolean allow)
Specifies a boolean flag to be set to a window of the caller activity whenever
start(Activity) is invoked. |
void |
configureTransitions(android.app.Activity activity)
Attaches all transitions, including those for shared elements, specified for this navigational
transition to a window of the specified activity via one of
Window#set...Transition(...) methods. |
void |
configureTransitionsOverlapping(android.app.Activity activity)
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.
|
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() |
T |
enterTransition(android.transition.Transition transition)
Specifies a transition to be attached to a window of the caller activity whenever
start(Activity) is invoked. |
android.transition.Transition |
exitTransition() |
T |
exitTransition(android.transition.Transition transition)
Specifies a transition to be attached to a window of the caller 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 transition activity.
|
T |
intentExtras(android.os.Bundle extras)
Specifies a bundle with extras for the transition 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() |
T |
reenterTransition(android.transition.Transition transition)
Specifies a transition to be attached to a window of the caller 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() |
T |
returnTransition(android.transition.Transition transition)
Specifies a transition to be attached to a window of the caller activity whenever
start(Activity) is invoked. |
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() |
T |
sharedElementEnterTransition(android.transition.Transition transition)
Specifies a transition for shared element to be attached to a window of the caller activity
whenever
start(Activity) is invoked. |
android.transition.Transition |
sharedElementExitTransition() |
T |
sharedElementExitTransition(android.transition.Transition transition)
Specifies a transition for shared element to be attached to a window of the caller activity
whenever
start(Activity) is invoked. |
android.transition.Transition |
sharedElementReenterTransition() |
T |
sharedElementReenterTransition(android.transition.Transition transition)
Specifies a transition for shared element to be attached to a window of the caller activity
whenever
start(Activity) is invoked. |
android.transition.Transition |
sharedElementReturnTransition() |
T |
sharedElementReturnTransition(android.transition.Transition transition)
Specifies a transition for shared element to be attached to a window of the caller activity
whenever
start(Activity) is invoked. |
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.
|
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 all
transitions and shared elements specified for this navigational transition.
|
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.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)
start(Activity) is invoked.Window.setEnterTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition enterTransition()
enterTransition(Transition) or null by
default.public T reenterTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setReenterTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition reenterTransition()
reenterTransition(Transition) or null by
default.public T returnTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setReturnTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition returnTransition()
returnTransition(Transition) or null by
default.public T exitTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setExitTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition exitTransition()
exitTransition(Transition) or null by
default.public T allowEnterTransitionOverlap(boolean allow)
start(Activity) is invoked.Window.setAllowEnterTransitionOverlap(boolean)public boolean allowEnterTransitionOverlap()
True if overlapping of enter transition is enabled, false otherwise.public T allowReturnTransitionOverlap(boolean allow)
start(Activity) is invoked.Window.setAllowReturnTransitionOverlap(boolean)public boolean allowReturnTransitionOverlap()
True if overlapping of return transition is enabled, false otherwise.public T sharedElementEnterTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setSharedElementEnterTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition sharedElementEnterTransition()
sharedElementEnterTransition(Transition)
or null by default.public T sharedElementReenterTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setSharedElementReenterTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition sharedElementReenterTransition()
sharedElementReenterTransition(Transition)
or null by default.public T sharedElementReturnTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setSharedElementReturnTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition sharedElementReturnTransition()
sharedElementReturnTransition(Transition)
or null by default.public T sharedElementExitTransition(android.transition.Transition transition)
start(Activity) is invoked.Window.setSharedElementExitTransition(Transition),
inflateTransition(Context, int)public android.transition.Transition sharedElementExitTransition()
sharedElementExitTransition(Transition)
or null by default.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)
caller - The activity that will be used to create and start an Intent created via
createIntent(Activity).configureTransitionsOverlapping(Activity),
configureTransitions(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.attachTransitions(Window),
attachSharedElementTransitions(Window),
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.public void configureTransitionsOverlapping(android.app.Activity activity)
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)
Window#set...Transition(...) methods.
Note, that for pre LOLLIPOP Android
versions this method does nothing.
activity - The activity to which window should be transitions attached.Window.setEnterTransition(Transition),
Window.setReturnTransition(Transition),
Window.setReenterTransition(Transition),
Window.setExitTransition(Transition),
Window.setSharedElementEnterTransition(Transition),
Window.setSharedElementReturnTransition(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)