Infairy platform define different layout object to let users interactive with bundle by graphic usere interface, each bundle can be put into many layout tag, each layout tag can design many layout object.
This chapter will show you how to ceate the layout Animation object:
First, you have to import Layout class:
This chapter will show you how to ceate the layout Animation object:
import com.infairy.cocina.SDK.Layout.Layout; import com.infairy.cocina.SDK.Layout.LayoutAnimation; import com.infairy.cocina.SDK.Layout.LayoutAnimationItem;Then, get Layout service
Layout layout=(Layout)Tools.getService(context, Layout.class.getName(), "(FUNCTION=LAYOUT)");Next, create layout tag and get LayoutID for other layout object used purpose:
LayoutTag ltag=new LayoutTag(); ltag.backgroundImage="img/background.png"; ltag.bundleID=BundleID; ltag.LayoutHeight=450; ltag.LayoutWidth=800; ltag.title="My App"; /* * Create layout tag and get layout id for other layout object use */ LayoutID=layout.createUI(this, ltag);We have to prepare the animation item:
LayoutAnimationItem[] ani=new LayoutAnimationItem[4]; ani[0]=new LayoutAnimationItem(); ani[0].imageSrc="icon/ani0.png"; ani[1]=new LayoutAnimationItem(); ani[1].imageSrc="icon/ani1.png"; ani[2]=new LayoutAnimationItem(); ani[2].imageSrc="icon/ani2.png"; ani[3]=new LayoutAnimationItem(); ani[3].imageSrc="icon/ani3.png";Create Aniamtion layout object:
LayoutAnimation la=new LayoutAnimation(); la.LayoutID=LayoutID; la.height=450; la.width=800; la.item=ani; //Animation item array la.left=0; la.top=0; la.Interval=1500; //Set the animation time interval in milli seconds LEARN_ID=layout.createUI(this, la); la=null; ani=null;OK, you have an animator object.
The Animation layout can be clicked by users, you just need to do defined the key value:
la.key=device.DEVICE_OPERATION_USER_DEFINED_0;"DEVICE_OPERATION_USER_DEFINED_0" is defined by com.infairy.cocina.SDK.device.DevicePool#DEVICE_OPERATION_xxx
then defined the Operation object( refer to Operation):
public class myFirstBundle implements BundleActivator, Runnable{ ... /* * Bundle ID */ String BundleID=""; /* * Layout ID */ String LayoutID=""; Thread me; /* * Layout object */ Layout layout; /* * entry point */ public void start(BundleContext context) throws Exception { ... /* * get layout service */ layout=(Layout)Tools.getService(context, Layout.class.getName(), "(FUNCTION=LAYOUT)"); ..... /* * define operation for layout key mapping */ Vector Operation=new Vector(); OperationDNA oobj=new OperationDNA(); //when user click the image layout object, this operation object will trigger to run the Funtoin:Go() oobj.KEY=device.DEVICE_OPERATION_USER_DEFINED_0; oobj.Function="Go"; Operation.addElement(oobj); dict.put(InfairyInterface.DeviceOperation, Operation); ... BundleID=device.addDevice(this, dict);You have also implemnt Go() function to catch up the action.
public void Go(){ .... }The Animation layout object properties show as below:
/** * Layout id of Bundle */ public String LayoutID=""; /** * Layout axis of top, default is 0 */ public int top=0; /** * Layout axis of left, default is 0 */ public int left=0; /** * Layout width in pixel, default is 10 */ public int width=10; /** * Layout height in pixel, default is 10 */ public int height=10; /** * Layout visibility, default is true */ public boolean visible=true; /** * Layout key defined, please refer to {@link com.infairy.cocina.SDK.device.DevicePool#DEVICE_OPERATION_DIMMER}, {@link com.infairy.cocina.SDK.device.DevicePool#DEVICE_OPERATION_xxx}... */ public String key=""; /** * Layout key value, defined by developer */ public String value=""; /** * Layout key index value, defined by developer */ public String index=""; /** * Animation images item array */ public LayoutAnimationItem[] item=null; /** * transparent(0.0~1.0) of layout, default is 1.0 */ public double alpha=1.0; /** * Image show time interval in millis, default is 500 ms */ public long Interval=500;The Animation item properties show as below:
/** * Animation images url */ public String imageSrc="";