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.
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; }