List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.app.uafeed.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 www . 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); 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: { toggleFullScreen(); 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.android.exchange.service.EasServerConnection.java
/** * Make an {@link HttpPost} for a specific request. * @param uri The uri for this request, as a {@link String}. * @param entity The {@link HttpEntity} for this request. * @param contentType The Content-Type for this request. * @param usePolicyKey Whether or not a policy key should be sent. * @return/* w w w .j a va 2 s . c om*/ */ public HttpPost makePost(final String uri, final HttpEntity entity, final String contentType, final boolean usePolicyKey) { final HttpPost post = new HttpPost(uri); post.setHeader("Authorization", makeAuthString()); post.setHeader("MS-ASProtocolVersion", String.valueOf(mProtocolVersion)); post.setHeader("User-Agent", getUserAgent()); post.setHeader("Accept-Encoding", "gzip"); // If there is no entity, we should not be setting a content-type since this will // result in a 400 from the server in the case of loading an attachment. if (contentType != null && entity != null) { post.setHeader("Content-Type", contentType); } if (usePolicyKey) { // If there's an account in existence, use its key; otherwise (we're creating the // account), send "0". The server will respond with code 449 if there are policies // to be enforced final String key; final String accountKey; if (mAccountId == Account.NO_ACCOUNT) { accountKey = null; } else { accountKey = Utility.getFirstRowString(mContext, ContentUris.withAppendedId(Account.CONTENT_URI, mAccountId), ACCOUNT_SECURITY_KEY_PROJECTION, null, null, null, 0); } if (!TextUtils.isEmpty(accountKey)) { key = accountKey; } else { key = "0"; } post.setHeader("X-MS-PolicyKey", key); } post.setEntity(entity); return post; }
From source file:org.devtcg.five.provider.FiveSyncAdapter.java
private void getImageData(SyncContext context, AbstractSyncProvider serverDiffs, String feedType, long modifiedSince) { if (context.hasError() == true || context.hasCanceled() == true) return;/* w w w . j a v a2 s . c o m*/ Uri localFeedUri = getLocalFeedUri(feedType); String tablePrefix = (feedType.equals(FEED_ALBUMS) ? "a." : ""); Cursor newRecords = serverDiffs.query(localFeedUri, new String[] { AbstractTableMerger.SyncableColumns._ID, AbstractTableMerger.SyncableColumns._SYNC_ID }, tablePrefix + AbstractTableMerger.SyncableColumns._SYNC_TIME + " > " + modifiedSince, null, null); Resources res = getContext().getResources(); int thumbWidth = res.getDimensionPixelSize(R.dimen.image_thumb_width); int thumbHeight = res.getDimensionPixelSize(R.dimen.image_thumb_height); int fullWidth = res.getDimensionPixelSize(R.dimen.large_artwork_width); int fullHeight = res.getDimensionPixelSize(R.dimen.large_artwork_height); try { while (newRecords.moveToNext() && !context.hasError() && !context.hasCanceled()) { long id = newRecords.getLong(0); long syncId = newRecords.getLong(1); try { Uri localFeedItemUri = ContentUris.withAppendedId(localFeedUri, id); if (feedType.equals(FEED_ARTISTS)) { downloadFileAndUpdateProvider(context, serverDiffs, mSource.getImageUrl(feedType, syncId, thumbWidth, thumbHeight), Five.makeArtistPhotoUri(id), localFeedItemUri, Five.Music.Artists.PHOTO); } else if (feedType.equals(FEED_ALBUMS)) { downloadFileAndUpdateProvider(context, serverDiffs, mSource.getImageUrl(feedType, syncId, thumbWidth, thumbHeight), Five.makeAlbumArtworkUri(id), localFeedItemUri, Five.Music.Albums.ARTWORK); downloadFileAndUpdateProvider(context, serverDiffs, mSource.getImageUrl(feedType, syncId, fullWidth, fullHeight), Five.makeAlbumArtworkBigUri(id), localFeedItemUri, Five.Music.Albums.ARTWORK_BIG); } } catch (IOException e) { markErrorUnlessCanceled(context, e); } } } finally { newRecords.close(); } }
From source file:com.anhubo.anhubo.ui.activity.unitDetial.UploadingActivity1.java
@TargetApi(19) private Bitmap handleImageOnKitKat(Intent data) { String imagePath = null;//from w w w .jav a 2 s. com Uri uri = data.getData(); Log.d("TAG", "handleImageOnKitKat: uri is " + uri); if (DocumentsContract.isDocumentUri(this, uri)) { // documentUridocument id? String docId = DocumentsContract.getDocumentId(uri); if ("com.android.providers.media.documents".equals(uri.getAuthority())) { String id = docId.split(":")[1]; // ??id String selection = MediaStore.Images.Media._ID + "=" + id; imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); imagePath = getImagePath(contentUri, null); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { // contentUri?? imagePath = getImagePath(uri, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { // fileUri??? imagePath = uri.getPath(); } Bitmap bitmap = displayImage(imagePath);// ? return bitmap; }
From source file:com.granita.icloudcalsync.resource.LocalCollection.java
/** Enqueues updating an existing resource in the local collection. The resource will be found by * the remote file name and all data will be updated. Requires commit(). */ public void updateByRemoteName(Resource remoteResource) throws LocalStorageException { T localResource = findByRemoteName(remoteResource.getName(), false); pendingOperations/* ww w .ja v a 2s. c om*/ .add(buildEntry( ContentProviderOperation .newUpdate(ContentUris.withAppendedId(entriesURI(), localResource.getLocalID())), remoteResource, true).withValue(entryColumnETag(), remoteResource.getETag()) .withYieldAllowed(true).build()); removeDataRows(localResource); addDataRows(remoteResource, localResource.getLocalID(), -1); }
From source file:com.nextgis.woody.activity.EditActivity.java
private void save() throws NGException { // Add constant values values.put(Constants.FIELD_DATETIME, Calendar.getInstance().getTimeInMillis()); AccountUtil.AccountData accountData; try {//from w w w .j av a 2s .c o m accountData = AccountUtil.getAccountData(this, Constants.ACCOUNT_NAME); values.put(Constants.FIELD_REPORTER, accountData.login); } catch (IllegalStateException e) { throw new NGException(getString(com.nextgis.maplib.R.string.error_auth)); } // Create or change feature IGISApplication app = (IGISApplication) getApplication(); if (null == app) { throw new IllegalArgumentException("Not a IGISApplication"); } Uri uri = Uri.parse("content://" + app.getAuthority() + "/" + Constants.KEY_MAIN); if (mFeatureId == NOT_FOUND) { // we need to get proper mFeatureId for new features first Uri result = getContentResolver().insert(uri, values); if (result == null) { Toast.makeText(this, getText(com.nextgis.maplibui.R.string.error_db_insert), Toast.LENGTH_SHORT) .show(); return; } else { mFeatureId = Long.parseLong(result.getLastPathSegment()); } } else { Uri updateUri = ContentUris.withAppendedId(uri, mFeatureId); boolean valuesUpdated = getContentResolver().update(updateUri, values, null, null) == 1; if (!valuesUpdated) { Toast.makeText(this, getText(com.nextgis.maplibui.R.string.error_db_update), Toast.LENGTH_SHORT) .show(); return; } } // add photos putAttaches(); finish(); }
From source file:org.mythtv.service.content.v25.LiveStreamHelperV25.java
public LiveStreamInfo findLiveStream(final Context context, final LocationProfile locationProfile, final Long id) { Log.d(TAG, "findLiveStream : enter"); String projection[] = null;//from w w w .j a v a 2 s .c o m String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(id) }; LiveStreamInfo liveStreamInfo = null; Uri uri = LiveStreamConstants.CONTENT_URI; if (null != id && id > 0) { uri = ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id); } selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { liveStreamInfo = convertCursorToLiveStreamInfo(cursor); } cursor.close(); Log.d(TAG, "findLiveStream : exit"); return liveStreamInfo; }
From source file:io.n7.calendar.caldav.CalDAVService.java
private void doRemoveCalendar(Account acc, long calid) throws Exception { mCR.delete(ContentUris.withAppendedId(asSyncAdapter(Calendars.CONTENT_URI), calid), null, null); }
From source file:at.bitfire.davdroid.resource.LocalCollection.java
/** Updates an existing resource in the local collection. The resource will be found by * the remote file name and all data will be updated. */ public void updateByRemoteName(Resource remoteResource) throws LocalStorageException { T localResource = findByRemoteName(remoteResource.getName(), false); pendingOperations// w w w.j a v a 2s .com .add(buildEntry( ContentProviderOperation .newUpdate(ContentUris.withAppendedId(entriesURI(), localResource.getLocalID())), remoteResource, true).withValue(entryColumnETag(), remoteResource.getETag()) .withYieldAllowed(true).build()); removeDataRows(localResource); addDataRows(remoteResource, localResource.getLocalID(), -1); commit(); }
From source file:at.flack.receiver.SmsReceiver.java
public final Bitmap fetchThumbnail(Context context, String address) { Integer id = fetchThumbnailId(context, address); if (id == null) return null; final Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id); final Cursor cursor = context.getContentResolver().query(uri, PHOTO_BITMAP_PROJECTION, null, null, null); try {/*from www . j av a2 s . c o m*/ Bitmap thumbnail = null; if (cursor.moveToFirst()) { final byte[] thumbnailBytes = cursor.getBlob(0); if (thumbnailBytes != null) { thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length); } } return thumbnail; } finally { cursor.close(); } }