Example usage for android.database Cursor isClosed

List of usage examples for android.database Cursor isClosed

Introduction

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

Prototype

boolean isClosed();

Source Link

Document

return true if the cursor is closed

Usage

From source file:fr.itinerennes.utils.IOUtils.java

/**
 * Closes an InputStream./*w w  w .j  a va  2  s.  co  m*/
 * <p>
 * Equivalent to {@link Cursor#close()} but accept null values.
 * 
 * @param cursor
 *            the {@link Cursor} to close, may be null or already closed
 */
public static void close(final Cursor cursor) {

    if (null != cursor && !cursor.isClosed()) {
        cursor.close();
    }
}

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

/**
 * True if the cursor position is between first and last (inclusive).
 *
 * @since 3.0.0/*from   w  ww.j a  v  a2s  .  c  o m*/
 */
public static boolean isActive(Cursor cursor) {
    return !cursor.isClosed() && !cursor.isBeforeFirst() && !cursor.isAfterLast();
}

From source file:Main.java

public static Map<String, Integer> getProvince(SQLiteDatabase db, String tableName) {
    Map<String, Integer> provinceMap = new LinkedHashMap<String, Integer>();
    Cursor cursor = db.query(tableName, new String[] { "DQX_DQXX01", "DQXX02" }, "DQXX03=?",
            new String[] { "1" }, null, null, "DQX_DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            provinceMap.put(cursor.getString(1), cursor.getInt(0));
        }/*from   w  ww .j a va  2 s.com*/
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return provinceMap;
}

From source file:Main.java

public static Map<String, Integer> getArea(SQLiteDatabase db, String tableName, int dqx_dqxx01) {
    Map<String, Integer> areaMap = new LinkedHashMap<String, Integer>();
    Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            areaMap.put(cursor.getString(0), cursor.getInt(1));
        }/*from  w w w.j av a2  s.  co  m*/
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return areaMap;
}

From source file:Main.java

/**
 * Gets a contact number and then displays the name of contact in the DP
 *
 * @param context       context of the activity from which it was called.
 * @param contactNumber a string representation of the contact number
 * @return returns the number if no contact exist.
 *///from w w w.  j  a v  a2  s .c  om
public static String getContactName(Context context, String contactNumber) {
    String displayName = null;
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(contactNumber));

    Cursor cur = context.getContentResolver().query(uri,
            new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);

    if (cur != null && cur.moveToFirst()) {
        displayName = cur.getString(cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
    } else {
        displayName = contactNumber;
    }

    if (!cur.isClosed()) {
        cur.close();
    }

    return displayName;
}

From source file:Main.java

public static Map<String, Integer> getCity(SQLiteDatabase db, String tableName, int dqx_dqxx01,
        boolean municipalities) {
    Map<String, Integer> cityMap = new LinkedHashMap<String, Integer>();
    Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        if (municipalities) {
            cursor.moveToNext();/*ww  w . java 2 s  . c  o m*/
        }
        while (cursor.moveToNext()) {
            cityMap.put(cursor.getString(0), cursor.getInt(1));
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return cityMap;
}

From source file:at.diamonddogs.util.Utils.java

/**
 * Checks a cursor for validity/*from  w ww  .j  a v  a  2  s .  co  m*/
 *
 * @param c the {@link Cursor} to check
 * @return <code>true</code> if the cursor is not <code>null</code>, not
 * closed and not empty, <code>false</code> otherwise
 */
public static boolean checkCursor(Cursor c) {
    if (c == null || c.isClosed()) {
        return false;
    }

    if (c.getCount() <= 0) {
        c.close();
        return false;
    }
    return true;
}

From source file:Main.java

private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String column = MediaStore.Images.Media.DATA;
    String[] projection = { column };
    try {//from   w w w.j av a  2  s.  co  m
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null && !cursor.isClosed())
            cursor.close();
    }
    return null;
}

From source file:Main.java

public static ArrayList<ContentValues> getProvince(SQLiteDatabase db) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;//from ww  w  . j a  va 2s.  co  m
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQXX03=?", new String[] { "1" },
            null, null, "DQX_DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("province_id", cursor.getInt(0));
            values.put("province", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:com.tonyodev.fetch.Utils.java

static RequestInfo createRequestInfo(Cursor cursor, boolean loggingEnabled) {

    if (cursor == null || cursor.isClosed() || cursor.getCount() < 1) {
        return null;
    }/*  w  w  w.jav a2  s  .c  o m*/

    long id = cursor.getLong(DatabaseHelper.INDEX_COLUMN_ID);
    int status = cursor.getInt(DatabaseHelper.INDEX_COLUMN_STATUS);
    String url = cursor.getString(DatabaseHelper.INDEX_COLUMN_URL);
    String filePath = cursor.getString(DatabaseHelper.INDEX_COLUMN_FILEPATH);
    int error = cursor.getInt(DatabaseHelper.INDEX_COLUMN_ERROR);
    long fileSize = cursor.getLong(DatabaseHelper.INDEX_COLUMN_FILE_SIZE);
    int priority = cursor.getInt(DatabaseHelper.INDEX_COLUMN_PRIORITY);
    long downloadedBytes = cursor.getLong(DatabaseHelper.INDEX_COLUMN_DOWNLOADED_BYTES);

    String headers = cursor.getString(DatabaseHelper.INDEX_COLUMN_HEADERS);
    List<Header> headersList = headerStringToList(headers, loggingEnabled);

    int progress = getProgress(downloadedBytes, fileSize);

    return new RequestInfo(id, status, url, filePath, progress, downloadedBytes, fileSize, error, headersList,
            priority);

}