Example usage for android.widget AbsListView requestDisallowInterceptTouchEvent

List of usage examples for android.widget AbsListView requestDisallowInterceptTouchEvent

Introduction

In this page you can find the example usage for android.widget AbsListView requestDisallowInterceptTouchEvent.

Prototype

@Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) 

Source Link

Usage

From source file:ti.modules.titanium.ui.widget.tableview.TiTableView.java

public TiTableView(TableViewProxy proxy) {
    super(proxy.getActivity());
    this.proxy = proxy;

    // Disable pull-down refresh support until a Titanium "RefreshControl" has been assigned.
    setSwipeRefreshEnabled(false);/*w  w w  .ja  va  2  s. c  o m*/

    if (proxy.getProperties().containsKey(TiC.PROPERTY_MAX_CLASSNAME)) {
        maxClassname = Math.max(TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_MAX_CLASSNAME)), maxClassname);
    }
    rowTypes = new HashMap<String, Integer>();
    rowTypeCounter = new AtomicInteger(-1);
    rowTypes.put(TableViewProxy.CLASSNAME_HEADER, rowTypeCounter.incrementAndGet());
    rowTypes.put(TableViewProxy.CLASSNAME_NORMAL, rowTypeCounter.incrementAndGet());
    rowTypes.put(TableViewProxy.CLASSNAME_DEFAULT, rowTypeCounter.incrementAndGet());

    this.viewModel = new TableViewModel(proxy);
    this.listView = new CustomListView(getContext());
    listView.setId(TI_TABLE_VIEW_ID);

    listView.setFocusable(true);
    listView.setFocusableInTouchMode(true);
    listView.setBackgroundColor(Color.TRANSPARENT);
    getInternalListView().setCacheColorHint(Color.TRANSPARENT);
    getInternalListView().setScrollingCacheEnabled(false);
    final KrollProxy fProxy = proxy;
    listView.setOnScrollListener(new OnScrollListener() {
        private boolean scrollValid = false;
        private int lastValidfirstItem = 0;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            view.requestDisallowInterceptTouchEvent(scrollState != ViewPager.SCROLL_STATE_IDLE);
            if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
                scrollValid = false;
                if (fProxy.hasListeners(TiC.EVENT_SCROLLEND)) {
                    KrollDict eventArgs = new KrollDict();
                    KrollDict size = new KrollDict();
                    size.put(TiC.PROPERTY_WIDTH, TiTableView.this.getWidth());
                    size.put(TiC.PROPERTY_HEIGHT, TiTableView.this.getHeight());
                    eventArgs.put(TiC.PROPERTY_SIZE, size);
                    fProxy.fireEvent(TiC.EVENT_SCROLLEND, eventArgs);
                }
            } else if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
                scrollValid = true;
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            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 (fireScroll) {
                lastValidfirstItem = firstVisibleItem;
                if (fProxy.hasListeners(TiC.EVENT_SCROLL)) {
                    KrollDict eventArgs = new KrollDict();
                    eventArgs.put("firstVisibleItem", firstVisibleItem);
                    eventArgs.put("visibleItemCount", visibleItemCount);
                    eventArgs.put("totalItemCount", totalItemCount);
                    KrollDict size = new KrollDict();
                    size.put(TiC.PROPERTY_WIDTH, TiTableView.this.getWidth());
                    size.put(TiC.PROPERTY_HEIGHT, TiTableView.this.getHeight());
                    eventArgs.put(TiC.PROPERTY_SIZE, size);
                    fProxy.fireEvent(TiC.EVENT_SCROLL, eventArgs);
                }
            }
        }
    });
    // get default divider height
    dividerHeight = listView.getDividerHeight();
    if (proxy.hasProperty(TiC.PROPERTY_SEPARATOR_COLOR)) {
        setSeparatorColor(TiConvert.toColor(proxy.getProperty(TiC.PROPERTY_SEPARATOR_COLOR)));
    }

    if (proxy.hasProperty(TiC.PROPERTY_SEPARATOR_STYLE)) {
        setSeparatorStyle(TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_SEPARATOR_STYLE),
                UIModule.TABLE_VIEW_SEPARATOR_STYLE_NONE));
    }
    adapter = new TTVListAdapter(viewModel, proxy);
    if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_HEADER_VIEW)) {
        TiViewProxy view = (TiViewProxy) proxy.getProperty(TiC.PROPERTY_HEADER_VIEW);
        listView.addHeaderView(layoutTableHeaderOrFooter(view), null, false);
    }
    if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_FOOTER_VIEW)) {
        TiViewProxy view = (TiViewProxy) proxy.getProperty(TiC.PROPERTY_FOOTER_VIEW);
        listView.addFooterView(layoutTableHeaderOrFooter(view), null, false);
    }

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (itemClickListener != null) {
                if (!(view instanceof TiBaseTableViewItem)) {
                    return;
                }
                rowClicked((TiBaseTableViewItem) view, position, false);
            }
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (itemLongClickListener == null) {
                return false;
            }
            TiBaseTableViewItem tvItem = null;
            if (view instanceof TiBaseTableViewItem) {
                tvItem = (TiBaseTableViewItem) view;
            } else {
                tvItem = getParentTableViewItem(view);
            }
            if (tvItem == null) {
                return false;
            }
            return rowClicked(tvItem, position, true);
        }
    });
    addView(listView);
}

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 w  w  w.ja  v  a  2s. c om
    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);
}