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 Sidebar object:
First, you have to import Layout class:
This chapter will show you how to ceate the layout Sidebar object:
import com.infairy.cocina.SDK.Layout.Layout; import com.infairy.cocina.SDK.Layout.LayoutListItem; import com.infairy.cocina.SDK.Layout.LayoutSidebar;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 List item, because sidebar item is same as List item:
LayoutListItem[] LI=new LayoutListItem[3]; LI[0]=layout.getLayoutListItem(); LI[0].Alias="Name1"; LI[0].ImageHeight=10; LI[0].ImageWidth=10; LI[0].Value="John"; LI[0].Index="28"; LI[0].ImageSource="Man"; LI[1]=layout.getLayoutListItem(); LI[1].Alias="Name2"; LI[1].ImageHeight=10; LI[1].ImageWidth=10; LI[1].Value="Bill"; LI[1].Index="28"; LI[1].ImageSource="Man"; LI[2]=layout.getLayoutListItem(); LI[2].Alias="Name3"; LI[2].ImageHeight=10; LI[2].ImageWidth=10; LI[2].Value="Mary"; LI[2].Index="22"; LI[2].ImageSource="Woman";Create Sidebar layout object:
LayoutSidebar ls=new LayoutSidebar(); ls.LayoutID=LayoutID; ls.width=130; ls.height=0; ls.left=0; ls.top=0; ls.backcolor="#aaffffff"; ls.fontSize=20; /* * the position of sidebar was defined by com.infairy.cocina.SDK.device.DevicePool#LAYOUT_ITEM_SIDEBAR_POSITION_xxx */ ls.position=device.LAYOUT_ITEM_SIDEBAR_POSITION_RIGHT; ls.listItem=LI //List item array ls.gauge=10; sidebarLeftID=layout.createUI(this, ls);Please note that, each sidebar item have different value and index, these two properties can be distingruish which icon was clicked.
ls.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.
Because of the Gridview have two properties was assigned, value & index, so you Go() fucntion also have to implement two parameter:
public void Go(String value, String index){ .... }The parameter "value" is mapping to the gridview item's value property and the parameter "index" is mapping to the gridview item's idnex property.
The Sidebar layout object properties show as below:
/** * layout height in pixel, , default is 10 */ public int height=10; /** * layout axis of left, , default is 0 */ public int left=0; /** * layout axis of top, , default is 0 */ public int top=0; /** * 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=""; /** * list item array */ public LayoutListItem[] listItem=null; /** * font color */ public String fontColor=""; /** * font size, default is 10 */ public int fontSize=10; /** * background color */ public String backcolor=""; /** * position, please refer to * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_ITEM_SIDEBAR_POSITION_BOTTOM} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_ITEM_SIDEBAR_POSITION_LEFT} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_ITEM_SIDEBAR_POSITION_RIGHT} * {@link com.infairy.cocina.SDK.device.DevicePool#LAYOUT_ITEM_SIDEBAR_POSITION_TOP} */ public String position=""; /** * item gauge, default id 5 */ public int gauge=5; //Default is 5 /** * visibility, default is true */ public boolean visible=true;