Package 

Class Controller


  • 
    public abstract class Controller
    
                        

    A 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.

    • 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.

      • getInstanceId

        @NonNull() final String getInstanceId()

        Returns this Controller's instance ID, which is generated when the instance is created andretained across restarts.

      • 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 Router
        tag - 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 Router
        tag - The router's tag or {@code null} if none is needed
        createIfNeeded - 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 Router
        tag - The router's tag or {@code null} if none is needed
        createIfNeeded - 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.
      • 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.

      • 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 startActivityForResult
        resultCode - The resultCode that was returned to the host Activity's onActivityResult method
        data - The data Intent that was returned to the host Activity's onActivityResult method
      • 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 permissions
        permissions - The array of permissions requested
        grantResults - The results for each permission requested
      • handleBack

         boolean handleBack()

        Should be overridden if this Controller needs to handle the back button being pressed.

      • 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.