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.frostwire.android.gui.adapters.FileListAdapter.java

private void populateViewThumbnail(View view, FileDescriptorItem item) {
    FileDescriptor fd = item.fd;/*  w w  w .j a v a2s  .c om*/

    final ImageButton fileThumbnail = findView(view,
            inGridMode() ? R.id.view_my_files_thumbnail_grid_item_browse_thumbnail_image_button
                    : R.id.view_my_files_thumbnail_list_item_browse_thumbnail_image_button);
    fileThumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);

    MediaPlaybackStatusOverlayView mediaOverlayView = findView(view,
            inGridMode() ? R.id.view_my_files_thumbnail_grid_item_playback_overlay_view
                    : R.id.view_my_files_thumbnail_list_item_playback_overlay_view);

    boolean inGridMode = inGridMode();
    final int thumbnailDimensions = inGridMode ? 256 : 96;

    if (fileType == Constants.FILE_TYPE_APPLICATIONS) {
        Uri uri = ImageLoader.getApplicationArtUri(fd.album);
        thumbnailLoader.load(uri, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
    } else {
        if (in(fileType, Constants.FILE_TYPE_AUDIO, Constants.FILE_TYPE_VIDEOS)) {
            if (fd.equals(Engine.instance().getMediaPlayer().getCurrentFD(getContext()))) {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.STOP);
            } else {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY);
            }
        } else if (fileType == Constants.FILE_TYPE_RINGTONES) {
            if (fd.equals(Engine.instance().getMediaPlayer().getSimplePlayerCurrentFD(getContext()))) {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.STOP);
            } else {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY);
            }
        }

        if (fd.fileType == Constants.FILE_TYPE_AUDIO) {
            Uri uri = ImageLoader.getAlbumArtUri(fd.albumId);
            Uri uriRetry = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, fd.id);
            uriRetry = ImageLoader.getMetadataArtUri(uriRetry);
            thumbnailLoader.load(uri, uriRetry, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
        } 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, thumbnailDimensions, thumbnailDimensions);
        } else if (fd.fileType == Constants.FILE_TYPE_PICTURES) {
            Uri uri = ContentUris.withAppendedId(Images.Media.EXTERNAL_CONTENT_URI, fd.id);
            thumbnailLoader.load(uri, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
        }
    }

    if (!inGridMode) {
        TextView title = findView(view, R.id.view_my_files_thumbnail_list_image_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_my_files_thumbnail_list_image_item_extra_text);
            fileExtra.setText(fd.artist);
        } else {
            TextView fileExtra = findView(view, R.id.view_my_files_thumbnail_list_image_item_extra_text);
            fileExtra.setText(R.string.empty_string);
        }
        TextView fileSize = findView(view, R.id.view_my_files_thumbnail_list_image_item_file_size);
        fileSize.setText(UIUtils.getBytesInHuman(fd.fileSize));
    }
    fileThumbnail.setTag(fd);
    fileThumbnail.setOnClickListener(downloadButtonClickListener);

    populateSDState(view, item);
}

From source file:info.staticfree.android.units.UnitUsageDBHelper.java

/**
 * Increments the usage counter for the given unit.
 * @param unit name of the unit//from w  w  w  . ja v a 2 s .  c o  m
 * @param db the unit usage database
 */
public static void logUnitUsed(String unit, ContentResolver cr) {
    final String[] selectionArgs = { unit };
    final Cursor c = cr.query(UsageEntry.CONTENT_URI, INCREMENT_QUERY_PROJECTION, UsageEntry._UNIT + "=?",
            selectionArgs, null);
    if (c.getCount() > 0) {
        c.moveToFirst();
        final int useCount = c.getInt(c.getColumnIndex(UsageEntry._USE_COUNT));
        final int id = c.getInt(c.getColumnIndex(UsageEntry._ID));
        final ContentValues cv = new ContentValues();
        cv.put(UsageEntry._USE_COUNT, useCount + 1);

        cr.update(ContentUris.withAppendedId(UsageEntry.CONTENT_URI, id), cv, null, null);
    } else {
        final ContentValues cv = new ContentValues();
        cv.put(UsageEntry._UNIT, unit);
        cv.put(UsageEntry._USE_COUNT, 1);
        cv.put(UsageEntry._FACTOR_FPRINT, getFingerprint(unit));
        cr.insert(UsageEntry.CONTENT_URI, cv);
    }
    c.close();
}

From source file:com.albedinsky.android.support.intent.CalendarIntent.java

/**
 *///  ww  w . j  a  v  a 2 s  .  c o m
@NonNull
@Override
@SuppressWarnings("ConstantConditions")
protected Intent onBuild() {
    switch (mType) {
    case TYPE_VIEW:
        final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
        builder.appendPath("time");
        ContentUris.appendId(builder, mBeginTime);
        return new Intent(Intent.ACTION_VIEW).setData(builder.build());
    case TYPE_INSERT_EVENT:
        return new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
                .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, mBeginTime)
                .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, mEndTime)
                .putExtra(CalendarContract.Events.TITLE, mTitle)
                .putExtra(CalendarContract.Events.DESCRIPTION, mDescription)
                .putExtra(CalendarContract.Events.EVENT_LOCATION, mLocation)
                .putExtra(CalendarContract.Events.AVAILABILITY, mAvailability);
    case TYPE_EDIT_EVENT:
        final Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId));
        if (!TextUtils.isEmpty(mTitle)) {
            intent.putExtra(CalendarContract.Events.TITLE, mTitle);
        }
        return intent;
    default:
        return new Intent(Intent.ACTION_VIEW)
                .setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId));
    }
}

From source file:com.csipsimple.ui.account.AccountsEditListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    final SipProfile account = profileFromContextMenuInfo(item.getMenuInfo());
    if (account == null) {
        // For some reason the requested item isn't available, do nothing
        return super.onContextItemSelected(item);
    }/*from   w  ww.jav  a2  s  .  co m*/

    switch (item.getItemId()) {
    case MENU_ITEM_DELETE: {
        getActivity().getContentResolver()
                .delete(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), null, null);
        return true;
    }
    case MENU_ITEM_MODIFY: {
        showDetails(account.id, account.wizard);
        return true;
    }
    case MENU_ITEM_ACTIVATE: {
        ContentValues cv = new ContentValues();
        cv.put(SipProfile.FIELD_ACTIVE, !account.active);
        getActivity().getContentResolver()
                .update(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), cv, null, null);
        return true;
    }
    case MENU_ITEM_WIZARD: {
        Intent it = new Intent(getActivity(), WizardChooser.class);
        it.putExtra(Intent.EXTRA_UID, account.id);
        startActivityForResult(it, CHANGE_WIZARD);
        return true;
    }
    }
    return super.onContextItemSelected(item);

}

From source file:com.android.emailcommon.provider.Account.java

/**
 * Check a single account for security hold status.
 *//*from ww  w .j a v a2  s  .c o  m*/
public static boolean isSecurityHold(Context context, long accountId) {
    return (Utility.getFirstRowLong(context, ContentUris.withAppendedId(Account.CONTENT_URI, accountId),
            ACCOUNT_FLAGS_PROJECTION, null, null, null, ACCOUNT_FLAGS_COLUMN_FLAGS, 0L)
            & Account.FLAGS_SECURITY_HOLD) != 0;
}

From source file:com.rukman.emde.smsgroups.syncadapter.SyncAdapter.java

private void deleteUnsyncedItems(ContentProviderClient provider, Account account, SyncResult syncResult)
        throws RemoteException, JSONException {

    Log.d(TAG, "Delete unsynced items before count: " + syncResult.stats.numDeletes);
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ContentProviderOperation op;//from  w  w  w. j  ava 2 s  . c  om
    ContentProviderResult[] results;

    // This is the good part
    Cursor unsyncedGroupsCursor = null;
    try {
        final String SELECT = GMSGroup.STATUS + " ISNULL OR " + GMSGroup.STATUS + " != "
                + GMSGroup.STATUS_SYNCED;
        unsyncedGroupsCursor = provider.query(GMSGroups.CONTENT_URI, new String[] { GMSGroup._ID,
                GMSGroup.CLOUD_ID, GMSGroup.STATUS, GMSGroup.NAME, GMSGroup.RAW_CONTACT_ID }, SELECT, null,
                null);
        ContentProviderClient contactsProvider;
        if (unsyncedGroupsCursor.moveToFirst()) {
            contactsProvider = getContext().getContentResolver()
                    .acquireContentProviderClient(ContactsContract.AUTHORITY);
            do {
                long groupId = unsyncedGroupsCursor.getLong(0);
                long groupRawContactId = unsyncedGroupsCursor.getLong(4);
                Cursor memberCursor = null;
                try {
                    memberCursor = provider.query(GMSContacts.CONTENT_URI,
                            new String[] { GMSContact._ID, GMSContact.GROUP_ID }, GMSContact.GROUP_ID + "=?",
                            new String[] { String.valueOf(groupId) }, null);
                    while (memberCursor.moveToNext()) {
                        op = ContentProviderOperation.newDelete(
                                ContentUris.withAppendedId(GMSContacts.CONTENT_URI, memberCursor.getLong(0)))
                                .build();
                        ops.add(op);
                    }
                } finally {
                    if (memberCursor != null) {
                        memberCursor.close();
                    }
                }
                op = ContentProviderOperation
                        .newDelete(ContentUris.withAppendedId(GMSGroups.CONTENT_URI, groupId)).build();
                ops.add(op);
                if (groupRawContactId <= 0) {
                    Cursor accountContactsCursor = null;
                    try {
                        String sourceId = unsyncedGroupsCursor.getString(1);
                        Log.d(TAG, String.format("Unsynced Group Id: %1$d, SourceId: %2$s", groupId, sourceId));
                        accountContactsCursor = GMSContactOperations.findGroupInContacts(contactsProvider,
                                account, sourceId);
                        if (accountContactsCursor != null && accountContactsCursor.moveToFirst()) {
                            groupRawContactId = accountContactsCursor.getLong(0);
                        }
                    } finally {
                        if (accountContactsCursor != null) {
                            accountContactsCursor.close();
                        }
                    }
                    GMSContactOperations.removeGroupFromContacts(contactsProvider, account, groupRawContactId,
                            syncResult);
                }
            } while (unsyncedGroupsCursor.moveToNext());
        }
    } finally {
        if (unsyncedGroupsCursor != null) {
            unsyncedGroupsCursor.close();
        }
    }
    // Now delete any unsynced contacts from the local provider
    op = ContentProviderOperation.newDelete(GMSContacts.CONTENT_URI)
            .withSelection(
                    GMSContact.STATUS + " ISNULL OR " + GMSContact.STATUS + " != " + GMSContact.STATUS_SYNCED,
                    null)
            .build();
    ops.add(op);

    op = ContentProviderOperation.newUpdate(GMSGroups.CONTENT_URI).withValue(GMSGroup.STATUS, null).build();
    ops.add(op);

    op = ContentProviderOperation.newUpdate(GMSContacts.CONTENT_URI).withValue(GMSContact.STATUS, null).build();
    ops.add(op);
    try {
        results = provider.applyBatch(ops);
        int numResults = results.length;
        for (int i = 0; i < numResults; ++i) {
            // The first first N-2 results were deletes
            if (i < numResults - 2) {
                syncResult.stats.numDeletes += results[i].count;
            } else {
                // The last two results were updates
                syncResult.stats.numEntries += results[i].count;
            }
        }
        Log.d(TAG, String.format("Delete unsynced items after count: %1$d, entries: %2$d",
                syncResult.stats.numDeletes, syncResult.stats.numEntries));
    } catch (OperationApplicationException e) {
        syncResult.stats.numSkippedEntries++;
        e.printStackTrace();
    }
}

From source file:org.gege.caldavsyncadapter.syncadapter.SyncAdapter.java

/**
 * checks the android events for the dirty flag.
 * the flag is set by android when the event has been changed. 
 * the dirty flag is removed when an android event has been updated from calendar event
 * @param provider//w  w w  .ja  v a2s.  c  o m
 * @param account
 * @param calendarUri
 * @param facade
 * @param caldavCalendarUri
 * @param stats
 * @param notifyList
 * @return count of dirty events
 */
private int checkDirtyAndroidEvents(ContentProviderClient provider, Account account, Uri calendarUri,
        CaldavFacade facade, URI caldavCalendarUri, SyncStats stats, ArrayList<Uri> notifyList) {
    Cursor curEvent = null;
    Cursor curAttendee = null;
    Cursor curReminder = null;
    Long EventID;
    Long CalendarID;
    AndroidEvent androidEvent = null;
    int rowDirty = 0;
    int rowInsert = 0;
    int rowUpdate = 0;
    int rowDelete = 0;

    try {
        CalendarID = ContentUris.parseId(calendarUri);
        String selection = "(" + Events.DIRTY + " = ?) AND (" + Events.CALENDAR_ID + " = ?)";
        String[] selectionArgs = new String[] { "1", CalendarID.toString() };
        curEvent = provider.query(Events.CONTENT_URI, null, selection, selectionArgs, null);

        while (curEvent.moveToNext()) {
            EventID = curEvent.getLong(curEvent.getColumnIndex(Events._ID));
            Uri returnedUri = ContentUris.withAppendedId(Events.CONTENT_URI, EventID);

            androidEvent = new AndroidEvent(account, provider, returnedUri, calendarUri);
            androidEvent.readContentValues(curEvent);

            selection = "(" + Attendees.EVENT_ID + " = ?)";
            selectionArgs = new String[] { String.valueOf(EventID) };
            curAttendee = provider.query(Attendees.CONTENT_URI, null, selection, selectionArgs, null);
            selection = "(" + Reminders.EVENT_ID + " = ?)";
            selectionArgs = new String[] { String.valueOf(EventID) };
            curReminder = provider.query(Reminders.CONTENT_URI, null, selection, selectionArgs, null);
            androidEvent.readAttendees(curAttendee);
            androidEvent.readReminder(curReminder);
            curAttendee.close();
            curReminder.close();

            String SyncID = androidEvent.ContentValues.getAsString(Events._SYNC_ID);

            boolean Deleted = false;
            int intDeleted = 0;
            intDeleted = curEvent.getInt(curEvent.getColumnIndex(Events.DELETED));
            Deleted = (intDeleted == 1);

            if (SyncID == null) {
                // new Android event
                String newGUID = java.util.UUID.randomUUID().toString() + "-caldavsyncadapter";
                String calendarPath = caldavCalendarUri.getPath();
                if (!calendarPath.endsWith("/"))
                    calendarPath += "/";

                SyncID = calendarPath + newGUID + ".ics";

                androidEvent.createIcs(newGUID);

                if (facade.createEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString())) {
                    //HINT: bugfix for google calendar
                    if (SyncID.contains("@"))
                        SyncID = SyncID.replace("@", "%40");
                    ContentValues values = new ContentValues();
                    values.put(Events._SYNC_ID, SyncID);

                    //google doesn't send the etag after creation
                    //HINT: my SabreDAV send always the same etag after putting a new event
                    //String LastETag = facade.getLastETag();
                    //if (!LastETag.equals("")) {
                    //   values.put(Event.ETAG, LastETag);
                    //} else {
                    //so get the etag with a new REPORT
                    CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                    calendarEvent.calendarURL = caldavCalendarUri.toURL();
                    URI SyncURI = new URI(SyncID);
                    calendarEvent.setUri(SyncURI);
                    CaldavFacade.getEvent(calendarEvent);
                    values.put(Event.ETAG, calendarEvent.getETag());
                    //}
                    values.put(Event.UID, newGUID);
                    values.put(Events.DIRTY, 0);
                    values.put(Event.RAWDATA, androidEvent.getIcsEvent().toString());

                    int rowCount = provider.update(
                            asSyncAdapter(androidEvent.getUri(), account.name, account.type), values, null,
                            null);
                    if (rowCount == 1) {
                        rowInsert += 1;
                        notifyList.add(androidEvent.getUri());
                    }
                }
            } else if (Deleted) {
                // deleted Android event
                if (facade.deleteEvent(URI.create(SyncID), androidEvent.getETag())) {
                    String mSelectionClause = "(" + Events._ID + "= ?)";
                    String[] mSelectionArgs = { String.valueOf(EventID) };

                    int countDeleted = provider.delete(
                            asSyncAdapter(Events.CONTENT_URI, account.name, account.type), mSelectionClause,
                            mSelectionArgs);

                    if (countDeleted == 1) {
                        rowDelete += 1;
                        notifyList.add(androidEvent.getUri());
                    }
                }
            } else {
                //update the android event to the server
                String uid = androidEvent.getUID();
                if ((uid == null) || (uid.equals(""))) {
                    //COMPAT: this is needed because in the past, the UID was not stored in the android event
                    CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                    URI syncURI = new URI(SyncID);
                    calendarEvent.setUri(syncURI);
                    calendarEvent.calendarURL = caldavCalendarUri.toURL();
                    if (calendarEvent.fetchBody()) {
                        calendarEvent.readContentValues();
                        uid = calendarEvent.getUID();
                    }
                }
                if (uid != null) {
                    androidEvent.createIcs(uid);

                    if (facade.updateEvent(URI.create(SyncID), androidEvent.getIcsEvent().toString(),
                            androidEvent.getETag())) {
                        selection = "(" + Events._ID + "= ?)";
                        selectionArgs = new String[] { EventID.toString() };
                        androidEvent.ContentValues.put(Events.DIRTY, 0);

                        //google doesn't send the etag after update
                        String LastETag = facade.getLastETag();
                        if (!LastETag.equals("")) {
                            androidEvent.ContentValues.put(Event.ETAG, LastETag);
                        } else {
                            //so get the etag with a new REPORT
                            CalendarEvent calendarEvent = new CalendarEvent(account, provider);
                            calendarEvent.calendarURL = caldavCalendarUri.toURL();
                            URI SyncURI = new URI(SyncID);
                            calendarEvent.setUri(SyncURI);
                            CaldavFacade.getEvent(calendarEvent);
                            androidEvent.ContentValues.put(Event.ETAG, calendarEvent.getETag());
                        }
                        androidEvent.ContentValues.put(Event.RAWDATA, androidEvent.getIcsEvent().toString());
                        int RowCount = provider.update(
                                asSyncAdapter(androidEvent.getUri(), account.name, account.type),
                                androidEvent.ContentValues, null, null);

                        if (RowCount == 1) {
                            rowUpdate += 1;
                            notifyList.add(androidEvent.getUri());
                        }
                    } else {
                        rowDirty += 1;
                    }
                } else {
                    rowDirty += 1;
                }
            }
        }
        curEvent.close();

        /*if ((rowInsert > 0) || (rowUpdate > 0) || (rowDelete > 0) || (rowDirty > 0)) {
           Log.i(TAG,"Android Rows inserted: " + String.valueOf(rowInsert));
           Log.i(TAG,"Android Rows updated:  " + String.valueOf(rowUpdate));
           Log.i(TAG,"Android Rows deleted:  " + String.valueOf(rowDelete));
           Log.i(TAG,"Android Rows dirty:    " + String.valueOf(rowDirty));
        }*/

        stats.numInserts += rowInsert;
        stats.numUpdates += rowUpdate;
        stats.numDeletes += rowDelete;
        stats.numSkippedEntries += rowDirty;
        stats.numEntries += rowInsert + rowUpdate + rowDelete;
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (CaldavProtocolException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    } catch (ParserException e) {
        // TODO Automatisch generierter Erfassungsblock
        e.printStackTrace();
    }

    return rowDirty;
}

From source file:com.android.music.TrackBrowserFragment.java

private void setTitle() {

    CharSequence fancyName = null;
    if (mAlbumId != null) {
        int numresults = mTrackCursor != null ? mTrackCursor.getCount() : 0;
        if (numresults > 0) {
            mTrackCursor.moveToFirst();/*from  w  ww . j  a  v a  2  s  . c  om*/
            int idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
            fancyName = mTrackCursor.getString(idx);
            // For compilation albums show only the album title,
            // but for regular albums show "artist - album".
            // To determine whether something is a compilation
            // album, do a query for the artist + album of the
            // first item, and see if it returns the same number
            // of results as the album query.
            String where = MediaStore.Audio.Media.ALBUM_ID + "='" + mAlbumId + "' AND "
                    + MediaStore.Audio.Media.ARTIST_ID + "=" + mTrackCursor
                            .getLong(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID));
            Cursor cursor = MusicUtils.query(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[] { MediaStore.Audio.Media.ALBUM }, where, null, null);
            if (cursor != null) {
                if (cursor.getCount() != numresults) {
                    // compilation album
                    fancyName = mTrackCursor.getString(idx);
                }
                cursor.deactivate();
            }
            if (fancyName == null || fancyName.equals(MediaStore.UNKNOWN_STRING)) {
                fancyName = getString(R.string.unknown_album_name);
            }
        }
    } else if (mPlaylist != null) {
        if (mPlaylist.equals("nowplaying")) {
            if (MusicUtils.getCurrentShuffleMode() == MediaPlaybackService.SHUFFLE_AUTO) {
                fancyName = getText(R.string.partyshuffle_title);
            } else {
                fancyName = getText(R.string.nowplaying_title);
            }
        } else if (mPlaylist.equals("podcasts")) {
            fancyName = getText(R.string.podcasts_title);
        } else if (mPlaylist.equals("recentlyadded")) {
            fancyName = getText(R.string.recentlyadded_title);
        } else {
            String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
            Cursor cursor = MusicUtils.query(getActivity(),
                    ContentUris.withAppendedId(Playlists.EXTERNAL_CONTENT_URI, Long.valueOf(mPlaylist)), cols,
                    null, null, null);
            if (cursor != null) {
                if (cursor.getCount() != 0) {
                    cursor.moveToFirst();
                    fancyName = cursor.getString(0);
                }
                cursor.deactivate();
            }
        }
    } else if (mGenre != null) {
        String[] cols = new String[] { MediaStore.Audio.Genres.NAME };
        Cursor cursor = MusicUtils.query(getActivity(),
                ContentUris.withAppendedId(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, Long.valueOf(mGenre)),
                cols, null, null, null);
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                cursor.moveToFirst();
                fancyName = cursor.getString(0);
            }
            cursor.deactivate();
        }
    }

    if (fancyName != null) {
        getActivity().setTitle(fancyName);
    } else {
        getActivity().setTitle(R.string.tracks_title);
    }
}

From source file:io.n7.calendar.caldav.CalDAVService.java

private void updateEventOnServer(String uid, long id, CalDAV4jIf caldavif) throws Exception {
    VEvent ve = getEvFromDB(uid, id);//  w w  w.  j  av  a 2s.  c o  m
    if (ve != null) {
        caldavif.updateEv(ve);

        //update DB to clear dirty
        ContentValues cv = new ContentValues();
        cv.put(Events._SYNC_DIRTY, 0);
        mCR.update(ContentUris.withAppendedId(EVENTS_URI, id), cv, null, null);
    } else
        //XXX this should never happen
        Log.e(TAG, "Could not find event with uid " + uid);

}

From source file:com.kyakujin.android.autoeco.ui.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterView.AdapterContextMenuInfo info;
    try {//from  w w w.  ja va 2s. c o  m
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    android.view.MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.context_menu_schedlist, menu);

    menu.setHeaderTitle(getResources().getString(R.string.label_menu));

    Intent intent = new Intent(null, ContentUris.withAppendedId(SchedTbl.CONTENT_URI, (int) info.id));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(mActivity, MainActivity.class),
            null, intent, 0, null);
}