本文整理汇总了C#中Android.Views.MotionEvent.GetPointerId方法的典型用法代码示例。如果您正苦于以下问题:C# MotionEvent.GetPointerId方法的具体用法?C# MotionEvent.GetPointerId怎么用?C# MotionEvent.GetPointerId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Views.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.GetPointerId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTouchEvent
public override bool OnTouchEvent(MotionEvent ev)
{
MotionEventActions action = ev.Action;
switch (action & MotionEventActions.Mask) {
case MotionEventActions.Down:
mActivePointerId = ev.GetPointerId(0);
break;
case MotionEventActions.Cancel:
case MotionEventActions.Up:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEventActions.PointerUp:
// Ignore deprecation, ACTION_POINTER_ID_MASK and
// ACTION_POINTER_ID_SHIFT has same value and are deprecated
// You can have either deprecation or lint target api warning
int pointerIndex = Compat.GetPointerIndex(ev.Action);
int pointerId = ev.GetPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.GetPointerId(newPointerIndex);
mLastTouchX = ev.GetX(newPointerIndex);
mLastTouchY = ev.GetY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev
.FindPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
: 0);
return base.OnTouchEvent(ev);
}
示例2: 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;
}
示例3: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
var index = e.ActionIndex;
var action = (MotionEventActions)e.ActionMasked;
var pointerId = e.GetPointerId(index);
switch (action) {
case MotionEventActions.Down:
if (this._velocityTracket == null) {
this._velocityTracket = VelocityTracker.Obtain();
}
else {
this._velocityTracket.Clear();
}
this._velocityTracket.AddMovement(e);
break;
case MotionEventActions.Move:
this._velocityTracket.AddMovement(e);
this._velocityTracket.ComputeCurrentVelocity(1000);
Log.Debug(DebugTag, "X velocity: " + VelocityTrackerCompat.GetXVelocity(this._velocityTracket, pointerId));
Log.Debug(DebugTag, "Y velocity: " + VelocityTrackerCompat.GetYVelocity(this._velocityTracket, pointerId));
break;
case MotionEventActions.Cancel:
case MotionEventActions.Up:
this._velocityTracket.Recycle();
break;
default:
break;
}
return true;
}
示例4: HandleDragEvent
public void HandleDragEvent(MotionEvent ev)
{
MotionEventActions action = ev.Action & MotionEventActions.Mask;
int pointerIndex;
switch (action) {
case MotionEventActions.Down:
_lastTouchX = ev.RawX;
_lastTouchY = ev.RawY;
_activePointerId = ev.GetPointerId (0);
_posX = _posX == 0 ? Shape.Center_X - Shape.Radius : _posX;
_posY = _posY == 0 ? Shape.Center_Y - Shape.Radius : _posX;
break;
case MotionEventActions.Move:
pointerIndex = ev.FindPointerIndex (_activePointerId);
float x = ev.RawX;
float y = ev.RawY;
float deltaX = x - _lastTouchX;
float deltaY = y - _lastTouchY;
_posX += deltaX;
_posY += deltaY;
if (RequestLayout != null)
RequestLayout ((int)_posX, (int)_posY, (int)_posX + Shape.Radius * 2, (int)_posY + Shape.Radius * 2);
_lastTouchX = x;
_lastTouchY = y;
break;
case MotionEventActions.Up:
_lastTouchX = ev.RawX;
_lastTouchY = ev.RawY;
Shape.Center_X = (int)_posX + Shape.Radius;
Shape.Center_Y = (int)_posY + Shape.Radius;
_posX = 0;
_posY = 0;
break;
case MotionEventActions.Cancel:
// We no longer need to keep track of the active pointer.
_activePointerId = -1;
break;
case MotionEventActions.PointerUp:
// check to make sure that the pointer that went up is for the gesture we're tracking.
pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
int pointerId = ev.GetPointerId (pointerIndex);
if (pointerId == _activePointerId) {
_lastTouchX = ev.RawX;
_lastTouchY = ev.RawY;
Shape.Center_X = (int)_posX + Shape.Radius;
Shape.Center_Y = (int)_posY + Shape.Radius;
}
break;
}
}
示例5: OnTouchEvent
public void OnTouchEvent(MotionEvent e)
{
if (!Enabled)
return;
Vector2 position = Vector2.Zero;
position.X = e.GetX(e.ActionIndex);
position.Y = e.GetY(e.ActionIndex);
UpdateTouchPosition(ref position);
int id = e.GetPointerId(e.ActionIndex);
switch (e.ActionMasked)
{
// DOWN
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
TouchPanel.AddEvent(id, TouchLocationState.Pressed, position);
break;
// UP
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
TouchPanel.AddEvent(id, TouchLocationState.Released, position);
break;
// MOVE
case MotionEventActions.Move:
for (int i = 0; i < e.PointerCount; i++)
{
id = e.GetPointerId(i);
position.X = e.GetX(i);
position.Y = e.GetY(i);
UpdateTouchPosition(ref position);
TouchPanel.AddEvent(id, TouchLocationState.Moved, position);
}
break;
// CANCEL, OUTSIDE
case MotionEventActions.Cancel:
case MotionEventActions.Outside:
for (int i = 0; i < e.PointerCount; i++)
{
id = e.GetPointerId(i);
TouchPanel.AddEvent(id, TouchLocationState.Released, position);
}
break;
}
}
示例6: 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:
// We no longer need to keep track of the active pointer.
_activePointerId = InvalidPointerId;
break;
case MotionEventActions.PointerUp:
// check to make sure that the pointer that went up is for the gesture we're tracking.
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;
}
示例7: OnTouch
private bool OnTouch(MotionEvent e)
{
PointerState state;
switch (e.ActionMasked)
{
case MotionEventActions.Cancel:
state = PointerState.Cancel;
break;
case MotionEventActions.Move:
state = PointerState.Move;
break;
case MotionEventActions.Outside:
state = PointerState.Out;
break;
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
state = PointerState.Down;
break;
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
state = PointerState.Up;
break;
default:
// Not handled
return false;
}
var startIndex = 0;
var endIndex = e.PointerCount;
if (state == PointerState.Down || state == PointerState.Up || state == PointerState.Out)
{
startIndex = e.ActionIndex;
endIndex = startIndex + 1;
}
for (var i = startIndex; i < endIndex; ++i)
{
var pointerId = e.GetPointerId(i);
var pixelPosition = new Vector2(e.GetX(i), e.GetY(i));
if(MultiTouchEnabled || pointerId == 0) // manually drop multi-touch events when disabled
HandlePointerEvents(pointerId, NormalizeScreenPosition(pixelPosition), state);
}
return true;
}
示例8: OnGenericMotionEvent
public override bool OnGenericMotionEvent(MotionEvent e)
{
for (var i = 0; i < e.PointerCount; i++)
{
var pointerId = e.GetPointerId(i);
var x = e.GetX(i);
var y = e.GetY(i);
switch (e.ActionMasked)
{
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
case MotionEventActions.Move:
moveFingerTrace(pointerId, x, y);
break;
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
case MotionEventActions.Cancel:
hideFingerTrace(pointerId);
break;
}
}
return false;
}
示例9: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
MotionEvent.PointerCoords mepc = new MotionEvent.PointerCoords();
int iEventPointerIndex = (int)(e.Action & MotionEventActions.PointerIdMask) >> (int)MotionEventActions.PointerIdShift;
int iEventPointerId = e.GetPointerId(iEventPointerIndex);
MotionEventActions action = e.Action & MotionEventActions.Mask;
switch (action)
{
case MotionEventActions.Down:
case MotionEventActions.PointerDown:
Log.Debug(tag, String.Format("Point Down"));
//DataClass.Drawables[iEventPointerId].Visible = true;
e.GetPointerCoords(iEventPointerIndex, mepc);
bool bFound = false;
foreach (var item in DataClass.Sources)
{
if (item.Collision(mepc.X, mepc.Y))
{
var nc = new Circle(item) { Visible = true };
DataClass.Drawables.Add(nc);
dctControlable.Add(iEventPointerId, nc);
bFound = true;
break;
}
}
if (bFound) break;
foreach (var item in DataClass.Drawables)
{
if (item.Collision(mepc.X, mepc.Y))
{
dctControlable.Add(iEventPointerId, item);
break;
}
}
break;
case MotionEventActions.Move:
var l = new List<string>();
for (int iPointerIndex = 0; iPointerIndex < e.PointerCount; iPointerIndex++)
{
int iPointerId = e.GetPointerId(iPointerIndex);
l.Add(String.Format("{0} => {1}", iPointerIndex, iPointerId));
try
{
e.GetPointerCoords(iPointerIndex, mepc);
dctControlable[iPointerId].X = mepc.X;
dctControlable[iPointerId].Y = mepc.Y;
}
catch
{
l.Add(String.Format("ex", iPointerIndex, iPointerId));
}
}
Log.Debug(tag, string.Format("{0}, {1}", iEventPointerIndex, string.Join(", ", l)));
break;
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
Log.Debug(tag, String.Format("Point Up"));
//DataClass.Drawables[iEventPointerId].Visible = false;
dctControlable.Remove(iEventPointerId);
break;
}
this.Invalidate();
return true;
}
示例10: OnTouchEvent
public override bool OnTouchEvent(MotionEvent ev)
{
base.OnTouchEvent(ev);
this.InitVelocityTrackerIfNotExists();
this.velocityTracker.AddMovement(ev);
switch (ev.Action & MotionEventActions.Mask)
{
case MotionEventActions.Down:
{
if (this.childWhoScrolling != null)
{
this.childWhoScrolling.OnTouchEvent(ev);
return false;
}
if (this.ChildCount == 0)
{
return false;
}
this.isBeingDragged = !this.scroller.IsFinishedY;
if (this.isBeingDragged)
{
if (this.Parent != null)
{
this.Parent.RequestDisallowInterceptTouchEvent(true);
}
}
// Stop, if touched during movement on inertia
if (!this.scroller.IsFinishedY)
{
this.scroller.AbortAnimation();
////FlingStrictSpan
}
this.lastMotionX = (int)ev.GetX();
this.lastMotionY = (int)ev.GetY();
this.activePointerId = ev.GetPointerId(0);
break;
}
case MotionEventActions.Move:
{
if (this.childWhoScrolling != null)
{
this.childWhoScrolling.OnTouchEvent(ev);
return false;
}
//int activePointerIndex = ev.FindPointerIndex(this.activePointerId);
//if (activePointerIndex == -1)
//{
// break;
//}
int x = (int)ev.GetX();
int y = (int)ev.GetY();
int deltaX = this.lastMotionX - x;
int deltaY = this.lastMotionY - y;
if (!this.isBeingDragged && (Math.Abs(deltaX) > this.touchSlop || Math.Abs(deltaY) > this.touchSlop))
{
if (this.Parent != null)
{
this.Parent.RequestDisallowInterceptTouchEvent(true);
}
this.isBeingDragged = true;
}
if (this.isBeingDragged)
{
// scroll after touch motions
this.lastMotionX = x;
this.lastMotionY = y;
int oldX = this.ScrollX;
int oldY = this.ScrollY;
int rangeX = this.GetScrollRangeX();
int rangeY = this.GetScrollRangeY();
// OverScroll is ignored for now
// bool canOverscrollX = this.OverScrollMode == Android.Views.OverScrollMode.Always ||
// (this.OverScrollMode == Android.Views.OverScrollMode.IfContentScrolls && rangeX > 0);
// bool canOverscrollY = this.OverScrollMode == Android.Views.OverScrollMode.Always ||
// (this.OverScrollMode == Android.Views.OverScrollMode.IfContentScrolls && rangeY > 0);
if (this.OverScrollBy(deltaX, deltaY, this.ScrollX, this.ScrollY, rangeX, rangeY, this.overflingDistance, this.overflingDistance, true))
{
////this.velocityTracker.Clear();
}
//this.OnScrollChanged(this.ScrollX, this.ScrollY, oldX, oldY);
}
break;
}
case MotionEventActions.Up:
if (this.childWhoScrolling != null)
//.........这里部分代码省略.........
示例11: OnInterceptTouchEvent
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
int currenrMotionX;
int currentMotionY;
if (ev.Action == MotionEventActions.Move && this.isBeingDragged)
{
return true;
}
if (this.ScrollX == 0 && !this.CanScrollVertically(1) &&
this.ScrollY == 0 && !this.CanScrollHorizontally(1))
{
return false;
}
switch (ev.Action & MotionEventActions.Mask)
{
case MotionEventActions.Move:
{
this.FindViewWhoScrolling((int)ev.GetX(), (int)ev.GetY(), 1, 1);
if (this.childWhoScrolling != null)
{
return false;
}
if (this.activePointerId == InvalidPointerId)
{
break;
}
int pointerIndex = ev.FindPointerIndex(this.activePointerId);
if (pointerIndex == -1)
{
break;
}
currenrMotionX = (int)ev.GetX(pointerIndex);
currentMotionY = (int)ev.GetY(pointerIndex);
int xDiff = Math.Abs(currenrMotionX - this.lastMotionX);
int yDiff = Math.Abs(currentMotionY - this.lastMotionY);
if (xDiff > this.touchSlop || yDiff > this.touchSlop)
{
this.isBeingDragged = true;
this.lastMotionX = currenrMotionX;
this.lastMotionY = currentMotionY;
this.InitVelocityTrackerIfNotExists();
this.velocityTracker.AddMovement(ev);
if (this.Parent != null)
{
this.Parent.RequestDisallowInterceptTouchEvent(true);
}
}
break;
}
case MotionEventActions.Down:
{
this.FindViewWhoScrolling((int)ev.GetX(), (int)ev.GetY(), 1, 1);
if (this.childWhoScrolling != null)
{
return false;
}
// Stop, if touched during movement on inertia
if (!this.scroller.IsFinishedY)
{
this.scroller.AbortAnimation();
////FlingStrictSpan
}
currenrMotionX = (int)ev.GetX();
currentMotionY = (int)ev.GetY();
this.lastMotionX = currenrMotionX;
this.lastMotionY = currentMotionY;
this.activePointerId = ev.GetPointerId(0);
////if (this.inChild(x, y))
{
this.isBeingDragged = false;
this.RecycleVelocityTracker();
////break;
}
this.InitOrResetVelocityTracker();
this.velocityTracker.AddMovement(ev);
////this.isBeingDragged = this.scroller.IsFinished;
break;
}
case MotionEventActions.Cancel:
case MotionEventActions.Up:
if (this.childWhoScrolling != null)
{
this.childWhoScrolling = null;
return false;
}
//.........这里部分代码省略.........
示例12: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
// Get current position of pointer at index 0.
// This will be the first pointer down and the last pointer up even if not the same
System.Drawing.PointF curr = new System.Drawing.PointF(e.GetX(), e.GetY());
switch (e.Action) {
case MotionEventActions.PointerDown:
pointer2Index = 1;
break;
case MotionEventActions.Down:
// Set the current box and add it to the List<Box> mBoxes
if (mCurrentBox == null) {
mCurrentBox = new Box(curr, e.GetPointerId(0));
mBoxes.Add(mCurrentBox);
}
break;
case MotionEventActions.Pointer2Down:
// Handle 2nd touch. Set the start point of the rotation
if (mRotationStart == null) {
// Get coordinates of pointer 2
MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
e.GetPointerCoords(1, pCoords);
// Set the starting coordinates for the rotation
mRotationStart = new Box(new System.Drawing.PointF(pCoords.X, pCoords.Y), e.GetPointerId(1));
mInitialRotation = mCurrentBox.Rotation;
pointer2Index = 1;
}
break;
case MotionEventActions.Move:
// Handle first pointer move, set end point for rectangle
if (mCurrentBox != null && mCurrentBox.PointerId == e.GetPointerId(0)) {
mCurrentBox.Current = curr;
}
// Handle second pointer move, set rotation amount
if (mRotationStart != null && mRotationStart.PointerId == e.GetPointerId(pointer2Index)) {
// Get coordinates of pointer 2
MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
e.GetPointerCoords(pointer2Index, pCoords);
// Set the rotation of the box to the difference between the origin of mRotation and the current position of pointer 2
mCurrentBox.Rotation = mInitialRotation + pCoords.Y - mRotationStart.Origin.Y;
}
Invalidate();
break;
case MotionEventActions.Pointer2Up:
mRotationStart = null;
break;
case MotionEventActions.PointerUp:
pointer2Index = 0;
break;
case MotionEventActions.Up:
mCurrentBox = null;
mRotationStart = null;
break;
case MotionEventActions.Cancel:
mCurrentBox = null;
mRotationStart = null;
break;
}
return true;
}
示例13: OnTouch
public bool OnTouch(View v, MotionEvent e)
{
TouchLocation tlocation;
TouchCollection collection = TouchPanel.Collection;
Vector2 position = Vector2.Zero;
position.X = e.GetX(e.ActionIndex);
position.Y = e.GetY(e.ActionIndex);
int id = e.GetPointerId(e.ActionIndex);
int index;
switch (e.ActionMasked)
{
// DOWN
case 0:
case 5:
tlocation = new TouchLocation(id, TouchLocationState.Pressed, position);
collection.Add(tlocation);
break;
// UP
case 1:
case 6:
index = collection.FindById(e.GetPointerId(e.ActionIndex), out tlocation);
if (index >= 0)
{
tlocation.State = TouchLocationState.Released;
collection[index] = tlocation;
}
break;
// MOVE
case 2:
for (int i = 0; i < e.PointerCount; i++)
{
id = e.GetPointerId(i);
position.X = e.GetX(i);
position.Y = e.GetY(i);
index = collection.FindById(id, out tlocation);
if (index >= 0)
{
tlocation.State = TouchLocationState.Moved;
tlocation.Position = position;
collection[index] = tlocation;
}
}
break;
// CANCEL, OUTSIDE
case 3:
case 4:
index = collection.FindById(id, out tlocation);
if (index >= 0)
{
tlocation.State = TouchLocationState.Invalid;
collection[index] = tlocation;
}
break;
}
return true;
}
示例14: OnTouchEvent
public override bool OnTouchEvent(MotionEvent e)
{
// This runs on a different thread to the main game loop (note the locking)
// TODO: does this contribute to input lag?
Monitor.Enter(TouchInputManager.lockObject); // Convert to lock?
try
{
bool processed = false; // Event has been processed
int count = e.PointerCount;
MotionEventActions a = e.Action;
MotionEventActions action = a & MotionEventActions.Mask;
// According to the docs, this does not actually produce the "Id" (despite the name), but the "Index"!
int actionPointerIndex = ((int)a & MotionEvent.ActionPointerIdMask) >> MotionEvent.ActionPointerIdShift;
for(int i = 0; i < count; i++) // for each pointer (unordered)
{
int id = e.GetPointerId(i);
var location = new System.Drawing.PointF(e.GetX(i), e.GetY(i));
Point position = inputScaler.TouchToLogical((int)location.X, (int)location.Y);
switch(action)
{
case MotionEventActions.Down:
TouchInputManager.SanityCheckAllTouchesUp();
goto case MotionEventActions.PointerDown; // Fall through
case MotionEventActions.PointerDown:
TouchInputManager.BeginTouch(id, position);
processed = true;
break;
case MotionEventActions.Move:
TouchInputManager.MoveTouch(id, position);
processed = true;
break;
case MotionEventActions.Up:
case MotionEventActions.PointerUp:
case MotionEventActions.Cancel:
TouchInputManager.EndTouch(id, position, action == MotionEventActions.Cancel);
processed = true;
break;
}
}
if(processed)
return true;
else
return base.OnTouchEvent(e);
}
finally
{
Monitor.Exit(TouchInputManager.lockObject);
// http://stackoverflow.com/questions/792185/why-are-touch-events-destroying-my-android-framerate
// http://stackoverflow.com/questions/4342464/android-touch-seriously-slowing-my-application
// Thread.Sleep(16); // TODO: is this necessary?
}
}
示例15: OnTouchEvent
public override bool OnTouchEvent (MotionEvent ev)
{
Log.Debug("PullToZoomScrollView", "onTouchEvent --> action = " + (0xFF & (int)ev.Action));
if (_isHeaderTop && _isEnableZoom) {
switch ((MotionEventActions)0xFF & ev.Action) {
case MotionEventActions.Down:
case MotionEventActions.Outside:
if (!_scalingRunnable.IsFinished()) {
_scalingRunnable.AbortAnimation();
}
_lastMotionY = ev.GetY();
_activePointerId = ev.GetPointerId(0);
_maxScale = (_screenHeight / _zoomHeight);
_lastScale = (_zoomContainer.Bottom / _zoomHeight);
if (_onScrollViewZoomListener != null) {
_onScrollViewZoomListener.onStart();
}
break;
case MotionEventActions.Move:
Log.Debug("PullToZoomScrollView", "_activePointerId = " + _activePointerId);
int j = ev.FindPointerIndex(_activePointerId);
if (j == -1) {
Log.Error("PullToZoomScrollView", "Invalid pointerId = " + _activePointerId + " in onTouchEvent");
} else {
if (_lastMotionY == -1.0F) {
_lastMotionY = ev.GetY(j);
}
if (_zoomContainer.Bottom >= _zoomHeight) {
FrameLayout.LayoutParams localLayoutParams = (FrameLayout.LayoutParams) _zoomContainer.LayoutParameters;
ViewGroup.LayoutParams headLayoutParams = _headerContainer.LayoutParameters;
float f = ((ev.GetY(j) - _lastMotionY + _zoomContainer.Bottom) / _zoomHeight - _lastScale) / 2.0F + _lastScale;
if ((_lastScale <= 1.0D) && (f < _lastScale)) {
localLayoutParams.Height = _zoomHeight;
localLayoutParams.Width = _zoomWidth;
localLayoutParams.Gravity = GravityFlags.Center;
headLayoutParams.Height = _zoomHeight;
_zoomContainer.LayoutParameters=localLayoutParams;
_headerContainer.LayoutParameters=headLayoutParams;
return base.OnTouchEvent(ev);
}
_lastScale = Math.Min(Math.Max(f, 1.0F), _maxScale);
localLayoutParams.Height = ((int) (_zoomHeight * _lastScale));
localLayoutParams.Width = ((int) (_zoomWidth * _lastScale));
localLayoutParams.Gravity = GravityFlags.Center;
headLayoutParams.Height = ((int) (_zoomHeight * _lastScale));
if (localLayoutParams.Height < _screenHeight) {
_zoomContainer.LayoutParameters=localLayoutParams;
_headerContainer.LayoutParameters=headLayoutParams;
}
_lastMotionY = ev.GetY(j);
return true;
}
_lastMotionY = ev.GetY(j);
}
break;
case MotionEventActions.Up:
Reset();
EndScaling();
if (_onScrollViewZoomListener != null) {
_onScrollViewZoomListener.onFinish();
}
break;
case MotionEventActions.Cancel:
int i = ev.ActionIndex;
_lastMotionY = ev.GetY(i);
_activePointerId = ev.GetPointerId(i);
break;
case MotionEventActions.PointerDown:
OnSecondaryPointerUp(ev);
_lastMotionY = ev.GetY(ev.FindPointerIndex(_activePointerId));
break;
}
}
return base.OnTouchEvent (ev);
}