Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Material] Slider.addOnChangeListener binding missing #230

Open
tipa opened this issue Dec 16, 2020 · 17 comments
Open

[Material] Slider.addOnChangeListener binding missing #230

tipa opened this issue Dec 16, 2020 · 17 comments
Labels
missing-api Java types/members not available in binding

Comments

@tipa
Copy link

tipa commented Dec 16, 2020

Version Information

  • Visual Studio version (eg. 16.8 or 8.8): 16.8.3
  • Xamarin.Android version (eg. 11.1): 11.1
  • Using AndroidX or Support Libraries: Xamarin.Google.Android.Material 1.2.1.1

Describe your Issue:

Slider.IOnChangeListener is bound, but there is no way to add it to the Slider class, the addOnChangeListener method hasn't been bound

Steps to Reproduce (with link to sample solution if possible):

var slider = FindViewById<Google.Android.Material.Slider>(Resource.Id.my_slider);
slider.addOnChangeListener(listener); // compile error
slider.Change += Slider_Changed; // compile error
@tipa tipa added the packages label Dec 16, 2020
@jpobst
Copy link
Contributor

jpobst commented Dec 16, 2020

Binding issue:

13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type L in method AddOnChangeListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type L in method AddOnChangeListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type T in method AddOnSliderTouchListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type T in method AddOnSliderTouchListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type L in method RemoveOnChangeListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type L in method RemoveOnChangeListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type T in method RemoveOnSliderTouchListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type T in method RemoveOnSliderTouchListener in managed type Google.Android.Material.Slider.RangeSlider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type L in method AddOnChangeListener in managed type Google.Android.Material.Slider.Slider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type L in method AddOnChangeListener in managed type Google.Android.Material.Slider.Slider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type T in method AddOnSliderTouchListener in managed type Google.Android.Material.Slider.Slider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type T in method AddOnSliderTouchListener in managed type Google.Android.Material.Slider.Slider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type L in method RemoveOnChangeListener in managed type Google.Android.Material.Slider.Slider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type L in method RemoveOnChangeListener in managed type Google.Android.Material.Slider.Slider.
13>    BINDINGSGENERATOR : warning BG8800: Unknown parameter type T in method RemoveOnSliderTouchListener in managed type Google.Android.Material.Slider.Slider.
13>    C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.Core.targets(61,5): message BG0000: warning BG8800: Unknown parameter type T in method RemoveOnSliderTouchListener in managed type Google.Android.Material.Slider.Slider.
13>    BINDINGSGENERATOR : warning BG8700: Unknown return type P in method GetPrimaryAnimatorProvider in managed type Google.Android.Material.Transition.MaterialElevationScale.

@jpobst jpobst added the bug Component does not function as intended label Dec 16, 2020
@jpobst jpobst changed the title Slider.addOnChangeListener binding missing [Material] Slider.addOnChangeListener binding missing Dec 16, 2020
@ivmazurenko
Copy link

Reproduced for RangeSlider too. Or maybe I should use other API ?

@stalexig
Copy link

Although have the same issue

@ivmazurenko
Copy link

Any updates?

@tipa
Copy link
Author

tipa commented Feb 5, 2021

workaround:

var method = Class.ForName("com.google.android.material.slider.BaseSlider").GetDeclaredMethods().FirstOrDefault(x => x.Name == "addOnChangeListener");
method?.Invoke(slider, this); // this is implementing IBaseOnChangeListener

@moljac
Copy link
Member

moljac commented Feb 18, 2021

Please try 1.3.0 and provide feedback here.

If it is not fixed automagically I will dive in next week

@tipa
Copy link
Author

tipa commented Feb 18, 2021

@moljac thanks for the new bindings - great stuff! 🥳
Unfortunately no magic fix for this issue :(

@moljac
Copy link
Member

moljac commented Feb 19, 2021

@tipa

Thanks.

OK. I will need to dig in. Hopefully soon

@tipa
Copy link
Author

tipa commented Jun 9, 2021

Friendly ping :)
Would be great if this could be fixed so no workaround is necessary

@tipa
Copy link
Author

tipa commented Jul 13, 2021

Sadly, this issue is still present with 1.4.0

@ibrahimmd90
Copy link

ibrahimmd90 commented Aug 2, 2021

This is a workaround until they fix binding issue:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState, Resource.Layout.my_activity);
    slider = FindViewById<Slider>(Resource.Id.slider);
    slider.Touch += Slider_Touch;
}

private void Slider_Touch(object sender, View.TouchEventArgs e)
{
    switch (e.Event.Action)
    {
        case MotionEventActions.Move:
        case MotionEventActions.Up:
            OnValueChange(slider, slider.Value, true);  //(Slider slider, float value, boolean fromUser)
            break;
    }
    e.Handled = false;
}

//This footprint matches native library callback
private void OnValueChange(Java.Lang.Object sender, float value, bool fromUser)
{
    //Do what you want to do as if you are listening to ValueChanged event (or at least very near to actual event)
}

@xtuzy
Copy link

xtuzy commented Dec 8, 2021

1.4.0.5 still not work

@jpobst
Copy link
Contributor

jpobst commented May 24, 2022

Moving my comment from #450 here:

Ugh, this one is a mess. According to the public documentation Slider is defined like this:

public class Slider extends View {
  public void addOnChangeListener (L listener) { ... }
}

One may be wondering what L is because it isn't specified anywhere. That's because decompiling the .jar shows that the public documentation is lying:

public class Slider extends BaseSlider<Slider, Slider.OnChangeListener, Slider.OnSliderTouchListener> 
{
 ...
}

abstract class BaseSlider<S extends BaseSlider<S, L, T>, L extends BaseOnChangeListener<S>, T extends BaseOnSliderTouchListener<S>> extends View 
{
  public void addOnChangeListener(@NonNull L listener) { ... }
}

That is, the public Slider class inherits from the private BaseSlider class, which isn't allowed in C#. Our tooling attempts to fix this and have Slider inherit from the public View instead, and copy all the methods that it can from the BaseSlider class directly into the Slider class.

However, due to the lack of generics support in our tooling, it is unable to copy the addOnChangeListener method which requires a generic parameter. Thus this method is dropped from the binding:

warning BG8800: Unknown parameter type 'L' for member 'Google.Android.Material.Slider.Slider.AddOnChangeListener (L)'.

I would suggest continuing to use the workaround listed above.

@DavidMarquezF
Copy link

Is there no progress with this. Right now it's not very convenient to use these controls

@letscodewithkalyan
Copy link

letscodewithkalyan commented Mar 7, 2023

Still same with "1.8.0" version. Any progress ?

@marcoburato-ecutek
Copy link

I'm also affected by this.

I understand that updating the tooling to support this edge case would be hard, but is it not possible to add the required code manually in the bindings? I believe something like this is done, for instance, to add method overloads that accept .NET classes like System.Text.StringBuilder to improve interoperability between .NET and Java.

@Zintom
Copy link

Zintom commented Sep 17, 2023

Just me being nosy here, what's the tooling issue? Is it to do with all generic methods like this?

@jpobst jpobst added missing-api Java types/members not available in binding and removed packages bug Component does not function as intended labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing-api Java types/members not available in binding
Projects
None yet
Development

No branches or pull requests