/** * Clean-up the resources attached to this object. This needs to be called when the ImageView is * no longer used. A good example is from {@link android.view.View#onDetachedFromWindow()} or from * {@link android.app.Activity#onDestroy()}. This is automatically called if you are using {@link * uk.co.senab.photoview.PhotoView}. */ @SuppressWarnings("deprecation") public void cleanup() { if (null != mImageView) { // Remove this as a global layout listener ViewTreeObserver observer = mImageView.getViewTreeObserver(); if (null != observer && observer.isAlive()) { observer.removeGlobalOnLayoutListener(this); } // Remove the ImageView's reference to this mImageView.setOnTouchListener(null); // make sure a pending fling runnable won't be run cancelFling(); } if (null != mGestureDetector) { mGestureDetector.setOnDoubleTapListener(null); } // Clear listeners too mMatrixChangeListener = null; mPhotoTapListener = null; mViewTapListener = null; // Finally, clear ImageView mImageView = null; }
@Override public final boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { ViewParent parent = v.getParent(); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event if (null != parent) parent.requestDisallowInterceptTouchEvent(true); else Log.i(LOG_TAG, "onTouch getParent() returned null"); // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post( new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } if (!handled && null != parent) { parent.requestDisallowInterceptTouchEvent(false); } // Finally, try the Scale/Drag detector if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) { handled = true; } } return handled; }
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent ev) { boolean handled = false; if (mZoomEnabled && hasDrawable((ImageView) v)) { getViewParentsFromImageView(v); switch (ev.getAction()) { case ACTION_DOWN: // First, disable the Parent from intercepting the touch // event setParentDisallowInterceptTouchEvent(true); // If we're flinging, and the user presses down, cancel // fling cancelFling(); break; case ACTION_CANCEL: case ACTION_UP: // If the user has zoomed less than min scale, zoom back // to min scale if (getScale() < mMinScale) { RectF rect = getDisplayRect(); if (null != rect) { v.post( new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY())); handled = true; } } break; } // Try the Scale/Drag detector if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) { handled = true; } // Check to see if the user double tapped if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) { handled = true; } } return handled; }