List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.aafr.alfonso.sunshine.app.service.SunshineService.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city// w w w . jav a 2 s. co m * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor locationCursor = this.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = this.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } // Always close our cursor if (null != locationCursor) locationCursor.close(); // Wait, that worked? Yes! return locationId; }
From source file:com.ichi2.libanki.Tags.java
/** * FIXME: This method must be fixed before it is used. Its behaviour is currently incorrect. * This method is currently unused in AnkiDroid so it will not cause any errors in its current state. *//* w w w. j av a 2s . co m*/ public void bulkAdd(List<Long> ids, String tags, boolean add) { List<String> newTags = split(tags); if (newTags == null || newTags.isEmpty()) { return; } // cache tag names register(newTags); // find notes missing the tags String l; if (add) { l = "tags not "; } else { l = "tags "; } StringBuilder lim = new StringBuilder(); for (String t : newTags) { if (lim.length() != 0) { lim.append(" or "); } lim.append(l).append("like '% ").append(t).append(" %'"); } Cursor cur = null; List<Long> nids = new ArrayList<Long>(); ArrayList<Object[]> res = new ArrayList<Object[]>(); try { cur = mCol.getDb().getDatabase().rawQuery( "select id, tags from notes where id in " + Utils.ids2str(ids) + " and (" + lim + ")", null); if (add) { while (cur.moveToNext()) { nids.add(cur.getLong(0)); res.add(new Object[] { addToStr(tags, cur.getString(1)), Utils.intNow(), mCol.usn(), cur.getLong(0) }); } } else { while (cur.moveToNext()) { nids.add(cur.getLong(0)); res.add(new Object[] { remFromStr(tags, cur.getString(1)), Utils.intNow(), mCol.usn(), cur.getLong(0) }); } } } finally { if (cur != null) { cur.close(); } } // update tags mCol.getDb().executeMany("update notes set tags=:t,mod=:n,usn=:u where id = :id", res); }
From source file:com.android.browser.BookmarksPageCallbacks.java
private void openInNewWindow(BrowserBookmarksAdapter adapter, int position) { if (mCallbacks != null) { Cursor c = adapter.getItem(position); boolean isFolder = c.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) == 1; if (isFolder) { long id = c.getLong(BookmarksLoader.COLUMN_INDEX_ID); new OpenAllInTabsTask(id).execute(); } else {// ww w . j a v a 2 s . c o m mCallbacks.onOpenInNewWindow(BrowserBookmarksPage.getUrl(c)); } } }
From source file:com.kwang.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*w ww.j a v a 2s.co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:app.com.example.android.sunshine.FetchWeatherTask.java
long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI long locationId; SQLiteDatabase db = new WeatherDbHelper(this.mContext).getWritableDatabase(); Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " =? ", new String[] { locationSetting }, null);//from w ww. j a va2 s.c om if (locationCursor.moveToFirst()) { int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIndex); } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** * Finds new resources (resources which haven't been uploaded yet). * New resources are 1) dirty, and 2) don't have an ETag yet. * Only records matching sqlFilter will be returned. * // www. j a v a 2s . c o m * @return IDs of new resources * @throws LocalStorageException when the content provider couldn't be queried */ public long[] findNew() throws LocalStorageException { String where = entryColumnDirty() + "=1 AND " + entryColumnETag() + " IS NULL"; if (entryColumnParentID() != null) where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId()); if (sqlFilter != null) where += " AND (" + sqlFilter + ")"; try { @Cleanup Cursor cursor = providerClient.query(entriesURI(), new String[] { entryColumnID() }, where, null, null); if (cursor == null) throw new LocalStorageException("Couldn't query new records"); long[] fresh = new long[cursor.getCount()]; for (int idx = 0; cursor.moveToNext(); idx++) { long id = cursor.getLong(0); // new record: we have to generate UID + remote file name for uploading T resource = findById(id, false); resource.initialize(); // write generated UID + remote file name into database ContentValues values = new ContentValues(2); values.put(entryColumnUID(), resource.getUid()); values.put(entryColumnRemoteName(), resource.getName()); providerClient.update(ContentUris.withAppendedId(entriesURI(), id), values, null, null); fresh[idx] = id; } return fresh; } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:com.example.rafa.sunshine.app.service.SunshineService.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/* ww w. jav a 2 s . c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; // First, check if the location with this city name exists in the db Cursor locationCursor = this.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues( ); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = this.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }
From source file:com.hhunj.hhudata.SearchBookContentsActivity.java
public void updatedb(List<SearchBookContentsResult> items) { int max_alarm_time_span = 60; ContentResolver resolver = getApplicationContext().getContentResolver(); ContentValues values = new ContentValues(); for (int i = 0; i < items.size(); i++) { SearchBookContentsResult res = items.get(i); long stationid = Long.parseLong(res.getPageNumber()); values.put(NotePad.Notes.TITLE, res.getName()); values.put(NotePad.Notes.NOTE, ""); values.put(NotePad.Notes.LONGITUTE, 108.0); values.put(NotePad.Notes.LATITUDE, 32.0); values.put(NotePad.Notes.SPEED, 55); values.put(NotePad.Notes.ALTITUDE, 55); values.put(NotePad.Notes.CREATEDDATE, res.getRectime().getTime()); values.put(NotePad.Notes._ID, stationid);//id Uri urlNote = NotePad.Notes.CONTENT_URI; Uri myUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, stationid); Cursor cur = resolver.query(myUri, NotePad.Notes.PROJECTION, null, null, null); if (cur != null && cur.moveToFirst()) { try { long id = cur.getLong(NotePad.Notes._ID_COLUMN); Date oldtime = new Date(cur.getLong(cur.getColumnIndex(NotePad.Notes.CREATEDDATE))); boolean oldalarm = (cur.getInt(NotePad.Notes.ALARM_COLUMN) == 0) ? false : true; long dif = (res.getRectime().getTime() - oldtime.getTime()) / (60 * 1000); dif = ((new Date()).getTime() - oldtime.getTime()) / (60 * 1000); if (dif > max_alarm_time_span) { //... if (oldalarm == false) { Log.w(TAG, "over time err--------"); String phoneNumber = "13338620269"; String message = "over time err--------"; sendSMS(phoneNumber, message); values.put(NotePad.Notes.ALARM, true); }//from ww w .j a va 2 s . c o m } else { values.put(NotePad.Notes.ALARM, false); } } catch (Exception e) { int aa = 0; } int count = resolver.update(myUri, values, null, null); // resolver.update( myUri, values, NotePad.Notes._ID + " = " +res.getPageNumber(), null); if (count == 0) { } } else { try { myUri = resolver.insert(urlNote, values); } catch (IllegalArgumentException e) { throw e; } } } }
From source file:com.andrew.apollo.utils.MusicUtils.java
public static List<Playlist> getPlaylists(final Context context) { final List<Playlist> result = new ArrayList<>(); final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.PlaylistsColumns.NAME }; try {//from w w w . j av a 2s . c o m final Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, null, null, null); if (cursor != null) { if (cursor.moveToFirst()) { do { result.add(new Playlist(cursor.getLong(0), cursor.getString(1))); } while (cursor.moveToNext()); } cursor.close(); } } catch (Throwable e) { LOG.error("Could not fetch playlists", e); } return result; }
From source file:br.com.dgimenes.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*ww w. j a v a 2 s . co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; // First, check if the location with this city name exists in the db Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }