Sub Process_Globals
End Sub
Sub Globals
Dim editCode As EditText
Dim code As String
Dim bStart As Button
Dim apan As apanel 'activity panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
code=File.ReadString(File.DirAssets,"test.b4a")
editCode.Initialize("editcode")
editCode.Text=code
Activity.addview(editCode,0%x,8%y,100%x,42%y)
bStart.Initialize("bstart")
bStart.Text="Start >"
Activity.addview(bStart,0,0,28%x,8%y)
apan.Initialize
bStart_click
Activity.addview(apan.pmain,0,50%y,100%x,50%y)
End Sub
Sub editCode_click
editCode.BringToFront
End Sub
Sub RemoveViews
Dim i As Int
For i=apan.pmain.NumberOfViews-1 To 0 Step -1
apan.pmain.RemoveViewAt(i)
Next
End Sub
Sub bStart_click
RemoveViews
Dim command As String
Dim e As Boolean
initGlobals
runSub( "Activity_Create(FirstTime As Boolean)")
End Sub
Sub runSub(command As String)
Dim e As Boolean
command=runAt(command)
Do Until e
runCode(command)
command=runAt(command)
If command.IndexOf("End Sub")>-1 Then e=True
Loop
End Sub
Sub getValues(objectProp As String)As String()
Dim apos, epos,count As Int
Dim s1,s2 As String
Dim v(10) As String
apos=objectProp.IndexOf("(")
If apos>-1 Then
epos=objectProp.IndexOf(")")
s1=objectProp.SubString2(apos+1,epos)
apos=0
Dim findEnd As Boolean
Do Until findEnd
epos=s1.IndexOf2(",",apos+1)
If epos<0 Then
findEnd=True
epos=s1.Length
End If
v(count)=s1.SubString2(apos,epos)
count=count+1
apos=epos+1
Loop
End If
Return v
End Sub
Sub getFunction(objectProp As String)As String
If objectProp.IndexOf("(") >-1 Then Return objectProp.SubString2(0,objectProp.IndexOf("("))
If objectProp.IndexOf("=") >-1 Then Return objectProp.SubString2(0,objectProp.IndexOf("="))
End Sub
Sub runCode(command)
Dim apos, epos, index As Int
Dim objectType,objectName, objectProp ,eventName,functionsName As String
Dim params(10) As String
objectName=command.SubString2(1,command.IndexOf("."))
objectProp=command.SubString(command.IndexOf(".")+1)
functionsName=getFunction(objectProp)
params=getValues(objectProp)
index=apan.findindex(objectName)
If functionsName="Initialize" Then
eventName=params(0)
initview(objectName,eventName)
End If
If functionsName="AddView" Then
params=getValues(objectProp)
index=apan.findindex(params(0))
addview(apan.p(index),params)
End If
If functionsName.IndexOf("Color=")>-1 Then
params=getValues(objectProp)
index=apan.findindex(objectName)
apan.p(index).Color=Colors.RGB(params(0),params(1),params(2))
End If
End Sub
Sub runAt(subname As String)As String
Dim apos, epos As Int
Dim findstr As String
apos=code.IndexOf2(subname,apos)
epos=code.IndexOf2(Chr(13),apos+subname.Length+3)
findstr=code.SubString2(apos+subname.Length+1,epos)
Return findstr
End Sub
Sub initGlobals
'in this first Version it define all Dim .. as of the hole code
Dim apos, epos As Int
Dim findEnd As Boolean
Dim objectType,s1,objectName As String
Do Until findEnd
apos=code.IndexOf2("Dim",apos)
epos=code.IndexOf2("Dim",apos+1)
If epos=-1 Then
findEnd=True
epos=code.IndexOf2("End Sub",apos+1)
End If
s1=code.SubString2(apos+3,epos)
objectName=s1.SubString2(0,s1.IndexOf("As"))
objectType=s1.SubString2(s1.IndexOf("As")+2,s1.Length)
apan.makeDim(objectName,objectType)
apos=epos
Loop
End Sub
Sub addview(o As View,pa() As String)
Dim i(4) As Int
i(0)=pa(1)
i(1)=pa(2)
i(2)=pa(3)
i(3)=pa(4)
apan.pmain.addview(o,i(0),i(1),i(2),i(3))
End Sub
Sub initview(objectName As String,eventName As String)
Dim index As Int
index=apan.findindex(objectName)
apan.Initialize2(objectName,eventName)
apan.event(index)=eventName
End Sub
Sub editcode_TextChanged (Old As String, New As String)
code=editCode.Text
End Sub
Sub editcode_EnterPressed
End Sub
Sub editcode_FocusChanged (HasFocus As Boolean)
End Sub