Forum Xamarin.Android

Java final int to C# enum binding

Hi all,

I'm trying to see if it is feasible for me to port a 3D android application to Xamarin. I am using a Java library called Rajawali3D and I have managed to fix all of the binding errors except one:

'RajawaliSurfaceView' does not implement interface member 'IRajawaliSurface.RenderMode'. 'GLSurfaceView.RenderMode' cannot implement 'IRajawaliSurface.RenderMode' because it does not have the matching return type of 'int'.

So, IRajawaliSurface.RenderMode is an int property but GLSurfaceView.RenderMode is an Android.Opengl.Rendermode property. Since RajawaliSurfaceView inherits from GLSurfaceView and implements IRajawaliSurface there is this return type conflict. At least, that's what I think. Correct me if I'm off track so far.

To solve this, I've been trying to change the type of IRajawaliSurface.RenderMode to be Android.Opengl.Rendermode. As it happens they both represent the same thing and each enum value in Rendermode corresponds to the int values in IRajawaliSurface.RenderMode. Here's what I've been trying in EnumMethods.xml:
<mapping jni-interface="org/rajawali3d/surface/IRajawaliSurface"> <method jni-name="getRenderMode" parameter="return" clr-enum-type="Android.Opengl.Rendermode" /> <method jni-name="setRenderMode" parameter="p0" clr-enum-type="Android.Opengl.Rendermode" /> </mapping>
So far this has had no effect. I have no idea what the problem is. I tried jni-class instead of jni-interface but that didn't work either. Here is the generated code for IRajawaliSurface.RenderMode:

// Metadata.xml XPath interface reference: path="/api/package[@name='org.rajawali3d.surface']/interface[@name='IRajawaliSurface']"
[Register ("org/rajawali3d/surface/IRajawaliSurface", "", "Org.Rajawali3d.Surface.IRajawaliSurfaceInvoker")]
public partial interface IRajawaliSurface : IJavaObject {
int RenderMode {
    // Metadata.xml XPath method reference: path="/api/package[@name='org.rajawali3d.surface']/interface[@name='IRajawaliSurface']/method[@name='getRenderMode' and count(parameter)=0]"
    [Register ("getRenderMode", "()I", "GetGetRenderModeHandler:Org.Rajawali3d.Surface.IRajawaliSurfaceInvoker, Rajawali")] get;
// Metadata.xml XPath method reference: path="/api/package[@name='org.rajawali3d.surface']/interface[@name='IRajawaliSurface']/method[@name='setRenderMode' and count(parameter)=1 and parameter[1][@type='int']]"
    [Register ("setRenderMode", "(I)V", "GetSetRenderMode_IHandler:Org.Rajawali3d.Surface.IRajawaliSurfaceInvoker, Rajawali")] set;

Any ideas?


  • la.tanblala.tanbla USMember ✭✭


  • la.tanblala.tanbla USMember ✭✭

    Can some one explain why my mapping in EnumMethods.xml is having no effect on the generated output?

  • la.tanblala.tanbla USMember ✭✭

    I still don't know what's up with my EnumMethods.xml and EnumFields.xml. They wouldn't have solved the problem any way, but I still don't like that I couldn't figure out how to get them to work. I was able to solve the problem by including the following tags in MetaData.xml:
    <attr path="/api/package[@name='org.rajawali3d.surface']/interface[@name='IRajawaliSurface']/method[@name='getRenderMode' and count(parameter)=0]" name="return">Android.Opengl.Rendermode</attr> <attr path="/api/package[@name='org.rajawali3d.surface']/interface[@name='IRajawaliSurface']/method[@name='setRenderMode' and count(parameter)=1 and parameter[1][@type='int']]/parameter[@type='int']" name="type">Android.Opengl.Rendermode</attr>
    So now my generated code casts from int to Android.Opengl.Rendermode. I don't have a Xamarin subscription, so I can't test if this will throw any runtime libraries, but if anyone has this type of problem and it does work or it doesn't, please post.

Sign In or Register to comment.