Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private edtName As B4XView
Private lblHello As B4XView
Private lstLanguages As ListView
Public loc As Localizator
Private name As String
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
loc.Initialize(File.DirAssets, "strings.db")
ResetLayout
End Sub
Private Sub ResetLayout
Root.RemoveAllViews
Root.LoadLayout("1")
If loc.Language = "he" Then FlipLayout
loc.LocalizeLayout(Root)
lstLanguages.SingleLineLayout.Label.Gravity = Gravity.CENTER
lstLanguages.SingleLineLayout.Label.TextColor = Colors.Gray
Dim availableLangs() As String = Array As String ("en", "fr", "he", "de")
For i = 0 To availableLangs.Length - 1
lstLanguages.AddSingleLine2(loc.Localize(availableLangs(i)), availableLangs(i))
Next
edtName.Text = name
UpdateNameLabel
End Sub
Sub FlipLayout
For Each v As B4XView In Root.GetAllViewsRecursive
v.Left = v.Parent.Width - v.Left - v.Width
Next
End Sub
Sub lstLanguages_ItemClick (Position As Int, Value As Object)
loc.ForceLocale(Value)
ResetLayout
End Sub
Sub edtName_TextChanged (Old As String, New As String)
If New <> "" Then
name = New
UpdateNameLabel
End If
End Sub
Sub UpdateNameLabel
lblHello.Text = loc.LocalizeParams("Hello {1}!", Array(name))
End Sub