Hi fellow developers,
I'm trying to convert an android java example code snippet to a C# code
snippet.
The java snippet uses Enums like: MotionEvent.ACTION_MASK and
MotionEvent.ACTION_DOWN.
Mono uses the default class android.Views.MotionEvent, which does not
contain these field constants.
So, how and I fix the code snippet below:
public override bool OnTouchEvent(MotionEvent eve)
{
base.OnTouchEvent(eve);
int action = eve.Action & MotionEvent.ACTION_MASK;
switch (action)
{
case MotionEvent.ACTION_DOWN:
{
System.Diagnostics.Debug.WriteLine("MultitouchExample: Action Down");
mTouchStart = DateTime.Now.Millisecond;
}
case MotionEvent.ACTION_MOVE:
{
System.Diagnostics.Debug.WriteLine("MultitouchExample: Action Move");
break;
}
...
...
I defined a generic image GestureListener of the form:
public class MyImageListener
{
MultiTouchGestureListener m_oMultiTouchGestureListener;
SingleTouchGestureListener m_oSingleTouchGestureListener;
ScaleGestureDetector m_gestures;
GestureDetector m_singleTouchGestures;
ImageView image;
Context context;
public MyImageListener(Context context, ImageView image)
{
this.context = context;
this.image = image;
// create gesture detector to capture single touch gestures
m_oSingleTouchGestureListener = new
SingleTouchGestureListener(image);
m_singleTouchGestures = new GestureDetector(context,
m_oSingleTouchGestureListener);
// Create scale gesture detector to capture multi-touch gestures
m_oMultiTouchGestureListener = new
MultiTouchGestureListener(image);
m_gestures = new ScaleGestureDetector(context,
m_oMultiTouchGestureListener);
}
public override bool OnTouchEvent(MotionEvent eve)
{
bool bAccepted = false;
bAccepted = m_singleTouchGestures.OnTouchEvent(eve); // single
touch gestures
if (bAccepted) return bAccepted;
m_oMultiTouchGestureListener.setMotionEvent(eve);
bAccepted = m_gestures.OnTouchEvent(eve); // multi-touch or
scale events
return bAccepted;
}
Thanks,
King Coffee
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/How-to-use-MotionEvent-members-tp5630688p5630688.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid