List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.robotoworks.mechanoid.db.SQuery.java
public List<Double> selectDoubleList(Uri uri, String column, String orderBy) { Cursor cursor = null; try {/* w w w . j a v a2s . c o m*/ cursor = select(uri, new String[] { column }, orderBy, false); List<Double> list = new ArrayList<Double>(cursor.getCount()); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); list.add(cursor.getDouble(0)); } return list; } finally { Closeables.closeSilently(cursor); } }
From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java
/** * Adds submissions to the map based on the provided <code>VisibleRegion</code>. Passes the VisibleRegion * to the {@link SubmissionDatabase#querySubmissions(VisibleRegion, Long)} * * @param visibleRegion The region currently visible on the map *///from www . j a v a 2 s . c o m private void addSubmissionsToMap(VisibleRegion visibleRegion) { SubmissionDatabase submissionDatabase = new SubmissionDatabase(getActivity()); Cursor queryCursor; if (this.minDateInMs > 0) { queryCursor = submissionDatabase.querySubmissions(visibleRegion, this.minDateInMs); } else { queryCursor = submissionDatabase.querySubmissions(visibleRegion, null); } queryCursor.moveToFirst(); if (queryCursor.getCount() > 0) { do { if (!this.submissionMarkerIdList .contains(queryCursor.getString(queryCursor.getColumnIndexOrThrow("submission_id")))) { ClusterMarker clusterMarker = new ClusterMarker( queryCursor.getString(queryCursor.getColumnIndexOrThrow("submission_id")), queryCursor.getDouble(queryCursor.getColumnIndexOrThrow("submission_latitude")), queryCursor.getDouble(queryCursor.getColumnIndexOrThrow("submission_longitude")), "", queryCursor.getString(queryCursor.getColumnIndexOrThrow("submission_positive"))); this.submissionMarkerIdList .add(queryCursor.getString(queryCursor.getColumnIndexOrThrow("submission_id"))); this.clusterManager.addItem(clusterMarker); } } while (queryCursor.moveToNext()); this.clusterManager.cluster(); } submissionDatabase.closeDbConnection(); }
From source file:edu.cens.loci.provider.LociDbUtils.java
/** * @param time/*w ww .j ava2 s .c om*/ * @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; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public SearchListItem getFavoriteByName(String name) { SearchListItem ret = null;/*from ww w. j ava2s . c om*/ SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " = ? ", new String[] { name.trim() }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); ret = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); break; } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.textuality.lifesaver2.Columns.java
public JSONObject cursorToJSON(Cursor cursor) { setColumns(cursor);//from w w w .j av a2s . com 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:com.baksoy.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getArtResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*from w ww .j a va 2 s . c o m*/ } case VIEW_TYPE_FUTURE_DAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getIconResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } // Read date from cursor long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE); // Find TextView and set formatted date on it viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); // Read weather forecast from cursor String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC); // Find TextView and set weather forecast on it viewHolder.descriptionView.setText(description); // For accessibility, add a content description to the icon field viewHolder.iconView.setContentDescription(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); // Read high temperature from cursor double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high)); // Read low temperature from cursor double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low)); }
From source file:ca.qc.bdeb.info.horus.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 ww . java 2 s . 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()); if (isMetric) { conversion = " C"; } else { conversion = " F"; } mScrollView.setBackgroundResource(Utility.getColorRessourceForWeatherCondition(weatherId)); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString + conversion); // 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 + conversion); // 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()); } if (weatherId > 199 && weatherId < 782) { changerTexteCouleur(); } } }
From source file:com.example.talonso.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getArtResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*from w ww . j a va2 s . c om*/ } case VIEW_TYPE_FUTURE_DAY: { // Get weather icon viewHolder.iconView.setImageResource(Utility .getIconResourceForWeatherCondition(cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } // Read date from cursor long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE); // Find TextView and set formatted date on it viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); // Read weather forecast from cursor String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC); // Find TextView and set weather forecast on it viewHolder.descriptionView.setText(description); // For accessibility, add a content description to the icon field viewHolder.iconView.setContentDescription(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); // Read high temperature from cursor double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high, isMetric)); // Read low temperature from cursor double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low, isMetric)); }
From source file:com.example.mihai.inforoute.app.ForecastFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (loader.getId() == 0) { if (!cursor.moveToFirst()) { return; }// w w w . j a v a 2 s. c om mForecastAdapter.swapCursor(cursor); } else { if (!cursor.moveToFirst()) { return; } TextView text_dist = (TextView) getView().findViewById(R.id.list_item_distance_textview); TextView text_status = (TextView) getView().findViewById(R.id.list_item_status_textview); TextView text_speed = (TextView) getView().findViewById(R.id.list_item_speed_textview); TextView text_time = (TextView) getView().findViewById(R.id.list_item_time_textview); TextView text_cons = (TextView) getView().findViewById(R.id.list_item_consum_textview); TextView text_totalCons = (TextView) getView().findViewById(R.id.list_item_consum_total_textview); TextView text_cost = (TextView) getView().findViewById(R.id.list_item_cost_textview); TextView text_index = (TextView) getView().findViewById(R.id.list_item_index_textview); // Extract properties from cursor int distance = cursor.getInt(0); String status = cursor.getString(1); int speed = cursor.getInt(2); double time = cursor.getDouble(3); int consumption = cursor.getInt(4); double tConsumption = cursor.getDouble(5); int cost = cursor.getInt(6); double indice = cursor.getDouble(7); // Populate fields with extracted properties text_dist.setText(Integer.toString(distance) + " Km"); text_status.setText(status); //TODO //sa utilizez shared preferences pentru a afisa in km/h sau m/s text_speed.setText(Integer.toString(speed) + " Km/h"); text_time.setText(formatTime(Double.toString(time))); text_cons.setText(Integer.toString(consumption) + " l/Km"); text_totalCons.setText(Double.toString(tConsumption) + " l"); text_cost.setText(Integer.toString(cost) + " RON"); text_index.setText(Double.toString(indice)); } //mRouteAdapter.swapCursor(data); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getFavoritesForString(String srchString) { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID };/*w ww . ja va2 s . co m*/ Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " LIKE ? ", new String[] { "%" + srchString + "%" }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add((SearchListItem) fd); cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }