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
I have been trying to use Custom Dialog. After hours of trial and error, here is what I got.

View attachment 148154

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
thank you so much for your effort and good will

something went wrong
i couldn't run your sample app - got too many errors

my app is not B4X - it is B4A so other things used in the sample did not fit
I'm getting frustrated ...
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
thank you so much for your effort and good will

something went wrong
i couldn't run your sample app - got too many errors

my app is not B4X - it is B4A so other things used in the sample did not fit
I'm getting frustrated ...
Upload a small project.
One of the difference between default B4A and B4XPages project is usage of Activity vs Root.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Upload a small project.
One of the difference between default B4A and B4XPages project is usage of Activity vs Root.
yes, i figured it out
i think my way to resolve this to a generic function is if i could pre-calculate the DialogHeight before creating it or during and then resize it
yes this is with no scroll but it will give a final solution to all my events
and yes, i need it to be working within b4a environment...
so far i use trial & error for each message to see the correct height - that's VERY bad
so the calculation for the right height will be the ultimate solution (if possible of course)
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
As you have the option CanScroll, you can decide whether you want to adjust the height. If you set it to True then you don't need to calculate the height.
sure
i wish it worked - the scroll does not really scroll the lines
tried it hundreds of times - it slightly moves up and that's it - no scroll
if the scroll worked it is all done
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
even if i preset the dialogheight to larger than 225dip then the title just disapears
the max is 225dip to show the title
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
I am using Custom template. I don't think the title will disappear.
not sure i understand what does it mean
i need my function to be 100% flexible
any way - the scroll does not scroll
i can upload my code if you like to see it
it's very basic and all dependent on your corrections
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
here's my code
the utmost simple & basic

the only thing i need is fixing the scroll and then i'm in heaven...


B4X:
Private Sub Button1_Click
    
    Dim Msg As String = ""
    Dim Ttl As String = ""
    Dim Scroll As Boolean = True
    Dim Bold As Boolean = False
    Dim dialogHeight As Int = 100dip
    Dim FontSize As Int = 15
    Dim btnY As String = "Yes"
    Dim btnN As String = "No"
    
    Ttl = "Demo Message"
    
    Msg = "This is a demo message to show flexibility" & CRLF & "each element is fully controllable" & CRLF & "including scrolling the text"

    Msg = Msg & CRLF & Msg & CRLF & Msg & CRLF & Msg

    Dim sf As Object = zgShowDialog(Ttl, xui.Color_RGB(0,128,128), xui.Color_white, _
                                    Msg, "center", xui.Color_DarkGray, _
                                    FontSize, xui.Color_Yellow, Bold, _
                                    btnY, xui.Color_black, xui.Color_green, _
                                    btnN, xui.Color_black, xui.Color_Red, _
                                    "light", _
                                    dialogHeight, _
                                    Scroll, _
                                    50, _
                                    0dip, _
                                    xui.Color_darkGray)


                                    
    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, msgBackgroundColor As Int, _
                         FontSize As Int, FontColor As Int, BoldFont As Boolean, _
                         btnYES As String, btnYES_TextColor As Int, btnYES_BackgroundColor As Int, _
                         btnNO As String, btnNO_TextColor As Int, btnNO_BackgroundColor As Int, _
                         Theme As String, _
                         DialogHeight As Int, _
                         CanScroll As Boolean, _
                         Top As Int, _
                         ButtonSize As Int, _
                         Footer_BackgroundColor As Int) As ResumableSub
    
    
    Private xui As XUI
    Dim prefdialog As PreferencesDialog

    If DialogHeight < 100dip Then DialogHeight = 100dip
    If DialogHeight > 225dip Then DialogHeight = 225dip

    If ButtonSize = 0dip Then ButtonSize = 75dip
    If ButtonSize > 125dip Then ButtonSize = 125dip
    
    If FontSize < 15 Then FontSize = 15
    If FontSize > 25 Then FontSize = 25
    
    If btnYES = "" And btnNO = "" Then
        btnNO = "OK"
    End If
    
    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 = 50dip        '100dip

    prefdialog.Initialize(Activity, Title, 300dip, DialogHeight)

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

    prefdialog.Dialog.Base.Top = Top
   
    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)
            
            If BoldFont = True Then
                Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
            Else
                Dim xfont As B4XFont = xui.CreateFont(Typeface.DEFAULT, FontSize)
            End If
            
            ft.textfield.Font = xfont
            ft.TextField.TextColor = FontColor
            ft.TextField.Enabled = False
        End If
    Next
    
    '    Dim MessageItem As B4XView = prefdialog.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)
    '    If BoldFont = True Then
    '        MessageText.Font = xui.CreateFont(Typeface.DEFAULT_BOLD, FontSize)
    '    Else
    '        MessageText.Font = xui.CreateFont(Typeface.DEFAULT, FontSize)
    '    End If
    '    MessageText.Enabled = False
    
    
    
    Dim MessageItem As B4XView = prefdialog.CustomListView1.GetPanel(0)
    MessageItem.Color = msgBackgroundColor        'xui.Color_Cyan
    prefdialog.Dialog.Base.Color = Footer_BackgroundColor        'xui.Color_DarkGray

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

    If btnNO <> "" Then
        Dim btnPrefCancel As B4XView = prefdialog.Dialog.GetButton(xui.DialogResponse_Cancel)
        btnPrefCancel.Width = ButtonSize        'btnPrefCancel.Width + 40dip
        btnPrefCancel.Left = 300dip - btnPrefCancel.Width - 15dip        'btnPrefCancel.Left - 20dip - 20dip
        btnPrefCancel.TextColor = btnNO_TextColor
        btnPrefCancel.Color = btnNO_BackgroundColor        'xui.Color_Transparent
    End If
   
    If btnYES <> "" Then
        Dim btnPrefOk As B4XView = prefdialog.Dialog.GetButton(xui.DialogResponse_Positive)
        btnPrefOk.Width = ButtonSize        'btnPrefOk.Width + 40dip
        btnPrefOk.Left = 20dip
        btnPrefOk.TextColor = btnYES_TextColor
        btnPrefOk.Color = btnYES_BackgroundColor        'xui.Color_Transparent
    End If

    'prefdialog.CustomListView1.sv.Height = prefdialog.CustomListView1.sv.ScrollViewInnerPanel.Height + 25dip
    
    Wait For (sf) Complete (Result As Int)
    
    If Result = xui.DialogResponse_Positive Then
        Return True
    End If
    
    Return False
    
End Sub
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
You are not using my latest example.
if you refer your sample project (B4X) - i told you i can't use it
my app is an old app running on many devices for many years - it is B4A
so i can't use it and now change my entire working app

so i still am on the code correction you uploaded with some minor additions as you can see to make it more flexible

if you refer to another version you uploaded then please correct me as i missed it...

the only thing i'm missing now that does not work is the scroll of the message
once i have a solution to that i'm done and very happy
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
1701263686251.png


Trial and error with different values:
B4X:
Dim Dlg As Dialog
Dlg.Initialize
Dlg.Height = 230dip ' <-- try with other value

ScrollView1.As(ScrollView).Panel.AddView(lbl, 5dip, 5dip, b4xview1.Width-10dip, Dialog.Dialog.Height)
 

Attachments

  • B4APreferencesDialogCustom.zip
    11.9 KB · Views: 46
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
View attachment 148175

Trial and error with different values:
B4X:
Dim Dlg As Dialog
Dlg.Initialize
Dlg.Height = 230dip ' <-- try with other value

ScrollView1.As(ScrollView).Panel.AddView(lbl, 5dip, 5dip, b4xview1.Width-10dip, Dialog.Dialog.Height)
THANK YOU!!
firstly scroll works

i see a total change of code & concept - i'll dive into it to learn it

the message window cuts the last part of the text so after all it shows the text but without the last 2 or 2 lines
and as much as i lower the height value it cuts more text
i couldn't manage to show the entire text
yes - i see in your sample screenshot that it does but running the sample as-is caused the text cut
so i think it depends on the device or its screen or whatever
but it works!
i also noticed that i can still have the flexibility i need so this may be the solution
i will now drill it down and then try to implement it in my app - this will be a real challenge

i will of course revert asap and update

once again - thank you so much for your help and good will!!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sorry for not following this thread as it has become really long. But, looking at the last few posts, I see a project by @aeric showing a scrolling text in a dialog. If that is part of a bigger project you are undertaking regarding B4XPreferenceDialog, would incorporating B4XLongTextTemplate which has a scrolling text be an option. If so, take a look at B4XLongTextTemplate ( part of XUI Views dialogs). If it is a fit and need help, come back. If it is not part of what you are looking for, please ignore this entire post.
1701286450836.png
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Sorry for not following this thread as it has become really long. But, looking at the last few posts, I see a project by @aeric showing a scrolling text in a dialog. If that is part of a bigger project you are undertaking regarding B4XPreferenceDialog, would incorporating B4XLongTextTemplate which has a scrolling text be an option. If so, take a look at B4XLongTextTemplate ( part of XUI Views dialogs). If it is a fit and need help, come back. If it is not part of what you are looking for, please ignore this entire post.
View attachment 148195
thank you for you input
i'm not aware of your solution or that feature
if you can put together a sample it will be much helpful and appreciated

so far aeric was very helping (and the only one) and provided a near perfect solution exactly as i was fantasizing about
i of course appreciate his and your help and good will

i feel we're just about to finish this topic
the only thing left is either auto calculate the dialog height to suit the text without losing any part or the title

once we are done i think this should be placed to the other pals here as it provides a full and flexible solution

once again thank both of you
 
Upvote 0
Top