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

fix CanvasTransformer StackOverflow bug #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,70 @@

public class CanvasTransformerBuilder {

private CanvasTransformer mTrans;
private static Interpolator lin = new Interpolator() {
public float getInterpolation(float t) {
return t;
}
};

private static Interpolator lin = new Interpolator() {
public float getInterpolation(float t) {
return t;
}
};
public CanvasTransformer zoom(final int openedX, final int closedX,
final int openedY, final int closedY,
final float px, final float py) {
return zoom(openedX, closedX, openedY, closedY, px, py, lin);
}

private void initTransformer() {
if (mTrans == null)
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) { }
};
}
public CanvasTransformer zoom(final int openedX, final int closedX,
final int openedY, final int closedY,
final float px, final float py, final Interpolator interp) {
return new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
float f = interp.getInterpolation(percentOpen);
canvas.scale((openedX - closedX) * f + closedX,
(openedY - closedY) * f + closedY, px, py);
}
};
}

public CanvasTransformer zoom(final int openedX, final int closedX,
final int openedY, final int closedY,
final int px, final int py) {
return zoom(openedX, closedX, openedY, closedY, px, py, lin);
}
public CanvasTransformer rotate(final int openedDeg, final int closedDeg,
final float px, final float py) {
return rotate(openedDeg, closedDeg, px, py, lin);
}

public CanvasTransformer zoom(final int openedX, final int closedX,
final int openedY, final int closedY,
final int px, final int py, final Interpolator interp) {
initTransformer();
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
mTrans.transformCanvas(canvas, percentOpen);
float f = interp.getInterpolation(percentOpen);
canvas.scale((openedX - closedX) * f + closedX,
(openedY - closedY) * f + closedY, px, py);
}
};
return mTrans;
}
public CanvasTransformer rotate(final int openedDeg, final int closedDeg,
final float px, final float py, final Interpolator interp) {
return new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
float f = interp.getInterpolation(percentOpen);
canvas.rotate((openedDeg - closedDeg) * f + closedDeg,
px, py);
}
};
}

public CanvasTransformer rotate(final int openedDeg, final int closedDeg,
final int px, final int py) {
return rotate(openedDeg, closedDeg, px, py, lin);
}
public CanvasTransformer translate(final int openedX, final int closedX,
final int openedY, final int closedY) {
return translate(openedX, closedX, openedY, closedY, lin);
}

public CanvasTransformer rotate(final int openedDeg, final int closedDeg,
final int px, final int py, final Interpolator interp) {
initTransformer();
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
mTrans.transformCanvas(canvas, percentOpen);
float f = interp.getInterpolation(percentOpen);
canvas.rotate((openedDeg - closedDeg) * f + closedDeg,
px, py);
}
};
return mTrans;
}
public CanvasTransformer translate(final int openedX, final int closedX,
final int openedY, final int closedY, final Interpolator interp) {
return new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
float f = interp.getInterpolation(percentOpen);
canvas.translate((openedX - closedX) * f + closedX,
(openedY - closedY) * f + closedY);
}
};
}

public CanvasTransformer translate(final int openedX, final int closedX,
final int openedY, final int closedY) {
return translate(openedX, closedX, openedY, closedY, lin);
}

public CanvasTransformer translate(final int openedX, final int closedX,
final int openedY, final int closedY, final Interpolator interp) {
initTransformer();
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
mTrans.transformCanvas(canvas, percentOpen);
float f = interp.getInterpolation(percentOpen);
canvas.translate((openedX - closedX) * f + closedX,
(openedY - closedY) * f + closedY);
}
};
return mTrans;
}

public CanvasTransformer concatTransformer(final CanvasTransformer t) {
initTransformer();
mTrans = new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
mTrans.transformCanvas(canvas, percentOpen);
t.transformCanvas(canvas, percentOpen);
}
};
return mTrans;
}
public CanvasTransformer concatTransformer(final CanvasTransformer... args) {
return new CanvasTransformer() {
public void transformCanvas(Canvas canvas, float percentOpen) {
for (final CanvasTransformer arg : args) {
arg.transformCanvas(canvas, percentOpen);
}
}
};
}

}