Developer

UI Component

The UI Component handles interaction with the user and displays tiles according to the MAF Extensibility layout configuration.

Similarly to the other components, applications can override, decorate, or replace default behavior. Applications can register their own MAFApplicationTileCreator to take over tile creation or to decorate a tile created by the framework.

UIElements can also be created with application code. By registering a MAFUIElementCreator, applications can build their own UIElements, and replace or modify the default UIElement creation of the framework.

Applications can also change the native views of the tiles by getting reference of the tile’s view with the findView(s) or getChildViews() methods. To call these methods, use the view identifiers specified in the default extensibility layout configuration.
	// MAFCore is the main object to deal with MAF Extensibility
	// MAFCore should be built before MAF Extensibility features can be used
        MAFCoreBuilder mafCoreBuilder = new MAFCoreBuilder(this, false);

        //Registering application Tile Controller Creator
        mafCoreBuilder.setApplicationTileCreator(new MyTileCreator());

	…

	private class MyTileCreator implements MAFApplicationTileCreator {

		@Override
		public boolean beforeCreateTile(String tileId,
				MAFTileController mafTileController) {
			//Let the framework to do the tile creation
			return false;
		}

		@Override
		public MAFTile createTile(String tileId,
				MAFTileController mafTileController) {
			//Will be never invoked as beforeCreateTile return false always 
			return null;
		}

		@Override
		public MAFTile afterCreateTile(MAFTile tile, String tileId,
				MAFTileController mafTileController) {
			//If this is the Tile we're interested in...
			if ("MyTileIdFromConfig".equals(tileId)) {
				//...return a new Decorator object
				return new MyTile(tile);
			}
			//...otherwise return the Tile created by the framework
			return tile;
		}

	}
	
	private class MyTile implements MAFTile {
		
		private MAFTile decoratedTile;

		public MyTile(MAFTile decoratedTile) {
			this.decoratedTile = decoratedTile;
		}

		@Override
		public View getView(boolean forceReload, int availableWidth,
				int availableHeight) {
			//Let the decorated tile to build the view
			View resultView = decoratedTile.getView(forceReload, availableWidth, availableHeight);
			//Search for a created sub-view we're interested in
			TextView myLabelTextView = (TextView) decoratedTile.findViewById("myLabelUIElementFromConfig");
			//Do some after modification
			myLabelTextView.setBackgroundColor(Color.RED);
			//And resturn the result
			return resultView;
		}
		
		@Override
		public boolean onEvent(String eventId) {
			//Keep all other methods untouched now
			return decoratedTile.onEvent(eventId);
		}

		…
		
	}