Example usage for android.database CursorWindow getNumRows

List of usage examples for android.database CursorWindow getNumRows

Introduction

In this page you can find the example usage for android.database CursorWindow getNumRows.

Prototype

public int getNumRows() 

Source Link

Document

Gets the number of rows in this window.

Usage

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  w  w  .  j a  v a 2  s  . c o m*/

    // 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;
}