Android Question Problems with B4XPreferencesDialog

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using this now since some 6 weeks and it is a lot better than using lots of B4XPages with layouts to show and alter all the settings I have.
I have some problems though altering the text sizes of the simple text item title (B4XFloatTextField) and the dialog buttons (OK and Cancel)
at the bottom. Ideally I would like to do this by adding Private variables to PreferencesDialog.bas as I did for the simple text value edit text (B4XFloatTextField.TextField).

B4X:
Sub Class_Globals
    Private xui As XUI
    Public mBase As B4XView
    Private miTextFieldFontSize As Int = 14 '14 is the default as set by B4XDialog

Public Sub getTextFieldFontSize As Int
    Return miTextFieldFontSize
End Sub

Public Sub setTextFieldFontSize(iFontSize As Int)
    miTextFieldFontSize = iFontSize
End Sub

Public Sub ShowDialog (Data As Map, Yes As Object, Cancel As Object) As ResumableSub

    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf
                tf.TextField.TextSize = miTextFieldFontSize 'If not set then this will be default 14

Having trouble though doing the same for the 2 mentioned items.
Any suggestions how to do this?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I'm not sure where are you setting it. Maybe before the items were created.

You can do it without changing anything in the code itself: https://www.b4x.com/android/forum/t...-size-of-preference-dialog.137495/post-870087
I am running it when things are ready and I can make it work fine with the textfield textsize:

B4X:
Private Sub btnMapSettings_Click
    
    lblSettingsType.Text = "Map"
    LoadPreferencesDialog(0, 0, 17, False)
    ProcessSettings
    
End Sub

Private Sub LoadPreferencesDialog(iMapIndex As Int, iStartIndex As Int, iEndIndex As Int, bSetOptions As Boolean)
    
    iOptionsIndex = iMapIndex
    
    prefdialog.Initialize(pnlSettings, "", pnlSettings.Width, pnlSettings.Height - 40dip)
    prefdialog.bDisableSoftKeyboard = True 'newly added to the b4xlib
    prefdialog.TextFieldFontSize = 17 * cMP.fTextRatio 'newly added to the b4xlib
    prefdialog.TextFieldID = Enums.eEditText.PreferencesDialogTextField 'newly added to the b4xlib
    
    prefdialog.LoadFromJson(File.ReadString(File.DirAssets, "PhonePats_Settings.json"), iStartIndex, iEndIndex)
    If bSetOptions Then
        prefdialog.ComboBoxWidth = iComboBoxWidth 'newly added to the b4xlib
        prefdialog.ComboBoxLeft = iComboBoxLeft  'newly added to the b4xlib
        prefdialog.SetOptions("Enums.iDateFormat", File.ReadList(File.DirAssets, "tabledatetypes.txt"))
    End If
    prefdialog.SetEventsListener(Me, "PrefDialog")
    
    'to get the variable values to be changed
    '----------------------------------------
    LoadSavedData
    
End Sub

Private Sub LoadSavedData
    
    Dim i As Int
    Dim tItem As B4XPrefItem

    For i = 0 To prefdialog.PrefItems.Size - 1
        tItem = prefdialog.PrefItems.Get(i)
        arrOptions(iOptionsIndex).Put(tItem.Key, GetVarValues(tItem.Key))
    Next

End Sub

Sub ProcessSettings
    
    Dim pd As Object = prefdialog.ShowDialog(arrOptions(iOptionsIndex), "OK", "CANCEL")
    Wait For (pd) Complete (Result As Int)
    
    If Result = xui.DialogResponse_Positive Then
        SaveOptions
    End If
    
    lblSettingsType.Text = ""
    cMP.HideKeyboard
    
End Sub

Public Sub SaveOptions
    
    Dim bSave As Boolean
    
    'Log("SaveOptions")
    
    For Each key As String In arrOptions(iOptionsIndex).Keys
        If key = "" Then Continue 'separators
        bSave = key <> "Enums.bAllowOnlyRealXLDates" And _
                key <> "Enums.bCalculateRadius" And _
                key <> "Enums.bShowChartLineDates" And _
                key <> "Enums.bMickeyMouse"
        SetVarValues(key, arrOptions(iOptionsIndex).Get(key), bSave)
        'Log(arrOptions(iOptionsIndex).Get(key))
    Next
    
    If vSelectedTextField.IsInitialized Then
        cMP.ClearFocus(vSelectedTextField)
    End If
    
End Sub

Will have a look at your suggested code in that link, but I prefer to have just one simple setting in one code line like:

B4X:
prefdialog.TextFieldFontSize = 17 * cMP.fTextRatio

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I'm not sure where are you setting it. Maybe before the items were created.

You can do it without changing anything in the code itself: https://www.b4x.com/android/forum/t...-size-of-preference-dialog.137495/post-870087
B4X:
prefdialog.CustomListView1.GetPanel(Int1).GetView(Int2).GetView(Int3).TextSize = 24

It does work, but I will have to work out (by trial and error?) what the values should be for Int2 and Int3 for the various different settings items.
I will need to run in a loop as there are multiple settings to show at once.
I understand Int1 will be the index of the item as in the JSON file.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Looking at the log of this code:

B4X:
        For Each v As B4XView In prefdialog.CustomListView1.GetPanel(0).GetAllViewsRecursive
            Try
                Log("view tag: " & v.Tag & ", v.Parent.Tag: " & v.Parent.Tag & ", Text: " & v.Text & ", textsize: " & v.TextSize)
            Catch
                Log("No textsize")
            End Try
        Next

No textsize
view tag: [I@bca14fd, v.Parent.Tag: , Text: LG, textsize: 11
No textsize
view tag: clear, v.Parent.Tag: , Text: , textsize: 20
view tag: v, v.Parent.Tag: , Text: , textsize: 20

It doesn't look this way I can get access to the title view text size.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Looking at the log of this code:

B4X:
        For Each v As B4XView In prefdialog.CustomListView1.GetPanel(0).GetAllViewsRecursive
            Try
                Log("view tag: " & v.Tag & ", v.Parent.Tag: " & v.Parent.Tag & ", Text: " & v.Text & ", textsize: " & v.TextSize)
            Catch
                Log("No textsize")
            End Try
        Next

No textsize
view tag: [I@bca14fd, v.Parent.Tag: , Text: LG, textsize: 11
No textsize
view tag: clear, v.Parent.Tag: , Text: , textsize: 20
view tag: v, v.Parent.Tag: , Text: , textsize: 20

It doesn't look this way I can get access to the title view text size.

RBS
Managed now to reduce the size of the title text label:

B4X:
Public Sub ShowDialog (Data As Map, Yes As Object, Cancel As Object) As ResumableSub

    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf

                'these 4 lines were added
                '------------------------
                tf.TextField.TextSize = miTextFieldFontSize 'If not set then this will be default 14
                tf.LargeLabelTextSize = miTitleLabelFontSize
                tf.SmallLabelTextSize = miTitleLabelFontSize
                tf.Update 'this is needed to make the above 2 lines take effect

A few more things to sort out:
Title text for boolean items not bold.
Alter the size of the font of title text for boolean items.
Alter the size of the font of the dialog buttons at the bottom (OK and Cancel).
Set some padding to the Title text text field to sometimes push the text down a bit.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Managed now to reduce the size of the title text label:

B4X:
Public Sub ShowDialog (Data As Map, Yes As Object, Cancel As Object) As ResumableSub

    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf

                'these 4 lines were added
                '------------------------
                tf.TextField.TextSize = miTextFieldFontSize 'If not set then this will be default 14
                tf.LargeLabelTextSize = miTitleLabelFontSize
                tf.SmallLabelTextSize = miTitleLabelFontSize
                tf.Update 'this is needed to make the above 2 lines take effect

A few more things to sort out:
Title text for boolean items not bold.
Alter the size of the font of title text for boolean items.
Alter the size of the font of the dialog buttons at the bottom (OK and Cancel).
Set some padding to the Title text text field to sometimes push the text down a bit.

RBS
All fixed now and attached my altered file PreferencesDialog.bas.
Only thing I haven't sorted yet is setting the shortoptions list (ComboBox) to not being bold, although that being bold is not a big problem.

RBS
 

Attachments

  • PreferencesDialog.zip
    8 KB · Views: 41
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
All fixed now and attached my altered file PreferencesDialog.bas.
Only thing I haven't sorted yet is setting the shortoptions list (ComboBox) to not being bold, although that being bold is not a big problem.

RBS
I think this thread answers this last question regarding the combobox:
So, I think all done.

RBS
 
Upvote 0
Top