private void unregisterListener() {
   if (mSuperScrollListener != null && mViewTreeObserver != null) {
     if (mViewTreeObserver.isAlive()) {
       mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
     }
     mViewTreeObserver = null;
   }
 }
 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);
   }
 }
 private void registerListener(View anchor) {
   if (mSuperScrollListener != null) {
     ViewTreeObserver vto =
         (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
     if (vto != mViewTreeObserver) {
       if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
         mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
       }
       if ((mViewTreeObserver = vto) != null) {
         vto.addOnScrollChangedListener(mSuperScrollListener);
       }
     }
   }
 }
  public void testAccessOnScrollChangedListener() throws Throwable {
    layout(R.layout.scrollview_layout);
    final ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.scroll_view);

    mViewTreeObserver = scrollView.getViewTreeObserver();

    final MockOnScrollChangedListener listener = new MockOnScrollChangedListener();
    assertFalse(listener.hasCalledOnScrollChanged());
    mViewTreeObserver.addOnScrollChangedListener(listener);

    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_DOWN);
          }
        });
    mInstrumentation.waitForIdleSync();
    new PollingCheck() {
      @Override
      protected boolean check() {
        return listener.hasCalledOnScrollChanged();
      }
    }.run();

    listener.reset();
    assertFalse(listener.hasCalledOnScrollChanged());

    mViewTreeObserver.removeOnScrollChangedListener(listener);
    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_UP);
          }
        });
    assertFalse(listener.hasCalledOnScrollChanged());
  }
package com.actionbarsherlock.internal.widget;
Example #6
0
 protected void zzb(ViewTreeObserver viewtreeobserver) {
   viewtreeobserver.removeOnScrollChangedListener(this);
 }