Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

In this page you can find the example usage for android.net Uri withAppendedPath.

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:com.example.android.lnotifications.OtherMetadataFragment.java

/**
 * Returns a {@link Bitmap} from the Uri specified as the argument.
 *
 * @param contactUri The Uri from which the result Bitmap is created.
 * @return The {@link Bitmap} instance retrieved from the contactUri.
 */// ww w . j  a v  a2 s . c o m
private Bitmap loadBitmapFromContactUri(Uri contactUri) {
    if (contactUri == null) {
        return null;
    }
    Bitmap result = null;
    Cursor cursor = getActivity().getContentResolver().query(contactUri, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
        int idx = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID);
        String hasPhoto = cursor.getString(idx);
        Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
        if (hasPhoto != null) {
            try {
                result = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), photoUri);
            } catch (IOException e) {
                Log.e(TAG, String.format("Failed to load resource. Uri %s", photoUri), e);
            }
        } else {
            Drawable defaultContactDrawable = getActivity().getResources()
                    .getDrawable(R.drawable.ic_contact_picture);
            result = ((BitmapDrawable) defaultContactDrawable).getBitmap();
        }
    }
    return result;
}

From source file:org.linphone.compatibility.ApiFivePlus.java

private static Uri getContactPictureUri(String id) {
    Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id));
    return Uri.withAppendedPath(person, Contacts.Photo.CONTENT_DIRECTORY);
}

From source file:com.frostwire.android.gui.adapters.menu.FileListAdapter.java

private void populateViewThumbnail(View view, FileDescriptorItem item) {
    FileDescriptor fd = item.fd;//from  ww  w .j  a va 2 s.c  om

    BrowseThumbnailImageButton fileThumbnail = findView(view, R.id.view_browse_peer_list_item_file_thumbnail);
    fileThumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);

    if (fileType == Constants.FILE_TYPE_APPLICATIONS) {
        Uri uri = Uri.withAppendedPath(ImageLoader.APPLICATION_THUMBNAILS_URI, fd.album);
        thumbnailLoader.load(uri, fileThumbnail, 96, 96);
    } else {
        if (in(fileType, Constants.FILE_TYPE_AUDIO, Constants.FILE_TYPE_VIDEOS,
                Constants.FILE_TYPE_RINGTONES)) {
            if (fd.equals(Engine.instance().getMediaPlayer().getCurrentFD())) {
                fileThumbnail.setOverlayState(MediaPlaybackOverlay.MediaPlaybackState.STOP);
            } else {
                fileThumbnail.setOverlayState(MediaPlaybackOverlay.MediaPlaybackState.PLAY);
            }
        }

        if (fd.fileType == Constants.FILE_TYPE_AUDIO) {
            Uri uri = ContentUris.withAppendedId(ImageLoader.ALBUM_THUMBNAILS_URI, fd.albumId);
            Uri uriRetry = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, fd.id);
            uriRetry = ImageLoader.getMetadataArtUri(uriRetry);
            thumbnailLoader.load(uri, uriRetry, fileThumbnail, 96, 96);
        } else if (fd.fileType == Constants.FILE_TYPE_VIDEOS) {
            Uri uri = ContentUris.withAppendedId(Video.Media.EXTERNAL_CONTENT_URI, fd.id);
            Uri uriRetry = ImageLoader.getMetadataArtUri(uri);
            thumbnailLoader.load(uri, uriRetry, fileThumbnail, 96, 96);
        } else if (fd.fileType == Constants.FILE_TYPE_PICTURES) {
            Uri uri = ContentUris.withAppendedId(Images.Media.EXTERNAL_CONTENT_URI, fd.id);
            thumbnailLoader.load(uri, fileThumbnail, 96, 96);
        }
    }

    TextView title = findView(view, R.id.view_browse_peer_list_item_file_title);
    title.setText(fd.title);

    if (fd.fileType == Constants.FILE_TYPE_AUDIO || fd.fileType == Constants.FILE_TYPE_APPLICATIONS) {
        TextView fileExtra = findView(view, R.id.view_browse_peer_list_item_extra_text);
        fileExtra.setText(fd.artist);
    } else {
        TextView fileExtra = findView(view, R.id.view_browse_peer_list_item_extra_text);
        fileExtra.setText(R.string.empty_string);
    }

    TextView fileSize = findView(view, R.id.view_browse_peer_list_item_file_size);
    fileSize.setText(UIUtils.getBytesInHuman(fd.fileSize));

    fileThumbnail.setTag(fd);
    fileThumbnail.setOnClickListener(downloadButtonClickListener);

    populateSDState(view, item);
}

From source file:net.ddns.mlsoftlaberge.contactslist.ui.ContactsBudgetFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    // Two main queries to load the required information
    case ContactDetailQuery.QUERY_ID:
        // This query loads main contact admins, see
        // ContactDetailQuery for more information.
        return new CursorLoader(getActivity(), mContactUri, ContactDetailQuery.PROJECTION,
                ContactDetailQuery.SELECTION, null, ContactDetailQuery.SORT_ORDER);
    case ContactAddressQuery.QUERY_ID:
        // This query loads contact address admins, see
        // ContactAddressQuery for more information.
        final Uri uri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);
        return new CursorLoader(getActivity(), mDataUri, ContactAddressQuery.PROJECTION,
                ContactAddressQuery.SELECTION, null, null);
    case ContactNotesQuery.QUERY_ID:
        // This query loads contact address admins, see
        // ContactAddressQuery for more information.
        final Uri nuri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);
        return new CursorLoader(getActivity(), mDataUri, ContactNotesQuery.PROJECTION,
                ContactNotesQuery.SELECTION, null, null);
    case ContactPhoneQuery.QUERY_ID:
        // This query loads contact address admins, see
        // ContactAddressQuery for more information.
        final Uri puri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);
        return new CursorLoader(getActivity(), mDataUri, ContactPhoneQuery.PROJECTION,
                ContactPhoneQuery.SELECTION, null, null);
    case ContactEmailQuery.QUERY_ID:
        // This query loads contact address admins, see
        // ContactAddressQuery for more information.
        final Uri euri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);
        return new CursorLoader(getActivity(), mDataUri, ContactEmailQuery.PROJECTION,
                ContactEmailQuery.SELECTION, null, null);
    }/* w w w.j av a  2  s.  co m*/
    return null;
}

From source file:cz.maresmar.sfm.view.credential.LoginListActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PORTAL_PICKER_REQUEST && resultCode == Activity.RESULT_OK) {
        Uri portalUri = data.getData();/*from   w  w w  .j  a  va2s  .com*/

        if (portalUri != null) {
            long portalId = ContentUris.parseId(portalUri);

            // Try to find credentials with this portal
            try (Cursor cursor = getContentResolver().query(mPortalsUri,
                    new String[] { ProviderContract.Portal.CREDENTIAL_ID },
                    ProviderContract.Portal.PORTAL_ID + " == " + portalId, null, null)) {

                // Has already data
                if (cursor != null && cursor.getCount() > 0) {
                    cursor.moveToFirst();

                    long credentialId = cursor.getLong(0);
                    Uri credentialUri = ContentUris.withAppendedId(
                            Uri.withAppendedPath(mUserUri, ProviderContract.CREDENTIALS_PATH), credentialId);
                    startCredentialDetailActivity(portalUri, credentialUri, LoginDetailActivity.CREDENTIAL_TAB);
                } else {
                    startCredentialDetailActivity(portalUri, null, LoginDetailActivity.CREDENTIAL_TAB);
                }
            }
        } else {
            // Create new portal
            startCredentialDetailActivity(portalUri, null, LoginDetailActivity.PORTAL_TAB);
        }
    }
}

From source file:ca.rmen.android.scrumchatter.team.Teams.java

/**
 * @return the Team currently selected by the user.
 *///from  w  w  w .jav a 2s  .  c om
@WorkerThread
private Team getCurrentTeam() {
    // Retrieve the current team name and construct a uri for the team based on the current team id.
    int teamId = Prefs.getInstance(mActivity).getTeamId();
    Uri teamUri = Uri.withAppendedPath(TeamColumns.CONTENT_URI, String.valueOf(teamId));
    Cursor c = mActivity.getContentResolver().query(teamUri, new String[] { TeamColumns.TEAM_NAME }, null, null,
            null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                String teamName = c.getString(0);
                return new Team(teamUri, teamName);
            }
        } finally {
            c.close();
        }
    }
    Log.wtf(TAG, "Could not get the current team", new Throwable());
    return selectFirstTeam();
}

From source file:com.silentcircle.contacts.interactions.ContactDeletionInteraction.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri contactUri = args.getParcelable(ARG_CONTACT_URI);
    return new CursorLoader(mContext, Uri.withAppendedPath(contactUri, Entity.CONTENT_DIRECTORY),
            ENTITY_PROJECTION, null, null, null);
}

From source file:org.linphone.compatibility.ApiFivePlus.java

private static Uri getContactPhotoUri(String id) {
    Uri person = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id));
    return Uri.withAppendedPath(person, Contacts.Photo.DISPLAY_PHOTO);
}

From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert batch of new data into Data table.
 * Batch comes as array list of {@link DataEntry} (timestamp - data pairs).
 * //from   w w w .j  av  a 2 s.c o  m
 * @param metric       id of metric
 * @param monitor      id of monitor
 * @param data         array list of {@link DataEntry} pairs
 * @return    number of rows inserted (should equal size of _data_ array list on success)
 * 
 * @see DataTable
 */
public synchronized long insertBatchData(int metric, int monitor, ArrayList<DataEntry> data) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertBatchData - insert into Data table: " + "metric-" + metric);
    long rowsInserted = 0;
    ContentValues values = new ContentValues();
    values.put(DataTable.COLUMN_METRIC_ID, metric);
    values.put(DataTable.COLUMN_MONITOR_ID, monitor);

    database.beginTransaction();
    try {
        for (DataEntry entry : data) {
            ContentValues contentValues = new ContentValues(values);
            contentValues.put(DataTable.COLUMN_TIMESTAMP, entry.timestamp);
            contentValues.put(DataTable.COLUMN_VALUE, entry.value);
            if (database.insert(DataTable.TABLE_DATA, null, contentValues) >= 0) {
                rowsInserted++;
            }
        }
        // Transaction is successful and all the records have been inserted
        database.setTransactionSuccessful();
    } catch (Exception e) {
        if (DebugLog.ERROR)
            Log.e(TAG, "Error on batch insert: " + e.toString());
    } finally {
        //End the transaction
        database.endTransaction();
    }
    if (rowsInserted > 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.MONITOR_DATA_URI, String.valueOf(monitor));
        context.getContentResolver().notifyChange(uri, null);
    }
    return rowsInserted;
}

From source file:org.sufficientlysecure.keychain.util.ContactHelper.java

/**
 * loads the profile picture of the main ("me") contact
 * http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
 *
 * @param highRes true for large image if present, false for thumbnail
 * @return bitmap of loaded photo// w  ww . java2  s.c o  m
 */
public Bitmap loadMainProfilePhoto(boolean highRes) {
    if (!isContactsPermissionGranted()) {
        return null;
    }

    try {
        long mainProfileContactId = getMainProfileContactId();

        Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,
                Long.toString(mainProfileContactId));
        InputStream photoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(mContentResolver,
                contactUri, highRes);
        if (photoInputStream == null) {
            return null;
        }
        return BitmapFactory.decodeStream(photoInputStream);
    } catch (Throwable ignored) {
        return null;
    }
}