Пример #1
0
  /**
   * 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;
  }
Пример #2
0
 public void onDismiss() {
   mPopup = null;
   mMenu.close();
   if (mTreeObserver != null) {
     if (!mTreeObserver.isAlive()) mTreeObserver = mAnchorView.getViewTreeObserver();
     mTreeObserver.removeGlobalOnLayoutListener(this);
     mTreeObserver = null;
   }
 }
Пример #3
0
 private void removeObserverForView(final View view) {
   final ViewTreeObserver treeObserver = view.getViewTreeObserver();
   if (treeObserver != null && treeObserver.isAlive()) {
     if (TiC.JELLY_BEAN_OR_GREATER) {
       treeObserver.removeOnGlobalLayoutListener(this);
     } else {
       treeObserver.removeGlobalOnLayoutListener(this);
     }
   }
 }
 public void tearDownListener() {
   final ViewTreeObserver viewTreeObserver = mView.getViewTreeObserver();
   if (viewTreeObserver != null) {
     viewTreeObserver.removeGlobalOnLayoutListener(this);
     viewTreeObserver.removeOnGlobalFocusChangeListener(this);
     viewTreeObserver.removeOnPreDrawListener(this);
     viewTreeObserver.removeOnScrollChangedListener(this);
     viewTreeObserver.removeOnTouchModeChangeListener(this);
   }
 }
 /**
  * Dismisses the popup window with activities.
  *
  * @return True if dismissed, false if already dismissed.
  */
 public boolean dismissPopup() {
   if (isShowingPopup()) {
     getListPopupWindow().dismiss();
     ViewTreeObserver viewTreeObserver = getViewTreeObserver();
     if (viewTreeObserver.isAlive()) {
       viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
     }
   }
   return true;
 }
Пример #6
0
 /** 删除监听器 */
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 public static final void removeOnGlobalLayoutListener(
     ViewTreeObserver viewTreeObserver,
     ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
     viewTreeObserver.removeGlobalOnLayoutListener(onGlobalLayoutListener);
   } else {
     viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener);
   }
 }
Пример #7
0
  @Override
  public void onDestroy() {
    super.onDestroy();
    if (mScrollView == null) {
      return;
    }

    ViewTreeObserver vto = mScrollView.getViewTreeObserver();
    if (vto.isAlive()) {
      vto.removeGlobalOnLayoutListener(mGlobalLayoutListener);
    }
  }
Пример #8
0
  public void testRemoveGlobalOnLayoutListener() {
    final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout);
    mViewTreeObserver = layout.getViewTreeObserver();

    MockOnGlobalLayoutListener listener = new MockOnGlobalLayoutListener();
    assertFalse(listener.hasCalledOnGlobalLayout());
    mViewTreeObserver.addOnGlobalLayoutListener(listener);
    mViewTreeObserver.dispatchOnGlobalLayout();
    assertTrue(listener.hasCalledOnGlobalLayout());

    listener.reset();
    assertFalse(listener.hasCalledOnGlobalLayout());
    mViewTreeObserver.removeGlobalOnLayoutListener(listener);
    mViewTreeObserver.dispatchOnGlobalLayout();
    assertFalse(listener.hasCalledOnGlobalLayout());
  }
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   ActivityChooserModel dataModel = mAdapter.getDataModel();
   if (dataModel != null) {
     try {
       dataModel.unregisterObserver(mModelDataSetOberver);
     } catch (IllegalStateException e) {
       // Oh, well... fixes issue #557
     }
   }
   ViewTreeObserver viewTreeObserver = getViewTreeObserver();
   if (viewTreeObserver.isAlive()) {
     viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
   }
   mIsAttachedToWindow = false;
 }
Пример #10
0
  /**
   * 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
   * EasePhotoView.co.senab.photoview.PhotoView}.
   */
  @SuppressLint("NewApi")
  @SuppressWarnings("deprecation")
  public final void cleanup() {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
      if (null != mImageView) {
        mImageView.get().getViewTreeObserver().removeOnGlobalLayoutListener(this);
      }

      if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
        mViewTreeObserver.removeOnGlobalLayoutListener(this);

        mViewTreeObserver = null;

        // Clear listeners too
        mMatrixChangeListener = null;
        mPhotoTapListener = null;
        mViewTapListener = null;
        // Finally, clear ImageView
        mImageView = null;
      }

    } else {
      if (null != mImageView) {
        mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
      }

      if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
        mViewTreeObserver.removeGlobalOnLayoutListener(this);

        mViewTreeObserver = null;

        // Clear listeners too
        mMatrixChangeListener = null;
        mPhotoTapListener = null;
        mViewTapListener = null;
        // Finally, clear ImageView
        mImageView = null;
      }
    }
  }