List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:com.msrproduction.sunshine.app.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/*from w w w . jav a 2s . 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; 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.moveToNext()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); 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); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:com.udacity.sunshine.FetchWeatherTask.java
private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); String[] projection = { LocationEntry._ID }; // whichever column doesn't matter, but don't need to return all String[] selectionArgs = { locationSetting }; String selection = LocationEntry.COLUMN_LOCATION_SETTING + " = ? "; // Check to see if location setting exists in db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, projection, selection, selectionArgs, null);//from w w w. j av a 2 s . com long locationRowId; if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); locationRowId = 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 locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); locationRowId = ContentUris.parseId(locationUri); } cursor.close(); return locationRowId; }
From source file:com.swisscom.android.sunshine.data.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 w w . ja 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_SETTINGS + " = ?", 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_SETTINGS, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_LATITUDE, lat); locationValues.put(LocationEntry.COLUMN_LONGITUDE, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:com.google.android.demos.jamendo.app.AlbumActivity.java
/** {@inheritDoc} */ public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) { switch (loaderId) { case LOADER_HEADER: { Uri uri = getIntent().getData(); String[] projection = { Albums._ID, Albums.ID, Albums.IMAGE, Albums.NAME, Artists.NAME, Artists.ID, Albums.GENRE };/*from w w w .j a v a 2 s . co m*/ String selection = String.format("%s=?", JamendoContract.PARAM_IMAGE_SIZE); String[] selectionArgs = { getDimensionPixelSizeAsString(R.dimen.image_size) }; String sortOrder = null; return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder); } case LOADER_LIST: { Uri uri = Tracks.CONTENT_URI; String[] projection = TrackListAdapter.PROJECTION; // Join the track query to the artist table so that the artist is known // even if the album cursor fails. String selection = String.format("%s=?&%s=?&%s=?", JamendoContract.PARAM_JOIN, JamendoContract.PARAM_JOIN, Albums.ID); Uri albumUri = getIntent().getData(); long albumId = ContentUris.parseId(albumUri); String[] selectionArgs = { JamendoContract.JOIN_TRACK_ALBUM, JamendoContract.JOIN_ALBUM_ARTIST, String.valueOf(albumId) }; String sortOrder = Tracks.Order.NUMALBUM.ascending(); return new CursorLoader(this, uri, projection, selection, selectionArgs, sortOrder); } default: return null; } }
From source file:emroxriprap.com.sunshine.app.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 av a2 s. c om * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; //check to see if this location already exists 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 locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIndex); } else { ContentValues locationValues = new ContentValues(); 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); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:org.sufficientlysecure.localcalendar.ui.EditActivity.java
@SuppressLint("NewApi") @Override// w w w . j a v a 2 s .c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit); displayNameEditText = (EditText) findViewById(R.id.edit_activity_text_cal_name); colorPicker = (ColorPicker) findViewById(R.id.edit_activity_color_picker); svBar = (SVBar) findViewById(R.id.edit_activity_svbar); colorPicker.addSVBar(svBar); // check if add new or edit existing Intent intent = getIntent(); Uri calendarUri = intent.getData(); if (calendarUri != null) { edit = true; } if (edit) { // edit calendar setTitle(R.string.edit_activity_name_edit); Cursor cur = getContentResolver().query(calendarUri, CalendarController.PROJECTION, null, null, null); mCalendarId = ContentUris.parseId(calendarUri); try { if (cur.moveToFirst()) { String displayName = cur.getString(CalendarController.PROJECTION_DISPLAY_NAME_INDEX); int color = cur.getInt(CalendarController.PROJECTION_COLOR_INDEX); // display for editing displayNameEditText.setText(displayName); setColor(color); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } } else { // new calendar setTitle(R.string.edit_activity_name_new); setColor(getResources().getColor(R.color.emphasis)); // on calendar creation, set both center colors to new color colorPicker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() { @Override public void onColorChanged(int color) { colorPicker.setOldCenterColor(color); } }); } // Based on Android version use ButtonBar on bottom or use custom Actionbar layout if (android.os.Build.VERSION.SDK_INT >= 11) { if (edit) { ActionBarHelper.setDoneView(getActionBar(), new OnClickListener() { @Override public void onClick(View view) { save(); } }); } else { ActionBarHelper.setDoneCancelView(getActionBar(), new OnClickListener() { @Override public void onClick(View view) { save(); } }, new OnClickListener() { @Override public void onClick(View view) { finish(); } }); } } else { // Android < 3.0 editButtons = (LinearLayout) findViewById(R.id.edit_activity_edit_buttons); deleteButton = (Button) findViewById(R.id.edit_activity_delete); importExportButton = (Button) findViewById(R.id.edit_activity_import_export); cancelButton = (Button) findViewById(R.id.edit_activity_cancel); saveButton = (Button) findViewById(R.id.edit_activity_save); if (edit) { editButtons.setVisibility(View.VISIBLE); } deleteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { delete(); } }); importExportButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { importExport(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); saveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { save(); } }); } // remove error when characters are entered displayNameEditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { displayNameEditText.setError(null); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); }
From source file:com.riasayu.gosuke.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/*from w w w. j a va 2s .co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ public 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 locationRowId = -1; Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { locationRowId = cursor.getLong(cursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); Uri locationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationRowId = ContentUris.parseId(locationUri); } return locationRowId; }
From source file:com.girnarsoft.android.shunshine.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/*from www . j av a 2 s . c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "=?", new String[] { locationSetting }, null); long location = 0; if (cursor.getCount() > 0) { cursor.moveToFirst(); location = cursor.getLong(cursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); location = ContentUris.parseId(uri); } return location; }
From source file:com.example.danstormont.sunshine.app.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//from ww w . j ava 2 s. c o 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()) { int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { 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:com.groupe1.miage.ujf.tracestaroute.FetchTrackTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from ww w. j a va 2 s .c om * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String cityName, double lat, double lon) { long locationId; // On regarde si la location avec nom de ville, x et y existe dja Cursor locationCursor = mContext.getContentResolver().query(TrackContract.LocationEntry.CONTENT_URI, new String[] { TrackContract.LocationEntry._ID }, TrackContract.LocationEntry.COLUMN_LOC_CITY + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT + " = ? AND " + TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG + " = ?", new String[] { cityName, String.valueOf(lat), String.valueOf(lon) }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(TrackContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { //Cration du lieu ContentValues locationValues = new ContentValues(); //Ajout des informations locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_CITY, cityName); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LAT, lat); locationValues.put(TrackContract.LocationEntry.COLUMN_LOC_COORD_LONG, lon); //Insertion dans la BD Uri insertedUri = mContext.getContentResolver().insert(TrackContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }