Search in sources :

Example 1 with WXScrollViewListener

use of com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener in project weex-example by KalicyZhou.

the class WXScroller method initComponentHostView.

@Override
protected ViewGroup initComponentHostView(@NonNull Context context) {
    String scroll;
    if (getDomObject() == null || getDomObject().getAttrs().isEmpty()) {
        scroll = "vertical";
    } else {
        scroll = getDomObject().getAttrs().getScrollDirection();
    }
    ViewGroup host;
    if (("horizontal").equals(scroll)) {
        mOrientation = Constants.Orientation.HORIZONTAL;
        WXHorizontalScrollView scrollView = new WXHorizontalScrollView(context);
        mRealView = new FrameLayout(context);
        scrollView.setScrollViewListener(new WXHorizontalScrollView.ScrollViewListener() {

            @Override
            public void onScrollChanged(WXHorizontalScrollView scrollView, int x, int y, int oldx, int oldy) {
                procAppear(x, y, oldx, oldy);
            }
        });
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        scrollView.addView(mRealView, layoutParams);
        scrollView.setHorizontalScrollBarEnabled(false);
        host = scrollView;
    } else {
        mOrientation = Constants.Orientation.VERTICAL;
        BounceScrollerView scrollerView = new BounceScrollerView(context, mOrientation, this);
        mRealView = new FrameLayout(context);
        WXScrollView innerView = scrollerView.getInnerView();
        innerView.addScrollViewListener(this);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        innerView.addView(mRealView, layoutParams);
        innerView.setVerticalScrollBarEnabled(true);
        innerView.addScrollViewListener(new WXScrollViewListener() {

            @Override
            public void onScrollChanged(WXScrollView scrollView, int x, int y, int oldx, int oldy) {
            }

            @Override
            public void onScrollToBottom(WXScrollView scrollView, int x, int y) {
            }

            @Override
            public void onScrollStopped(WXScrollView scrollView, int x, int y) {
                List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
                if (listeners != null && listeners.size() > 0) {
                    for (OnWXScrollListener listener : listeners) {
                        if (listener != null) {
                            listener.onScrollStateChanged(scrollView, x, y, OnWXScrollListener.IDLE);
                        }
                    }
                }
            }

            @Override
            public void onScroll(WXScrollView scrollView, int x, int y) {
                List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
                if (listeners != null && listeners.size() > 0) {
                    for (OnWXScrollListener listener : listeners) {
                        if (listener != null) {
                            listener.onScrolled(scrollView, x, y);
                        }
                    }
                }
            }
        });
        host = scrollerView;
    }
    host.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            procAppear(0, 0, 0, 0);
            View view;
            if ((view = getHostView()) == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    return host;
}
Also used : LayoutParams(android.widget.FrameLayout.LayoutParams) ViewGroup(android.view.ViewGroup) WXHorizontalScrollView(com.taobao.weex.ui.view.WXHorizontalScrollView) OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) BounceScrollerView(com.taobao.weex.ui.view.refresh.wrapper.BounceScrollerView) View(android.view.View) WXScrollView(com.taobao.weex.ui.view.WXScrollView) WXHorizontalScrollView(com.taobao.weex.ui.view.WXHorizontalScrollView) BaseBounceView(com.taobao.weex.ui.view.refresh.wrapper.BaseBounceView) Point(android.graphics.Point) WXScrollView(com.taobao.weex.ui.view.WXScrollView) LayoutParams(android.widget.FrameLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) BounceScrollerView(com.taobao.weex.ui.view.refresh.wrapper.BounceScrollerView) ArrayList(java.util.ArrayList) List(java.util.List) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi) WXScrollViewListener(com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener)

Example 2 with WXScrollViewListener

use of com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener in project incubator-weex by apache.

the class WXScroller method initComponentHostView.

@Override
protected ViewGroup initComponentHostView(@NonNull Context context) {
    String scroll;
    if (getDomObject() == null || getDomObject().getAttrs().isEmpty()) {
        scroll = "vertical";
    } else {
        scroll = getDomObject().getAttrs().getScrollDirection();
    }
    ViewGroup host;
    if (("horizontal").equals(scroll)) {
        mOrientation = Constants.Orientation.HORIZONTAL;
        WXHorizontalScrollView scrollView = new WXHorizontalScrollView(context);
        mRealView = new FrameLayout(context);
        scrollView.setScrollViewListener(new WXHorizontalScrollView.ScrollViewListener() {

            @Override
            public void onScrollChanged(WXHorizontalScrollView scrollView, int x, int y, int oldx, int oldy) {
                procAppear(x, y, oldx, oldy);
            }
        });
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        scrollView.addView(mRealView, layoutParams);
        scrollView.setHorizontalScrollBarEnabled(false);
        host = scrollView;
    } else {
        mOrientation = Constants.Orientation.VERTICAL;
        BounceScrollerView scrollerView = new BounceScrollerView(context, mOrientation, this);
        mRealView = new FrameLayout(context);
        WXScrollView innerView = scrollerView.getInnerView();
        innerView.addScrollViewListener(this);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        innerView.addView(mRealView, layoutParams);
        innerView.setVerticalScrollBarEnabled(true);
        innerView.setNestedScrollingEnabled(WXUtils.getBoolean(getDomObject().getAttrs().get(Constants.Name.NEST_SCROLLING_ENABLED), true));
        innerView.addScrollViewListener(new WXScrollViewListener() {

            @Override
            public void onScrollChanged(WXScrollView scrollView, int x, int y, int oldx, int oldy) {
            }

            @Override
            public void onScrollToBottom(WXScrollView scrollView, int x, int y) {
            }

            @Override
            public void onScrollStopped(WXScrollView scrollView, int x, int y) {
                List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
                if (listeners != null && listeners.size() > 0) {
                    for (OnWXScrollListener listener : listeners) {
                        if (listener != null) {
                            listener.onScrollStateChanged(scrollView, x, y, OnWXScrollListener.IDLE);
                        }
                    }
                }
            }

            @Override
            public void onScroll(WXScrollView scrollView, int x, int y) {
                List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
                if (listeners != null && listeners.size() > 0) {
                    for (OnWXScrollListener listener : listeners) {
                        if (listener != null) {
                            if (listener instanceof ICheckBindingScroller) {
                                if (((ICheckBindingScroller) listener).isNeedScroller(getRef(), null)) {
                                    listener.onScrolled(scrollView, x, y);
                                }
                            } else {
                                listener.onScrolled(scrollView, x, y);
                            }
                        }
                    }
                }
            }
        });
        host = scrollerView;
    }
    host.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            procAppear(0, 0, 0, 0);
            View view;
            if ((view = getHostView()) == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    return host;
}
Also used : LayoutParams(android.widget.FrameLayout.LayoutParams) ViewGroup(android.view.ViewGroup) WXHorizontalScrollView(com.taobao.weex.ui.view.WXHorizontalScrollView) ICheckBindingScroller(com.taobao.weex.common.ICheckBindingScroller) OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) BounceScrollerView(com.taobao.weex.ui.view.refresh.wrapper.BounceScrollerView) View(android.view.View) WXScrollView(com.taobao.weex.ui.view.WXScrollView) WXHorizontalScrollView(com.taobao.weex.ui.view.WXHorizontalScrollView) BaseBounceView(com.taobao.weex.ui.view.refresh.wrapper.BaseBounceView) Point(android.graphics.Point) WXScrollView(com.taobao.weex.ui.view.WXScrollView) LayoutParams(android.widget.FrameLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) BounceScrollerView(com.taobao.weex.ui.view.refresh.wrapper.BounceScrollerView) ArrayList(java.util.ArrayList) List(java.util.List) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi) WXScrollViewListener(com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener)

Aggregations

TargetApi (android.annotation.TargetApi)2 Point (android.graphics.Point)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ViewTreeObserver (android.view.ViewTreeObserver)2 FrameLayout (android.widget.FrameLayout)2 LayoutParams (android.widget.FrameLayout.LayoutParams)2 OnWXScrollListener (com.taobao.weex.common.OnWXScrollListener)2 WXHorizontalScrollView (com.taobao.weex.ui.view.WXHorizontalScrollView)2 WXScrollView (com.taobao.weex.ui.view.WXScrollView)2 WXScrollViewListener (com.taobao.weex.ui.view.WXScrollView.WXScrollViewListener)2 BaseBounceView (com.taobao.weex.ui.view.refresh.wrapper.BaseBounceView)2 BounceScrollerView (com.taobao.weex.ui.view.refresh.wrapper.BounceScrollerView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ICheckBindingScroller (com.taobao.weex.common.ICheckBindingScroller)1