removeOnDrawListener ( )源码实例Demo

android.view.ViewTreeObserver#removeOnDrawListener ( )源码实例Demo

下面列出了android.view.ViewTreeObserver#removeOnDrawListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: science-journal   文件: RunReviewOverlay.java
public void refreshAfterChartLoad(final boolean backUpdateProgressBar, final int numAttempts) {
  if (!chartController.hasDrawnChart()) {
    // Refresh the Run Review Overlay after the line graph presenter's chart
    // has finished drawing itself.
    final ViewTreeObserver observer = chartController.getChartViewTreeObserver();
    if (observer == null) {
      return;
    }
    observer.removeOnDrawListener(onDrawListener);
    onDrawListener =
        new ViewTreeObserver.OnDrawListener() {
          @Override
          public void onDraw() {
            RunReviewOverlay.this.post(
                new Runnable() {
                  @Override
                  public void run() {
                    if (!observer.isAlive()) {
                      if (numAttempts < MAX_REFRESH_ATTEMPTS) {
                        // Just try again, maybe it will come alive.
                        refreshAfterChartLoad(backUpdateProgressBar, numAttempts + 1);
                      }
                      return;
                    }
                    // The ViewTreeObserver calls its listeners without an iterator,
                    // so we need to remove the listener outside the flow or we risk
                    // an index-out-of-bounds crash in the case of multiple listeners.
                    observer.removeOnDrawListener(onDrawListener);
                    onDrawListener = null;
                    refresh(backUpdateProgressBar);
                  }
                });
          }
        };
    observer.addOnDrawListener(onDrawListener);
  } else {
    refresh(backUpdateProgressBar);
  }
}
 
源代码2 项目: science-journal   文件: RunReviewOverlay.java
public void onDestroy() {
  if (chartController != null) {
    chartController.removeChartDataLoadedCallback(this);
    if (onDrawListener != null) {
      final ViewTreeObserver observer = chartController.getChartViewTreeObserver();
      if (observer != null) {
        observer.removeOnDrawListener(onDrawListener);
      }
      onDrawListener = null;
    }
    onLabelClickListener = null;
    timestampChangeListener = null;
    onSeekbarTouchListener = null;
  }
}
 
源代码3 项目: ParallaxEverywhere   文件: PEWTextView.java
@Override
protected void onDetachedFromWindow() {
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    viewTreeObserver.removeOnScrollChangedListener(mOnScrollChangedListener);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        viewTreeObserver.removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
    } else {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    if (updateOnDraw
            && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        viewTreeObserver.removeOnDrawListener(onDrawListener);
    }
    super.onDetachedFromWindow();
}
 
源代码4 项目: ParallaxEverywhere   文件: PEWImageView.java
@Override
protected void onDetachedFromWindow() {
    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    viewTreeObserver.removeOnScrollChangedListener(mOnScrollChangedListener);
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        viewTreeObserver.removeOnGlobalLayoutListener(mOnGlobalLayoutListener);
    } else {
        viewTreeObserver.removeGlobalOnLayoutListener(mOnGlobalLayoutListener);
    }
    if (updateOnDraw
        && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            viewTreeObserver.removeOnDrawListener(onDrawListener);
    }
    super.onDetachedFromWindow();
}