'Class module
Sub Class_Globals
Dim pmain As Panel
Dim objectCount As Int
Dim pa(100) As Panel
Dim bu(100) As Button
Dim la(100) As Label
Dim et(100) As EditText
Dim wv(100) As WebView
Dim tag(100) As String
Dim name(100) As String
Dim event(100) As String
Dim oType(100) As String
Dim editCode As EditText
Dim code As String
Dim apan As aPanel 'activity panel
End Sub
Sub load(edi As Panel,app As Panel )
code=File.ReadString(File.DirAssets,"test.b4a")
editCode.Initialize("editcode")
edi.AddView(editCode,0,0,100%x,80%y)
editCode.Text=code
pmain.Initialize("acty")
pmain.Color=Colors.Blue
app.AddView(pmain,0,0,100%x,80%y)
End Sub
Public Sub makeDim(objectName As String,objectType As String)
name(objectCount)=objectName
oType(objectCount)=objectType
objectCount=objectCount+1
End Sub
Public Sub Initialize2(objectName As String,eventname As String)
Dim ix As Int
Dim v As View
Dim es As String
Dim oTyp As String
ix=findindex(objectName)
oTyp=oType(ix)
If oTyp="Panel" Then
pa(ix).Initialize("pevent")
pa(ix).tag=ix
End If
If oTyp="Button" Then
bu(ix).Initialize("bevent")
bu(ix).tag=ix
End If
If oTyp="EditText" Then
et(ix).Initialize("eevent")
et(ix).tag=ix
End If
If oTyp="Label" Then
la(ix).Initialize("levent")
la(ix).tag=ix
End If
If oTyp="WebView" Then
wv(ix).Initialize("wevent")
wv(ix).tag=ix
End If
name(ix)=objectName
End Sub
Public Sub Initialize()
End Sub
Sub acty_click
pmain.BringToFront
End Sub
Sub findindex(objectName As String) As Int
For m = 0 To objectCount-1
If name(m).trim=objectName.trim Then Return m
Next
End Sub
Sub pevent_click
Dim send As Panel
Dim index As Int
Dim s1 As String
send=Sender
index=send.tag
s1=name(index)&"_click"
runSub(s1.Trim)
End Sub
Sub bevent_click
Dim send As Button
Dim index As Int
Dim s1 As String
send=Sender
index=send.tag
s1=name(index)&"_click"
runSub(s1.Trim)
End Sub
Sub bStart
RemoveViews
CallSub2(Main,"switcher",2)
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=findindex(objectName)
objectType=oType(index)
If functionsName="Initialize" Then
eventName=params(0)
initview(objectName,eventName)
End If
If functionsName="AddView" Then
params=getValues(objectProp)
faddview(params)
End If
If functionsName.IndexOf("Color=")>-1 Then
Dim v As View
params=getValues(objectProp)
v=fgetView(index)
v.Color=Colors.RGB(params(0),params(1),params(2))
End If
If objectProp.IndexOf("Text=")>-1 Then
setText(index,objectProp.SubString(objectProp.IndexOf("Text=")+6))
End If
If objectProp.IndexOf("LoadUrl(")>-1 Then
Dim tx As String
tx=objectProp.SubString2(objectProp.IndexOf("LoadUrl(")+9,objectProp.LastIndexOf(")")-1)
loadUrl(index,tx)
End If
End Sub
Sub loadUrl(ix As Int,tx As String)
wv(ix).loadUrl(tx)
End Sub
Sub setText(ix As Int,tx As String)
Dim es As String
Dim oTyp As String
oTyp=oType(ix).Trim
If oTyp="Button" Then
bu(ix).Text=tx
End If
If oTyp="EditText" Then
et(ix).Text=tx
End If
If oTyp="Label" Then
la(ix).Text=tx
End If
End Sub
Sub fgetView(ix As Int) As View
Dim v As View
Dim es As String
Dim oTyp As String
oTyp=oType(ix).Trim
If oTyp="Panel" Then
v=pa(ix)
es="p"
End If
If oTyp="Button" Then
v=bu(ix)
es="b"
End If
If oTyp="EditText" Then
v=et(ix)
es="e"
End If
If oTyp="Label" Then
v=la(ix)
es="l"
End If
If oTyp="WebView" Then
v=la(ix)
es="w"
End If
Return v
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).Trim
makeDim(objectName,objectType)
apos=epos
Loop
End Sub
Sub faddview(pm() As String)
Dim v As View
Dim i(4) As Int
Dim ix As Int
Dim oTyp As String
ix=findindex(pm(0))
oTyp=oType(ix)
i(0)=pm(1)
i(1)=pm(2)
i(2)=pm(3)
i(3)=pm(4)
If oTyp="Panel" Then v=pa(ix)
If oTyp="Button" Then v=bu(ix)
If oTyp="EditText" Then v=et(ix)
If oTyp="Label" Then v=la(ix)
If oTyp="WebView" Then v=wv(ix)
pmain.addview(v,i(0),i(1),i(2),i(3))
End Sub
Sub initview(objectName As String,eventName As String)
Dim index As Int
index=findindex(objectName)
Initialize2(objectName,eventName)
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
Sub RemoveViews
Dim i As Int
For i=pmain.NumberOfViews-1 To 0 Step -1
pmain.RemoveViewAt(i)
Next
End Sub