Example usage for android.view ViewTreeObserver removeOnDrawListener

List of usage examples for android.view ViewTreeObserver removeOnDrawListener

Introduction

In this page you can find the example usage for android.view ViewTreeObserver removeOnDrawListener.

Prototype

public void removeOnDrawListener(OnDrawListener victim) 

Source Link

Document

Remove a previously installed pre-draw callback.

Note: this method cannot be invoked from android.view.ViewTreeObserver.OnDrawListener#onDraw() .

Usage

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

public void onDestroy() {
    if (mChartController != null) {
        mChartController.removeChartDataLoadedCallback(this);
        if (mOnDrawListener != null) {
            final ViewTreeObserver observer = mChartController.getChartViewTreeObserver();
            if (observer != null) {
                observer.removeOnDrawListener(mOnDrawListener);
            }/*from   w  w  w .j a va2  s  .c o  m*/
            mOnDrawListener = null;
        }
        mOnLabelClickListener = null;
        mTimestampChangeListener = null;
        mOnSeekbarTouchListener = null;
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

public void refreshAfterChartLoad(final boolean backUpdateProgressBar) {
    if (!mChartController.hasDrawnChart()) {
        // Refresh the Run Review Overlay after the line graph presenter's chart
        // has finished drawing itself.
        final ViewTreeObserver observer = mChartController.getChartViewTreeObserver();
        if (observer == null) {
            return;
        }//from  www .  java  2s  . c o  m
        observer.removeOnDrawListener(mOnDrawListener);
        mOnDrawListener = new ViewTreeObserver.OnDrawListener() {
            @Override
            public void onDraw() {
                RunReviewOverlay.this.post(new Runnable() {
                    @Override
                    public void run() {
                        // 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(mOnDrawListener);
                        mOnDrawListener = null;
                        refresh(backUpdateProgressBar);
                    }
                });

            }
        };
        observer.addOnDrawListener(mOnDrawListener);
    } else {
        refresh(backUpdateProgressBar);
    }
}