Example usage for android.widget ListAdapter getItemId

List of usage examples for android.widget ListAdapter getItemId

Introduction

In this page you can find the example usage for android.widget ListAdapter getItemId.

Prototype

long getItemId(int position);

Source Link

Document

Get the row id associated with the specified position in the list.

Usage

From source file:com.aliasapps.seq.scroller.TwoWayView.java

private int findSyncPosition() {
    int itemCount = mItemCount;

    if (itemCount == 0) {
        return INVALID_POSITION;
    }//ww  w.j av a 2  s . co  m

    final long idToMatch = mSyncRowId;

    // If there isn't a selection don't hunt for it
    if (idToMatch == INVALID_ROW_ID) {
        return INVALID_POSITION;
    }

    // Pin seed to reasonable values
    int seed = mSyncPosition;
    seed = Math.max(0, seed);
    seed = Math.min(itemCount - 1, seed);

    long endTime = SystemClock.uptimeMillis() + SYNC_MAX_DURATION_MILLIS;

    long rowId;

    // first position scanned so far
    int first = seed;

    // last position scanned so far
    int last = seed;

    // True if we should move down on the next iteration
    boolean next = false;

    // True when we have looked at the first item in the data
    boolean hitFirst;

    // True when we have looked at the last item in the data
    boolean hitLast;

    // Get the item ID locally (instead of getItemIdAtPosition), so
    // we need the adapter
    final ListAdapter adapter = mAdapter;
    if (adapter == null) {
        return INVALID_POSITION;
    }

    while (SystemClock.uptimeMillis() <= endTime) {
        rowId = adapter.getItemId(seed);
        if (rowId == idToMatch) {
            // Found it!
            return seed;
        }

        hitLast = (last == itemCount - 1);
        hitFirst = (first == 0);

        if (hitLast && hitFirst) {
            // Looked at everything
            break;
        }

        if (hitFirst || (next && !hitLast)) {
            // Either we hit the top, or we are trying to move down
            last++;
            seed = last;

            // Try going up next time
            next = false;
        } else if (hitLast || (!next && !hitFirst)) {
            // Either we hit the bottom, or we are trying to move up
            first--;
            seed = first;

            // Try going down next time
            next = true;
        }
    }

    return INVALID_POSITION;
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

private void rememberSyncState() {
    if (getChildCount() == 0) {
        return;/*w w w  .j av  a2s.c  o  m*/
    }

    mNeedSync = true;

    if (mSelectedPosition >= 0) {
        View child = getChildAt(mSelectedPosition - mFirstPosition);

        mSyncRowId = mNextSelectedRowId;
        mSyncPosition = mNextSelectedPosition;

        if (child != null) {
            mSpecificStart = (mIsVertical ? child.getTop() : child.getLeft());
        }

        mSyncMode = SYNC_SELECTED_POSITION;
    } else {
        // Sync the based on the offset of the first view
        View child = getChildAt(0);
        ListAdapter adapter = getAdapter();

        if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
            mSyncRowId = adapter.getItemId(mFirstPosition);
        } else {
            mSyncRowId = NO_ID;
        }

        mSyncPosition = mFirstPosition;

        if (child != null) {
            mSpecificStart = child.getTop();
        }

        mSyncMode = SYNC_FIRST_POSITION;
    }
}

From source file:com.artifex.mupdflib.TwoWayView.java

private void rememberSyncState() {
    if (getChildCount() == 0) {
        return;//w  ww . j  a v  a 2  s  .  c o m
    }

    mNeedSync = true;

    if (mSelectedPosition >= 0) {
        View child = getChildAt(mSelectedPosition - mFirstPosition);

        mSyncRowId = mNextSelectedRowId;
        mSyncPosition = mNextSelectedPosition;

        if (child != null) {
            mSpecificStart = getChildStartEdge(child);
        }

        mSyncMode = SYNC_SELECTED_POSITION;
    } else {
        // Sync the based on the offset of the first view
        View child = getChildAt(0);
        ListAdapter adapter = getAdapter();

        if (mFirstPosition >= 0 && mFirstPosition < adapter.getCount()) {
            mSyncRowId = adapter.getItemId(mFirstPosition);
        } else {
            mSyncRowId = NO_ID;
        }

        mSyncPosition = mFirstPosition;

        if (child != null) {
            mSpecificStart = getChildStartEdge(child);
        }

        mSyncMode = SYNC_FIRST_POSITION;
    }
}