Android Question help in logic

ilan

Expert
Licensed User
Longtime User
hi

i need help to find the correct logic to get what i need. i am using this tool to get some information from a bal file:


this tool is converting a complete bal file to json file so it gets all information from each view like colors, position, size, name etc.
what i need is just get from each view 5 parameters.

Name
Left
Top
Width
Height

i dont need the json file so i am trying to get the info directly from the created map that holds all information.

the structure of the map look as follow.

first, there is a map that hold all parameters of a single view. if the view has children then it holds also a map with the key ":kids"
this map will hold again a map of maps that each map will hold all parameters and again if it has children it will also hold a key ":kids"
if not it wont.

now i am able to get all views with the parameters but not the kids and their kids.

i try for 2 days to find a logic how to do that. it needs to be something that is recursive like this code:

what i have until now is this. change just one sub in the balconvertor class and add 1 sub:

B4X:
Public Sub ConvertBalToJsonInMemory(Dir As String, FileName As String) As Map
    Dim reader As RandomAccessFile
    reader.Initialize2(Dir, FileName, True, True)
    Dim design As Map
    Dim lh As Map = ReadLayoutHeader(reader)
    If lh.Get("Version") < 3 Then
#If UI
        Dim xui As XUI
        xui.MsgboxAsync("Unsupported version: " & FileName, "")
#end if
#If NON_UI
        Log("Unsupported version: " & FileName)
#End If
        Return design
    End If
    design.Initialize
    design.Put("LayoutHeader", lh)
    Dim cache() As String = LoadStringsCache(reader)
    Dim numberOfVariants As Int = reader.ReadInt(reader.CurrentPosition)
    Dim variants As List
    variants.Initialize
    For i = 0 To numberOfVariants - 1
        variants.Add(ReadVariantFromStream(reader))
    Next
    'design.Put("Variants", variants)
    'design.Put("Data", ReadMap(reader, cache))
    'reader.ReadInt(reader.CurrentPosition) '0
'    design.Put("FontAwesome", reader.ReadSignedByte(reader.CurrentPosition) = 1)
    'design.Put("MaterialIcons", reader.ReadSignedByte(reader.CurrentPosition) = 1)
  
  
    '############################# MY CODE to get params START ##############################
  
'    D:\F\android apps\ONLINE\wwwSAGITALnet\The Giant Duel\PICS-STUFF\testbal\Files
    Dim dmap As Map = ReadMap(reader, cache)
    Dim kidsmap As Map = dmap.Get(":kids")
'    Dim map2 As Map = kidsmap.Get("1")
'    Dim kidsmap2 As Map = map2.Get(":kids") 

    Dim mymap, refmap As Map
    mymap.Initialize
    refmap.Initialize
  
'    Dim hasnokids As Boolean = False

    For Each key As String In kidsmap.Keys
        mymap.Put(key,returnviewprops(kidsmap.Get(key)))
    Next


    'check if all views exists and log them
    For Each key As String In mymap.Keys 'relevant code
        Dim myitem As mapItem = mymap.Get(key)
        Log(myitem.name)
        Log(myitem.left)
        Log(myitem.top)
        Log(myitem.width)
        Log(myitem.height)
        Log("---------------------")
    Next
  
'
'    csType
'    Type
'    animationDuration
'    drawable
'    eventName
'    fullScreen
'    includeTitle
'    javaType
'    name
'    parent
'    tag
'    title
'    titleColor
'    visible
'    variant0
'    :kids

    reader.Close
    Return design
End Sub

Sub returnviewprops(m As Map) As mapItem 'relevant code
    Dim myitem As mapItem
    myitem.Initialize
    myitem.name = m.Get("name")
    If m.ContainsKey("variant0") Then
        Dim varmap As Map = m.Get("variant0")
        myitem.left = varmap.Get("left")
        myitem.top = varmap.Get("top")
        myitem.width = varmap.Get("width")
        myitem.height = varmap.Get("height")
    End If
    Return myitem
End Sub


'############################# MY CODE to get params END ##############################

results:

Waiting for debugger to connect...
Program started.
ConvertBalToJson: 1.bal
Panel1
0
0
320
300
---------------------
Panel2
0
300
320
130
---------------------
ImageView5
350
0
320
430
---------------------
ListView1
350
0
320
430
---------------------

this is exactly what i need, i just need now to get all kids in the panels and if there are also panels with kids get them to so something that is recursive.

i attach a sample bal file and the convertor i have.

thanx in advance
 

Attachments

  • 1.bal
    6.5 KB · Views: 263
  • BalConverter.zip
    7.4 KB · Views: 261
Last edited:
Top