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:com.robotoworks.mechanoid.db.SQuery.java

public float firstFloat(Uri uri, String column, String orderBy) {
    Cursor cursor = null;
    float value = 0;

    try {//from   ww w  .  jav  a2 s.com
        cursor = select(uri, new String[] { column }, orderBy, false);

        if (cursor.moveToFirst()) {
            value = cursor.getFloat(0);
        }

    } finally {
        Closeables.closeSilently(cursor);
    }

    return value;
}

From source file:com.textuality.lifesaver2.Columns.java

public JSONObject cursorToJSON(Cursor cursor) {
    setColumns(cursor);//from w  w  w. j a v  a2 s  .  c  om
    JSONObject json = new JSONObject();
    try {
        for (int i = 0; i < mNames.length; i++) {
            int col = mColumns[i];
            if (cursor.isNull(col))
                continue;
            switch (mTypes[i]) {
            case STRING:
                String str = cursor.getString(col);
                if (mNames[i].equals("number")) {
                    json.put("name", mNameFinder.find(str));
                } else if (mNames[i].equals("address")) {
                    str = PhoneNumberUtils.formatNumber(str);
                    str = PhoneNumberUtils.stripSeparators(str);
                    json.put("name", mNameFinder.find(str));
                }
                json.put(mNames[i], str);
                break;
            case INT:
                json.put(mNames[i], cursor.getInt(col));
                break;
            case LONG:
                long val = cursor.getLong(col);
                json.put(mNames[i], val);
                if (mNames[i].equals("date")) {
                    json.put("tzoffset", mTZ.getOffset(val));
                }
                break;
            case FLOAT:
                json.put(mNames[i], cursor.getFloat(col));
                break;
            case DOUBLE:
                json.put(mNames[i], cursor.getDouble(col));
                break;
            }
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    return json;
}

From source file:export.format.FacebookCourse.java

private JSONArray trail(long activityId) throws JSONException {
    final String cols[] = { DB.LOCATION.TYPE, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.TIME,
            DB.LOCATION.SPEED };/*from w ww .  ja  v a 2  s. c om*/
    Cursor c = mDB.query(DB.LOCATION.TABLE, cols, DB.LOCATION.ACTIVITY + " = " + activityId, null, null, null,
            null);
    if (c.moveToFirst()) {
        Location prev = null, last = null;
        double sumDist = 0;
        long sumTime = 0;
        double accTime = 0;
        final double period = 30;
        JSONArray arr = new JSONArray();
        do {
            switch (c.getInt(0)) {
            case DB.LOCATION.TYPE_START:
            case DB.LOCATION.TYPE_RESUME:
                last = new Location("Dill");
                last.setLatitude(c.getDouble(1));
                last.setLongitude(c.getDouble(2));
                last.setTime(c.getLong(3));
                accTime = period * 1000; // always emit first point
                                         // start/resume
                break;
            case DB.LOCATION.TYPE_END:
                accTime = period * 1000; // always emit last point
            case DB.LOCATION.TYPE_GPS:
            case DB.LOCATION.TYPE_PAUSE:
                Location l = new Location("Sill");
                l.setLatitude(c.getDouble(1));
                l.setLongitude(c.getDouble(2));
                l.setTime(c.getLong(3));
                if (!c.isNull(4))
                    l.setSpeed(c.getFloat(4));
                if (last != null) {
                    sumDist += l.distanceTo(last);
                    sumTime += l.getTime() - last.getTime();
                    accTime += l.getTime() - last.getTime();
                }
                prev = last;
                last = l;
            }
            if (Math.round(accTime / 1000) >= period) {
                arr.put(point(prev, last, sumTime, sumDist));
                accTime -= period * 1000;
            }
        } while (c.moveToNext());
        c.close();
        return arr;
    }
    c.close();
    return null;
}

From source file:edu.cens.loci.provider.LociDbUtils.java

public LociLocation getPlaceLocationEstimationWithBestAccuracy(long start, long end) {
    LociLocation placeLoc = null;/*from w w  w .  j a va  2 s . co m*/

    String[] columns = new String[] { Tracks._ID, Tracks.TIME, Tracks.LATITUDE, Tracks.LONGITUDE,
            Tracks.ALTITUDE, Tracks.SPEED, Tracks.BEARING, Tracks.ACCURACY };

    String selection = Tracks.TIME + ">=" + start + " AND " + Tracks.TIME + " <= " + end;

    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    Cursor cursor = db.query(Tables.TRACKS, columns, selection, null, null, null, null);

    float minAccuracy = Float.MAX_VALUE;

    if (cursor.moveToFirst()) {
        do {
            if (minAccuracy > cursor.getFloat(cursor.getColumnIndex(Tracks.ACCURACY))) {
                if (placeLoc == null)
                    placeLoc = new LociLocation(LocationManager.GPS_PROVIDER);
                placeLoc.setTime(cursor.getLong(cursor.getColumnIndex(Tracks.TIME)));
                placeLoc.setLatitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LATITUDE)));
                placeLoc.setLongitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LONGITUDE)));
                placeLoc.setAltitude(cursor.getDouble(cursor.getColumnIndex(Tracks.ALTITUDE)));
                placeLoc.setSpeed(cursor.getFloat(cursor.getColumnIndex(Tracks.SPEED)));
                placeLoc.setBearing(cursor.getFloat(cursor.getColumnIndex(Tracks.BEARING)));
                placeLoc.setAccuracy(cursor.getFloat(cursor.getColumnIndex(Tracks.ACCURACY)));
                minAccuracy = placeLoc.getAccuracy();
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return placeLoc;
}

From source file:com.robotoworks.mechanoid.db.SQuery.java

public float[] selectFloatArray(Uri uri, String column, String orderBy) {
    Cursor cursor = null;

    try {//from   w ww .  jav  a2s.  co  m
        cursor = select(uri, new String[] { column }, orderBy, false);

        float[] array = new float[cursor.getCount()];

        for (int i = 0; i < cursor.getCount(); i++) {
            cursor.moveToNext();
            array[i] = cursor.getFloat(0);
        }

        return array;

    } finally {
        Closeables.closeSilently(cursor);
    }
}

From source file:com.robotoworks.mechanoid.db.SQuery.java

public List<Float> selectFloatList(Uri uri, String column, String orderBy) {
    Cursor cursor = null;

    try {/*from ww  w .j ava2  s  .  c  o m*/
        cursor = select(uri, new String[] { column }, orderBy, false);

        List<Float> list = new ArrayList<Float>(cursor.getCount());

        for (int i = 0; i < cursor.getCount(); i++) {
            cursor.moveToNext();
            list.add(cursor.getFloat(0));
        }

        return list;

    } finally {
        Closeables.closeSilently(cursor);
    }
}

From source file:com.jackie.sunshine.app.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    Log.d(TAG, "onLoadFinished: ");
    if (data == null || !data.moveToFirst())
        return;//from w  w w .j  a v  a 2s  .com

    Context context = getContext();

    int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
    mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));

    // Read date from cursor and update views for day of week and date
    long date = data.getLong(COL_WEATHER_DATE);
    String friendlyDateStr = Utility.getDayName(context, date);
    String dateStr = Utility.getFormattedMonthDay(context, date);
    mTvDate.setText(dateStr);
    mTvFriendlyDate.setText(friendlyDateStr);

    // Read description from cursor and update view
    String weatherDescription = data.getString(COL_WEATHER_DESC);
    mTvDescription.setText(weatherDescription);
    mIconView.setContentDescription(weatherDescription);

    boolean isMetric = Utility.isMetric(context);

    // Read high temperature from cursor and update view
    String high = Utility.formatTemperature(context, data.getDouble(COL_WEATHER_MAX_TEMP));
    mTvHighTemp.setText(high);

    // Read low temperature from cursor and update view
    String low = Utility.formatTemperature(context, data.getDouble(COL_WEATHER_MIN_TEMP));
    mTvLowTemp.setText(low);

    // Read humidity from cursor and update view
    float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
    mTvHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));

    // Read wind speed and direction from cursor and update view
    float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
    float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
    mTvWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

    // Read pressure from cursor and update view
    float pressure = data.getFloat(COL_WEATHER_PRESSURE);
    mTvPressure.setText(getString(R.string.format_pressure, pressure));

    mForecastStr = String.format("%s - %s - %s/%s", dateStr, weatherDescription, high, low);

    if (mShareAction != null) {
        mShareAction.setShareIntent(createShareIntent());
    }
}

From source file:edu.cens.loci.provider.LociDbUtils.java

public ArrayList<LociCircleArea> getGpsCircleArea(long placeId) {
    ArrayList<LociCircleArea> areas = new ArrayList<LociCircleArea>();
    Cursor cursor = getPlaceData(placeId, GpsCircleArea.CONTENT_ITEM_TYPE);

    if (cursor.moveToFirst()) {
        do {/*w  w w. j  a v  a  2s.  c o  m*/
            double latitude = cursor.getDouble(cursor.getColumnIndex(GpsCircleArea.LATITUDE));
            double longitude = cursor.getDouble(cursor.getColumnIndex(GpsCircleArea.LONGITUDE));
            float radius = cursor.getFloat(cursor.getColumnIndex(GpsCircleArea.RADIUS));

            areas.add(new LociCircleArea(latitude, longitude, radius));

        } while (cursor.moveToNext());
    }
    cursor.close();

    if (areas.size() <= 0) {

    }

    return areas;
}

From source file:fr.eoit.activity.util.ItemListViewBinder.java

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    int viewId = view.getId();

    numberOfElements = cursor.getCount();
    currentPosition = cursor.getPosition();

    switch (viewId) {
    case R.id.item_name:
    case R.id.ITEM_NAME:
        String value = cursor.getString(columnIndex);
        initName(view, value);/*  w w w.j av  a  2 s  . com*/
        break;

    case R.id.item_icon:
    case R.id.ITEM_ICON:
        id = cursor.getLong(columnIndex);
        initIcon(view, id);
        break;

    case R.id.item_quantity:
    case R.id.ITEM_QUANTITY:
        quantity = cursor.getLong(columnIndex);
        int ml = 0;
        int groupId = 0;
        if (cursor.getColumnIndex(Blueprint.COLUMN_NAME_ML) != -1) {
            ml = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_ML));
        }
        if (cursor.getColumnIndex(Item.COLUMN_NAME_GROUP_ID) != -1) {
            groupId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_GROUP_ID));
        }
        if (cursor.getColumnIndex(Prices.COLUMN_NAME_PRODUCE_PRICE) != -1) {
            price = cursor.getDouble(cursor.getColumnIndexOrThrow(Prices.COLUMN_NAME_PRODUCE_PRICE));
        }
        initQuantity(id, view, quantity, ml, groupId, price);
        break;

    case R.id.ITEM_DMG_PER_JOB:
        float damagePerJob = cursor.getFloat(columnIndex);
        initDamagePerJob(view, damagePerJob);
        break;

    case R.id.warn_icon:
    case R.id.WARN_ICON:
        price = PricesUtils.getPriceOrNaN(cursor);
        initWarnIcon(view, price);
        break;

    case R.id.item_price:
    case R.id.ITEM_PRICE:
        addToTotalPrice(id, price, quantity);
        break;

    case R.id.item_volume:
    case R.id.ITEM_VOLUME:
        double volume = cursor.getDouble(columnIndex);
        addToTotalVolume(id, volume, quantity);
        break;

    default:
        throw new IllegalArgumentException("viewId : " + viewId);
    }

    return true;
}

From source file:com.nadmm.airports.afd.AirportsCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor c) {
    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.name = (TextView) view.findViewById(R.id.facility_name);
        holder.id = (TextView) view.findViewById(R.id.facility_id);
        holder.location = (TextView) view.findViewById(R.id.location);
        holder.distance = (TextView) view.findViewById(R.id.distance);
        holder.other = (TextView) view.findViewById(R.id.other_info);
        view.setTag(holder);//w w w  .j  a  va 2 s. c  o  m
    }

    String name = c.getString(c.getColumnIndex(Airports.FACILITY_NAME));
    String siteNumber = c.getString(c.getColumnIndex(Airports.SITE_NUMBER));
    String type = DataUtils.decodeLandingFaclityType(siteNumber);
    holder.name.setText(String.format("%s %s", name, type));
    String id = c.getString(c.getColumnIndex(Airports.ICAO_CODE));
    if (id == null || id.trim().length() == 0) {
        id = c.getString(c.getColumnIndex(Airports.FAA_CODE));
    }
    holder.id.setText(id);
    String city = c.getString(c.getColumnIndex(Airports.ASSOC_CITY));
    String state = c.getString(c.getColumnIndex(Airports.ASSOC_STATE));
    String use = c.getString(c.getColumnIndex(Airports.FACILITY_USE));
    holder.location.setText(String.format("%s, %s, %s", city, state, DataUtils.decodeFacilityUse(use)));

    if (c.getColumnIndex(LocationColumns.DISTANCE) >= 0 && c.getColumnIndex(LocationColumns.BEARING) >= 0) {
        // Check if we have distance information
        float distance = c.getFloat(c.getColumnIndex(LocationColumns.DISTANCE));
        float bearing = c.getFloat(c.getColumnIndex(LocationColumns.BEARING));
        holder.distance.setText(String.format("%.1f NM %s, initial course %.0f\u00B0 M", distance,
                GeoUtils.getCardinalDirection(bearing), bearing));
    } else {
        holder.distance.setVisibility(View.GONE);
    }

    String fuel = c.getString(c.getColumnIndex(Airports.FUEL_TYPES));
    float elev = c.getFloat(c.getColumnIndex(Airports.ELEVATION_MSL));
    String ctaf = c.getString(c.getColumnIndex(Airports.CTAF_FREQ));
    String unicom = c.getString(c.getColumnIndex(Airports.UNICOM_FREQS));
    String status = c.getString(c.getColumnIndex(Airports.STATUS_CODE));
    mStringBuilder.setLength(0);
    if (status.equals("O")) {
        mStringBuilder.append(FormatUtils.formatFeetMsl(elev));
        if (ctaf != null && ctaf.length() > 0) {
            mStringBuilder.append(", ");
            mStringBuilder.append(ctaf);
        } else if (unicom != null && unicom.length() > 0) {
            mStringBuilder.append(", ");
            mStringBuilder.append(unicom);
        }
        if (fuel != null && fuel.length() > 0) {
            mStringBuilder.append(", ");
            mStringBuilder.append(DataUtils.decodeFuelTypes(fuel));
        }
    } else {
        mStringBuilder.append(type);
        mStringBuilder.append(", ");
        mStringBuilder.append(DataUtils.decodeStatus(status));
    }
    holder.other.setText(mStringBuilder.toString());
}