7.3 Mobile WidgetProcessors

Metawidget supports WidgetProcessors for mobile environments.

7.3.1 Android WidgetProcessors

DisabledAttributeProcessor

DisabledAttributeProcessor calls setEnabled(false) on a View, based on the disabled attribute.

SimpleBindingProcessor

Like most other Metawidgets, AndroidMetawidget supports property binding. As of the time of writing, however, Android leaves much of the implementation of property binding to the developer. AndroidMetawidget automates this by supplying a SimpleBindingProcessor. This implementation is pluggable, so may be swapped out as and when later releases of Android more fully support data binding.

SimpleBindingProcessor binds properties using setValue. To save values back into the domain object, clients must call save:

myMetawidget.getWidgetProcessor( SimpleBindingProcessor.class ).save( myMetawidget )

If the type of the business property does not match the type expected by the View, clients can register a Converter. First implement the org.metawidget.android.widget.widgetprocessor.binding.simple.Converter interface...

public class ColorConverter
	implements Converter<Color> {

	public Color convertFromView( View widget, Object value, Class<?> intoClass ) {

		// return (String) value as a Color
	}
	
	Object convertForView( View widget, Color value ) {
	
		// return Color as a String (e.g. ff0000)
	}
}

...then register it either programmatically or in metawidget.xml:

<widgetProcessors>
	<array>
		<simpleBindingProcessor xmlns="java:org.metawidget.android.widget.widgetprocessor.binding.simple"
				config="SimpleBindingProcessorConfig">
			<converter>
				<class>java.lang.Color</class>
				<colorConverter xmlns="java:com.myapp"/>
			</converter>					
			<converter>
				...another converter...
			</converter>					
		</simpleBindingProcessor>
		...