Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setScale & setPosition problems #50

Open
gfowley opened this issue Jul 12, 2013 · 2 comments
Open

setScale & setPosition problems #50

gfowley opened this issue Jul 12, 2013 · 2 comments

Comments

@gfowley
Copy link

gfowley commented Jul 12, 2013

Using setScale and setPosition seems to work initially (imageview shows image at specified scale and position), but any touch interaction results in imageview immediately reverting to default position and scale.

May be related to #27 ,but @silentw's fix:

protected void handleUp() {
  multiTouch = false;
  currentScale = image.getScale(); //THIS

...doesn't solve the problem for me.

After much mucking about with setScale and setPosition it seems the problem lays in the touch listener not being set to match the view position and scale, the touch listener contains state that is dependent upon the imageview state ?

Based upon their respective .reset() methods (which are more comprehensive than the setScale and setPosition methods) I've added .setTo(...) methods to GestureImageView...

public void reset() {
  x = centerX;
  y = centerY;
  scaleAdjust = startingScale;
  if (gestureImageViewTouchListener != null) {
    gestureImageViewTouchListener.reset();
  }
  redraw();
}

public void setTo(float newX, float newY, float newScale) {
  x = newX;
  y = newY;
  scaleAdjust = newScale;
  if (gestureImageViewTouchListener != null) {
      gestureImageViewTouchListener.setTo(newX, newY, newScale);
  }
  redraw();
}

...and GestureImageViewTouchListener...

public void reset() {
  currentScale = startingScale;
  next.x = centerX;
  next.y = centerY;
  calculateBoundaries();
  image.setScale(currentScale);
  image.setPosition(next.x, next.y);
  image.redraw();
}

public void setTo(float newX, float newY, float newScale) {
  currentScale = newScale;
  next.x = newX;
  next.y = newY;
  calculateBoundaries();
  image.setScale(currentScale);
  image.setPosition(next.x, next.y);
  image.redraw();
}

Using these methods results in the imagview displaying at the new scale and position. If I drag the image and then zoom it works as expected. However, if I just zoom the image (without having first panned) it reverts to the default scale and position.

Before I throw more hours at this, any advice on likely directions to proceed in ?

@gfowley
Copy link
Author

gfowley commented Jul 13, 2013

A few hours later...

Setting lastScale in GestureImageViewTouchListener seems to do the trick.

GestureImageView:

  public void setTo(float newX, float newY, float newScale) {
    x = newX;
    y = newY;
    scaleAdjust = newScale;
    if (gestureImageViewTouchListener != null) {
        gestureImageViewTouchListener.setTo(newX, newY, newScale);
    }
    redraw();
  }

GestureImageViewTouchListener:

  public void setTo(float newX, float newY, float newScale) {
    currentScale = newScale;
    lastScale = newScale;
    next.x = newX;
    next.y = newY;
    calculateBoundaries();
    image.setScale(currentScale);
    image.setPosition(next.x, next.y);
    image.redraw();
  }

Pull request to follow.

@gfowley
Copy link
Author

gfowley commented Jul 13, 2013

I was tempted to change setScale and setPostion to also work like this, but they are used internally in GestureImageView and I'd rather not cause breakage.

Leads me to the question, were setScale and setPosition only expected to work as used internally and I shouldn't have expected them to work as part of the the public API yet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant