зеркало из https://github.com/mono/mail-archives.git
396 строки
17 KiB
HTML
396 строки
17 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE> [mono-android] Gesture listener subclass no longer works with V4
|
|
</TITLE>
|
|
<LINK REL="Index" HREF="index.html" >
|
|
<LINK REL="made" HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20Gesture%20listener%20subclass%20no%20longer%20works%20with%20V4&In-Reply-To=CAA2GyZgUQLnmYOUa8ioPd2kXjn0On2k6mmO10Yd6hib95bmcZw%40mail.gmail.com">
|
|
<META NAME="robots" CONTENT="index,nofollow">
|
|
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
|
<LINK REL="Previous" HREF="008142.html">
|
|
<LINK REL="Next" HREF="008149.html">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#ffffff">
|
|
<H1>[mono-android] Gesture listener subclass no longer works with V4</H1>
|
|
<B>John Murray</B>
|
|
<A HREF="mailto:monodroid%40lists.ximian.com?Subject=%5Bmono-android%5D%20Gesture%20listener%20subclass%20no%20longer%20works%20with%20V4&In-Reply-To=CAA2GyZgUQLnmYOUa8ioPd2kXjn0On2k6mmO10Yd6hib95bmcZw%40mail.gmail.com"
|
|
TITLE="[mono-android] Gesture listener subclass no longer works with V4">john at murray.gb.com
|
|
</A><BR>
|
|
<I>Fri Dec 30 10:48:46 EST 2011</I>
|
|
<P><UL>
|
|
<LI>Previous message: <A HREF="008142.html">[mono-android] Gesture listener subclass no longer works with V4
|
|
</A></li>
|
|
<LI>Next message: <A HREF="008149.html">[mono-android] Gesture listener subclass no longer works with V4
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#8148">[ date ]</a>
|
|
<a href="thread.html#8148">[ thread ]</a>
|
|
<a href="subject.html#8148">[ subject ]</a>
|
|
<a href="author.html#8148">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
<HR>
|
|
<!--beginarticle-->
|
|
<PRE>Many thanks
|
|
Did not see Tomasz's post but thanks to both of you
|
|
Works just fine now
|
|
|
|
|
|
|
|
-----Original Message-----
|
|
From: Mike Child [mailto:<A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">mike at mikechild.net</A>]
|
|
Sent: 30 December 2011 12:43
|
|
To: Discussions related to Mono for Android
|
|
Cc: <A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">john at murray.gb.com</A>
|
|
Subject: Re: [mono-android] Gesture listener subclass no longer works with
|
|
V4
|
|
|
|
Like Tomasz said, Inherit from Java.Lang.Object. You should never
|
|
implement the Handle property yourself.
|
|
|
|
Mike Child
|
|
|
|
|
|
|
|
On Fri, Dec 30, 2011 at 7:16 AM, Tomasz Cielecki <<A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">tomasz at ostebaronen.dk</A>>
|
|
wrote:
|
|
><i> Have your class GestureListener inherit Java.Lang.Object, this way you
|
|
</I>><i> don't have to Implement the Handle property. I did this with an
|
|
</I>><i> ISensorEventListener and it works just fine.
|
|
</I>><i>
|
|
</I>><i> On Fri, Dec 30, 2011 at 12:18 PM, John Murray <<A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">john at murray.gb.com</A>> wrote:
|
|
</I>>><i> The following code adapted from some stuff on Stackoverflow has served me
|
|
</I>>><i> well up to now
|
|
</I>>><i>
|
|
</I>>><i> I have made major adaptations to it  but this code is the basic original
|
|
</I>–
|
|
>><i> I’ve stripped everything out and put it in the simple one button one
|
|
</I>>><i> textview MonoDroid sample project but it behaves the same under v4 as my
|
|
</I>>><i> main project viz if falls over with an unhandled exception on lines
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public IntPtr Handle
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             get { throw new NotImplementedException(); }
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i> In the OnCreate when the line
|
|
</I>>><i>
|
|
</I>>><i>             gestureScanner = new GestureDetector(this, gestureListener);
|
|
</I>>><i>
|
|
</I>>><i> then as this instance of gesture detector is called it goes straight to
|
|
</I>the
|
|
>><i> IntPtr  code and hangs
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> Presumably v4 is now enforcing some correct way of doing things and this
|
|
</I>>><i> code is not acceptable – I cannot trace what’s going on – as soon as the
|
|
</I>>><i> onCreate is called it seems to go straight to this line and fall over –
|
|
</I>as I
|
|
>><i> said never happened until v4
|
|
</I>>><i>
|
|
</I>>><i> I know it is probably my code but I couldn’t get it much simpler – I have
|
|
</I>>><i> probably mistranslated from the Java code I found on StackOverFlow and as
|
|
</I>I
|
|
>><i> am boilerplating I don’t really understand deeply what’s going on with
|
|
</I>the
|
|
>><i> Java Handle
|
|
</I>>><i>
|
|
</I>>><i> Any help gratefully received
|
|
</I>>><i>
|
|
</I>>><i> John Murray
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> ///////////////////////////////////////////////////////
|
|
</I>>><i>
|
|
</I>>><i> using System;
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> using Android.App;
|
|
</I>>><i>
|
|
</I>>><i> using Android.Content;
|
|
</I>>><i>
|
|
</I>>><i> using Android.Runtime;
|
|
</I>>><i>
|
|
</I>>><i> using Android.Views;
|
|
</I>>><i>
|
|
</I>>><i> using Android.Widget;
|
|
</I>>><i>
|
|
</I>>><i> using Android.OS;
|
|
</I>>><i>
|
|
</I>>><i> using Android.Gestures;
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> namespace MonodroidC
|
|
</I>>><i>
|
|
</I>>><i> {
|
|
</I>>><i>
|
|
</I>>><i>     [Activity(Label = "MonodroidC", MainLauncher = true, Icon =
|
|
</I>>><i> "@drawable/icon")]
|
|
</I>>><i>
|
|
</I>>><i>     public class Activity1 : Activity
|
|
</I>>><i>
|
|
</I>>><i>     {
|
|
</I>>><i>
|
|
</I>>><i>         private TextView displayText;
|
|
</I>>><i>
|
|
</I>>><i>         private GestureDetector gestureScanner;
|
|
</I>>><i>
|
|
</I>>><i>         private GestureListener gestureListener;
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         protected override void OnCreate(Bundle bundle)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             base.OnCreate(bundle);
|
|
</I>>><i>
|
|
</I>>><i>             SetContentView(Resource.Layout.Main);
|
|
</I>>><i>
|
|
</I>>><i>             displayText = FindViewById<TextView>(Resource.Id.t11);
|
|
</I>>><i>
|
|
</I>>><i>             gestureListener = new GestureListener(displayText);
|
|
</I>>><i>
|
|
</I>>><i>             gestureScanner = new GestureDetector(this, gestureListener);
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public override bool OnTouchEvent(MotionEvent e)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             return gestureScanner.OnTouchEvent(e);
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>     }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>     public class GestureListener : GestureDetector.IOnGestureListener
|
|
</I>>><i>
|
|
</I>>><i>     {
|
|
</I>>><i>
|
|
</I>>><i>         private readonly TextView view;
|
|
</I>>><i>
|
|
</I>>><i>         private static int SWIPE_MAX_OFF_PATH = 250;
|
|
</I>>><i>
|
|
</I>>><i>         private static int SWIPE_MIN_DISTANCE = 120;
|
|
</I>>><i>
|
|
</I>>><i>         private static int SWIPE_THRESHOLD_VELOCITY = 200;
|
|
</I>>><i>
|
|
</I>>><i>         public GestureListener(TextView view)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             this.view = view;
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public IntPtr Handle
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             get { throw new NotImplementedException(); }
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public bool OnDown(MotionEvent e)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             view.Text = "- DOWN -";
|
|
</I>>><i>
|
|
</I>>><i>             return true;
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public bool OnFling(MotionEvent e1, MotionEvent e2, float
|
|
</I>velocityX,
|
|
>><i> float velocityY)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             try
|
|
</I>>><i>
|
|
</I>>><i>             {
|
|
</I>>><i>
|
|
</I>>><i>                 if (Math.Abs(e1.GetY() - e2.GetY()) > SWIPE_MAX_OFF_PATH)
|
|
</I>>><i>
|
|
</I>>><i>                     return false;
|
|
</I>>><i>
|
|
</I>>><i>                 // right to left swipe
|
|
</I>>><i>
|
|
</I>>><i>                 if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE &&
|
|
</I>>><i> Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
|
|
</I>>><i>
|
|
</I>>><i>                     Toast.MakeText(view.Context, "Left Swipe",
|
|
</I>>><i> ToastLength.Short).Show();
|
|
</I>>><i>
|
|
</I>>><i>                 else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE &&
|
|
</I>>><i> Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
|
|
</I>>><i>
|
|
</I>>><i>                     Toast.MakeText(view.Context, "Right Swipe",
|
|
</I>>><i> ToastLength.Short).Show();
|
|
</I>>><i>
|
|
</I>>><i>             }
|
|
</I>>><i>
|
|
</I>>><i>             catch (Exception e)
|
|
</I>>><i>
|
|
</I>>><i>             {
|
|
</I>>><i>
|
|
</I>>><i>                 // nothing
|
|
</I>>><i>
|
|
</I>>><i>             }
|
|
</I>>><i>
|
|
</I>>><i>             return false;
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public void OnLongPress(MotionEvent e)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             view.Text = "- LONG PRESS -";
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public bool OnScroll(MotionEvent e1, MotionEvent e2, float
|
|
</I>>><i> distanceX, float distanceY)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             view.Text = "- FLING -";
|
|
</I>>><i>
|
|
</I>>><i>             return true;
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public void OnShowPress(MotionEvent e)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             view.Text = "- SHOW PRESS -";
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>         public bool OnSingleTapUp(MotionEvent e)
|
|
</I>>><i>
|
|
</I>>><i>         {
|
|
</I>>><i>
|
|
</I>>><i>             view.Text = "- SINGLE TAP UP -";
|
|
</I>>><i>
|
|
</I>>><i>             return true;
|
|
</I>>><i>
|
|
</I>>><i>         }
|
|
</I>>><i>
|
|
</I>>><i>     }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> }
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> _______________________________________________
|
|
</I>>><i> Monodroid mailing list
|
|
</I>>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">Monodroid at lists.ximian.com</A>
|
|
</I>>><i>
|
|
</I>>><i> UNSUBSCRIBE INFORMATION:
|
|
</I>>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">http://lists.ximian.com/mailman/listinfo/monodroid</A>
|
|
</I>>><i>
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> --
|
|
</I>><i> Med Venlig Hilsen / With Best Regards
|
|
</I>><i> Tomasz Cielecki
|
|
</I>><i> <A HREF="http://ostebaronen.dk">http://ostebaronen.dk</A>
|
|
</I>><i> _______________________________________________
|
|
</I>><i> Monodroid mailing list
|
|
</I>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">Monodroid at lists.ximian.com</A>
|
|
</I>><i>
|
|
</I>><i> UNSUBSCRIBE INFORMATION:
|
|
</I>><i> <A HREF="http://lists.ximian.com/mailman/listinfo/monodroid">http://lists.ximian.com/mailman/listinfo/monodroid</A>
|
|
</I>
|
|
</PRE>
|
|
|
|
|
|
|
|
|
|
|
|
<!--endarticle-->
|
|
<HR>
|
|
<P><UL>
|
|
<!--threads-->
|
|
<LI>Previous message: <A HREF="008142.html">[mono-android] Gesture listener subclass no longer works with V4
|
|
</A></li>
|
|
<LI>Next message: <A HREF="008149.html">[mono-android] Gesture listener subclass no longer works with V4
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#8148">[ date ]</a>
|
|
<a href="thread.html#8148">[ thread ]</a>
|
|
<a href="subject.html#8148">[ subject ]</a>
|
|
<a href="author.html#8148">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
|
|
<hr>
|
|
<a href="http://lists.ximian.com/mailman/listinfo/monodroid">More information about the Monodroid
|
|
mailing list</a><br>
|
|
</body></html>
|