Example usage for android.widget AdapterView INVALID_POSITION

List of usage examples for android.widget AdapterView INVALID_POSITION

Introduction

In this page you can find the example usage for android.widget AdapterView INVALID_POSITION.

Prototype

int INVALID_POSITION

To view the source code for android.widget AdapterView INVALID_POSITION.

Click Source Link

Document

Represents an invalid position.

Usage

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

private boolean handleCancelEvent() {
    if (mVelocityTracker == null || mCurrentView == null) {
        return false;
    }/* w  w  w  .jav a 2  s. c  o  m*/

    if (mCurrentPosition != AdapterView.INVALID_POSITION && mSwiping) {
        onCancelSwipe(mCurrentView, mCurrentPosition);
        restoreCurrentViewTranslation();
    }

    reset();
    return false;
}

From source file:com.game.sns.view.swipelist.SwipeListViewTouchListener.java

private void resetCell() {
    if (downPosition != AdapterView.INVALID_POSITION) {
        if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
            backView.setVisibility(View.VISIBLE);
        }//from  www  . j a v a2s  .  c om
        frontView.setClickable(opened.get(downPosition));
        frontView.setLongClickable(opened.get(downPosition));
        frontView = null;
        backView = null;
        downPosition = AdapterView.INVALID_POSITION;
    }
}

From source file:de.lespace.apprtc.activity.ConnectActivity.java

private String getSelectedItem() {
    int position = AdapterView.INVALID_POSITION;
    if (roomListView.getCheckedItemCount() > 0 && adapter.getCount() > 0) {
        position = roomListView.getCheckedItemPosition();
        if (position >= adapter.getCount()) {
            position = AdapterView.INVALID_POSITION;
        }//  w w  w. jav  a2s . c o m
    }
    if (position != AdapterView.INVALID_POSITION) {
        return (String) adapter.getItem(position);
    } else {
        return null;
    }
}

From source file:com.ardnezar.lookapp.ConnectActivity.java

private String getSelectedItem() {
    int position = AdapterView.INVALID_POSITION;
    if (roomListView.getCheckedItemCount() > 0 && adapter.getCount() > 0) {
        position = roomListView.getCheckedItemPosition();
        if (position >= adapter.getCount()) {
            position = AdapterView.INVALID_POSITION;
        }/*  ww w  .j  a  v a2  s .c  o m*/
    }
    if (position != AdapterView.INVALID_POSITION) {
        return adapter.getItem(position);
    } else {
        return null;
    }
}

From source file:com.game.sns.view.swipelist.SwipeListViewTouchListener.java

/**
 * Return ScrollListener for ListView//from  www .  ja  v a 2s  . c  o  m
 *
 * @return OnScrollListener
 */
public AbsListView.OnScrollListener makeScrollListener() {
    return new AbsListView.OnScrollListener() {

        private boolean isFirstItem = false;
        private boolean isLastItem = false;

        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            if (swipeClosesAllItemsWhenListMoves && scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                closeOpenedItems();
            }
            if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                listViewMoving = true;
                setEnabled(false);
            }
            if (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_FLING
                    && scrollState != SCROLL_STATE_TOUCH_SCROLL) {
                listViewMoving = false;
                downPosition = AdapterView.INVALID_POSITION;
                swipeListView.resetScrolling();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        setEnabled(true);
                    }
                }, 500);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (isFirstItem) {
                boolean onSecondItemList = firstVisibleItem == 1;
                if (onSecondItemList) {
                    isFirstItem = false;
                }
            } else {
                boolean onFirstItemList = firstVisibleItem == 0;
                if (onFirstItemList) {
                    isFirstItem = true;
                    swipeListView.onFirstListItem();
                }
            }
            if (isLastItem) {
                boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
                if (onBeforeLastItemList) {
                    isLastItem = false;
                }
            } else {
                boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
                if (onLastItemList) {
                    isLastItem = true;
                    swipeListView.onLastListItem();
                }
            }
        }
    };
}

From source file:com.money.manager.ex.search.SearchParametersFragment.java

private SearchParameters collectSearchCriteria() {
    if (getView() == null) {
        return getSearchParameters();
    }//  w w w  .ja  v a2  s  .  com

    SearchParameters searchParameters = getSearchParameters();

    // Account
    if (this.spinAccount != null) {
        int selectedAccountPosition = spinAccount.getSelectedItemPosition();
        if (selectedAccountPosition != AdapterView.INVALID_POSITION) {
            int selectedAccountId = mAccountIdList.get(selectedAccountPosition);
            if (selectedAccountId != Constants.NOT_SET) {
                searchParameters.accountId = selectedAccountId;
            }
        }
    }

    // Transaction Type
    searchParameters.deposit = viewHolder.cbxDeposit.isChecked();
    searchParameters.transfer = cbxTransfer.isChecked();
    searchParameters.withdrawal = cbxWithdrawal.isChecked();

    // Status
    if (spinStatus.getSelectedItemPosition() > 0) {
        searchParameters.status = mStatusValues.get(spinStatus.getSelectedItemPosition());
    }

    // Amount from
    Object tag = viewHolder.txtAmountFrom.getTag();
    if (tag != null) {
        searchParameters.amountFrom = MoneyFactory.fromString((String) tag);
    }
    // Amount to
    tag = viewHolder.txtAmountTo.getTag();
    if (tag != null) {
        searchParameters.amountTo = MoneyFactory.fromString((String) tag);
    }

    //        // Date from
    //        if (viewHolder.txtDateFrom.getTag() != null) {
    //            searchParameters.dateFrom = new MmxDate(viewHolder.txtDateFrom.getTag().toString()).toDate();
    //        }
    //        // Date to
    //        if (viewHolder.txtDateTo.getTag() != null) {
    //            String dateString = viewHolder.txtDateTo.getTag().toString();
    //            searchParameters.dateTo = new MmxDate(dateString).toDate();
    //        }
    // Payee
    if (viewHolder.txtSelectPayee.getTag() != null) {
        searchParameters.payeeId = Integer.parseInt(viewHolder.txtSelectPayee.getTag().toString());
        searchParameters.payeeName = viewHolder.txtSelectPayee.getText().toString();
    }
    // Category
    if (txtSelectCategory.getTag() != null) {
        searchParameters.category = (CategorySub) txtSelectCategory.getTag();
    }
    // Transaction number
    if (!TextUtils.isEmpty(viewHolder.txtTransNumber.getText())) {
        searchParameters.transactionNumber = viewHolder.txtTransNumber.getText().toString();
    }
    // Notes
    if (!TextUtils.isEmpty(txtNotes.getText())) {
        searchParameters.notes = txtNotes.getText().toString();
    }

    return searchParameters;
}

From source file:com.game.sns.view.swipelist.SwipeListViewTouchListener.java

/**
 * @see View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent)
 *//* ww w . j  av  a2s  .c  o m*/
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {

    if (!swipeListView.getIsEnable()) {
        return false;
    }

    if (!isSwipeEnabled()) {
        return false;
    }

    if (viewWidth < 2) {
        viewWidth = swipeListView.getWidth();
    }

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        if (paused && downPosition != AdapterView.INVALID_POSITION) {
            return false;
        }
        swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE;

        int childCount = swipeListView.getChildCount();
        int[] listViewCoords = new int[2];
        swipeListView.getLocationOnScreen(listViewCoords);
        int x = (int) motionEvent.getRawX() - listViewCoords[0];
        int y = (int) motionEvent.getRawY() - listViewCoords[1];
        View child;
        for (int i = 0; i < childCount; i++) {
            child = swipeListView.getChildAt(i);
            child.getHitRect(rect);

            int childPosition = swipeListView.getPositionForView(child);

            // dont allow swiping if this is on the header or footer or IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter
            boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition)
                    && swipeListView.getAdapter().getItemViewType(childPosition) >= 0;

            if (allowSwipe && rect.contains(x, y)) {
                setParentView(child);
                setFrontView(child.findViewById(swipeFrontView));

                downX = motionEvent.getRawX();
                downPosition = childPosition;

                frontView.setClickable(!opened.get(downPosition));
                frontView.setLongClickable(!opened.get(downPosition));

                velocityTracker = VelocityTracker.obtain();
                velocityTracker.addMovement(motionEvent);
                if (swipeBackView > 0) {
                    setBackView(child.findViewById(swipeBackView));
                }
                break;
            }
        }
        view.onTouchEvent(motionEvent);
        return true;
    }

    case MotionEvent.ACTION_UP: {
        if (velocityTracker == null || !swiping || downPosition == AdapterView.INVALID_POSITION) {
            break;
        }

        float deltaX = motionEvent.getRawX() - downX;
        velocityTracker.addMovement(motionEvent);
        velocityTracker.computeCurrentVelocity(1000);
        float velocityX = Math.abs(velocityTracker.getXVelocity());
        if (!opened.get(downPosition)) {
            if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) {
                velocityX = 0;
            }
            if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) {
                velocityX = 0;
            }
        }
        float velocityY = Math.abs(velocityTracker.getYVelocity());
        boolean swap = false;
        boolean swapRight = false;
        if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY * 2 < velocityX) {
            swapRight = velocityTracker.getXVelocity() > 0;
            Log.d("SwipeListView", "swapRight: " + swapRight + " - swipingRight: " + swipingRight);
            if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) {
                swap = false;
            } else if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) {
                swap = false;
            } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) {
                swap = false;
            } else {
                swap = true;
            }
        } else if (Math.abs(deltaX) > viewWidth / 2) {
            swap = true;
            swapRight = deltaX > 0;
        }
        generateAnimate(frontView, swap, swapRight, downPosition);
        if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
            swapChoiceState(downPosition);
        }

        velocityTracker.recycle();
        velocityTracker = null;
        downX = 0;
        // change clickable front view
        //                if (swap) {
        //                    frontView.setClickable(opened.get(downPosition));
        //                    frontView.setLongClickable(opened.get(downPosition));
        //                }
        swiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (velocityTracker == null || paused || downPosition == AdapterView.INVALID_POSITION) {
            break;
        }

        velocityTracker.addMovement(motionEvent);
        velocityTracker.computeCurrentVelocity(1000);
        float velocityX = Math.abs(velocityTracker.getXVelocity());
        float velocityY = Math.abs(velocityTracker.getYVelocity());

        float deltaX = motionEvent.getRawX() - downX;
        float deltaMode = Math.abs(deltaX);

        int swipeMode = this.swipeMode;
        int changeSwipeMode = swipeListView.changeSwipeMode(downPosition);
        if (changeSwipeMode >= 0) {
            swipeMode = changeSwipeMode;
        }

        if (swipeMode == SwipeListView.SWIPE_MODE_NONE) {
            deltaMode = 0;
        } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) {
            if (opened.get(downPosition)) {
                if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) {
                    deltaMode = 0;
                } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) {
                    deltaMode = 0;
                }
            } else {
                if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) {
                    deltaMode = 0;
                } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) {
                    deltaMode = 0;
                }
            }
        }
        if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE
                && velocityY < velocityX) {
            swiping = true;
            swipingRight = (deltaX > 0);
            Log.d("SwipeListView", "deltaX: " + deltaX + " - swipingRight: " + swipingRight);
            if (opened.get(downPosition)) {
                swipeListView.onStartClose(downPosition, swipingRight);
                swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL;
            } else {
                if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) {
                    swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS;
                } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) {
                    swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS;
                } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHOICE) {
                    swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE;
                } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) {
                    swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE;
                } else {
                    swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL;
                }
                swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight);
            }
            swipeListView.requestDisallowInterceptTouchEvent(true);
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            swipeListView.onTouchEvent(cancelEvent);
            if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
                backView.setVisibility(View.GONE);
            }
        }

        if (swiping && downPosition != AdapterView.INVALID_POSITION) {
            if (opened.get(downPosition)) {
                deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset;
            }
            move(deltaX);
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

/**
 * Resets the fields to the initial values, ready to start over.
 *//*from   w w w  . j  a  v a  2s.c  om*/
private void reset() {
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
    }

    mVelocityTracker = null;
    mDownX = 0;
    mDownY = 0;
    mCurrentView = null;
    mSwipingView = null;
    mLeftSwipingView = null;
    mRightSwipingView = null;
    mCurrentPosition = AdapterView.INVALID_POSITION;
    mSwiping = false;
    mCanDismissCurrent = false;
    //mflingToRight = false;
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Gets the selected item position if current view is an adapter view. Returns AdapterView.INVALID_POSITION if not
 * valid./*from   w w  w .  j  a  v  a 2 s . c  om*/
 * @return selected position
 */
public int getSelectedItemPosition() {
    int result = AdapterView.INVALID_POSITION;
    if (view instanceof AdapterView<?>) {
        result = ((AdapterView<?>) view).getSelectedItemPosition();
    }
    return result;
}

From source file:com.androidquery.AbstractAQuery.java

/**
 * Gets the selected item position if current view is an adapter view.
 *
 * Returns AdapterView.INVALID_POSITION if not valid.
 *
 * @return selected position/*ww  w  .  j  a v a  2 s. c om*/
 */
public int getSelectedItemPosition() {

    int result = AdapterView.INVALID_POSITION;

    if (view instanceof AdapterView<?>) {
        result = ((AdapterView<?>) view).getSelectedItemPosition();
    }

    return result;

}