Developer

Activity Status

MAFActivityState object is an MAF-specific object that provides access to the current Android activity instance.

The framework can provide its feature set even if it does not have full access to the life cycle of the underlying OS objects, such as an activity.

To access the latest activity instance, some methods require MAFActivityState as an input parameter instead of an activity or context object. ActivityState objects must provide access to the actual instance. For example, if you have a MAFTile object reference, call the getActivityState() method to get the relevant ActivityState object.

To interact with the MAF Extensibility framework from your own activity, use the MAFActivityManager.provideActivityState() in your activity’s onCreate() method, and invoke the returned object’s methods from your activity’s appropriate callbacks.
	// 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.setApplicationUIElementCreator(new MyViewCreator());

	…

	private class MyViewCreator implements MAFApplicationUIElementCreator {

		@Override
		public boolean beforeCreateUIElement(MAFActivityState activityState,
				String uiElementId, String uiElementType, ViewGroup parentView,
				int availableWidth, int availableHeight,
				List<MAFParameter> parameters, MAFTile tile) {
			//If its the UI Element we're interested in take over the creation
			if ("myUIelementIdFromConfig".equals(uiElementId))  {
				return true;
			}
			//Otherwise use the default behaviour
			return false;
		}

		@Override
		public View createUIElement(final MAFActivityState activityState,
				final String uiElementId, String uiElementType, ViewGroup parentView,
				int availableWidth, int availableHeight,
				List<MAFParameter> parameters, final MAFTile tile) {
			//This method will be invoked only for our UI elements (the ones we returned true for on the beforeCreateUIElement method 
			final TextView textView = new TextView(activityState.getActivity());
			textView.setText(Long.toString(System.currentTimeMillis()));
			final List<MAFParameter> actionParamList = new ArrayList<MAFParameter>();
			actionParamList.add(new MAFDefaultParameter("targetUIElementId", "myUIelementIdFromConfig"));
			textView.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					tile.getController().performAction(new MAFDefaultAction("uiRefresh", actionParamList), activityState, "onClick", uiElementId, textView, tile);
				}
			});
			return textView;
		}

		@Override
		public View afterCreateUIElement(View view,
				MAFActivityState activityState, String uiElementId,
				String uiElementType, ViewGroup parentView, int availableWidth,
				int availableHeight, List<MAFParameter> parameters, MAFTile tile) {
			//We do not need any changes here now, so return the created view as it is
			return view;
		}

		@Override
		public boolean beforeRefreshUIElement(View view,
				MAFActivityState activityState, String uiElementId,
				String uiElementType, ViewGroup parentView, int availableWidth,
				int availableHeight, List<MAFParameter> parameters, MAFTile tile) {
			//If its the UI Element we're interested in take over the refresh mechanism
			if ("myUIelementIdFromConfig".equals(uiElementId))  {
				return true;
			}
			return false;
		}

		@Override
		public void refreshUIElement(View view, MAFActivityState activityState,
				String uiElementId, String uiElementType, ViewGroup parentView,
				int availableWidth, int availableHeight,
				List<MAFParameter> parameters, MAFTile tile) {
			//This method will be invoked only for our UI elements (the ones we returned true for on the beforeRefreshUIElement method 
			((TextView)view).setText(Long.toString(System.currentTimeMillis()));
		}

		@Override
		public void afterRefreshUIElement(View view,
				MAFActivityState activityState, String uiElementId,
				String uiElementType, ViewGroup parentView, int availableWidth,
				int availableHeight, List<MAFParameter> parameters, MAFTile tile) {
			//We do not need any changes here now
		}
	}