List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.flym.dennikn.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;/* ww w.j a v a 2 s .c o m*/ if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } } break; } case R.id.menu_full_screen: { setImmersiveFullScreen(true); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } } } return true; }
From source file:com.smarthome.deskclock.Alarms.java
/** * A convenience method to set an alarm in the Alarms * content provider./* w ww . jav a 2 s . c o m*/ * @return Time when the alarm will fire. */ public static long setAlarm(Context context, Alarm alarm) { ContentValues values = createContentValues(alarm); ContentResolver resolver = context.getContentResolver(); resolver.update(ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id), values, null, null); long timeInMillis = calculateAlarm(alarm); if (alarm.enabled) { // Disable the snooze if we just changed the snoozed alarm. This // only does work if the snoozed alarm is the same as the given // alarm. // TODO: disableSnoozeAlert should have a better name. disableSnoozeAlert(context, alarm.id); // Disable the snooze if this alarm fires before the snoozed alarm. // This works on every alarm since the user most likely intends to // have the modified alarm fire next. clearSnoozeIfNeeded(context, timeInMillis); } setNextAlert(context); // postAlarmId(context,alarm); return timeInMillis; }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
private static void enableTimeScheduleInternal(final Context context, final TimeSchedule schedule, boolean enabled) { if (schedule == null) { return;/*from w w w . j a va 2 s. c o m*/ } ContentResolver resolver = context.getContentResolver(); ContentValues values = new ContentValues(2); values.put(ENABLED, enabled ? 1 : 0); // If we are enabling the schedule, calculate schedule time since the time // value in TimeSchedule may be old. if (enabled) { long time = 0; if (!schedule.daysOfWeek.isRepeatSet()) { time = calculateTimeSchedule(schedule); } values.put(SCHEDULE_TIME, time); } resolver.update(ContentUris.withAppendedId(CONTENT_URI, schedule.id), values, null, null); }
From source file:com.example.android.cloudnotes.ui.HomeActivity.java
private void viewNote(Intent launchIntent) { final long noteId = launchIntent.getLongExtra(EXTRA_NOTE_ID, -1); showNote(ContentUris.withAppendedId(NotesProvider.CONTENT_URI, noteId)); }
From source file:org.ohmage.sync.ResponseSyncAdapter.java
@Override public synchronized void onPerformSync(Account account, Bundle extras, String authority, final ContentProviderClient provider, final SyncResult syncResult) { Log.d(TAG, "Start onPerformSync()"); // Check for authtoken String token = null;//www . j av a 2s .co m try { token = am.blockingGetAuthToken(account, AuthUtil.AUTHTOKEN_TYPE, true); } catch (OperationCanceledException e) { syncResult.stats.numSkippedEntries++; } catch (IOException e) { syncResult.stats.numIoExceptions++; } catch (AuthenticatorException e) { syncResult.stats.numAuthExceptions++; } // If the token wasn't found or there was a problem, we can stop now if (token == null || syncResult.stats.numSkippedEntries > 0 || syncResult.stats.numIoExceptions > 0 || syncResult.stats.numAuthExceptions > 0) { Log.d(TAG, "No token found or there was a problem."); return; } // Upload responses Observable<Long> toDelete = null; Observable<ResponseFiles> filesToDelete = null; Cursor cursor = null; try { cursor = provider.query(Responses.CONTENT_URI, new String[] { BaseColumns._ID, Responses.SURVEY_ID, Responses.SURVEY_VERSION, Responses.RESPONSE_DATA, Responses.RESPONSE_METADATA, Responses.RESPONSE_EXTRAS }, null, null, null); AppLogManager.getInstance().logInfo(mContext, "ResponsesSyncStarted", cursor.getCount() + " surveys to upload."); while (cursor.moveToNext()) { final ResponseFiles files = gson.fromJson(cursor.getString(5), ResponseFiles.class); try { // Make the call to upload responses Observable<Response> uploadResponse = null; if (Ohmage.USE_DSU_DATAPOINTS_API) { uploadResponse = uploadDatapoint(cursor, files); } else { uploadOhmagePoint(cursor, files); } // Map the data for the upload response to the local id in the db final long localResponseId = cursor.getLong(0); Observable<Long> responseId = uploadResponse.map(new Func1<Response, Long>() { @Override public Long call(Response response) { return localResponseId; } }); if (toDelete == null) { toDelete = responseId; } else { toDelete = Observable.mergeDelayError(responseId, toDelete); } // Map the data for the upload response to the files in the db Observable<ResponseFiles> responseFiles = uploadResponse .map(new Func1<Response, ResponseFiles>() { @Override public ResponseFiles call(Response response) { return files; } }); if (filesToDelete == null) { filesToDelete = responseFiles; } else { filesToDelete = Observable.mergeDelayError(responseFiles, filesToDelete); } } catch (AuthenticationException e) { Crashlytics.logException(e); Log.e(TAG, "Auth", e); syncResult.stats.numAuthExceptions++; } catch (Exception e) { Log.e(TAG, "Other uploading error", e); Crashlytics.logException(e); } } cursor.close(); } catch (RemoteException e) { Log.e(TAG, "Remote", e); Crashlytics.logException(e); syncResult.stats.numIoExceptions++; } finally { if (cursor != null) cursor.close(); } if (toDelete != null) { Log.d(TAG, "Start deleting responses."); toDelete.flatMap(new Func1<Long, Observable<ContentProviderOperation>>() { @Override public Observable<ContentProviderOperation> call(Long aLong) { return Observable.from(ContentProviderOperation.newDelete( appendSyncAdapterParam(ContentUris.withAppendedId(Responses.CONTENT_URI, aLong))) .build()); } }).subscribe(new Subscriber<ContentProviderOperation>() { ArrayList<ContentProviderOperation> toDelete = new ArrayList<ContentProviderOperation>(); @Override public void onCompleted() { try { getContext().getContentResolver().applyBatch(ResponseContract.CONTENT_AUTHORITY, toDelete); } catch (RemoteException e) { syncResult.stats.numIoExceptions++; } catch (OperationApplicationException e) { syncResult.stats.numIoExceptions++; } unsubscribe(); } @Override public void onError(Throwable e) { // Send error report Log.e(TAG, "Upload failed", e); Crashlytics.logException(e); onCompleted(); } @Override public void onNext(ContentProviderOperation args) { toDelete.add(args); } }); } if (filesToDelete != null) { filesToDelete.doOnNext(new Action1<ResponseFiles>() { @Override public void call(ResponseFiles responseFiles) { for (String s : responseFiles.getIds()) { responseFiles.getFile(s).delete(); } } }).subscribe(new Subscriber<ResponseFiles>() { @Override public void onCompleted() { unsubscribe(); } @Override public void onError(Throwable e) { Crashlytics.logException(e); } @Override public void onNext(ResponseFiles responseFiles) { } }); } }
From source file:com.carlrice.reader.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;/*from w w w.j ava 2 s .com*/ if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = Application.context().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); if (cursor != null) { String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } } break; } case R.id.menu_full_screen: { setImmersiveFullScreen(true); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = Application.context().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } } } return true; }
From source file:cochrane343.journal.MainActivity.java
@Override public void onUpdateExpense(final long expenseId, final String description, final long costInCents, final long category) { final ContentValues newExpense = getContentValues(description, costInCents, category); final Uri uri = ContentUris.withAppendedId(Expense.EXPENSES_URI, expenseId); getContentResolver().update(uri, newExpense, null, null); Toast.makeText(this, R.string.toast_updated_expense, Toast.LENGTH_SHORT).show(); }
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
@Override public String getCTag() throws LocalStorageException { try {// w ww .j a v a 2 s. co m @Cleanup Cursor c = providerClient.query(ContentUris.withAppendedId(calendarsURI(), id), new String[] { COLLECTION_COLUMN_CTAG }, null, null, null); if (c.moveToFirst()) { return c.getString(0); } else throw new LocalStorageException("Couldn't query calendar CTag"); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:at.bitfire.davdroid.resource.LocalCalendar.java
@Override public String getCTag() throws LocalStorageException { try {//from w w w . ja v a 2 s . co m @Cleanup Cursor c = providerClient.query(ContentUris.withAppendedId(calendarsURI(), id), new String[] { COLLECTION_COLUMN_CTAG }, null, null, null); if (c != null && c.moveToFirst()) return c.getString(0); else throw new LocalStorageException("Couldn't query calendar CTag"); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:com.kyakujin.android.tagnotepad.ui.TagListFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); AdapterView.AdapterContextMenuInfo info; try {/*from ww w. j ava 2s . c o m*/ info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { Log.e(TAG, "bad AdapterContextMenuInfo", e); return; } Cursor c = (Cursor) mTagListView.getAdapter().getItem(info.position); if (c == null) { return; } android.view.MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.context_menu_tag_list, menu); mTagName = c.getString(TagsQuery.TAGNAME); menu.setHeaderTitle(mTagName); Intent intent = new Intent(null, ContentUris.withAppendedId(Tags.CONTENT_URI, (int) info.id)); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(getActivity(), TagListFragment.class), null, intent, 0, null); }