List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java
private Vector<String> getTripData(long tripId) { Vector<String> tripData = new Vector<String>(); mDb.openReadOnly();//from www. java2s .co m Cursor tripCursor = mDb.fetchTrip(tripId); String note = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_NOTE)); String purpose = tripCursor.getString(tripCursor.getColumnIndex(DbAdapter.K_TRIP_PURP)); Double startTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_START)); Double endTime = tripCursor.getDouble(tripCursor.getColumnIndex(DbAdapter.K_TRIP_END)); tripCursor.close(); mDb.close(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); tripData.add(note); tripData.add(purpose); tripData.add(df.format(startTime)); tripData.add(df.format(endTime)); return tripData; }
From source file:br.com.anteros.android.persistence.backup.DatabaseMaintenanceFragment.java
private Object getObjectValue(Cursor cursor, int columnIndex) throws SQLException { switch (SQLiteResultSet.getDataType((SQLiteCursor) cursor, columnIndex)) { case SQLiteResultSet.FIELD_TYPE_INTEGER: long val = cursor.getLong(columnIndex); if (val > Integer.MAX_VALUE || val < Integer.MIN_VALUE) { return new Long(val); } else {/*from ww w . ja va2 s.co m*/ return new Integer((int) val); } case SQLiteResultSet.FIELD_TYPE_FLOAT: return new Double(cursor.getDouble(columnIndex)); case SQLiteResultSet.FIELD_TYPE_BLOB: return cursor.getBlob(columnIndex); case SQLiteResultSet.FIELD_TYPE_NULL: return null; case SQLiteResultSet.FIELD_TYPE_STRING: default: return cursor.getString(columnIndex); } }
From source file:info.wncwaterfalls.app.InformationMapFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { int loaderId = loader.getId(); if (cursor.moveToFirst()) { switch (loaderId) { case InformationMapFragment.WATERFALL_QUERY_LOADER: // Get some data from the db mLat = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lat")); mLon = cursor.getDouble(AttrDatabase.COLUMNS.indexOf("geo_lon")); mName = cursor.getString(AttrDatabase.COLUMNS.indexOf("name")); mMapName = cursor.getString(AttrDatabase.COLUMNS.indexOf("map_name")); // Now that we have what we need... setupMap();//from w w w . j a v a 2 s . c o m break; } } }
From source file:com.acl.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader and use it to populate the ListView it's attached to. mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null, // the column names to use to fill the textviews new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC, WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP }, // the textviews to fill with the data pulled from the columns above new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview, R.id.list_item_high_textview, R.id.list_item_low_textview }, 0);/*from w ww. j a v a2s . co m*/ mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { boolean isMetric = Utility.isMetric(getActivity()); switch (columnIndex) { case COL_WEATHER_MAX_TEMP: case COL_WEATHER_MIN_TEMP: { // we have to do some formatting and possibly a conversion ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric)); return true; } case COL_WEATHER_DATE: { String dateString = cursor.getString(columnIndex); TextView dateView = (TextView) view; dateView.setText(Utility.formatDate(dateString)); return true; } } return false; } }); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { String dateString = Utility.formatDate(cursor.getString(COL_WEATHER_DATE)); String weatherDescription = cursor.getString(COL_WEATHER_DESC); boolean isMetric = Utility.isMetric(getActivity()); String high = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MAX_TEMP), isMetric); String low = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MIN_TEMP), isMetric); String detailString = String.format("%s - %s - %s/%s", dateString, weatherDescription, high, low); Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, detailString); startActivity(intent); } } }); return rootView; }
From source file:org.xbmc.kore.ui.sections.video.TVShowInfoFragment.java
/** {@inheritDoc} */ @Override/* w ww . j a v a2 s . c om*/ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { if (cursor != null) { switch (cursorLoader.getId()) { case LOADER_TVSHOW: cursor.moveToFirst(); DataHolder dataHolder = getDataHolder(); dataHolder.setFanArtUrl(cursor.getString(TVShowDetailsQuery.FANART)); dataHolder.setPosterUrl(cursor.getString(TVShowDetailsQuery.THUMBNAIL)); dataHolder.setRating(cursor.getDouble(TVShowDetailsQuery.RATING)); dataHolder.setMaxRating(10); String premiered = cursor.getString(TVShowDetailsQuery.PREMIERED); String studio = cursor.getString(TVShowDetailsQuery.STUDIO); dataHolder.setDetails(String.format(getString(R.string.premiered), premiered) + " | " + studio + "\n" + cursor.getString(TVShowDetailsQuery.GENRES)); dataHolder.setTitle(cursor.getString(TVShowDetailsQuery.TITLE)); int numEpisodes = cursor.getInt(TVShowDetailsQuery.EPISODE), watchedEpisodes = cursor.getInt(TVShowDetailsQuery.WATCHEDEPISODES); dataHolder.setUndertitle(String.format(getString(R.string.num_episodes), numEpisodes, numEpisodes - watchedEpisodes)); dataHolder.setDescription(cursor.getString(TVShowDetailsQuery.PLOT)); updateView(dataHolder); checkOutdatedTVShowDetails(cursor); break; } } }
From source file:tech.rithm.udacitysunwearable.MainActivity.java
/** * Called when a Loader has finished loading its data. * * NOTE: There is one small bug in this code. If no data is present in the cursor do to an * initial load being performed with no access to internet, the loading indicator will show * indefinitely, until data is present from the ContentProvider. This will be fixed in a * future version of the course./*w w w. j ava 2 s .c o m*/ * * @param loader The Loader that has finished. * @param data The data generated by the Loader. */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { double max_temp; double min_temp; if (data != null && data.moveToFirst()) { max_temp = data.getDouble(INDEX_WEATHER_MAX_TEMP); min_temp = data.getDouble(INDEX_WEATHER_MIN_TEMP); weatherId = data.getInt(INDEX_WEATHER_CONDITION_ID); maxTemp = SunshineWeatherUtils.formatTemperature(this, max_temp); minTemp = SunshineWeatherUtils.formatTemperature(this, min_temp); weatherImageId = SunshineWeatherUtils.getSmallArtResourceIdForWeatherCondition(weatherId); weatherDescription = SunshineWeatherUtils.getStringForWeatherCondition(this, weatherId); sendWeather(); } mForecastAdapter.swapCursor(data); if (mPosition == RecyclerView.NO_POSITION) mPosition = 0; mRecyclerView.smoothScrollToPosition(mPosition); if (data != null && data.getCount() != 0) showWeatherDataView(); }
From source file:com.josenaves.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The SimpleCursorAdapter will take data from the database through the // Loader and use it to populate the ListView it's attached to. mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null, // the column names to use to fill the textviews new String[] { WeatherContract.WeatherEntry.COLUMN_DATETEXT, WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, WeatherContract.WeatherEntry.COLUMN_MIN_TEMP }, // the textviews to fill with the data pulled from the columns above new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview, R.id.list_item_high_textview, R.id.list_item_low_textview }, 0);//from ww w.j a v a2 s .c o m mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { boolean isMetric = Utility.isMetric(getActivity()); switch (columnIndex) { case COL_WEATHER_MAX_TEMP: case COL_WEATHER_MIN_TEMP: { // we have to do some formatting and possibly a conversion ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric)); return true; } case COL_WEATHER_DATE: { String dateString = cursor.getString(columnIndex); TextView dateView = (TextView) view; dateView.setText(Utility.formatDate(dateString)); return true; } } return false; } }); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { SimpleCursorAdapter adapter = (SimpleCursorAdapter) adapterView.getAdapter(); Cursor cursor = adapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { String dateString = Utility.formatDate(cursor.getString(COL_WEATHER_DATE)); String weatherDescription = cursor.getString(COL_WEATHER_DESC); boolean isMetric = Utility.isMetric(getActivity()); String high = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MAX_TEMP), isMetric); String low = Utility.formatTemperature(cursor.getDouble(COL_WEATHER_MIN_TEMP), isMetric); String detailString = String.format("%s - %s - %s/%s", dateString, weatherDescription, high, low); Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, detailString); startActivity(intent); } } }); return rootView; }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
private TestResult cursorToTestResult(Cursor cursor) { long id = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_ID)); String type = cursor.getString(columnIdx.get(SKSQLiteHelper.TR_COLUMN_TYPE)); long dtime = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_DTIME)); String location = cursor.getString(columnIdx.get(SKSQLiteHelper.TR_COLUMN_LOCATION)); long success = cursor.getLong(columnIdx.get(SKSQLiteHelper.TR_COLUMN_SUCCESS)); double result = cursor.getDouble(columnIdx.get(SKSQLiteHelper.TR_COLUMN_RESULT)); return new TestResult(type, dtime, location, success, result); }
From source file:com.example.shutapp.DatabaseHandler.java
/** * Reads the database for a chatroom.// ww w . ja v a 2 s . c om * @param name of the chatroom * @return the chatroom object */ public Chatroom getChatroom(String name) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CHATROOMS, new String[] { KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE, KEY_RADIUS }, KEY_NAME + "=?", new String[] { name }, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); } Chatroom chatroom = new Chatroom(cursor.getString(0), cursor.getDouble(1), cursor.getDouble(2), cursor.getFloat(StringLiterals.THREE)); // return chatroom return chatroom; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public ArrayList<TrafficData> getAllTrafficFromDate(String date, int typeID) { ArrayList<TrafficData> list = new ArrayList<TrafficData>(); String q = "SELECT * FROM " + LocalTransformationDB.TABLE_TRAFFIC_MON // + ";";/* w ww . j ava 2 s . co m*/ + " where( " + LocalTransformationDB.COLUMN_DATE_TEXT + " like '" + date + "%' AND " + LocalTransformationDB.COLUMN_TYPE + " = " + typeID + ")" + " ORDER BY " + LocalTransformationDB.COLUMN_ID + ";"; Cursor cursor = database.rawQuery(q, null); if (cursor.moveToFirst()) { do { TrafficData trafficData = new TrafficData( cursor.getString(cursor.getColumnIndex(LocalTransformationDB.COLUMN_DATE_TEXT)), cursor.getInt(cursor.getColumnIndex(LocalTransformationDB.COLUMN_TYPE)), cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_X_AXIS)), cursor.getDouble(cursor.getColumnIndex(LocalTransformationDB.COLUMN_Y_AXIS))); list.add(trafficData); } while (cursor.moveToNext()); } cursor.close(); return list; }