Example usage for android.database Cursor getPosition

List of usage examples for android.database Cursor getPosition

Introduction

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

Prototype

int getPosition();

Source Link

Document

Returns the current position of the cursor in the row set.

Usage

From source file:Main.java

public static float getFloatFromCursor(Cursor cursor, String columnName) {
    float value = -1;
    if (cursor != null && cursor.getPosition() >= 0 && cursor.getPosition() < cursor.getCount()) {
        int columnIndex = cursor.getColumnIndex(columnName);
        if (columnIndex >= 0) {
            value = cursor.getFloat(columnIndex);
        }//from   w  ww .  ja  va2  s  .c om
    }
    return value;
}

From source file:Main.java

public static Map<String, Uri> getRingtones(Activity activity) {
    RingtoneManager manager = new RingtoneManager(activity);
    manager.setType(RingtoneManager.TYPE_RINGTONE);
    Cursor cursor = manager.getCursor();

    Map<String, Uri> list = new LinkedHashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());

        list.put(notificationTitle, notificationUri);
    }// w w w.j  a  va  2 s .  c om

    return list;
}

From source file:Main.java

private static int getType(Cursor cursor, int columnIndex) throws Exception {

    if (Build.VERSION.SDK_INT >= 11) {
        return cursor.getType(columnIndex);
    }/* www  .j a v  a 2s. c  o m*/

    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    int type = -1;
    if (cursorWindow.isNull(pos, columnIndex)) {
        type = Cursor.FIELD_TYPE_NULL;
    } else if (cursorWindow.isLong(pos, columnIndex)) {
        type = Cursor.FIELD_TYPE_INTEGER;
    } else if (cursorWindow.isFloat(pos, columnIndex)) {
        type = Cursor.FIELD_TYPE_FLOAT;
    } else if (cursorWindow.isString(pos, columnIndex)) {
        type = Cursor.FIELD_TYPE_STRING;
    } else if (cursorWindow.isBlob(pos, columnIndex)) {
        type = Cursor.FIELD_TYPE_BLOB;
    }

    return type;
}

From source file:net.sf.sprockets.database.Cursors.java

/**
 * Get all int values in the first column.
 *
 * @param close true to close the cursor or false to leave it open
 * @since 2.5.0/*  w ww . j a va2s. c  o  m*/
 */
public static int[] allInts(Cursor cursor, boolean close) {
    int[] i = EMPTY_INT_ARRAY;
    if (cursor.moveToFirst()) {
        i = new int[cursor.getCount()];
        do {
            i[cursor.getPosition()] = cursor.getInt(0);
        } while (cursor.moveToNext());
    }
    close(cursor, close);
    return i;
}

From source file:net.sf.sprockets.database.Cursors.java

/**
 * Get all long values in the first column.
 *
 * @param close true to close the cursor or false to leave it open
 *//*from   w ww. ja  v  a  2s  .  co  m*/
public static long[] allLongs(Cursor cursor, boolean close) {
    long[] l = EMPTY_LONG_ARRAY;
    if (cursor.moveToFirst()) {
        l = new long[cursor.getCount()];
        do {
            l[cursor.getPosition()] = cursor.getLong(0);
        } while (cursor.moveToNext());
    }
    close(cursor, close);
    return l;
}

From source file:net.sf.sprockets.database.Cursors.java

/**
 * Get all String values in the first column.
 *
 * @param close true to close the cursor or false to leave it open
 *//*  w  w w .  ja v a 2 s .  co  m*/
public static String[] allStrings(Cursor cursor, boolean close) {
    String[] s = EMPTY_STRING_ARRAY;
    if (cursor.moveToFirst()) {
        s = new String[cursor.getCount()];
        do {
            s[cursor.getPosition()] = cursor.getString(0);
        } while (cursor.moveToNext());
    }
    close(cursor, close);
    return s;
}

From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java

public static long getCurrentIndex(Cursor mCursor) {

    long dateUtc = -1;

    if (mCursor == null)
        return -1;

    if (mCursor.getCount() <= 0)
        return -1;

    final int initialPosition = mCursor.getPosition();

    int index = -1;

    for (int i = 0; i < mCursor.getCount(); i++) {
        mCursor.moveToPosition(i);/*w  ww  .  ja  v  a  2  s .  c  o m*/
        final long value = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
        if (System.currentTimeMillis() - value < 0) {
            index = i - 1;
            mCursor.moveToPosition(Math.max(0, index));
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }

        if ((i == 0) && (System.currentTimeMillis() - value < 0)) {

            mCursor.moveToPosition(0);
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }

        if (i == (mCursor.getCount() - 1)) {
            index = (mCursor.getCount() - 1);
            mCursor.moveToPosition(Math.max(0, index));
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }
    }

    if (initialPosition >= 0)
        mCursor.moveToPosition(initialPosition);
    return dateUtc;

}

From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java

public static long getTonightIndex(Cursor mCursor) {
    if (mCursor == null)
        return -1;

    if (mCursor.getCount() <= 0)
        return -1;

    long dateUtc = -1;

    final int initialPosition = mCursor.getPosition();

    mCursor.moveToPosition(0);//from   w ww .j a  v  a2  s . c  o  m

    final long initialValue = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));

    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(initialValue);
    calendar.set(Calendar.HOUR_OF_DAY, 19);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    for (int i = 0; i < mCursor.getCount(); i++) {
        mCursor.moveToPosition(i);
        final long value = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));

        if (calendar.getTime().getTime() - value < 0) {

            mCursor.moveToPosition(Math.max(0, i - 1));
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }
        if ((i == 0) && (calendar.getTime().getTime() - value < 0)) {

            mCursor.moveToPosition(0);
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }

        if (i == (mCursor.getCount() - 1)) {

            mCursor.moveToPosition(Math.max(0, mCursor.getCount() - 1));
            dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue));
            break;
        }
    }

    if (initialPosition >= 0)
        mCursor.moveToPosition(initialPosition);

    return dateUtc;
}

From source file:com.fede.Utilities.GeneralUtils.java

public static String[] getMissedCalls(Context context) {
    Long lastFlushed = PrefUtils.getLastFlushedCalls(context);
    java.text.DateFormat timeForm = android.text.format.DateFormat.getTimeFormat(context);

    Long yesterday = get24HoursAgoTime();

    if (lastFlushed == 0 || lastFlushed < yesterday) {
        lastFlushed = yesterday; // not later than 24 hours ago
    }//from   w  ww.j  a va  2s.c o m

    String where = android.provider.CallLog.Calls.TYPE + " = " + android.provider.CallLog.Calls.MISSED_TYPE
            + " and " + android.provider.CallLog.Calls.DATE + " > " + lastFlushed;

    Cursor c = context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, null, where, null,
            android.provider.CallLog.Calls.DATE + " DESC");

    int nameIdx = c.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME);
    int numbIdx = c.getColumnIndexOrThrow(CallLog.Calls.NUMBER);
    int dateIdx = c.getColumnIndexOrThrow(CallLog.Calls.DATE);

    String[] result = new String[c.getCount()];

    if (c.moveToFirst())
        do {
            String name = c.getString(nameIdx);
            name = (name != null) ? name : "";
            String number = c.getString(numbIdx);
            String when = timeForm.format(c.getLong(dateIdx));
            result[c.getPosition()] = String.format(context.getString(R.string.flushed_calls), name, number,
                    when);
        } while (c.moveToNext());
    c.close();

    PrefUtils.setLastFlushedCalls(context);
    return result;

}

From source file:io.pivotal.arca.adapters.SupportCursorAdapter.java

@Override
public void bindView(final View container, final Context context, final Cursor cursor) {
    final int type = getItemViewType(cursor.getPosition());
    mHelper.bindView(container, context, cursor, type);
}