Example usage for android.content ContentResolver update

List of usage examples for android.content ContentResolver update

Introduction

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

Prototype

public final int update(@RequiresPermission.Write @NonNull Uri uri, @Nullable ContentValues values,
        @Nullable String where, @Nullable String[] selectionArgs) 

Source Link

Document

Update row(s) in a content URI.

Usage

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

public void displayUser(final ParcelableUser user) {
    mFriendship = null;//ww w . java2 s .  co  m
    mUser = null;
    mUserId = -1;
    mAccountId = -1;
    mAdapter.clear();
    if (user == null || user.user_id <= 0 || getActivity() == null)
        return;
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final boolean user_is_me = user.account_id == user.user_id;
    mErrorRetryContainer.setVisibility(View.GONE);
    mAccountId = user.account_id;
    mUser = user;
    mUserId = user.user_id;
    mScreenName = user.screen_name;
    mProfileNameContainer.drawLeft(getUserColor(getActivity(), mUserId));
    mProfileNameContainer.drawRight(getAccountColor(getActivity(), user.account_id));
    mNameView.setText(user.name);
    mNameView.setCompoundDrawablesWithIntrinsicBounds(0, 0,
            getUserTypeIconRes(user.is_verified, user.is_protected), 0);
    mScreenNameView.setText("@" + user.screen_name);
    final String description = user.description;
    mDescriptionContainer.setVisibility(user_is_me || !isEmpty(description) ? View.VISIBLE : View.GONE);
    mDescriptionView.setText(description);
    final TwidereLinkify linkify = new TwidereLinkify(mDescriptionView);
    linkify.setOnLinkClickListener(this);
    linkify.addAllLinks();
    mDescriptionView.setMovementMethod(null);
    final String location = user.location;
    mLocationContainer.setVisibility(user_is_me || !isEmpty(location) ? View.VISIBLE : View.GONE);
    mLocationView.setText(location);
    mURLContainer.setVisibility(user_is_me || !isEmpty(user.url) ? View.VISIBLE : View.GONE);
    mURLView.setText(user.url);
    mURLView.setMovementMethod(null);
    mCreatedAtView.setText(formatToLongTimeString(getActivity(), user.created_at));
    mTweetCount.setText(String.valueOf(user.statuses_count));
    mFollowersCount.setText(String.valueOf(user.followers_count));
    mFriendsCount.setText(String.valueOf(user.friends_count));
    if (mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true)) {
        mProfileImageLoader.displayImage(mProfileImageView, user.profile_image_url);
    } else {
        mProfileImageView.setImageResource(R.drawable.ic_profile_image_default);
    }
    if (isMyAccount(getActivity(), user.user_id)) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        if (user.profile_image_url != null) {
            values.put(Accounts.PROFILE_IMAGE_URL, user.profile_image_url);
        }
        values.put(Accounts.NAME, user.name);
        values.put(Accounts.SCREEN_NAME, user.screen_name);
        final String where = Accounts.ACCOUNT_ID + " = " + user.user_id;
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new FavoritesAction(1));
    mAdapter.add(new UserMentionsAction(2));
    mAdapter.add(new UserListsAction(3));
    if (user_is_me) {
        mAdapter.add(new SavedSearchesAction(4));
        if (user.is_protected) {
            mAdapter.add(new IncomingFriendshipsAction(5));
        }
        mAdapter.add(new UserBlocksAction(6));
    }
    mAdapter.notifyDataSetChanged();
    if (!user.is_cache) {
        getFriendship();
    }
    getBannerImage();
}

From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java

@SuppressWarnings("Recycle")
private void update_0_1() throws URISyntaxException {
    String v0_principalURL = accountManager.getUserData(account, "principal_url"),
            v0_addressBookPath = accountManager.getUserData(account, "addressbook_path");
    Constants.log.debug("Old principal URL = " + v0_principalURL);
    Constants.log.debug("Old address book path = " + v0_addressBookPath);

    URI principalURI = new URI(v0_principalURL);

    // update address book
    if (v0_addressBookPath != null) {
        String addressBookURL = principalURI.resolve(v0_addressBookPath).toASCIIString();
        Constants.log.debug("New address book URL = " + addressBookURL);
        accountManager.setUserData(account, "addressbook_url", addressBookURL);
    }/*from w w w . j  a v a 2 s .  co m*/

    // update calendars
    ContentResolver resolver = context.getContentResolver();
    Uri calendars = Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
            .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup
    Cursor cursor = resolver.query(calendars, new String[] { Calendars._ID, Calendars.NAME }, null, null, null);
    while (cursor != null && cursor.moveToNext()) {
        int id = cursor.getInt(0);
        String v0_path = cursor.getString(1), v1_url = principalURI.resolve(v0_path).toASCIIString();
        Constants.log.debug("Updating calendar #" + id + " name: " + v0_path + " -> " + v1_url);
        Uri calendar = ContentUris.appendId(
                Calendars.CONTENT_URI.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                        .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                        .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true"),
                id).build();
        ContentValues newValues = new ContentValues(1);
        newValues.put(Calendars.NAME, v1_url);
        if (resolver.update(calendar, newValues, null, null) != 1)
            Constants.log.debug("Number of modified calendars != 1");
    }

    accountManager.setUserData(account, "principal_url", null);
    accountManager.setUserData(account, "addressbook_path", null);

    accountManager.setUserData(account, KEY_SETTINGS_VERSION, "1");
}

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

public void displayUser(final ParcelableUser user) {
    mFriendship = null;/* ww  w  .j  av  a2s .co m*/
    mUser = null;
    mAdapter.clear();
    if (user == null || user.id <= 0 || getActivity() == null)
        return;
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final boolean userIsMe = user.account_id == user.id;
    mErrorRetryContainer.setVisibility(View.GONE);
    mUser = user;
    mProfileNameContainer.drawStart(getUserColor(getActivity(), user.id, true));
    mProfileNameContainer.drawEnd(getAccountColor(getActivity(), user.account_id));
    final String nick = getUserNickname(getActivity(), user.id, true);
    mNameView.setText(
            TextUtils.isEmpty(nick) ? user.name : getString(R.string.name_with_nickname, user.name, nick));
    mProfileImageView.setUserType(user.is_verified, user.is_protected);
    mScreenNameView.setText("@" + user.screen_name);
    mDescriptionContainer.setVisibility(userIsMe || !isEmpty(user.description_html) ? View.VISIBLE : View.GONE);
    mDescriptionView.setText(user.description_html != null ? Html.fromHtml(user.description_html) : null);
    final TwidereLinkify linkify = new TwidereLinkify(this);
    linkify.setLinkTextColor(ThemeUtils.getUserLinkTextColor(getActivity()));
    linkify.applyAllLinks(mDescriptionView, user.account_id, false);
    mDescriptionView.setMovementMethod(null);
    mLocationContainer.setVisibility(userIsMe || !isEmpty(user.location) ? View.VISIBLE : View.GONE);
    mLocationView.setText(user.location);
    mURLContainer.setVisibility(
            userIsMe || !isEmpty(user.url) || !isEmpty(user.url_expanded) ? View.VISIBLE : View.GONE);
    mURLView.setText(isEmpty(user.url_expanded) ? user.url : user.url_expanded);
    mURLView.setMovementMethod(null);
    final String created_at = formatToLongTimeString(getActivity(), user.created_at);
    final double total_created_days = (System.currentTimeMillis() - user.created_at) / 1000 / 60 / 60 / 24;
    final long daily_tweets = Math.round(user.statuses_count / Math.max(1, total_created_days));
    mCreatedAtView.setText(getString(R.string.daily_statuses_count, created_at, daily_tweets));
    mTweetCount.setText(getLocalizedNumber(mLocale, user.statuses_count));
    mFollowersCount.setText(getLocalizedNumber(mLocale, user.followers_count));
    mFriendsCount.setText(getLocalizedNumber(mLocale, user.friends_count));
    if (mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true)) {
        mProfileImageLoader.displayProfileImage(mProfileImageView,
                getOriginalTwitterProfileImage(user.profile_image_url));
        final int def_width = getResources().getDisplayMetrics().widthPixels;
        final int width = mBannerWidth > 0 ? mBannerWidth : def_width;
        mProfileBannerView.setImageBitmap(null);
        mProfileImageLoader.displayProfileBanner(mProfileBannerView, user.profile_banner_url, width);
    } else {
        mProfileImageView.setImageResource(R.drawable.ic_profile_image_default);
        mProfileBannerView.setImageResource(android.R.color.transparent);
    }
    if (isMyAccount(getActivity(), user.id)) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        values.put(Accounts.NAME, user.name);
        values.put(Accounts.SCREEN_NAME, user.screen_name);
        values.put(Accounts.PROFILE_IMAGE_URL, user.profile_image_url);
        values.put(Accounts.PROFILE_BANNER_URL, user.profile_banner_url);
        final String where = Accounts.ACCOUNT_ID + " = " + user.id;
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new FavoritesAction(1));
    mAdapter.add(new UserMentionsAction(2));
    mAdapter.add(new UserListsAction(3));
    mAdapter.add(new UserListMembershipsAction(4));
    if (userIsMe) {
        mAdapter.add(new SavedSearchesAction(11));
        if (user.is_protected) {
            mAdapter.add(new IncomingFriendshipsAction(12));
        }
        mAdapter.add(new UserBlocksAction(13));
    }
    mAdapter.notifyDataSetChanged();
    if (!user.is_cache) {
        getFriendship();
    }
    invalidateOptionsMenu();
    setMenu(mMenuBar.getMenu());
    mMenuBar.show();
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

public void displayUser(final ParcelableUser user) {
    mRelationship = null;/*ww w.j  a v  a2 s  .c om*/
    mUser = null;
    mAdapter.clear();
    if (user == null || user.id <= 0 || getActivity() == null)
        return;
    final Resources res = getResources();
    final LoaderManager lm = getLoaderManager();
    lm.destroyLoader(LOADER_ID_USER);
    lm.destroyLoader(LOADER_ID_FRIENDSHIP);
    final boolean userIsMe = user.account_id == user.id;
    mErrorRetryContainer.setVisibility(View.GONE);
    mUser = user;
    mProfileNameContainer.drawStart(getUserColor(getActivity(), user.id, true));
    mProfileNameContainer.drawEnd(getAccountColor(getActivity(), user.account_id));
    final String nick = getUserNickname(getActivity(), user.id, true);
    mNameView.setText(
            TextUtils.isEmpty(nick) ? user.name : getString(R.string.name_with_nickname, user.name, nick));
    mProfileImageView.setUserType(user.is_verified, user.is_protected);
    mScreenNameView.setText("@" + user.screen_name);
    mDescriptionContainer.setVisibility(userIsMe || !isEmpty(user.description_html) ? View.VISIBLE : View.GONE);
    mDescriptionView.setText(user.description_html != null ? Html.fromHtml(user.description_html) : null);
    final TwidereLinkify linkify = new TwidereLinkify(this);
    linkify.setLinkTextColor(ThemeUtils.getUserLinkTextColor(getActivity()));
    linkify.applyAllLinks(mDescriptionView, user.account_id, false);
    mDescriptionView.setMovementMethod(null);
    mLocationContainer.setVisibility(userIsMe || !isEmpty(user.location) ? View.VISIBLE : View.GONE);
    mLocationView.setText(user.location);
    mURLContainer.setVisibility(
            userIsMe || !isEmpty(user.url) || !isEmpty(user.url_expanded) ? View.VISIBLE : View.GONE);
    mURLView.setText(isEmpty(user.url_expanded) ? user.url : user.url_expanded);
    mURLView.setMovementMethod(null);
    final String createdAt = formatToLongTimeString(getActivity(), user.created_at);
    final float daysSinceCreated = (System.currentTimeMillis() - user.created_at) / 1000 / 60 / 60 / 24;
    final int dailyTweets = Math.round(user.statuses_count / Math.max(1, daysSinceCreated));
    mCreatedAtView.setText(res.getQuantityString(R.plurals.created_at_with_N_tweets_per_day, dailyTweets,
            createdAt, dailyTweets));
    mTweetCount.setText(getLocalizedNumber(mLocale, user.statuses_count));
    mFollowersCount.setText(getLocalizedNumber(mLocale, user.followers_count));
    mFriendsCount.setText(getLocalizedNumber(mLocale, user.friends_count));
    if (mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true)) {
        mProfileImageLoader.displayProfileImage(mProfileImageView,
                getOriginalTwitterProfileImage(user.profile_image_url));
        final int def_width = res.getDisplayMetrics().widthPixels;
        final int width = mBannerWidth > 0 ? mBannerWidth : def_width;
        mProfileBannerView.setImageBitmap(null);
        mProfileImageLoader.displayProfileBanner(mProfileBannerView, user.profile_banner_url, width);
    } else {
        mProfileImageView.setImageResource(R.drawable.ic_profile_image_default);
        mProfileBannerView.setImageResource(android.R.color.transparent);
    }
    if (isMyAccount(getActivity(), user.id)) {
        final ContentResolver resolver = getContentResolver();
        final ContentValues values = new ContentValues();
        values.put(Accounts.NAME, user.name);
        values.put(Accounts.SCREEN_NAME, user.screen_name);
        values.put(Accounts.PROFILE_IMAGE_URL, user.profile_image_url);
        values.put(Accounts.PROFILE_BANNER_URL, user.profile_banner_url);
        final String where = Accounts.ACCOUNT_ID + " = " + user.id;
        resolver.update(Accounts.CONTENT_URI, values, where, null);
    }
    mAdapter.add(new FavoritesAction(1));
    mAdapter.add(new UserMentionsAction(2));
    mAdapter.add(new UserListsAction(3));
    mAdapter.add(new UserListMembershipsAction(4));
    if (userIsMe) {
        mAdapter.add(new SavedSearchesAction(11));
        if (user.is_protected) {
            mAdapter.add(new IncomingFriendshipsAction(12));
        }
        mAdapter.add(new UserBlocksAction(13));
        mAdapter.add(new MutesUsersAction(14));
    }
    mAdapter.notifyDataSetChanged();
    if (!user.is_cache) {
        getFriendship();
    }
    invalidateOptionsMenu();
    setMenu(mMenuBar.getMenu());
    mMenuBar.show();
}

From source file:com.tct.mail.NotificationActionIntentService.java

/**
 * Give the chance to restore the mail's status,here we restore to queue status
 * @param context// ww w . j a  v  a  2 s . c  o m
 * @param boxId is the outbox's id
 */
private void cleanFaildMailStatus(Context context, long boxId) {
    Cursor cursor = null;
    ContentResolver resolver = context.getContentResolver();
    ArrayList<Long> pendingSendMails = new ArrayList<Long>();
    ContentValues value = new ContentValues();
    //query the failed mails
    try {
        cursor = resolver.query(EmailContent.Message.CONTENT_URI,
                EmailContent.Message.ID_COLUMN_WITH_STATUS_PROJECTION,
                MessageColumns.SENDING_STATUS + "=?" + " AND " + MessageColumns.MAILBOX_KEY + "=?",
                new String[] { Long.toString(EmailContent.Message.MAIL_IN_FAILED_STATUS),
                        Long.toString(boxId) },
                null);
        while (cursor.moveToNext()) {
            pendingSendMails.add(cursor.getLong(0));
        }
    } catch (Exception e) {
        LogUtils.e(LogUtils.TAG, e, "Exception happen during queue the failed mails in cleanFaildMailStatus ");
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    //update the mails status
    if (pendingSendMails.size() > 0) {
        for (long id : pendingSendMails) {
            value.clear();
            Uri uri = ContentUris.withAppendedId(EmailContent.Message.CONTENT_URI, id);
            value.put(MessageColumns.SENDING_STATUS, EmailContent.Message.MAIL_IN_QUEUE_STATUS);
            resolver.update(uri, value, null, null);
            LogUtils.d(LogUtils.TAG, "update the mail's status from FAIL to QUEUE,current message id is %d",
                    id);
        }
    }
    pendingSendMails.clear();
}

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

private void moveItem(boolean up) {
    int curcount = mTrackCursor.getCount();
    int curpos = mTrackList.getSelectedItemPosition();
    if ((up && curpos < 1) || (!up && curpos >= curcount - 1)) {
        return;/*from  ww  w  . ja v a 2  s.c  o  m*/
    }

    if (mTrackCursor instanceof NowPlayingCursor) {
        NowPlayingCursor c = (NowPlayingCursor) mTrackCursor;
        c.moveItem(curpos, up ? curpos - 1 : curpos + 1);
        ((TrackListAdapter) mTrackList.getAdapter()).notifyDataSetChanged();
        mTrackList.invalidateViews();
        mDeletedOneRow = true;
        if (up) {
            mTrackList.setSelection(curpos - 1);
        } else {
            mTrackList.setSelection(curpos + 1);
        }
    } else {
        int colidx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.PLAY_ORDER);
        mTrackCursor.moveToPosition(curpos);
        int currentplayidx = mTrackCursor.getInt(colidx);
        Uri baseUri = MediaStore.Audio.Playlists.Members.getContentUri("external", Long.valueOf(mPlaylist));
        ContentValues values = new ContentValues();
        String where = MediaStore.Audio.Playlists.Members._ID + "=?";
        String[] wherearg = new String[1];
        ContentResolver res = getActivity().getContentResolver();
        if (up) {
            values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, currentplayidx - 1);
            wherearg[0] = mTrackCursor.getString(0);
            res.update(baseUri, values, where, wherearg);
            mTrackCursor.moveToPrevious();
        } else {
            values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, currentplayidx + 1);
            wherearg[0] = mTrackCursor.getString(0);
            res.update(baseUri, values, where, wherearg);
            mTrackCursor.moveToNext();
        }
        values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, currentplayidx);
        wherearg[0] = mTrackCursor.getString(0);
        res.update(baseUri, values, where, wherearg);
    }
}

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

@MediumTest
public void testCrashReport() throws Exception {
    long start = System.currentTimeMillis();
    ContentResolver r = getContext().getContentResolver();

    // Log a test (fake) crash report.
    Checkin.reportCrash(r, new CrashData("Test", "Test Activity", new BuildData("Test Build", "123", start),
            new ThrowableData(new RuntimeException("Test Exception"))));

    // Crashes aren't indexed; go through them all to find the one we added.
    Cursor c = r.query(Checkin.Crashes.CONTENT_URI, null, null, null, null);

    Uri uri = null;/*from ww  w  .  j av  a2s . com*/
    while (c.moveToNext()) {
        String coded = c.getString(c.getColumnIndex(Checkin.Crashes.DATA));
        byte[] bytes = Base64.decodeBase64(coded.getBytes());
        CrashData crash = new CrashData(new DataInputStream(new ByteArrayInputStream(bytes)));

        // Should be exactly one recently added "Test" crash.
        if (crash.getId().equals("Test") && crash.getTime() > start) {
            assertEquals("Test Activity", crash.getActivity());
            assertEquals("Test Build", crash.getBuildData().getFingerprint());
            assertEquals("Test Exception", crash.getThrowableData().getMessage());

            assertNull(uri);
            uri = ContentUris.withAppendedId(Checkin.Crashes.CONTENT_URI,
                    c.getInt(c.getColumnIndex(Checkin.Crashes._ID)));
        }
    }
    assertNotNull(uri);
    c.close();

    // Update the "logs" column.
    ContentValues values = new ContentValues();
    values.put(Checkin.Crashes.LOGS, "Test Logs");
    assertEquals(1, r.update(uri, values, null, null));

    c = r.query(uri, null, null, null, null);
    assertTrue(c.moveToNext());
    String logs = c.getString(c.getColumnIndex(Checkin.Crashes.LOGS));
    assertEquals("Test Logs", logs);
    c.deleteRow();
    c.close();

    c.requery();
    assertFalse(c.moveToNext());
    c.close();
}

From source file:org.jsharkey.sky.WebserviceHelper.java

/**
 * Perform a webservice query to retrieve and store the forecast for the
 * given widget. This call blocks until request is finished and
 * {@link Forecasts#CONTENT_URI} has been updated.
 *//*from w  w  w  . j a v a 2  s.  co  m*/
public static void updateForecasts(Context context, Uri appWidgetUri, int days) throws ForecastParseException {

    Uri appWidgetForecasts = Uri.withAppendedPath(appWidgetUri, AppWidgets.TWIG_FORECASTS);

    ContentResolver resolver = context.getContentResolver();

    Cursor cursor = null;
    double lat = Double.NaN;
    double lon = Double.NaN;

    // Pull exact forecast location from database
    try {
        cursor = resolver.query(appWidgetUri, PROJECTION_APPWIDGET, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            lat = cursor.getDouble(COL_LAT);
            lon = cursor.getDouble(COL_LON);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    // Query webservice for this location
    List<Forecast> forecasts = queryLocation(lat, lon, days);

    if (forecasts == null || forecasts.size() == 0) {
        throw new ForecastParseException("No forecasts found from webservice query");
    }

    // Purge existing forecasts covered by incoming data, and anything
    // before today
    long lastMidnight = ForecastUtils.getLastMidnight();
    long earliest = Long.MAX_VALUE;
    for (Forecast forecast : forecasts) {
        earliest = Math.min(earliest, forecast.validStart);
    }

    resolver.delete(appWidgetForecasts, ForecastsColumns.VALID_START + " >= " + earliest + " OR "
            + ForecastsColumns.VALID_START + " <= " + lastMidnight, null);

    // Insert any new forecasts found
    ContentValues values = new ContentValues();
    for (Forecast forecast : forecasts) {
        Log.d(TAG, "inserting forecast with validStart=" + forecast.validStart);
        values.clear();
        values.put(ForecastsColumns.VALID_START, forecast.validStart);
        values.put(ForecastsColumns.TEMP_HIGH, forecast.tempHigh);
        values.put(ForecastsColumns.TEMP_LOW, forecast.tempLow);
        values.put(ForecastsColumns.CONDITIONS, forecast.conditions);
        values.put(ForecastsColumns.URL, forecast.url);
        if (forecast.alert) {
            values.put(ForecastsColumns.ALERT, ForecastsColumns.ALERT_TRUE);
        }
        resolver.insert(appWidgetForecasts, values);
    }

    // Mark widget cache as being updated
    values.clear();
    values.put(AppWidgetsColumns.LAST_UPDATED, System.currentTimeMillis());
    resolver.update(appWidgetUri, values, null, null);
}

From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java

@Override
protected void onDestroy() {
    if (getIntent().getAction().equals(Intent.ACTION_EDIT)) {
        String url = mUrlEditText.getText().toString();
        ContentResolver cr = getContentResolver();

        Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID,
                FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null);

        if (cursor.moveToFirst() && !getIntent().getData().getLastPathSegment().equals(cursor.getString(0))) {
            cursor.close();/*from w  w w .  j ava 2s. c  om*/
            Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Toast.LENGTH_LONG).show();
        } else {
            cursor.close();
            ContentValues values = new ContentValues();

            if (!url.startsWith(Constants.HTTP) && !url.startsWith(Constants.HTTPS)) {
                url = Constants.HTTP + url;
            }
            values.put(FeedColumns.URL, url);

            String name = mNameEditText.getText().toString();

            values.put(FeedColumns.NAME, name.trim().length() > 0 ? name : null);
            values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null);
            values.put(FeedColumns.FETCH_MODE, 0);
            values.putNull(FeedColumns.ERROR);

            cr.update(getIntent().getData(), values, null, null);
            if (!name.equals(mPreviousName)) {
                cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);
                cr.notifyChange(FeedColumns.GROUPED_FEEDS_CONTENT_URI, null);
            }
        }
    }

    super.onDestroy();
}

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    final ContentResolver resolver = getContentResolver();
    ContentValues values;//from www . j  a v a2  s  .com
    switch (requestCode) {
    case REQUEST_SELECT_ACCOUNT: {
        if (resultCode == RESULT_OK) {
            if (intent == null || intent.getExtras() == null) {
                break;
            }
            final Bundle bundle = intent.getExtras();
            if (bundle == null) {
                break;
            }
            final long[] account_ids = bundle.getLongArray(INTENT_KEY_IDS);
            if (account_ids != null) {
                values = new ContentValues();
                values.put(Accounts.IS_ACTIVATED, 0);
                resolver.update(Accounts.CONTENT_URI, values, null, null);
                values = new ContentValues();
                values.put(Accounts.IS_ACTIVATED, 1);
                for (final long account_id : account_ids) {
                    final String where = Accounts.USER_ID + " = " + account_id;
                    resolver.update(Accounts.CONTENT_URI, values, where, null);
                }
            }
            checkDefaultAccountSet();
        } else if (resultCode == RESULT_CANCELED) {
            if (getActivatedAccountIds(this).length <= 0) {
                finish();
            } else {
                checkDefaultAccountSet();
            }
        }
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}