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

The following examples show how to use android.view.ViewTreeObserver#addOnScrollChangedListener() . 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: PopupWindow.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @hide */
protected void attachToAnchor(View anchor, int xoff, int yoff, int gravity) {
    detachFromAnchor();

    final ViewTreeObserver vto = anchor.getViewTreeObserver();
    if (vto != null) {
        vto.addOnScrollChangedListener(mOnScrollChangedListener);
    }
    anchor.addOnAttachStateChangeListener(mOnAnchorDetachedListener);

    final View anchorRoot = anchor.getRootView();
    anchorRoot.addOnAttachStateChangeListener(mOnAnchorRootDetachedListener);
    anchorRoot.addOnLayoutChangeListener(mOnLayoutChangeListener);

    mAnchor = new WeakReference<>(anchor);
    mAnchorRoot = new WeakReference<>(anchorRoot);
    mIsAnchorRootAttached = anchorRoot.isAttachedToWindow();
    mParentRootView = mAnchorRoot;

    mAnchorXoff = xoff;
    mAnchorYoff = yoff;
    mAnchoredGravity = gravity;
}
 
Example 2
Source File: PopupWindowCompat.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    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);
            }
        }
    }
}
 
Example 3
Source File: PopupWindowCompat.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    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);
            }
        }
    }
}
 
Example 4
Source File: PopupWindowCompat.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    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);
            }
        }
    }
}
 
Example 5
Source File: PopupWindowCompat.java    From zen4android with MIT License 6 votes vote down vote up
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    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);
            }
        }
    }
}
 
Example 6
Source File: ActionBarPopupWindow.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    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);
            }
        }
    }
}
 
Example 7
Source File: ActionBarPopupWindow.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 8
Source File: AdWebView.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
private void setupViewTreeObserver() {
    ViewTreeObserver treeObserver = getViewTreeObserver();
    if (treeObserver.isAlive()) {
        treeObserver.removeOnScrollChangedListener(this);
        treeObserver.removeGlobalOnLayoutListener(this);

        treeObserver.addOnScrollChangedListener(this);
        treeObserver.addOnGlobalLayoutListener(this);
    }
}
 
Example 9
Source File: ActionBarPopupWindow.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 10
Source File: ActionBarPopupWindow.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 11
Source File: PEWImageView.java    From ParallaxEverywhere with MIT License 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    mOnScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            applyParallax();
        }
    };

    mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            heightImageView = (float) getHeight();
            widthImageView = (float) getWidth();

            applyParallax();
        }
    };

    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    viewTreeObserver.addOnScrollChangedListener(mOnScrollChangedListener);
    viewTreeObserver.addOnGlobalLayoutListener(mOnGlobalLayoutListener);

    if (updateOnDraw
            && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        onDrawListener = new ViewTreeObserver.OnDrawListener() {
            @Override
            public void onDraw() {
                applyParallax();
            }
        };
        viewTreeObserver.addOnDrawListener(onDrawListener);
    }

    parallaxAnimation();
}
 
Example 12
Source File: PEWTextView.java    From ParallaxEverywhere with MIT License 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    mOnScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            applyParallax();
        }
    };

    mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            heightView = (float) getHeight();
            widthView = (float) getWidth();

            applyParallax();
        }
    };

    ViewTreeObserver viewTreeObserver = getViewTreeObserver();
    viewTreeObserver.addOnScrollChangedListener(mOnScrollChangedListener);
    viewTreeObserver.addOnGlobalLayoutListener(mOnGlobalLayoutListener);

    if (updateOnDraw
            && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        onDrawListener = new ViewTreeObserver.OnDrawListener() {
            @Override
            public void onDraw() {
                applyParallax();
            }
        };
        viewTreeObserver.addOnDrawListener(onDrawListener);
    }

    parallaxAnimation();
}
 
Example 13
Source File: AppActivityLifecycleCallbacks.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * 注册 ViewTreeObserver
 */
private void registerViewTreeObserver(Activity activity) {
    ViewTreeObserver viewTreeObserver = activity.getWindow().getDecorView().getViewTreeObserver();
    viewTreeObserver.addOnGlobalFocusChangeListener(AppViewTreeObserver.getInstance());
    viewTreeObserver.addOnGlobalLayoutListener(AppViewTreeObserver.getInstance());
    viewTreeObserver.addOnScrollChangedListener(AppViewTreeObserver.getInstance());
}
 
Example 14
Source File: ActionBarPopupWindow.java    From KrGallery with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 15
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 16
Source File: ActionBarPopupWindow.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 17
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 18
Source File: ReviewAndConfirmActivity.java    From px-android with MIT License 4 votes vote down vote up
private void addScrollListener(final View floatingConfirmLayout, final ViewGroup scrollView) {
    final ViewTreeObserver viewTreeObserver = scrollView.getViewTreeObserver();
    viewTreeObserver.addOnScrollChangedListener(
        () -> resolveFloatingButtonElevationVisibility(floatingConfirmLayout, scrollView));
}
 
Example 19
Source File: InterpolateOnScrollPositionChangeHelper.java    From material-components-android with Apache License 2.0 2 votes vote down vote up
/**
 * Start listening for scroll changes and interpolating based on position.
 *
 * @param viewTreeObserver {@link ViewTreeObserver belonging to the {@link View} being
 * interpolated.
 */
public void startListeningForScrollChanges(@NonNull ViewTreeObserver viewTreeObserver) {
  viewTreeObserver.addOnScrollChangedListener(scrollChangedListener);
}