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