Example usage for android.content ContentUris withAppendedId

List of usage examples for android.content ContentUris withAppendedId

Introduction

In this page you can find the example usage for android.content ContentUris withAppendedId.

Prototype

public static Uri withAppendedId(Uri contentUri, long id) 

Source Link

Document

Appends the given ID to the end of the path.

Usage

From source file:com.google.android.demos.jamendo.app.ArtistActivity.java

/** {@inheritDoc} */
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Uri uri = ContentUris.withAppendedId(Albums.CONTENT_URI, id);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);/* w  w  w  .  ja v a 2  s  .c o  m*/
}

From source file:com.codebutler.farebot.fragments.CardsFragment.java

@Override
public 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:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

/**
 * Handles a click event from the LongClickDialog.
 *//*from w ww .j  ava 2 s  .  c  o  m*/
@Override
public void onClick(DialogInterface dialog, int position) {
    switch (position) {
    // delete
    case 0:
        // delete the entry in the database
        Uri bookDelete = ContentUris.withAppendedId(PapyrusContentProvider.Books.CONTENT_URI, selectedBookID);
        resolver.delete(bookDelete, null, null);

        Toast.makeText(getApplicationContext(), getString(R.string.BooksBrowser_toast_bookDeleted),
                Toast.LENGTH_SHORT).show();
        break;
    // lend book to someone
    case 1:
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, 1001);
        break;
    }
}

From source file:com.codebutler.farebot.activities.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete_card) {
        long id = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).id;
        Uri uri = ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD, id);
        getContentResolver().delete(uri, null, null);
        return true;
    }//w  ww.  j  a  v  a2s .  c om
    return false;
}

From source file:com.andryr.musicplayer.images.ArtworkCache.java

@Override
protected Bitmap retrieveBitmap(Long key, int reqWidth, int reqHeight) {
    if (key == -1) {
        return null;
    }//from   w  w w  .j  av a  2 s. com

    if (PrefUtils.getInstance().useFreeArtworks()) {
        return getFreeArtwork(reqWidth, reqHeight);
    }

    Uri uri = ContentUris.withAppendedId(ArtworkHelper.getArtworkUri(), key);

    try {
        if (uri != null) {
            ContentResolver res = mContext.getContentResolver();
            Bitmap bitmap = BitmapHelper.decode(res.openInputStream(uri), reqWidth, reqHeight);
            return bitmap;

        }
    } catch (IOException e) {
        Log.e(TAG, "get image from contentresolver", e);
    }

    try {
        return downloadArtwork(mContext, key, reqWidth, reqHeight);
    } catch (IOException e) {
        Log.e(TAG, "download", e);
    }

    return null;
}

From source file:com.android.contacts.common.model.ContactLoaderTest.java

public void testLoadContactWithContactIdUri() {
    // Use content Uris that only contain the ID
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
    final Uri entityUri = Uri.withAppendedPath(baseUri, Contacts.Entity.CONTENT_DIRECTORY);
    final Uri lookupUri = ContentUris
            .withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY), CONTACT_ID);

    ContactQueries queries = new ContactQueries();
    mContactsProvider.expectTypeQuery(baseUri, Contacts.CONTENT_ITEM_TYPE);
    queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);

    Contact contact = assertLoadContact(baseUri);

    assertEquals(CONTACT_ID, contact.getId());
    assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(LOOKUP_KEY, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());
    mContactsProvider.verify();/*  w  w  w . ja  v  a2  s . c o m*/
}

From source file:com.marvin.webvox.DownloadTouchIcon.java

@Override
public void onPostExecute(Bitmap icon) {
    // Do this first in case the download failed.
    if (mActivity != null) {
        // Remove the touch icon loader from the BrowserActivity.
        mActivity.mTouchIconLoader = null;
    }/*w w w .  j a  va  2  s  . c o  m*/

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.PNG, 100, os);
    ContentValues values = new ContentValues();
    //        values.put(Browser.BookmarkColumns.TOUCH_ICON,
    //                os.toByteArray());

    if (mCursor.moveToFirst()) {
        do {
            mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)),
                    values, null, null);
        } while (mCursor.moveToNext());
    }
    mCursor.close();
}

From source file:com.android.browser.DownloadTouchIcon.java

private void storeIcon(Bitmap icon) {
    // Do this first in case the download failed.
    if (mTab != null) {
        // Remove the touch icon loader from the BrowserActivity.
        mTab.mTouchIconLoader = null;/*from   w w w  .j  av a2 s . c o  m*/
    }

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.PNG, 100, os);
    ContentValues values = new ContentValues();
    values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());

    if (mCursor.moveToFirst()) {
        do {
            mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)),
                    values, null, null);
        } while (mCursor.moveToNext());
    }
}

From source file:com.energysystem.videoexplorerTV.video.VideoProvider.java

public static HashMap<String, List<Video>> buildMedia(String url, Cursor data) throws JSONException {

    mMovieList = new HashMap<String, List<Video>>();
    mMovieList.clear();/* www.ja  v  a 2s  .  c  o m*/
    Log.e("Abrimos", "Videos");
    List<Video> categoryList = new ArrayList<Video>();
    List<Video> categoryList2 = new ArrayList<Video>();

    while (data.moveToNext()) {
        int videoID = data.getInt(data.getColumnIndex(MediaStore.Video.Media._ID));
        int title = data.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE);
        int category = data.getColumnIndexOrThrow(MediaStore.Video.Media.CATEGORY);
        int durationID = data.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
        int data_string = data.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
        //int videoUrl = data.getColumnIndexOrThrow(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString());
        // int bgImageUrl = data.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI.toString());

        int duration = Integer.parseInt(data.getString(durationID));

        String categoria = new File(data.getString(data_string)).getParent();
        Log.e("Ruta:", categoria);
        if (categoria.equals("/storage/emulated/0/Movies")) {
            categoryList.add(buildMovieInfo(categoria, data.getString(title), "Descripcion",
                    String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration),
                            TimeUnit.MILLISECONDS.toSeconds(duration)
                                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID)
                            .toString()));
            mMovieList.put("Almacenamiento Interno", categoryList);
        } else {
            categoryList2.add(buildMovieInfo(categoria, data.getString(title), "Descripcion",
                    String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration),
                            TimeUnit.MILLISECONDS.toSeconds(duration)
                                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(),
                    ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID)
                            .toString()));
            mMovieList.put("USB", categoryList2);
        }
    }

    /*JSONObject jsonObj = new VideoProvider().parseUrl(url);
    JSONArray categories = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS);
    if (null != categories) {
    Log.d(TAG, "category #: " + categories.length());
    String title;
    String videoUrl;
    String bgImageUrl;
    String cardImageUrl;
    String studio;
    for (int i = 0; i < categories.length(); i++) {
        JSONObject category = categories.getJSONObject(i);
        String category_name = category.getString(TAG_CATEGORY);
        JSONArray videos = category.getJSONArray(TAG_MEDIA);
        Log.d(TAG,
                "category: " + i + " Name:" + category_name + " video length: "
                        + videos.length());
        List<Video> categoryList = new ArrayList<Video>();
        if (null != videos) {
            for (int j = 0; j < videos.length(); j++) {
                JSONObject video = videos.getJSONObject(j);
                String description = video.getString(TAG_DESCRIPTION);
                JSONArray videoUrls = video.getJSONArray(TAG_SOURCES);
                if (null == videoUrls || videoUrls.length() == 0) {
                    continue;
                }
                title = video.getString(TAG_TITLE);
                videoUrl = getVideoPrefix(category_name, videoUrls.getString(0));
                bgImageUrl = getThumbPrefix(category_name, title,
                        video.getString(TAG_BACKGROUND));
                cardImageUrl = getThumbPrefix(category_name, title,
                        video.getString(TAG_CARD_THUMB));
                studio = video.getString(TAG_STUDIO);
                categoryList.add(buildMovieInfo(category_name, title, description, studio,
                        videoUrl, cardImageUrl,
                        bgImageUrl));
            }
            mMovieList.put(category_name, categoryList);
        }
    }
    }*/
    Log.e("VideoProvider", "Tamano mMovie: " + mMovieList.size());
    return mMovieList;
}

From source file:com.google.android.demos.jamendo.app.SearchActivity.java

/** {@inheritDoc} */
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Uri data = ContentUris.withAppendedId(Albums.CONTENT_URI, id);
    Intent intent = new Intent(Intent.ACTION_VIEW, data);
    startActivity(intent);/*from   w  w  w.jav a  2  s. c om*/
}