Android Code Snippet SD: MsgBox re-stylized

Discussion in 'Code Snippets' started by Star-Dust, Apr 20, 2017.

  1. Star-Dust

    Star-Dust Well-Known Member Licensed User

    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

    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Private Button1, Button2, Button3, Button4 As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        Activity.Title="MsgBox New"
        Button1.Initialize(
    "B1")
        Button1.Text=
    "MsgBox3"
        
    Activity.AddView(Button1,0dip,0dip,150dip,40dip)

        Button2.Initialize(
    "B2")
        Button2.Text=
    "MsgBox4-S0"
        
    Activity.AddView(Button2,0dip,50dip,150dip,40dip)

        Button3.Initialize(
    "B3")
        Button3.Text=
    "MsgBox4-S1"
        
    Activity.AddView(Button3,0dip,100dip,150dip,40dip)

        Button4.Initialize(
    "B4")
        Button4.Text=
    "MsgBox4-S2"
        
    Activity.AddView(Button4,0dip,150dip,150dip,40dip)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub B1_Click
        
    Dim I As Int

        i=
    MsgBox3("Message","MsgBox3","Yes","Cancel","No")
        
    Select I
            
    Case DialogResponse.POSITIVE
                
    ToastMessageShow("YES",False)
            
    Case DialogResponse.NEGATIVE
                
    ToastMessageShow("NO",False)
            
    Case DialogResponse.POSITIVE
                
    ToastMessageShow("Cancel",False)
        
    End Select
    End Sub

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

    Sub B3_Click
        
    If MsgBox4("Message","MsgBox4 - Style 1","Yes","Cancel","No",1)=DialogResponse.POSITIVE Then
            
    ToastMessageShow("YES",False)
        
    Else
            
    ToastMessageShow("No",False)
        
    End If
    End Sub

    Sub B4_Click
        
    If MsgBox4("Message","MsgBox4 - Style 2","Yes","Cancel","No",2)=DialogResponse.POSITIVE Then
            
    ToastMessageShow("YES",False)
        
    Else
            
    ToastMessageShow("No",False)
        
    End If
    End Sub

    #Region Grafic Support

    Sub Corner(Colore As Int) As ColorDrawable
        
    Dim cdb As ColorDrawable
        cdb.Initialize(Colore, 
    20dip)
        
    Return cdb
    End Sub

    Sub Underline(Colore As Int, ColoreLinea As Int) As Bitmap
        
    Dim Bm As Bitmap
        
    Dim Can As Canvas

        Bm.InitializeMutable(
    300dip,200dip)
        Can.Initialize2(Bm)
        Can.DrawColor(Colore)
        Can.DrawLine(
    0dip,198dip,300dip,198dip,ColoreLinea,2dip)
        
    Return Bm
    End Sub

    Sub Trapezio(Colore As Int) As Bitmap
        
    Dim Bm As Bitmap
        
    Dim Can As Canvas
        
    Dim Path1 As Path

        Bm.InitializeMutable(
    300dip,100dip)
        Can.Initialize2(Bm)
        Path1.Initialize(
    0dip,0dip)
        Path1.LineTo(
    0dip,70dip)
        Path1.LineTo(
    150dip,100dip)
        Path1.LineTo(
    300dip,70dip)
        Path1.LineTo(
    300dip,0dip)
        Path1.LineTo(
    0dip,0dip)
        Can.DrawPath(Path1,Colore,
    True,1dip)
        
    Return Bm
    End Sub

    Sub Ellisse(Colore As Int) As Bitmap
        
    Dim Bm As Bitmap
        
    Dim Can As Canvas
        
    Dim Rec1 As Rect

        Bm.InitializeMutable(
    300dip,100dip)
        Can.Initialize2(Bm)
        Rec1.Initialize(-
    40dip,-100dip,340dip,100dip)
        Can.DrawOval(Rec1,Colore,
    True,1dip)
        
    'Can.DrawOval(Rec1,Colors.DarkGray,False,3dip)
        Return Bm
    End Sub

    Sub Frangia(Colore As Int) As Bitmap
        
    Dim Bm As Bitmap
        
    Dim Can As Canvas
        
    Dim Rec1 As Rect

        Bm.InitializeMutable(
    300dip,100dip)
        Can.Initialize2(Bm)
        Can.DrawColor(
    Colors.White)
        Rec1.Initialize(
    0dip,0dip,300dip,90dip)
        Can.DrawRect(Rec1,Colore,
    True,1dip)
        
    For i=0 To 7
            Can.DrawCircle(
    10dip+i*40dip,90dip,10dip,Colore,True,1dip)
            Can.DrawCircle(
    30dip+i*40dip,90dip,10dip,Colors.White,True,1dip)
        
    Next
        
    'Can.DrawOval(Rec1,Colors.DarkGray,False,3dip)
        Return Bm
    End Sub

    #End Region

    #Region MsgBoxNew
    Sub MsgBox3(Message As String, Title As String, Positive As String, Cancel As String,Negative As StringAs Int
        
    Dim P, Box As Panel
        
    Dim Ret As Int

        P.Initialize(
    "PanelMsgBox3")
        P.Color=
    Colors.ARGB(210,10,10,10)
        
    Activity.AddView(P,0dip,0dip,100%x,100%y)

        Box.Initialize(
    "Box")
        Box.Tag=
    ""
        
    'Box.Color=Colors.White
        Box.Background=Corner(Colors.White)
        
    'Box.SetBackgroundImage(Border(Colors.White,Colors.Black))
        P.AddView(Box,50%x-180dip,50%y-150dip,360dip,300dip)

        
    Dim L As Label
        L.Initialize(
    "")
        L.SetBackgroundImage(Underline(
    Colors.White,Colors.DarkGray))
        L.Textcolor=
    Colors.Black
        L.Gravity=
    Gravity.CENTER
        L.TextSize=
    18
        L.Typeface=
    Typeface.DEFAULT_BOLD
        L.Text=Title
        Box.AddView(L,
    20dip,0dip,320dip,50dip)

        
    Dim Mess As Label
        Mess.Initialize(
    "")
        Mess.textColor=
    Colors.Black
        Mess.Text=Message
        Mess.Gravity=
    Gravity.CENTER
        Mess.TextSize=
    22
        Box.AddView(Mess,
    10dip,50dip,340dip,150dip)

        
    Dim BPositive, BCancel, BNegative As Button

        
    If Positive.Trim<>"" Then
            BPositive.Initialize(
    "BMsgBox3")
            BPositive.Text=Positive
            BPositive.Gravity=
    Gravity.CENTER
            BPositive.TextColor=
    Colors.White
            BPositive.Typeface=
    Typeface.DEFAULT_BOLD
            BPositive.Background=Corner(
    Colors.RGB(60,150,80))
            BPositive.Tag=
    DialogResponse.POSITIVE
            Box.AddView(BPositive,
    20dip,220dip,100dip,60dip)
        
    End If

        
    If Negative.Trim<>"" Then
            BNegative.Initialize(
    "BMsgBox3")
            BNegative.Text=Negative
            BNegative.Gravity=
    Gravity.CENTER
            BNegative.TextColor=
    Colors.White
            BNegative.Typeface=
    Typeface.DEFAULT_BOLD
            BNegative.Background=Corner(
    Colors.RGB(60,150,80))
            BNegative.Tag=
    DialogResponse.NEGATIVE
            Box.AddView(BNegative,
    240dip,220dip,100dip,60dip)
        
    End If

        
    If Cancel.Trim<>"" Then
            BCancel.Initialize(
    "BMsgBox3")
            BCancel.Text=Cancel
            BCancel.Gravity=
    Gravity.CENTER
            BCancel.TextColor=
    Colors.White
            BCancel.Typeface=
    Typeface.DEFAULT_BOLD
            BCancel.Background=Corner(
    Colors.RGB(60,150,80))
            BCancel.Tag=
    DialogResponse.CANCEL
            Box.AddView(BCancel,
    130dip,220dip,100dip,60dip)
        
    Else
            BPositive.Left=
    10dip
            BPositive.Width=
    165dip
            BNegative.Left=
    185dip
            BNegative.Width=
    165dip
        
    End If

        
    Do While Box.Tag=""
            
    DoEvents
        
    Loop

        Ret=Box.Tag
        P.RemoveView
        
    Return Ret
    End Sub

    Sub PanelMsgBox3_Touch (Action As Int, X As Float, Y As Float)
        
    Dim P As Panel = Sender

        P.RemoveView
    End Sub

    Sub BMsgBox3_Click
        
    Dim B As Button = Sender
        
    Dim P As Panel = B.Parent

        P.Tag=B.Tag
    End Sub

    Sub MsgBox4(Message As String, Title As String, Positive As String, Cancel As String,Negative As String, GraficStyle As Int) As Int
        
    ' GraficStyle:  0 = Trapezio; 1 = Ellisse; 2 = Frangia
        Dim P, Box As Panel
        
    Dim Ret As Int

        P.Initialize(
    "PanelMsgBox3")
        P.Color=
    Colors.ARGB(210,10,10,10)
        
    Activity.AddView(P,0dip,0dip,100%x,100%y)

        Box.Initialize(
    "Box")
        Box.Tag=
    ""
        Box.Color=
    Colors.White
        
    'Box.SetBackgroundImage(Border(Colors.White,Colors.Black))
        P.AddView(Box,50%x-180dip,50%y-150dip,360dip,300dip)

        
    Dim L As Label
        L.Initialize(
    "")
        
    Select GraficStyle
            
    Case 0
                L.SetBackgroundImage(Trapezio(
    Colors.RGB(60,150,80)))
            
    Case 1
                L.SetBackgroundImage(Ellisse(
    Colors.RGB(60,150,80)))    
            
    Case 2
                L.SetBackgroundImage(Frangia(
    Colors.RGB(60,150,80)))
        
    End Select

        L.Textcolor=
    Colors.White
        L.Gravity=
    Gravity.CENTER
        L.TextSize=
    20
        L.Typeface=
    Typeface.DEFAULT_BOLD
        L.Text=Title
        Box.AddView(L,
    0dip,0dip,360dip,80dip)

        
    Dim Mess As Label
        Mess.Initialize(
    "")
        Mess.textColor=
    Colors.Black
        Mess.Text=Message
        Mess.Gravity=
    Gravity.CENTER
        Mess.TextSize=
    22
        Box.AddView(Mess,
    10dip,80dip,340dip,130dip)

        
    Dim BPositive, BCancel, BNegative As Button

        
    If Positive.Trim<>"" Then
            BPositive.Initialize(
    "BMsgBox3")
            BPositive.Text=Positive
            BPositive.Gravity=
    Gravity.CENTER
            BPositive.TextColor=
    Colors.White
            BPositive.Typeface=
    Typeface.DEFAULT_BOLD
            BPositive.Background=Corner(
    Colors.RGB(60,150,80))
            BPositive.Tag=
    DialogResponse.POSITIVE
            Box.AddView(BPositive,
    20dip,220dip,100dip,60dip)
        
    End If

        
    If Negative.Trim<>"" Then
            BNegative.Initialize(
    "BMsgBox3")
            BNegative.Text=Negative
            BNegative.Gravity=
    Gravity.CENTER
            BNegative.TextColor=
    Colors.White
            BNegative.Typeface=
    Typeface.DEFAULT_BOLD
            BNegative.Background=Corner(
    Colors.RGB(60,150,80))
            BNegative.Tag=
    DialogResponse.NEGATIVE
            Box.AddView(BNegative,
    240dip,220dip,100dip,60dip)
        
    End If

        
    If Cancel.Trim<>"" Then
            BCancel.Initialize(
    "BMsgBox3")
            BCancel.Text=Cancel
            BCancel.Gravity=
    Gravity.CENTER
            BCancel.TextColor=
    Colors.White
            BCancel.Typeface=
    Typeface.DEFAULT_BOLD
            BCancel.Background=Corner(
    Colors.RGB(60,150,80))
            BCancel.Tag=
    DialogResponse.CANCEL
            Box.AddView(BCancel,
    130dip,220dip,100dip,60dip)
        
    Else
            BPositive.Left=
    10dip
            BPositive.Width=
    165dip
            BNegative.Left=
    185dip
            BNegative.Width=
    165dip
        
    End If

        
    Do While Box.Tag=""
            
    DoEvents
        
    Loop

        Ret=Box.Tag
        P.RemoveView
        
    Return Ret
    End Sub

    #End Region
    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
     

    Attached Files:

    Last edited: Apr 20, 2017
  2. Star-Dust

    Star-Dust Well-Known Member Licensed User

    UPDATE:

    Created MsgBox class and variation management screen orientation

    Use:
    Code:
    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

     

    Attached Files:

    Last edited: May 2, 2017
Loading...