List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:de.escoand.readdaily.DownloadHandler.java
public static void stopDownload(final Context context, final String name) { Database db = Database.getInstance(context); Cursor c = db.getDownloads(); long id = 0;/*from w ww . jav a2s.c o m*/ // get download id while (c.moveToNext()) if (c.getString(c.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) { id = c.getLong(c.getColumnIndex(Database.COLUMN_ID)); break; } c.close(); if (id <= 0) return; // stop download ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).remove(id); db.removeDownload(id); }
From source file:Main.java
public static long uriFileSize(Context context, String contentUri) { long result = 0; Uri uri = Uri.parse(contentUri);/*from www . j a v a 2 s . co m*/ if (!uri.getScheme().equals("content")) { return (fileUriFileSize(context, contentUri)); } String[] p = { MediaStore.MediaColumns.SIZE }; Cursor cursor = context.getContentResolver().query(uri, p, // which columns null, // which rows (all rows) null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); if (cursor.moveToFirst()) { result = cursor.getLong(iColumn); } } return (result); }
From source file:Main.java
/** * Find a download with the specified name. Returns -1 if none was * found.//from w w w .j a va2s. c om */ static long findPath(DownloadManager dm, String path) { DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus( DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING); Cursor c = dm.query(query); if (!c.moveToFirst()) return -1; final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID); final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI); do { final String uri = c.getString(columnLocalURI); if (uri != null && uri.endsWith(path)) return c.getLong(columnID); } while (c.moveToNext()); return -1; }
From source file:Main.java
static Object getObject(Cursor cursor, int columnIndex) throws Exception { int type = getType(cursor, columnIndex); Object value;/*from w w w .j av a2s . co m*/ switch (type) { case Cursor.FIELD_TYPE_BLOB: value = cursor.getBlob(columnIndex); break; case Cursor.FIELD_TYPE_FLOAT: value = cursor.getFloat(columnIndex); break; case Cursor.FIELD_TYPE_INTEGER: value = cursor.getLong(columnIndex); break; case Cursor.FIELD_TYPE_NULL: value = null; break; case Cursor.FIELD_TYPE_STRING: value = cursor.getString(columnIndex); break; default: value = cursor.getString(columnIndex); } return value; }
From source file:Main.java
private static Object getCursorValue(Cursor cursor, Field field, String columnName) { Class<?> fieldType = field.getType(); if (fieldType.equals(int.class) || field.equals(Integer.class)) { return cursor.getInt(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(String.class)) { return cursor.getString(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(float.class) || field.equals(Float.class)) { return cursor.getFloat(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(double.class) || field.equals(Double.class)) { return cursor.getDouble(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(Date.class)) { long time = cursor.getLong(cursor.getColumnIndex(columnName)); Date date = new Date(time); return date; }// www. j av a 2 s . c o m return cursor.getString(cursor.getColumnIndex(columnName)); }
From source file:de.schildbach.wallet.data.ExchangeRatesProvider.java
public static ExchangeRate getExchangeRate(final Cursor cursor) { final String currencyCode = cursor .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE)); final Coin rateCoin = Coin .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN))); final Fiat rateFiat = Fiat.valueOf(currencyCode, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); return new ExchangeRate(new org.bitcoinj.utils.ExchangeRate(rateCoin, rateFiat), source); }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static long parseLong(final Cursor c, final String columnName) { return c.getLong(c.getColumnIndex(columnName)); }
From source file:com.alchemiasoft.common.model.Book.java
public static Book oneFrom(@NonNull Cursor c) { final Book book = new Book(); int index;/* ww w.ja va 2s .c o m*/ if ((index = c.getColumnIndex(BookDB.Book.SERVER_ID)) > -1) { book.mServerId = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book._ID)) > -1) { book.mId = c.getLong(index); } if ((index = c.getColumnIndex(BookDB.Book.TITLE)) > -1) { book.mTitle = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.AUTHOR)) > -1) { book.mAuthor = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.SOURCE)) > -1) { book.mSource = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.DESCRIPTION)) > -1) { book.mDescription = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.PAGES)) > -1) { book.mPages = c.getInt(index); } if ((index = c.getColumnIndex(BookDB.Book.NOTES)) > -1) { book.mNotes = c.getString(index); } if ((index = c.getColumnIndex(BookDB.Book.OWNED)) > -1) { book.mOwned = c.getInt(index) == 1 ? true : false; } if ((index = c.getColumnIndex(BookDB.Book.UPDATED_AT)) > -1) { book.mUpdatedAt = c.getLong(index); } return book; }
From source file:com.fanfou.app.opensource.api.ApiParser.java
public static Date parseDate(final Cursor c, final String columnName) { return new Date(c.getLong(c.getColumnIndex(columnName))); }
From source file:org.opendatakit.common.android.utilities.ODKCursorUtils.java
/** * Return the data stored in the cursor at the given index and given position * (ie the given row which the cursor is currently on) as null OR whatever * data type it is./*w w w . j av a 2s . c o m*/ * <p> * This does not actually convert data types from one type to the other. * Instead, it safely preserves null values and returns boxed data values. If * you specify ArrayList or HashMap, it JSON deserializes the value into one * of those. * * @param c * @param clazz * @param i * @return */ @SuppressWarnings("unchecked") public static final <T> T getIndexAsType(Cursor c, Class<T> clazz, int i) { // If you add additional return types here be sure to modify the javadoc. try { if (i == -1) return null; if (c.isNull(i)) { return null; } if (clazz == Long.class) { Long l = c.getLong(i); return (T) l; } else if (clazz == Integer.class) { Integer l = c.getInt(i); return (T) l; } else if (clazz == Double.class) { Double d = c.getDouble(i); return (T) d; } else if (clazz == String.class) { String str = c.getString(i); return (T) str; } else if (clazz == Boolean.class) { // stored as integers Integer l = c.getInt(i); return (T) Boolean.valueOf(l != 0); } else if (clazz == ArrayList.class) { // json deserialization of an array String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, ArrayList.class); } else if (clazz == HashMap.class) { // json deserialization of an object String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, HashMap.class); } else { throw new IllegalStateException("Unexpected data type in SQLite table"); } } catch (ClassCastException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " in SQLite table "); } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } }