List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.google.android.demos.jamendo.app.JamendoListActivity.java
/** {@inheritDoc} */ public void onItemClick(AdapterView<?> l, View v, int position, long id) { Uri contentUri = getIntent().getData(); Uri uri = ContentUris.withAppendedId(contentUri, id); startActivity(new Intent(Intent.ACTION_VIEW, uri)); }
From source file:at.bitfire.ical4android.AndroidEvent.java
public Event getEvent() throws FileNotFoundException, CalendarStorageException { if (event != null) return event; try {/*w w w .j av a 2s .c om*/ @Cleanup EntityIterator iterEvents = CalendarContract.EventsEntity.newEntityIterator(calendar.provider.query( calendar.syncAdapterURI( ContentUris.withAppendedId(CalendarContract.EventsEntity.CONTENT_URI, id)), null, null, null, null), calendar.provider); if (iterEvents.hasNext()) { event = new Event(); Entity e = iterEvents.next(); populateEvent(e.getEntityValues()); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { if (Attendees.CONTENT_URI.equals(subValue.uri)) populateAttendee(subValue.values); if (Reminders.CONTENT_URI.equals(subValue.uri)) populateReminder(subValue.values); } populateExceptions(); return event; } else throw new FileNotFoundException("Locally stored event couldn't be found"); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't read locally stored event", e); } }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
/** * Marks all members of the current group as dirty. *//*ww w.ja va 2 s. c o m*/ public void markMembersDirty() throws ContactsStorageException { assertID(); BatchOperation batch = new BatchOperation(addressBook.provider); for (long member : getMembers()) batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newUpdate( addressBook.syncAdapterURI(ContentUris.withAppendedId(RawContacts.CONTENT_URI, member))) .withValue(RawContacts.DIRTY, 1).withYieldAllowed(true))); batch.commit(); }
From source file:com.google.android.apps.muzei.SourceSubscriberService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null || intent.getAction() == null) { return;//from w ww . ja v a 2s .com } String action = intent.getAction(); if (!ACTION_PUBLISH_STATE.equals(action)) { return; } // Handle API call from source String token = intent.getStringExtra(EXTRA_TOKEN); ComponentName selectedSource = SourceManager.getSelectedSource(this); if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) { Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for " + selectedSource); return; } SourceState state = null; if (intent.hasExtra(EXTRA_STATE)) { Bundle bundle = intent.getBundleExtra(EXTRA_STATE); if (bundle != null) { state = SourceState.fromBundle(bundle); } } if (state == null) { // If there is no state, there is nothing to change return; } ContentValues values = new ContentValues(); values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString()); values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true); values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription()); values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable()); JSONArray commandsSerialized = new JSONArray(); int numSourceActions = state.getNumUserCommands(); boolean supportsNextArtwork = false; for (int i = 0; i < numSourceActions; i++) { UserCommand command = state.getUserCommandAt(i); if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) { supportsNextArtwork = true; } else { commandsSerialized.put(command.serialize()); } } values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork); values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString()); ContentResolver contentResolver = getContentResolver(); Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { selectedSource.flattenToShortString() }, null, null); if (existingSource != null && existingSource.moveToFirst()) { Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, existingSource.getLong(0)); contentResolver.update(sourceUri, values, null, null); } else { contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values); } if (existingSource != null) { existingSource.close(); } Artwork artwork = state.getCurrentArtwork(); if (artwork != null) { artwork.setComponentName(selectedSource); contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues()); // Download the artwork contained from the newly published SourceState startService(TaskQueueService.getDownloadCurrentArtworkIntent(this)); } }
From source file:com.android.talkback.labeling.LabelProvider.java
/** * Inserts a label in the labels database. * * @param uri The content URI for labels. * @param values The values to insert for the new label. * @return The URI of the newly inserted label, * or {@code null} if the insert failed. *///from ww w. j a v a 2 s. c om @Override public Uri insert(Uri uri, ContentValues values) { if (uri == null) { LogUtils.log(this, Log.WARN, NULL_URI_FORMAT_STRING); return null; } if (!UserManagerCompat.isUserUnlocked(getContext())) { return null; } switch (sUriMatcher.match(uri)) { case LABELS: initializeDatabaseIfNull(); if (values == null) { return null; } if (values.containsKey(LabelsTable.KEY_ID)) { LogUtils.log(this, Log.WARN, "Label ID must be assigned by the database."); return null; } long rowId = mDatabase.insert(LabelsTable.TABLE_NAME, null, values); if (rowId < 0) { LogUtils.log(this, Log.WARN, "Failed to insert label."); return null; } else { return ContentUris.withAppendedId(LABELS_CONTENT_URI, rowId); } default: LogUtils.log(this, Log.WARN, UNKNOWN_URI_FORMAT_STRING, uri); return null; } }
From source file:com.google.android.apps.paco.FindMyExperimentsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.find_experiments, null); setContentView(mainLayout);//w w w . j a v a 2 s . c om Intent intent = getIntent(); if (intent.getData() == null) { intent.setData(ExperimentColumns.CONTENT_URI); } userPrefs = new UserPreferences(this); list = (ListView) findViewById(R.id.find_experiments_list); createListHeader(); createRefreshHeader(); experimentProviderUtil = new ExperimentProviderUtil(this); refreshButton = (Button) findViewById(R.id.RefreshExperimentsButton2); refreshButton.setVisibility(View.VISIBLE); refreshButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (!isConnected()) { showDialogById(DownloadHelper.NO_NETWORK_CONNECTION); } else { refreshList(); } } }); progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar); reloadAdapter(); list.setItemsCanFocus(true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> listview, View textview, int position, long id) { Experiment experiment = experiments.get(position); Uri uri = ContentUris.withAppendedId(getIntent().getData(), experiment.getServerId()); String action = getIntent().getAction(); if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { // The caller is waiting for us to return an experiment selected by // the user. The have clicked on one, so return it now. setResult(RESULT_OK, new Intent().setData(uri)); } else { Intent experimentIntent = new Intent(FindMyExperimentsActivity.this, ExperimentDetailActivity.class); experimentIntent.setData(uri); experimentIntent.putExtra(ExperimentDetailActivity.ID_FROM_MY_EXPERIMENTS_FILE, true); startActivityForResult(experimentIntent, JOIN_REQUEST_CODE); } } }); registerForContextMenu(list); }
From source file:com.codebutler.farebot.activities.MainActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { Uri uri = ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD, id); startActivity(new Intent(Intent.ACTION_VIEW, uri)); }
From source file:com.bangz.smartmute.RulelistActivity.java
@Override public void onRuleItemSelected(long id, int ruletype) { Uri uri = ContentUris.withAppendedId(RulesColumns.CONTENT_URI, id); Intent intent = new Intent(); intent.setData(uri);//from www . java2s. c o m switch (ruletype) { case RulesColumns.RT_LOCATION: intent.setClass(this, LocationRuleEditActivity.class); intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT); break; case RulesColumns.RT_WIFI: intent.setClass(this, WifiEditActivity.class); intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT); break; case RulesColumns.RT_TIME: intent.setClass(this, TimeRuleEditActivity.class); intent.putExtra(Constants.INTENT_EDITORNEW, Constants.INTENT_EDIT); break; } startActivity(intent); }
From source file:com.google.android.apps.paco.FindExperimentsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.find_experiments, null); setContentView(mainLayout);/*w w w.ja v a 2s . co m*/ Intent intent = getIntent(); if (intent.getData() == null) { intent.setData(ExperimentColumns.CONTENT_URI); } userPrefs = new UserPreferences(this); list = (ListView) findViewById(R.id.find_experiments_list); createListHeader(); createRefreshHeader(); experimentProviderUtil = new ExperimentProviderUtil(this); refreshButton = (Button) findViewById(R.id.RefreshExperimentsButton2); refreshButton.setVisibility(View.VISIBLE); refreshButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (!isConnected()) { showDialogById(DownloadHelper.NO_NETWORK_CONNECTION); } else { refreshList(); } } }); progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar); reloadAdapter(); list.setItemsCanFocus(true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> listview, View textview, int position, long id) { Experiment experiment = experiments.get(position); Uri uri = ContentUris.withAppendedId(getIntent().getData(), experiment.getServerId()); String action = getIntent().getAction(); if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { // The caller is waiting for us to return an experiment selected by // the user. The have clicked on one, so return it now. setResult(RESULT_OK, new Intent().setData(uri)); } else { Intent experimentIntent = new Intent(FindExperimentsActivity.this, ExperimentDetailActivity.class); experimentIntent.setData(uri); startActivityForResult(experimentIntent, JOIN_REQUEST_CODE); } } }); registerForContextMenu(list); }