Skip to content

Loading…

Allow a callback when the view is ready #66

Closed
wants to merge 1 commit into from

2 participants

@singpolyma

Allows for setting initial zoom and pan safely, otherwise bad things
happen if the drawable hasn't quite loaded yet.

Closes #64

@singpolyma singpolyma Allow a callback when the view is ready
Allows for setting initial zoom and pan safely, otherwise bad things
happen if the drawable hasn't quite loaded yet.
685fd09
@MikeOrtiz
Owner

I decided not to use a callback, but rather to fix setZoom so that it will be called again with the proper zoom variables during onDraw. You can find my solution here: c20a532.

@MikeOrtiz MikeOrtiz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2014
  1. @singpolyma

    Allow a callback when the view is ready

    singpolyma committed
    Allows for setting initial zoom and pan safely, otherwise bad things
    happen if the drawable hasn't quite loaded yet.
Showing with 26 additions and 2 deletions.
  1. +26 −2 src/com/example/touch/TouchImageView.java
View
28 src/com/example/touch/TouchImageView.java
@@ -94,6 +94,8 @@
private ScaleGestureDetector mScaleDetector;
private GestureDetector mGestureDetector;
+ private Runnable onReady = null;
+ private boolean ready = false;
public TouchImageView(Context context) {
super(context);
@@ -390,7 +392,23 @@ public void setZoom(TouchImageView img) {
PointF center = img.getCenterOfZoomedImage();
setZoom(img.getCurrentZoom(), center.x, center.y, img.getScaleType());
}
-
+
+ public void setOnReady(Runnable r) {
+ if(ready && r != null) {
+ r.run();
+ } else {
+ onReady = r;
+ }
+ }
+
+ private void ready() {
+ if(!ready && onReady != null) {
+ onReady.run();
+ onReady = null;
+ }
+ ready = true;
+ }
+
/**
* For a given point on the view (ie, a touch event), returns the
* point relative to the original drawable's coordinate system.
@@ -1181,4 +1199,10 @@ private void printMatrixInfo() {
matrix.getValues(m);
Log.d(DEBUG, "Scale: " + m[Matrix.MSCALE_X] + " TransX: " + m[Matrix.MTRANS_X] + " TransY: " + m[Matrix.MTRANS_Y]);
}
-}
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ ready();
+ super.onDraw(canvas);
+ }
+}
Something went wrong with that request. Please try again.