Android Question trying my luck again: (prefdialog) need an expert eye help

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi,

trying my luck again...


i've created this following general purpose function to be used in my B4A project
it works very nice but i have a few (non critical issues)

1.
the title - how can i lock the title so it will not be scrolled when the user scrolls the message content?
i want the title to be fixed as the bottom bar with the buttons

2.
how can i change the width of the buttons so i can use extra text if needed?

3.
is there a way to change the background color other than the theme?
for example red background and yellow text

4. can i change the background color of the bottom bar - the buttons bar?

i will appreciate any input
and of course i will be dancing on the table (you should mot even imagine this horror sight) if anyone will be kind and modify the code to support what i dream about...

thanks

B4X:
Public Sub zgShowDialog (Title As String, TitlebackColor As Int, TitleTextColor As Int, _
                        Msg As String, msgAlign As String, FontSize As Int, fontColor As Int, _ 
                        btnYES As String, btnYES_TextColor As Int, btnNO As String, btnNO_TextColor As Int, _
                        Theme As String, DialogHeight As Int, CanScroll As Boolean, Top As Int) As ResumableSub

    Dim bRet As Boolean = False
    Private Xui As XUI
    Dim prefdialog As PreferencesDialog

    
    If DialogHeight<150dip Then DialogHeight=150dip
    If FontSize<12 Then FontSize=12
    If btnYES="" And btnNO="" Then btnNO="OK"
    If msgAlign="" Then msgAlign="Right"
    If (msgAlign.ToUpperCase<>"RIGHT") And (msgAlign.ToUpperCase<>"LEFT") And (msgAlign.ToUpperCase<>"CENTER") Then msgAlign="Right"
    If TitlebackColor=0 Then TitlebackColor = Colors.Red
    If TitleTextColor=0 Then TitleTextColor = Colors.Yellow
    
    If Top = 0 Then Top = 100dip

    
    msgAlign=msgAlign.ToUpperCase
    
    prefdialog.Initialize(Activity, "", 300dip, DialogHeight)


    If Title <> "" Then
        prefdialog.AddSeparator(Title)
    End If
    
    prefdialog.AddMultilineTextItem("First", "", DialogHeight)
    
    
    If Theme.ToUpperCase="LIGHT" Then
        prefdialog.Theme = prefdialog.THEME_LIGHT
    Else
        prefdialog.Theme = prefdialog.THEME_DARK
    End If
    
    If Title<>"" Then
        If TitlebackColor<>0 Then prefdialog.SeparatorBackgroundColor = TitlebackColor
        If TitleTextColor<>0 Then prefdialog.SeparatorTextColor = TitleTextColor
    End If

    Dim Data As Map = CreateMap("First": Msg)
    
    Dim sf As Object = prefdialog.ShowDialog(Data, btnYES, btnNO)

    If Top > 0 Then
        prefdialog.Dialog.Base.Top = Top
    End If
    

    For i = 0 To prefdialog.PrefItems.Size - 1
        
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)
        
        If pi.ItemType = prefdialog.TYPE_MULTILINETEXT Then
            
            Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag
            
            ft.TextField.SetTextAlignment("CENTER",msgAlign.ToUpperCase)
            
            Dim xfont As B4XFont=Xui.CreateFont(Typeface.DEFAULT_BOLD,FontSize)
            ft.textfield.Font = xfont
            
            ft.TextField.TextColor = fontColor
            
            ft.TextField.Enabled = False
        End If
    Next

    If CanScroll = False Then
        Sleep(0)
        prefdialog.CustomListView1.sv.Height = prefdialog.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
    End If


    
    If (btnNO<>"") And (btnNO_TextColor<>0) Then
        Dim btnPrefCancel As B4XView = prefdialog.Dialog.GetButton(Xui.DialogResponse_Cancel)
        btnPrefCancel.Width = btnPrefCancel.Width + 20dip
        btnPrefCancel.Left = btnPrefCancel.Left - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
    End If
    
    If (btnYES<>"") And (btnYES_TextColor<>0) Then
        Dim btnPrefOk As B4XView = prefdialog.Dialog.GetButton(Xui.DialogResponse_Positive)
        btnPrefOk.Width = btnPrefOk.Width + 20dip
        btnPrefOk.Left = 20dip        'btnOk.Left - 10dip
        btnPrefOk.TextColor = btnYES_TextColor
    End If
    
    
        
    Wait For (sf) Complete (Result As Int)
    If Result = Xui.DialogResponse_Positive Then
        bRet = True
    Else
        bRet = False
    End If
    
    
    Return bRet
    
End Sub
 
Solution
B4X:
b4xview2.SetTextAlignment("TOP", Dialog.Message.Alignment)

Let the function to allow for horizontal and vertical alignment.
YES!! YES!!
that works like charm
so now we have a full working solution
given - it the text is too long for the window size in height it will be cut, but that is OK as long as the text in the message is normal in length it is fine
i think we can leave this as is
i can't even think of keeping this and bein a pest - you really saved me here

to sunnarize:
a full flexible and controlled prefdialog mechanism with scrolling text - check!
to note: keep the text within a "normal" length or set the dialog height to a larger value

Dear aeric - i can't say how much i appreciate your help and value your work...

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
It seems you are making a duplicate post.
https://www.b4x.com/android/forum/threads/prefdialog-need-an-expert-eye-to-look-help.157368/

I think for 2 to 4, they may be not difficult. There are already answers on the forum. Try search with B4XPreferencesDialog keyword and your requirements.
I am not sure about #1.
well - almost
the first one got lost and ignored so it was declared "old" and i got a message to open a new one

as per 2 - 4 : i did search - couldn't find the exact answers i needed so i've asked here hoping...
as per 1: - this one is a tricky one (for me) but i do need to resolve it...

thanks for your attention
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not sure I understand you on #1, is it similar to this tutorial?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
#3 and #4, if I understand correctly:

B4X:
Private Sub Button1_Click
    Dim sf As Object = zgShowDialog("Test Dialog", _
    xui.Color_Blue, _
    xui.Color_Magenta, _
    $"This is a sample message in B4XPreferenceDialog.
    Are you happy developing apps with B4A?"$, _
    "", _
    18, _
    xui.Color_Yellow, _
    "Yup", _
    xui.Color_Green, _
    "Nah!", _
    xui.Color_Red, _
    "LIGHT", _
    200, _
    True, _
    50)
    Wait For (sf) Complete (result As Boolean)
    Log(result)
End Sub

Public Sub zgShowDialog (Title As String, _
    TitleBackColor As Int, _
    TitleTextColor As Int, _
    Msg As String, _
    msgAlign As String, _
    FontSize As Int, _
    FontColor As Int, _
    btnYES As String, _
    btnYES_TextColor As Int, _
    btnNO As String, _
    btnNO_TextColor As Int, _
    Theme As String, _
    DialogHeight As Int, _
    CanScroll As Boolean, _
    Top As Int) As ResumableSub
    If DialogHeight < 150dip Then DialogHeight = 150dip
    If FontSize < 12 Then FontSize = 12
    If btnYES = "" And btnNO = "" Then btnNO = "OK"
    Select msgAlign.ToUpperCase
        Case "LEFT", "CENTER"
            msgAlign = msgAlign.ToUpperCase
        Case Else
            msgAlign = "RIGHT"
    End Select
    If TitleBackColor = 0 Then TitleBackColor = Colors.Red
    If TitleTextColor = 0 Then TitleTextColor = Colors.Yellow
    If Top = 0 Then Top = 100dip

    PrefDialog1.Initialize(Root, Title, 300dip, DialogHeight)

    If Title <> "" Then
        'PrefDialog1.AddSeparator(Title)
        'PrefDialog1.SeparatorBackgroundColor = TitleBackColor
        'PrefDialog1.SeparatorTextColor = TitleTextColor
        PrefDialog1.Dialog.TitleBarColor = TitleBackColor
        PrefDialog1.Dialog.TitleBarTextColor = TitleTextColor
    End If
   
    PrefDialog1.AddMultilineTextItem("First", "", DialogHeight)
   
    If Theme.ToUpperCase = "LIGHT" Then
        PrefDialog1.Theme = PrefDialog1.THEME_LIGHT
    Else
        PrefDialog1.Theme = PrefDialog1.THEME_DARK
    End If
   
    Dim Data As Map = CreateMap("First": Msg)
    Dim sf As Object = PrefDialog1.ShowDialog(Data, btnYES, btnNO)

    PrefDialog1.Dialog.Base.Top = Top
   
    For i = 0 To PrefDialog1.PrefItems.Size - 1
        Dim pi As B4XPrefItem = PrefDialog1.PrefItems.Get(i)
        If pi.ItemType = PrefDialog1.TYPE_MULTILINETEXT Then          
            Dim ft As B4XFloatTextField = PrefDialog1.CustomListView1.GetPanel(i).GetView(0).Tag          
            ft.TextField.SetTextAlignment("CENTER", msgAlign)          
            Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
            ft.textfield.Font = xfont          
            ft.TextField.TextColor = FontColor          
            ft.TextField.Enabled = False
        End If
    Next
    Dim MessageItem As B4XView = PrefDialog1.CustomListView1.GetPanel(0)
    MessageItem.Color = xui.Color_Red
    PrefDialog1.Dialog.Base.Color = xui.Color_DarkGray

    If CanScroll = False Then
        Sleep(0)
        PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
    End If

    If btnNO <> "" Then
        Dim btnPrefCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnPrefCancel.Width = btnPrefCancel.Width + 20dip
        btnPrefCancel.Left = btnPrefCancel.Left - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
        btnPrefCancel.Color = xui.Color_Transparent
    End If
   
    If btnYES <> "" Then
        Dim btnPrefOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
        btnPrefOk.Width = btnPrefOk.Width + 20dip
        btnPrefOk.Left = 20dip
        btnPrefOk.TextColor = btnYES_TextColor
        btnPrefOk.Color = xui.Color_Transparent
    End If
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Return True
    End If
    Return False
End Sub

Screenshot_1701079515.png
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
#3 and #4, if I understand correctly:

B4X:
Private Sub Button1_Click
    Dim sf As Object = zgShowDialog("Test Dialog", _
    xui.Color_Blue, _
    xui.Color_Magenta, _
    $"This is a sample message in B4XPreferenceDialog.
    Are you happy developing apps with B4A?"$, _
    "", _
    18, _
    xui.Color_Yellow, _
    "Yup", _
    xui.Color_Green, _
    "Nah!", _
    xui.Color_Red, _
    "LIGHT", _
    200, _
    True, _
    50)
    Wait For (sf) Complete (result As Boolean)
    Log(result)
End Sub

Public Sub zgShowDialog (Title As String, _
    TitleBackColor As Int, _
    TitleTextColor As Int, _
    Msg As String, _
    msgAlign As String, _
    FontSize As Int, _
    FontColor As Int, _
    btnYES As String, _
    btnYES_TextColor As Int, _
    btnNO As String, _
    btnNO_TextColor As Int, _
    Theme As String, _
    DialogHeight As Int, _
    CanScroll As Boolean, _
    Top As Int) As ResumableSub
    If DialogHeight < 150dip Then DialogHeight = 150dip
    If FontSize < 12 Then FontSize = 12
    If btnYES = "" And btnNO = "" Then btnNO = "OK"
    Select msgAlign.ToUpperCase
        Case "LEFT", "CENTER"
            msgAlign = msgAlign.ToUpperCase
        Case Else
            msgAlign = "RIGHT"
    End Select
    If TitleBackColor = 0 Then TitleBackColor = Colors.Red
    If TitleTextColor = 0 Then TitleTextColor = Colors.Yellow
    If Top = 0 Then Top = 100dip

    PrefDialog1.Initialize(Root, Title, 300dip, DialogHeight)

    If Title <> "" Then
        'PrefDialog1.AddSeparator(Title)
        'PrefDialog1.SeparatorBackgroundColor = TitleBackColor
        'PrefDialog1.SeparatorTextColor = TitleTextColor
        PrefDialog1.Dialog.TitleBarColor = TitleBackColor
        PrefDialog1.Dialog.TitleBarTextColor = TitleTextColor
    End If
  
    PrefDialog1.AddMultilineTextItem("First", "", DialogHeight)
  
    If Theme.ToUpperCase = "LIGHT" Then
        PrefDialog1.Theme = PrefDialog1.THEME_LIGHT
    Else
        PrefDialog1.Theme = PrefDialog1.THEME_DARK
    End If
  
    Dim Data As Map = CreateMap("First": Msg)
    Dim sf As Object = PrefDialog1.ShowDialog(Data, btnYES, btnNO)

    PrefDialog1.Dialog.Base.Top = Top
  
    For i = 0 To PrefDialog1.PrefItems.Size - 1
        Dim pi As B4XPrefItem = PrefDialog1.PrefItems.Get(i)
        If pi.ItemType = PrefDialog1.TYPE_MULTILINETEXT Then         
            Dim ft As B4XFloatTextField = PrefDialog1.CustomListView1.GetPanel(i).GetView(0).Tag         
            ft.TextField.SetTextAlignment("CENTER", msgAlign)         
            Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
            ft.textfield.Font = xfont         
            ft.TextField.TextColor = FontColor         
            ft.TextField.Enabled = False
        End If
    Next
    Dim MessageItem As B4XView = PrefDialog1.CustomListView1.GetPanel(0)
    MessageItem.Color = xui.Color_Red
    PrefDialog1.Dialog.Base.Color = xui.Color_DarkGray

    If CanScroll = False Then
        Sleep(0)
        PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
    End If

    If btnNO <> "" Then
        Dim btnPrefCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnPrefCancel.Width = btnPrefCancel.Width + 20dip
        btnPrefCancel.Left = btnPrefCancel.Left - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
        btnPrefCancel.Color = xui.Color_Transparent
    End If
  
    If btnYES <> "" Then
        Dim btnPrefOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
        btnPrefOk.Width = btnPrefOk.Width + 20dip
        btnPrefOk.Left = 20dip
        btnPrefOk.TextColor = btnYES_TextColor
        btnPrefOk.Color = xui.Color_Transparent
    End If
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Return True
    End If
    Return False
End Sub

View attachment 148106
dear aeric, very dear...
from first look it seems you've solved ALL my issues including those i didn't even mention
MANY THANKS!!
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
#3 and #4, if I understand correctly:

B4X:
Private Sub Button1_Click
    Dim sf As Object = zgShowDialog("Test Dialog", _
    xui.Color_Blue, _
    xui.Color_Magenta, _
    $"This is a sample message in B4XPreferenceDialog.
    Are you happy developing apps with B4A?"$, _
    "", _
    18, _
    xui.Color_Yellow, _
    "Yup", _
    xui.Color_Green, _
    "Nah!", _
    xui.Color_Red, _
    "LIGHT", _
    200, _
    True, _
    50)
    Wait For (sf) Complete (result As Boolean)
    Log(result)
End Sub

Public Sub zgShowDialog (Title As String, _
    TitleBackColor As Int, _
    TitleTextColor As Int, _
    Msg As String, _
    msgAlign As String, _
    FontSize As Int, _
    FontColor As Int, _
    btnYES As String, _
    btnYES_TextColor As Int, _
    btnNO As String, _
    btnNO_TextColor As Int, _
    Theme As String, _
    DialogHeight As Int, _
    CanScroll As Boolean, _
    Top As Int) As ResumableSub
    If DialogHeight < 150dip Then DialogHeight = 150dip
    If FontSize < 12 Then FontSize = 12
    If btnYES = "" And btnNO = "" Then btnNO = "OK"
    Select msgAlign.ToUpperCase
        Case "LEFT", "CENTER"
            msgAlign = msgAlign.ToUpperCase
        Case Else
            msgAlign = "RIGHT"
    End Select
    If TitleBackColor = 0 Then TitleBackColor = Colors.Red
    If TitleTextColor = 0 Then TitleTextColor = Colors.Yellow
    If Top = 0 Then Top = 100dip

    PrefDialog1.Initialize(Root, Title, 300dip, DialogHeight)

    If Title <> "" Then
        'PrefDialog1.AddSeparator(Title)
        'PrefDialog1.SeparatorBackgroundColor = TitleBackColor
        'PrefDialog1.SeparatorTextColor = TitleTextColor
        PrefDialog1.Dialog.TitleBarColor = TitleBackColor
        PrefDialog1.Dialog.TitleBarTextColor = TitleTextColor
    End If
  
    PrefDialog1.AddMultilineTextItem("First", "", DialogHeight)
  
    If Theme.ToUpperCase = "LIGHT" Then
        PrefDialog1.Theme = PrefDialog1.THEME_LIGHT
    Else
        PrefDialog1.Theme = PrefDialog1.THEME_DARK
    End If
  
    Dim Data As Map = CreateMap("First": Msg)
    Dim sf As Object = PrefDialog1.ShowDialog(Data, btnYES, btnNO)

    PrefDialog1.Dialog.Base.Top = Top
  
    For i = 0 To PrefDialog1.PrefItems.Size - 1
        Dim pi As B4XPrefItem = PrefDialog1.PrefItems.Get(i)
        If pi.ItemType = PrefDialog1.TYPE_MULTILINETEXT Then         
            Dim ft As B4XFloatTextField = PrefDialog1.CustomListView1.GetPanel(i).GetView(0).Tag         
            ft.TextField.SetTextAlignment("CENTER", msgAlign)         
            Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
            ft.textfield.Font = xfont         
            ft.TextField.TextColor = FontColor         
            ft.TextField.Enabled = False
        End If
    Next
    Dim MessageItem As B4XView = PrefDialog1.CustomListView1.GetPanel(0)
    MessageItem.Color = xui.Color_Red
    PrefDialog1.Dialog.Base.Color = xui.Color_DarkGray

    If CanScroll = False Then
        Sleep(0)
        PrefDialog1.CustomListView1.sv.Height = PrefDialog1.CustomListView1.sv.ScrollViewInnerPanel.Height + 10dip
    End If

    If btnNO <> "" Then
        Dim btnPrefCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnPrefCancel.Width = btnPrefCancel.Width + 20dip
        btnPrefCancel.Left = btnPrefCancel.Left - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
        btnPrefCancel.Color = xui.Color_Transparent
    End If
  
    If btnYES <> "" Then
        Dim btnPrefOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
        btnPrefOk.Width = btnPrefOk.Width + 20dip
        btnPrefOk.Left = 20dip
        btnPrefOk.TextColor = btnYES_TextColor
        btnPrefOk.Color = xui.Color_Transparent
    End If
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Return True
    End If
    Return False
End Sub

View attachment 148106
hi
found one issue with scrolling

take this message for example

Msg = "This is a demo message to show flexibility" & CRLF & "each element is fully controllable" & CRLF & "including scrolling the text"

and use the function with it
keep font size to 18
it shows all text perfectly

no double the message like

Msg = Msg & CRLF & Msg

and send it now
i mean to use the message window for a longer text
now the scroll is actually missing almost the entire "second" part

is there a way to fix the scrolled area so it will contain the entire text as long as it gets?

thanks
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Upvote 0

aeric

Expert
Licensed User
Longtime User
By the way, I can also replace the code for the message text:

B4X:
'    For i = 0 To PrefDialog1.PrefItems.Size - 1
'        Dim pi As B4XPrefItem = PrefDialog1.PrefItems.Get(i)
'        If pi.ItemType = PrefDialog1.TYPE_MULTILINETEXT Then
'            Log(i)
'            Dim ft As B4XFloatTextField = PrefDialog1.CustomListView1.GetPanel(i).GetView(0).Tag
'            ft.TextField.SetTextAlignment("CENTER", msgAlign)
'            Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
'            ft.textfield.Font = xfont
'            ft.TextField.TextColor = FontColor
'            ft.TextField.Enabled = False
'        End If
'    Next
    Dim MessageItem As B4XView = PrefDialog1.CustomListView1.GetPanel(0)
    MessageItem.Color = xui.Color_Red
    Dim MessageText As B4XView = MessageItem.GetView(0).Tag.As(B4XFloatTextField).TextField
    MessageText.TextColor = FontColor
    MessageText.SetTextAlignment("CENTER", msgAlign)
    MessageText.Font = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
    MessageText.Enabled = False
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
By the way, I can also replace the code for the message text:

B4X:
'    For i = 0 To PrefDialog1.PrefItems.Size - 1
'        Dim pi As B4XPrefItem = PrefDialog1.PrefItems.Get(i)
'        If pi.ItemType = PrefDialog1.TYPE_MULTILINETEXT Then
'            Log(i)
'            Dim ft As B4XFloatTextField = PrefDialog1.CustomListView1.GetPanel(i).GetView(0).Tag
'            ft.TextField.SetTextAlignment("CENTER", msgAlign)
'            Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
'            ft.textfield.Font = xfont
'            ft.TextField.TextColor = FontColor
'            ft.TextField.Enabled = False
'        End If
'    Next
    Dim MessageItem As B4XView = PrefDialog1.CustomListView1.GetPanel(0)
    MessageItem.Color = xui.Color_Red
    Dim MessageText As B4XView = MessageItem.GetView(0).Tag.As(B4XFloatTextField).TextField
    MessageText.TextColor = FontColor
    MessageText.SetTextAlignment("CENTER", msgAlign)
    MessageText.Font = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
    MessageText.Enabled = False
this code change blocked the scroll and actually displayed only part of the text
with no scroll option
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I think you need to try with different values of DialogHeight.

B4X:
PrefDialog1.Initialize(Root, Title, 300dip, DialogHeight)
yes, if i set the height to a larger value it works but then it is not as general as i wanted
i wanted to have a fixed container and scrollable text
one other reason is when a user set the phone font size or screen size larger it all changes
so the best solution is to allow scrolling, this way it will show all text at any size
do you think the original beautiful function you created from my lame one - can it be set to scroll the entire text?
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
BTW
the link to calculate the window height - i'm afraid i got lost
it is not originally for that type of object so i can't figure out what to do or what to change in the function
can you help?
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I think you need to try with different values of DialogHeight.

B4X:
PrefDialog1.Initialize(Root, Title, 300dip, DialogHeight)
changing DialogHeight value from 200 to 400 for example doesn't have any impact and does not chage the message window height at all

changing the 200 to 200dip for example will enlarge the height but the title disapears
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
looks like the best solution is to cancel scroll and keep the text "normal" size
how can i calculate the dialogHeight to suit the text and keep the title?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I have been trying to use Custom Dialog. After hours of trial and error, here is what I got.

1701189698335.png


B4X:
Sub Class_Globals
    Private Root As B4XView
    Public xui As XUI
    Private Label1 As B4XView
    Private ScrollView1 As B4XView
    Private PrefDialog1 As PreferencesDialog
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub B4XPage_Resize(Width As Int, Height As Int)
    If PrefDialog1.IsInitialized And PrefDialog1.Dialog.Visible Then PrefDialog1.Dialog.Resize(Width, Height)
End Sub

Private Sub Button1_Click
    Dim sf As Object = zgShowDialog("Test Dialog", _
    xui.Color_Blue, _
    xui.Color_Magenta, _
    $"This is a sample message in B4XPreferenceDialog.
This message is very long so you can scroll it.
Do you want to close this dialog?"$, _
    "CENTER", _
    18, _
    xui.Color_Yellow, _
    "Yup", _
    xui.Color_Green, _
    "Nah!", _
    xui.Color_Red, _
    "LIGHT", _
    150, _
    True, _
    100)
    Wait For (sf) Complete (result As Boolean)
    Log(result)
End Sub

Public Sub zgShowDialog (Title As String, _
    TitleBackColor As Int, _
    TitleTextColor As Int, _
    Msg As String, _
    msgAlign As String, _
    FontSize As Int, _
    FontColor As Int, _
    btnYES As String, _
    btnYES_TextColor As Int, _
    btnNO As String, _
    btnNO_TextColor As Int, _
    Theme As String, _
    DialogHeight As Int, _
    CanScroll As Boolean, _
    Top As Int) As ResumableSub
    If DialogHeight < 150dip Then DialogHeight = 150dip
    If FontSize < 12 Then FontSize = 12
    If btnYES = "" And btnNO = "" Then btnNO = "OK"
    Select msgAlign.ToUpperCase
        Case "LEFT", "CENTER"
            msgAlign = msgAlign.ToUpperCase
        Case Else
            msgAlign = "RIGHT"
    End Select
    If TitleBackColor = 0 Then TitleBackColor = Colors.Red
    If TitleTextColor = 0 Then TitleTextColor = Colors.Yellow
    If Top = 0 Then Top = 100dip

    PrefDialog1.Initialize(Root, "", 300dip, DialogHeight)
    If Theme.ToUpperCase = "LIGHT" Then
        PrefDialog1.Theme = PrefDialog1.THEME_LIGHT
    Else
        PrefDialog1.Theme = PrefDialog1.THEME_DARK
    End If
 
    Dim b4xview1 As B4XView = xui.CreatePanel("")
    b4xview1.SetLayoutAnimated(0, 0, 0, 300dip, 150dip)
    b4xview1.LoadLayout("Custom1")
   
    If Title <> "" Then
        Label1.Text = Title
        Label1.Parent.Color = TitleBackColor
        Label1.TextColor = TitleTextColor
    End If
   
    Dim lbl As Label
    lbl.Initialize("lbl")
    Dim b4xview2 As B4XView = lbl
    b4xview2.SetTextAlignment("CENTER", msgAlign)
    b4xview2.Font = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
    'b4xview2.Color = xui.Color_Transparent
    b4xview2.TextColor = FontColor
    b4xview2.Text = Msg
   
    ScrollView1.ScrollViewContentHeight = DialogHeight + 20dip
    ScrollView1.ScrollViewInnerPanel.Color = xui.Color_Red
    ScrollView1.As(ScrollView).Panel.AddView(lbl, 5dip, 5dip, b4xview1.Width - 10dip, b4xview1.Height - 10dip)
    Dim sf As Object = PrefDialog1.Dialog.ShowCustom(b4xview1, btnYES, "", btnNO)

    PrefDialog1.Dialog.Base.Color = xui.Color_DarkGray
    PrefDialog1.Dialog.Base.Top = Top
   
    If btnNO <> "" Then
        Dim btnPrefCancel As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnPrefCancel.Width = btnPrefCancel.Width + 20dip
        btnPrefCancel.Left = btnPrefCancel.Left - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
        btnPrefCancel.Color = xui.Color_Transparent
    End If
   
    If btnYES <> "" Then
        Dim btnPrefOk As B4XView = PrefDialog1.Dialog.GetButton(xui.DialogResponse_Positive)
        btnPrefOk.Width = btnPrefOk.Width + 20dip
        btnPrefOk.Left = 20dip
        btnPrefOk.TextColor = btnYES_TextColor
        btnPrefOk.Color = xui.Color_Transparent
    End If
   
    If CanScroll = False Then
        Sleep(0)
        Dim extraHeight As Int = 80dip
        ScrollView1.Height = ScrollView1.ScrollViewInnerPanel.Height + extraHeight
        b4xview1.Height = b4xview1.Height + extraHeight
        PrefDialog1.Dialog.Base.Height = PrefDialog1.Dialog.Base.Height + extraHeight
        PrefDialog1.mBase.Height = PrefDialog1.mBase.Height + extraHeight
        If btnNO <> "" Then btnPrefCancel.Top = btnPrefCancel.Top + extraHeight
        If btnYES <> "" Then btnPrefOk.Top = btnPrefOk.Top + extraHeight
    End If
   
    Wait For (sf) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Return True
    End If
    Return False
End Sub
 

Attachments

  • B4XPreferencesDialogCustomColor.zip
    12.3 KB · Views: 98
Last edited:
Upvote 0
Top