Example usage for android.database Cursor getDouble

List of usage examples for android.database Cursor getDouble

Introduction

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

Prototype

double getDouble(int columnIndex);

Source Link

Document

Returns the value of the requested column as a double.

Usage

From source file:org.glom.app.SqlUtils.java

/**
 * @param dataItem//from   w ww  .  j ava  2 s  .c o m
 * @param field
 * @param rsIndex         The column index, 0-based.
 * @param cursor
 * @param primaryKeyValue
 * @throws SQLException
 */
public static void fillDataItemFromResultSet(final DataItem dataItem, final LayoutItemField field,
        final int rsIndex, final Cursor cursor, final String documentID, final String tableName,
        final TypedDataItem primaryKeyValue) {

    switch (field.getGlomType()) {
    case TYPE_TEXT:
        final String text = cursor.getString(rsIndex);
        dataItem.setText(text != null ? text : "");
        break;
    case TYPE_BOOLEAN:
        dataItem.setBoolean(cursor.getInt(rsIndex) > 0);
        break;
    case TYPE_NUMERIC:
        dataItem.setNumber(cursor.getDouble(rsIndex));
        break;
    case TYPE_DATE:
        /* TODO:
        final Date date = cursor.getDate(rsIndex);
        if (date != null) {
        // TODO: Pass Date and Time types instead of converting to text here?
        // TODO: Use a 4-digit-year short form, somehow.
        final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT);
        dataItem.setText(dateFormat.format(date));
        } else {
        dataItem.setText("");
        }
        */
        break;
    case TYPE_TIME:
        /* TODO:
        final Time time = cursor.getTime(rsIndex);
        if (time != null) {
        final DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.ROOT);
        dataItem.setText(timeFormat.format(time));
        } else {
        dataItem.setText("");
        }
        */
        break;
    case TYPE_IMAGE:
        //We don't get the data here.
        //Instead we provide a way for the client to get the image separately.

        //This doesn't seem to work,
        //presumably because the base64 encoding is wrong:
        //final byte[] imageByteArray = rs.getBytes(rsIndex);
        //if (imageByteArray != null) {
        //   String base64 = org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(imageByteArray);
        //   base64 = "data:image/png;base64," + base64;

        //TODO: final String url = Utils.buildImageDataUrl(primaryKeyValue, documentID, tableName, field);
        //TODO: dataItem.setImageDataUrl(url);
        break;
    case TYPE_INVALID:
    default:
        Log.warn(documentID, tableName, "Invalid LayoutItem Field type. Using empty string for value.");
        dataItem.setText("");
        break;
    }
}

From source file:com.taobao.weex.devtools.inspector.protocol.module.Database.java

/**
 * Flatten all columns and all rows of a cursor to a single array.  The array cannot be
 * interpreted meaningfully without the number of columns.
 *
 * @param cursor// w  w  w .j  av  a2  s .c o  m
 * @param limit Maximum number of rows to process.
 * @return List of Java primitives matching the value type of each column, converted to
 *      strings.
 */
private static ArrayList<String> flattenRows(Cursor cursor, int limit) {
    Util.throwIfNot(limit >= 0);
    ArrayList<String> flatList = new ArrayList<>();
    final int numColumns = cursor.getColumnCount();
    for (int row = 0; row < limit && cursor.moveToNext(); row++) {
        for (int column = 0; column < numColumns; column++) {
            switch (cursor.getType(column)) {
            case Cursor.FIELD_TYPE_NULL:
                flatList.add(null);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                flatList.add(String.valueOf(cursor.getLong(column)));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                flatList.add(String.valueOf(cursor.getDouble(column)));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                flatList.add(blobToString(cursor.getBlob(column)));
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                flatList.add(cursor.getString(column));
                break;
            }
        }
    }
    if (!cursor.isAfterLast()) {
        for (int column = 0; column < numColumns; column++) {
            flatList.add("{truncated}");
        }
    }
    return flatList;
}

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

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

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

/**
 * Helper method that converts the cursor to a destination object.
 *//*from  www. j a v a  2s .  c o  m*/
static Destination getCursorDestination(Cursor mCursor) {

    Destination d = new Destination();

    d.id = mCursor.getInt(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ID));
    d.identifier = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_IDENTIFIER));

    d.city = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_CITY));
    d.region = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_REGION));
    d.country = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_COUNTRY));

    d.arrival = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ARRIVAL));
    d.departure = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_DEPARTURE));

    double lat = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LAT));
    double lng = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LNG));
    d.position = new LatLng(lat, lng);

    d.presentsDelivered = mCursor
            .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTSDELIVERED));
    d.presentsDeliveredAtDestination = mCursor
            .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTS_DESTINATION));

    d.timezone = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_TIMEZONE));
    d.altitude = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ALTITUDE));
    d.photoString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PHOTOS));
    d.weatherString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_WEATHER));
    d.streetViewString = mCursor
            .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_STREETVIEW));

    d.gmmStreetViewString = mCursor
            .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_GMMSTREETVIEW));

    // Process the panoramio string if possible
    d.photos = processPhoto(d.photoString);
    d.weather = processWeather(d.weatherString);
    d.streetView = processStreetView(d.streetViewString);
    d.gmmStreetView = processStreetView(d.gmmStreetViewString);

    return d;
}

From source file:li.barter.utils.Utils.java

/**
 * Converts a cursor to a bundle. Field datatypes will be maintained. Floats will be stored in
 * the Bundle as Doubles, and Integers will be stored as Longs due to Cursor limitationcs
 *
 * @param cursor The cursor to convert to a Bundle. This must be positioned to the row to be
 *               read/*from   ww w  . j  av a 2s .  c  om*/
 * @return The converted bundle
 */
public static Bundle cursorToBundle(Cursor cursor) {

    final int columnCount = cursor.getColumnCount();
    final Bundle bundle = new Bundle(columnCount);

    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {

        final String columnName = cursor.getColumnName(columnIndex);
        switch (cursor.getType(columnIndex)) {

        case Cursor.FIELD_TYPE_STRING: {
            bundle.putString(columnName, cursor.getString(columnIndex));
            break;
        }

        case Cursor.FIELD_TYPE_BLOB: {
            bundle.putByteArray(columnName, cursor.getBlob(columnIndex));
            break;
        }

        case Cursor.FIELD_TYPE_FLOAT: {
            bundle.putDouble(columnName, cursor.getDouble(columnIndex));
            break;
        }

        case Cursor.FIELD_TYPE_INTEGER: {
            bundle.putLong(columnName, cursor.getLong(columnIndex));
            break;
        }
        }
    }

    return bundle;
}

From source file:pro.dbro.iburn_2012.OpenStreetMapFragment.java

public static ArrayList<OverlayItem> generateOverlayItems() {

    final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
    String[] projection = new String[] { CampTable.COLUMN_NAME, CampTable.COLUMN_LATITUDE,
            CampTable.COLUMN_LONGITUDE, CampTable.COLUMN_ID };
    Cursor camps = FragmentTabsPager.app.getContentResolver().query(PlayaContentProvider.CAMP_URI, projection,
            null, null, CampTable.COLUMN_LATITUDE + " ASC");
    if (camps.moveToFirst()) {
        Drawable base_pin = FragmentTabsPager.app.getResources().getDrawable(R.drawable.red_pin);
        OverlayItem item;//from w w w  .  ja  v a2s .c  o  m
        do {
            if (!camps.isNull(camps.getColumnIndex(CampTable.COLUMN_LATITUDE))) {
                item = new OverlayItem(camps.getString(camps.getColumnIndex(CampTable.COLUMN_NAME)),
                        camps.getString(camps.getColumnIndex(CampTable.COLUMN_ID)),
                        new GeoPoint(camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LATITUDE)),
                                camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LONGITUDE))));
                item.setMarker(base_pin);
                items.add(item);
                //Log.d("Camp Location added", String.valueOf(camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LATITUDE))) + " : " + camps.getDouble(camps.getColumnIndex(CampTable.COLUMN_LONGITUDE)));
            }

        } while (camps.moveToNext());
    }
    camps.close();
    return items;
}

From source file:com.example.asadkhan.sunshine.ForecastAdapter.java

private String convertCursorRowToUXFormat(Cursor cursor) {

    String highAndLow = formatHighLows(cursor.getDouble(MainForecastFragment.COL_WEATHER_MAX_TEMP),
            cursor.getDouble(MainForecastFragment.COL_WEATHER_MIN_TEMP));

    return Utility.formatDate(cursor.getLong(MainForecastFragment.COL_WEATHER_DATE)) + " - "
            + cursor.getString(MainForecastFragment.COL_WEATHER_DESC) + " - " + highAndLow;
}

From source file:com.roque.rueda.cashflows.adapters.AccountAdapter.java

/**
 * Bind an existing view to the data pointed to by cursor.
 * @param view       Existing view, returned earlier by newView
 * @param ctx          Interface to application's global information
 * @param cursor      The cursor from which to get the data. 
 *                         The cursor is already moved to the correct position.
 * //from ww w .j  a v a  2  s.  c  o m
 */
@Override
public void bindView(View view, Context ctx, Cursor cursor) {

    Account account = new Account();
    account.id = cursor.getLong(cursor.getColumnIndex(AccountTable._ID));
    account.initialBalance = cursor.getDouble(cursor.getColumnIndex(AccountTable.ACCOUNT_INITIAL_BALANCE));
    account.endBalance = cursor.getDouble(cursor.getColumnIndex(AccountTable.ACCOUNT_END_BALANCE));
    account.photoNumber = cursor.getLong(cursor.getColumnIndex(AccountTable.PHOTO_NUMBER));
    account.name = cursor.getString(cursor.getColumnIndex(AccountTable.ACCOUNT_NAME));

    AccountView holder = (AccountView) view.getTag();
    holder.setModel(account);
}

From source file:edu.mit.mobile.android.locast.maps.LocatableMapFragment.java

protected MarkerOptions getMarker(Cursor c) {
    final MarkerOptions mo = new MarkerOptions();
    mo.position(new LatLng(c.getDouble(c.getColumnIndex(Locatable.COL_LATITUDE)),
            c.getDouble(c.getColumnIndex(Locatable.COL_LONGITUDE))));
    mo.title(c.getString(c.getColumnIndex(Titled.COL_TITLE)));
    mo.snippet(c.getString(c.getColumnIndex(Titled.COL_DESCRIPTION)));

    return mo;//from   w  w  w.j a v a  2s  . c om
}

From source file:piuk.blockchain.android.ui.AmountCalculatorFragment.java

public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    if (data != null) {
        data.moveToFirst();// w ww  .ja  v  a  2 s . c om
        exchangeRate = data.getDouble(data.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_EXCHANGE_RATE_15M));

        updateAppearance();
    }
}