public final class

Controller

extends Object
java.lang.Object
   ↳ com.neomades.app.Controller

Class Overview

The controller manages navigation between screens of the application.

Screens can be pushed to the real screen, and popped when they are not needed anymore.

The controller works like a stack, it keeps trace of your screens, so the user can navigate between the screens with the BACK key of the device or BACK button in the title bar for IOS platforms.

Dialogs can also be shown from the controller.

Summary

Public Methods
Screen getCurrent()
Returns the current screen.
Controller getParentController()
Returns the parent navigation controller used in some cases like SlideScreen to manage a stack of screens.
Preferences getPreferences(String name)
Controller getRootController()
Returns the root navigation controller used by the application to manage a stack of screens.
int getScreenCount()
Returns the screen stack size.
Vibrator getVibrator()
void hideDialog()
Hides the current dialog.
void popScreen()
This method removes a screen from the real screen.
void pushScreen(Class screen, ScreenParams parameters)
Pushes a screen to the real screen.
void pushScreen(Class screen)
Pushes a screen to the real screen.
void pushScreen(Class screen, ScreenParams parameters, ScreenResultListener resultListener)
Pushes a screen to the real screen.
void replaceCurrentScreen(Class screen, ScreenParams parameters)
This method replaces the current top screen to the display.
void replaceCurrentScreen(Class screen)
This method replaces the current top screen to the display.
void resetScreenStack(Class screen, ScreenParams parameters)
This method clears the history and pushes only one screen to be displayed with parameters.
void resetScreenStack(Class screen)
This method clears the history and pushes only one screen to be displayed.
void runOnBackgroundThread(Runnable action)
Calls action.run() asynchronously on the Background-Thread.
void runOnUiThread(Runnable action)
Calls action.run() asynchronously on the UI-Thread.
void scheduleService(Class service)
Starts a Service and runs it approximatively every 30 minutes.
void scheduleService(Class service, long interval)
Starts a Service and runs it periodically.
void showBottomSheet(ModalBottomSheet bottomSheet)
Shows a bottom sheet in top of the current screen.
void showDialog(Dialog dialog)
Shows a dialog in top of the current screen.
void startService(Class service)
Starts a Service now and run it once.
void stopService(Class service)
Stops the Service given as parameter.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Screen getCurrent ()

Returns the current screen.

Returns
  • the current screen

public Controller getParentController ()

Returns the parent navigation controller used in some cases like SlideScreen to manage a stack of screens.

Returns
  • the parent navigation controller
See Also

public Preferences getPreferences (String name)

See getPreferences(String).

Same method as Preferences.getPreferences(String).

Parameters
name name of the Preferences object.
Returns
  • the corresponding preferences object

public Controller getRootController ()

Returns the root navigation controller used by the application to manage a stack of screens.

Returns
  • the root navigation controller

public int getScreenCount ()

Returns the screen stack size.

Returns
  • the number of Screen in this controller stack.

public Vibrator getVibrator ()

See Vibrator.getVibrator() .

Same method as Vibrator.getVibrator().

Returns
  • the current device vibrator.

public void hideDialog ()

Hides the current dialog.

Warning : this method has to be called from the UI-Thread. Use runOnUiThread(Runnable) if you are on another thread

Throws
CrossThreadException if the method is called from outside the UI-Thread

public void popScreen ()

This method removes a screen from the real screen.

If another screen is already present in the internal stack of screens, the current screen is popped, and the previous screen is set to the real screen.

If the popScreen() method is called and no screen is present into the stack, the application will exit in some platforms (all but iOS)

public void pushScreen (Class screen, ScreenParams parameters)

Pushes a screen to the real screen.

This method takes the class given in parameter, constructs a new instance of it, and call onCreate() on it. This method pushes the screen on an internal stack, so that if popScreen is called, the previous screen is set back to the real screen.

Same method as pushScreen(Class, ScreenParams, null).

Parameters
screen the type of screen to be built and pushed with additional information
parameters additional information given to the pushed screen

public void pushScreen (Class screen)

Pushes a screen to the real screen.

This method takes the class given in parameter, constructs a new instance of it, and call onCreate() on it. This method pushes the screen on an internal stack, so that if popScreen is called, the previous screen is set back to the real screen.

Same method as pushScreen(Class, null, null).

Parameters
screen the type of screen to be built and pushed

public void pushScreen (Class screen, ScreenParams parameters, ScreenResultListener resultListener)

Pushes a screen to the real screen.

This method takes the class given in parameter, constructs a new instance of it, and call onCreate() on it. This method pushes the screen on an internal stack, so that if popScreen is called, the previous screen is set back to the real screen.

Parameters
screen the type of screen to be built and pushed with additional information
parameters additional information given to the pushed screen
resultListener screen which waiting for a result from the pushed screen

public void replaceCurrentScreen (Class screen, ScreenParams parameters)

This method replaces the current top screen to the display.

The difference with pushScreen(Class) is that the history will replace the old current screen.

If the method is called when no screen is present into the stack, then the method will do exactly the same thing as pushScreen(Class, ScreenParams) method.

Parameters
screen the screen to be built and displayed.
parameters additional information given to the pushed screen

public void replaceCurrentScreen (Class screen)

This method replaces the current top screen to the display.

The difference with pushScreen(Class) is that the history will replace the old current screen.

If the method is called when no screen is present into the stack, then the method will do exactly the same thing as pushScreen(Class) method.

Parameters
screen the screen to be built and displayed.

public void resetScreenStack (Class screen, ScreenParams parameters)

This method clears the history and pushes only one screen to be displayed with parameters.

If the method is called when no screen is present into the stack, then the method will do exactly the same thing as pushScreen(Class, ScreenParams) method.

Parameters
screen the screen to be built and displayed.
parameters additional information given to the pushed screen

public void resetScreenStack (Class screen)

This method clears the history and pushes only one screen to be displayed.

If the method is called when no screen is present into the stack, then the method will do exactly the same thing as pushScreen(Class) method.

Parameters
screen the screen to be built and displayed.

public void runOnBackgroundThread (Runnable action)

Calls action.run() asynchronously on the Background-Thread. This method should be used when an application needs to do long operation or non-UI operation.

Parameters
action the action to run

public void runOnUiThread (Runnable action)

Calls action.run() asynchronously on the UI-Thread. This method should be used when an application thread needs to update the GUI.

If already on the UI-Thread, the Runnable is run immediately.

Parameters
action the action to run

public void scheduleService (Class service)

Starts a Service and runs it approximatively every 30 minutes. The time interval may vary depending on the platform.

This function will throw SecurityException if you do not have permission to start the given service. The service class should be declared in the URS file.

Parameters
service the service to run

public void scheduleService (Class service, long interval)

Starts a Service and runs it periodically.

The time interval can be specified directly in millisecond but prefer to use INTERVAL_MINUTE, INTERVAL_30_MINUTES, INTERVAL_HOUR or INTERVAL_DAY. If the time interval is too short (less than several minutes), the system will try to respect it as much as possible but if it can't it will apply its own period. In all cases, the period is not exact and the service execution may sometimes be delayed for several minutes.

This function will throw SecurityException if you do not have permission to start the given service. The service class should be declared in the URS file.

Limitations

In iOS, the service will not be stopped after the application is paused or killed however it is the iOS system that will decide when the service fires, whatever is the schedule time.

In Android, the minimum schedule interval is 15 minutes. If less, the interval will be set to 15 minutes.

Parameters
service the service to run
interval period interval in millisecond

public void showBottomSheet (ModalBottomSheet bottomSheet)

Shows a bottom sheet in top of the current screen.

Warning : this method has to be called from the UI-Thread. Use runOnUiThread(Runnable) if you are on another thread

When a bottom sheet is shown, the screen behind it will keep its state (not paused, not resumed).

Parameters
bottomSheet the sheet to show
Throws
CrossThreadException if the method is called from outside the UI-Thread
See Also

public void showDialog (Dialog dialog)

Shows a dialog in top of the current screen.

Warning : this method has to be called from the UI-Thread. Use runOnUiThread(Runnable) if you are on another thread

When a dialog is shown, the screen behind it will keep its state (not paused, not resumed).

Parameters
dialog the popup to show
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void startService (Class service)

Starts a Service now and run it once. A little delay of a few second may be observed before the service is executed.

This function will throw SecurityException if you do not have permission to start the given service. The service class should be declared in the URS file.

Parameters
service the service to start

public void stopService (Class service)

Stops the Service given as parameter.

Parameters
service the service to stop