Building MAF Core

To interact with the Extensibility framework, build an implementer of the MAFCore interface, which acts as a mediator between the application and the various components of the framework.

Use the MAFCoreBuilder class to build a MAFCore object. MAFCoreBuilder offers setter methods to inject your own code to replace or override the framework’s default behavior in different scenarios.

Most use cases require only one MAFCore instance, however, you can have several instances. Each MAFCore instance has its own lifecycle, and its own context, but they share the same space in the file system, which also means that they share the same MAF Extensibility framework configuration.

Building a MAFCore instance is always the first step of using the Extensibility features. If the opening screen of your app is extensible, there are two options for displaying the first MAF driven screen:
  • Create your own application object to build MAFCore and use one of its switchScreen() methods to navigate to the first screen of your application.
  • Define a subclass of the MAFTileActivity as a launcher activity in your AndroidManifest.xml. In this subclass, implement a template method (onBeforeMAFCreate()) where you can build your MAFCore object and provide it for the activity instance, so that it can use the framework feature set.
If your opening screen is not driven by the Extensibility Framework, build your application in the usual way, creating a MAFCore object only when you need it either to navigate to a framework driven screen, or to ask for a view created by the MAF Extensibility Framework. That view is based on the predefined layout configuration XML and you can use it in your application similar to any native Android view.

If you override the appropriate creation mechanism, the framework can work without any layout configuration. However, to use the framework to get its configuration-driven layouts, you must provide a valid configuration file. Use the appropriate static methods of MAFCoreBuilder class to provide a configuration. To avoid setting the default configuration at each application start, first retrieve the current configuration state. This way you can also decide which available configuration the framework should use.

If you do not want to use MAF Extensibility Framework features in your application, use the release() method to release all your MAFCore objects to free resources.

public class MAFExtensibilityBlockUISampleActivity extends MAFTileActivity {

    private MAFCore mafCore;

    //Data DataSourceAdapter used to provide data from the underlying database
    private MAFDBDataSourceAdapter appDataSourceAdapter;
	
    // Method onBeforeMAFCreate is a call-back that is called by MAF Extensibility 
    // to let the application to build MAFCore if not yet built. 
    // This can help to let the application the use MAF Extensibility features even 
    // for the first activity initializing the MAFCore within this call back back method.  
    @Override
    protected MAFCore onBeforeMAFCreate() {

//if its already created return it
    	if (mafCore != null) return mafCore;
    	
    	// Setting log behavior
	// Logging to default Android log should not be turned on in productive
	// mode
	MAFLogger.logToAndroid(true);
	// Change log level for more log messages. Low level logging can reduce
	// performance
	MAFLogger.setLogLevel(IMAFLogger.INFO);

	//Check if default configuration and styling already set for MAF Extensibility
	MAFConfigurationState state = MAFCoreBuilder.getConfigurationState(this);
	if (!state.hasValidDefaultConfiguration()) {
		// Sets the default (built-in) layout and styling configuration.
		MAFCoreBuilder.setDefaultConfiguration(this, R.raw.layout_phone,
				R.raw.styles);
	}

	// MAFCore is the main object to deal with MAF Extensibility
	// MAFCore should be built before MAF Extensibility feature can be used
        MAFCoreBuilder mafCoreBuilder = new MAFCoreBuilder(this, false);

        // Initialization of a DataSource that uses built in SQLite database for handling data requests.
        // Initialization of a DB Adapter is not a long-running process so it can be done in the UI thread
        appDataSourceAdapter = new MAFDBDataSourceAdapter(this);
        // add demo data to the DB DataSource
        addTestData(appDataSourceAdapter);
        // let MAF Extensibility to use this DB DataSource Adapter
        mafCoreBuilder.setApplicationDataSourceAdapter(appDataSourceAdapter);

        //Building MAFCore
        mafCore = mafCoreBuilder.build();
        return mafCore;
    }