Example usage for android.database Cursor getFloat

List of usage examples for android.database Cursor getFloat

Introduction

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

Prototype

float getFloat(int columnIndex);

Source Link

Document

Returns the value of the requested column as a float.

Usage

From source file:Main.java

private static String dumpRow(Cursor c) {
    String result = "VALUES(";

    for (int pos = 0; pos < c.getColumnCount(); pos++) {
        switch (c.getType(pos)) {
        case Cursor.FIELD_TYPE_NULL:
            result += "null";
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            result += Integer.toString(c.getInt(pos));
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            result += Float.toString(c.getFloat(pos));
            break;
        case Cursor.FIELD_TYPE_STRING:
            result += DatabaseUtils.sqlEscapeString(c.getString(pos));
            break;
        case Cursor.FIELD_TYPE_BLOB:
            result += "X'";
            for (byte b : c.getBlob(pos)) {
                result += String.format("%02X", b);
            }//  ww w  . j  a v a  2s  . c  om
            result += "'";
            break;
        default:
            return "Invalid field type " + c.getType(pos) + " at position " + pos;
        }

        if (pos < c.getColumnCount() - 1) {
            result += ", ";
        }
    }
    return result + ")";
}

From source file:Main.java

public static Object cursorValue(String column, Cursor cr) {
    Object value = false;/*from w w  w  . ja  va2  s.com*/
    int index = cr.getColumnIndex(column);
    switch (cr.getType(index)) {
    case Cursor.FIELD_TYPE_NULL:
        value = false;
        break;
    case Cursor.FIELD_TYPE_STRING:
        value = cr.getString(index);
        break;
    case Cursor.FIELD_TYPE_INTEGER:
        value = cr.getInt(index);
        break;
    case Cursor.FIELD_TYPE_FLOAT:
        value = cr.getFloat(index);
        break;
    case Cursor.FIELD_TYPE_BLOB:
        value = cr.getBlob(index);
        break;
    }
    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;
    }/*from   w  ww .jav a 2s.  co  m*/
    return cursor.getString(cursor.getColumnIndex(columnName));
}

From source file:Main.java

public static String logCursor(String prefix, Cursor cr) {
    StringBuilder sb = new StringBuilder().append(prefix + ": ");
    for (int i = 0; i < cr.getColumnCount(); i++) {
        sb.append(cr.getColumnName(i)).append("=");
        switch (cr.getType(i)) {
        case Cursor.FIELD_TYPE_NULL:
            sb.append("NULL");
            break;
        case Cursor.FIELD_TYPE_STRING:
            sb.append("\"").append(cr.getString(i)).append("\"");
            break;
        case Cursor.FIELD_TYPE_INTEGER:
            sb.append(cr.getInt(i));// w w w.j  a  v  a 2s  .  c o m
            break;
        case Cursor.FIELD_TYPE_FLOAT:
            sb.append(cr.getFloat(i));
            break;
        case Cursor.FIELD_TYPE_BLOB:
            sb.append("BIN(").append(cr.getBlob(i).length).append("b)");
            break;
        }
        sb.append(" ");
    }
    return sb.toString();
}

From source file:fr.eoit.parameter.Parameters.java

private static void parseStationCursor(Cursor cursor) {
    while (!cursor.isAfterLast()) {
        int stationId = cursor.getInt(cursor.getColumnIndexOrThrow(Station._ID));
        int regionId = cursor.getInt(cursor.getColumnIndexOrThrow(Station.COLUMN_NAME_REGION_ID));
        int solarSystemId = cursor.getInt(cursor.getColumnIndexOrThrow(Station.COLUMN_NAME_SOLAR_SYSTEM_ID));
        int role = cursor.getInt(cursor.getColumnIndexOrThrow(Station.COLUMN_NAME_ROLE));
        String stationName = cursor.getString(cursor.getColumnIndexOrThrow(Station.COLUMN_NAME_NAME));
        float standing = cursor.getFloat(cursor.getColumnIndexOrThrow(Station.COLUMN_NAME_STANDING));

        switch (role) {
        case EOITConst.Stations.PRODUCTION_ROLE:
            Stations.initProdStation(regionId, solarSystemId, stationId, stationName, standing);
            break;
        case EOITConst.Stations.TRADE_ROLE:
            Stations.initTradeStation(regionId, solarSystemId, stationId, stationName, standing);
            break;
        case EOITConst.Stations.BOTH_ROLES:
            Stations.initProdStation(regionId, solarSystemId, stationId, stationName, standing);
            Stations.initTradeStation(regionId, solarSystemId, stationId, stationName, standing);
            break;

        default://w  w w  . j a  v  a  2 s  .co m
            break;
        }
        cursor.moveToNext();
    }
}

From source file:org.droidparts.inner.converter.FloatConverter.java

@Override
public <G1, G2> Float readFromCursor(Class<Float> valType, Class<G1> genericArg1, Class<G2> genericArg2,
        Cursor cursor, int columnIndex) {
    return cursor.getFloat(columnIndex);
}

From source file:de.escoand.readdaily.DownloadHandler.java

public static float downloadProgress(final Context context, final String name) {
    Cursor cursor = Database.getInstance(context).getDownloads();
    long id = 0;//from w  ww.ja  v  a  2 s .  co m
    float progress;

    // get download id
    while (cursor.moveToNext())
        if (cursor.getString(cursor.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) {
            id = cursor.getLong(cursor.getColumnIndex(Database.COLUMN_ID));
            break;
        }
    cursor.close();
    if (id <= 0)
        return SUBSCRIPTION_DOWNLOAD_UNKNOWN;

    // get download
    cursor = ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE))
            .query(new DownloadManager.Query().setFilterById(id));
    if (!cursor.moveToFirst()) {
        Database.getInstance(context).removeDownload(id);
        return DOWNLOAD_ID_UNKNOWN;
    }

    // get progress
    progress = cursor.getFloat(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
            / cursor.getFloat(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));

    cursor.close();
    return progress;
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a Float out of a column in a Cursor and writes it to a ContentValues.
 * Adds nothing to the ContentValues if the column isn't present or if its value is null.
 *
 * @param cursor The cursor to read from
 * @param column The column to read// ww w.j ava 2  s.  com
 * @param values The {@link ContentValues} to put the value into
 */
public static void cursorFloatToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) {
    final int index = cursor.getColumnIndexOrThrow(column);
    if (!cursor.isNull(index)) {
        values.put(column, cursor.getFloat(index));
    }
}

From source file:com.bydavy.card.receipts.ReceiptListAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final ReceiptListItemView receiptListItem = (ReceiptListItemView) view;

    receiptListItem.mReceiptId = cursor.getLong(mColumnId);
    receiptListItem.setShop(cursor.getString(mColumnShop));
    receiptListItem.setNote(cursor.getString(mColumnNote));
    receiptListItem.setTotal(cursor.getFloat(mColumnTotal));
    receiptListItem.setTimeStamp(cursor.getInt(mColumnDate));
    receiptListItem.setIsVerified(cursor.getInt(mColumnVerified) == 1);
    receiptListItem.setIsSelected(isSelected(receiptListItem.mReceiptId));
}

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private Object getValueFromCursor(Cursor cursor, int index, int columnType) {
    switch (columnType) {
    case Cursor.FIELD_TYPE_FLOAT:
        return cursor.getFloat(index);
    case Cursor.FIELD_TYPE_INTEGER:
        return cursor.getInt(index);
    case Cursor.FIELD_TYPE_BLOB:
        // convert byte[] to binary string; it's good enough, because
        // WebSQL doesn't support blobs anyway
        return new String(cursor.getBlob(index));
    case Cursor.FIELD_TYPE_STRING:
        return cursor.getString(index);
    }//from  w ww  .j a va2  s . c o  m
    return null;
}