public override bool dispatchTouchEvent(android.view.MotionEvent ev) { if (mDefaultTouchRecepient == null) { return(base.dispatchTouchEvent(ev)); } if (base.dispatchTouchEvent(ev)) { return(true); } mTempRect.set(0, 0, 0, 0); offsetRectIntoDescendantCoords(mDefaultTouchRecepient, mTempRect); ev.setLocation(ev.getX() + mTempRect.left, ev.getY() + mTempRect.top); return(mDefaultTouchRecepient.dispatchTouchEvent(ev)); }
public virtual bool onTouch(android.view.View v, android.view.MotionEvent @event) { int action = @event.getAction(); if (@event.getPointerCount() > 1) { // ZoomButtonsController doesn't handle mutitouch. Give up control. return(false); } if (mReleaseTouchListenerOnUp) { // The controls were dismissed but we need to throw away all events until the up if (action == android.view.MotionEvent.ACTION_UP || action == android.view.MotionEvent .ACTION_CANCEL) { mOwnerView.setOnTouchListener(null); setTouchTargetView(null); mReleaseTouchListenerOnUp = false; } // Eat this event return(true); } dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT); android.view.View targetView = mTouchTargetView; switch (action) { case android.view.MotionEvent.ACTION_DOWN: { targetView = findViewForTouch((int)@event.getRawX(), (int)@event.getRawY()); setTouchTargetView(targetView); break; } case android.view.MotionEvent.ACTION_UP: case android.view.MotionEvent.ACTION_CANCEL: { setTouchTargetView(null); break; } } if (targetView != null) { // The upperleft corner of the target view in raw coordinates int targetViewRawX = mContainerRawLocation[0] + mTouchTargetWindowLocation[0]; int targetViewRawY = mContainerRawLocation[1] + mTouchTargetWindowLocation[1]; android.view.MotionEvent containerEvent = android.view.MotionEvent.obtain(@event); // Convert the motion event into the target view's coordinates (from // owner view's coordinates) containerEvent.offsetLocation(mOwnerViewRawLocation[0] - targetViewRawX, mOwnerViewRawLocation [1] - targetViewRawY); // These are floats because we need to potentially offset away this exact amount float containerX = containerEvent.getX(); float containerY = containerEvent.getY(); if (containerX < 0 && containerX > -ZOOM_CONTROLS_TOUCH_PADDING) { containerEvent.offsetLocation(-containerX, 0); } if (containerY < 0 && containerY > -ZOOM_CONTROLS_TOUCH_PADDING) { containerEvent.offsetLocation(0, -containerY); } bool retValue = targetView.dispatchTouchEvent(containerEvent); containerEvent.recycle(); return(retValue); } else { return(false); } }
/// <summary> /// Will forward touch events to the delegate view if the event is within the bounds /// specified in the constructor. /// </summary> /// <remarks> /// Will forward touch events to the delegate view if the event is within the bounds /// specified in the constructor. /// </remarks> /// <param name="event">The touch event to forward</param> /// <returns>True if the event was forwarded to the delegate, false otherwise.</returns> public virtual bool onTouchEvent(android.view.MotionEvent @event) { int x = (int)@event.getX(); int y = (int)@event.getY(); bool sendToDelegate = false; bool hit = true; bool handled = false; switch (@event.getAction()) { case android.view.MotionEvent.ACTION_DOWN: { android.graphics.Rect bounds = mBounds; if (bounds.contains(x, y)) { mDelegateTargeted = true; sendToDelegate = true; } break; } case android.view.MotionEvent.ACTION_UP: case android.view.MotionEvent.ACTION_MOVE: { sendToDelegate = mDelegateTargeted; if (sendToDelegate) { android.graphics.Rect slopBounds = mSlopBounds; if (!slopBounds.contains(x, y)) { hit = false; } } break; } case android.view.MotionEvent.ACTION_CANCEL: { sendToDelegate = mDelegateTargeted; mDelegateTargeted = false; break; } } if (sendToDelegate) { android.view.View delegateView = mDelegateView; if (hit) { // Offset event coordinates to be inside the target view @event.setLocation(delegateView.getWidth() / 2, delegateView.getHeight() / 2); } else { // Offset event coordinates to be outside the target view (in case it does // something like tracking pressed state) int slop = mSlop; @event.setLocation(-(slop * 2), -(slop * 2)); } handled = delegateView.dispatchTouchEvent(@event); } return(handled); }