B4A Library CustomKeyboard-Library

I developed a hexeditor to change the contents of hex-files. During the work I found that editing a hex-file by using the standard-softkeyboard is horrible. So I decided to write a library for an own softkeyboard. This library needs at least API-level-15

Good for understanding how it works is a posting of Maarten Fampennings which you can find here.
Also useful is a guide on the xda-developers-page. You'll find it here.

After a lot of pitfalls I got it working and can share it now. Because I don't have much sparetime I can't give much support.

With this CustomKeyboard-library you can replace the standard-softkeyboard with your self-designed-CustomKeyboard. You can use different keyboards and also different styles (see example 3). You also can have popup-minikeyboards for keys with more than one value. Have a good look in the 3 included examples and into the xml-files of the example-projects. Each method have an online-explanation of it's use included. You can add the EditTextView which you want to use with the CustomKeyboard by designer or with xml-file. The only difference between the two methods is that if you use the xml-method you can implement your owen full styling (textSelectHandle for example). If you use the designer-method you always get the standard styling from B4A. You can register as much EditTextViews as you like for each CustomKeyboard.
Declare just one CustomKeyboard-instance in your activity and use the RegisterEditText, ChangeKeyboardLayout/ChangeKeyboardStyle-methods to switch between different keyboards and styles (see example 3).

HOW TO USE:
  • put the CustomKeyboard.jar-file and the CustomKeyboard.xml-file into your AdditionalLibraries-folder
  • put the xml-file for the KeyboardView into the layout-folder of your project and mark it as writeprotected
  • put the xml-file(s) for the KeyboardLayout(s) into the xml-folder of your project and mark them as writeprotected
  • put all the drawables you used in the KeyboardLayout into the drawable-folder(s) of your project and mark them as writeprotected
  • put all your styling xml-files (if any) into the values-folder of your project and mark them as writeprotected
  • from now chose version a) (add EditTextView by designer) or version b) (add EditTextView by xml)

a)
  • place an EditTextView in the designer
  • in Activity_Create-sub load the designer-created layout-file into your Activity
  • initialize your CustomKeyboard with the Initialize-method of CustomKeyboard
  • register your EditTextView with the RegisterEditText-method of CustomKeyboard

b)
  • create an xml-file with an EditTextView, load it into the layout-folder of your project and mark it as writeprotected
  • in Activity_Create-sub load the designer-created layout-file into your Activity (if any)
  • with XmlLayoutBuilder load the EditTextView-xml-file into your Activity or any Panel
  • get the EditTextView with the GetAllViewsRecursive-method of XmlLayoutBuilder, remove it from parent and add again with layoutvalues
  • initialize your CustomKeyboard with the Initialize-method of CustomKeyboard
  • register your EditTextView with the RegisterEditText-method of CustomKeyboard


SUPPORTED EVENTS:

Keyboard related:
  • KeyboardEventName_KeyboardHeightChanged(NewHeight As Int, OldHeight As Int)
  • KeyboardEventName_onKeyUp(ViewTag As Object, PrimaryKeyCode As Int)
  • KeyboardEventName_KeyPressed (ViewTag As Object, PrimaryKeyCode As Int, AddKeyCodes() As Int) As Boolean
  • KeyboardEventName_onKeyDown(ViewTag As Object, PrimaryKeyCode As Int)

This events are all self-explanatory. You can catch the EditTextView which fired the event via the ViewTag (see example2)

EditText related:
  • eventName_Touch (Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean, fires if the registered EditText is touched by the user
  • eventName_FocusChanged (HasFocus As Boolean), fires if the registered EditText gets or looses focus
  • eventName_Click(), fires if the registered EditText is clicked by the user
  • eventName_TextChanged (Old As String, New As String), fires if the text of the registered EditText has changed
  • eventName_HandleAction() As Boolean, fires if the CustomKeyboard of the registered EditText contains an Enter-key and this is pressed


AVAILABLE METHODS:
  • IsOScompatible () As Boolean
  • Initialize (KeyboardEventName As String, KeyboardViewFileName As String)
  • IsIntialized () As Boolean
  • RegisterEditText (editTextView As EditText, eventName As String, KeyboardLayoutFileName As String, showCursor As Boolean) As Boolean
  • UnregisterEditText (et As EditText) As Boolean
  • GetRegisteredStatus (et As EditText) As String
  • SetCustomFilter (et As EditText, DefaultInputType As Integer, AcceptedCharacters As String)
  • SetLengthFilter (et As EditText, MaxLength As Integer)
  • ShowKeyboard (et As EditText)
  • HideKeyboard ()
  • IsSoftKeyboardVisible () As Boolean
  • GetCurKeyboardStyle () As String
  • GetCurLayoutFile () As String
  • ChangeKeyboardLayout (et As EditText, KeyboardLayoutFileName As String) As Boolean
  • ChangeKeyboardStyle (KeyboardViewFileName As String) As Boolean
  • ChangeKeyValues (OldLabel As String, OldIsIcon As Boolean, NewLabel As String, NewIsIcon As Boolean, NewCodes() As Integer) As Boolean
  • ShowPreviewPopup (show As Boolean)
  • IsPreviewEnabled () As Boolean
  • SetHapticFeedbackEnabled (boolean goEnabled)
  • IsHapticFeedbackEnabled () As Boolean
  • SetShifted (goShifted As Boolean)
  • IsShifted () As Boolean
  • HandleBack () As Boolean
  • GetSelectionStart (et As EditText) As Integer
  • GetSelectionEnd (et As EditText) As Integer
  • SetSelection (et As EditText, start As Integer, stop As Integer)
  • DeleteSelection (et As EditText)
  • ExtendSelection (et As EditText, toIndex As Integer)
  • InsertText (et As EditText, text As String, startIndex As Integer) As Boolean
 

Attachments

  • CustomKeyboardSample2.zip
    204.3 KB · Views: 592
  • CustomKeyboardSample3.zip
    349.7 KB · Views: 624
  • CustomKeyboardSample1.zip
    185.2 KB · Views: 591
  • CustomKeyboardLib.zip
    24.9 KB · Views: 598
Last edited:

ivan.tellez

Active Member
Licensed User
Longtime User
Just to be clear, This Lib its for use only in the same app right? Can't be used to create an installable keyboard available to all the aps?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I made a custom keyboard using your example as a base.

How would I add a Drag Tab to the top of it? So the use can drag the keyboard around the screen if they want.
Also if I wanted to add a Field to the keyboard (so I can show what they are type - kind of like a calculator)

Sorry for these probably easy questions but I haven't done much with xml

Thanks

BobVal
 

hears

Active Member
Licensed User
Longtime User
can you share this JAVA code ? i want make a full russian keyboard.not only numbers.
my email:[email protected]
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Wasn't sure if you were talking to me or the person who created the base class.

If me, here is the Keyboard I created.
 

Attachments

  • Keyboard.zip
    50 KB · Views: 432

hears

Active Member
Licensed User
Longtime User

Mwinsor

Member
Licensed User
Longtime User
I'm trying to use this library in my application but it shows no keyboard. I copied over all of the resource files but I cannot get this to work. It "acts" like it is working but the keyboard doesn't show. If I change to "standard" and use all the same calls it does show which leads me to think I have something else missing visually.
 

Mwinsor

Member
Licensed User
Longtime User
I'm trying to use this library in my application but it shows no keyboard. I copied over all of the resource files but I cannot get this to work. It "acts" like it is working but the keyboard doesn't show. If I change to "standard" and use all the same calls it does show which leads me to think I have something else missing visually.
I actually found the problem. If the activity had a background color in the designer, the keyboard didn't show up.
 

sigster

Active Member
Licensed User
Longtime User
NEXT was in CustomKeyboardSample2

B4X:
        <Key android:codes="60005"    android:keyLabel="NEXT" android:keyWidth="20%p" android:keyEdgeFlags="right" />
 

joko0124

Member
Licensed User
Longtime User
I actually found the problem. If the activity had a background color in the designer, the keyboard didn't show up.
Did your problem has been solved? Any solutions? I have also been experiencing it right now.
 

joko0124

Member
Licensed User
Longtime User
B4A Masters!
How can I move my modified custom keyboard to front? Master @Erel can you teach me please?
 

Attachments

  • Screenshot_2023-04-08-00-53-02-872_bwsi.PumpOperations.jpg
    Screenshot_2023-04-08-00-53-02-872_bwsi.PumpOperations.jpg
    343 KB · Views: 93
Top