Binding Java Library - android-wheel

Hello,

So I am trying to create a binding for the (android-wheel library)[https://github.com/maarek/android-wheel]. I got the Assembly to compile with the following Metadata.xml:



AndroidWheel.Widget
AndroidWheel.Widget.Adapters

 <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AbstractWheelTextAdapter']/method[@name='getItemText']" name="visibility">public</attr>
 <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AbstractWheelTextAdapter']" name="visibility">public</attr>

 <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AdapterWheel']/method[@name='getItemText']"  name="visibility">public</attr>
 <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AdapterWheel']"  name="visibility">public</attr>
</metadata>

Then I create an adapter for the file following the https://github.com/maarek/android-wheel/blob/master/wheel-demo/src/kankan/wheel/demo/extended/HoloWheelActivity.java example.

The adapter looks like this:

            using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using AndroidWheel.Widget.Adapters;

    namespace DEMO.Droid
    {
        class DemoTypeAdapter : AbstractWheelTextAdapter {
            // City names
            public static Java.Lang.String[] cities = {new Java.Lang.String("New York")};//, "Washington", "Chicago", "Atlanta", "Orlando"};

            /**
             * Constructor
             */
            //FIXME: Look for no resource.
            public DemoTypeAdapter(Context context) : base(context, Resource.Layout.city_holo_layout){
                ItemTextResource = Resource.Id.font_picker_name;
            }

            public override View GetItem(int index, View cachedView, ViewGroup parent) {
                View view = base.GetItem(index, cachedView, parent);
                return view;
            }

            public override Int32 ItemsCount {
                get{
                    return cities.Count();
                }
            }

            public override global::Java.Lang.ICharSequence GetItemTextFormatted(Int32 index) {
                return cities[index];
            }
        }
    }

I am unsure about the Java.Lang.String that I am doing in the above code and also the overriding of the GetItemTextFormatted method.

This compiles then in my Activity I do (separate project with the AndroidWheel library referenced):

        WheelView cities = (WheelView) View.FindViewById(Resource.Id.demo_picker);
        cities.VisibleItems = 5; // Number of items
        cities.SetWheelBackground(Resource.Drawable.wheel_bg_holo);
        cities.SetWheelForeground(Resource.Drawable.wheel_val_holo);
        //cities.SetShadowColor(0xFF000000, 0x88000000, 0x00000000);
        cities.ViewAdapter = new FontTypeAdapter(this);
        cities.CurrentItem = 1;;

The problem I have is how to reference the WheelView in the Layout XML?

    <kankan.wheel.widget.WheelView android:id="@+id/demo_picker"
    android:layout_height="110dp"
    android:layout_width="wrap_content"
            android:layout_gravity="center_vertical"
    android:layout_marginLeft="10dp"
    android:layout_weight="1.5"/>

The app compiles and runs but fails when creating the view with:

 ....
 [mono] android.view.InflateException: Binary XML file line #1: Error inflating class kankan.wheel.widget.WheelView
 ....

I do not know how to reference the correct path to the WheelView, I had similar issues when trying to do set an "android:actionViewClass="my.custom.actionView"". How do you resolve the path to the C# Class?

I cannot see any difference betweent this setup and the setup of https://github.com/xamarin/monodroid-samples/tree/master/OsmDroidBindingExample in mycode.

Posts

  • AdrianCookeAdrianCooke USMember

    I just noticed that I indented the XML for the Metadata.xml incorrectly, it should be:

            <metadata>
              <!-- fixup the namespaces, notice that we have to do onw for each namespace. -->
              <attr path="/api/package[@name='kankan.wheel.widget']" name="managedName">AndroidWheel.Widget</attr>
              <attr path="/api/package[@name='kankan.wheel.widget.adapters']" name="managedName">AndroidWheel.Widget.Adapters</attr>
    
              <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AbstractWheelTextAdapter']/method[@name='getItemText']" name="visibility">public</attr>
              <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AbstractWheelTextAdapter']" name="visibility">public</attr>
    
              <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AdapterWheel']/method[@name='getItemText']"  name="visibility">public</attr>
              <attr path="/api/package[@name='kankan.wheel.widget.adapters']/class[@name='AdapterWheel']"  name="visibility">public</attr>
    
            </metadata>
    
  • AdrianCookeAdrianCooke USMember

    I figured out what the problem is. It should be in the documentation for creating Java bindings.

    The android-wheel uses some resources and Xamarin does not know about them thus you have to follow the instructions in forums.xamarin.com/discussion/137/shared-resource-with-java-bindings-library post from topgenorth to get the LibraryProjectZip added to the bindings library.

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Just a heads up: Section 5 of the Binding a Java Library (.jar) project explains this.

  • AdrianCookeAdrianCooke USMember

    Hello ToGeNorth,

    Sorry my bad. I did not see that. Possibly move it to above the 4. Troubleshooting Bindings section to make it more visible? But I just did not read far enough...

  • BarryDunneBarryDunne IEUniversity

    I am hoping to use that widget, could you please share your working bindings project?
    Thanks,
    Barry.

  • MikeDennisMikeDennis USMember ✭✭

    @AdrianCooke and @BarryDunne : I am planning to use the same widget, is there any sample project available for reference?

Sign In or Register to comment.