/// <summary>Maps a point to a position in the list.</summary> /// <remarks>Maps a point to a position in the list.</remarks> /// <param name="x">X in local coordinate</param> /// <param name="y">Y in local coordinate</param> /// <returns> /// The position of the item which contains the specified point, or /// <see cref="android.widget.AdapterView.INVALID_POSITION">android.widget.AdapterView.INVALID_POSITION /// </see> /// if the point does not intersect an item. /// </returns> public virtual int pointToPosition(int x, int y) { android.graphics.Rect frame = mTouchFrame; if (frame == null) { mTouchFrame = new android.graphics.Rect(); frame = mTouchFrame; } int count = getChildCount(); { for (int i = count - 1; i >= 0; i--) { android.view.View child = getChildAt(i); if (child.getVisibility() == android.view.View.VISIBLE) { child.getHitRect(frame); if (frame.contains(x, y)) { return(mFirstPosition + i); } } } } return(android.widget.AdapterView.INVALID_POSITION); }
/// <summary>Returns the View that should receive a touch at the given coordinates.</summary> /// <remarks>Returns the View that should receive a touch at the given coordinates.</remarks> /// <param name="rawX">The raw X.</param> /// <param name="rawY">The raw Y.</param> /// <returns>The view that should receive the touches, or null if there is not one.</returns> private android.view.View findViewForTouch(int rawX, int rawY) { // Reverse order so the child drawn on top gets first dibs. int containerCoordsX = rawX - mContainerRawLocation[0]; int containerCoordsY = rawY - mContainerRawLocation[1]; android.graphics.Rect frame = mTempRect; android.view.View closestChild = null; int closestChildDistanceSq = int.MaxValue; { for (int i = mContainer.getChildCount() - 1; i >= 0; i--) { android.view.View child = mContainer.getChildAt(i); if (child.getVisibility() != android.view.View.VISIBLE) { continue; } child.getHitRect(frame); if (frame.contains(containerCoordsX, containerCoordsY)) { return(child); } int distanceX; if (containerCoordsX >= frame.left && containerCoordsX <= frame.right) { distanceX = 0; } else { distanceX = System.Math.Min(System.Math.Abs(frame.left - containerCoordsX), System.Math.Abs (containerCoordsX - frame.right)); } int distanceY; if (containerCoordsY >= frame.top && containerCoordsY <= frame.bottom) { distanceY = 0; } else { distanceY = System.Math.Min(System.Math.Abs(frame.top - containerCoordsY), System.Math.Abs (containerCoordsY - frame.bottom)); } int distanceSq = distanceX * distanceX + distanceY * distanceY; if ((distanceSq < mTouchPaddingScaledSq) && (distanceSq < closestChildDistanceSq)) { closestChild = child; closestChildDistanceSq = distanceSq; } } } return(closestChild); }