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:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    String maxRateString = "";
    String rateString = "";
    String maxRateSymbol = "";
    double maxRateValue = 0;

    updateEmptyView();//w ww .ja va  2  s  . co  m

    if (data == null) {
        Log.d(LOG_TAG, "Main Forex Loader Finished: No data returned");

        return;
    }
    if (data.getCount() <= 0) {
        Log.d(LOG_TAG, "Main Forex Loader Finished: No data returned");

        data.close();
        return;
    }

    for (int i = 0; i < data.getCount(); i++) {
        data.moveToPosition(i);
        rateString = Utility.formatCurrencyRate(getActivity(), data.getString(COL_CURRENCY_TO_SYMBOL),
                data.getDouble(COL_RATE_VAL));

        if (rateString.length() > maxRateString.length()) {
            maxRateString = rateString;
            maxRateSymbol = data.getString(COL_CURRENCY_TO_SYMBOL);
            maxRateValue = data.getDouble(COL_RATE_VAL);
        }
    }

    mForexAdapter.setMaxRateVal(maxRateSymbol, maxRateValue);
    mForexAdapter.swapCursor(data);
}

From source file:com.example.owen.sunshine.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
        // Use placeholder Image
        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 friendlyDateText = Utility.getDayName(getActivity(), date);
        String dateText = Utility.getFormattedMonthDay(getActivity(), date);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);//from  w  ww  .  j av  a  2s. co m

        // Read description from cursor and update view
        String description = data.getString(COL_WEATHER_DESC);
        mDescriptionView.setText(description);

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high, isMetric);
        mHighTempView.setText(highString);

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
        mLowTempView.setText(lowString);

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.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);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

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

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

        // If onCreateOptionsMenu has already happened, we need to update the share intent now.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareForecastIntent());
        }
    }
}

From source file:org.dharmaseed.android.TalkCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {

    // Set talk title and teacher name
    TextView title = (TextView) view.findViewById(R.id.item_view_title);
    TextView teacher = (TextView) view.findViewById(R.id.item_view_detail1);
    TextView center = (TextView) view.findViewById(R.id.item_view_detail2);
    title.setText(getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TITLE));
    teacher.setText(getString(cursor, DBManager.C.Teacher.TABLE_NAME + "." + DBManager.C.Teacher.NAME));
    center.setText(getString(cursor, DBManager.C.Center.TABLE_NAME + "." + DBManager.C.Teacher.NAME));

    // Set date/* w  ww . j a  va  2s .c o m*/
    TextView date = (TextView) view.findViewById(R.id.item_view_detail3);
    String recDate = getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.RECORDING_DATE);
    try {
        date.setText(DateFormat.getDateInstance().format(parser.parse(recDate)));
    } catch (ParseException e) {
        date.setText("");
    }

    // Set the talk duration
    final TextView durationView = (TextView) view.findViewById(R.id.item_view_detail4);
    double duration = cursor.getDouble(cursor.getColumnIndexOrThrow(
            DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.DURATION_IN_MINUTES)));
    String durationStr = DateUtils.formatElapsedTime((long) (duration * 60));
    durationView.setText(durationStr);

    // Set teacher photo
    String photoFilename = DBManager.getTeacherPhotoFilename(cursor.getInt(cursor.getColumnIndexOrThrow(
            DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TEACHER_ID))));
    ImageView photoView = (ImageView) view.findViewById(R.id.item_view_photo);
    try {
        FileInputStream photo = context.openFileInput(photoFilename);
        photoView.setImageBitmap(BitmapFactory.decodeStream(photo));
    } catch (FileNotFoundException e) {
        Drawable icon = ContextCompat.getDrawable(context, R.drawable.dharmaseed_icon);
        photoView.setImageDrawable(icon);
    }

    // Set talk stars
    handleStars(view, cursor.getInt(cursor.getColumnIndexOrThrow(DBManager.C.Talk.ID)));
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
        // Use weather art image
        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 friendlyDateText = Utility.getDayName(getActivity(), date);
        String dateText = Utility.getFormattedMonthDay(getActivity(), date);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);//from   w w  w  .j av  a  2 s. co m

        // Read description from cursor and update view
        String description = data.getString(COL_WEATHER_DESC);
        mDescriptionView.setText(description);

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high, isMetric);
        mHighTempView.setText(highString);

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
        mLowTempView.setText(lowString);

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.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);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

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

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

        // If onCreateOptionsMenu has already happened, we need to update the share intent now.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareForecastIntent());
        }
    }
}

From source file:ca.mudar.mtlaucasou.BaseMapFragment.java

/**
 * Get the list of Placemarks from the database and return them as array to
 * be added as OverlayItems in the map./*from   w w  w  .j  a  v a 2  s. com*/
 * 
 * @return ArrayList of MarpMarkers
 */
protected ArrayList<MapMarker> fetchMapMarkers() {
    MapMarker mMapMarker;
    ArrayList<MapMarker> alLocations = new ArrayList<MapMarker>();

    Cursor cur = getActivity().getApplicationContext().getContentResolver()
            .query(mActivityHelper.getContentUri(indexSection), MAP_MARKER_PROJECTION, null, null, null);
    if (cur.moveToFirst()) {
        final int columnId = cur.getColumnIndexOrThrow(BaseColumns._ID);
        final int columnName = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_NAME);
        final int columnAddress = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_ADDRESS);
        final int columnGeoLat = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LAT);
        final int columnGeoLng = cur.getColumnIndexOrThrow(PlacemarkColumns.PLACEMARK_GEO_LNG);

        do {
            mMapMarker = new MapMarker(cur.getInt(columnId), cur.getString(columnName),
                    cur.getString(columnAddress), cur.getDouble(columnGeoLat), cur.getDouble(columnGeoLng));
            alLocations.add(mMapMarker);

        } while (cur.moveToNext());
    }
    /**
     * Note: using startManagingCursor() crashed the application when
     * running on Honeycomb! So we don't manage the cursor and close it
     * manually here.
     */
    cur.close();

    return alLocations;
}

From source file:com.samknows.measurement.storage.DBHelper.java

public JSONArray getAverageResults(long starttime, long endtime, List<Integer> test_batches) {
    synchronized (sync) {
        open();/* w  w w .  j  a  v a  2 s . co  m*/
        JSONArray ret = new JSONArray();
        String selection = String.format("dtime BETWEEN %d AND %d AND success <> 0", starttime, endtime);
        if (test_batches != null && test_batches.size() == 0) {
            return ret;
        }
        if (test_batches != null) {
            selection += " AND " + getInClause(SKSQLiteHelper.TR_COLUMN_BATCH_ID, test_batches);
        }
        String averageColumn = String.format("AVG(%s)", SKSQLiteHelper.TR_COLUMN_RESULT);

        String[] columns = { SKSQLiteHelper.TR_COLUMN_TYPE, averageColumn, "COUNT(*)" };
        String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE;
        Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null,
                null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {

            JSONObject curr = new JSONObject();
            try {
                int test_type_id = TestResult.testStringToId(cursor.getString(0));
                curr.put(AVERAGEDATA_TYPE, test_type_id + "");
                curr.put(AVERAGEDATA_VALUE, TestResult.hrResult(test_type_id, cursor.getDouble(1)));
            } catch (JSONException je) {

            }
            ret.put(curr);
            cursor.moveToNext();
        }
        cursor.close();
        close();
        return ret;
    }
}

From source file:ua.com.elius.sunshine.app.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

        int artId = Utility.getArtResourceForWeatherCondition(weatherId);

        mIconView.setImageResource(artId);

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String friendlyDateText = Utility.getDayName(getActivity(), date);
        String dateText = Utility.getFormattedMonthDay(getActivity(), date);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);/*from   w  w w . java  2  s .  c  o  m*/

        // Read description from cursor and update view
        String description = data.getString(COL_WEATHER_DESC);
        mDescriptionView.setText(description);

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high, isMetric);
        mHighTempView.setText(highString);

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
        mLowTempView.setText(lowString);

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.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);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

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

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

        // If onCreateOptionsMenu has already happened, we need to update the share intent now.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareForecastIntent());
        }
    }
}

From source file:br.com.dgimenes.sunshine.DetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
        // Read weather condition ID from cursor
        int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

        // Use weather art image
        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 friendlyDateText = Utility.getDayName(getActivity(), date);
        String dateText = Utility.getFormattedMonthDay(getActivity(), date);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);/*from ww  w  . j a va 2  s. c o  m*/

        // Read description from cursor and update view
        String description = data.getString(COL_WEATHER_DESC);
        mDescriptionView.setText(description);

        // Read high temperature from cursor and update view
        boolean isMetric = Utility.isMetric(getActivity());

        double high = data.getDouble(COL_WEATHER_MAX_TEMP);
        String highString = Utility.formatTemperature(getActivity(), high, isMetric);
        mHighTempView.setText(highString);

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
        mLowTempView.setText(lowString);

        // Read humidity from cursor and update view
        float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
        mHumidityView.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);
        mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

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

        // We still need this for the share intent
        mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

        // If onCreateOptionsMenu has already happened, we need to update the share intent now.
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareForecastIntent());
        }
    }
}

From source file:com.androzic.location.LocationService.java

public Track getTrack(long start, long end) {
    if (trackDB == null)
        openDatabase();/* www.  j  av  a2s. c  o m*/
    Track track = new Track();
    if (trackDB == null)
        return track;
    Cursor cursor = trackDB.rawQuery(
            "SELECT * FROM track WHERE datetime >= ? AND datetime <= ? ORDER BY _id DESC",
            new String[] { String.valueOf(start), String.valueOf(end) });
    for (boolean hasItem = cursor.moveToLast(); hasItem; hasItem = cursor.moveToPrevious()) {
        double latitude = cursor.getDouble(cursor.getColumnIndex("latitude"));
        double longitude = cursor.getDouble(cursor.getColumnIndex("longitude"));
        double elevation = cursor.getDouble(cursor.getColumnIndex("elevation"));
        double speed = cursor.getDouble(cursor.getColumnIndex("speed"));
        double bearing = cursor.getDouble(cursor.getColumnIndex("track"));
        double accuracy = cursor.getDouble(cursor.getColumnIndex("accuracy"));
        int code = cursor.getInt(cursor.getColumnIndex("code"));
        long time = cursor.getLong(cursor.getColumnIndex("datetime"));
        track.addPoint(code == 0, latitude, longitude, elevation, speed, bearing, accuracy, time);
    }
    cursor.close();
    return track;
}

From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case ID_LOADER_REPORT:
        //                ((IncomeVsExpensesAdapter) getListAdapter()).swapCursor(data);
        ((IncomeVsExpensesAdapter) getListAdapter()).changeCursor(data);

        if (isResumed()) {
            setListShown(true);//  w ww.java  2s  .  c o  m
        } else {
            setListShownNoAnimation(true);
        }
        // calculate income, expenses
        double income = 0, expenses = 0;
        if (data == null)
            return;

        while (data.moveToNext()) {
            if (data.getInt(data.getColumnIndex(
                    IncomeVsExpenseReportEntity.Month)) != IncomeVsExpensesActivity.SUBTOTAL_MONTH) {
                income += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income));
                expenses += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses));
            }
        }
        updateListViewFooter(mFooterListView, income, expenses);
        if (data.getCount() > 0) {
            getListView().removeFooterView(mFooterListView);
            getListView().addFooterView(mFooterListView);
        }

        if (((IncomeVsExpensesActivity) getActivity()).mIsDualPanel) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    showChart();
                }
            }, 1 * 1000);
        }
        break;

    case ID_LOADER_YEARS:
        if (data != null && data.moveToFirst()) {
            while (!data.isAfterLast()) {
                int year = data.getInt(data.getColumnIndex("Year"));
                if (mYearsSelected.get(year, false) == false) {
                    mYearsSelected.put(year, false);
                }
                data.moveToNext();
            }
            startLoader();
        }
    }
}