Example usage for android.database Cursor getExtras

List of usage examples for android.database Cursor getExtras

Introduction

In this page you can find the example usage for android.database Cursor getExtras.

Prototype

Bundle getExtras();

Source Link

Document

Returns a bundle of extra values.

Usage

From source file:com.btmura.android.reddit.app.CommentListController.java

@Override
public void swapCursor(Cursor cursor) {
    adapter.swapCursor(cursor);
    cursorExtras = cursor != null ? cursor.getExtras() : null;
}

From source file:android.support.content.ContentPager.java

/**
 * @return true if the cursor extras contains all of the signs of being paged.
 *     Technically we could also check SDK version since facilities for paging
 *     were added in SDK 26, but if it looks like a duck and talks like a duck
 *     itsa duck (especially if it helps with testing).
 *///from  www.j  a v a2s  .co  m
@WorkerThread
private boolean isProviderPaged(Cursor cursor) {
    Bundle extras = cursor.getExtras();
    extras = extras != null ? extras : Bundle.EMPTY;
    String[] honoredArgs = extras.getStringArray(EXTRA_HONORED_ARGS);

    return (extras.containsKey(EXTRA_TOTAL_COUNT) && honoredArgs != null
            && contains(honoredArgs, QUERY_ARG_OFFSET) && contains(honoredArgs, QUERY_ARG_LIMIT));
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java

private void updateSpinnerState(Cursor cursor) {
    Bundle extras = cursor != null ? cursor.getExtras() : null;
    if (DBG) {/* w ww  .j  ava2  s  .  c  o m*/
        Log.d(LOG_TAG, "updateSpinnerState - extra = "
                + (extras != null ? extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS) : null));
    }
    // Check if the Cursor indicates that the query is not complete and show the spinner
    if (extras != null && extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)) {
        // mSearchView.getWindow().getDecorView().post(mStartSpinnerRunnable); // TODO:
        return;
    }
    // If cursor is null or is done, stop the spinner
    // mSearchView.getWindow().getDecorView().post(mStopSpinnerRunnable); // TODO:
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

private void updateSpinnerState(Cursor cursor) {
    Bundle extras = cursor != null ? cursor.getExtras() : null;
    if (DBG) {//from w w w .java 2s  .c  om
        Log.d(LOG_TAG, "updateSpinnerState - extra = "
                + (extras != null ? extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS) : null));
    }
    // Check if the Cursor indicates that the query is not complete and show the spinner
    if (extras != null && extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)) {
        return;
    }
    // If cursor is null or is done, stop the spinner
}

From source file:android.support.content.ContentPager.java

@WorkerThread
private @Nullable Cursor processProviderPagedCursor(Query query, Cursor cursor) {

    CursorWindow window = getWindow(cursor);
    int windowSize = cursor.getCount();
    if (window != null) {
        if (DEBUG)
            Log.d(TAG, "Returning provider-paged cursor.");
        windowSize = window.getNumRows();
    }/*from w  ww . j  a  v  a2  s  .com*/

    // Android O paging APIs are *all* about avoiding CursorWindow swaps,
    // because the swaps need to happen on the UI thread in jank-inducing ways.
    // But, the APIs don't *guarantee* that no window-swapping will happen
    // when traversing a cursor.
    //
    // Here in the support lib, we can guarantee there is no window swapping
    // by detecting mismatches between requested sizes and window sizes.
    // When a mismatch is detected we can return a cursor that reports
    // a size bounded by its CursorWindow size, and includes a suggested
    // size to use for subsequent queries.

    if (DEBUG)
        Log.d(TAG, "Cursor window overflow detected. Returning re-paged cursor.");

    int disposition = (cursor.getCount() <= windowSize) ? CURSOR_DISPOSITION_PAGED : CURSOR_DISPOSITION_REPAGED;

    Cursor result = new CursorView(cursor, windowSize, disposition);
    Bundle extras = result.getExtras();

    // If the orig cursor reports a size larger than the window, suggest a better limit.
    if (cursor.getCount() > windowSize) {
        extras.putInt(EXTRA_REQUESTED_LIMIT, query.getLimit());
        extras.putInt(EXTRA_SUGGESTED_LIMIT, (int) (windowSize * .85));
    }

    mStats.increment(Stats.EXTRA_PROVIDER_PAGED);
    mStats.includeStats(extras);
    return result;
}

From source file:com.android.contacts.list.ContactEntryListAdapter.java

/**
 * Updates the indexer, which is used to produce section headers.
 *//*from  w  w  w  . ja v a2 s.  com*/
//private void updateIndexer(Cursor cursor) {
public void updateIndexer(Cursor cursor) {
    if (cursor == null) {
        setIndexer(null);
        return;
    }

    Bundle bundle = cursor.getExtras();
    if (bundle.containsKey(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES)) {
        String sections[] = bundle.getStringArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES);
        int counts[] = bundle.getIntArray(ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS);
        setIndexer(new ContactsSectionIndexer(sections, counts));
    } else {
        setIndexer(null);
    }
}

From source file:com.silentcircle.contacts.list.ScContactEntryListAdapter.java

/**
 * Updates the indexer, which is used to produce section headers.
 *//*from  w  w  w .  j a v  a  2  s . c  om*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void updateIndexer(Cursor cursor) {
    if (cursor == null) {
        setIndexer(null);
        return;
    }
    Bundle bundle = cursor.getExtras();

    if (bundle == Bundle.EMPTY && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) // try the dirty trick
        bundle = mContext.getContentResolver().call(ScContactsContract.AUTHORITY_URI, "INDEX", null, null);

    if (bundle != null
            && bundle.containsKey(ScContactsContract.ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES)) {
        String sections[] = bundle
                .getStringArray(ScContactsContract.ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_TITLES);
        int counts[] = bundle.getIntArray(ScContactsContract.ContactCounts.EXTRA_ADDRESS_BOOK_INDEX_COUNTS);
        setIndexer(new ContactsSectionIndexer(sections, counts));
    } else {
        setIndexer(null);
    }
}

From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java

private void updateSpinnerState(Cursor cursor) {
    Bundle extras = cursor != null ? cursor.getExtras() : null;
    if (DBG) {/*from w ww. j a  v a  2s  .  c  o  m*/
        Log.d(LOG_TAG, "updateSpinnerState - extra = "
                + (extras != null ? extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS) : null));
    }
    // Check if the Cursor indicates that the query is not complete and show
    // the spinner
    if (extras != null && extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)) {
        // mSearchView.getWindow().getDecorView().post(mStartSpinnerRunnable);
        // // TODO:
        return;
    }
    // If cursor is null or is done, stop the spinner
    // mSearchView.getWindow().getDecorView().post(mStopSpinnerRunnable); //
    // TODO:
}

From source file:android.support.content.InMemoryCursor.java

/**
 * @param cursor source of data to copy. Ownership is reserved to the called, meaning
 *               we won't ever close it.
 *//*from   w  w w .j a  v  a2s.  c o  m*/
InMemoryCursor(Cursor cursor, int offset, int length, int disposition) {
    checkArgument(offset < cursor.getCount());

    // NOTE: The cursor could simply be saved to a field, but we choose to wrap
    // in a dedicated relay class to avoid hanging directly onto a reference
    // to the cursor...so future authors are not enticed to think there's
    // a live link between the delegate cursor and this cursor.
    mObserverRelay = new ObserverRelay(cursor);

    mColumnNames = cursor.getColumnNames();
    mRowCount = Math.min(length, cursor.getCount() - offset);
    int numColumns = cursor.getColumnCount();

    mExtras = ContentPager.buildExtras(cursor.getExtras(), cursor.getCount(), disposition);

    mColumnType = new int[numColumns];
    mTypedColumnIndex = new int[NUM_TYPES][numColumns];
    mColumnTypeCount = new int[NUM_TYPES];

    if (!cursor.moveToFirst()) {
        throw new RuntimeException("Can't position cursor to first row.");
    }

    for (int col = 0; col < numColumns; col++) {
        int type = cursor.getType(col);
        mColumnType[col] = type;
        mTypedColumnIndex[type][col] = mColumnTypeCount[type]++;
    }

    mLongs = new long[mRowCount * mColumnTypeCount[FIELD_TYPE_INTEGER]];
    mDoubles = new double[mRowCount * mColumnTypeCount[FIELD_TYPE_FLOAT]];
    mBlobs = new byte[mRowCount * mColumnTypeCount[FIELD_TYPE_BLOB]][];
    mStrings = new String[mRowCount * mColumnTypeCount[FIELD_TYPE_STRING]];

    for (int row = 0; row < mRowCount; row++) {
        if (!cursor.moveToPosition(offset + row)) {
            throw new RuntimeException("Unable to position cursor.");
        }

        // Now copy data from the row into primitive arrays.
        for (int col = 0; col < mColumnType.length; col++) {
            int type = mColumnType[col];
            int position = getCellPosition(row, col, type);

            switch (type) {
            case FIELD_TYPE_NULL:
                throw new UnsupportedOperationException("Not implemented.");
            case FIELD_TYPE_INTEGER:
                mLongs[position] = cursor.getLong(col);
                break;
            case FIELD_TYPE_FLOAT:
                mDoubles[position] = cursor.getDouble(col);
                break;
            case FIELD_TYPE_BLOB:
                mBlobs[position] = cursor.getBlob(col);
                break;
            case FIELD_TYPE_STRING:
                mStrings[position] = cursor.getString(col);
                break;
            }
        }
    }
}

From source file:android.support.content.ContentPager.java

@WorkerThread
@GuardedBy("mContentLock")
private Cursor createPagedCursor(Query query) {
    Cursor unpaged = mCursorCache.get(query.getUri());
    checkState(unpaged != null, "No un-paged cursor in cache, or can't retrieve it.");

    mStats.increment(Stats.EXTRA_COMPAT_PAGED);

    if (DEBUG)/*  www .j a va  2s  .  c o m*/
        Log.d(TAG, "Synthesizing cursor for page: " + query);
    int count = Math.min(query.getLimit(), unpaged.getCount());

    // don't wander off the end of the cursor.
    if (query.getOffset() + query.getLimit() > unpaged.getCount()) {
        count = unpaged.getCount() % query.getLimit();
    }

    if (DEBUG)
        Log.d(TAG, "Cursor count: " + count);

    Cursor result = null;
    // If the cursor isn't advertising support for paging, but is in-fact smaller
    // than the page size requested, we just decorate the cursor with paging data,
    // and wrap it without copy.
    if (query.getOffset() == 0 && unpaged.getCount() < query.getLimit()) {
        result = new CursorView(unpaged, unpaged.getCount(), CURSOR_DISPOSITION_WRAPPED);
    } else {
        // This creates an in-memory copy of the data that fits the requested page.
        // ContentObservers registered on InMemoryCursor are directly registered
        // on the unpaged cursor.
        result = new InMemoryCursor(unpaged, query.getOffset(), count, CURSOR_DISPOSITION_COPIED);
    }

    mStats.includeStats(result.getExtras());
    return result;
}