Java Code Examples for android.widget.AdapterView.INVALID_POSITION

The following are Jave code examples for showing how to use INVALID_POSITION of the android.widget.AdapterView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: K9ListActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Shortcuts that work no matter what is selected
    if (QMail.useVolumeKeysForListNavigationEnabled() &&
            (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
            keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {

        final ListView listView = getListView();

        int currentPosition = listView.getSelectedItemPosition();
        if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
            currentPosition = listView.getFirstVisiblePosition();
        }

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && currentPosition > 0) {
            listView.setSelection(currentPosition - 1);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
                currentPosition < listView.getCount()) {
            listView.setSelection(currentPosition + 1);
        }

        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 2
Project: DailyTech   File: ArticleWidgetRemoteViewsFactory.java   View Source Code Vote up 6 votes
@Override
public RemoteViews getViewAt(int position) {
    if (position == AdapterView.INVALID_POSITION ||
            data == null || !data.moveToPosition(position)) {
        return null;
    }

    RemoteViews views = new RemoteViews(mContext.getPackageName(),
            R.layout.widget_detail_list_item);


    int articleTitleIndex = data.getColumnIndex(ArticleContract.ArticleEntry.COLUMN_ARTICLE_TITLE);
    String articleTitle = data.getString(articleTitleIndex);
    views.setTextViewText(R.id.news_widget_title, articleTitle);

    return views;
}
 
Example 3
Project: MyAnimeViewer   File: LibraryFragment.java   View Source Code Vote up 6 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putString(Constants.ANIME_PATH, mPath);
    if (!mPrevPath.empty()) {
        ArrayList<String> copy = new ArrayList<String>(mPrevPath);
        outState.putStringArrayList(Constants.ANIME_PREV_PATH_LIST, copy);
    }
    if (mAdapter != null)
        mAdapter.onSaveInstanceState(outState);

    if (mActivatedPosition != AdapterView.INVALID_POSITION) {
        //Serialize and persist the activated item position.
        outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
        Log.d(TAG, STATE_ACTIVATED_POSITION + "=" + mActivatedPosition);
    }
    super.onSaveInstanceState(outState);
}
 
Example 4
Project: MyAnimeViewer   File: AnimeCardGridFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    if (mActivatedPosition != AdapterView.INVALID_POSITION) {
        //Serialize and persist the activated item position.
        outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
    }
    super.onSaveInstanceState(outState);
}
 
Example 5
Project: q-mail   File: MessageListFragment.java   View Source Code Vote up 5 votes
private int adapterToListViewPosition(int position) {
    if (position >= 0 && position < adapter.getCount()) {
        return position;
    }

    return AdapterView.INVALID_POSITION;
}
 
Example 6
Project: gamesboard   File: ItemListAbstractFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(Bundle outState) {
	super.onSaveInstanceState(outState);
	if (activatedPosition != AdapterView.INVALID_POSITION) {
		// Serialize and persist the activated item position.
		outState.putInt(STATE_ACTIVATED_POSITION, activatedPosition);
	}
}
 
Example 7
Project: q-mail   File: MessageListFragment.java   View Source Code Vote up 5 votes
public void onMoveUp() {
    int currentPosition = listView.getSelectedItemPosition();
    if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
        currentPosition = listView.getFirstVisiblePosition();
    }
    if (currentPosition > 0) {
        listView.setSelection(currentPosition - 1);
    }
}
 
Example 8
Project: ht-recyclerviewadapter   File: BGASwipeItemLayout.java   View Source Code Vote up 5 votes
private void performAdapterViewItemClick() {
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(BGASwipeItemLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view.getAdapter().getItemId(p));
        }
    }
}
 
Example 9
Project: q-mail   File: MessageListFragment.java   View Source Code Vote up 5 votes
private int getPositionForUniqueId(long uniqueId) {
    for (int position = 0, end = adapter.getCount(); position < end; position++) {
        Cursor cursor = (Cursor) adapter.getItem(position);
        if (cursor.getLong(uniqueIdColumn) == uniqueId) {
            return position;
        }
    }

    return AdapterView.INVALID_POSITION;
}
 
Example 10
Project: q-mail   File: MessageListFragment.java   View Source Code Vote up 5 votes
private MessageReference getMessageAtPosition(int adapterPosition) {
    if (adapterPosition == AdapterView.INVALID_POSITION) {
        return null;
    }

    Cursor cursor = (Cursor) adapter.getItem(adapterPosition);

    String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
    String folderName = cursor.getString(FOLDER_NAME_COLUMN);
    String messageUid = cursor.getString(UID_COLUMN);

    return new MessageReference(accountUuid, folderName, messageUid, null);
}
 
Example 11
Project: GitHub   File: SwipeLayout.java   View Source Code Vote up 5 votes
private void performAdapterViewItemClick() {
    if (getOpenStatus() != Status.Close) return;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view
                    .getAdapter().getItemId(p));
        }
    }
}
 
Example 12
Project: MyAnimeViewer   File: OfflineHistoryMaterialFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    if (mActivatedPosition != AdapterView.INVALID_POSITION) {
        //Serialize and persist the activated item position.
        outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
    }
    super.onSaveInstanceState(outState);
}
 
Example 13
Project: MyAnimeViewer   File: HistoryMaterialFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    if (mActivatedPosition != AdapterView.INVALID_POSITION) {
        //Serialize and persist the activated item position.
        outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
    }
    super.onSaveInstanceState(outState);
}
 
Example 14
Project: MyAnimeViewer   File: ParseAnimeListFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(Bundle outState) {
    if (mActivatedPosition != AdapterView.INVALID_POSITION) {
        //Serialize and persist the activated item position.
        outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
    }
    super.onSaveInstanceState(outState);
}
 
Example 15
Project: Hitalk   File: SwipeItemLayout.java   View Source Code Vote up 5 votes
private void performAdapterViewItemClick() {
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeItemLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view.getAdapter().getItemId(p));
        }
    }
}
 
Example 16
Project: Hitalk   File: SwipeItemLayout.java   View Source Code Vote up 5 votes
private boolean performAdapterViewItemLongClick() {
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeItemLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeItemLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeItemLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
Example 17
Project: Views   File: SwipeLayout.java   View Source Code Vote up 5 votes
private void performAdapterViewItemClick() {
    if (getOpenStatus() != Status.Close) return;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view
                    .getAdapter().getItemId(p));
        }
    }
}
 
Example 18
Project: NoticeDog   File: DragSortController.java   View Source Code Vote up 5 votes
public int viewIdHitPosition(MotionEvent ev, int id) {
    final int x = (int) ev.getX();
    final int y = (int) ev.getY();

    int touchPos = mDslv.pointToPosition(x, y); // includes headers/footers

    final int numHeaders = mDslv.getHeaderViewsCount();
    final int numFooters = mDslv.getFooterViewsCount();
    final int count = mDslv.getCount();

    // Log.d("mobeta", "touch down on position " + itemnum);
    // We're only interested if the touch was on an
    // item that's not a header or footer.
    if (touchPos != AdapterView.INVALID_POSITION && touchPos >= numHeaders
            && touchPos < (count - numFooters)) {
        final View item = mDslv.getChildAt(touchPos - mDslv.getFirstVisiblePosition());
        final int rawX = (int) ev.getRawX();
        final int rawY = (int) ev.getRawY();

        View dragBox = id == 0 ? item : (View) item.findViewById(id);
        if (dragBox != null) {
            dragBox.getLocationOnScreen(mTempLoc);

            if (rawX > mTempLoc[0] && rawY > mTempLoc[1] &&
                    rawX < mTempLoc[0] + dragBox.getWidth() &&
                    rawY < mTempLoc[1] + dragBox.getHeight()) {

                mItemX = item.getLeft();
                mItemY = item.getTop();

                return touchPos;
            }
        }
    }

    return MISS;
}
 
Example 19
Project: GravityBox   File: TouchInterceptor.java   View Source Code Vote up 4 votes
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if ((mDragListener != null || mDropListener != null) && mDragView != null) {
        int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                Rect r = mTempRect;
                mDragView.getDrawingRect(r);
                stopDragging();
                if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
                    mDropListener.drop(mFirstDragPos, mDragPos);
                }
                unExpandViews(false);
                break;

            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
                int x = (int) ev.getX();
                int y = (int) ev.getY();
                dragView(x, y);
                int itemnum = getItemForPosition(y);
                if (itemnum >= 0) {
                    if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
                        if (mDragListener != null) {
                            mDragListener.drag(mDragPos, itemnum);
                        }
                        mDragPos = itemnum;
                        doExpansion();
                    }
                    int speed = 0;
                    adjustScrollBounds(y);
                    if (y > mLowerBound) {
                        // scroll the list up a bit
                        speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
                    } else if (y < mUpperBound) {
                        // scroll the list down a bit
                        speed = y < mUpperBound / 2 ? -16 : -4;
                    }
                    if (speed != 0) {
                        int ref = pointToPosition(0, mHeight / 2);
                        if (ref == AdapterView.INVALID_POSITION) {
                            // we hit a divider or an invisible view, check
                            // somewhere else
                            ref = pointToPosition(0, mHeight / 2 + getDividerHeight() + 64);
                        }
                        View v = getChildAt(ref - getFirstVisiblePosition());
                        if (v != null) {
                            int pos = v.getTop();
                            setSelectionFromTop(ref, pos - speed);
                        }
                    }
                }
                break;
        }
        return true;
    }
    return super.onTouchEvent(ev);
}
 
Example 20
Project: orgzly-android   File: GesturedListView.java   View Source Code Vote up 4 votes
@Override
public boolean onFling(MotionEvent ev1, MotionEvent ev2, float velocityX, float velocityY) {
    if (isItemToolbarActive) {
        if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "Quick-menu already active");
        return false;
    }

    /* Only if we never scrolled vertically. */
    if (scrolledHorizontally) {
        int horizontalFling = isHorizontalFling(velocityX, velocityY);

        if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "After scrolling horizontally: " + horizontalFling);

        if (horizontalFling != 0) {
            isItemToolbarActive = true;

            /* INVALID_POSITION can happen after swiping empty space below notes
             * (when there are only few on the top).
             */
            if (itemPosition != AdapterView.INVALID_POSITION) {
                Gesture gesture = horizontalFling == 1 ?
                        Gesture.FLING_RIGHT : Gesture.FLING_LEFT;

                boolean menuFound = itemMenus.open(itemPosition, gesture);

                /*
                 * If it's the last item in the list scroll to it to make quick-menu visible.
                 * Wait for quick-menu opening animation to end.
                 */
                if (menuFound && itemPosition == getCount() - 1) {
                    new Handler().postDelayed(() ->
                                    smoothScrollToPosition(itemPosition),
                            getResources().getInteger(R.integer.item_menu_animation_duration));
                }
            }

            return true;
        }

    } else {
        if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, "After not scrolling horizontally");
    }

    return false;
}