reference_modules_android - NibiruOS/mobile GitHub Wiki

Android

Generic cross components

Application

No platform-specific bootstrap is required, so the only action made by AndroidBootstrap is calling the application entry point.

Application startup is performed by BootstrapActivity. You must configure this activity in the AndroidManifest.xml file as launcher activity.

Inversion of control

Dependency injection is based on RoboGuice. It is based on Guice and uses Guice standard modules for configuration.

This framework requires creating a string array resource in order to define the modules to be used. For example:

<resources>
	<string-array name="roboguice_modules">
		<item>ar.com.oxen.nibiru.mobile.android.ioc.DefaultAndroidModule</item>
		<item>ar.com.oxen.nibiru.mobile.android.ioc.DefaultAndroidHardwareModule</item>
		<item>ar.com.oxen.nibiru.mobile.core.ioc.DefaultSecurityModule</item>
		<item>ar.com.oxen.nibiru.mobile.android.ioc.DefaultSecurityModule</item>
		<item>ar.com.oxen.nibiru.mobile.sample.android.Module</item>
	</string-array>
</resources>

An advantage of this approach is that such module list can be customized using Android resource selection mechanisms.

The ar.com.oxen.nibiru.mobile.android.ioc package contains many Guice modules for default configurations. It also contains generic providers.

Unified API components

Event handling

Event bus listening is implemented using android.content.BroadcastReceiver. Events are thrown using android.content.Intent instances. The ar.com.oxen.nibiru.mobile.android.event package contains such implementations.

User interface

User interface is divided into many packages, just like at the core module. The ar.com.oxen.nibiru.mobile.android.ui contains a android.widget.Toast based implementation for AlertManager.

Place management

Places are handled using android.content.Intent instances. Inside the ar.com.oxen.nibiru.mobile.android.ui.place package, the IntentPlace class wraps an intent inside a Nibiru Mobile place, while the IntentPlaceManager implements a place manager which creates IntentPlace instances. IntentPlace just fires an intent.

The intent action is build by convention. Its structure is:

{application_package_name}.place.{place_name}

You must follow such convention when configuring AndroidManifest.xml file.

Model-View-Presenter pattern

The ar.com.oxen.nibiru.mobile.android.ui.mvp contains different classes for implementing the MVP pattern. Most of them are just adapters. We will overlook them in order to focus on more important classes.

The main class is PresenterActivity, which delegates on the presenter. In order to get the presenter responsible for executing the logic, it asks to the presenter mapper using the place as parameter. This class also shows the view.

For each presenter, you must add an activity of this type, following the conventions explained in the previous section.

Regarding the view, there is a more specific interface, AndroidView, which allows handling Android events. BaseAndroidView provides an empty implementation for this interface.

User preferences

User preferences are stored using android.content.SharedPreferences. The implementation can be found at the ar.com.oxen.nibiru.mobile.android.preferences package.

Geolocation

The ar.com.oxen.nibiru.mobile.android.geolocation package contains a native location service implementation.

⚠️ **GitHub.com Fallback** ⚠️