Example usage for android.content ContentResolver delete

List of usage examples for android.content ContentResolver delete

Introduction

In this page you can find the example usage for android.content ContentResolver delete.

Prototype

public final int delete(@RequiresPermission.Write @NonNull Uri url, @Nullable String where,
        @Nullable String[] selectionArgs) 

Source Link

Document

Deletes row(s) specified by a content URI.

Usage

From source file:com.bt.download.android.gui.Librarian.java

private void deleteSharedStates(List<Integer> sharingIds) {
    try {/*from   ww  w .  ja v a  2  s  . c om*/
        ContentResolver cr = context.getContentResolver();
        int deleted = cr.delete(UniversalStore.Sharing.Media.CONTENT_URI,
                SharingColumns._ID + " IN " + StringUtils.buildSet(sharingIds), null);
        Log.d(TAG, "Deleted " + deleted + " shared states");
    } catch (Throwable e) {
        Log.e(TAG, "Failed to delete shared states", e);
    }
}

From source file:com.bt.download.android.gui.Librarian.java

private void deleteSharedState(byte fileType, int fileId) {
    try {//from  ww w .j  a v a 2  s.c  om
        ContentResolver cr = context.getContentResolver();
        int deleted = cr.delete(UniversalStore.Sharing.Media.CONTENT_URI,
                SharingColumns.FILE_ID + "= ? AND " + SharingColumns.FILE_TYPE + " = ?",
                new String[] { String.valueOf(fileId), String.valueOf(fileType) });
        Log.d(TAG, "deleteSharedState " + deleted + " rows  (fileType: " + fileType + ", fileId: " + fileId
                + " )");
    } catch (Throwable e) {
        Log.e(TAG, "Failed to delete shared state for fileType=" + fileType + ", fileId=" + fileId, e);
    }
}

From source file:com.android.unit_tests.CheckinProviderTest.java

@MediumTest
public void testEventReport() {
    long start = System.currentTimeMillis();
    ContentResolver r = getContext().getContentResolver();
    Checkin.logEvent(r, Checkin.Events.Tag.TEST, "Test Value");

    Cursor c = r.query(Checkin.Events.CONTENT_URI, null, Checkin.Events.TAG + "=?",
            new String[] { Checkin.Events.Tag.TEST.toString() }, null);

    long id = -1;
    while (c.moveToNext()) {
        String tag = c.getString(c.getColumnIndex(Checkin.Events.TAG));
        String value = c.getString(c.getColumnIndex(Checkin.Events.VALUE));
        long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE));
        assertEquals(Checkin.Events.Tag.TEST.toString(), tag);
        if ("Test Value".equals(value) && date >= start) {
            assertTrue(id < 0);/*from  w  w  w .  j av  a 2 s  .  c om*/
            id = c.getInt(c.getColumnIndex(Checkin.Events._ID));
        }
    }
    assertTrue(id > 0);

    int rows = r.delete(ContentUris.withAppendedId(Checkin.Events.CONTENT_URI, id), null, null);
    assertEquals(1, rows);
    c.requery();
    while (c.moveToNext()) {
        long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE));
        assertTrue(date < start); // Have deleted the only newer TEST.
    }

    c.close();
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Processes the specified destructive action (archive, delete, mute) on the message.
 *//*from  ww  w  .  j  a  v a2s .  co m*/
public static void processDestructiveAction(final Context context,
        final NotificationAction notificationAction) {
    LogUtils.i(LOG_TAG, "processDestructiveAction: %s", notificationAction.getNotificationActionType());

    final NotificationActionType destructAction = notificationAction.getNotificationActionType();
    final Conversation conversation = notificationAction.getConversation();
    final Folder folder = notificationAction.getFolder();

    final ContentResolver contentResolver = context.getContentResolver();
    final Uri uri = conversation.uri.buildUpon()
            .appendQueryParameter(UIProvider.FORCE_UI_NOTIFICATIONS_QUERY_PARAMETER, Boolean.TRUE.toString())
            .build();

    switch (destructAction) {
    case ARCHIVE_REMOVE_LABEL: {
        if (folder.isInbox()) {
            // Inbox, so archive
            final ContentValues values = new ContentValues(1);
            values.put(UIProvider.ConversationOperations.OPERATION_KEY,
                    UIProvider.ConversationOperations.ARCHIVE);

            contentResolver.update(uri, values, null, null);
        } else {
            // Not inbox, so remove label
            final ContentValues values = new ContentValues(1);

            final String removeFolderUri = folder.folderUri.fullUri.buildUpon()
                    .appendPath(Boolean.FALSE.toString()).toString();
            values.put(ConversationOperations.FOLDERS_UPDATED, removeFolderUri);

            contentResolver.update(uri, values, null, null);
        }
        break;
    }
    case DELETE: {
        contentResolver.delete(uri, null, null);
        break;
    }
    default:
        throw new IllegalArgumentException("The specified NotificationActionType is not a destructive action.");
    }
}

From source file:com.bt.download.android.gui.Librarian.java

public void deleteFiles(byte fileType, Collection<FileDescriptor> fds) {
    List<Integer> ids = new ArrayList<Integer>(fds.size());

    for (FileDescriptor fd : fds) {
        if (new File(fd.filePath).delete()) {
            ids.add(fd.id);//w  ww. j  a v  a  2 s  .  com
            deleteSharedState(fd.fileType, fd.id);
        }
    }

    try {
        ContentResolver cr = context.getContentResolver();
        TableFetcher fetcher = TableFetchers.getFetcher(fileType);
        cr.delete(fetcher.getContentUri(), MediaColumns._ID + " IN " + StringUtils.buildSet(ids), null);
    } catch (Throwable e) {
        Log.e(TAG, "Failed to delete files from media store", e);
    }

    invalidateCountCache(fileType);
}

From source file:com.sentaroh.android.SMBExplorer.FileIo.java

@SuppressLint("InlinedApi")
private static int deleteMediaStoreItem(String fp) {
    int dc_image = 0, dc_audio = 0, dc_video = 0, dc_files = 0;
    String mt = isMediaFile(fp);/*from www.j  a  v a  2s  .co  m*/
    if (mt != null && (mt.startsWith("audio") || mt.startsWith("video") || mt.startsWith("image"))) {
        ContentResolver cri = mContext.getContentResolver();
        ContentResolver cra = mContext.getContentResolver();
        ContentResolver crv = mContext.getContentResolver();
        ContentResolver crf = mContext.getContentResolver();
        dc_image = cri.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.DATA + "=?",
                new String[] { fp });
        dc_audio = cra.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.Media.DATA + "=?",
                new String[] { fp });
        dc_video = crv.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.DATA + "=?",
                new String[] { fp });
        if (Build.VERSION.SDK_INT >= 11) {
            dc_files = crf.delete(MediaStore.Files.getContentUri("external"),
                    MediaStore.Files.FileColumns.DATA + "=?", new String[] { fp });
        }
        sendLogMsg("I", "deleMediaStoreItem fn=" + fp + ", delete count image=" + dc_image + ", audio="
                + dc_audio + ", video=" + dc_video + ", files=" + dc_files);
    } else {
        sendDebugLogMsg(1, "I", "deleMediaStoreItem not MediaStore library. fn=" + fp + "");
    }

    return dc_image + dc_audio + dc_video + dc_files;
}

From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {//from   w  w  w  . j av  a 2s  .c o  m

    Context context = getContext();

    App.getApiManager().getEarthquakeService().getData().enqueue(new Callback<EarthquakeObject>() {
        @Override
        public void onResponse(Call<EarthquakeObject> call, Response<EarthquakeObject> response) {
            EarthquakeObject earthquake = response.body();

            Vector<ContentValues> cVVector = new Vector<>(earthquake.getFeatures().size());

            double currentBiggest = 0.0;
            ContentValues notifyValues = null;

            for (Feature each : earthquake.getFeatures()) {

                ContentValues earthquakeValues = new ContentValues();

                earthquakeValues.put(EarthquakeColumns.PLACE, each.getProperties().getPlace());
                earthquakeValues.put(EarthquakeColumns.ID_EARTH, each.getId());
                earthquakeValues.put(EarthquakeColumns.MAG, each.getProperties().getMag());
                earthquakeValues.put(EarthquakeColumns.TYPE, each.getProperties().getType());
                earthquakeValues.put(EarthquakeColumns.ALERT, each.getProperties().getAlert());
                earthquakeValues.put(EarthquakeColumns.TIME, each.getProperties().getTime());
                earthquakeValues.put(EarthquakeColumns.URL, each.getProperties().getUrl());
                earthquakeValues.put(EarthquakeColumns.DETAIL, each.getProperties().getDetail());
                earthquakeValues.put(EarthquakeColumns.DEPTH, each.getGeometry().getCoordinates().get(2));
                earthquakeValues.put(EarthquakeColumns.LONGITUDE, each.getGeometry().getCoordinates().get(0));
                earthquakeValues.put(EarthquakeColumns.LATITUDE, each.getGeometry().getCoordinates().get(1));

                LatLng latLng = new LatLng(each.getGeometry().getCoordinates().get(1),
                        each.getGeometry().getCoordinates().get(0));
                LatLng location = LocationUtils.getLocation(context);
                earthquakeValues.put(EarthquakeColumns.DISTANCE, LocationUtils.getDistance(latLng, location));

                cVVector.add(earthquakeValues);

                if (each.getProperties().getMag() != null && each.getProperties().getMag() > currentBiggest) {
                    currentBiggest = each.getProperties().getMag();
                    notifyValues = new ContentValues(earthquakeValues);
                    notifyValues.put(EarthquakeColumns.PLACE,
                            Utilities.formatEarthquakePlace(each.getProperties().getPlace()));
                }
            }

            int inserted = 0;
            // add to database
            ContentResolver resolver = context.getContentResolver();

            if (cVVector.size() > 0) {
                ContentValues[] cvArray = new ContentValues[cVVector.size()];
                cVVector.toArray(cvArray);
                inserted = resolver.bulkInsert(EarthquakeColumns.CONTENT_URI, cvArray);
            }

            // Set the date to day minus one to delete old data from the database
            Date date = new Date();
            date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS);

            int deleted = resolver.delete(EarthquakeColumns.CONTENT_URI, EarthquakeColumns.TIME + " <= ?",
                    new String[] { String.valueOf(date.getTime()) });
            Log.v(TAG, "Service Complete. " + inserted + " Inserted, " + deleted + " deleted");
            sendNotification(notifyValues);
        }

        @Override
        public void onFailure(Call<EarthquakeObject> call, Throwable t) {
            Log.e(TAG, "onFailure: " + t.toString());
        }
    });

    App.getNewsManager().getNewsService().getNews().enqueue(new Callback<Rss>() {
        @Override
        public void onResponse(Call<Rss> call, Response<Rss> response) {
            Channel news = response.body().getChannel();

            Vector<ContentValues> cVVector = new Vector<>(news.getItem().size());

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z",
                    Locale.getDefault());
            Date date = new Date();

            for (Item each : news.getItem()) {

                ContentValues weatherValues = new ContentValues();

                try {
                    date = simpleDateFormat.parse(each.getPubDate());
                } catch (ParseException e) {
                    Log.e(TAG, "e:" + e);
                }

                weatherValues.put(NewsColumns.DATE, date.getTime());
                weatherValues.put(NewsColumns.TITLE, each.getTitle());
                weatherValues.put(NewsColumns.DESCRIPTION,
                        Html.toHtml(new SpannedString(each.getDescription())));
                weatherValues.put(NewsColumns.URL, each.getLink());
                weatherValues.put(NewsColumns.GUID, each.getGuid().getContent());

                cVVector.add(weatherValues);
            }

            int inserted = 0;
            // add to database
            ContentResolver resolver = getContext().getContentResolver();

            if (cVVector.size() > 0) {

                // Student: call bulkInsert to add the weatherEntries to the database here
                ContentValues[] cvArray = new ContentValues[cVVector.size()];
                cVVector.toArray(cvArray);
                inserted = resolver.bulkInsert(NewsColumns.CONTENT_URI, cvArray);
            }

            // Set the date to day minus two to delete old data from the database
            date = new Date();
            date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS * 3);

            int deleted = resolver.delete(NewsColumns.CONTENT_URI, NewsColumns.DATE + " <= ?",
                    new String[] { String.valueOf(date.getTime()) });
        }

        @Override
        public void onFailure(Call<Rss> call, Throwable t) {
            Log.e(TAG, "onFailure: " + t.toString());
        }
    });

    // TODO: 4/22/16 possible refactoring 
    //checking the last update and notify if it' the first of the day
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String lastNotificationKey = context.getString(R.string.sharedprefs_key_last_countupdate);
    long lastSync = prefs.getLong(lastNotificationKey, DateUtils.DAY_IN_MILLIS);

    if (System.currentTimeMillis() - lastSync >= Utilities.getSyncIntervalPrefs(context)
            * DateUtils.SECOND_IN_MILLIS) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        Date date = new Date(System.currentTimeMillis());

        String startTime[] = new String[] { simpleDateFormat.format(date.getTime() - DateUtils.YEAR_IN_MILLIS),
                simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS * 30),
                simpleDateFormat.format(date.getTime() - DateUtils.WEEK_IN_MILLIS),
                simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS) };

        String endTime = simpleDateFormat.format(date);

        int iterator = 1;
        while (iterator < CountColumns.ALL_COLUMNS.length) {
            final int round = iterator;

            App.getApiManager().getEarthquakeService().getEarthquakeStats(startTime[round - 1], endTime)
                    .enqueue(new Callback<CountEarthquakes>() {
                        @Override
                        public void onResponse(Call<CountEarthquakes> call,
                                Response<CountEarthquakes> response) {
                            ContentValues count = new ContentValues();
                            count.put(CountColumns.ALL_COLUMNS[round], response.body().getCount());

                            ContentResolver contentResolver = context.getContentResolver();

                            Cursor cursor = contentResolver.query(CountColumns.CONTENT_URI, null, null, null,
                                    null);

                            if (cursor != null) {
                                if (cursor.getCount() < 1) {
                                    long inserted = ContentUris
                                            .parseId(contentResolver.insert(CountColumns.CONTENT_URI, count));
                                    //Log.d(TAG, "inserted:" + inserted);
                                } else {
                                    int updated = contentResolver.update(CountColumns.CONTENT_URI, count,
                                            CountColumns._ID + " = ?", new String[] { "1" });
                                    //Log.d(TAG, "updated: " + updated);
                                }
                                cursor.close();
                            }

                        }

                        @Override
                        public void onFailure(Call<CountEarthquakes> call, Throwable t) {
                            Log.e(TAG, "Error: " + t);
                        }
                    });
            iterator++;
        }

        //refreshing last sync
        prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).apply();
    }

    // notify PagerActivity that data has been updated
    context.getContentResolver().notifyChange(EarthquakeColumns.CONTENT_URI, null, false);
    context.getContentResolver().notifyChange(NewsColumns.CONTENT_URI, null, false);
    context.getContentResolver().notifyChange(CountColumns.CONTENT_URI, null, false);

    updateWidgets();
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

@SuppressLint({ "NewApi", "NewApi", "NewApi" })
@Override//from  ww  w .  ja  v a  2  s  .  c om
public boolean onMenuItemClick(final MenuItem item) {
    if (mStatus == null)
        return false;
    final String text_plain = mStatus.text_plain;
    final String screen_name = mStatus.screen_name;
    final String name = mStatus.name;
    switch (item.getItemId()) {
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + mStatus.screen_name + ": " + text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_RETWEET: {
        if (isMyRetweet(mStatus)) {
            mService.destroyStatus(mAccountId, mStatus.retweet_id);
        } else {
            final long id_to_retweet = mStatus.is_retweet && mStatus.retweet_id > 0 ? mStatus.retweet_id
                    : mStatus.status_id;
            mService.retweetStatus(mAccountId, id_to_retweet);
        }
        break;
    }
    case MENU_TRANSLATE: {
        translate(mStatus);
        break;
    }
    case MENU_QUOTE_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_ADD_TO_BUFFER: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putBoolean(INTENT_KEY_IS_BUFFER, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), screen_name, text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final List<String> mentions = new Extractor().extractMentionedScreennames(text_plain);
        mentions.remove(screen_name);
        mentions.add(0, screen_name);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, mStatusId);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, text_plain);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAV: {
        if (mStatus.is_favorite) {
            mService.destroyFavorite(mAccountId, mStatusId);
        } else {
            mService.createFavorite(mAccountId, mStatusId);
        }
        break;
    }
    case MENU_COPY_CLIPBOARD: {
        final String textToCopy = "@" + mStatus.screen_name + ": " + mStatus.text_plain;
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            clipboard.setText(textToCopy);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData.newPlainText("Status", textToCopy);
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_DELETE: {
        mService.destroyStatus(mAccountId, mStatusId);
        break;
    }
    case MENU_EXTENSIONS: {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_STATUS, mStatus);
        intent.putExtras(extras);
        startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions)));
        break;
    }
    case MENU_MUTE_SOURCE: {
        final String source = HtmlEscapeHelper.unescape(mStatus.source);
        if (source == null)
            return false;
        final Uri uri = Filters.Sources.CONTENT_URI;
        final ContentValues values = new ContentValues();
        final SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFERENCES_NAME,
                Context.MODE_PRIVATE).edit();
        final ContentResolver resolver = getContentResolver();
        values.put(Filters.TEXT, source);
        resolver.delete(uri, Filters.TEXT + " = '" + source + "'", null);
        resolver.insert(uri, values);
        editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit();
        Toast.makeText(getActivity(), getString(R.string.source_muted, source), Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(INTENT_ACTION_SET_COLOR);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_COLOR: {
        clearUserColor(getActivity(), mStatus.user_id);
        updateUserColor();
        break;
    }
    case MENU_RECENT_TWEETS: {
        openUserTimeline(getActivity(), mAccountId, mStatus.user_id, mStatus.screen_name);
        break;
    }
    case MENU_FIND_RETWEETS: {
        openUserRetweetedStatus(getActivity(), mStatus.account_id,
                mStatus.retweet_id > 0 ? mStatus.retweet_id : mStatus.status_id);
        break;
    }
    default:
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.akop.bach.parser.PsnParser.java

@Override
public void deleteAccount(BasicAccount account) {
    ContentResolver cr = mContext.getContentResolver();
    long accountId = account.getId();

    // Clear games & achievements
    StringBuffer buffer = new StringBuffer();
    Cursor c = cr.query(Games.CONTENT_URI, new String[] { Games._ID }, Games.ACCOUNT_ID + "=" + accountId, null,
            null);/*from   w  w  w.  ja  v  a  2s .  c o m*/

    try {
        if (c != null) {
            while (c.moveToNext()) {
                if (buffer.length() > 0)
                    buffer.append(",");
                buffer.append(c.getLong(0));
            }
        }
    } finally {
        if (c != null)
            c.close();
    }

    // Clear trophies
    cr.delete(Trophies.CONTENT_URI, Trophies.GAME_ID + " IN (" + buffer.toString() + ")", null);

    // Clear rest of data
    cr.delete(Games.CONTENT_URI, Games.ACCOUNT_ID + "=" + accountId, null);
    cr.delete(Profiles.CONTENT_URI, Profiles.ACCOUNT_ID + "=" + accountId, null);
    cr.delete(Friends.CONTENT_URI, Friends.ACCOUNT_ID + "=" + accountId, null);

    // Send notifications
    cr.notifyChange(Profiles.CONTENT_URI, null);
    cr.notifyChange(Trophies.CONTENT_URI, null);
    cr.notifyChange(Games.CONTENT_URI, null);
    cr.notifyChange(Friends.CONTENT_URI, null);

    // Delete authenticated session
    deleteSession(account);
}

From source file:org.mariotaku.twidere.fragment.UserProfileFragment.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    if (mUser == null || mTwitterWrapper == null)
        return false;
    switch (item.getItemId()) {
    case MENU_TAKE_PHOTO: {
        takePhoto();/*from w ww .j av  a 2 s.  c o  m*/
        break;
    }
    case MENU_ADD_IMAGE: {
        pickImage();
        break;
    }
    case MENU_BLOCK: {
        if (mTwitterWrapper == null || mFriendship == null) {
            break;
        }
        if (mFriendship.isSourceBlockingTarget()) {
            mTwitterWrapper.destroyBlock(mAccountId, mUser.user_id);
        } else {
            mTwitterWrapper.createBlockAsync(mAccountId, mUser.user_id);
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        mTwitterWrapper.reportSpam(mAccountId, mUser.user_id);
        break;
    }
    case MENU_MUTE_USER: {
        final String screen_name = mUser.screen_name;
        final Uri uri = Filters.Users.CONTENT_URI;
        final ContentValues values = new ContentValues();
        final ContentResolver resolver = getContentResolver();
        values.put(Filters.Users.TEXT, screen_name);
        resolver.delete(uri, Filters.Users.TEXT + " = '" + screen_name + "'", null);
        resolver.insert(uri, values);
        Toast.makeText(getActivity(), R.string.user_muted, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final String name = mUser.name;
        final String screen_name = mUser.screen_name;
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
        bundle.putString(INTENT_KEY_TEXT, "@" + screen_name + " ");
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWIDERE);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(mAccountId));
        builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(mUser.user_id));
        startActivity(new Intent(Intent.ACTION_VIEW, builder.build()));
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), SetColorActivity.class);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_COLOR: {
        clearUserColor(getActivity(), mUserId);
        mProfileNameContainer.drawLeft(getUserColor(getActivity(), mUserId));
        break;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}