public abstract class Controller
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Controller.LifecycleListener
Allows external classes to listen for lifecycle events in a Controller
|
static class |
Controller.RetainViewMode
Modes that will influence when the Controller will allow its view to be destroyed
|
| Modifier | Constructor and Description |
|---|---|
protected |
Controller()
Convenience constructor for use when no arguments are needed.
|
protected |
Controller(android.os.Bundle args)
Constructor that takes arguments that need to be retained across restarts.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLifecycleListener(Controller.LifecycleListener lifecycleListener)
Adds a listener for all of this Controller's lifecycle events
|
android.app.Activity |
getActivity()
Returns the host Activity of this Controller's
Router or null if this
Controller has not yet been attached to an Activity or if the Activity has been destroyed. |
android.content.Context |
getApplicationContext()
Returns the Application Context derived from the host Activity or
null if this Controller
has not yet been attached to an Activity or if the Activity has been destroyed. |
android.os.Bundle |
getArgs()
Returns any arguments that were set in this Controller's constructor
|
Router |
getChildRouter(android.view.ViewGroup container)
Retrieves the child
Router for the given container. |
Router |
getChildRouter(android.view.ViewGroup container,
java.lang.String tag)
Retrieves the child
Router for the given container/tag combination. |
Router |
getChildRouter(android.view.ViewGroup container,
java.lang.String tag,
boolean createIfNeeded)
Retrieves the child
Router for the given container/tag combination. |
java.util.List<Router> |
getChildRouters()
Returns all of this Controller's child Routers
|
java.lang.String |
getInstanceId()
Returns this Controller's instance ID, which is generated when the instance is created and
retained across restarts.
|
ControllerChangeHandler |
getOverriddenPopHandler()
Returns the
ControllerChangeHandler that should be used for popping this Controller, or null
if the handler from the RouterTransaction should be used instead. |
ControllerChangeHandler |
getOverriddenPushHandler()
Returns the
ControllerChangeHandler that should be used for pushing this Controller, or null
if the handler from the RouterTransaction should be used instead. |
Controller |
getParentController()
Returns this Controller's parent Controller if it is a child Controller or
null if
it has no parent. |
android.content.res.Resources |
getResources()
Returns the Resources from the host Activity or
null if this Controller has not
yet been attached to an Activity or if the Activity has been destroyed. |
Controller.RetainViewMode |
getRetainViewMode()
Returns this Controller's
Controller.RetainViewMode. |
Router |
getRouter()
Returns the
Router object that can be used for pushing or popping other Controllers |
Controller |
getTargetController()
Returns the target Controller that was set with the
setTargetController(Controller)
method or null if this Controller has no target. |
android.view.View |
getView()
Return this Controller's View or
null if it has not yet been created or has been
destroyed. |
boolean |
handleBack()
Should be overridden if this Controller needs to handle the back button being pressed.
|
boolean |
isAttached()
Returns whether or not this Controller is currently attached to a host View.
|
boolean |
isBeingDestroyed()
Returns whether or not this Controller is currently in the process of being destroyed.
|
boolean |
isDestroyed()
Returns whether or not this Controller has been destroyed.
|
protected void |
onActivityPaused(android.app.Activity activity)
Called when this Controller's host Activity is paused
|
void |
onActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
Should be overridden if this Controller has called startActivityForResult and needs to handle
the result.
|
protected void |
onActivityResumed(android.app.Activity activity)
Called when this Controller's host Activity is resumed
|
protected void |
onActivityStarted(android.app.Activity activity)
Called when this Controller's host Activity is started
|
protected void |
onActivityStopped(android.app.Activity activity)
Called when this Controller's host Activity is stopped
|
protected void |
onAttach(android.view.View view)
Called when this Controller is attached to its host ViewGroup
|
protected void |
onChangeEnded(ControllerChangeHandler changeHandler,
ControllerChangeType changeType)
Called when this Controller completes the process of being swapped in or out of the host view.
|
protected void |
onChangeStarted(ControllerChangeHandler changeHandler,
ControllerChangeType changeType)
Called when this Controller begins the process of being swapped in or out of the host view.
|
protected void |
onContextAvailable(android.content.Context context)
Called when this Controller has a Context available to it.
|
protected void |
onContextUnavailable()
Called when this Controller's Context is no longer available.
|
void |
onCreateOptionsMenu(android.view.Menu menu,
android.view.MenuInflater inflater)
Adds option items to the host Activity's standard options menu.
|
protected abstract android.view.View |
onCreateView(android.view.LayoutInflater inflater,
android.view.ViewGroup container)
Called when the controller is ready to display its view.
|
protected void |
onDestroy()
Called when this Controller has been destroyed.
|
protected void |
onDestroyView(android.view.View view)
Called when this Controller's View is being destroyed.
|
protected void |
onDetach(android.view.View view)
Called when this Controller is detached from its host ViewGroup
|
boolean |
onOptionsItemSelected(android.view.MenuItem item)
Called when an option menu item has been selected by the user.
|
void |
onPrepareOptionsMenu(android.view.Menu menu)
Prepare the screen's options menu to be displayed.
|
void |
onRequestPermissionsResult(int requestCode,
java.lang.String[] permissions,
int[] grantResults)
Should be overridden if this Controller has requested runtime permissions and needs to handle the user's response.
|
protected void |
onRestoreInstanceState(android.os.Bundle savedInstanceState)
Restores data that was saved in the
onSaveInstanceState(Bundle) method. |
protected void |
onRestoreViewState(android.view.View view,
android.os.Bundle savedViewState)
Restores data that was saved in the
onSaveViewState(View, Bundle) method. |
protected void |
onSaveInstanceState(android.os.Bundle outState)
Called to save this Controller's state in the event that its host Activity is destroyed.
|
protected void |
onSaveViewState(android.view.View view,
android.os.Bundle outState)
Called to save this Controller's View state.
|
void |
overridePopHandler(ControllerChangeHandler overriddenPopHandler)
Overrides the
ControllerChangeHandler that should be used for popping this Controller. |
void |
overridePushHandler(ControllerChangeHandler overriddenPushHandler)
Overrides the
ControllerChangeHandler that should be used for pushing this Controller. |
void |
registerForActivityResult(int requestCode)
Registers this Controller to handle onActivityResult responses.
|
void |
removeChildRouter(Router childRouter)
Removes a child
Router from this Controller. |
void |
removeLifecycleListener(Controller.LifecycleListener lifecycleListener)
Removes a previously added lifecycle listener
|
void |
requestPermissions(java.lang.String[] permissions,
int requestCode)
Calls requestPermission(String[], int) from this Controller's host Activity.
|
void |
setHasOptionsMenu(boolean hasOptionsMenu)
Registers/unregisters for participation in populating the options menu by receiving options-related
callbacks, such as
onCreateOptionsMenu(Menu, MenuInflater) |
void |
setOptionsMenuHidden(boolean optionsMenuHidden)
Sets whether or not this controller's menu items should be visible.
|
void |
setRetainViewMode(Controller.RetainViewMode retainViewMode)
Sets this Controller's
Controller.RetainViewMode, which will influence when its view will be released. |
void |
setTargetController(Controller target)
Optional target for this Controller.
|
boolean |
shouldShowRequestPermissionRationale(java.lang.String permission)
Gets whether you should show UI with rationale for requesting a permission.
|
void |
startActivity(android.content.Intent intent)
Calls startActivity(Intent) from this Controller's host Activity.
|
void |
startActivityForResult(android.content.Intent intent,
int requestCode)
Calls startActivityForResult(Intent, int) from this Controller's host Activity.
|
void |
startActivityForResult(android.content.Intent intent,
int requestCode,
android.os.Bundle options)
Calls startActivityForResult(Intent, int, Bundle) from this Controller's host Activity.
|
void |
startIntentSenderForResult(android.content.IntentSender intent,
int requestCode,
android.content.Intent fillInIntent,
int flagsMask,
int flagsValues,
int extraFlags,
android.os.Bundle options)
Calls startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle) from this Controller's host Activity.
|
protected Controller()
protected Controller(android.os.Bundle args)
args - Any arguments that need to be retained.protected abstract android.view.View onCreateView(android.view.LayoutInflater inflater,
android.view.ViewGroup container)
return inflater.inflate(R.layout.my_layout, container, false);, plus
any binding code.inflater - The LayoutInflater that should be used to inflate viewscontainer - The parent view that this Controller's view will eventually be attached to.
This Controller's view should NOT be added in this method. It is simply passed in
so that valid LayoutParams can be used during inflation.public final Router getRouter()
Router object that can be used for pushing or popping other Controllerspublic android.os.Bundle getArgs()
public final Router getChildRouter(android.view.ViewGroup container)
Router for the given container. If no child router for this container
exists yet, it will be created.container - The ViewGroup that hosts the child Routerpublic final Router getChildRouter(android.view.ViewGroup container, java.lang.String tag)
Router for the given container/tag combination. If no child router for
this container exists yet, it will be created. Note that multiple routers should not exist
in the same container unless a lot of care is taken to maintain order between them. Avoid using
the same container unless you have a great reason to do so (ex: ViewPagers).container - The ViewGroup that hosts the child Routertag - The router's tag or null if none is neededpublic final Router getChildRouter(android.view.ViewGroup container, java.lang.String tag, boolean createIfNeeded)
Router for the given container/tag combination. Note that multiple
routers should not exist in the same container unless a lot of care is taken to maintain order
between them. Avoid using the same container unless you have a great reason to do so (ex: ViewPagers).
The only time this method will return null is when the child router does not exist prior
to calling this method and the createIfNeeded parameter is set to false.container - The ViewGroup that hosts the child Routertag - The router's tag or null if none is neededcreateIfNeeded - If true, a router will be created if one does not yet exist. Else null will be returned in this case.public final void removeChildRouter(Router childRouter)
Router from this Controller. When removed, all Controllers currently managed by
the Router will be destroyed.childRouter - The router to be removedpublic final boolean isDestroyed()
public final boolean isBeingDestroyed()
public final boolean isAttached()
public final android.view.View getView()
null if it has not yet been created or has been
destroyed.public final android.app.Activity getActivity()
Router or null if this
Controller has not yet been attached to an Activity or if the Activity has been destroyed.public final android.content.res.Resources getResources()
null if this Controller has not
yet been attached to an Activity or if the Activity has been destroyed.public final android.content.Context getApplicationContext()
null if this Controller
has not yet been attached to an Activity or if the Activity has been destroyed.public final Controller getParentController()
null if
it has no parent.public final java.lang.String getInstanceId()
public final java.util.List<Router> getChildRouters()
public void setTargetController(Controller target)
target - The Controller that is the target of this one.public final Controller getTargetController()
setTargetController(Controller)
method or null if this Controller has no target.protected void onDestroyView(android.view.View view)
view - The View to which this Controller should be bound.protected void onChangeStarted(ControllerChangeHandler changeHandler, ControllerChangeType changeType)
changeHandler - The ControllerChangeHandler that's managing the swapchangeType - The type of change that's occurringprotected void onChangeEnded(ControllerChangeHandler changeHandler, ControllerChangeType changeType)
changeHandler - The ControllerChangeHandler that's managing the swapchangeType - The type of change that occurredprotected void onContextAvailable(android.content.Context context)
protected void onContextUnavailable()
protected void onAttach(android.view.View view)
view - The View for this Controller (passed for convenience)protected void onDetach(android.view.View view)
view - The View for this Controller (passed for convenience)protected void onDestroy()
protected void onActivityStarted(android.app.Activity activity)
protected void onActivityResumed(android.app.Activity activity)
protected void onActivityPaused(android.app.Activity activity)
protected void onActivityStopped(android.app.Activity activity)
protected void onSaveViewState(android.view.View view,
android.os.Bundle outState)
view - This Controller's View, passed for convenienceoutState - The Bundle into which the View state should be savedprotected void onRestoreViewState(android.view.View view,
android.os.Bundle savedViewState)
onSaveViewState(View, Bundle) method. This should be overridden
to restore the View's state to where it was before it was destroyed.view - This Controller's View, passed for conveniencesavedViewState - The bundle that has data to be restoredprotected void onSaveInstanceState(android.os.Bundle outState)
outState - The Bundle into which data should be savedprotected void onRestoreInstanceState(android.os.Bundle savedInstanceState)
onSaveInstanceState(Bundle) method. This should be overridden
to restore this Controller's state to where it was before it was destroyed.savedInstanceState - The bundle that has data to be restoredpublic final void startActivity(android.content.Intent intent)
public final void startActivityForResult(android.content.Intent intent,
int requestCode)
public final void startActivityForResult(android.content.Intent intent,
int requestCode,
android.os.Bundle options)
public final void startIntentSenderForResult(android.content.IntentSender intent,
int requestCode,
android.content.Intent fillInIntent,
int flagsMask,
int flagsValues,
int extraFlags,
android.os.Bundle options)
throws android.content.IntentSender.SendIntentException
android.content.IntentSender.SendIntentExceptionpublic final void registerForActivityResult(int requestCode)
startActivityForResult(Intent, int)requestCode - The request code being registered for.public void onActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
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 methodpublic final void requestPermissions(java.lang.String[] permissions,
int requestCode)
shouldShowRequestPermissionRationale(String) and
onRequestPermissionsResult(int, String[], int[]) will be forwarded back to this Controller by the system.public boolean shouldShowRequestPermissionRationale(java.lang.String permission)
Activity.shouldShowRequestPermissionRationale(String)permission - A permission this Controller has requestedpublic void onRequestPermissionsResult(int requestCode,
java.lang.String[] permissions,
int[] grantResults)
requestCode - The requestCode that was used to request the permissionspermissions - The array of permissions requestedgrantResults - The results for each permission requestedpublic boolean handleBack()
public final void addLifecycleListener(Controller.LifecycleListener lifecycleListener)
lifecycleListener - The listenerpublic final void removeLifecycleListener(Controller.LifecycleListener lifecycleListener)
lifecycleListener - The listener to be removedpublic Controller.RetainViewMode getRetainViewMode()
Controller.RetainViewMode. Defaults to Controller.RetainViewMode.RELEASE_DETACH.public void setRetainViewMode(Controller.RetainViewMode retainViewMode)
Controller.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.public final ControllerChangeHandler getOverriddenPushHandler()
ControllerChangeHandler that should be used for pushing this Controller, or null
if the handler from the RouterTransaction should be used instead.public void overridePushHandler(ControllerChangeHandler overriddenPushHandler)
ControllerChangeHandler that should be used for pushing this Controller. If this is a
non-null value, it will be used instead of the handler from the RouterTransaction.public ControllerChangeHandler getOverriddenPopHandler()
ControllerChangeHandler that should be used for popping this Controller, or null
if the handler from the RouterTransaction should be used instead.public void overridePopHandler(ControllerChangeHandler overriddenPopHandler)
ControllerChangeHandler that should be used for popping this Controller. If this is a
non-null value, it will be used instead of the handler from the RouterTransaction.public final void setHasOptionsMenu(boolean hasOptionsMenu)
onCreateOptionsMenu(Menu, MenuInflater)hasOptionsMenu - If true, this controller's options menu callbacks will be called.public final void setOptionsMenuHidden(boolean optionsMenuHidden)
optionsMenuHidden - Defaults to false. If true, this controller's menu items will not be shown.public void onCreateOptionsMenu(android.view.Menu menu,
android.view.MenuInflater inflater)
setHasOptionsMenu(boolean) has been called.menu - The menu into which your options should be placed.inflater - The inflater that can be used to inflate your menu items.public void onPrepareOptionsMenu(android.view.Menu menu)
menu - The menu that will be displayedpublic boolean onOptionsItemSelected(android.view.MenuItem item)
item - The selected item.