Sub CreateJsonfromDesign()
Dim Design As Map
Design.Initialize
Dim assignedTypes As List
assignedTypes.Initialize
Dim whatassign As Map
whatassign.Initialize
whatassign.put("B4XDesigner","citem01")
whatassign.put("JavaType",".LabelWrapper")
whatassign.put("DesignerType","Label")
assignedTypes.Add(whatassign)
whatassign.put("B4XDesigner","citem02")
whatassign.put("JavaType",".CustomViewWrapper")
whatassign.put("DesignerType","CustomView")
assignedTypes.Add(whatassign)
whatassign.put("B4XDesigner","citem03")
whatassign.put("JavaType",".CustomViewWrapper")
whatassign.put("DesignerType","CustomView")
assignedTypes.Add(whatassign)
Dim emptylayout As String= $"{
"MaterialIcons": false,
"Variants": [
{
"Scale": 1,
"Height": 600,
"Width": 600
}
],
"LayoutHeader": {
"Version": 5,
"DesignerScript": [
"'All variants script\n",
"'Variant specific script: 600x600,scale=1\n"
],
"GridSize": 10,
"ControlsHeaders": [
{
"JavaType": ".PaneWrapper$ConcretePaneWrapper",
"DesignerType": "Pane",
"Name": "Main"
}
],
"Files": []
},
"Data": {
"parent": "",
"borderColor": {
"ValueType": 6,
"Value": "0xFF000000"
},
"drawable": {
"color": {
"ValueType": 6,
"Value": "0xFFF0F8FF"
},
"csType": "Dbasic.Designer.Drawable.ColorDrawable",
"colorKey": "-fx-background-color",
"type": "ColorDrawable"
},
"orientation": "INHERIT",
"visible": true,
":kids": {},
"csType": "Dbasic.Designer.MetaMain",
"handleResizeEvent": true,
"type": ".PaneWrapper$ConcretePaneWrapper",
"title": "Form",
"enabled": true,
"variant0": {
"top": 0,
"left": 0,
"hanchor": 0,
"width": 200,
"vanchor": 0,
"height": 200
},
"cornerRadius": {
"ValueType": 7,
"Value": 0
},
"javaType": ".PaneWrapper$ConcretePaneWrapper",
"duration": 0,
"file": "",
"borderWidth": {
"ValueType": 7,
"Value": 0
},
"alpha": {
"ValueType": 7,
"Value": 1
},
"name": "Main",
"eventName": "MainForm",
"extraCss": "",
"tag": ""
},
"FontAwesome": false
}"$
Design=emptylayout.As(JSON).ToMap
Dim variants As List=Design.Get("Variants")
Dim variantlist As Map=variants.Get(0)
variantlist.Put("Height",Root.Height)
variantlist.Put("Width",Root.Width)
Dim LayoutHeader As Map=Design.Get("LayoutHeader")
LayoutHeader.put("GridSize",10)
Dim Data As Map = Design.Get("Data")
Dim controls As List=LayoutHeader.Get("ControlsHeaders")
Dim kids As Map
kids.Initialize
Log(controls.Size)
Dim acontrolofthem As Map
acontrolofthem.initialize
Dim kid As Int = 0
Dim controlnames As List = Array As String("citem01","citem02","citem03")
For k = 0 To controlnames.Size -1
Dim whatis As String = controlnames.Get(k)
Dim whatassign As Map = assignedTypes.Get(k)
acontrolofthem.put("JavaType",whatassign.Get("JavaType"))
acontrolofthem.put("DesignerType",whatassign.Get("DesignerType"))
acontrolofthem.put("Name",controlnames.Get(k))
controls.Add(acontrolofthem)
Dim jp As JSONParser
jp.Initialize(File.ReadString(File.DirAssets, whatis & ".json"))
Dim currentkid As Map=jp.NextObject
currentkid.Put("name",controlnames.Get(k))
currentkid.Put("eventName",controlnames.Get(k))
kids.put(kid.As(String).Trim, currentkid)
kid=kid+1
Next
Data.Put(":kids",kids)
Design.Put("LayoutHeader", LayoutHeader)
Design.Put("Variants", variants)
Design.Put("Data", Data)
Design.Put("FontAwesome", False)
Design.Put("MaterialIcons", False)
Log(Design.As(JSON).ToString)
End Sub