Java Code Examples for android.database.Cursor#getFloat()
The following examples show how to use
android.database.Cursor#getFloat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Progress.java From BaseProject with Apache License 2.0 | 6 votes |
public static Progress parseCursorToBean(Cursor cursor) { Progress progress = new Progress(); progress.tag = cursor.getString(cursor.getColumnIndex(Progress.TAG)); progress.url = cursor.getString(cursor.getColumnIndex(Progress.URL)); progress.folder = cursor.getString(cursor.getColumnIndex(Progress.FOLDER)); progress.filePath = cursor.getString(cursor.getColumnIndex(Progress.FILE_PATH)); progress.fileName = cursor.getString(cursor.getColumnIndex(Progress.FILE_NAME)); progress.fraction = cursor.getFloat(cursor.getColumnIndex(Progress.FRACTION)); progress.totalSize = cursor.getLong(cursor.getColumnIndex(Progress.TOTAL_SIZE)); progress.currentSize = cursor.getLong(cursor.getColumnIndex(Progress.CURRENT_SIZE)); progress.status = cursor.getInt(cursor.getColumnIndex(Progress.STATUS)); progress.priority = cursor.getInt(cursor.getColumnIndex(Progress.PRIORITY)); progress.date = cursor.getLong(cursor.getColumnIndex(Progress.DATE)); progress.request = (Request<?, ? extends Request>) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.REQUEST))); progress.extra1 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA1))); progress.extra2 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA2))); progress.extra3 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA3))); return progress; }
Example 2
Source File: OCursorListAdapter.java From framework with GNU Affero General Public License v3.0 | 6 votes |
private Object getValue(Cursor c, String column) { Object value = false; int index = c.getColumnIndex(column); switch (c.getType(index)) { case Cursor.FIELD_TYPE_NULL: value = false; break; case Cursor.FIELD_TYPE_BLOB: case Cursor.FIELD_TYPE_STRING: value = c.getString(index); break; case Cursor.FIELD_TYPE_FLOAT: value = c.getFloat(index); break; case Cursor.FIELD_TYPE_INTEGER: value = c.getInt(index); break; } return value; }
Example 3
Source File: PrimitiveMethodsFactoryMethodStorIOSQLiteGetResolver.java From storio with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override @NonNull public PrimitiveMethodsFactoryMethod mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) { boolean field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1; short field2 = cursor.getShort(cursor.getColumnIndex("field2")); int field3 = cursor.getInt(cursor.getColumnIndex("field3")); long field4 = cursor.getLong(cursor.getColumnIndex("field4")); float field5 = cursor.getFloat(cursor.getColumnIndex("field5")); double field6 = cursor.getDouble(cursor.getColumnIndex("field6")); String field7 = cursor.getString(cursor.getColumnIndex("field7")); byte[] field8 = cursor.getBlob(cursor.getColumnIndex("field8")); PrimitiveMethodsFactoryMethod object = PrimitiveMethodsFactoryMethod.create(field1, field2, field3, field4, field5, field6, field7, field8); return object; }
Example 4
Source File: DefaultDownloadIndex.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private static Download getDownloadForCurrentRow(Cursor cursor) { DownloadRequest request = new DownloadRequest( /* id= */ cursor.getString(COLUMN_INDEX_ID), /* type= */ cursor.getString(COLUMN_INDEX_TYPE), /* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)), /* streamKeys= */ decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)), /* customCacheKey= */ cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY), /* data= */ cursor.getBlob(COLUMN_INDEX_DATA)); DownloadProgress downloadProgress = new DownloadProgress(); downloadProgress.bytesDownloaded = cursor.getLong(COLUMN_INDEX_BYTES_DOWNLOADED); downloadProgress.percentDownloaded = cursor.getFloat(COLUMN_INDEX_PERCENT_DOWNLOADED); return new Download( request, /* state= */ cursor.getInt(COLUMN_INDEX_STATE), /* startTimeMs= */ cursor.getLong(COLUMN_INDEX_START_TIME_MS), /* updateTimeMs= */ cursor.getLong(COLUMN_INDEX_UPDATE_TIME_MS), /* contentLength= */ cursor.getLong(COLUMN_INDEX_CONTENT_LENGTH), /* stopReason= */ cursor.getInt(COLUMN_INDEX_STOP_REASON), /* failureReason= */ cursor.getInt(COLUMN_INDEX_FAILURE_REASON), downloadProgress); }
Example 5
Source File: RouteFragment.java From open with GNU General Public License v3.0 | 6 votes |
public float getAverageSpeed() { if (db == null) { return 0; } Cursor cursor = db. rawQuery("SELECT AVG(" + COLUMN_SPEED + ") as avg_speed " + "from (select " + COLUMN_SPEED + " from " + TABLE_LOCATIONS + " where " + COLUMN_ROUTE_ID + " = '" + routeId + "' ORDER BY time DESC LIMIT " + getNumberOfLocationsForAverageSpeed() + ")", null); cursor.moveToFirst(); return cursor.getFloat(0); }
Example 6
Source File: SqlUtils.java From EhViewer with Apache License 2.0 | 5 votes |
public static float getFloat(Cursor cursor, String column, float defValue) { try { int index = cursor.getColumnIndex(column); if (index != -1) { return cursor.getFloat(index); } } catch (Throwable e) { /* Ignore */ } return defValue; }
Example 7
Source File: BoxedTypesMethodsConstructorIgnoreNullStorIOContentResolverGetResolver.java From storio with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override @NonNull public BoxedTypesMethodsConstructorIgnoreNull mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) { Boolean field1 = null; if (!cursor.isNull(cursor.getColumnIndex("field1"))) { field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1; } Short field2 = null; if (!cursor.isNull(cursor.getColumnIndex("field2"))) { field2 = cursor.getShort(cursor.getColumnIndex("field2")); } Integer field3 = null; if (!cursor.isNull(cursor.getColumnIndex("field3"))) { field3 = cursor.getInt(cursor.getColumnIndex("field3")); } Long field4 = null; if (!cursor.isNull(cursor.getColumnIndex("field4"))) { field4 = cursor.getLong(cursor.getColumnIndex("field4")); } Float field5 = null; if (!cursor.isNull(cursor.getColumnIndex("field5"))) { field5 = cursor.getFloat(cursor.getColumnIndex("field5")); } Double field6 = null; if (!cursor.isNull(cursor.getColumnIndex("field6"))) { field6 = cursor.getDouble(cursor.getColumnIndex("field6")); } BoxedTypesMethodsConstructorIgnoreNull object = new BoxedTypesMethodsConstructorIgnoreNull(field1, field2, field3, field4, field5, field6); return object; }
Example 8
Source File: MediaUtils.java From BeMusic with Apache License 2.0 | 5 votes |
private static List<Song> getAudioList (Cursor cursor) { List<Song> audioList = null; if (cursor.getCount() > 0) { audioList = new ArrayList<Song>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { Bundle bundle = new Bundle (); for (int i = 0; i < AUDIO_KEYS.length; i++) { final String key = AUDIO_KEYS[i]; final int columnIndex = cursor.getColumnIndex(key); final int type = cursor.getType(columnIndex); switch (type) { case Cursor.FIELD_TYPE_BLOB: break; case Cursor.FIELD_TYPE_FLOAT: float floatValue = cursor.getFloat(columnIndex); bundle.putFloat(key, floatValue); break; case Cursor.FIELD_TYPE_INTEGER: int intValue = cursor.getInt(columnIndex); bundle.putInt(key, intValue); break; case Cursor.FIELD_TYPE_NULL: break; case Cursor.FIELD_TYPE_STRING: String strValue = cursor.getString(columnIndex); bundle.putString(key, strValue); break; } } Song audio = new Song(bundle); audioList.add(audio); } } cursor.close(); return audioList; }
Example 9
Source File: BoxedTypesPrivateFieldsIgnoreNullStorIOContentResolverGetResolver.java From storio with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override @NonNull public BoxedTypesPrivateFieldsIgnoreNull mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) { Boolean field1 = null; if (!cursor.isNull(cursor.getColumnIndex("field1"))) { field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1; } Short field2 = null; if (!cursor.isNull(cursor.getColumnIndex("field2"))) { field2 = cursor.getShort(cursor.getColumnIndex("field2")); } Integer field3 = null; if (!cursor.isNull(cursor.getColumnIndex("field3"))) { field3 = cursor.getInt(cursor.getColumnIndex("field3")); } Long field4 = null; if (!cursor.isNull(cursor.getColumnIndex("field4"))) { field4 = cursor.getLong(cursor.getColumnIndex("field4")); } Float field5 = null; if (!cursor.isNull(cursor.getColumnIndex("field5"))) { field5 = cursor.getFloat(cursor.getColumnIndex("field5")); } Double field6 = null; if (!cursor.isNull(cursor.getColumnIndex("field6"))) { field6 = cursor.getDouble(cursor.getColumnIndex("field6")); } BoxedTypesPrivateFieldsIgnoreNull object = new BoxedTypesPrivateFieldsIgnoreNull(field1, field2, field3, field4, field5, field6); return object; }
Example 10
Source File: FloatFieldAdapter.java From opentasks with Apache License 2.0 | 5 votes |
@Override public Float getFrom(Cursor cursor) { int columnIdx = cursor.getColumnIndex(mFieldName); if (columnIdx < 0) { throw new IllegalArgumentException("The column '" + mFieldName + "' is missing in cursor."); } return cursor.isNull(columnIdx) ? null : cursor.getFloat(columnIdx); }
Example 11
Source File: FloatFieldAdapter.java From opentasks-provider with Apache License 2.0 | 5 votes |
@Override public Float getFrom(Cursor cursor) { int columnIdx = cursor.getColumnIndex(mFieldName); if (columnIdx < 0) { throw new IllegalArgumentException("The column '" + mFieldName + "' is missing in cursor."); } return cursor.isNull(columnIdx) ? null : cursor.getFloat(columnIdx); }
Example 12
Source File: BoxedTypesFieldsIgnoreNullStorIOContentResolverGetResolver.java From storio with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override @NonNull public BoxedTypesFieldsIgnoreNull mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) { BoxedTypesFieldsIgnoreNull object = new BoxedTypesFieldsIgnoreNull(); if (!cursor.isNull(cursor.getColumnIndex("field1"))) { object.field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1; } if (!cursor.isNull(cursor.getColumnIndex("field2"))) { object.field2 = cursor.getShort(cursor.getColumnIndex("field2")); } if (!cursor.isNull(cursor.getColumnIndex("field3"))) { object.field3 = cursor.getInt(cursor.getColumnIndex("field3")); } if (!cursor.isNull(cursor.getColumnIndex("field4"))) { object.field4 = cursor.getLong(cursor.getColumnIndex("field4")); } if (!cursor.isNull(cursor.getColumnIndex("field5"))) { object.field5 = cursor.getFloat(cursor.getColumnIndex("field5")); } if (!cursor.isNull(cursor.getColumnIndex("field6"))) { object.field6 = cursor.getDouble(cursor.getColumnIndex("field6")); } return object; }
Example 13
Source File: BoxedTypesMethodsFactoryMethodStorIOSQLiteGetResolver.java From storio with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override @NonNull public BoxedTypesMethodsFactoryMethod mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) { Boolean field1 = null; if (!cursor.isNull(cursor.getColumnIndex("field1"))) { field1 = cursor.getInt(cursor.getColumnIndex("field1")) == 1; } Short field2 = null; if (!cursor.isNull(cursor.getColumnIndex("field2"))) { field2 = cursor.getShort(cursor.getColumnIndex("field2")); } Integer field3 = null; if (!cursor.isNull(cursor.getColumnIndex("field3"))) { field3 = cursor.getInt(cursor.getColumnIndex("field3")); } Long field4 = null; if (!cursor.isNull(cursor.getColumnIndex("field4"))) { field4 = cursor.getLong(cursor.getColumnIndex("field4")); } Float field5 = null; if (!cursor.isNull(cursor.getColumnIndex("field5"))) { field5 = cursor.getFloat(cursor.getColumnIndex("field5")); } Double field6 = null; if (!cursor.isNull(cursor.getColumnIndex("field6"))) { field6 = cursor.getDouble(cursor.getColumnIndex("field6")); } BoxedTypesMethodsFactoryMethod object = BoxedTypesMethodsFactoryMethod.create(field1, field2, field3, field4, field5, field6); return object; }
Example 14
Source File: Cursors.java From cathode with Apache License 2.0 | 4 votes |
public static float getFloat(Cursor cursor, String column) { return cursor.getFloat(cursor.getColumnIndexOrThrow(column)); }
Example 15
Source File: LocationsFileDbHelper.java From your-local-weather with GNU General Public License v3.0 | 4 votes |
public Location getLocationById(long id) { SQLiteDatabase db = getReadableDatabase(); String[] projection = { LocationsContract.Locations.COLUMN_NAME_ADDRESS, LocationsContract.Locations.COLUMN_NAME_ORDER_ID, LocationsContract.Locations.COLUMN_NAME_LONGITUDE, LocationsContract.Locations.COLUMN_NAME_LATITUDE, LocationsContract.Locations.COLUMN_NAME_LOCALE, LocationsContract.Locations.COLUMN_NAME_LOCATION_NICKNAME, LocationsContract.Locations.COLUMN_NAME_LOCATION_ACCURACY, LocationsContract.Locations.COLUMN_NAME_ENABLED, LocationsContract.Locations.COLUMN_NAME_LAST_UPDATE_TIME_IN_MS, LocationsContract.Locations.COLUMN_NAME_LOCATION_UPDATE_SOURCE, LocationsContract.Locations.COLUMN_NAME_ADDRESS_FOUND }; Cursor cursor = null; try { cursor = db.query( LocationsContract.Locations.TABLE_NAME, projection, LocationsContract.Locations._ID + "=" + id, null, null, null, null ); if (!cursor.moveToNext()) { return null; } byte[] cachedAddressBytes = cursor.getBlob( cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_ADDRESS)); Address address = null; if (cachedAddressBytes != null) { address = LocationsDbHelper.getAddressFromBytes(cachedAddressBytes); } int orderId = cursor.getInt(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_ORDER_ID)); double longitude = cursor.getDouble(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LONGITUDE)); double latitude = cursor.getDouble(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LATITUDE)); String locale = cursor.getString(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LOCALE)); String nickname = cursor.getString(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LOCATION_NICKNAME)); float accuracy = cursor.getFloat(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LOCATION_ACCURACY)); long locationUpdateTime = cursor.getLong(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LAST_UPDATE_TIME_IN_MS)); String locationSource = cursor.getString(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_LOCATION_UPDATE_SOURCE)); boolean addressFound = 1 == cursor.getInt(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_ADDRESS_FOUND)); boolean enabled = 1 == cursor.getInt(cursor.getColumnIndexOrThrow(LocationsContract.Locations.COLUMN_NAME_ENABLED)); if (locale == null) { locale = PreferenceUtil.getLanguage(context); } return new Location( id, orderId, nickname, locale, longitude, latitude, accuracy, locationSource, locationUpdateTime, addressFound, enabled, address); } finally { if (cursor != null) { cursor.close(); } } }
Example 16
Source File: FloatColumnConverter.java From android-open-project-demo with Apache License 2.0 | 4 votes |
@Override public Float getFieldValue(final Cursor cursor, int index) { return cursor.isNull(index) ? null : cursor.getFloat(index); }
Example 17
Source File: DatabaseHandler.java From GPSLogger with GNU General Public License v3.0 | 4 votes |
public List<LocationExtended> getPlacemarksList(long TrackID, long startNumber, long endNumber) { List<LocationExtended> placemarkList = new ArrayList<>(); String selectQuery = "SELECT * FROM " + TABLE_PLACEMARKS + " WHERE " + KEY_TRACK_ID + " = " + TrackID + " AND " + KEY_LOCATION_NUMBER + " BETWEEN " + startNumber + " AND " + endNumber + " ORDER BY " + KEY_LOCATION_NUMBER; //Log.w("myApp", "[#] DatabaseHandler.java - getLocationList(" + TrackID + ", " + startNumber + ", " +endNumber + ") ==> " + selectQuery); SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); double lcdata_double; float lcdata_float; if (cursor != null) { // looping through all rows and adding to list if (cursor.moveToFirst()) { do { Location lc = new Location("DB"); lc.setLatitude(cursor.getDouble(3)); lc.setLongitude(cursor.getDouble(4)); lcdata_double = cursor.getDouble(5); if (lcdata_double != NOT_AVAILABLE) lc.setAltitude(lcdata_double); //else lc.removeAltitude(); lcdata_float = cursor.getFloat(6); if (lcdata_float != NOT_AVAILABLE) lc.setSpeed(lcdata_float); //else lc.removeSpeed(); lcdata_float = cursor.getFloat(7); if (lcdata_float != NOT_AVAILABLE) lc.setAccuracy(lcdata_float); //else lc.removeAccuracy(); lcdata_float = cursor.getFloat(8); if (lcdata_float != NOT_AVAILABLE) lc.setBearing(lcdata_float); //else lc.removeBearing(); lc.setTime(cursor.getLong(9)); LocationExtended extdloc = new LocationExtended(lc); extdloc.setNumberOfSatellites(cursor.getInt(10)); extdloc.setNumberOfSatellitesUsedInFix(cursor.getInt(13)); extdloc.setDescription(cursor.getString(12)); placemarkList.add(extdloc); // Add Location to list } while (cursor.moveToNext()); } cursor.close(); } return placemarkList; }
Example 18
Source File: Storage.java From NoiseCapture with GNU General Public License v3.0 | 4 votes |
public LeqValue(Cursor cursor) { this(cursor.getInt(cursor.getColumnIndex(COLUMN_LEQ_ID)), cursor.getInt(cursor.getColumnIndex(COLUMN_FREQUENCY)), cursor.getFloat(cursor.getColumnIndex(COLUMN_SPL))); }
Example 19
Source File: FloatSerializer.java From sprinkles with Apache License 2.0 | 4 votes |
@Override public Float unpack(Cursor c, String name) { return c.getFloat(c.getColumnIndexOrThrow(name)); }
Example 20
Source File: SQLiteUtils.java From twitt4droid with Apache License 2.0 | 2 votes |
/** * Gets the float value of the given column. * * @param cursor a Cursor. * @param columnName the column name. * @return the column value if exists; otherwise {@code null}. */ static Float getFloat(Cursor cursor, String columnName) { return containsColumn(cursor, columnName) && !cursor.isNull(cursor.getColumnIndex(columnName)) ? cursor.getFloat(cursor.getColumnIndex(columnName)) : null; }