Introduction


DGBootstrap is the library that includes the four basic libraries of the Digipolitan framework, DGFoundation, DGSQL, DGSQLite and DGNetwork. He is made to allow you to develop an application using all our non GUI features (Dependency injection, cache repositories, model factories etc…)


It automatically configure the DependencyInjectorManager to allow the use of SQLite and some other features like the UsageManager (to execute a tast at the first launch or every x launches)



This sample’s purpose is to show you the different steps to create a simple app using DGBootstrap and be ready for your project development.



Prerequisites

Android Studio


Sample

We will create the two main classes defining an Android application, the Application and the Activity and configure the manifest.
Here is a screenshot of our project structure


Getting started Android

Including dependencies

You need to declare the Digipolitan maven repository to be able to resolve maven dependencies. Simply declare it in your project build.gradle file :

		
allprojects {
	repositories {
	jcenter()
		maven {
			url 'http://maven.digipolitan.com/libs-release/' 
		} 
	}
}
		
	

And declare a dependency for DGBootstrap in your app module :

		
dependencies {
	compile 'com.android.support:appcompat-v7:21.0.2'
	compile 'com.digipolitan.libraries:DGBootstrap:1.0'
}
		
	

Here the sample requires appcompat-v7 and DGBootstrap.


Creating the Application

The Application object is the shared Context of your application code, you can override some methods to customize it

		
public class Application extends AbstractApplication{

	@Override
	protected void bootstrap() {
		super.bootstrap();
		// here you can add your own modules to the dependency manager
	}
	
	@Override
	protected void rebootApplication() {
		//called when app is restored from background since getResetDuration() you can tell your restored activity to do some stuff via getCurrentActivity()
	}
	
	@Override
	public long getResetDuration() {
		//you need to override this method to specify the duration(in millis) the app needs to be in background to be reset
		return (long) (DateUtils.MINUTE_TIME_IN_MILLIS * 2.5);
	}
}
		
	

Creating the Activity

You need to override DGAbstractActivity, to be sure that the Application is notified of the current Activity displayed.

		
public class MainActivity extends DGAbstractActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LogManager.d("Activity Created!");
	}
	
	@Override
	protected int getLayoutRes() {
		return R.layout.activity_main;
	}
}
		
	

Configuring the manifest

Now we need to configure the manifest to declare our application, activity and set the environment

		
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.digipolitan.libraries.bootstrap.bootstrapsample" >
	<application
	android:name=".application.Application"
	android:allowBackup="true"
	android:icon="@drawable/ic_launcher"
	android:label="@string/app_name"
	android:theme="@style/AppTheme" >
		<meta-data android:name="com.digipolitan.libraries.foundation.environment" android:value="@string/environment_type_debug"></meta-data>
	
		<activity
			android:name=".application.activities.MainActivity"
			android:label="@string/app_name" >
		
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>
	</application>
</manifest>
		
	

If you launch the app you should see an entry in the LogCat :

  com.digipolitan.libraries.bootstrap.bootstrapsample D/[MainActivity][onCreate:14]﹕ Activity Created!