Android Question B4XPreferencesDialog TextSize

Brian Michael

Active Member
Licensed User
Hello, Today I come with a concern that I have not managed to make it work.
I have a problem with my app and it is that the size of the font that the device has affects me.
This affects the visibility of the data. Therefore I thought about using B4XPreferenceDialog so that the user could choose a number from -5 to 5, based on the original size of the label it would increase or subtract the value that the user selected in the preferences.

The code I use is this:

B4X:
Sub SaveData
    Dim ser As B4XSerializator
    File.WriteBytes(xui.DefaultFolder, OptionsFile, ser.ConvertObjectToBytes(Array(Options)))
End Sub

Sub LoadSavedData
    Try
        If File.Exists(xui.DefaultFolder, OptionsFile) Then
            Dim ser As B4XSerializator
            Dim opt() As Object = ser.ConvertBytesToObject(File.ReadBytes(xui.DefaultFolder, OptionsFile))
            Options = opt(0)
        End If
    Catch
        Log(LastException)
    End Try
End Sub

Sub openPreferences
    Wait For (prefdialog.ShowDialog(Options, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        SaveData
        PrintOptions(Options)
        setSize(Options.GetDefault("Size",0.0))
    End If
End Sub

Sub PrintOptions (Option As Map)
    Dim sb As StringBuilder
    sb.Initialize
    For Each key As String In Option.Keys
        If key = "" Then Continue 'separators
        sb.Append(key).Append(": ").Append(Option.Get(key)).Append(CRLF)
    Next
    Log(sb.ToString)
End Sub

Public Sub OriginalTextSize
    Sleep(0)
    For Each n As B4XView In Activity.GetAllViewsRecursive 'an array
        If n Is Label Then
            Dim lbl As Label = n
            Dim tags As List = Array As String("title","title2","title3","h1","h2","h3","label","label2","label3")
            If tags.IndexOf(lbl.Tag) <> -1 Then lbl.tag = lbl.TextSize
        End If
    Next
End Sub

Public Sub setSize(Size As Float)
    Log("setSizeText")
    For Each n As B4XView In Activity.GetAllViewsRecursive 'an array
    If n = Null Then Continue
    If Not(n Is Label) Then Continue   
    Dim lbl As Label = n
    Log(lbl.Tag)
    If (lbl.Tag = "") Then Continue
    Dim original As String = lbl.tag
    If Not(IsNumber(original)) Then Continue
    lbl.TextSize = original + Size
    Next
End Sub


The code only works when you apply the size, but when I try to call it in the AppStart, it doesn't work.
Is there any way to achieve this without errors?

Thanks for whatching!
 
Top