/** Returns a fixed SmoothStreaming client manifest {@link Uri}. */ public static Uri fixManifestUri(Uri manifestUri) { if (Util.toLowerInvariant(manifestUri.getLastPathSegment()).matches("manifest(\\(.+\\))?")) { return manifestUri; } return Uri.withAppendedPath(manifestUri, "Manifest"); }
@Implementation protected static Uri withAppendedId(Uri contentUri, long id) { return Uri.withAppendedPath(contentUri, String.valueOf(id)); }
public void notifyChange() { Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/messages"); contentResolver.notifyChange(uri, null); }
@NonNull private static Uri generateContentUri(@NonNull final Context context, final String basepath) { final String authority = getAuthority(context); final Uri authorityUri = Uri.parse("content://" + authority); //noinspection UnnecessaryLocalVariable final Uri contentUri = Uri.withAppendedPath(authorityUri, basepath); return contentUri; }
private List<MediaStoreData> query(Uri contentUri, String[] projection, String sortByCol, String idCol, String dateTakenCol, String dateModifiedCol, String mimeTypeCol, String orientationCol, MediaStoreData.Type type) { final List<MediaStoreData> data = new ArrayList<MediaStoreData>(); Cursor cursor = getContext().getContentResolver() .query(contentUri, projection, null, null, sortByCol + " DESC"); if (cursor == null) { return data; } try { final int idColNum = cursor.getColumnIndexOrThrow(idCol); final int dateTakenColNum = cursor.getColumnIndexOrThrow(dateTakenCol); final int dateModifiedColNum = cursor.getColumnIndexOrThrow(dateModifiedCol); final int mimeTypeColNum = cursor.getColumnIndex(mimeTypeCol); final int orientationColNum = cursor.getColumnIndexOrThrow(orientationCol); while (cursor.moveToNext()) { long id = cursor.getLong(idColNum); long dateTaken = cursor.getLong(dateTakenColNum); String mimeType = cursor.getString(mimeTypeColNum); long dateModified = cursor.getLong(dateModifiedColNum); int orientation = cursor.getInt(orientationColNum); data.add(new MediaStoreData(id, Uri.withAppendedPath(contentUri, Long.toString(id)), mimeType, dateTaken, dateModified, orientation, type)); } } finally { cursor.close(); } return data; }
/** * Get the ID for the note type / model which is currently in use * @return id for current model, or <0 if there was a problem */ public long getCurrentModelId() { // Get the current model Uri uri = Uri.withAppendedPath(Model.CONTENT_URI, Model.CURRENT_MODEL_ID); final Cursor singleModelCursor = mResolver.query(uri, null, null, null, null); if (singleModelCursor == null) { return -1L; } long modelId; try { singleModelCursor.moveToFirst(); modelId = singleModelCursor.getLong(singleModelCursor.getColumnIndex(Model._ID)); } finally { singleModelCursor.close(); } return modelId; }
public RecipientSpan(Recipient recipient) { super(TextUtils.isEmpty(recipient.name) ? recipient.number : recipient.name, mSpanHeight, mSpanMaxWidth, mSpanPaddingLeft, mSpanPaddingRight, mSpanTypeface, mSpanTextColor, mSpanTextSize, mSpanBackgroundColor); mRecipient = recipient; if(TextUtils.isEmpty(recipient.lookupKey)) setImageResource(mDefaultAvatarId); else Picasso.with(getContext()) .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey)) .placeholder(mDefaultAvatarId) .into(this); }
@Override public void onClick(View v) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(numberEntry.getText().toString())); GlideApp.with(MainActivity.this) .load(uri) .override(Target.SIZE_ORIGINAL) .into(imageViewLookup); } });
private static Uri getContentUri(final String basepath) { final Uri authorityUri = Uri.parse("content://" + AUTHORITY); return Uri.withAppendedPath(authorityUri, basepath); } }
/** * Notify all concerned parties that the message list has changed. * * <p><strong>Note:</strong> * Notifying the content resolver of the change will cause the {@code CursorLoader} in * {@code MessageListFragment} to reload the cursor. But especially with flag changes this will * block because of the DB write operation to update the flags. So additionally we use * {@link LocalBroadcastManager} to send a {@link #ACTION_CACHE_UPDATED} broadcast. This way * {@code MessageListFragment} can update the view without reloading the cursor. * </p> */ private void notifyChange() { LocalBroadcastManager.getInstance(sContext).sendBroadcast(new Intent(ACTION_CACHE_UPDATED)); Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + mAccountUuid + "/messages"); sContext.getContentResolver().notifyChange(uri, null); } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123"); fetcher = new ThumbFetcher(uri, opener); }
@Override public void onClick(View v) { // If contact has been assigned, extras should no longer be null, but do a null check // anyway just in case assignContactFromPhone or Email was called with a null bundle or // wasn't assigned previously. final Bundle extras = (this.extras == null) ? new Bundle() : this.extras; if (contactUri != null) { QuickContact.showQuickContact(getContext(), ContactBadge.this, contactUri, QuickContact.MODE_LARGE, null); } else if (contactEmail != null) { extras.putString(EXTRA_URI_CONTENT, contactEmail); queryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras, Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)), EMAIL_LOOKUP_PROJECTION, null, null, null); } }
/** * Return a {@link Cursor} instance that can be used to fetch information * about the contact with the given email address. * * @param address The email address to search for. * @return A {@link Cursor} instance that can be used to fetch information * about the contact with the given email address */ private Cursor getContactByAddress(final String address) { final Uri uri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, Uri.encode(address)); if (hasContactPermission()) { return mContentResolver.query( uri, PROJECTION, null, null, SORT_ORDER); } else { return new EmptyCursor(); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { ContactView v = (ContactView)convertView; if(v == null) { v = (ContactView)LayoutInflater.from(parent.getContext()).inflate(position == 0 ? R.layout.row_contact_selected : R.layout.row_contact_replace, parent, false); v.setOnClickListener(this); } v.setTag(position); Recipient recipient = (Recipient)getItem(position); v.setNameText(position == 0 ? recipient.name : null); v.setAddressText(recipient.number); if(TextUtils.isEmpty(recipient.lookupKey)) v.setAvatarResource(mDefaultAvatarId); else Picasso.with(getContext()) .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey)) .placeholder(mDefaultAvatarId) .into(v); return v; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { ContactView v = (ContactView)convertView; if (v == null) v = new ContactView(getContext(), null, 0, R.style.ContactView); Recipient recipient = (Recipient) getItem(position); v.setNameText(recipient.name); v.setAddressText(recipient.number); if(TextUtils.isEmpty(recipient.lookupKey)) v.setAvatarResource(mDefaultAvatarId); else Picasso.with(getContext()) .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey)) .placeholder(mDefaultAvatarId) .into(v); return v; }
/** * Assign a contact based on an email address. This should only be used when * the contact's URI is not available, as an extra query will have to be * performed to lookup the URI based on the email. * * @param emailAddress * The email address of the contact. * @param lazyLookup * If this is true, the lookup query will not be performed * until this view is clicked. * @param extras * A bundle of extras to populate the contact edit page with if the contact * is not found and the user chooses to add the email address to an existing contact or * create a new contact. Uses the same string constants as those found in * {@link android.provider.ContactsContract.Intents.Insert} */ public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) { contactEmail = emailAddress; this.extras = extras; if (!lazyLookup) { queryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null, Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)), EMAIL_LOOKUP_PROJECTION, null, null, null); } else { contactUri = null; onContactUriChanged(); } }
@Test(expected = NumberFormatException.class) public void parseIdThrowsNumberFormatException() { ContentUris.parseId(Uri.withAppendedPath(URI, "bar")); }
private void showContact(long id) { GlideRequests glideRequests = GlideApp.with(this); RequestOptions originalSize = new RequestOptions().override(Target.SIZE_ORIGINAL); Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id); glideRequests.load(contactUri).apply(originalSize).into(imageViewContact); Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri); glideRequests.load(lookupUri).apply(originalSize).into(imageViewLookup); Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY); glideRequests.load(photoUri).apply(originalSize).into(imageViewPhoto); Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO); glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto); } }
@Test public void canParseId() { assertThat(ContentUris.parseId(Uri.withAppendedPath(URI, "1"))).isEqualTo(1L); assertThat(ContentUris.parseId(URI)).isEqualTo(-1L); }
public void testDelete() throws Exception { final Uri[] workingUris = { mTrayUri.get(), mTrayUri.builder().setModule("module").build(), mTrayUri.builder().setModule("module").setKey("key").build(), mTrayUri.getInternal(), mTrayUri.builder().setInternal(true).setModule("module").build(), mTrayUri.builder().setInternal(true).setModule("module").setKey("key").build() }; for (Uri uri : workingUris) { getProviderMockContext().getContentResolver().delete(uri, null, null); } final Uri badUri = Uri .withAppendedPath(Uri.parse("content://" + MockProvider.AUTHORITY), "something"); try { getProviderMockContext().getContentResolver().delete(badUri, null, null); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("not supported")); } }