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 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 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(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(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(Activity activity)
This method groups calls to
configureIncomingTransitions(Activity) and
configureOutgoingTransitions(Activity) into one call. |
Intent |
createIntent(Activity caller)
Creates an intent that can be used to start activity for which is this transition created.
|
Transition |
enterTransition()
Returns enter transition for the incoming activity.
|
T |
enterTransition(Transition transition)
Specifies enter transition to be attached to a window of an incoming activity.
|
Transition |
exitTransition()
Returns exit transition for the outgoing activity.
|
T |
exitTransition(Transition transition)
Specifies exit transition to be attached to a window of an outgoing activity whenever
start(Activity) is invoked. |
void |
finish(Activity caller)
Finishes the given caller activity in order to run its exit transitions.
|
protected void |
finishCaller(Activity caller)
Finishes the specified caller activity either via
Activity.finishAfterTransition()
or via Activity.finish() depending on the current API capabilities. |
protected void |
finishCallerDelayed(Activity caller,
long delay)
Like
finishCaller(Activity) but this will postpone the finishing by the requested
delay. |
Class<? extends Activity> |
getActivityClass()
Returns the class of activity specified for this navigational transition.
|
Transition |
inflateTransition(Context context,
int resource)
Inflates a new instance of Transition from the specified resource.
|
TransitionManager |
inflateTransitionManager(Context context,
int resource,
ViewGroup sceneRoot)
Inflates a new instance of TransitionManager from the specified resource.
|
Bundle |
intentExtras()
Returns the bundle with extras for the incoming activity.
|
T |
intentExtras(Bundle extras)
Specifies a bundle with extras for the incoming activity.
|
ActivityOptions |
makeSceneTransitionAnimation(Activity caller)
Creates a new instance of ActivityOptions for the specified caller activity.
|
protected void |
onFinish(Activity caller)
Invoked whenever
finish(Activity) is called. |
protected void |
onFinishCaller(Activity caller)
Invoked whenever
finishCaller(Activity) or finishCallerDelayed(Activity, long)
is called. |
protected void |
onStart(Activity caller)
Invoked whenever
start(Activity) is called. |
Transition |
reenterTransition()
Returns reenter transition for the outgoing activity.
|
T |
reenterTransition(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.
|
Transition |
returnTransition()
Returns return transition for the incoming activity.
|
T |
returnTransition(Transition transition)
Specifies return transition to be attached to a window of an incoming activity.
|
T |
sharedElement(View element,
String elementName)
Adds shared element that should be transferred to the transitioning (called) activity via
ActivityOptions as Bundle. |
Transition |
sharedElementEnterTransition()
Returns shared element enter transition for the incoming activity.
|
T |
sharedElementEnterTransition(Transition transition)
Specifies enter transition for shared element to be attached to a window of an incoming
activity.
|
Transition |
sharedElementExitTransition()
Returns shared element exit transition for the outgoing activity.
|
T |
sharedElementExitTransition(Transition transition)
Specifies exit transition for shared element to be attached to a window of an outgoing
activity whenever
start(Activity) is invoked. |
Transition |
sharedElementReenterTransition()
Returns shared element reenter transition for the outgoing activity.
|
T |
sharedElementReenterTransition(Transition transition)
Specifies reenter transition for shared element to be attached to a window of an outgoing
activity whenever
start(Activity) is invoked. |
Transition |
sharedElementReturnTransition()
Returns shared element return transition for the incoming activity.
|
T |
sharedElementReturnTransition(Transition transition)
Specifies return transition for shared element to be attached to a window of an incoming
activity.
|
List<Pair<View,String>> |
sharedElements()
Returns a list of all shared elements specified for this navigational transition.
|
T |
sharedElements(Pair<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.
|
Pair<View,String> |
singleSharedElement()
Returns the single shared element at the
0 position among the current shared elements. |
void |
start(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 Activity> mClassOfTransitionActivity
start(Activity).public BaseNavigationalTransition()
public BaseNavigationalTransition(@NonNull Class<? extends 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.@Nullable public final Class<? extends Activity> getActivityClass()
null if not activity class
has been specified.BaseNavigationalTransition(Class)public T intentExtras(@Nullable 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()@NonNull public 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(@Nullable Transition transition)
enterTransition(),
Window.setEnterTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)@Nullable public Transition enterTransition()
enterTransition(Transition) or null by
default.public T reenterTransition(@Nullable Transition transition)
start(Activity) is invoked.reenterTransition(),
Window.setReenterTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)@Nullable public Transition reenterTransition()
reenterTransition(Transition) or null by
default.public T returnTransition(@Nullable Transition transition)
returnTransition(),
Window.setReturnTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)@Nullable public Transition returnTransition()
returnTransition(Transition) or null by
default.public T exitTransition(@Nullable Transition transition)
start(Activity) is invoked.exitTransition(),
Window.setExitTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)@Nullable public Transition exitTransition()
exitTransition(Transition) or null by
default.public T allowEnterTransitionOverlap(boolean allow)
Default value: unspecified
allowEnterTransitionOverlap(),
Window.setAllowEnterTransitionOverlap(boolean),
configureIncomingTransitions(Activity)public boolean allowEnterTransitionOverlap()
This method returns true if overlapping has not been specified, which is a default
behaviour of Window.getAllowEnterTransitionOverlap().
True if overlapping of enter transition is enabled, false otherwise.public T allowReturnTransitionOverlap(boolean allow)
Default value: unspecified
allowReturnTransitionOverlap(),
Window.setAllowReturnTransitionOverlap(boolean),
configureIncomingTransitions(Activity)public boolean allowReturnTransitionOverlap()
This method returns true if overlapping has not been specified, which is a default
behaviour of Window.getAllowReturnTransitionOverlap().
True if overlapping of return transition is enabled, false otherwise.public T sharedElementEnterTransition(@Nullable Transition transition)
sharedElementEnterTransition(),
Window.setSharedElementEnterTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)@Nullable public Transition sharedElementEnterTransition()
sharedElementEnterTransition(Transition)
or null by default.public T sharedElementReenterTransition(@Nullable Transition transition)
start(Activity) is invoked.sharedElementReenterTransition(),
Window.setSharedElementReenterTransition(Transition),
inflateTransition(Context, int),
configureOutgoingTransitions(Activity)@Nullable public Transition sharedElementReenterTransition()
sharedElementReenterTransition(Transition)
or null by default.public T sharedElementReturnTransition(@Nullable Transition transition)
sharedElementReturnTransition(),
Window.setSharedElementReturnTransition(Transition),
inflateTransition(Context, int),
configureIncomingTransitions(Activity)@Nullable public Transition sharedElementReturnTransition()
sharedElementReturnTransition(Transition)
or null by default.public T sharedElementExitTransition(@Nullable Transition transition)
start(Activity) is invoked.sharedElementExitTransition(),
Window.setSharedElementExitTransition(Transition),
inflateTransition(Context, int)@Nullable public Transition sharedElementExitTransition()
sharedElementExitTransition(Transition)
or null by default.public T sharedElementsUseOverlay(boolean useOverlay)
Default value: unspecified
sharedElementsUseOverlay(),
Window.setSharedElementsUseOverlay(boolean),
configureIncomingTransitions(Activity),
configureOutgoingTransitions(Activity)public boolean sharedElementsUseOverlay()
This method returns true if usage of overlay has not been specified, which is a default
behaviour of Window.getSharedElementsUseOverlay().
True if shared elements will use overlay, false otherwise.sharedElementsUseOverlay(boolean)@Nullable public Transition inflateTransition(@NonNull 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)@Nullable public TransitionManager inflateTransitionManager(@NonNull Context context, int resource, @NonNull 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(@NonNull Pair<View,String>... elements)
elements - The desired shared elements pairs.sharedElement(View, String)public T sharedElement(@NonNull View element, @NonNull 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)@Nullable public List<Pair<View,String>> sharedElements()
null if there are no shared elements specified.sharedElements(Pair[]),
sharedElement(View, String),
singleSharedElement()@Nullable public Pair<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(@NonNull Activity caller)
configureOutgoingTransitions(Activity).caller - The activity that will be used to create and start an Intent created via
createIntent(Activity).protected void onStart(@NonNull 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(@NonNull 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(@NonNull Activity caller)
Activity.finishAfterTransition()
or via Activity.finish() depending on the current API capabilities.caller - The caller activity to finish.protected void onFinishCaller(@NonNull 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 configureTransitions(@NonNull Activity activity)
configureIncomingTransitions(Activity) and
configureOutgoingTransitions(Activity) into one call.activity - The activity of which window transitions to configure.public void configureIncomingTransitions(@NonNull 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(@NonNull 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)@Nullable public ActivityOptions makeSceneTransitionAnimation(@NonNull 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.@NonNull public Intent createIntent(@NonNull 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(@NonNull Activity caller)
caller - The activity that should be finished and of which exit transitions should be started.start(Activity)protected void onFinish(@NonNull 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)