6

I created java binding library via visual studio extension called Xamarin.GradleBinding. I added ru.rambler.android:swipe-layout:1.0.14 package and while using its SwipeLayout, it all works well. But unfortunately it did not created corresponding C# classes or anything like that. I tried adding package manually but still nothing.

I checked the source on GitHub. SwipeLayout has a public void method reset() without parameters:

public void reset()

I try to call this method from c# with JNIEnv.

IntPtr type = JNIEnv.FindClass("ru/rambler/libs/swipe_layout/SwipeLayout");
IntPtr method = JNIEnv.GetMethodID(type, "reset", "()V");
try
{
    JNIEnv.CallObjectMethod(_swiper.Handle, method);
}
catch (Exception ex)
{
    var s = ex.Message;
}

Type and method are successfully found but calling

JNIEnv.CallObjectMethod(_swiper.Handle, method);

This method crashes the app, it does not even goes into catch block.

Tt must be cause of the _swiper.Handle first parameter. _swiper field is of type ViewGroup since SwipeLayout is derived from ViewGroup. I can't find how to get the pointer of the view to pass that method.

while debugging, when I investigate the _swiper, it seems to be the correct instance of SwipeLayout

enter image description here

nkr
  • 3,026
  • 7
  • 31
  • 39
mister_giga
  • 560
  • 1
  • 15
  • 37
  • I'm pretty sure build gradles don't exist in xamarin – FreakyAli Jan 17 '18 at 09:23
  • it works, it displays the custom view when I add in AXML file, but there is no c# equivalent class – mister_giga Jan 17 '18 at 10:02
  • what class are you looking for – FreakyAli Jan 17 '18 at 10:10
  • @G.hakim SwipeLayout – mister_giga Jan 17 '18 at 10:28
  • what does it do? there will probably be a xamarin android equivalent for it why not use that – FreakyAli Jan 17 '18 at 10:29
  • @G.hakim i use it in collection where you swipe view and see some actions. This is simple to use and has a good experience, thats why i want to use it – mister_giga Jan 17 '18 at 10:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163326/discussion-between-mister-giga-and-g-hakim). – mister_giga Jan 17 '18 at 12:54
  • I would say that you are going down the wrong path for this binding library. Rather than going directly to JNI, you should be trying to "help" the binding generator, so you get a more accurate and complete binding. For example a typical reason C# classes are not bound is that you are missing a reference jar dependency. In this library we see `com.android.support:support-core-ui:24.2.1` - https://github.com/rambler-digital-solutions/swipe-layout-android/blob/develop/swipe-layout/build.gradle#L28 – Jon Douglas Jan 22 '18 at 16:37
  • Given how large this library is, it would actually probably be more beneficial to convert to C# instead of binding as it's only 1 class. – Jon Douglas Jan 22 '18 at 16:38
  • See my blog: https://www.jon-douglas.com/2016/10/28/porting-android-libraries-to-xamarin-android/ – Jon Douglas Jan 22 '18 at 16:38

1 Answers1

1

I have done a rewrite of the control to C# with Xamarin.Android. It is available here on my GitHub, but I haven't had time to test it yet, so it might have bugs.

But you can try it and potentially fix the bugs I have missed during the rewrite using the original .java source code.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • Thank you, I will try it and tell you results – mister_giga Jan 25 '18 at 08:21
  • sorry, it has bugs in really. it draws layout well, but calling Reset on it makes it dissapear while it shall reset state, also if i swipe fast the layout swipes too much. :( but thank you for your efforts – mister_giga Jan 28 '18 at 21:19
  • But feel free to fix the issues, it should be just oversights :-) – Martin Zikmund Jan 28 '18 at 21:20
  • I need that library because I want it's functionality without looking inside the code. I will also need to reference other java packages and I can't sit and rewrite every library I may need – mister_giga Jan 28 '18 at 21:44
  • I understand. You will definitely need to look into the Xamarin Java library binding a bit more to learn about the ways to give the binder a hint of how to bind the classes. It should be possible with a bit of help to bind any native library. – Martin Zikmund Jan 28 '18 at 21:55
  • Yearly unclosed answer review - @mister_giga, if this helped, please consider accepting the answer as solution so that the question is closed. – Martin Zikmund Dec 06 '18 at 15:52