-
public abstract class ControllerA Controller manages portions of the UI. It is similar to an Activity or Fragment in that it manages its own lifecycle and controls interactions between the UI and whatever logic is required. It is, however, a much lighter weight component than either Activities or Fragments. While it offers several lifecycle methods, they are much simpler and more predictable than those of Activities and Fragments.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumController.RetainViewModeModes that will influence when the Controller will allow its view to be destroyed
public abstract classController.LifecycleListenerAllows external classes to listen for lifecycle events in a Controller
-
Field Summary
Fields Modifier and Type Field Description private final BundleargsbooleanisBeingDestroyedprivate booleanhasOptionsMenuprivate booleanoptionsMenuHiddenRouterrouterViewviewprivate ControllerparentControllerStringinstanceIdprivate ControllerChangeHandleroverriddenPushHandlerprivate ControllerChangeHandleroverriddenPopHandlerprivate Controller.RetainViewModeretainViewMode
-
Method Summary
Modifier and Type Method Description BundlegetArgs()Returns any arguments that were set in this Controller's constructor final booleanisBeingDestroyed()Returns whether or not this Controller is currently in the process of being destroyed. final voidsetHasOptionsMenu(boolean hasOptionsMenu)Registers/unregisters for participation in populating the options menu by receiving options-relatedcallbacks, such as onCreateOptionsMenu final voidsetOptionsMenuHidden(boolean optionsMenuHidden)Sets whether or not this controller's menu items should be visible. final RoutergetRouter()Returns the Router object that can be used for pushing or popping other Controllers final voidsetRouter(@NonNull() Router router)final ViewgetView()Return this Controller's View or {@code null}if it has not yet been created or has beendestroyed.final ControllergetParentController()Returns this Controller's parent Controller if it is a child Controller or {@code null}ifit has no parent.final voidsetParentController(@Nullable() Controller controller)final StringgetInstanceId()Returns this Controller's instance ID, which is generated when the instance is created andretained across restarts. final ControllerChangeHandlergetOverriddenPushHandler()Returns the ControllerChangeHandler that should be used for pushing this Controller, or nullif the handler from the RouterTransaction should be used instead. ControllerChangeHandlergetOverriddenPopHandler()Returns the ControllerChangeHandler that should be used for popping this Controller, or nullif the handler from the RouterTransaction should be used instead. Controller.RetainViewModegetRetainViewMode()Returns this Controller's RetainViewMode. voidsetRetainViewMode(@NonNull() Controller.RetainViewMode retainViewMode)Sets this Controller's RetainViewMode, which will influence when its view will be released.This is useful when a Controller's view hierarchy is expensive to tear down and rebuild. final RoutergetChildRouter(@NonNull() ViewGroup container)Retrieves the child Router for the given container. final RoutergetChildRouter(@NonNull() ViewGroup container, @Nullable() String tag)Retrieves the child Router for the given container/tag combination. final RoutergetChildRouter(@NonNull() ViewGroup container, @Nullable() String tag, boolean createIfNeeded)Retrieves the child Router for the given container/tag combination. final RoutergetChildRouter(@NonNull() ViewGroup container, @Nullable() String tag, boolean createIfNeeded, boolean boundToHostContainerId)Retrieves the child Router for the given container/tag combination. final voidremoveChildRouter(@NonNull() Router childRouter)Removes a child Router from this Controller. final booleanisDestroyed()Returns whether or not this Controller has been destroyed. final booleanisAttached()Returns whether or not this Controller is currently attached to a host View. final ActivitygetActivity()Returns the host Activity of this Controller's Router or {@code null}if thisController has not yet been attached to an Activity or if the Activity has been destroyed.final ResourcesgetResources()Returns the Resources from the host Activity or {@code null}if this Controller has notyet been attached to an Activity or if the Activity has been destroyed.final ContextgetApplicationContext()Returns the Application Context derived from the host Activity or {@code null}if this Controllerhas not yet been attached to an Activity or if the Activity has been destroyed.voidsetTargetController(@Nullable() Controller target)Optional target for this Controller. final ControllergetTargetController()Returns the target Controller that was set with the setTargetController method or {@code null}if this Controller has no target.final voidstartActivity(@NonNull() Intent intent)Calls startActivity(Intent) from this Controller's host Activity. final voidstartActivityForResult(@NonNull() Intent intent, int requestCode)Calls startActivityForResult(Intent, int) from this Controller's host Activity. final voidstartActivityForResult(@NonNull() Intent intent, int requestCode, @Nullable() Bundle options)Calls startActivityForResult(Intent, int, Bundle) from this Controller's host Activity. final voidstartIntentSenderForResult(@NonNull() IntentSender intent, int requestCode, @Nullable() Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, @Nullable() Bundle options)Calls startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle) from this Controller's host Activity. final voidregisterForActivityResult(int requestCode)Registers this Controller to handle onActivityResult responses. voidonActivityResult(int requestCode, int resultCode, @Nullable() Intent data)Should be overridden if this Controller has called startActivityForResult and needs to handlethe result. final voidrequestPermissions(@NonNull() Array<String> permissions, int requestCode)Calls requestPermission(String[], int) from this Controller's host Activity. booleanshouldShowRequestPermissionRationale(@NonNull() String permission)Gets whether you should show UI with rationale for requesting a permission. voidonRequestPermissionsResult(int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)Should be overridden if this Controller has requested runtime permissions and needs to handle the user's response. booleanhandleBack()Should be overridden if this Controller needs to handle the back button being pressed. final voidaddLifecycleListener(@NonNull() Controller.LifecycleListener lifecycleListener)Adds a listener for all of this Controller's lifecycle events final voidremoveLifecycleListener(@NonNull() Controller.LifecycleListener lifecycleListener)Removes a previously added lifecycle listener voidoverridePushHandler(@Nullable() ControllerChangeHandler overriddenPushHandler)Overrides the ControllerChangeHandler that should be used for pushing this Controller. voidoverridePopHandler(@Nullable() ControllerChangeHandler overriddenPopHandler)Overrides the ControllerChangeHandler that should be used for popping this Controller. voidonCreateOptionsMenu(@NonNull() Menu menu, @NonNull() MenuInflater inflater)Adds option items to the host Activity's standard options menu. voidonPrepareOptionsMenu(@NonNull() Menu menu)Prepare the screen's options menu to be displayed. booleanonOptionsItemSelected(@NonNull() MenuItem item)Called when an option menu item has been selected by the user. -
-
Method Detail
-
getArgs
@NonNull() Bundle getArgs()
Returns any arguments that were set in this Controller's constructor
-
isBeingDestroyed
final boolean isBeingDestroyed()
Returns whether or not this Controller is currently in the process of being destroyed.
-
setHasOptionsMenu
final void setHasOptionsMenu(boolean hasOptionsMenu)
Registers/unregisters for participation in populating the options menu by receiving options-relatedcallbacks, such as onCreateOptionsMenu
- Parameters:
hasOptionsMenu- If true, this controller's options menu callbacks will be called.
-
setOptionsMenuHidden
final void setOptionsMenuHidden(boolean optionsMenuHidden)
Sets whether or not this controller's menu items should be visible. This is useful for hiding thecontroller's options menu items when its UI is hidden, and not just when it is detached from thewindow (the default).
- Parameters:
optionsMenuHidden- Defaults to false.
-
getRouter
final Router getRouter()
Returns the Router object that can be used for pushing or popping other Controllers
-
getView
@Nullable() final View getView()
Return this Controller's View or
{@code null}if it has not yet been created or has beendestroyed.
-
getParentController
@Nullable() final Controller getParentController()
Returns this Controller's parent Controller if it is a child Controller or
{@code null}ifit has no parent.
-
setParentController
final void setParentController(@Nullable() Controller controller)
-
getInstanceId
@NonNull() final String getInstanceId()
Returns this Controller's instance ID, which is generated when the instance is created andretained across restarts.
-
getOverriddenPushHandler
@Nullable() final ControllerChangeHandler getOverriddenPushHandler()
Returns the ControllerChangeHandler that should be used for pushing this Controller, or nullif the handler from the RouterTransaction should be used instead.
-
getOverriddenPopHandler
@Nullable() ControllerChangeHandler getOverriddenPopHandler()
Returns the ControllerChangeHandler that should be used for popping this Controller, or nullif the handler from the RouterTransaction should be used instead.
-
getRetainViewMode
@NonNull() Controller.RetainViewMode getRetainViewMode()
Returns this Controller's RetainViewMode. Defaults to RELEASE_DETACH.
-
setRetainViewMode
void setRetainViewMode(@NonNull() Controller.RetainViewMode retainViewMode)
Sets this Controller's RetainViewMode, which will influence when its view will be released.This is useful when a Controller's view hierarchy is expensive to tear down and rebuild.
-
getChildRouter
@NonNull() final Router getChildRouter(@NonNull() ViewGroup container)
Retrieves the child Router for the given container. If no child router for this containerexists yet, it will be created.
- Parameters:
container- The ViewGroup that hosts the child Router
-
getChildRouter
@NonNull() final Router getChildRouter(@NonNull() ViewGroup container, @Nullable() String tag)
Retrieves the child Router for the given container/tag combination. If no child router forthis container exists yet, it will be created. Note that multiple routers should not existin the same container unless a lot of care is taken to maintain order between them. Avoid usingthe same container unless you have a great reason to do so (ex: ViewPagers).
- Parameters:
container- The ViewGroup that hosts the child Routertag- The router's tag or{@code null}if none is needed
-
getChildRouter
@Nullable() final Router getChildRouter(@NonNull() ViewGroup container, @Nullable() String tag, boolean createIfNeeded)
Retrieves the child Router for the given container/tag combination. Note that multiplerouters should not exist in the same container unless a lot of care is taken to maintain orderbetween them. Avoid using the same container unless you have a great reason to do so (ex: ViewPagers).The only time this method will return
{@code null}is when the child router does not exist priorto calling this method and the createIfNeeded parameter is set to false.- Parameters:
container- The ViewGroup that hosts the child Routertag- The router's tag or{@code null}if none is neededcreateIfNeeded- If true, a router will be created if one does not yet exist.
-
getChildRouter
@Nullable() final Router getChildRouter(@NonNull() ViewGroup container, @Nullable() String tag, boolean createIfNeeded, boolean boundToHostContainerId)
Retrieves the child Router for the given container/tag combination. Note that multiplerouters should not exist in the same container unless a lot of care is taken to maintain orderbetween them. Avoid using the same container unless you have a great reason to do so (ex: ViewPagers).The only time this method will return
{@code null}is when the child router does not exist priorto calling this method and the createIfNeeded parameter is set to false.- Parameters:
container- The ViewGroup that hosts the child Routertag- The router's tag or{@code null}if none is neededcreateIfNeeded- If true, a router will be created if one does not yet exist.boundToHostContainerId- If true, a router will only ever rebind with a container with the same view id on state restoration.
-
removeChildRouter
final void removeChildRouter(@NonNull() Router childRouter)
Removes a child Router from this Controller. When removed, all Controllers currently managed bythe Router will be destroyed.
- Parameters:
childRouter- The router to be removed
-
isDestroyed
final boolean isDestroyed()
Returns whether or not this Controller has been destroyed.
-
isAttached
final boolean isAttached()
Returns whether or not this Controller is currently attached to a host View.
-
getActivity
@Nullable() final Activity getActivity()
Returns the host Activity of this Controller's Router or
{@code null}if thisController has not yet been attached to an Activity or if the Activity has been destroyed.
-
getResources
@Nullable() final Resources getResources()
Returns the Resources from the host Activity or
{@code null}if this Controller has notyet been attached to an Activity or if the Activity has been destroyed.
-
getApplicationContext
@Nullable() final Context getApplicationContext()
Returns the Application Context derived from the host Activity or
{@code null}if this Controllerhas not yet been attached to an Activity or if the Activity has been destroyed.
-
setTargetController
void setTargetController(@Nullable() Controller target)
Optional target for this Controller. One reason this could be used is to send results back to the Controllerthat started this one. Target Controllers are retained across instances. It is recommendedthat Controllers enforce that their target Controller conform to a specific Interface.
- Parameters:
target- The Controller that is the target of this one.
-
getTargetController
@Nullable() final Controller getTargetController()
Returns the target Controller that was set with the setTargetController method or
{@code null}if this Controller has no target.
-
startActivity
final void startActivity(@NonNull() Intent intent)
Calls startActivity(Intent) from this Controller's host Activity.
-
startActivityForResult
final void startActivityForResult(@NonNull() Intent intent, int requestCode)
Calls startActivityForResult(Intent, int) from this Controller's host Activity.
-
startActivityForResult
final void startActivityForResult(@NonNull() Intent intent, int requestCode, @Nullable() Bundle options)
Calls startActivityForResult(Intent, int, Bundle) from this Controller's host Activity.
-
startIntentSenderForResult
final void startIntentSenderForResult(@NonNull() IntentSender intent, int requestCode, @Nullable() Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, @Nullable() Bundle options)
Calls startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle) from this Controller's host Activity.
-
registerForActivityResult
final void registerForActivityResult(int requestCode)
Registers this Controller to handle onActivityResult responses. Calling this method is NOTnecessary when calling startActivityForResult
- Parameters:
requestCode- The request code being registered for.
-
onActivityResult
void onActivityResult(int requestCode, int resultCode, @Nullable() Intent data)
Should be overridden if this Controller has called startActivityForResult and needs to handlethe result.
- Parameters:
requestCode- The requestCode passed to startActivityForResultresultCode- The resultCode that was returned to the host Activity's onActivityResult methoddata- The data Intent that was returned to the host Activity's onActivityResult method
-
requestPermissions
final void requestPermissions(@NonNull() Array<String> permissions, int requestCode)
Calls requestPermission(String[], int) from this Controller's host Activity. Results for this request,including shouldShowRequestPermissionRationale and onRequestPermissionsResult will be forwarded back to this Controller by the system.
-
shouldShowRequestPermissionRationale
boolean shouldShowRequestPermissionRationale(@NonNull() String permission)
Gets whether you should show UI with rationale for requesting a permission. {@see android.app.Activity#shouldShowRequestPermissionRationale(String)}
- Parameters:
permission- A permission this Controller has requested
-
onRequestPermissionsResult
void onRequestPermissionsResult(int requestCode, @NonNull() Array<String> permissions, @NonNull() Array<int> grantResults)
Should be overridden if this Controller has requested runtime permissions and needs to handle the user's response.
- Parameters:
requestCode- The requestCode that was used to request the permissionspermissions- The array of permissions requestedgrantResults- The results for each permission requested
-
handleBack
boolean handleBack()
Should be overridden if this Controller needs to handle the back button being pressed.
-
addLifecycleListener
final void addLifecycleListener(@NonNull() Controller.LifecycleListener lifecycleListener)
Adds a listener for all of this Controller's lifecycle events
- Parameters:
lifecycleListener- The listener
-
removeLifecycleListener
final void removeLifecycleListener(@NonNull() Controller.LifecycleListener lifecycleListener)
Removes a previously added lifecycle listener
- Parameters:
lifecycleListener- The listener to be removed
-
overridePushHandler
void overridePushHandler(@Nullable() ControllerChangeHandler overriddenPushHandler)
Overrides the ControllerChangeHandler that should be used for pushing this Controller. If this is anon-null value, it will be used instead of the handler from the RouterTransaction.
-
overridePopHandler
void overridePopHandler(@Nullable() ControllerChangeHandler overriddenPopHandler)
Overrides the ControllerChangeHandler that should be used for popping this Controller. If this is anon-null value, it will be used instead of the handler from the RouterTransaction.
-
onCreateOptionsMenu
void onCreateOptionsMenu(@NonNull() Menu menu, @NonNull() MenuInflater inflater)
Adds option items to the host Activity's standard options menu. This will only be called if setHasOptionsMenu has been called.
- Parameters:
menu- The menu into which your options should be placed.inflater- The inflater that can be used to inflate your menu items.
-
onPrepareOptionsMenu
void onPrepareOptionsMenu(@NonNull() Menu menu)
Prepare the screen's options menu to be displayed. This is called directly before showing themenu and can be used modify its contents.
- Parameters:
menu- The menu that will be displayed
-
onOptionsItemSelected
boolean onOptionsItemSelected(@NonNull() MenuItem item)
Called when an option menu item has been selected by the user.
- Parameters:
item- The selected item.
-
-
-
-