Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Android custom renderer for longpress ok in API 19, 21 but not 22?

$
0
0

I have a custom renderer to enable tap and longpress capture on an image (see code below) which works fine on device running 4.4.4 (API19) and on another device that's running API 21 but when I try it on a device running API 22 (Samsung S6) although tap works longpress doesn't.

When I debug it (using API 22) I can see the HandleTouch event called in both cases but the OnLongPress method in the listener is never called yet when debugging using API 21 it is called.

Is this a problem with Xamarin.Android or with Android API's does anyone know?

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using Android.Views;
using System;

[assembly: ExportRenderer (typeof(myApp.uuiImage), typeof(myApp.Droid.uuiImageRenderer))]

namespace myApp.Droid
{
public class uuiImageRenderer : ImageRenderer
{
private uuiImageListener _listener;
private GestureDetector _detector;

    protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
    {
        base.OnElementChanged (e);

        if (_listener == null) 
        {
            _listener = new uuiImageListener(this);
            _detector = new GestureDetector(_listener);
            this.Touch += HandleTouch;
        }
    }
    void HandleTouch(object sender, Android.Views.View.TouchEventArgs e)
    {
        _detector.OnTouchEvent(e.Event);
    }
}
public class uuiImageListener : GestureDetector.SimpleOnGestureListener
{
    private uuiImageRenderer _renderer;

    public uuiImageListener(uuiImageRenderer renderer)
    {
        _renderer = renderer;
    }
    public override void OnLongPress(MotionEvent e)
    {
        uuiImage image = _renderer.Element as uuiImage;
        if (image != null)
        {
            image.held();
        }

        base.OnLongPress(e);
    }
    public override bool OnSingleTapConfirmed(MotionEvent e)
    {
        uuiImage image = _renderer.Element as uuiImage;
        if (image != null)
        {
            image.tapped();
        }

        return base.OnSingleTapConfirmed(e);
    }
}

}


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>