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 DateTime object:
First, you have to DateTime Layout class:
This chapter will show you how to ceate the layout DateTime object:
import com.infairy.cocina.SDK.Layout.Layout; import com.infairy.cocina.SDK.Layout.LayoutDateTime;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);Nex, create DateTime layout object:
LayoutDateTime ldt=new LayoutDateTime(); ldt.LayoutID=LayoutID[0]; //DateTime format, refer to com.ifnairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_xxx ldt.format=device.LAYOUT_TYPE_TIME_FORMAT_YEAR_MONTH_DAY; ldt.width=149; ldt.height=30; ldt.left=537; ldt.top=14; ldt.fontColor="#4b718a"; ldt.fontSize=30; /* * Create DateTime object */ layout.createUI(this, ldt);The DateTime layout can be clicked by users, you just need to do defined the key value:
ldt.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 DateTime 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; /** * font size, default is 10 */ public int fontSize=10; /** * data format, please refer to * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_DAY} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_HOUR_MINUTE_SECOND} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_HOUR_MINUTE} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_HOUR} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_MINUTE_SECOND} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_MINUTE} * and {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_xxx} ... * default is com.infairy.cocina.SDK.device.DevicePool#LAYOUT_TYPE_TIME_FORMAT_HOUR_MINUTE} */ public String format="hh:mm"; /** * font color */ public String fontColor=""; /** * 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="";