Example usage for android.support.v4.view ViewPager SCROLL_STATE_IDLE

List of usage examples for android.support.v4.view ViewPager SCROLL_STATE_IDLE

Introduction

In this page you can find the example usage for android.support.v4.view ViewPager SCROLL_STATE_IDLE.

Prototype

int SCROLL_STATE_IDLE

To view the source code for android.support.v4.view ViewPager SCROLL_STATE_IDLE.

Click Source Link

Document

Indicates that the pager is in an idle, settled state.

Usage

From source file:com.viewpagerindicator.TitlePageIndicatorEx1.java

@Override
public void onPageSelected(int position) {
    Log.d("xx", "page select : " + position);
    if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position;//from  w  ww. j a v  a2  s. co  m
        invalidate();
    }

    mSelectedPage = position;

    if (mListener != null) {
        mListener.onPageSelected(position);
    }
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

@Override
public void onPageScrollStateChanged(final int state) {
    // If VP idle, reset to MIN_FRACTION
    if (state == ViewPager.SCROLL_STATE_IDLE) {
        mFraction = MIN_FRACTION;/*from w w  w.  ja v a2 s  .c  om*/
        mIsSetIndexFromTabBar = false;

        if (mOnPageChangeListener != null)
            mOnPageChangeListener.onPageSelected(mIndex);
        else {
            if (mOnTabStripSelectedIndexListener != null)
                mOnTabStripSelectedIndexListener.onEndTabSelected(mTitles[mIndex], mIndex);
        }
    }
    mScrollState = state;

    if (mOnPageChangeListener != null)
        mOnPageChangeListener.onPageScrollStateChanged(state);
}

From source file:info.guardianproject.pixelknot.PixelKnotActivity.java

@Override
public void onPageScrollStateChanged(int state) {
    if (state == ViewPager.SCROLL_STATE_IDLE) {
        h.post(new Runnable() {
            @Override//  www .j  a v a  2s .  co  m
            public void run() {
                int page = view_pager.getCurrentItem();
                for (int v = 0; v < progress_holder.getChildCount(); v++) {
                    View view = progress_holder.getChildAt(v);
                    if (view instanceof ImageView)
                        ((ImageView) view).setBackgroundResource(page == v ? d_ : d);
                }

                Fragment f = pk_pager.getItem(page);
                ((ActivityListener) f).initButtons();
                ((ActivityListener) f).updateUi();
            }
        });

    }

}

From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java

@Override
public void onPageScrollStateChanged(final int state) {
    // If VP idle, reset to MIN_FRACTION
    mScrollState = state;/*from ww  w.ja  v a  2s.c o  m*/
    if (state == ViewPager.SCROLL_STATE_IDLE) {
        if (mOnPageChangeListener != null)
            mOnPageChangeListener.onPageSelected(mIndex);
        if (mIsViewPagerMode && mOnTabStripSelectedIndexListener != null)
            mOnTabStripSelectedIndexListener.onEndTabSelected(mTitles[mIndex], mIndex);
    }

    if (mOnPageChangeListener != null)
        mOnPageChangeListener.onPageScrollStateChanged(state);
}

From source file:com.android.common.TitlePageIndicator.java

public void onPageSelected(int position) {
    if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position;//from   w  w  w .  jav  a 2s .co m
        invalidate();
    }

    if (mListener != null) {
        mListener.onPageSelected(position);
    }
}

From source file:team2.mainapp.TitlePageIndicator.java

@Override
public void onPageSelected(int position) {
    GlobalState gState = (GlobalState) ((Activity) this.getContext()).getApplication();
    gState.setPosition(position);/*from w  w w .  ja va 2  s  . c  o  m*/

    if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position;
        invalidate();
    }

    if (mListener != null) {
        mListener.onPageSelected(position);
    }
}

From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java

@Override
public void onPageScrollStateChanged(int state) {
    // Guard against image resizing (fling up/down effect) while the user is scrolling horizontally between images
    if (state == ViewPager.SCROLL_STATE_DRAGGING && !isViewPagerBeingDragged) {
        isViewPagerBeingDragged = true;//from   w  w  w . j  av a 2  s .  c o m
        imagePager.setOnTouchListener(null);
    }
    if ((state == ViewPager.SCROLL_STATE_SETTLING || state == ViewPager.SCROLL_STATE_IDLE)
            && isViewPagerBeingDragged) {
        isViewPagerBeingDragged = false;
        imagePager.setOnTouchListener(imageAreaTouchHandler);
    }
}

From source file:ti.modules.titanium.ui.widget.abslistview.TiAbsListView.java

public TiAbsListView(TiViewProxy proxy, Activity activity) {
    super(proxy);

    //initializing variables
    sections = Collections.synchronizedList(new ArrayList<AbsListSectionProxy>());
    itemTypeCount = new AtomicInteger(CUSTOM_TEMPLATE_ITEM_TYPE);
    templatesByBinding = new HashMap<String, TiAbsListViewTemplate>();
    defaultTemplateBinding = defaultTemplateKey;
    templatesByBinding.put(defaultTemplateKey, defaultTemplate);
    defaultTemplate.setType(BUILT_IN_TEMPLATE_ITEM_TYPE);
    caseInsensitive = true;/*from   ww  w . j a va2s  .  c o m*/
    ignoreExactMatch = false;

    //handling marker
    HashMap preloadMarker = ((AbsListViewProxy) proxy).getPreloadMarker();
    if (preloadMarker != null) {
        setMarker(preloadMarker);
    } else {
        resetMarker();
    }

    final KrollProxy fProxy = proxy;
    //initializing listView
    listView = createListView(activity);
    listView.setSelector(android.R.color.transparent);
    listView.setAreHeadersSticky(false);

    //      listView.setDuplicateParentStateEnabled(true);
    AbsListView internalListView = getInternalListView();
    if (TiC.LOLLIPOP_OR_GREATER) {
        listView.setNestedScrollingEnabled(true);
        internalListView.setNestedScrollingEnabled(true);
    }
    if (internalListView instanceof ListView) {
        ((ListView) internalListView).setHeaderDividersEnabled(false);
        ((ListView) internalListView).setFooterDividersEnabled(false);
    }

    if (listView instanceof CustomListView) {
        ((CustomListView) listView).setOnPullListener(new OnPullListener() {
            private boolean canUpdate = false;

            @Override
            public void onPull(boolean canUpdate) {
                if (canUpdate != this.canUpdate) {
                    this.canUpdate = canUpdate;
                    if (fProxy.hasListeners(TiC.EVENT_PULL_CHANGED, false)) {
                        KrollDict event = dictForScrollEvent();
                        event.put("active", canUpdate);
                        fProxy.fireEvent(TiC.EVENT_PULL_CHANGED, event, false, false);
                    }
                }
                if (fProxy.hasListeners(TiC.EVENT_PULL, false)) {
                    KrollDict event = dictForScrollEvent();
                    event.put("active", canUpdate);
                    fProxy.fireEvent(TiC.EVENT_PULL, event, false, false);
                }
            }

            @Override
            public void onPullEnd(boolean canUpdate) {
                if (fProxy.hasListeners(TiC.EVENT_PULL_END, false)) {
                    KrollDict event = dictForScrollEvent();
                    event.put("active", canUpdate);
                    fProxy.fireEvent(TiC.EVENT_PULL_END, event, false, false);
                }
            }
        });
    }

    adapter = new TiBaseAdapter(activity);
    listView.setOnScrollListener(new OnScrollListener() {
        private boolean scrollTouch = false;
        private int lastValidfirstItem = 0;
        private Timer endTimer = null;

        public void cancelEndCall() {
            if (endTimer != null) {
                endTimer.cancel();
                endTimer = null;
            }
        }

        public void delayEndCall() {
            cancelEndCall();
            endTimer = new Timer();

            TimerTask action = new TimerTask() {
                public void run() {
                    scrollTouch = false;
                    if (fProxy.hasListeners(TiC.EVENT_SCROLLEND, false)) {
                        fProxy.fireEvent(TiC.EVENT_SCROLLEND, dictForScrollEvent(), false, false);
                    }
                }

            };

            this.endTimer.schedule(action, 200);
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

            view.requestDisallowInterceptTouchEvent(scrollState != ViewPager.SCROLL_STATE_IDLE);
            if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
                if (scrollTouch) {
                    delayEndCall();
                }
            } else if (scrollState == OnScrollListener.SCROLL_STATE_FLING) {
                cancelEndCall();
            } else if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
                cancelEndCall();
                if (hideKeyboardOnScroll && hasFocus()) {
                    blur();
                }
                if (scrollTouch == false) {
                    scrollTouch = true;
                    if (fProxy.hasListeners(TiC.EVENT_SCROLLSTART, false)) {
                        fProxy.fireEvent(TiC.EVENT_SCROLLSTART, dictForScrollEvent(), false, false);
                    }
                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            //            Log.d(TAG, "onScroll : " + scrollValid, Log.DEBUG_MODE);
            //            boolean fireScroll = scrollValid;
            //            if (!fireScroll && visibleItemCount > 0) {
            //               //Items in a list can be selected with a track ball in which case
            //               //we must check to see if the first visibleItem has changed.
            //               fireScroll = (lastValidfirstItem != firstVisibleItem);
            //            }
            if (fProxy.hasListeners(TiC.EVENT_SCROLL, false)) {
                int newScrollOffset = getScroll();
                //                   Log.d(TAG, "newScrollOffset : " + newScrollOffset, Log.DEBUG_MODE);
                lastValidfirstItem = firstVisibleItem;
                if (newScrollOffset != currentScrollOffset) {
                    currentScrollOffset = newScrollOffset;
                    fProxy.fireEvent(TiC.EVENT_SCROLL, dictForScrollEvent(currentScrollOffset), false, false);
                }
            }
        }
    });

    listView.setOnStickyHeaderChangedListener(new OnStickyHeaderChangedListener() {

        @Override
        public void onStickyHeaderChanged(StickyListHeadersListViewAbstract l, View header, int itemPosition,
                long headerId) {
            //for us headerId is the section index
            int sectionIndex = (int) headerId;
            if (fProxy.hasListeners(TiC.EVENT_HEADER_CHANGE, false)) {
                KrollDict data = new KrollDict();
                AbsListSectionProxy section = null;
                synchronized (sections) {
                    if (sectionIndex >= 0 && sectionIndex < sections.size()) {
                        section = sections.get(sectionIndex);
                    } else {
                        return;
                    }
                }
                data.put(TiC.PROPERTY_HEADER_VIEW, section.getHoldedProxy(TiC.PROPERTY_HEADER_VIEW));
                data.put(TiC.PROPERTY_SECTION, section);
                data.put(TiC.PROPERTY_SECTION_INDEX, sectionIndex);
                fProxy.fireEvent(TiC.EVENT_HEADER_CHANGE, data, false, false);
            }
        }
    });

    internalListView.setCacheColorHint(Color.TRANSPARENT);
    listView.setEnabled(true);
    getLayoutParams().autoFillsHeight = true;
    getLayoutParams().autoFillsWidth = true;
    //      listView.setFocusable(false);
    listView.setFocusable(true);
    listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    //       try {
    // //         headerFooterId = TiRHelper.getApplicationResource("layout.titanium_ui_list_header_or_footer");
    // //         titleId = TiRHelper.getApplicationResource("id.titanium_ui_list_header_or_footer_title");
    //          isCheck = TiRHelper.getApplicationResource("drawable.btn_check_buttonless_on_64");
    //          hasChild = TiRHelper.getApplicationResource("drawable.btn_more_64");
    //          disclosure = TiRHelper.getApplicationResource("drawable.disclosure_64");
    //       } catch (ResourceNotFoundException e) {
    //          Log.e(TAG, "XML resources could not be found!!!", Log.DEBUG_MODE);
    //       }
    setNativeView(listView);
}

From source file:com.benefit.buy.library.viewpagerindicator.TitlePageIndicator.java

@Override
public void onPageSelected(int position) {
    if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position;/*from w w w.  j a va2 s.co  m*/
        invalidate();
    }
    if (mListener != null) {
        mListener.onPageSelected(position);
    }
}

From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java

@Override
public void onPageSelected(int position) {
    if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position;//from ww  w .  j  a  v  a  2  s .  c o m
        invalidate();
    }

    if (mListener != null) {
        mListener.onPageSelected(position);
    }
}