Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
In Android's KeyboardView.OnKeyboardActionListener , the onKey, onPress, and onRelease methods take an int and an int for onKey, but in XA's KeyboardView.IOnKeyboardActionListener  those methods take an Android.Views.Keycode Enumeration and for OnKey it also takes an Android.Views.Keycode array.
This has been causing some difficulty for the customer who reported bug #43397 which was rightly resolved as a feature, but the issue they are hitting seems more to do with the fact that the XA versions of these methods expect a KeyCode rather than an int. This seems to be causing the issue encountered in bug #43397. IOW in order to get their custom keyboards CAPS lick button to properly display the status with a green dot, the have to set the android:codes in the qwerty.xml file (defining the custom keyboard) for the CAPS key to -1, and then -1 is passed in to OnKey, and there is no -1 value in the Keycode enum, so it would seem that this is not the enum that should be used, or better that the methods just take an int as in native Android.
## Steps to reproduce
=== Xamarin Studio Enterprise ===
Version 6.0.2 (build 73)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Mono 4.4.2 (mono-4.4.0-branch-c7sr1/f72fe45) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Package version: 404020011
=== Xamarin.Profiler ===
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Apple Developer Tools ===
Xcode 7.3.1 (10188.1)
=== Xamarin.Mac ===
Version: 184.108.40.206 (Visual Studio Enterprise)
=== Xamarin.Android ===
Version: 220.127.116.11 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
SDK Tools Version: 25.1.7
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3
Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
Android Designer EPL code available here:
=== Xamarin Android Player ===
Location: /Applications/Xamarin Android Player.app
=== Xamarin.iOS ===
Version: 18.104.22.168 (Visual Studio Enterprise)
Build date: 2016-07-28 12:17:02-0400
=== Xamarin Inspector ===
Build date: Tue Apr 26 23:07:44 UTC 2016
=== Build Information ===
Release ID: 600020073
Git revision: a6f7a24a9723a2d4f5d33c176615b0d44703ab5b
Build date: 2016-07-26 13:36:15-04
Xamarin addins: f5acb37866a0141bc5ddbe95118f18dae4014568
Build lane: monodevelop-lion-cycle7-sr1
=== Operating System ===
Mac OS X 10.11.6
Darwin Jons-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
Thu Jun 23 18:25:34 PDT 2016
=== Enabled user installed addins ===
Xamarin Inspector 0.8.0.0
As more information...
I think the Keycode enumerator should not be used as type for the OnKey method and that Android expects the int value to be the Unicode value of the character.
In the sample application I’ve supplied (can be found in the linked bug: 43397), if you add a popup to a key then you get incorrect values passed in. Or rather the Keycode enumerator fails to map correctly. Here are steps to reproduce:
Step 1 – Modify a key in qwerty.xml to have a popup keyboard. I used the “-“ key:
<Key android:codes="69" android:keyLabel="-" android:popupCharacters=",./?" android:popupKeyboard="@xml/keyboard_popup_template" android:keyEdgeFlags="right"/>
Step 2 – Create a new file in the xml folder called keyboard_popup.template.xml with the following contents:
<?xml version="1.0" encoding="utf-8" ?>
Execute the application and press & hold the key to get the popup keyboard as shown in this image:
This is the value passed for each key to the OnKey method:
• [ == 91
• ] == 93
• , == 44
• . == 46
• / == 47
• ? == 63
Here is the KeyCode mappings for those values:
• [ == 91 == Mute
• ] == 93 == PageDown
• , == 44 == P
• . == 46 == R
• / == 47 == S
• ? == 63 == Sym
Here is the Unicode mappings for those values:
• [ == 91 == U005B (which is 91 decimal)
• ] == 93 == U005D (which is 93 decimal)
• , == 44 == U002C (which is 44 decimal)
• . == 46 == U002E (which is 46 decimal)
• / == 47 == U002F (which is 47 decimal)
• ? == 63 == U003F (which is 63 decimal)
In the Keyboard.Key class, you can specify the popupCharacters and you can specify the layout, but I didn’t see anything that lets you specify the VALUES of the popup characters, so I don’t see any way to map the keys to the Keycode enumerator. As you can see in the data above Android assumes you’ll be casting the INT in the OnKey to a Unicode character… not a Keycode enumerator.
It appears the OnKey method for the KeyboardView.IOnKeyboardActionListener interface should not use the Keycode enumerator but should instead use an int and int.
Up until now I have been able to work around this bug – however in order to use popup keys on the keyboard it must map to Unicode values and NOT Keycode enumerator values.
Also, please answer this – what Keycode enumerator maps to Question Mark? (Hint: None.) This begs the question… how do I represent keys not in Keycode enumerator? In other words, if it should use the Keycode enumerator, and if I use the example above, what should the "?" map to in the Keycode enumerator because currently the Keycode enumerator does not contain an entry for "?".
There are always chances that a method or field that takes int "had better be converted to enum even if there are slight chance of use case where enums cannot apply".
I am PERSONALLY against applying enums to the entire Xamarin.Android world, but the world is already made. In this world, we should live in the best-matching enum application API.
(I am against it only because I am fine with Java-styled int constants, which is quite argurable.)
This method should not be dragged back to int. It should be kept in enum because that would make 99% people happier. There is no global solution for this that works for 100% people.
And as a workaround, conversion between int and enums is easy.