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.arminsam.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);
        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);/*  ww  w.j  a  v  a2  s .c  o m*/

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

        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(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.xeon.amar.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(R.drawable.ic_launcher);
        // 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 . com

        // 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);
        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);
        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.groksolutions.grok.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date/*  www.  j a v a 2 s  .co m*/
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, HTMITApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - HTMITApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        GrokDatabase grokdb = HTMITApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = grokdb.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:com.YOMPsolutions.YOMP.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date/*from w w w  .  j  ava 2s .c  o  m*/
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, YOMPApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - YOMPApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        YOMPDatabase YOMPdb = YOMPApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = YOMPdb.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:com.numenta.htmit.mobile.metric.MetricDetailFragment.java

/**
 * Load the metric values for the given {@code metricId} for the time period
 * specified by the given {@code from} and {@code to} dates.
 *
 * @param metricId The metric to get the data from
 * @param from Start Date//w  w  w  . j ava 2  s  .  c o m
 * @param to End Date
 * @return metric data
 */
private float[] getMetricRawValues(String metricId, long from, long to) {
    if (_metricValues != null && from == _startTimestamp && to == _endTimestamp) {
        return _metricValues;
    }
    // Outside buffered range
    if (to > _endTimestamp) {

        // Calculate the maximum time window we keep in the database. From
        // the last known timestamp up to the maximum number of days we keep
        // in the local database.
        // This window will be used by the scroller.
        _endTimestamp = Math.max(to, HTMITApplication.getDatabase().getLastTimestamp());
        _startTimestamp = _endTimestamp - HTMITApplication.getNumberOfDaysToSync() * DataUtils.MILLIS_PER_DAY;

        // Calculate result size based on the date range and time
        // interval
        int size = (int) (_endTimestamp - _startTimestamp) / METRIC_DATA_INTERVAL;
        _metricValues = new float[size];
        Arrays.fill(_metricValues, Float.NaN);
        HTMITDatabase database = HTMITApplication.getDatabase();
        Cursor cursor = null;
        try {
            cursor = database.getMetricData(metricId, new String[] { "timestamp", "metric_value" },
                    new Date(_startTimestamp), new Date(_endTimestamp), 0, 0);
            int i = 0;
            // Round timestamp to closest 5 minute interval
            long currentTimestamp = (_startTimestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

            // In the hour view, start from the end of the bar
            if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
                currentTimestamp += METRIC_DATA_INTERVAL;
            }
            while (i < size) {
                if (cursor.moveToNext()) {
                    long timestamp = cursor.getLong(0);
                    // Round timestamp to closest 5 minute interval
                    timestamp = (timestamp / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

                    while (currentTimestamp < timestamp && i < size) {
                        _metricValues[i++] = Float.NaN;
                        currentTimestamp += METRIC_DATA_INTERVAL;
                    }
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = cursor.getFloat(1);
                } else {
                    currentTimestamp += METRIC_DATA_INTERVAL;
                    _metricValues[i++] = Float.NaN;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Error getting metric data", e);
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    long fromRounded = (from / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;
    long toRounded = (to / METRIC_DATA_INTERVAL) * METRIC_DATA_INTERVAL;

    int start;
    // In the hour view, start from the end of the bar
    if (_metricAnomalyData.getAggregation() == AggregationType.Hour) {
        start = (int) Math.max(0,
                (fromRounded - _startTimestamp - METRIC_DATA_INTERVAL) / METRIC_DATA_INTERVAL);
    } else {
        start = (int) Math.max(0, (fromRounded - _startTimestamp) / METRIC_DATA_INTERVAL);
    }
    int end = (int) Math.min(_metricValues.length, (toRounded - _startTimestamp) / METRIC_DATA_INTERVAL);

    return Arrays.copyOfRange(_metricValues, start, end);
}

From source file:vn.alovoice.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(R.drawable.ic_launcher);
        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  ava  2 s  . co  m

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

        mIconView.setContentDescription(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);
        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);
        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.example.dickchang.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);
        // 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);/*  w w w  .j  a v a2s. co m*/

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

        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(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);
        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);
        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:app.com.oz_heng.android.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);/*w  ww.  j av  a2  s  . com*/

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

        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(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);
        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);
        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.fulltoast.android.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);

        // 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);/*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);

        // For accessibility, add a content description to the icon field
        mIconView.setContentDescription(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);
        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);
        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:edu.cens.loci.provider.LociDbUtils.java

/**
 * @param time/*www.j  av a  2s .  co  m*/
 * @param before
 * @return first location before time if before is true. Otherwise, after time. 
 *         returns null if no location is available.
 */
public LociLocation getFirstLocationBeforeOrAfterTime(long time, boolean before) {

    LociLocation loc = null;

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

    String selection = Tracks.TIME + "<=" + time;
    String order = " DESC";

    if (!before) {
        selection = Tracks.TIME + ">=" + time;
        order = " ASC";
    }

    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    Cursor cursor = db.query(Tables.TRACKS, columns, selection, null, null, null, Tracks.TIME + order, "" + 1);

    if (cursor.moveToFirst()) {
        loc = new LociLocation(LocationManager.GPS_PROVIDER);
        loc.setTime(cursor.getLong(cursor.getColumnIndex(Tracks.TIME)));
        loc.setLatitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LATITUDE)));
        loc.setLongitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LONGITUDE)));
        loc.setAltitude(cursor.getDouble(cursor.getColumnIndex(Tracks.ALTITUDE)));
        loc.setSpeed(cursor.getFloat(cursor.getColumnIndex(Tracks.SPEED)));
        loc.setBearing(cursor.getFloat(cursor.getColumnIndex(Tracks.BEARING)));
        loc.setAccuracy(cursor.getFloat(cursor.getColumnIndex(Tracks.ACCURACY)));
    }
    cursor.close();
    return loc;
}