List of usage examples for android.content ContentUris parseId
public static long parseId(Uri contentUri)
From source file:fr.eoidb.activity.MarketGroupListActivity.java
/** Called when the activity is first created. */ @Override/*from ww w . j av a 2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.market_group_list); Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { // handles a search query query = intent.getStringExtra(SearchManager.QUERY); showResults(); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { // handles a click on a search suggestion; launches activity to show word Intent itemIntent = new Intent(this, ItemInfoActivity.class); itemIntent.setData(intent.getData()); startActivity(itemIntent); finish(); } else { // If there is no data associated with the Intent, sets the data to the default URI, which // accesses a list of notes. if (intent.getData() == null) { intent.setData(MarketGroups.CONTENT_URI); } if (getIntent().getData().equals(MarketGroups.CONTENT_URI)) { marketGroupId = -1; } else { marketGroupId = ContentUris.parseId(getIntent().getData()); } // Creates the backing adapter for the ListView. adapter = new SimpleCursorAdapter(this, R.layout.market_group_row, null, dataColumns, viewIDs, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); adapter.setViewBinder(new MarketGroupListViewBinder(false)); ListView itemListView = (ListView) findViewById(R.id.market_group_list); itemListView.setOnItemClickListener(new MarketGroupOnItemListClickListener()); // Sets the ListView's adapter to be the cursor adapter that was just created. itemListView.setAdapter(adapter); getSupportLoaderManager().initLoader(LOADER_ID, null, this); } }
From source file:ru.getlect.sunshine.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 . ja va2 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 { // 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 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(); return locationId; }
From source file:com.makotosan.vimeodroid.TransferService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { counter++;/*www . ja va2s. c om*/ transfer = new Transfer(); final String videoUri = intent.getStringExtra("videouri"); final TransferType transferType = TransferType.valueOf(intent.getStringExtra("transferType")); final String fileName = intent.getStringExtra("fileName"); Bitmap bitmapThumbnail = null; int transferIcon = android.R.drawable.stat_sys_download; if (transferType == TransferType.Upload) { // Get the resource ID for the video final long resourceId = ContentUris.parseId(Uri.parse(videoUri)); bitmapThumbnail = android.provider.MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), resourceId, android.provider.MediaStore.Video.Thumbnails.MICRO_KIND, null); transfer.setIcon(bitmapThumbnail); transferIcon = android.R.drawable.stat_sys_upload; } // Initialize our notification final Notification notification = new Notification(transferIcon, "Transferring...", System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.contentView = new RemoteViews(this.getPackageName(), R.layout.transferprogress); final Intent manageIntent = new Intent(this, ManageTransfersActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, manageIntent, 0); notification.contentIntent = pendingIntent; if (bitmapThumbnail != null) { notification.contentView.setImageViewBitmap(R.id.transferprogressIcon, bitmapThumbnail); } else { notification.contentView.setImageViewResource(R.id.transferprogressIcon, R.drawable.icon); } notification.contentView.setProgressBar(R.id.transferprogressBar, 100, 0, false); notification.contentView.setTextViewText(R.id.transferprogressText, "Transferring... "); notification.contentView.setOnClickPendingIntent(R.layout.transferprogress, pendingIntent); // Add it to the collection of notifications notifications.put(counter, notification); // Add our notification to the notification tray notificationManager.notify(counter, notification); // Initialize our asynchronous transfer task final TransferTask task = new TransferTask(counter, transferType); task.execute(videoUri, fileName); return Service.START_STICKY; }
From source file:com.tigerbase.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 w w . j a v a2 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) { // 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 Log.v(LOG_TAG, "addLocation"); Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); long locationId = 0; if (locationCursor.moveToFirst()) { Log.v(LOG_TAG, "addLocation: Found location"); int idColumnIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(idColumnIndex); } locationCursor.close(); if (locationId > 0) { Log.v(LOG_TAG, "addLocation: Return Location " + locationId); return locationId; } ContentValues newLocationValues = new ContentValues(); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); newLocationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri newLocationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, newLocationValues); locationId = ContentUris.parseId(newLocationUri); Log.v(LOG_TAG, "addLocation: Created location " + locationId); return locationId; }
From source file:com.waageweb.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 w w. j a va 2s . 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) { // Students: 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()) { // If it exists, return the current ID return locationCursor.getLong(locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, "" + lat); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, "" + lon); Uri uriInserted = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); // Otherwise, insert it using the content resolver and the base URI return ContentUris.parseId(uriInserted); } }
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/*from w w w .ja v a2 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 = 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; }
From source file:com.example.mihai.inforoute.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 av a2 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(RouteContract.LocationEntry.CONTENT_URI, new String[] { RouteContract.LocationEntry._ID }, RouteContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(RouteContract.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(RouteContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(RouteContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(RouteContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(RouteContract.LocationEntry.COLUMN_COORD_LONG, lon); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(RouteContract.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(); return locationId; }
From source file:com.google.android.demos.jamendo.app.PlaylistActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); int groupId = MENU_GROUP_INTENT_OPTIONS; int itemId = Menu.NONE; int order = Menu.NONE; ComponentName caller = getComponentName(); Intent[] specifics = null;/* www . j av a 2 s .c o m*/ Intent intent = new Intent(); long id = ContentUris.parseId(getIntent().getData()); intent.setDataAndType(JamendoContract.createPlaylistUri(JamendoContract.FORMAT_M3U, Playlists.ID, id), JamendoContract.CONTENT_TYPE_M3U); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); int flags = 0; MenuItem[] outSpecificItems = null; menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems); return menu.hasVisibleItems(); }
From source file:com.luxtech_eg.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 w w.j a v 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 = 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_LATITUDEE, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_LONGITUDE, 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; }
From source file:com.smarthome.deskclock.Alarms.java
/** * Creates a new Alarm and fills in the given alarm's id. *//*from w ww . ja v a 2s .com*/ public static long addAlarm(Context context, Alarm alarm) { ContentValues values = createContentValues(alarm); Uri uri = context.getContentResolver().insert(Alarm.Columns.CONTENT_URI, values); alarm.id = (int) ContentUris.parseId(uri); long timeInMillis = calculateAlarm(alarm); if (alarm.enabled) { clearSnoozeIfNeeded(context, timeInMillis); } setNextAlert(context); // postAlarmId(context,alarm); return timeInMillis; }