private OfficeThing getTouchedThing(int xTouchModel, int yTouchModel) { OfficeThing touched = null; foreach (OfficeThing thing in mOfficeLayout.ThingsTopDown) { int top = thing.Top; int left = thing.Left; int bottom = thing.Top + mRenderUtil.getScreenHeight(thing); int right = thing.Left + mRenderUtil.getScreenWidth(thing); if (yTouchModel <= bottom && yTouchModel >= top && xTouchModel >= left && xTouchModel <= right) { touched = thing; break; } } return(touched); }
private void moveThing(OfficeThing touchedThing, int xTouchLogical, int yTouchLogical) { //TODO: make sure these are accurate int newTop = yTouchLogical - mRenderUtil.getModelHeight(touchedThing) / 2; int newLeft = xTouchLogical - mRenderUtil.getModelWidth(touchedThing) / 2; int newBottom = yTouchLogical + mRenderUtil.getModelHeight(touchedThing) / 2; int newRight = xTouchLogical + mRenderUtil.getModelWidth(touchedThing) / 2; if (newTop < 0 || newLeft < 0 || newBottom > LOGICAL_HEIGHT || newRight > LOGICAL_WIDTH) { Log.v(TAG, "Dragging beyond screen edge. Limiting"); } // Limit moves to the boundaries of the screen if (newTop < 0) { newTop = 0; } if (newLeft < 0) { newLeft = 0; } if (newBottom > LOGICAL_HEIGHT) { newTop = LOGICAL_HEIGHT - mRenderUtil.getModelHeight(touchedThing); } if (newRight > LOGICAL_WIDTH) { newLeft = LOGICAL_WIDTH - mRenderUtil.getModelWidth(touchedThing); } // Save the object touchedThing.Top = newTop; touchedThing.Left = newLeft; // Notify listeners if (null != this.mThingChangedListener) { mThingChangedListener.thingChanged(touchedThing.Key, touchedThing); } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: @Override public boolean onTouchEvent(final android.view.MotionEvent event) public override bool onTouchEvent(MotionEvent @event) { bool handled = false; OfficeThing touchedThing; int xTouchLogical; int yTouchLogical; int pointerId; int actionIndex = @event.ActionIndex; // get touch event coordinates and make transparent wrapper from it switch (@event.ActionMasked) { case MotionEvent.ACTION_DOWN: // first pointer, clear the pointer mSelectedThing = null; xTouchLogical = screenToModel((int) @event.getX(0)); yTouchLogical = screenToModel((int) @event.getY(0)); // check if we've touched inside something touchedThing = getTouchedThing(xTouchLogical, yTouchLogical); if (touchedThing == null) { mSelectedThingChangeListener.thingChanged(null); break; } mSelectedThing = touchedThing; if (null != mSelectedThingChangeListener) { mSelectedThingChangeListener.thingChanged(touchedThing); } touchedThing.setzIndex(mOfficeLayout.HighestzIndex + 1); Log.v(TAG, "Selected " + touchedThing); handled = true; break; case MotionEvent.ACTION_MOVE: pointerId = @event.getPointerId(actionIndex); if (pointerId > 0) { break; } xTouchLogical = screenToModel((int) @event.getX(actionIndex)); yTouchLogical = screenToModel((int) @event.getY(actionIndex)); touchedThing = mSelectedThing; if (null == touchedThing) { break; } moveThing(touchedThing, xTouchLogical, yTouchLogical); handled = true; break; case MotionEvent.ACTION_UP: mSelectedThing = null; invalidate(); handled = true; break; case MotionEvent.ACTION_CANCEL: handled = true; break; } return base.onTouchEvent(@event) || handled; }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: @Override public boolean onTouchEvent(final android.view.MotionEvent event) public override bool onTouchEvent(MotionEvent @event) { bool handled = false; OfficeThing touchedThing; int xTouchLogical; int yTouchLogical; int pointerId; int actionIndex = @event.ActionIndex; // get touch event coordinates and make transparent wrapper from it switch (@event.ActionMasked) { case MotionEvent.ACTION_DOWN: // first pointer, clear the pointer mSelectedThing = null; xTouchLogical = screenToModel((int)@event.getX(0)); yTouchLogical = screenToModel((int)@event.getY(0)); // check if we've touched inside something touchedThing = getTouchedThing(xTouchLogical, yTouchLogical); if (touchedThing == null) { mSelectedThingChangeListener.thingChanged(null); break; } mSelectedThing = touchedThing; if (null != mSelectedThingChangeListener) { mSelectedThingChangeListener.thingChanged(touchedThing); } touchedThing.setzIndex(mOfficeLayout.HighestzIndex + 1); Log.v(TAG, "Selected " + touchedThing); handled = true; break; case MotionEvent.ACTION_MOVE: pointerId = @event.getPointerId(actionIndex); if (pointerId > 0) { break; } xTouchLogical = screenToModel((int)@event.getX(actionIndex)); yTouchLogical = screenToModel((int)@event.getY(actionIndex)); touchedThing = mSelectedThing; if (null == touchedThing) { break; } moveThing(touchedThing, xTouchLogical, yTouchLogical); handled = true; break; case MotionEvent.ACTION_UP: mSelectedThing = null; invalidate(); handled = true; break; case MotionEvent.ACTION_CANCEL: handled = true; break; } return(base.onTouchEvent(@event) || handled); }