Java Code Examples for android.view.ViewTreeObserver#removeOnPreDrawListener()

The following examples show how to use android.view.ViewTreeObserver#removeOnPreDrawListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewTarget.java    From giffun with Apache License 2.0 6 votes vote down vote up
private void checkCurrentDimens() {
    if (cbs.isEmpty()) {
        return;
    }

    int currentWidth = getViewWidthOrParam();
    int currentHeight = getViewHeightOrParam();
    if (!isSizeValid(currentWidth) || !isSizeValid(currentHeight)) {
        return;
    }

    notifyCbs(currentWidth, currentHeight);
    // Keep a reference to the layout listener and remove it here
    // rather than having the observer remove itself because the observer
    // we add the listener to will be almost immediately merged into
    // another observer and will therefore never be alive. If we instead
    // keep a reference to the listener and remove it here, we get the
    // current view tree observer and should succeed.
    ViewTreeObserver observer = view.getViewTreeObserver();
    if (observer.isAlive()) {
        observer.removeOnPreDrawListener(layoutListener);
    }
    layoutListener = null;
}
 
Example 2
Source File: DeferredRequestCreator.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreDraw() {
    ImageView target = this.target.get();
    if (target == null) {
        return true;
    }
    ViewTreeObserver vto = target.getViewTreeObserver();
    if (!vto.isAlive()) {
        return true;
    }

    int width = target.getWidth();
    int height = target.getHeight();

    if (width <= 0 || height <= 0) {
        return true;
    }

    vto.removeOnPreDrawListener(this);

    this.creator.unfit().resize(width, height).into(target, callback);
    return true;
}
 
Example 3
Source File: DeferredRequestCreator.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreDraw() {
    ImageView target = this.target.get();
    if (target == null) {
        return true;
    }
    ViewTreeObserver vto = target.getViewTreeObserver();
    if (!vto.isAlive()) {
        return true;
    }

    int width = target.getWidth();
    int height = target.getHeight();

    if (width <= 0 || height <= 0) {
        return true;
    }

    vto.removeOnPreDrawListener(this);

    this.creator.unfit().resize(width, height).into(target, callback);
    return true;
}
 
Example 4
Source File: LithoScrollView.java    From litho with Apache License 2.0 6 votes vote down vote up
void mount(
    ComponentTree contentComponentTree,
    final ScrollPosition scrollPosition,
    boolean isIncrementalMountEnabled) {
  mLithoView.setComponentTree(contentComponentTree);

  mIsIncrementalMountEnabled = isIncrementalMountEnabled;
  mScrollPosition = scrollPosition;
  final ViewTreeObserver.OnPreDrawListener onPreDrawListener =
      new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
          setScrollY(scrollPosition.y);
          ViewTreeObserver currentViewTreeObserver = getViewTreeObserver();
          if (currentViewTreeObserver.isAlive()) {
            currentViewTreeObserver.removeOnPreDrawListener(this);
          }
          return true;
        }
      };
  getViewTreeObserver().addOnPreDrawListener(onPreDrawListener);

  mOnPreDrawListener = onPreDrawListener;
}
 
Example 5
Source File: DeferredRequestCreator.java    From picasso with Apache License 2.0 6 votes vote down vote up
@Override public boolean onPreDraw() {
  ImageView target = this.target;

  ViewTreeObserver vto = target.getViewTreeObserver();
  if (!vto.isAlive()) {
    return true;
  }

  int width = target.getWidth();
  int height = target.getHeight();

  if (width <= 0 || height <= 0) {
    return true;
  }

  target.removeOnAttachStateChangeListener(this);
  vto.removeOnPreDrawListener(this);

  this.creator.unfit().resize(width, height).into(target, callback);
  return true;
}
 
Example 6
Source File: DeferredRequestCreator.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
void cancel() {
    callback = null;
    ImageView target = this.target.get();
    if (target == null) {
        return;
    }
    ViewTreeObserver vto = target.getViewTreeObserver();
    if (!vto.isAlive()) {
        return;
    }
    vto.removeOnPreDrawListener(this);
}
 
Example 7
Source File: DeferredRequestCreator.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
void cancel() {
    callback = null;
    ImageView target = this.target.get();
    if (target == null) {
        return;
    }
    ViewTreeObserver vto = target.getViewTreeObserver();
    if (!vto.isAlive()) {
        return;
    }
    vto.removeOnPreDrawListener(this);
}
 
Example 8
Source File: FloatingActionButtonImpl.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void onDetachedFromWindow() {
  ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
  if (preDrawListener != null) {
    viewTreeObserver.removeOnPreDrawListener(preDrawListener);
    preDrawListener = null;
  }
}
 
Example 9
Source File: CoordinatorLayout.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
@Override
public void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    resetTouchBehaviors();
    stopScrollBarsWaken();
    if (mNeedsPreDrawListener && mOnPreDrawListener != null) {
        final ViewTreeObserver vto = getViewTreeObserver();
        vto.removeOnPreDrawListener(mOnPreDrawListener);
    }
    if (mNestedScrollingTarget != null) {
        onStopNestedScroll(mNestedScrollingTarget);
    }
    mIsAttachedToWindow = false;
}
 
Example 10
Source File: CoordinatorLayout.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the pre-draw listener if we're attached to a window and mark that we currently
 * do not need it when attached.
 */
void removePreDrawListener() {
    if (mIsAttachedToWindow) {
        if (mOnPreDrawListener != null) {
            final ViewTreeObserver vto = getViewTreeObserver();
            vto.removeOnPreDrawListener(mOnPreDrawListener);
        }
    }
    mNeedsPreDrawListener = false;
}
 
Example 11
Source File: DeferredRequestCreator.java    From picasso with Apache License 2.0 5 votes vote down vote up
void cancel() {
  creator.clearTag();
  callback = null;

  target.removeOnAttachStateChangeListener(this);

  ViewTreeObserver vto = target.getViewTreeObserver();
  if (vto.isAlive()) {
    vto.removeOnPreDrawListener(this);
  }
}