Example usage for android.widget ImageView setOnTouchListener

List of usage examples for android.widget ImageView setOnTouchListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnTouchListener.

Prototype

public void setOnTouchListener(OnTouchListener l) 

Source Link

Document

Register a callback to be invoked when a touch event is sent to this view.

Usage

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;/*from w w  w . ja  va  2 s.c o  m*/
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:com.biggun.drawbitmapmesh.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;//from  w w w  .  j a v a 2 s  . co m
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }

            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:org.catnut.adapter.TweetAdapter.java

private void injectThumbs(final Context context, final String originUri, String mediumThumbUrl,
        String smallThumbUrl, final ImageView thumbs) {
    switch (mThumbsOption) {
    case SMALL://w ww .j av  a2 s. com
    case MEDIUM:
        if (!TextUtils.isEmpty(originUri)) {
            if (mStayInLatest) { // not in offline mode
                RequestCreator creator;
                if (mThumbsOption == ThumbsOption.MEDIUM) {
                    creator = Picasso.with(context).load(mediumThumbUrl).centerCrop().resize(mScreenWidth,
                            (int) (mScreenWidth * Constants.GOLDEN_RATIO));
                } else {
                    creator = Picasso.with(context).load(smallThumbUrl);
                }
                creator.placeholder(android.R.drawable.ic_menu_report_image).error(R.drawable.error)
                        .into(thumbs);
                thumbs.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        return CatnutUtils.imageOverlay(v, event);
                    }
                });
                thumbs.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        thumbs.getDrawable().clearColorFilter();
                        thumbs.invalidate();
                        Intent intent = SingleFragmentActivity.getIntent(context,
                                SingleFragmentActivity.PHOTO_VIEWER);
                        intent.putExtra(Constants.PIC, originUri);
                        mContext.startActivity(intent);
                    }
                });
            } else {
                // sometimes, the user may read timeline in offline mode(may opening the 2/3g),
                // so, don' t load the image
                // todo, may be we need to check it in cache or place the network unavailable image?
                thumbs.setImageResource(android.R.drawable.ic_menu_report_image);
            }
            thumbs.setVisibility(View.VISIBLE);
            break;
        }
        // otherwise, fall through...
    case NONE:
    case ORIGINAL:
    default:
        thumbs.setVisibility(View.GONE);
        break;
    }
}

From source file:com.thingsee.tracker.MainActivity.java

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;// www. j  a  va 2 s  .c  om

    TileProvider wmsTileProvider = TileProviderFactory.getKapsiWmsTileProvider();
    mMap.addTileOverlay(new TileOverlayOptions().tileProvider(wmsTileProvider).fadeIn(true));

    initGoogleMap();

    trackerList = (HorizontalScrollView) this.findViewById(R.id.tracker_scroll_area);
    mTrackerItemLayout = (LinearLayout) findViewById(R.id.trackers);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mainari, 16));
    Marker mark = mMap.addMarker(new MarkerOptions().position(mainari));

    ImageView locateButton = (ImageView) findViewById(R.id.app_icon);

    //set the ontouch listener
    locateButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                if (onChildOnMapView) {
                    onUpPressed();
                } else {
                    userZoomAndPanOnMap = false;
                    zoomToBoundingBox();
                }
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    ImageView settingsButton = (ImageView) findViewById(R.id.header_settings_icon);

    //set the ontouch listener
    settingsButton.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                ImageView view = (ImageView) v;
                //overlay is black with transparency of 0x77 (119)
                view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP:
                final Dialog verificationQuery = new Dialog(mContext,
                        android.R.style.Theme_Translucent_NoTitleBar);
                verificationQuery.requestWindowFeature(Window.FEATURE_NO_TITLE);
                verificationQuery.setCancelable(false);
                verificationQuery.setContentView(R.layout.request_admin_code);
                ClearTextView ok = (ClearTextView) verificationQuery.findViewById(R.id.ok);
                ok.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                        EditText code = (EditText) verificationQuery.findViewById(R.id.verification_code);
                        if (code.getText().toString().equalsIgnoreCase("password")) {
                            Intent intent = new Intent(MainActivity.this, MenuActivity.class);
                            startActivity(intent);
                        }
                    }
                });
                ClearTextView cancel = (ClearTextView) verificationQuery.findViewById(R.id.cancel);
                cancel.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        verificationQuery.dismiss();
                    }
                });
                verificationQuery.show();
                verificationQuery.getWindow().setDimAmount(0.5f);
                verificationQuery.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            case MotionEvent.ACTION_CANCEL: {
                ImageView view = (ImageView) v;
                //clear the overlay
                view.getDrawable().setColorFilter(mResources.getColor(R.color.white_effect),
                        PorterDuff.Mode.SRC_ATOP);
                view.invalidate();
                break;
            }
            }

            return true;
        }
    });

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng position) {
            if (onChildOnMapView) {
                if (trackerModelWithMarker != null) {
                    trackerModelWithMarker.getMarker().showInfoWindow();
                }
            }
        }
    });

    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (trackersActive) {
                LatLng latlng = marker.getPosition();
                userZoomAndPanOnMap = false;
                if ((latlng.latitude == mainari.latitude) && (latlng.longitude == mainari.longitude)) {
                    if (onChildOnMapView) {
                        if (trackerModelWithMarker != null) {
                            trackerModelWithMarker.getMarker().showInfoWindow();
                        }
                    }
                } else {
                    if (!onChildOnMapView) {
                        trackerModelWithMarker = null;
                        // Zoom to marker tapped
                        zoomToMarker(latlng);
                        //Remove other markers
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    focusOnChildOnMap(trackerModel.getSerialNumber());
                                    trackerModelWithMarker = trackerModel;
                                    trackerModelWithMarker.getMarker().showInfoWindow();
                                }
                            }
                        }
                    } else {
                        trackerModelWithMarker.getMarker().showInfoWindow();
                        for (String key : trackers.keySet()) {
                            TrackerModel trackerModel = trackers.get(key);
                            if (trackerModel.getLatestLatLng() != null) {
                                if ((trackerModel.getLatestLatLng().latitude == latlng.latitude)
                                        && (trackerModel.getLatestLatLng().longitude == latlng.longitude)) {
                                    onBackPressed();
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            // Getting view from the layout file info_window_layout
            View v = null;

            for (String key : trackers.keySet()) {
                TrackerModel trackerModel = trackers.get(key);
                if (trackerModel.getLatestLatLng() != null) {
                    if ((trackerModel.getLatestLatLng().latitude == arg0.getPosition().latitude)
                            && (trackerModel.getLatestLatLng().longitude == arg0.getPosition().longitude)) {
                        v = getLayoutInflater().inflate(R.layout.info_window, null);
                        trackerModelWithMarker = trackerModel;
                        TextView trackerAccuracy = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_accuracy);
                        if (trackerModelWithMarker.getAccuracy() != -1) {
                            trackerAccuracy
                                    .setText(String.format(mResources.getString(R.string.tracker_accuracy),
                                            trackerModelWithMarker.getAccuracy()));
                        } else {
                            trackerAccuracy.setText(
                                    String.format(mResources.getString(R.string.tracker_accuracy), 0.0f));
                        }
                        TextView trackerDistanceTs = (TextView) v
                                .findViewById(R.id.tracker_marker_popup_update_timestamp);
                        if (trackerModelWithMarker.getLastLocationUpdate() != 0) {
                            String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources,
                                    trackerModelWithMarker.getLastLocationUpdate());
                            trackerDistanceTs.setText(
                                    mResources.getString(R.string.tracker_timestamp) + " " + timeStampText);
                        } else {
                            trackerDistanceTs.setText(mResources.getString(R.string.tracker_timestamp) + " - ");
                        }
                        trackerInfoWindow = v;
                    }
                }
            }
            // Returning the view containing InfoWindow contents
            return v;
        }
    });
    IntentFilter statusIntentFilter = new IntentFilter(CommonConstants.BROADCAST_ACTION);
    statusIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
    mFetchCloudDataStateReceiver = new FetchCloudDataStateReceiver();
    LocalBroadcastManager.getInstance(this).registerReceiver(mFetchCloudDataStateReceiver, statusIntentFilter);

    mapLoaded = true;
    if (splashReady) {
        mSplashHandler.postDelayed(splashScreenOffFromDisplay, 0);
    }
}

From source file:org.catnut.fragment.TweetFragment.java

/**
 * ??//w w  w .ja  v  a 2s . c  o  m
 *
 * @param thumb url
 * @param originalUrl url
 */
private void loadThumbs(String thumb, final String originalUrl, final ImageView thumbs,
        final JSONArray jsonArray, View overflow) {
    if (!TextUtils.isEmpty(thumb)) {
        if (mStayInLatest) {
            int screenWidth = CatnutUtils.getScreenWidth(getActivity());
            Picasso.with(getActivity()).load(thumb).into(thumbs);
            thumbs.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return CatnutUtils.imageOverlay(v, event);
                }
            });
            thumbs.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    thumbs.getDrawable().clearColorFilter();
                    mText.invalidate();
                    Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                            SingleFragmentActivity.PHOTO_VIEWER);
                    intent.putExtra(Constants.PIC, originalUrl);
                    startActivity(intent);
                }
            });
        } else {
            thumbs.setImageResource(R.drawable.error);
        }
        thumbs.setVisibility(View.VISIBLE);
    } else {
        thumbs.setVisibility(View.GONE);
        overflow.setVisibility(View.GONE);
    }
    if (jsonArray != null && jsonArray.length() > 1) {
        overflow.setVisibility(View.VISIBLE);
        overflow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View view = LayoutInflater.from(getActivity()).inflate(R.layout.tweet_pics, null);
                LinePageIndicator indicator = (LinePageIndicator) view.findViewById(R.id.indicator);
                final ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
                pager.setPageTransformer(true, new PageTransformer.DepthPageTransformer());
                pager.setAdapter(new PagerAdapter() {
                    @Override
                    public int getCount() {
                        return jsonArray.length();
                    }

                    @Override
                    public boolean isViewFromObject(View view, Object object) {
                        return view == object;
                    }

                    @Override
                    public void destroyItem(ViewGroup container, int position, Object object) {
                        container.removeView((View) object);
                    }

                    @Override
                    public Object instantiateItem(ViewGroup container, int position) {
                        View v = LayoutInflater.from(getActivity()).inflate(R.layout.photo, null);
                        TouchImageView iv = (TouchImageView) v.findViewById(R.id.image);
                        String url = jsonArray.optJSONObject(position).optString(Status.thumbnail_pic);
                        String replace = url.replace(Constants.THUMBNAIL, Status.MEDIUM_THUMBNAIL);
                        Picasso.with(getActivity()).load(replace).into(iv);
                        container.addView(v);
                        return v;
                    }
                });
                indicator.setViewPager(pager);
                new AlertDialog.Builder(
                        new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Dialog)).setView(view)
                                .setPositiveButton(getString(R.string.original_pics),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                ArrayList<Uri> urls = new ArrayList<Uri>(jsonArray.length());
                                                for (int i = 0; i < jsonArray.length(); i++) {
                                                    String s = jsonArray.optJSONObject(i)
                                                            .optString(Status.thumbnail_pic)
                                                            .replace(Constants.THUMBNAIL,
                                                                    Status.LARGE_THUMBNAIL);
                                                    urls.add(Uri.parse(s));
                                                }
                                                Intent intent = SingleFragmentActivity.getIntent(getActivity(),
                                                        SingleFragmentActivity.GALLERY);
                                                intent.putExtra(GalleryPagerFragment.CUR_INDEX,
                                                        pager.getCurrentItem());
                                                intent.putExtra(GalleryPagerFragment.URLS, urls);
                                                intent.putExtra(GalleryPagerFragment.TITLE,
                                                        getString(R.string.tweet_pics));
                                                startActivity(intent);
                                            }
                                        })
                                .setNegativeButton(getString(R.string.close), null).show();
            }
        });
    } else {
        overflow.setVisibility(View.GONE);
    }
}

From source file:com.mooc.viewpage_photoview_circleindicator.photoview.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    //?// w  w w  . j  a  v  a  2  s.  c  om
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);//???bitmap??
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    //
    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}

From source file:suntai.ditudome.utils.photoview.PhotoViewAttacher.java

public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }/* w ww  .j av  a 2s  . c  o  m*/

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.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;
}

From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java

@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }/* w  w w. j  a  v  a  2s .  co  m*/

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.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;
}

From source file:com.cylan.jiafeigou.support.photoview.PhotoViewAttacher.java

/**
 * 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 View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 * {@link PhotoView}.//from w  w w.java  2 s. c  om
 */
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView'account reference to this
        imageView.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, clearLocal ImageView
    mImageView = null;
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

/**
 * 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 View#onDetachedFromWindow()} or
 * from {@link android.app.Activity#onDestroy()}. This is automatically called if you are using
 *//*from w w w .  jav  a2 s .com*/
@SuppressWarnings("deprecation")
public void cleanup() {
    if (null == mImageView) {
        return; // cleanup already done
    }

    final ImageView imageView = mImageView.get();

    if (null != imageView) {
        // Remove this as a global layout listener
        ViewTreeObserver observer = imageView.getViewTreeObserver();
        if (null != observer && observer.isAlive()) {
            observer.removeGlobalOnLayoutListener(this);
        }

        // Remove the ImageView's reference to this
        imageView.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;
}