Hi,
I am zooming into a canvas and than dragging it around. So far it works
with the below code. My problem es, that I want to detect, when the border
of the canvas is reached. Then the dragging should stop. I don't get this
to work (please see comment in the code below for my try in "case
MotionEvent.ACTION_MOVE: ") and need help..
Another issue is, that the scrolling has differed speed depending on the
scaleSize and goes into different directions depending on scaleFactor > 1
or < 1. I tried to solve this with the variable "richtungsKorrektur"
Thanks for help
Tobias
<code>
@Override public boolean onTouchEvent(MotionEvent ev) {
// If we are not supporting either zoom or pan, return early.
if (!mSupportsZoom && !mSupportsPan) return false;
// Let the ScaleGestureDetector inspect all events.
scaleDetector.onTouchEvent(ev);
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
pause = true;
final float x = ev.getX();
final float y = ev.getY();
mLastTouchX = x;
mLastTouchY = y;
mActivePointerId = ev.getPointerId(0);
break;
}
case MotionEvent.ACTION_MOVE: {
final int pointerIndex =
ev.findPointerIndex(mActivePointerId);
final float x = ev.getX(pointerIndex);
final float y = ev.getY(pointerIndex);
// Only move if the view supports panning and
// ScaleGestureDetector isn't processing a gesture.
if (mSupportsPan && !scaleDetector.isInProgress()) {
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
float altx = mPosX, alty = mPosY;
float richtungsKorrektur = (scaleFactor < 1 ? 1 : -1) *
(15-Math.abs(scaleFactor-1));
mPosX += dx * richtungsKorrektur;
mPosY += dy * richtungsKorrektur;
// TODO: try to detect when border is reached and stop
then
float mPosXMin =
mCanvas.getWidth()/scaleFactor-this.getWidth();
if (mPosX < mPosXMin) mPosX = altx; // this seems to
be wrong..
//...
//...
invalidate();
}
mLastTouchX = x;
mLastTouchY = y;
break;
}
case MotionEvent.ACTION_UP: {
pause = false;
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_POINTER_UP: {
final int pointerIndex = (ev.getAction() &
MotionEvent.ACTION_POINTER_INDEX_MASK)
>> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
}
}
return true;
}
</code>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.