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 can be use but if the dialog is too long then the title is not visible.
hi,
thanks for the new sample
as said it works

however - the text is being cut and the part i miss is larger as the height is smaller
secondly - the text is displayed to the bottom leaving a gap to the top part of the window

any way to fix it?
 
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)
hi
please see attached screenshot
when the text is short it is set to the lower part not the upper
i think if this is sorted then we can finish as the entire dream of full dynamic and flexible window might be not possible so i will have to set the height for each message according its size
 

Attachments

  • Screenshot_20231130_093956_b4a.example.jpg
    Screenshot_20231130_093956_b4a.example.jpg
    192.9 KB · Views: 113
Upvote 0

aeric

Expert
Licensed User
Longtime User
hi,
thanks for the new sample
as said it works

however - the text is being cut and the part i miss is larger as the height is smaller
secondly - the text is displayed to the bottom leaving a gap to the top part of the window

any way to fix it?
I mean by using B4XLongTextTemplate, the title will disappear.

For my last example, as I said, you need to try values like 100dip or 400dip for the dialog height.

Also try use "TOP" instead of "CENTER" for the message alignment.
B4X:
b4xview2.SetTextAlignment("TOP", Dialog.Message.Alignment)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
hi
please see attached screenshot
when the text is short it is set to the lower part not the upper
i think if this is sorted then we can finish as the entire dream of full dynamic and flexible window might be not possible so i will have to set the height for each message according its size
B4X:
b4xview2.SetTextAlignment("TOP", Dialog.Message.Alignment)

Let the function to allow for horizontal and vertical alignment.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
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
as this is now mainly your code - i can't publish it, but as it is so useful i suggest you do it

all the best
 
Upvote 0
Solution

aeric

Expert
Licensed User
Longtime User
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
as this is now mainly your code - i can't publish it, but as it is so useful i suggest you do it

all the best
It's your idea, I just assist. It's belongs to you.
If you feel better to add my name as a credit e.g "with help by aeric", that is just sufficient. :)
You can share the code and let anyone benefit from it.

Lastly, you can mark my answer as a solution.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
It's your idea, I just assist. It's belongs to you.
If you feel better to add my name as a credit e.g "with help by aeric", that is just sufficient. :)
You can share the code and let anyone benefit from it.

Lastly, you can mark my answer as a solution.
i will !
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
folks
here is the solution i offer to all who wants it
it is based on PrefDialog as a replacement to the regular internal dialogs
the reason to use it is that regular dialogs are gone if the app is paused and then returns
this way it actually freezes as it was before it was paused
for my needs it was critical
i had an idea
could not have done it all by myself so a dear pal here @aeric came to my rescue and spent days until he found the solution
without him it could not be done so thank you aeric one again

this sample shows how to fully control each and every element in the dialog
same dialog serves both a confirm dialog (yes/no) and a regular message dialog
one thing to keep in mind - keep the text short
longer text will require changing the window height or lose a part of the text end
you can use it as you choose and change whatever you like

the sample is very detailed and the code is basic and primitive to make it as clear and easy as possible

if anyone finds a solution to handle the entire text in scroll without losing a part i'd be happy to hear

once again - many thanks to aeric as without him it could not be done
enjoy
 

Attachments

  • B4APreferencesDialogCustom.zip
    15.5 KB · Views: 117
Upvote 0

Mahares

Expert
Licensed User
Longtime User
if anyone finds a solution to handle the entire text in scroll without losing a part i'd be happy to hear
YES I can post you a code for B4XLongTextTemplate to replace your code in Button2 click code. It will display a message 100 lines long centered without truncating any of it. If you are happy with what you got, then hasta lavista.
1701346283781.png
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Oh sure, yes
Add these lines to your Sub GLobals:
B4X:
'Mahares
    Private MyDialog As B4XDialog  'XUI Views lib must be checked
    Private LongTextTemplate As B4XLongTextTemplate

Replace your Activity_Create sub with this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("MainPage")
    
    'Mahares
    MyDialog.Initialize (Activity)
    MyDialog.Title = "Message title"
    MyDialog.ButtonsHeight=55dip
    LongTextTemplate.Initialize
End Sub

Replace your Button2 click with this:
B4X:
Private Sub Button2_Click
    Dim sb As StringBuilder
    sb.Initialize
    Dim s As String = $"This is a demo message to show flexibility including scrolling the text.${CRLF}"$
    For i=0 To 99
        sb.Append(s)
    Next
    s= sb.ToString
    LongTextTemplate.Text = s
    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_DarkGray
'    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_Black
'    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_White
    LongTextTemplate.Resize(300dip,250dip)
    LongTextTemplate.CustomListView1.DefaultTextColor = xui.Color_Yellow
'    LongTextTemplate.CustomListView1.DefaultTextColor = xui.Color_Black

    Dim rs As Object = MyDialog.ShowTemplate(LongTextTemplate, "Ok", "", "")
    
    Dim e As B4XView=LongTextTemplate.CustomListView1.GetPanel(0).GetView(0)
    e.SetTextAlignment("TOP","CENTER")
    Wait For (rs) Complete (Result As Int)
End Sub
Run your project and check out Button2 click. I did not mess with with your button1. Please report back.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Add these lines to your Sub GLobals:
B4X:
'Mahares
    Private MyDialog As B4XDialog  'XUI Views lib must be checked
    Private LongTextTemplate As B4XLongTextTemplate

Replace your Activity_Create sub with this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("MainPage")
 
    'Mahares
    MyDialog.Initialize (Activity)
    MyDialog.Title = "Message title"
    MyDialog.ButtonsHeight=55dip
    LongTextTemplate.Initialize
End Sub

Replace your Button2 click with this:
B4X:
Private Sub Button2_Click
    Dim sb As StringBuilder
    sb.Initialize
    Dim s As String = $"This is a demo message to show flexibility including scrolling the text.${CRLF}"$
    For i=0 To 99
        sb.Append(s)
    Next
    s= sb.ToString
    LongTextTemplate.Text = s
    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_DarkGray
'    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_Black
'    LongTextTemplate.CustomListView1.DefaultTextBackgroundColor = xui.Color_White
    LongTextTemplate.Resize(300dip,250dip)
    LongTextTemplate.CustomListView1.DefaultTextColor = xui.Color_Yellow
'    LongTextTemplate.CustomListView1.DefaultTextColor = xui.Color_Black

    Dim rs As Object = MyDialog.ShowTemplate(LongTextTemplate, "Ok", "", "")
 
    Dim e As B4XView=LongTextTemplate.CustomListView1.GetPanel(0).GetView(0)
    e.SetTextAlignment("TOP","CENTER")
    Wait For (rs) Complete (Result As Int)
End Sub
Run your project and check out Button2 click. I did not mess with with your button1. Please report back.
wow!
really simple and easy and it work!!
i will embed this in my app to see how it all works together
thank you so much!!

just 2 questions -
1- how do i control the buttons text & back color? (each with its own color - green for OK red-no cyan-cancel and the backgrounds each with its own color)
2 - how can i keep the background of the calling activity and not make it so dark?

thanks
 
Last edited:
Upvote 0
Top