Android Code Snippet SD: MsgBox re-stylized

There are many libraries that update and modify MsgBox and all interesting, but no one meets my needs.
So I created someone I did. I hope someone else might be useful.

It's not a library. Only snippets of code. Does not require any additional library. You can include on your sources or you can wrap them into Class.

msgbox3.png msgbox4.png msgbox5.png msgbox6.png


MsgBox3(Message As String, Title As String, Positive As String, Cancel As String,Negative As String) As Int
The parameters are the same as MsgBox2

MsgBox4(Message As String, Title As String, Positive As String, Cancel As String,Negative As String, GraficStyle As Int) As Int

GraficStyle
0 = Trapeze
1 = Ellisse
2 = Fringe
 

Attachments

  • messageBox.zip
    8.5 KB · Views: 875
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
UPDATE:

Created MsgBox class and variation management screen orientation

Use:
B4X:
    Dim MsBox As SDMsgBox

    MsBox.Initialize(Activity)

    If MsBox.MsgBox4("Message","MsgBox4 - Style 0","Yes","","No",0)=DialogResponse.POSITIVE Then
        ToastMessageShow("YES",False)
    Else
        ToastMessageShow("No",False)
    End If

Method
MsgBox3
(Message As String, Title As String, Positive As String, Cancel As String,Negative As String) As Int
MsgBox4(Message As String, Title As String, Positive As String, Cancel As String,Negative As String, GraficStyle As Int) As Int
GraficStyle
0 = Trapeze; 1 = Ellisse; 2 = Fringe

Proprietes
Response
As int
' as DialogResponse

 
Last edited:

jnjft

Member
Licensed User
Longtime User
Hello Star-Dust!
Thanks a lot for the MsgBox-enhancements!
I have the issue, that after tapping on Ok or Cancel or No the MsgBox disappears, but the Activity stays dimmed. It is not until I tap on the sreen that the activity shows up with the normal brightness again.
What could be wrong?

Thanks for your effort
 

Star-Dust

Expert
Licensed User
Longtime User
Hello Star-Dust!
Thanks a lot for the MsgBox-enhancements!
I have the issue, that after tapping on Ok or Cancel or No the MsgBox disappears, but the Activity stays dimmed. It is not until I tap on the sreen that the activity shows up with the normal brightness again.
What could be wrong?

Thanks for your effort
The screen is darkened, giving the impression that the activity is paused. It's just a trick.
I open a transparent gray panel under the box. See the code below.
B4X:
Sub MsgBox3(Message As String, Title As String, Positive As String, Cancel As String,Negative As String) As Int
    Dim P, Box As Panel
    '...
    '...
    P.Initialize("PanelMsgBox3")
    P.Color=Colors.ARGB(210,10,10,10)

When you click on a button the panelle is removed, as in the code you see below
B4X:
Do While Box.Tag=""
        DoEvents
        DoEvents
        If P.Width<>GetDeviceLayoutValues.Width  Then
            Activity.Width=GetDeviceLayoutValues.Width
            Activity.Height=GetDeviceLayoutValues.Height
            P.Width=GetDeviceLayoutValues.Width
            P.Height=GetDeviceLayoutValues.Height
            Box.Left=P.Width/2-180dip
            Box.Top=P.Height/2-150dip
        End If
    Loop

Ret=Box.Tag
P.RemoveView ' PANEL GRAY REMOVED
Return Ret

If you have not modified the code it should work.

In any case, I suggest changing the code to no longer use the modal MsgBox, but the event one
This would avoid creating problems with the DoEvents.

For example, removing the block that I pasted on and modifying the click event of the three options (Yes, Cancel, No)
B4X:
Sub BMsgBox3_Click
    Dim B As Button = Sender
    Dim P As Panel = B.Parent
 
    P.Tag=B.Tag
    P.RemoveView ' Remove Panel Gray
End Sub

With these changes you can use the MessageBox also with the Wait For

Regard
 

jnjft

Member
Licensed User
Longtime User
Thanks for the reply!
I didn't change the code and I understand what you mean - alas, P.RemoveView doesn't remove the gray panel at my place.
I've come so far with logs:
- The loop Do While Box.Tag = "" is exited and Ret gets the contents of Box.Tag, but the next statement (P.RemoveView) fails
- When I touch the gray panel actively I enter PanelMsgBox3_Touch, and the code there does exactly what I want - remove the panel. Although it only contains the two statements
B4X:
Sub PanelMsgBox3_Touch (Action As Int, X As Float, Y As Float)
Dim P as Panel = Sender
P.RemoveView
 

jnjft

Member
Licensed User
Longtime User
Is there a possibility to simulate the panel touch event? I had no success with calling PanelMsgBox3_Touch(0, 10, 10).

Regards
Johann
 

Star-Dust

Expert
Licensed User
Longtime User
Make Public a Sub.
 

tagwato

Member
Licensed User
Longtime User
(...)
In any case, I suggest changing the code to no longer use the modal MsgBox, but the event one
This would avoid creating problems with the DoEvents.
For example, removing the block that I pasted on and modifying the click event of the three options (Yes, Cancel, No)
(...)
With these changes you can use the MessageBox also with the Wait For
Regard
Hi, @Star-Dust ,
I liked very much your approach to create message-boxes "dynamically", and I'd like to use it with the Async/Wait For mechanism.
But I didn't understand what event/response/sub to wait for.
Could you please elaborate your previous reply demonstrating:
- how to create/call the MsgBox3 object so that it is compatible with an assynchronous usage
- how to wait for the response/choice the user has selected.
The doubt is how to change this:
B4X:
Dim I As Int = MsgBox4("Message","MsgBox4 - Style 2","Yes","Cancel","No",1)
If I=DialogResponse.POSITIVE Then
(...)
to an implementation like this:
B4X:
MsgBox4("Message","MsgBox4 - Style 2","Yes","Cancel","No",1)
Wait For(<<something>>) Complete (I As Int)
If I=DialogResponse.POSITIVE Then
(...)
What is the <<something>> we should wait for? Besides that, any other ajustments needed in the code?
 

tagwato

Member
Licensed User
Longtime User
What is the <<something>> we should wait for? Besides that, any other ajustments needed in the code?
Never mind, I think I have found a solution.
Changed the signature of the MsgBox3 and MsgBox4 subs, so that they are now "ResumableSub".
And using them like this:
B4X:
Dim rs As ResumableSub = MsgBox3("Message","MsgBox3","Yes","Cancel","No")
Wait For(rs) Complete (I As Int)
If I=DialogResponse.POSITIVE Then
(...)

The full adjusted project is attached, if anyone is interested.
 

Attachments

  • Home-made-MsgBoxes-using-Wait-For.zip
    7.9 KB · Views: 85
Last edited:
Top