public abstract class

Application

extends Object
implements Orientation
java.lang.Object
   ↳ com.neomades.app.Application

Class Overview

Inherit that class to set the entry point of the application.

Entry point

By overriding the onStart(Controller) method, the application says what screen should be pushed on start.

For example, an application which wants to show a Splash screen :

 public class MyApplication extends Application {
 	public void onStart(Controller controller) {
 		controller.pushScreen(SplashScreen.class);
 	}
 }
 

Life cycle

Each NeoMAD application has single instance of Application.

Summary

Constants
int PROXIMITY_ENTER_REGION Key indicating that the terminal is entering a proximity region.
int PROXIMITY_EXIT_REGION Key indicating that the terminal is exiting a proximity region.
int PUSH_FAILURE The registration has failed.
int PUSH_REGISTERED The device is registered in the OS Push Notification server.
int PUSH_SERVICE_CHANGED_ID The registration has changed the device registration unique Identifier.
int PUSH_UNREGISTERED The device has been unregistered from the server.
int THEME_DARK Black or Dark theme
int THEME_LIGHT White or Light theme
[Expand]
Inherited Constants
From interface com.neomades.app.Orientation
Fields
protected final Controller controller
Public Constructors
Application()
Do not override this constructor.
Public Methods
void exit()
Try or Ask to exit the application.
ContentManager getContentManager()
Gets the registered content manager.
static Application getCurrent()
Returns the current instance of the application.
EventBus getEventBus()
String getName()
Returns the Application name.
String getPackageName()
Returns the main package name of the application.
final boolean isActivated()
final boolean isBackground()
boolean isCreated()
Returns if the Application has been created.
final boolean isDeactivated()
final boolean isForeground()
boolean isStarted()
Returns if the Application has started and should be ready to show to a screen
void openURL(String url)
Attempts to open the resource at the specified URL.
void registerContentManager(ContentManager manager)
void setApplicationDelegate(ApplicationDelegate delegate)
Sets a specific application delegate.
void setBadgeNumber(int number)
Sets the badge number displayed over the application icon (iOS)
void startVoiceCall(String phoneNumber)
Starts a voice call to a phone number.
void unregisterContentManager(ContentManager manager)
Protected Methods
final Controller getController()
void onActivated()
Called when the application will be activated (after onStart(Controller)).
void onBackground()
Called when the application goes in background.
boolean onBeforeExit(Controller controller)
Override this method to provide a behavior when the application is about to exit.
void onCreate(Controller controller)
Called before onStart(Controller) method.
void onDeactivated()
Called when the application will be deactivated.
void onExit()
Called when the application exits (just before the process is killed by the system).
void onForeground()
Called when the application goes in foreground.
void onHandlePushMessage(String payload)
void onLocalNotificationReceived(Notification notification)
Automatically called when the end-user clicks on a local Notification.
void onProximityChanged(Location myLocation, ProximityRegion region, int status)
This method will be called when proximity to registered coordinates is detected.
void onPushMessageReceived(PushMessage message)
Called when the end-user has clicked a Push-Notification.
void onPushRegistrationChanged(int status, String message)
Called when the push registration status has changed.
abstract void onStart(Controller controller)
Override this method to provide a behavior when starting the application : for example push the main screen in this method
final void setActionBarEnabled(boolean enabled)
Set the android ActionBar mode enabled or not.
final void setActionBarTheme(int nativeTheme)
Sets a native theme type (light or dark) to use in the action bar for this application.
final void setBackButtonText(String backButtonText)
Replaces the "Back" button text.
final void setBackButtonTextColor(Color backButtonTextColor)
Changes the "Back" button text color.
void setEventBusEnabled(boolean on)
final void setForcedTheme(int nativeTheme)
Sets a native theme type (light or dark) to use for this application.
final void setSupportedOrientation(int orientation)
Forces the application to be in portrait and/or landscape mode.
final void setTitleBackground(Background background)
Sets the title bar background.
final void setTitleBackgroundColor(Color bgColor)
Sets the title bar background color.
final void setTitleBackgroundImage(Image image)
Sets the title bar background image.
final void setTitleBackgroundImage(int resImage)
Sets the title bar background image.
final void setTitleColor(Color titleColor)
Sets the title text color.
final void setTitleFont(Font font)
Sets the title font.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int PROXIMITY_ENTER_REGION

Key indicating that the terminal is entering a proximity region.

Constant Value: 1 (0x00000001)

public static final int PROXIMITY_EXIT_REGION

Key indicating that the terminal is exiting a proximity region.

Constant Value: 2 (0x00000002)

public static final int PUSH_FAILURE

The registration has failed. See message parameter to get details of the failure.

Constant Value: 2 (0x00000002)

public static final int PUSH_REGISTERED

The device is registered in the OS Push Notification server.

Constant Value: 1 (0x00000001)

public static final int PUSH_SERVICE_CHANGED_ID

The registration has changed the device registration unique Identifier.

Constant Value: 3 (0x00000003)

public static final int PUSH_UNREGISTERED

The device has been unregistered from the server.

Constant Value: 4 (0x00000004)

protected static final int THEME_DARK

Black or Dark theme

Constant Value: 2 (0x00000002)

protected static final int THEME_LIGHT

White or Light theme

Constant Value: 1 (0x00000001)

Fields

protected final Controller controller

Public Constructors

public Application ()

Do not override this constructor.
Do not call this constructor.

Public Methods

public void exit ()

Try or Ask to exit the application.

Not supported on iOS.
com.neomades.mad.TargetInfo#HAS_EXIT_FEATURE TargetInfo.HAS_EXIT_FEATURE could be used to put a condition around usage of this method.

The controller will check whether the application is authorized to exit, by calling onBeforeExit(Controller) method and the response of this method will authorize to exit or not.

See Also

public ContentManager getContentManager ()

Gets the registered content manager.

Returns
  • the registered content manager or null.

public static Application getCurrent ()

Returns the current instance of the application.

Returns
  • the instance of application

public EventBus getEventBus ()

Returns
  • the application event bus

public String getName ()

Returns the Application name.

Returns
  • the application name

public String getPackageName ()

Returns the main package name of the application.

Be careful with the returned value and the URS Application identifier. This package could be different at runtime from the source code if an Application identifier is set in the URS file.

Returns
  • the main package name of the application

public final boolean isActivated ()

Returns
  • true if the application is in background and active state (still alive but without UI)

public final boolean isBackground ()

Returns
  • true if the application is in background state (still alive)

public boolean isCreated ()

Returns if the Application has been created.

Returns

public final boolean isDeactivated ()

Returns
  • if the application is in background and inactive state (sleeping)

public final boolean isForeground ()

Returns
  • true if the application is in foreground state

public boolean isStarted ()

Returns if the Application has started and should be ready to show to a screen

Returns

public void openURL (String url)

Attempts to open the resource at the specified URL.

If the URL is a "resource" on the World Wide Web, the application will open the browser at the specified URL.

If the url starts with file://, it will try to open the file installed at the path specified after file:// using the default application that can open the file depending on its extension.

Parameters
url the URL to open
Throws
IllegalArgumentException if the file does not exist or is a directory

public void registerContentManager (ContentManager manager)

public void setApplicationDelegate (ApplicationDelegate delegate)

Sets a specific application delegate. Setting an ApplicationDelegate might be useful in very specific case when the application uses the NeoMAD specific code feature. This will enable to access the native application instance in the specific code.

Use this method inside your application's onCreate(Controller) method.

Parameters
delegate a delegate or null

public void setBadgeNumber (int number)

Sets the badge number displayed over the application icon (iOS)

Parameters
number a positive non-zero integer to show badge.

public void startVoiceCall (String phoneNumber)

Starts a voice call to a phone number.

To use this method, the PHONE_CALL permission must be declared in the URS file.

Parameters
phoneNumber the phone number to call

public void unregisterContentManager (ContentManager manager)

Protected Methods

protected final Controller getController ()

Returns
  • the root controller or null

protected void onActivated ()

Called when the application will be activated (after onStart(Controller)).

protected void onBackground ()

Called when the application goes in background.

protected boolean onBeforeExit (Controller controller)

Override this method to provide a behavior when the application is about to exit. For example save the state of the application or ask confirmation.

Parameters
controller the controller of this application
Returns
  • true if the application is authorized to exit
See Also

protected void onCreate (Controller controller)

Called before onStart(Controller) method.

The onStart(Controller) is not necessary called after this method. For example, a click over Notification could launch the application.

 public MyApplication extends Application implements PushServiceListener, PushMessageListener {
 
 	protected void onCreate(Controller controller) {
 		PushServiceManager pushService = PushServiceManager.getDefault();
 		
 		// Register the push service if not registered
 		pushService.register();
 	}
 
 	protected void onPushMessageReceived(PushMessage message) {
 		// called when a push notification is clicked by the end-user
 	}
 
 	protected void onPushRegistrationChanged(int status, String message) {
 		if (status == REGISTERED) {
 			// the push service is ready
 
 			// send to the application server the current ID 
 			// by HTTP
 			String id = message; 
 			// After now, the service currentID could be get also by PushServiceManager.getDefault().getCurrentID();
 			// ...
 		} else if (status == SERVICE_CHANGED_ID) {
 			// the push service has changed the ID
 			String newId = message;
 			
 		} else if (status == UNREGISTERED) {
 			// the push service has unregistered this device
 			
 		} else if (status == FAILURE) {
 			String details = message;
 			
 		}
 	}
 
 }
 
 

Warning: This method is called before onStart(Controller). The application could be started by a Push-Notification or by the end-user. The onStart(Controller) method is called after only if the user has launched manually the application.

protected void onDeactivated ()

Called when the application will be deactivated.

protected void onExit ()

Called when the application exits (just before the process is killed by the system).

protected void onForeground ()

Called when the application goes in foreground.

protected void onHandlePushMessage (String payload)

This method is deprecated.
see onPushMessageReceived(PushMessage) and ApplicationonPushMessageReceived(PushMessage)

Handles a Push-Notification message received from the server before showing it.

This handler replaces the default android visual Notification in the notification Bar.

NB. if the notification has a "notification" section (see PushMessage), this callback will not be called.

Limitation

Only called in android.

Parameters
payload the message payload data. See details in PushMessage.
See Also

protected void onLocalNotificationReceived (Notification notification)

Automatically called when the end-user clicks on a local Notification.

Parameters
notification the clicked notification
See Also

protected void onProximityChanged (Location myLocation, ProximityRegion region, int status)

This method will be called when proximity to registered coordinates is detected. It could be called if the terminal enters or exits the given ProximityRegion. Override this method in your Application class to make the required treatments A proximity event could also wake up a not-running application on Android and iOS platforms.

Parameters
myLocation the current location
region the defined proximity region.
status an integer indicating whether the terminal is entering or exiting the defined region.

protected void onPushMessageReceived (PushMessage message)

Called when the end-user has clicked a Push-Notification.

Parameters
message the clicked message

protected void onPushRegistrationChanged (int status, String message)

Called when the push registration status has changed.

Parameters
status the new status
message the details attached with the status.

protected abstract void onStart (Controller controller)

Override this method to provide a behavior when starting the application : for example push the main screen in this method

Parameters
controller the controller of this application
See Also

protected final void setActionBarEnabled (boolean enabled)

Set the android ActionBar mode enabled or not.

By default, the action bar is enabled.

Parameters
enabled true to set enabled the action bar.

protected final void setActionBarTheme (int nativeTheme)

Sets a native theme type (light or dark) to use in the action bar for this application.

This method should be call at the beginning of the onStart(Controller) method.

Only supported by Android.

Parameters
nativeTheme THEME_DARK or THEME_LIGHT

protected final void setBackButtonText (String backButtonText)

Replaces the "Back" button text.

This method must be called into onStart(Controller) method in order to keep the same back button text during the navigation.

Cross Platform Considerations

On iOS it changes the left back button of the navigation bar.

On Android this method does nothing.

Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setBackButtonTextColor (Color backButtonTextColor)

Changes the "Back" button text color.

This method must be called into onStart(Controller) method in order to keep the same back button text color during the navigation.

Cross Platform Considerations

On iOS it changes the left back button text color of the navigation bar.

On Android this method does nothing.

Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected void setEventBusEnabled (boolean on)

protected final void setForcedTheme (int nativeTheme)

Sets a native theme type (light or dark) to use for this application.

This method should be call at the beginning of the onStart(Controller) method.

Limitation

Not supported on iOS platform.

Parameters
nativeTheme THEME_DARK or THEME_LIGHT

protected final void setSupportedOrientation (int orientation)

Forces the application to be in portrait and/or landscape mode. This method does nothing if the device cannot handle orientation changing.

By default, the requested orientation is AUTO which means PORTRAIT and LANDSCAPE

Cross Platform Considerations

On some platforms, the orientation cannot be changed once a screen has been pushed to the display. So, this method should be called before any screen is pushed (at the beginning of the Application.onStart() for example).

Parameters
orientation the requested orientation (AUTO by default)
See Also

protected final void setTitleBackground (Background background)

Sets the title bar background.

This method must be called into onStart(Controller) method.

Parameters
background the background of the title bar
Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setTitleBackgroundColor (Color bgColor)

Sets the title bar background color.

This method must be called into onStart(Controller) method.

Parameters
bgColor the background color of the title bar
Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setTitleBackgroundImage (Image image)

Sets the title bar background image.

This method must be called into onStart(Controller) method.

Parameters
image the background image of the title bar
Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setTitleBackgroundImage (int resImage)

Sets the title bar background image.

This method must be called into onStart(Controller) method.

Parameters
resImage the background image of the title bar
Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setTitleColor (Color titleColor)

Sets the title text color.

This method must be called into onStart(Controller) method.

Parameters
titleColor the color for the title
Throws
IllegalStateException If this method is called outside onStart(Controller) method.

protected final void setTitleFont (Font font)

Sets the title font.

This method must be called into onStart(Controller) method.

Parameters
font the font for the title
Throws
IllegalStateException If this method is called outside onStart(Controller) method.