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); } }
void clearCallbacksAndListener() { // 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; cbs.clear(); }
private void a() { if (b.isEmpty()) {} int i; int j; do { return; i = c(); j = b(); } while ((!a(i)) || (!a(j))); a(i, j); ViewTreeObserver localViewTreeObserver = a.getViewTreeObserver(); if (localViewTreeObserver.isAlive()) { localViewTreeObserver.removeOnPreDrawListener(c); } c = null; }
public void testRemoveOnPreDrawListener() { final LinearLayout layout = (LinearLayout) mActivity.findViewById(R.id.linearlayout); mViewTreeObserver = layout.getViewTreeObserver(); MockOnPreDrawListener listener = new MockOnPreDrawListener(); assertFalse(listener.hasCalledOnPreDraw()); mViewTreeObserver.addOnPreDrawListener(listener); mViewTreeObserver.dispatchOnPreDraw(); assertTrue(listener.hasCalledOnPreDraw()); listener.reset(); assertFalse(listener.hasCalledOnPreDraw()); mViewTreeObserver.removeOnPreDrawListener(listener); mViewTreeObserver.dispatchOnPreDraw(); assertFalse(listener.hasCalledOnPreDraw()); }
/** Stop receiving onPreDraw() notifications. */ private void unregisterPreDrawListener() { if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) { mViewTreeObserver.removeOnPreDrawListener(this); } mViewTreeObserver = null; }