B4A Library [Lib] BetterDialogs

I tried to improve the most useful dialogs of the Dialogs library. In my version, HTML tags are interpreted (even in the text of buttons), the InputBox uses a Masked EditText and has more options, you can check if the input is valid before closing the dialog, and the CustomDialog is fully customizable. I also solved an issue with the virtual keyboard.

MsgBox (under Gingerbread and JellyBean):

msgbox.png


InputBox (under Gingerbread and JellyBean):

inputbox.png


CustomDialog (under Gingerbread and JellyBean):

cd1.jpg


Another CustomDialog (under Gingerbread and JellyBean):

cd2.png


v1.1:
- I added a CloseDialog function;
- I added a margin parameter to the custom dialog.

v1.2:
- I fixed a bug in InputBox when there's a default value;
- I added the BackKeyPressed event for custom dialogs.

v1.3:
- I added a PasswordMode option to the InputBox;
- I added a CancelOnTouchOutside option.

v1.4:
- I added a CursorPosition option to the InputBox.

v2.0:
- I moved the CustomDialog parameters to the BD_CustomDlgParams class.
- I added two new parameters: Duration and DialogGravity.
- I removed the Margin parameter and added the MarginHeight parameter (to be used when Gravity is set to TOP).
- The BodyWidth and BodyHeight parameters defines now accurately the size of the dialog body.

v2.1:
- I added a "closing" event raised just before a custom dialog is dismissed. You can cancel the closure by returning False.

v2.11:
- I added the "DlgResponse" parameter to the Closing event.

This library does not work with Android versions < 2.
It requires another library: Masked EditText
 

Attachments

  • BetterDialogs v2.11.zip
    55.6 KB · Views: 2,389
  • Java source - BetterDialogs.zip
    8.5 KB · Views: 765
Last edited:

TheMightySwe

Active Member
Licensed User
Longtime User
Post your code if you want that someone tries to find where's the error.

Oh, something went wrong in the last post

B4X:
Sub Process_Globals

    Type StringAnswer(Cancelled As Boolean, Value As String)

End Sub


Sub Globals

    ' New AlphaNumeric
   
    Dim AlphaNumericPanel As Panel
    Dim AlphaNumericEditText As EditText
    Dim AlphaNumericButton(60) As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)

    Dim Response As StringAnswer

    Response =ShowAlphaNumericalDialog("Test", "", False, 60)

End Sub

Sub ShowAlphaNumericalDialog(Title As String, Default As String, IsPassword As Boolean, MaxLength As Int) As StringAnswer

    Dim PanelSize As Coordinates
    Dim Dialog As BetterDialogs
    Dim ResponseValue As StringAnswer
    Dim DialogAnswer As Int
   
    PanelSize.Initialize
   
    AlphaNumericPanel.Initialize("AlphaNumericPanel")

    AlphaNumericEditText.Initialize("AlphaNumericEditText")
    AlphaNumericEditText.Tag = MaxLength
   
    If IsPassword = True Then
        AlphaNumericEditText.PasswordMode = True
    Else
        AlphaNumericEditText.PasswordMode = False
    End If
   
    AlphaNumericEditText.Text = Default

    Dim LeftPos, TopPos, ButtonWidth, ButtonHeight, Button0x75Width, Button1x0Width, Button1x25Width, Button1x5Width, Button2x25Width As Int

    PanelSize.Width = 100%x - 30dip - 10dip ' 30dip = Dialog Borders, 10 dip = extra margin
    Button1x0Width = (PanelSize.Width - (1dip * 15)) / 15
    ButtonHeight = Button1x0Width
    Button0x75Width = Button1x0Width * 0.75
    Button1x25Width = Button1x0Width * 1.25
    Button1x5Width = Button1x0Width * 1.5
    Button2x25Width = Button1x0Width * 2.25

    ' EditText
   
    LeftPos = 5dip
    TopPos = 5dip
   
    AlphaNumericPanel.AddView(AlphaNumericEditText,5dip, 5dip, PanelSize.Width - 10dip, ButtonHeight)

    ' 13 knappar rad 1

    Dim FirstRow, FirstRowCapped, FirstRowButtonSizes, SecondRow, SecondRowCapped, SecondRowButtonSizes, ThirdRow, ThirdRowCapped, ThirdRowButtonSizes, ForthRow, ForthRowCapped, ForthRowButtonSizes As List

    FirstRow.Initialize2(Array As String("§","1","2","3","4","5","6","7","8","9","0","+","",Chr(8)))
    FirstRowCapped.Initialize2(Array As String("½","!",Chr(34),"#","$","%","&","/","(",")","=","?","",Chr(8)))
    FirstRowButtonSizes.Initialize2(Array As Int(Button0x75Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button2x25Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    For i = 0 To FirstRow.Size - 1

        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = FirstRow.Get(i)
        Key.ShiftedKey = FirstRowCapped.Get(i)
       
        AlphaNumericButton(i).Initialize("AlphaNumButton")
        AlphaNumericButton(i).Tag = Key
        AlphaNumericButton(i).Typeface = DroidSansMono
        AlphaNumericButton(i).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i).Gravity = Gravity.CENTER
       
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i).Text = TranslateNonVisibleCharToText(Key.NormalKey)       
        Else
            Key.IsShifted = False
            AlphaNumericButton(i).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
       
        If i = FirstRow.Size - 1 Then
            ButtonWidth = PanelSize.Width - LeftPos - 1dip - 5dip
        Else
            ButtonWidth = FirstRowButtonSizes.Get(i)
        End If
       


       
        AlphaNumericPanel.AddView(AlphaNumericButton(i), LeftPos, TopPos, ButtonWidth, ButtonHeight)
        LeftPos = LeftPos + FirstRowButtonSizes.Get(i) + 1dip

    Next

    ' 13 knappar rad 2 + dubbelt så hög Entertangent
   
    SecondRow.Initialize2(Array As String(Chr(9),"q","w","e","r","t","y","u","i","o","p","å","´"))
    SecondRowCapped.Initialize2(Array As String(Chr(9),"Q","W","E","R","T","Y","U","I","O","P","Å","^"))
    SecondRowButtonSizes.Initialize2(Array As String(Button1x25Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    For i = 0 To SecondRow.Size - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = SecondRow.Get(i)
        Key.ShiftedKey = SecondRowCapped.Get(i)
       
        AlphaNumericButton(i+FirstRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size).Gravity = Gravity.CENTER
       
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i+FirstRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        Else
            Key.IsShifted = False
            AlphaNumericButton(i+FirstRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If

        ButtonWidth = SecondRowButtonSizes.Get(i)

        AlphaNumericPanel.AddView(AlphaNumericButton(i+FirstRow.Size), LeftPos, TopPos, ButtonWidth, ButtonHeight)
        LeftPos = LeftPos + SecondRowButtonSizes.Get(i) + 1dip

    Next
   
    ' 13 knappar rad 3

    ThirdRow.Initialize2(Array As String(Chr(15),"a","s","d","f","g","h","j","k","l","ö","ä","'"))
    ThirdRowCapped.Initialize2(Array As String(Chr(15),"A","S","D","F","G","H","J","K","L","Ö","Ä","*"))
    ThirdRowButtonSizes.Initialize2(Array As String(Button1x5Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip
   
    For i = 0 To ThirdRow.Size - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = ThirdRow.Get(i)
        Key.ShiftedKey = ThirdRowCapped.Get(i)
       
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Gravity = Gravity.CENTER
       
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)       
        Else
            Key.IsShifted = False
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
       
        AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Tag = Key
        AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Gravity = Gravity.CENTER
        AlphaNumericPanel.AddView(AlphaNumericButton(i + FirstRow.Size + SecondRow.Size),LeftPos,TopPos,ThirdRowButtonSizes.Get(i),ButtonHeight)
        LeftPos = LeftPos + ThirdRowButtonSizes.Get(i) + 1dip

    Next

    ' 13 knappar rad 4

    ForthRow.Initialize2(Array As String(Chr(14),"<","z","x","c","v","b","n","m",",",".","-",Chr(14)))
    ForthRowCapped.Initialize2(Array As String(Chr(14),">","Z","X","C","V","B","N","M",";",":","_",Chr(14)))
    ForthRowButtonSizes.Initialize2(Array As String(Button1x25Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button2x25Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip
   
    For i = 0 To ForthRow.Size - 1

        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = ForthRow.Get(i)
        Key.ShiftedKey = ForthRowCapped.Get(i)

        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Gravity = Gravity.CENTER

        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)       
        Else
            Key.IsShifted = False
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
       
        If i = ForthRow.Size - 1 Then
            ButtonWidth = PanelSize.Width - LeftPos - 1dip - 5dip
        Else
            ButtonWidth = ForthRowButtonSizes.Get(i)
        End If
       
        AlphaNumericPanel.AddView(AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size),LeftPos,TopPos,ButtonWidth,ButtonHeight)
        LeftPos = LeftPos + ForthRowButtonSizes.Get(i) + 1dip

    Next

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    ' + Spaceknapp

    Dim Key As KeyboardKey
    Key.Initialize
    Key.NormalKey = " "
    Key.ShiftedKey = " "
   
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Initialize("AlphaNumButton")
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Tag = Key
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Typeface = DroidSansMono
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).TextSize = Screen.FontSizeButtons
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Gravity = Gravity.CENTER
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Text = "Mellanslag"

    AlphaNumericPanel.AddView(AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size),LeftPos,TopPos,PanelSize.Width - 10dip, ButtonHeight)
   
    PanelSize.Height = TopPos + ButtonHeight + 5dip

    Dim AlphaNumericDialogParams As BD_CustomDlgParams
    AlphaNumericDialogParams.Initialize
    AlphaNumericDialogParams.Title = Title
    AlphaNumericDialogParams.Background = Graphics.GenerateWatermarkLogoDialogBackground(PanelSize.Width,PanelSize.Height)
    AlphaNumericDialogParams.DialogBody = AlphaNumericPanel
    AlphaNumericDialogParams.BodyWidth = PanelSize.Width
    AlphaNumericDialogParams.BodyHeight = PanelSize.Height
    AlphaNumericDialogParams.PositiveButton = Language.GetString(Language.LanguageStrings.DialogsOK)
    AlphaNumericDialogParams.CancelButton = Language.GetString(Language.LanguageStrings.DialogsCancel)

    DialogAnswer = Dialog.CustomDialog(AlphaNumericDialogParams, "AlphaNumPad")
   
    Select DialogAnswer
   
        Case DialogResponse.POSITIVE

            ResponseValue.Cancelled = False
            ResponseValue.Value = AlphaNumericEditText.Text
       
        Case DialogResponse.CANCEL
       
            ResponseValue.Cancelled = True
            ResponseValue.Value = 0.00
       
        Case DialogResponse.NEGATIVE
       
            ResponseValue.Cancelled = True
            ResponseValue.Value = 0.00
       
    End Select

    Return ResponseValue

End Sub

Sub AlphaNumPad_BackKeyPressed As Boolean

    Return False 'Cancels the dialog
   
End Sub

Sub ShiftUp

    For x = 0 To AlphaNumericButton.Length - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsShifted = False
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub ShiftDown

    For x = 0 To AlphaNumericButton.Length - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsShifted = True
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub CapsLockOn

    For x = 0 To AlphaNumericButton.Length - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsCapsLock = True
        Key.IsShifted = True
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub CapsLockOff

    For x = 0 To AlphaNumericButton.Length - 1
   
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsCapsLock = False
        Key.IsShifted = False
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub TranslateNonVisibleCharToText(Character As String) As String

    Select Character

        Case Chr(8):
       
            Return "<--"
       
        Case Chr(9):
       
            Return "Tab"

        Case Chr(14):
       
            Return "Shift"
       
        Case Chr(15):
       
            Return "Caps Lock"

        Case Chr(34):

            Return Chr(34)

        Case Else
       
        Return Character
   
    End Select

End Sub

Sub AlphaNumButton_Click

        Dim KeyButton As Button = Sender
        Dim ClickedKey As KeyboardKey
       
        ClickedKey.Initialize
        ClickedKey = KeyButton.Tag
       
        Dim KeyChar As String
       
        If ClickedKey.IsShifted = True Then
            KeyChar = ClickedKey.ShiftedKey
        Else
            KeyChar = ClickedKey.NormalKey
        End If

        Select KeyChar

        Case Chr(8):
       
            If ClickedKey.IsCapsLock = True Then
                CapsLockOff
            Else
                CapsLockOn
            End If
           
       
        Case Chr(9):
       
            If ClickedKey.IsShifted = True Then
                ShiftUp
            Else
                ShiftDown
            End If

        Case Else
       
            If AlphaNumericEditText.SelectionStart = -1 Then
                AlphaNumericEditText.Text = AlphaNumericEditText.Text & KeyChar
            Else
                Dim Start As Int = AlphaNumericEditText.SelectionStart
                AlphaNumericEditText.Text = AlphaNumericEditText.Text.SubString2(0, Start) & KeyChar & AlphaNumericEditText.Text.SubString(Start)
            End If
   
    End Select
   
End Sub
 

Informatix

Expert
Licensed User
Longtime User
Oh, something went wrong in the last post

B4X:
Sub Process_Globals

    Type StringAnswer(Cancelled As Boolean, Value As String)

End Sub


Sub Globals

    ' New AlphaNumeric
  
    Dim AlphaNumericPanel As Panel
    Dim AlphaNumericEditText As EditText
    Dim AlphaNumericButton(60) As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)

    Dim Response As StringAnswer

    Response =ShowAlphaNumericalDialog("Test", "", False, 60)

End Sub

Sub ShowAlphaNumericalDialog(Title As String, Default As String, IsPassword As Boolean, MaxLength As Int) As StringAnswer

    Dim PanelSize As Coordinates
    Dim Dialog As BetterDialogs
    Dim ResponseValue As StringAnswer
    Dim DialogAnswer As Int
  
    PanelSize.Initialize
  
    AlphaNumericPanel.Initialize("AlphaNumericPanel")

    AlphaNumericEditText.Initialize("AlphaNumericEditText")
    AlphaNumericEditText.Tag = MaxLength
  
    If IsPassword = True Then
        AlphaNumericEditText.PasswordMode = True
    Else
        AlphaNumericEditText.PasswordMode = False
    End If
  
    AlphaNumericEditText.Text = Default

    Dim LeftPos, TopPos, ButtonWidth, ButtonHeight, Button0x75Width, Button1x0Width, Button1x25Width, Button1x5Width, Button2x25Width As Int

    PanelSize.Width = 100%x - 30dip - 10dip ' 30dip = Dialog Borders, 10 dip = extra margin
    Button1x0Width = (PanelSize.Width - (1dip * 15)) / 15
    ButtonHeight = Button1x0Width
    Button0x75Width = Button1x0Width * 0.75
    Button1x25Width = Button1x0Width * 1.25
    Button1x5Width = Button1x0Width * 1.5
    Button2x25Width = Button1x0Width * 2.25

    ' EditText
  
    LeftPos = 5dip
    TopPos = 5dip
  
    AlphaNumericPanel.AddView(AlphaNumericEditText,5dip, 5dip, PanelSize.Width - 10dip, ButtonHeight)

    ' 13 knappar rad 1

    Dim FirstRow, FirstRowCapped, FirstRowButtonSizes, SecondRow, SecondRowCapped, SecondRowButtonSizes, ThirdRow, ThirdRowCapped, ThirdRowButtonSizes, ForthRow, ForthRowCapped, ForthRowButtonSizes As List

    FirstRow.Initialize2(Array As String("§","1","2","3","4","5","6","7","8","9","0","+","",Chr(8)))
    FirstRowCapped.Initialize2(Array As String("½","!",Chr(34),"#","$","%","&","/","(",")","=","?","",Chr(8)))
    FirstRowButtonSizes.Initialize2(Array As Int(Button0x75Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button2x25Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    For i = 0 To FirstRow.Size - 1

        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = FirstRow.Get(i)
        Key.ShiftedKey = FirstRowCapped.Get(i)
      
        AlphaNumericButton(i).Initialize("AlphaNumButton")
        AlphaNumericButton(i).Tag = Key
        AlphaNumericButton(i).Typeface = DroidSansMono
        AlphaNumericButton(i).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i).Gravity = Gravity.CENTER
      
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i).Text = TranslateNonVisibleCharToText(Key.NormalKey)      
        Else
            Key.IsShifted = False
            AlphaNumericButton(i).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
      
        If i = FirstRow.Size - 1 Then
            ButtonWidth = PanelSize.Width - LeftPos - 1dip - 5dip
        Else
            ButtonWidth = FirstRowButtonSizes.Get(i)
        End If
      


      
        AlphaNumericPanel.AddView(AlphaNumericButton(i), LeftPos, TopPos, ButtonWidth, ButtonHeight)
        LeftPos = LeftPos + FirstRowButtonSizes.Get(i) + 1dip

    Next

    ' 13 knappar rad 2 + dubbelt så hög Entertangent
  
    SecondRow.Initialize2(Array As String(Chr(9),"q","w","e","r","t","y","u","i","o","p","å","´"))
    SecondRowCapped.Initialize2(Array As String(Chr(9),"Q","W","E","R","T","Y","U","I","O","P","Å","^"))
    SecondRowButtonSizes.Initialize2(Array As String(Button1x25Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    For i = 0 To SecondRow.Size - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = SecondRow.Get(i)
        Key.ShiftedKey = SecondRowCapped.Get(i)
      
        AlphaNumericButton(i+FirstRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size).Gravity = Gravity.CENTER
      
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i+FirstRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        Else
            Key.IsShifted = False
            AlphaNumericButton(i+FirstRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If

        ButtonWidth = SecondRowButtonSizes.Get(i)

        AlphaNumericPanel.AddView(AlphaNumericButton(i+FirstRow.Size), LeftPos, TopPos, ButtonWidth, ButtonHeight)
        LeftPos = LeftPos + SecondRowButtonSizes.Get(i) + 1dip

    Next
  
    ' 13 knappar rad 3

    ThirdRow.Initialize2(Array As String(Chr(15),"a","s","d","f","g","h","j","k","l","ö","ä","'"))
    ThirdRowCapped.Initialize2(Array As String(Chr(15),"A","S","D","F","G","H","J","K","L","Ö","Ä","*"))
    ThirdRowButtonSizes.Initialize2(Array As String(Button1x5Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip
  
    For i = 0 To ThirdRow.Size - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = ThirdRow.Get(i)
        Key.ShiftedKey = ThirdRowCapped.Get(i)
      
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size).Gravity = Gravity.CENTER
      
        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)      
        Else
            Key.IsShifted = False
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
      
        AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Tag = Key
        AlphaNumericButton(i + FirstRow.Size + SecondRow.Size).Gravity = Gravity.CENTER
        AlphaNumericPanel.AddView(AlphaNumericButton(i + FirstRow.Size + SecondRow.Size),LeftPos,TopPos,ThirdRowButtonSizes.Get(i),ButtonHeight)
        LeftPos = LeftPos + ThirdRowButtonSizes.Get(i) + 1dip

    Next

    ' 13 knappar rad 4

    ForthRow.Initialize2(Array As String(Chr(14),"<","z","x","c","v","b","n","m",",",".","-",Chr(14)))
    ForthRowCapped.Initialize2(Array As String(Chr(14),">","Z","X","C","V","B","N","M",";",":","_",Chr(14)))
    ForthRowButtonSizes.Initialize2(Array As String(Button1x25Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width, _
    Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button1x0Width,Button2x25Width))

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip
  
    For i = 0 To ForthRow.Size - 1

        Dim Key As KeyboardKey
        Key.Initialize
        Key.NormalKey = ForthRow.Get(i)
        Key.ShiftedKey = ForthRowCapped.Get(i)

        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Initialize("AlphaNumButton")
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Tag = Key
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Typeface = DroidSansMono
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).TextSize = Screen.FontSizeButtons
        AlphaNumericButton(i+FirstRow.Size + SecondRow.Size + ThirdRow.Size).Gravity = Gravity.CENTER

        If Default = "" Then
            Key.IsShifted = True
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)      
        Else
            Key.IsShifted = False
            AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        End If
      
        If i = ForthRow.Size - 1 Then
            ButtonWidth = PanelSize.Width - LeftPos - 1dip - 5dip
        Else
            ButtonWidth = ForthRowButtonSizes.Get(i)
        End If
      
        AlphaNumericPanel.AddView(AlphaNumericButton(i + FirstRow.Size + SecondRow.Size + ThirdRow.Size),LeftPos,TopPos,ButtonWidth,ButtonHeight)
        LeftPos = LeftPos + ForthRowButtonSizes.Get(i) + 1dip

    Next

    LeftPos = 5dip
    TopPos = TopPos + ButtonHeight + 1dip

    ' + Spaceknapp

    Dim Key As KeyboardKey
    Key.Initialize
    Key.NormalKey = " "
    Key.ShiftedKey = " "
  
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Initialize("AlphaNumButton")
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Tag = Key
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Typeface = DroidSansMono
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).TextSize = Screen.FontSizeButtons
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Gravity = Gravity.CENTER
    AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size).Text = "Mellanslag"

    AlphaNumericPanel.AddView(AlphaNumericButton(FirstRow.Size + SecondRow.Size + ThirdRow.Size + ForthRow.Size),LeftPos,TopPos,PanelSize.Width - 10dip, ButtonHeight)
  
    PanelSize.Height = TopPos + ButtonHeight + 5dip

    Dim AlphaNumericDialogParams As BD_CustomDlgParams
    AlphaNumericDialogParams.Initialize
    AlphaNumericDialogParams.Title = Title
    AlphaNumericDialogParams.Background = Graphics.GenerateWatermarkLogoDialogBackground(PanelSize.Width,PanelSize.Height)
    AlphaNumericDialogParams.DialogBody = AlphaNumericPanel
    AlphaNumericDialogParams.BodyWidth = PanelSize.Width
    AlphaNumericDialogParams.BodyHeight = PanelSize.Height
    AlphaNumericDialogParams.PositiveButton = Language.GetString(Language.LanguageStrings.DialogsOK)
    AlphaNumericDialogParams.CancelButton = Language.GetString(Language.LanguageStrings.DialogsCancel)

    DialogAnswer = Dialog.CustomDialog(AlphaNumericDialogParams, "AlphaNumPad")
  
    Select DialogAnswer
  
        Case DialogResponse.POSITIVE

            ResponseValue.Cancelled = False
            ResponseValue.Value = AlphaNumericEditText.Text
      
        Case DialogResponse.CANCEL
      
            ResponseValue.Cancelled = True
            ResponseValue.Value = 0.00
      
        Case DialogResponse.NEGATIVE
      
            ResponseValue.Cancelled = True
            ResponseValue.Value = 0.00
      
    End Select

    Return ResponseValue

End Sub

Sub AlphaNumPad_BackKeyPressed As Boolean

    Return False 'Cancels the dialog
  
End Sub

Sub ShiftUp

    For x = 0 To AlphaNumericButton.Length - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsShifted = False
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub ShiftDown

    For x = 0 To AlphaNumericButton.Length - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsShifted = True
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub CapsLockOn

    For x = 0 To AlphaNumericButton.Length - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsCapsLock = True
        Key.IsShifted = True
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.ShiftedKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub CapsLockOff

    For x = 0 To AlphaNumericButton.Length - 1
  
        Dim Key As KeyboardKey
        Key.Initialize
        Key = AlphaNumericButton(x).Tag
        Key.IsCapsLock = False
        Key.IsShifted = False
        AlphaNumericButton(x).Text = TranslateNonVisibleCharToText(Key.NormalKey)
        AlphaNumericButton(x).Tag = Key

    Next

End Sub

Sub TranslateNonVisibleCharToText(Character As String) As String

    Select Character

        Case Chr(8):
      
            Return "<--"
      
        Case Chr(9):
      
            Return "Tab"

        Case Chr(14):
      
            Return "Shift"
      
        Case Chr(15):
      
            Return "Caps Lock"

        Case Chr(34):

            Return Chr(34)

        Case Else
      
        Return Character
  
    End Select

End Sub

Sub AlphaNumButton_Click

        Dim KeyButton As Button = Sender
        Dim ClickedKey As KeyboardKey
      
        ClickedKey.Initialize
        ClickedKey = KeyButton.Tag
      
        Dim KeyChar As String
      
        If ClickedKey.IsShifted = True Then
            KeyChar = ClickedKey.ShiftedKey
        Else
            KeyChar = ClickedKey.NormalKey
        End If

        Select KeyChar

        Case Chr(8):
      
            If ClickedKey.IsCapsLock = True Then
                CapsLockOff
            Else
                CapsLockOn
            End If
          
      
        Case Chr(9):
      
            If ClickedKey.IsShifted = True Then
                ShiftUp
            Else
                ShiftDown
            End If

        Case Else
      
            If AlphaNumericEditText.SelectionStart = -1 Then
                AlphaNumericEditText.Text = AlphaNumericEditText.Text & KeyChar
            Else
                Dim Start As Int = AlphaNumericEditText.SelectionStart
                AlphaNumericEditText.Text = AlphaNumericEditText.Text.SubString2(0, Start) & KeyChar & AlphaNumericEditText.Text.SubString(Start)
            End If
  
    End Select
  
End Sub
Activity_Create is not a place to show dialogs and, more generally, to raise events. Open your dialog in the Resume event or use CallSubDelayed if you want to keep your code in Create (untested but that should work).
 

TheMightySwe

Active Member
Licensed User
Longtime User
Activity_Create is not a place to show dialogs and, more generally, to raise events. Open your dialog in the Resume event or use CallSubDelayed if you want to keep your code in Create (untested but that should work).


I just put it there for testing, I try the resume.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Hi, I cannot provide the sample as isolated code. Anyway, I just calle a sub in a code module. The code module contains the betterdialogs stuff.

Sometimes the keyboard hides and sometimes not. Not using any custom dialog.

Might be issues with other libraries etc.
 

maleche

Active Member
Licensed User
Longtime User
Hello folks,
I'm trying to find the best method to use the InputDialog for IP address
I would like to use "INPUT_TYPE_NUMBERS" as the input type, but there is no period "."
what other library would give me IP numbers or is there an Input Type that will allow Numbers with periods.
"INPUT_TYPE_DECIMAL_NUMBERS" will not allow multiple periods and I don't want to use the whole alpha keyboard.
thanks!
 

Informatix

Expert
Licensed User
Longtime User
Hello folks,
I'm trying to find the best method to use the InputDialog for IP address
I would like to use "INPUT_TYPE_NUMBERS" as the input type, but there is no period "."
what other library would give me IP numbers or is there an Input Type that will allow Numbers with periods.
"INPUT_TYPE_DECIMAL_NUMBERS" will not allow multiple periods and I don't want to use the whole alpha keyboard.
thanks!
For an IP address, you could use a mask with fixed dots, e.g. "###.###.###.###".
 

maleche

Active Member
Licensed User
Longtime User
I did notice the mask for the IP. I need the INPUT_TYPE_NUMBERS dialog to also show the period "." so it can be entered into the text box.
is there an input type to show the period and numbers too? the "INPUT_TYPE_DECIMAL_NUMBERS" only allowed one period.
thanks
 

Andris

Active Member
Licensed User
Longtime User
Does the HTML in BetterDialogs support text alignment? It seems that
B4X:
text-align: center
doesn't work, so I suspect the answer is no. Great library though!
 

Dave O

Well-Known Member
Licensed User
Longtime User
I have a "rename item" input box where I'd like to do a "Select All" on the text when they open the dialog (instead of just positioning the cursor at the end).

That way, the user can just start typing to replace a default name (which is the most common action in this particular dialog), and not have to fiddle with the cursor or long-press for the actionbar so they can choose Select All.

Is there a way to do this, using the BetterDialogs library (or even agraham's original Dialogs library)? I've played with the BetterDialogs example but couldn't find a function or property that seemed relevant.

BTW, the zip file did not contain your customary docs (an HTML file or text file), so I assume the best way to inspect the properties and methods is to use the auto-suggest feature of the IDE? Or are the docs there and I missed them?

Any help greatly appreciated. Merci!
 

Informatix

Expert
Licensed User
Longtime User
No, there's no documentation file, but you can use the object browser to see all functions with their description.

I confirm that you cannot select the text. You have two solutions: either you use the Hint property to show the default name and you let the Default property empty, or you create a custom dialog with an EditText inside.
 

Dave O

Well-Known Member
Licensed User
Longtime User
> create a custom dialog with an EditText inside

I tried this (by modifying your demo), and called SelectAll on the edittext field.

The custom dialog opens, and the text is indeed all selected, but the keyboard does not appear unless I tap on the field (which deselects the text). Is there a way to force the keyboard open like InputBox does? I tried RequestFocus and IME.showKeyboard, but of course they can't really be called by me during a modal dialog, correct?

What I'm looking for (ideally) is for the dialog to open, the text to be selected, and the keyboard is shown, so the user can start typing immediately.

The InputBox does this already (except the Select All part). What would be very handy is if there was a way to request the InputBox to do a select-all. For example, if the CursorPosition was set to a negative value, the InputBox code could interpret that as "select all", then call the SelectAll method on its edittext field (essentially just passing through the SelectAll request).

My workaround for now is to create my own modal dialog (using a blocking panel and a dialog panel).

Thanks!
 

Informatix

Expert
Licensed User
Longtime User
> create a custom dialog with an EditText inside

I tried this (by modifying your demo), and called SelectAll on the edittext field.

The custom dialog opens, and the text is indeed all selected, but the keyboard does not appear unless I tap on the field (which deselects the text). Is there a way to force the keyboard open like InputBox does? I tried RequestFocus and IME.showKeyboard, but of course they can't really be called by me during a modal dialog, correct?

What I'm looking for (ideally) is for the dialog to open, the text to be selected, and the keyboard is shown, so the user can start typing immediately.

The InputBox does this already (except the Select All part). What would be very handy is if there was a way to request the InputBox to do a select-all. For example, if the CursorPosition was set to a negative value, the InputBox code could interpret that as "select all", then call the SelectAll method on its edittext field (essentially just passing through the SelectAll request).

My workaround for now is to create my own modal dialog (using a blocking panel and a dialog panel).

Thanks!
The OpenKeyboard property does not work? In the demo, it works fine on all my devices.
 

Dave O

Well-Known Member
Licensed User
Longtime User
Ah yes, not sure how I missed that one. That part works fine now, thanks.

Is there any way to auto-close the dialog when the user finishes typing (and clicks the Done button on the keyboard)?

Right now, in both the InputBox and the CustomDialog, clicking the keyboard's Done button closes the keyboard, but leaves the dialog open, so the user must click OK to dismiss it. (That would be normal behaviour in a custom dialog, because there may be several widgets, but would be nice to have the option to auto-close the dialog.)

Thanks again!
 

Informatix

Expert
Licensed User
Longtime User
Ah yes, not sure how I missed that one. That part works fine now, thanks.

Is there any way to auto-close the dialog when the user finishes typing (and clicks the Done button on the keyboard)?

Right now, in both the InputBox and the CustomDialog, clicking the keyboard's Done button closes the keyboard, but leaves the dialog open, so the user must click OK to dismiss it. (That would be normal behaviour in a custom dialog, because there may be several widgets, but would be nice to have the option to auto-close the dialog.)

Thanks again!
In Java, there are the events "onKeyPreIME" and "onEditorAction" to detect a keypress on Back or Done that closes the keyboard. But in B4A, I'm not familiar with what you can do. Maybe by using the IME library.
 

jayel

Active Member
Licensed User
Longtime User
Hello,

I use betterdialogs with success, my app is running on blackberry Z10 with the 10.3 wish can run apk files.
Now when I use your betterdialogs and I put : IP.InputType = IP.INPUT_TYPE_TEXT_WITH_CAPS the capitalization works perfectly with the blackberry.
But when I use a lib that someone made to capitalize the sentences in a textbox, the capitalization works on a android device but not on a balckberry device.
maybe you can help because yours does work.

I use lib in attachment.
 

Attachments

  • SLInpTypeConst.bas
    11.9 KB · Views: 215

Informatix

Expert
Licensed User
Longtime User
Hello,

I use betterdialogs with success, my app is running on blackberry Z10 with the 10.3 wish can run apk files.
Now when I use your betterdialogs and I put : IP.InputType = IP.INPUT_TYPE_TEXT_WITH_CAPS the capitalization works perfectly with the blackberry.
But when I use a lib that someone made to capitalize the sentences in a textbox, the capitalization works on a android device but not on a balckberry device.
maybe you can help because yours does work.

I use lib in attachment.
Sorry but I don't have enough time to debug code made by others. I fixed some issues related to InputType in my library (you have to set this value at a specific time; doing it before or after other settings may not work).
 
Top