-
public abstract class RouterA Router implements navigation and backstack handling for Controllers. Router objects are attached to Activity/containing ViewGroup pairs. Routers do not directly render or push Views to the container ViewGroup, but instead defer this responsibility to the ControllerChangeHandler specified in a given transaction.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumRouter.PopRootControllerModeDefines the way a Router will handle back button or pop events when there is only one controllerleft in the backstack.
-
Field Summary
Fields Modifier and Type Field Description final Backstackbackstackprivate Router.PopRootControllerModepopRootControllerMode
-
Method Summary
Modifier and Type Method Description voidsetBackstack(@NonNull() List<RouterTransaction> newBackstack, @Nullable() ControllerChangeHandler changeHandler)Sets the backstack, transitioning from the current top controller to the top of the new stack (if different)using the passed ControllerChangeHandler RoutersetPopRootControllerMode(@NonNull() Router.PopRootControllerMode popRootControllerMode)Sets the method this router will use to handle back presses when there is only one controller left in the backstack.Defaults to POP_ROOT_CONTROLLER_LEAVING_VIEW so that the developer can either finish its containing Activity orotherwise hide its parent view without any strange artifacting. abstract ActivitygetActivity()Returns this Router's host Activity or {@code null}if it has either not yet been attached toan Activity or if the Activity has been destroyed.abstract voidonActivityResult(int requestCode, int resultCode, @Nullable() Intent data)This should be called by the host Activity when its onActivityResult method is called if the instanceIdof the controller that called startActivityForResult is not known. voidonRequestPermissionsResult(@NonNull() String instanceId, int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)This should be called by the host Activity when its onRequestPermissionsResult method is called. booleanhandleBack()This should be called by the host Activity when its onBackPressed method is called. booleanpopCurrentController()Pops the top Controller from the backstack booleanpopController(@NonNull() Controller controller)Pops the passed Controller from the backstack voidpushController(@NonNull() RouterTransaction transaction)Pushes a new Controller to the backstack voidreplaceTopController(@NonNull() RouterTransaction transaction)Replaces this Router's top Controller with a new Controller intgetContainerId()RoutersetPopsLastView(boolean popsLastView)If set to true, this router will handle back presses by performing a change handler on the last controller and viewin the stack. booleanpopToRoot()Pops all Controllers until only the root is left booleanpopToRoot(@Nullable() ControllerChangeHandler changeHandler)Pops all Controller until only the root is left booleanpopToTag(@NonNull() String tag)Pops all Controllers until the Controller with the passed tag is at the top booleanpopToTag(@NonNull() String tag, @Nullable() ControllerChangeHandler changeHandler)Pops all Controllers until the Controller with the passed tag is at the top voidsetRoot(@NonNull() RouterTransaction transaction)Sets the root Controller. ControllergetControllerWithInstanceId(@NonNull() String instanceId)Returns the hosted Controller with the given instance id or {@code null}if no suchController exists in this Router.ControllergetControllerWithTag(@NonNull() String tag)Returns the hosted Controller that was pushed with the given tag or {@code null}if nosuch Controller exists in this Router.intgetBackstackSize()Returns the number of Controllers currently in the backstack booleanhasRootController()Returns whether or not this Router has a root Controller voidaddChangeListener(@NonNull() ControllerChangeHandler.ControllerChangeListener changeListener)Adds a listener for all of this Router's Controller change events voidremoveChangeListener(@NonNull() ControllerChangeHandler.ControllerChangeListener changeListener)Removes a previously added listener voidrebindIfNeeded()Attaches this Router's existing backstack to its container if one exists. final voidonActivityResult(@NonNull() String instanceId, int requestCode, int resultCode, @Nullable() Intent data)final voidonActivityStarted(@NonNull() Activity activity)final voidonActivityResumed(@NonNull() Activity activity)final voidonActivityPaused(@NonNull() Activity activity)final voidonActivityStopped(@NonNull() Activity activity)voidonActivityDestroyed(@NonNull() Activity activity, boolean isConfigurationChange)voidprepareForHostDetach()voidsaveInstanceState(@NonNull() Bundle outState)voidrestoreInstanceState(@NonNull() Bundle savedInstanceState)final voidonCreateOptionsMenu(@NonNull() Menu menu, @NonNull() MenuInflater inflater)final voidonPrepareOptionsMenu(@NonNull() Menu menu)final booleanonOptionsItemSelected(@NonNull() MenuItem item)final BooleanhandleRequestedPermission(@NonNull() String permission)-
-
Method Detail
-
setBackstack
@UiThread() void setBackstack(@NonNull() List<RouterTransaction> newBackstack, @Nullable() ControllerChangeHandler changeHandler)
Sets the backstack, transitioning from the current top controller to the top of the new stack (if different)using the passed ControllerChangeHandler
- Parameters:
newBackstack- The new backstackchangeHandler- An optional change handler to be used to handle the root view of transition
-
setPopRootControllerMode
@NonNull() Router setPopRootControllerMode(@NonNull() Router.PopRootControllerMode popRootControllerMode)
Sets the method this router will use to handle back presses when there is only one controller left in the backstack.Defaults to POP_ROOT_CONTROLLER_LEAVING_VIEW so that the developer can either finish its containing Activity orotherwise hide its parent view without any strange artifacting.
-
getActivity
@Nullable() abstract Activity getActivity()
Returns this Router's host Activity or
{@code null}if it has either not yet been attached toan Activity or if the Activity has been destroyed.
-
onActivityResult
abstract void onActivityResult(int requestCode, int resultCode, @Nullable() Intent data)
This should be called by the host Activity when its onActivityResult method is called if the instanceIdof the controller that called startActivityForResult is not known.
- Parameters:
requestCode- The Activity's onActivityResult requestCoderesultCode- The Activity's onActivityResult resultCodedata- The Activity's onActivityResult data
-
onRequestPermissionsResult
void onRequestPermissionsResult(@NonNull() String instanceId, int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)
This should be called by the host Activity when its onRequestPermissionsResult method is called. The call will be forwardedto the Controller with the instanceId passed in.
- Parameters:
instanceId- The instanceId of the Controller to which this result should be forwardedrequestCode- The Activity's onRequestPermissionsResult requestCodepermissions- The Activity's onRequestPermissionsResult permissionsgrantResults- The Activity's onRequestPermissionsResult grantResults
-
handleBack
@UiThread() boolean handleBack()
This should be called by the host Activity when its onBackPressed method is called. The call will be forwardedto its top Controller. If that controller doesn't handle it, then it will be popped.
-
popCurrentController
@UiThread() boolean popCurrentController()
Pops the top Controller from the backstack
-
popController
@UiThread() boolean popController(@NonNull() Controller controller)
Pops the passed Controller from the backstack
- Parameters:
controller- The controller that should be popped from this Router
-
pushController
@UiThread() void pushController(@NonNull() RouterTransaction transaction)
Pushes a new Controller to the backstack
- Parameters:
transaction- The transaction detailing what should be pushed, including the Controller,and its push and pop ControllerChangeHandler, and its tag.
-
replaceTopController
@UiThread() void replaceTopController(@NonNull() RouterTransaction transaction)
Replaces this Router's top Controller with a new Controller
- Parameters:
transaction- The transaction detailing what should be pushed, including the Controller,and its push and pop ControllerChangeHandler, and its tag.
-
getContainerId
int getContainerId()
-
setPopsLastView
@NonNull()@Deprecated() Router setPopsLastView(boolean popsLastView)
If set to true, this router will handle back presses by performing a change handler on the last controller and viewin the stack. This defaults to false so that the developer can either finish its containing Activity or otherwisehide its parent view without any strange artifacting.Note: This method has been deprecated and should be replaced with setPopRootControllerMode.
-
popToRoot
@UiThread() boolean popToRoot()
Pops all Controllers until only the root is left
-
popToRoot
@UiThread() boolean popToRoot(@Nullable() ControllerChangeHandler changeHandler)
Pops all Controller until only the root is left
- Parameters:
changeHandler- The ControllerChangeHandler to handle this transaction
-
popToTag
@UiThread() boolean popToTag(@NonNull() String tag)
Pops all Controllers until the Controller with the passed tag is at the top
- Parameters:
tag- The tag being popped to
-
popToTag
@UiThread() boolean popToTag(@NonNull() String tag, @Nullable() ControllerChangeHandler changeHandler)
Pops all Controllers until the Controller with the passed tag is at the top
- Parameters:
tag- The tag being popped tochangeHandler- The ControllerChangeHandler to handle this transaction
-
setRoot
@UiThread() void setRoot(@NonNull() RouterTransaction transaction)
Sets the root Controller. If any Controllers are currently in the backstack, they will be removed.
- Parameters:
transaction- The transaction detailing what should be pushed, including the Controller,and its push and pop ControllerChangeHandler, and its tag.
-
getControllerWithInstanceId
@Nullable() Controller getControllerWithInstanceId(@NonNull() String instanceId)
Returns the hosted Controller with the given instance id or
{@code null}if no suchController exists in this Router.- Parameters:
instanceId- The instance ID being searched for
-
getControllerWithTag
@Nullable() Controller getControllerWithTag(@NonNull() String tag)
Returns the hosted Controller that was pushed with the given tag or
{@code null}if nosuch Controller exists in this Router.- Parameters:
tag- The tag being searched for
-
getBackstackSize
int getBackstackSize()
Returns the number of Controllers currently in the backstack
-
hasRootController
boolean hasRootController()
Returns whether or not this Router has a root Controller
-
addChangeListener
void addChangeListener(@NonNull() ControllerChangeHandler.ControllerChangeListener changeListener)
Adds a listener for all of this Router's Controller change events
- Parameters:
changeListener- The listener
-
removeChangeListener
void removeChangeListener(@NonNull() ControllerChangeHandler.ControllerChangeListener changeListener)
Removes a previously added listener
- Parameters:
changeListener- The listener to be removed
-
rebindIfNeeded
@UiThread() void rebindIfNeeded()
Attaches this Router's existing backstack to its container if one exists.
-
onActivityResult
final void onActivityResult(@NonNull() String instanceId, int requestCode, int resultCode, @Nullable() Intent data)
-
onActivityStarted
final void onActivityStarted(@NonNull() Activity activity)
-
onActivityResumed
final void onActivityResumed(@NonNull() Activity activity)
-
onActivityPaused
final void onActivityPaused(@NonNull() Activity activity)
-
onActivityStopped
final void onActivityStopped(@NonNull() Activity activity)
-
onActivityDestroyed
void onActivityDestroyed(@NonNull() Activity activity, boolean isConfigurationChange)
-
prepareForHostDetach
void prepareForHostDetach()
-
saveInstanceState
void saveInstanceState(@NonNull() Bundle outState)
-
restoreInstanceState
void restoreInstanceState(@NonNull() Bundle savedInstanceState)
-
onCreateOptionsMenu
final void onCreateOptionsMenu(@NonNull() Menu menu, @NonNull() MenuInflater inflater)
-
onPrepareOptionsMenu
final void onPrepareOptionsMenu(@NonNull() Menu menu)
-
onOptionsItemSelected
final boolean onOptionsItemSelected(@NonNull() MenuItem item)
-
handleRequestedPermission
@Nullable() final Boolean handleRequestedPermission(@NonNull() String permission)
-
-
-
-