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:com.djkong.android.greatweather.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);//ww w.ja  va  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:com.crankworks.cycletracks.TripUploader.java

private JSONObject getCoordsJSON(long tripId) throws JSONException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    mDb.openReadOnly();//ww w .  j av  a2 s  .  co m
    Cursor tripCoordsCursor = mDb.fetchAllCoordsForTrip(tripId);

    // Build the map between JSON fieldname and phone db fieldname:
    Map<String, Integer> fieldMap = new HashMap<String, Integer>();
    fieldMap.put(TRIP_COORDS_TIME, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_TIME));
    fieldMap.put(TRIP_COORDS_LAT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LAT));
    fieldMap.put(TRIP_COORDS_LON, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LGT));
    fieldMap.put(TRIP_COORDS_ALT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ALT));
    fieldMap.put(TRIP_COORDS_SPEED, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_SPEED));
    fieldMap.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));
    fieldMap.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));

    // Build JSON objects for each coordinate:
    JSONObject tripCoords = new JSONObject();
    while (!tripCoordsCursor.isAfterLast()) {
        JSONObject coord = new JSONObject();

        coord.put(TRIP_COORDS_TIME, df.format(tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_TIME))));
        coord.put(TRIP_COORDS_LAT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LAT)) / 1E6);
        coord.put(TRIP_COORDS_LON, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LON)) / 1E6);
        coord.put(TRIP_COORDS_ALT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_ALT)));
        coord.put(TRIP_COORDS_SPEED, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_SPEED)));
        coord.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_HACCURACY)));
        coord.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_VACCURACY)));

        tripCoords.put(coord.getString("rec"), coord);
        tripCoordsCursor.moveToNext();
    }
    tripCoordsCursor.close();
    mDb.close();
    return tripCoords;
}

From source file:src.com.nustats.pacelogger.TripUploader.java

private JSONObject getCoordsJSON(long tripId) throws JSONException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");

    mDb.openReadOnly();/*from  www  . ja  v a2s. c om*/
    Cursor tripCoordsCursor = mDb.fetchAllCoordsForTrip(tripId);

    // Build the map between JSON fieldname and phone db fieldname:
    Map<String, Integer> fieldMap = new HashMap<String, Integer>();
    fieldMap.put(TRIP_COORDS_TIME, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_TIME));
    fieldMap.put(TRIP_COORDS_LAT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LAT));
    fieldMap.put(TRIP_COORDS_LON, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LGT));
    fieldMap.put(TRIP_COORDS_ALT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ALT));
    fieldMap.put(TRIP_COORDS_SPEED, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_SPEED));
    fieldMap.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));
    fieldMap.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC));

    // Build JSON objects for each coordinate:
    JSONObject tripCoords = new JSONObject();
    while (!tripCoordsCursor.isAfterLast()) {
        JSONObject coord = new JSONObject();

        coord.put(TRIP_COORDS_TIME, df.format(tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_TIME))));
        coord.put(TRIP_COORDS_LAT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LAT)) / 1E6);
        coord.put(TRIP_COORDS_LON, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LON)) / 1E6);
        coord.put(TRIP_COORDS_ALT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_ALT)));
        coord.put(TRIP_COORDS_SPEED, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_SPEED)));
        coord.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_HACCURACY)));
        coord.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_VACCURACY)));

        tripCoords.put(coord.getString("rec"), coord);
        tripCoordsCursor.moveToNext();
    }
    tripCoordsCursor.close();
    mDb.close();
    return tripCoords;
}

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.c o  m*/
        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:org.xbmc.kore.ui.sections.video.TVShowEpisodeDetailsFragment.java

/**
 * Display the episode details/*from  ww  w  .  j a v a  2 s.c om*/
 *
 * @param cursor Cursor with the data
 */
private void displayEpisodeDetails(Cursor cursor) {
    cursor.moveToFirst();
    mediaTitle.setText(cursor.getString(EpisodeDetailsQuery.TITLE));
    mediaUndertitle.setText(cursor.getString(EpisodeDetailsQuery.SHOWTITLE));

    int runtime = cursor.getInt(EpisodeDetailsQuery.RUNTIME) / 60;
    String durationPremiered = runtime > 0
            ? String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) + "  |  "
                    + cursor.getString(EpisodeDetailsQuery.FIRSTAIRED)
            : cursor.getString(EpisodeDetailsQuery.FIRSTAIRED);
    mediaPremiered.setText(durationPremiered);
    String season = String.format(getString(R.string.season_episode), cursor.getInt(EpisodeDetailsQuery.SEASON),
            cursor.getInt(EpisodeDetailsQuery.EPISODE));
    mediaSeason.setText(season);

    double rating = cursor.getDouble(EpisodeDetailsQuery.RATING);
    if (rating > 0) {
        mediaRating.setVisibility(View.VISIBLE);
        mediaMaxRating.setVisibility(View.VISIBLE);
        mediaRating.setText(String.format("%01.01f", rating));
        mediaMaxRating.setText(getString(R.string.max_rating_video));
    } else {
        mediaRating.setVisibility(View.INVISIBLE);
        mediaMaxRating.setVisibility(View.INVISIBLE);
    }

    mediaDescription.setText(cursor.getString(EpisodeDetailsQuery.PLOT));
    mediaDirectors.setText(cursor.getString(EpisodeDetailsQuery.DIRECTOR));

    setupSeenButton(cursor.getInt(EpisodeDetailsQuery.PLAYCOUNT));

    // Images
    Resources resources = getActivity().getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

    int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width);
    int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height);
    //        UIUtils.loadImageIntoImageview(hostManager,
    //                cursor.getString(EpisodeDetailsQuery.THUMBNAIL),
    //                mediaPoster, posterWidth, posterHeight);
    int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height);
    UIUtils.loadImageIntoImageview(getHostManager(), cursor.getString(EpisodeDetailsQuery.THUMBNAIL), mediaArt,
            displayMetrics.widthPixels, artHeight);

    // Setup movie download info
    tvshowDownloadInfo = new FileDownloadHelper.TVShowInfo(cursor.getString(EpisodeDetailsQuery.SHOWTITLE),
            cursor.getInt(EpisodeDetailsQuery.SEASON), cursor.getInt(EpisodeDetailsQuery.EPISODE),
            cursor.getString(EpisodeDetailsQuery.TITLE), cursor.getString(EpisodeDetailsQuery.FILE));

    // Check if downloaded file exists
    downloadButton.setVisibility(View.VISIBLE);
    if (tvshowDownloadInfo.downloadFileExists()) {
        Resources.Theme theme = getActivity().getTheme();
        TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorAccent });
        downloadButton
                .setColorFilter(styledAttributes.getColor(0, getResources().getColor(R.color.accent_default)));
        styledAttributes.recycle();
    } else {
        downloadButton.clearColorFilter();
    }
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Adds {@link ClusterMarker} admin markers into the map as basic markers that won't be grouped.
 * Calls the SQLite {@link SubmissionDatabase#queryAdminMarkers()} for a cursor with admin markers
 *//*from  w w w .  ja  v a  2s . com*/
private void addAdminMarkersToMap() {
    SubmissionDatabase submissionDatabase = new SubmissionDatabase(getActivity());
    Cursor queryCursor = submissionDatabase.queryAdminMarkers();
    queryCursor.moveToFirst();
    if (queryCursor.getCount() > 0) {
        do {
            if (!this.submissionMarkerIdList
                    .contains(queryCursor.getString(queryCursor.getColumnIndexOrThrow("admin_marker_id")))) {
                ClusterMarkerAdmin adminMarker = new ClusterMarkerAdmin(
                        queryCursor.getString(queryCursor.getColumnIndexOrThrow("admin_marker_id")),
                        queryCursor.getDouble(queryCursor.getColumnIndexOrThrow("admin_marker_latitude")),
                        queryCursor.getDouble(queryCursor.getColumnIndexOrThrow("admin_marker_longitude")),
                        queryCursor.getString(queryCursor.getColumnIndexOrThrow("admin_marker_title")), "");
                this.submissionMarkerIdList
                        .add(queryCursor.getString(queryCursor.getColumnIndexOrThrow("admin_marker_id")));
                this.clusterManager.addItem(adminMarker);
            }

        } while (queryCursor.moveToNext());
        this.clusterManager.cluster();
    }
    submissionDatabase.closeDbConnection();
}

From source file:com.money.manager.ex.budget.BudgetAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // Category//from   ww  w .j  a  v a 2 s. c o  m

    boolean hasSubcategory = false;
    TextView categoryTextView = (TextView) view.findViewById(R.id.categoryTextView);
    if (categoryTextView != null) {
        int categoryCol = cursor.getColumnIndex(BudgetQuery.CATEGNAME);
        String category = cursor.getString(categoryCol);

        // Subcategory
        String subCategory = cursor.getString(cursor.getColumnIndex(BudgetQuery.SUBCATEGNAME));
        if (!TextUtils.isEmpty(subCategory)) {
            category += ":" + subCategory;
            hasSubcategory = true;
        }

        categoryTextView.setText(category);
    }

    // Frequency

    TextView frequencyTextView = (TextView) view.findViewById(R.id.frequencyTextView);
    if (frequencyTextView != null) {
        String text = cursor.getString(cursor.getColumnIndex(BudgetQuery.PERIOD));
        frequencyTextView.setText(text);
    }

    CurrencyService currencyService = new CurrencyService(mContext);

    // Amount

    TextView amountTextView = (TextView) view.findViewById(R.id.amountTextView);
    if (amountTextView != null) {
        double amount = cursor.getDouble(cursor.getColumnIndex(BudgetQuery.AMOUNT));
        String text = currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(amount));
        amountTextView.setText(text);
    }

    // Estimated
    // Actual
    // todo: colour the amount depending on whether it is above/below the budgeted amount.
    TextView actualTextView = (TextView) view.findViewById(R.id.actualTextView);
    if (actualTextView != null) {
        double actual;
        if (!hasSubcategory) {
            int categoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.CATEGID));
            actual = getAmountForCategory(categoryId);
        } else {
            int subCategoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.SUBCATEGID));
            actual = getAmountForSubCategory(subCategoryId);
        }

        String actualString = currencyService.getBaseCurrencyFormatted(MoneyFactory.fromDouble(actual));
        actualTextView.setText(actualString);
    }
}

From source file:me.albinmathew.celluloid.ui.activities.MoviesActivity.java

/**
 * show Favourite movies from database//from  w  ww  .  j a v a  2s  . com
 */
private void showFavouriteMovies() {
    mCurrentSortSelection = CAConstants.FAVOURITES;
    Cursor cursor = getContentResolver().query(MovieContract.Movie.CONTENT_URI, null, null, null,
            MovieContract.Movie._ID + " DESC");
    ArrayList<MoviesResponseBean> mPosterList = new ArrayList<>();
    if (cursor != null) {
        while (cursor.moveToNext()) {
            MoviesResponseBean resultModel = new MoviesResponseBean();
            resultModel.setTitle(cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_TITLE)));
            resultModel.setPosterPath(
                    cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_POSTER_URL)));
            resultModel.setBackdropPath(
                    cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_BACK_DROP_URL)));
            resultModel.setOriginalTitle(
                    cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_ORIGINAL_TITLE)));
            resultModel.setOverview(cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_PLOT)));
            resultModel
                    .setVoteAverage(cursor.getDouble(cursor.getColumnIndex(MovieContract.Movie.COLUMN_RATING)));
            resultModel.setReleaseDate(
                    cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_RELEASE_DATE)));
            resultModel.setId(cursor.getLong(cursor.getColumnIndex(MovieContract.Movie.COLUMN_MOVIE_ID)));
            resultModel.setGenreId(CommonUtil.convertStringToArray(
                    cursor.getString(cursor.getColumnIndex(MovieContract.Movie.COLUMN_GENRE_ID))));
            mPosterList.add(resultModel);
        }
        clearAdapter();
        mMoviesAdapter.getMoviesList().addAll(mPosterList);
        mMoviesAdapter.notifyDataSetChanged();
        cursor.close();
    }
}

From source file:com.katamaditya.apps.weather4u.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(WeatherUtil.getArtResourceForWeatherCondition(weatherId));

        // Read date from cursor and update views for day of week and date
        long date = data.getLong(COL_WEATHER_DATE);
        String friendlyDateText = WeatherUtil.getDayName(getActivity(), date);
        String dateText = WeatherUtil.getFormattedMonthDay(getActivity(), date);
        mFriendlyDateView.setText(friendlyDateText);
        mDateView.setText(dateText);//from   ww w.j  a  v  a 2s  .  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 = WeatherUtil.isMetric(getActivity());

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

        // Read low temperature from cursor and update view
        double low = data.getDouble(COL_WEATHER_MIN_TEMP);
        String lowString = WeatherUtil.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(WeatherUtil.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

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

    if (cursor.moveToFirst()) {
        do {//  www  . j  a v a 2  s .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;
}