本文整理汇总了C#中Android.Views.MotionEvent.GetX方法的典型用法代码示例。如果您正苦于以下问题:C# MotionEvent.GetX方法的具体用法?C# MotionEvent.GetX怎么用?C# MotionEvent.GetX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Views.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.GetX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTouch
// Check touch position on button
public bool OnTouch(View v, MotionEvent e)
{
switch (e.Action)
{
// Get the x and y position for a touch (always before move)
case MotionEventActions.Down:
old_x = e.GetX ();
old_y = e.GetY ();
Console.WriteLine ("x = " + old_x + " y = " + old_y);
break;
// Get the x and y position difference continously
case MotionEventActions.Move:
// Get the difference between current position and old position
new_x = e.GetX () - old_x;
new_y = e.GetY () - old_y;
// Convert to int, to remove decimal numbers (apparently can't be send through the tcp listener)
int_x = Convert.ToInt32 (new_x);
int_y = Convert.ToInt32 (new_y);
// Convert to string, so it can be send
send_x = Convert.ToString (int_x);
send_y = Convert.ToString (int_y);
// Send x and y position over two messages
Connect (ipAddress, send_x);
Connect (ipAddress, send_y);
// Set old position to current position
old_x = e.GetX ();
old_y = e.GetY ();
break;
}
return true;
}
示例2: OnFling
public bool OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
// Right to left swipe
if (e1.GetX() - e2.GetX() > MinSwipeDistance
&& Math.Abs(velocityX) > SwipeThreadsholdVelocity) {
if (_page.CaptureSwipeRightToLeft)
_page.OnSwipeRightToLeft ();
}
// Left to right swipe
else if (e2.GetX() - e1.GetX() > MinSwipeDistance
&& Math.Abs(velocityX) > SwipeThreadsholdVelocity) {
if (_page.CaptureSwipeLeftToRight)
_page.OnSwipeLeftToRight ();
}
if (e1.GetY() - e2.GetY() > MinSwipeDistance
&& Math.Abs(velocityY) > SwipeThreadsholdVelocity) {
if (_page.CaptureSwipeBottomToTop)
_page.OnSwipeBottomToTop ();
}
// Left to right swipe
else if (e2.GetY() - e1.GetY() > MinSwipeDistance
&& Math.Abs(velocityY) > SwipeThreadsholdVelocity) {
if (_page.CaptureSwipeTopToBottom)
_page.OnSwipeTopToBottom ();
}
return true;
}
示例3: OnTouchEvent
public override bool OnTouchEvent (MotionEvent e)
{
if (e.Action == MotionEventActions.Move) {
if (oldX == 0) {
oldX = (int)e.GetX ();
}
if (oldY == 0) {
oldY = (int)e.GetY ();
}
newX = (int)e.GetX ();
newY = (int)e.GetY ();
if (newY > oldY + buffer) {
CurrentDirection = DirectionUp;
} else if (newY + buffer < oldY) {
CurrentDirection = DirectionDown;
} else {
CurrentDirection = DirectionNone;
}
if (newY > oldY + buffer) {
oldY = (int)e.GetY ();
}
if (newY + buffer < oldY) {
oldY = (int)e.GetY ();
}
oldX = (int)e.GetX ();
} else if (e.Action == MotionEventActions.Up) {
oldX = 0;
oldY = 0;
}
return base.OnTouchEvent (e);
}
示例4: CalculateRotation
private static float CalculateRotation(MotionEvent motionEvent)
{
double deltaX = (motionEvent.GetX(0) - motionEvent.GetX(1));
double deltaY = (motionEvent.GetY(0) - motionEvent.GetY(1));
var radians = Math.Atan2(deltaY, deltaX);
return (float) ToDegrees(radians);
}
示例5: UpdateStateByEvent
protected internal override void UpdateStateByEvent(MotionEvent curr)
{
base.UpdateStateByEvent(curr);
MotionEvent prev = mPrevEvent;
mCurrLen = -1;
mPrevLen = -1;
// Previous
float px0 = prev.GetX(0);
float py0 = prev.GetY(0);
float px1 = prev.GetX(1);
float py1 = prev.GetY(1);
float pvx = px1 - px0;
float pvy = py1 - py0;
mPrevFingerDiffX = pvx;
mPrevFingerDiffY = pvy;
// Current
float cx0 = curr.GetX(0);
float cy0 = curr.GetY(0);
float cx1 = curr.GetX(1);
float cy1 = curr.GetY(1);
float cvx = cx1 - cx0;
float cvy = cy1 - cy0;
mCurrFingerDiffX = cvx;
mCurrFingerDiffY = cvy;
}
示例6: OnFling
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
try
{
if ( Math.Abs ( e1.GetY () - e2.GetY () ) > SWIPE_MAX_OFF_PATH )
return false;
// right to left swipe
if ( e1.GetX () - e2.GetX () > SWIPE_MIN_DISTANCE && Math.Abs ( velocityX ) > SWIPE_THRESHOLD_VELOCITY && LeftEvent != null )
{
RightEvent ();
}
else if ( e2.GetX () - e1.GetX () > SWIPE_MIN_DISTANCE && Math.Abs ( velocityX ) > SWIPE_THRESHOLD_VELOCITY && RightEvent != null )
{
if(e1.GetX()<100)
{
Console.WriteLine("e1.GetX() : "+ e1.GetX());
Console.WriteLine("e2.GetX() : "+ e2.GetX());
LeftEvent ();
}
}
}
catch ( Exception e )
{
Console.WriteLine ( "Gesture listener didn't worked properly..." +e.Message);
}
return false;
}
示例7: Detect
public bool Detect(MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
this.startX = e.GetX();
this.startY = e.GetY();
this.tapPossiable = true;
break;
case MotionEventActions.Move:
if (this.tapPossiable)
{
if (Math.Abs(e.GetX() - this.startX) > this.slop || Math.Abs(e.GetY() - this.startY) > this.slop)
{
this.tapPossiable = false;
}
}
break;
case MotionEventActions.Up:
if (this.tapPossiable && e.EventTime - e.DownTime < tapTimeout)
{
((ITapableView)this.owner).WrapedNativeRaiseTap();
}
break;
}
return false;
}
示例8: OnFling
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
// Swipe left
if (e1.GetX() > e2.GetX())
{
Console.WriteLine("Left");
_id++;
if (_id == _point.Count)
{
_id = 0;
}
}
// Swipe right
else if (e2.GetX() > e1.GetX())
{
Console.WriteLine("Right");
_id--;
if (_id < 0)
{
_id = _point.Count - 1;
}
}
_webview.LoadUrl("file://" + ThisApp.GetEPUBPage(ThisApp.Language, "w_E_20130315", _point[_id].Source).Path);
return base.OnFling(e1, e2, velocityX, velocityY);
}
示例9: UpdateStateByEvent
/// <summary>
/// Updates the current state with the given event.
/// </summary>
/// <param name="curr">The current event.</param>
protected override void UpdateStateByEvent (MotionEvent curr)
{
base.UpdateStateByEvent (curr);
MotionEvent prev = _previousEvent;
_currLen = -1;
_prevLen = -1;
if (prev != null && prev.PointerCount > 1 &&
curr.PointerCount > 1) {
// previous
float px0 = prev.GetX (0);
float py0 = prev.GetY (0);
float px1 = prev.GetX (1);
float py1 = prev.GetY (1);
float pvx = px1 - px0;
float pvy = py1 - py0;
_prevFingerDiffX = pvx;
_prevFingerDiffY = pvy;
// current
float cx0 = curr.GetX (0);
float cy0 = curr.GetY (0);
float cx1 = curr.GetX (1);
float cy1 = curr.GetY (1);
float cvx = cx1 - cx0;
float cvy = cy1 - cy0;
_currFingerDiffX = cvx;
_currFingerDiffY = cvy;
}
}
示例10: GetActiveX
public override float GetActiveX(MotionEvent ev)
{
try {
return ev.GetX(mActivePointerIndex);
} catch (Exception e) {
return ev.GetX();
}
}
示例11: GetRotation
private static float GetRotation(MotionEvent e)
{
var deltaX = e.GetX(0) - e.GetX(1);
var deltaY = e.GetY(0) - e.GetY(1);
var radians = (float)Math.Atan2(deltaY, deltaX);
return MathHelper.RadiansToDegrees(radians);
}
示例12: OnDown
public bool OnDown(MotionEvent e)
{
State = GestureRecognizerState.Began;
_currentTranslation = new Xamarin.Forms.Point (e.GetX (), e.GetY ());
_currentPoint = new Xamarin.Forms.Point (e.GetX (), e.GetY ());
_previousPoint = new Xamarin.Forms.Point (e.GetX (), e.GetY ());
OnGesture ();
return true;
}
示例13: OnTouchEvent
public override bool OnTouchEvent (MotionEvent ev)
{
_scaleDetector.OnTouchEvent (ev);
MotionEventActions action = ev.Action & MotionEventActions.Mask;
int pointerIndex;
switch (action) {
case MotionEventActions.Down:
_lastTouchX = ev.GetX ();
_lastTouchY = ev.GetY ();
_activePointerId = ev.GetPointerId (0);
break;
case MotionEventActions.Move:
pointerIndex = ev.FindPointerIndex (_activePointerId);
float x = ev.GetX (pointerIndex);
float y = ev.GetY (pointerIndex);
if (!_scaleDetector.IsInProgress) {
// Only move the ScaleGestureDetector isn't already processing a gesture.
float deltaX = x - _lastTouchX;
float deltaY = y - _lastTouchY;
_posX += deltaX;
_posY += deltaY;
Invalidate ();
}
_lastTouchX = x;
_lastTouchY = y;
break;
case MotionEventActions.Up:
case MotionEventActions.Cancel:
// This events occur when something cancels the gesture (for example the
// activity going in the background) or when the pointer has been lifted up.
// We no longer need to keep track of the active pointer.
_activePointerId = InvalidPointerId;
break;
case MotionEventActions.PointerUp:
// We only want to update the last touch position if the the appropriate pointer
// has been lifted off the screen.
pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
int pointerId = ev.GetPointerId (pointerIndex);
if (pointerId == _activePointerId) {
// This was our active pointer going up. Choose a new
// action pointer and adjust accordingly
int newPointerIndex = pointerIndex == 0 ? 1 : 0;
_lastTouchX = ev.GetX (newPointerIndex);
_lastTouchY = ev.GetY (newPointerIndex);
_activePointerId = ev.GetPointerId (newPointerIndex);
}
break;
}
return true;
}
示例14: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
switch (e.Action) {
case MotionEventActions.Down:
lastX = e.GetX ();
lastY = e.GetY ();
break;
case MotionEventActions.Up:
var diffX = Math.Abs (e.GetX () - lastX);
var diffY = Math.Abs (e.GetY () - lastY);
if (diffX > diffY) {
if (diffX > 100) {
if (ScaleX == 1.0f) {
this.Animate ().ScaleX (0.0f).WithEndAction (new Java.Lang.Runnable (() => {
textView.Text = cards.Card[counter].Foreign[0].ItemElement.Text;
this.Animate ().ScaleX (0.999f);
}));
} else
this.Animate ().ScaleX (0.0f).WithEndAction (new Java.Lang.Runnable (() => {
textView.Text = cards.Card[counter].Native[0].ItemElement.Text;
this.Animate ().ScaleX (1.00f);
}));
}
} else {
this.Animate ().ScaleX (0f);
this.Animate ().ScaleY (0f);
this.Animate ().Alpha (0f).WithEndAction (new Java.Lang.Runnable (() => {
counter++;
if (counter < cards.Card.Count) {
levelView.Level = cards.Card [counter].Level;
textView.Text = cards.Card[counter].Native[0].ItemElement.Text;
this.TranslationY = 0.0f;
this.ScaleX = 0.0f;
this.ScaleY = 0.0f;
this.Alpha = 1.0f;
this.Animate ().ScaleX (1.0f);
this.Animate ().ScaleY (1.0f);
}
}));
if (e.GetY () - lastY > 0) {
cards.Card [counter].Level++;
this.Animate ().TranslationYBy (1000f);
} else {
cards.Card [counter].Level = 0;
this.Animate ().TranslationYBy (-1000f);
}
}
break;
default:
break;
}
return true;// base.OnTouchEvent (e);
}
示例15: DispatchTouchEvent
/**
* When the user swipes their finger horizontally, dispatch
* those touch events to the ViewPager. When they swipe
* vertically, dispatch those touch events to the date or
* time picker (depending on which page we're currently on).
*
* @param event
*/
public override bool DispatchTouchEvent (MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
_x1 = e.GetX();
_y1 = e.GetY();
break;
case MotionEventActions.Move:
_x2 = e.GetX();
_y2 = e.GetY();
if (isScrollingHorizontal(_x1, _y1, _x2, _y2))
{
// When the user is scrolling the ViewPager horizontally,
// block the pickers from scrolling vertically.
return base.DispatchTouchEvent(e);
}
break;
}
// As long as the ViewPager isn't scrolling horizontally,
// dispatch the event to the DatePicker or TimePicker,
// depending on which page the ViewPager is currently on.
switch (CurrentItem)
{
case 0:
if (_datePicker != null)
_datePicker.DispatchTouchEvent(e);
break;
case 1:
if (_timePicker != null)
_timePicker.DispatchTouchEvent(e);
break;
}
// need this for the ViewPager to scroll horizontally at all
return base.DispatchTouchEvent (e);
}