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:totalcross.android.ConnectionManager4A.java

public static void setDefaultConfiguration(int type, String cfg) {
    if (cfg == null)
        cfg = "";

    switch (type) {
    case GPRS: {/*from w  w  w. j  a v a  2s  . c  o  m*/
        int id = -1;
        ContentResolver contentResolver = Launcher4A.loader.getContentResolver();
        Cursor cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
        if (cursor == null || cursor.getCount() <= 0) {
            TelephonyManager tel = (TelephonyManager) Launcher4A.loader
                    .getSystemService(Context.TELEPHONY_SERVICE);
            String networkOperator = tel.getNetworkOperator();

            if (networkOperator != null && networkOperator.length() > 0) {
                int mcc = Integer.parseInt(networkOperator.substring(0, 3));
                int mnc = Integer.parseInt(networkOperator.substring(3));
                ContentValues values = new ContentValues();
                values.put("apn", "tim.br");
                values.put("user", "tim");
                values.put("password", "tim");
                values.put("mcc", mcc);
                values.put("mnc", mnc);
                values.put("numeric", mcc + "" + mnc);
                contentResolver.insert(CONTENT_URI, values);
                cursor = contentResolver.query(CONTENT_URI, new String[] { "_id" },
                        "apn = ? and user = ? and password = ?", new String[] { "tim.br", "tim", "tim" }, null);
            }
        }
        if (cursor == null)
            return;
        if (cursor.moveToFirst())
            id = cursor.getInt(0);
        cursor.close();

        if (id > -1) {
            ContentValues values = new ContentValues();
            //See /etc/apns-conf.xml. The TelephonyProvider uses this file to provide
            //content://telephony/carriers/preferapn URI mapping
            values.put("apn_id", id);
            contentResolver.update(PREFERRED_APN_URI, values, null, null);
            cursor = contentResolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + id, null,
                    null);
            if (cursor != null)
                cursor.close();
        }
    }
        break;
    case WIFI:
        connWIFI = connWIFIPrefix + cfg;
        break;
    //default:
    //   throw new IllegalArgumentException("Invalid value for argument 'type'");
    }
}

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

@Override
public boolean onMenuItemClick(final MenuItem item) {
    final ParcelableStatus status = mSelectedStatus;
    if (status == null)
        return false;
    final long account_id = getDefaultAccountId(mApplication);
    switch (item.getItemId()) {
    case MENU_VIEW: {
        openStatus(getActivity(), status);
        break;//w ww.  j  a v a  2  s . c o  m
    }
    case MENU_SHARE: {
        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "@" + status.screen_name + ": " + status.text_plain);
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
        break;
    }
    case MENU_TRANSLATE: {
        translate(status);
        break;
    }
    case MENU_RETWEET: {
        if (isMyRetweet(status)) {
            mService.destroyStatus(status.account_id, status.status_id);
        } else {
            final long id_to_retweet = mSelectedStatus.is_retweet && mSelectedStatus.retweet_id > 0
                    ? mSelectedStatus.retweet_id
                    : mSelectedStatus.status_id;
            mService.retweetStatus(status.account_id, id_to_retweet);
        }
        break;
    }
    case MENU_QUOTE: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain));
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_QUOTE_REPLY: {
        final Intent intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        bundle.putBoolean(INTENT_KEY_IS_QUOTE, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.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, status.account_id);
        bundle.putBoolean(INTENT_KEY_IS_BUFFER, true);
        bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.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(status.text_plain);
        mentions.remove(status.screen_name);
        mentions.add(0, status.screen_name);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, status.text_plain);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_FAV: {
        if (mSelectedStatus.is_favorite) {
            mService.destroyFavorite(status.account_id, status.status_id);
        } else {
            mService.createFavorite(status.account_id, status.status_id);
        }
        break;
    }
    case MENU_CONVERSATION: {
        openConversation(getActivity(), status.account_id, status.status_id);
        break;
    }
    case MENU_DELETE: {
        mService.destroyStatus(status.account_id, status.status_id);
        break;
    }
    case MENU_EXTENSIONS: {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS);
        final Bundle extras = new Bundle();
        extras.putParcelable(INTENT_KEY_STATUS, status);
        intent.putExtras(extras);
        startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions)));
        break;
    }
    case MENU_MULTI_SELECT: {
        if (!mApplication.isMultiSelectActive()) {
            mApplication.startMultiSelect();
        }
        final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems();
        if (!list.contains(status)) {
            list.add(status);
        }
        break;
    }
    case MENU_BLOCK: {
        mService.createBlock(account_id, status.user_id);
        break;
    }
    case MENU_REPORT_SPAM: {
        mService.reportSpam(account_id, status.user_id);
        break;
    }
    case MENU_MUTE_USER: {
        final String screen_name = status.screen_name;
        final Uri uri = Filters.Users.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.Users.TEXT, screen_name);
        resolver.delete(uri, Filters.Users.TEXT + " = '" + screen_name + "'", null);
        resolver.insert(uri, values);
        editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit();
        Toast.makeText(getActivity(), R.string.user_muted, Toast.LENGTH_SHORT).show();
        break;
    }
    case MENU_MAKE_GAP: {
        Uri uri = Statuses.CONTENT_URI;
        final Uri query_uri = buildQueryUri(uri, false);
        ContentResolver mResolver = getContentResolver();
        final ContentValues values = new ContentValues();
        values.put(Statuses.IS_GAP, 1);
        final StringBuilder where = new StringBuilder();
        where.append(Statuses.ACCOUNT_ID + "=" + account_id);
        where.append(" AND " + Statuses.STATUS_ID + "=" + status.status_id);
        mResolver.update(query_uri, values, where.toString(), null);
        getActivity().sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED).putExtra(INTENT_KEY_SUCCEED, true));
        break;
    }
    case MENU_COPY: {
        final CharSequence text = Html.fromHtml(status.text_html);
        if (ClipboardUtils.setText(getActivity(), text)) {
            Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    }
    return true;
}

From source file:de.ub0r.android.websms.WebSMSReceiver.java

/**
 * Save Message to internal database./* w  ww. ja  v  a 2 s  .co  m*/
 *
 * @param context {@link android.content.Context}
 * @param specs   {@link de.ub0r.android.websms.connector.common.ConnectorSpec}
 * @param command {@link de.ub0r.android.websms.connector.common.ConnectorCommand}
 * @param msgType sent or draft?
 */
static void saveMessage(final Context context, final ConnectorSpec specs, final ConnectorCommand command,
        final int msgType) {
    if (command.getType() != ConnectorCommand.TYPE_SEND) {
        return;
    }
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(WebSMS.PREFS_DROP_SENT, false)) {
        Log.i(TAG, "drop sent messages");
        return;
    }

    // save message to android's internal sms database
    final ContentResolver cr = context.getContentResolver();
    assert cr != null;
    final ContentValues values = new ContentValues();
    values.put(TYPE, msgType);

    if (msgType == MESSAGE_TYPE_SENT) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            if (isRealSMS(specs)) {
                // drop messages from "SMS" connector. it gets saved internally.
                return;
            }

            try {
                // API19+ does not allow writing to content://sms anymore
                // anyway, give it a try, if SMSdroid is not installed
                // AppOps might let the app write the message
                if (Telephony.Sms.getDefaultSmsPackage(context).equals("de.ub0r.android.smsdroid")) {
                    sendMessageToSMSdroid(context, specs, command);
                    return;
                }
            } catch (NullPointerException e) {
                Log.w(TAG, "there is no telephony service!");
                // fall back saving the message the old fashion way. it might work..
            }
        }

        final String[] uris = command.getMsgUris();
        if (uris != null && uris.length > 0) {
            for (String s : uris) {
                final Uri u = Uri.parse(s);
                try {
                    final int updated = cr.update(u, values, null, null);
                    Log.d(TAG, "updated: " + updated);
                    if (updated > 0 && specs != null && !isRealSMS(specs)) {
                        sendMessageToCallMeter(context, specs, u);
                    }
                } catch (SQLiteException e) {
                    Log.e(TAG, "error updating sent message: " + u, e);
                    Toast.makeText(context, R.string.log_error_saving_message, Toast.LENGTH_LONG).show();
                }
            }
            return; // skip legacy saving
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        return; // skip saving drafts on API19+
    }

    final String text = command.getText();

    Log.d(TAG, "save message(s):");
    Log.d(TAG, "type: " + msgType);
    Log.d(TAG, "TEXT: " + text);
    values.put(READ, 1);
    values.put(BODY, text);
    if (command.getSendLater() > 0) {
        values.put(DATE, command.getSendLater());
        Log.d(TAG, "DATE: " + command.getSendLater());
    }
    final String[] recipients = command.getRecipients();
    final ArrayList<String> inserted = new ArrayList<String>(recipients.length);
    for (String recipient : recipients) {
        if (recipient == null || recipient.trim().length() == 0) {
            continue; // skip empty recipients

        }
        String address = Utils.getRecipientsNumber(recipient);
        Log.d(TAG, "TO: " + address);
        try {
            final Cursor c = cr.query(
                    URI_SMS, PROJECTION_ID, TYPE + " = " + MESSAGE_TYPE_DRAFT + " AND " + ADDRESS + " = '"
                            + address + "' AND " + BODY + " like '" + text.replace("'", "_") + "'",
                    null, DATE + " DESC");
            if (c != null && c.moveToFirst()) {
                final Uri u = URI_SENT.buildUpon().appendPath(c.getString(0)).build();
                assert u != null;
                Log.d(TAG, "skip saving draft: " + u);
                inserted.add(u.toString());
            } else {
                final ContentValues cv = new ContentValues(values);
                cv.put(ADDRESS, address);
                // save sms to content://sms/sent
                Uri u = cr.insert(URI_SENT, cv);
                if (u != null) {
                    inserted.add(u.toString());
                    if (msgType == MESSAGE_TYPE_SENT) {
                        // API19+ code may reach this point
                        // SMSdroid is not default app
                        // but message was saved as sent somehow
                        sendMessageToCallMeter(context, specs, u);
                    }
                }
            }
            if (c != null && !c.isClosed()) {
                c.close();
            }
        } catch (SQLiteException e) {
            Log.e(TAG, "failed saving message", e);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "failed saving message", e);
            Toast.makeText(context, R.string.log_error_saving_message, Toast.LENGTH_LONG).show();
        }
    }
    if (msgType == MESSAGE_TYPE_DRAFT && inserted.size() > 0) {
        command.setMsgUris(inserted.toArray(new String[inserted.size()]));
    }
}

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

private void parseAccountSummary(PsnAccount account) throws ParserException, IOException {
    ContentValues cv = parseSummaryData(account);
    ContentResolver cr = mContext.getContentResolver();

    long accountId = account.getId();
    boolean newRecord = true;

    long started = System.currentTimeMillis();
    Cursor c = cr.query(Profiles.CONTENT_URI, new String[] { Profiles._ID },
            Profiles.ACCOUNT_ID + "=" + accountId, null, null);

    if (c != null) {
        if (c.moveToFirst())
            newRecord = false;//from w ww .  jav  a  2 s. c  o m
        c.close();
    }

    if (newRecord) {
        cv.put(Profiles.ACCOUNT_ID, account.getId());
        cv.put(Profiles.UUID, account.getUuid());

        cr.insert(Profiles.CONTENT_URI, cv);
    } else {
        cr.update(Profiles.CONTENT_URI, cv, Profiles.ACCOUNT_ID + "=" + accountId, null);
    }

    cr.notifyChange(Profiles.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Summary update", started);

    account.refresh(Preferences.get(mContext));
    account.setOnlineId(cv.getAsString(Profiles.ONLINE_ID));
    account.setIconUrl(cv.getAsString(Profiles.ICON_URL));
    account.setLastSummaryUpdate(System.currentTimeMillis());
    account.save(Preferences.get(mContext));
}

From source file:com.ichi2.anki.tests.ContentProviderTest.java

/**
 * Test giving the answer for a reviewed card
 *//*  w w  w  .ja v a2  s. com*/
public void testAnswerCard() {
    Collection col;
    col = CollectionHelper.getInstance().getCol(getContext());
    Sched sched = col.getSched();
    long deckId = mTestDeckIds[0];
    col.getDecks().select(deckId);
    Card card = sched.getCard();

    ContentResolver cr = getContext().getContentResolver();
    Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
    ContentValues values = new ContentValues();
    long noteId = card.note().getId();
    int cardOrd = card.getOrd();
    int ease = AbstractFlashcardViewer.EASE_3; //<- insert real ease here

    values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
    values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
    values.put(FlashCardsContract.ReviewInfo.EASE, ease);
    int updateCount = cr.update(reviewInfoUri, values, null, null);

    assertEquals("Check if update returns 1", 1, updateCount);

    sched.reset();
    Card newCard = sched.getCard();
    if (newCard != null) {
        if (newCard.note().getId() == card.note().getId() && newCard.getOrd() == card.getOrd()) {
            fail("Next scheduled card has not changed");
        }
    } else {
        //We expected this
    }
}

From source file:com.ichi2.anki.tests.ContentProviderTest.java

/**
 * Check that an Exception is thrown when unsupported operations are performed
 *///from  w  ww .j  a v  a2  s  . c  o  m
public void testUnsupportedOperations() {
    final ContentResolver cr = getContext().getContentResolver();
    ContentValues dummyValues = new ContentValues();
    Uri[] updateUris = {
            // Can't update most tables in bulk -- only via ID
            FlashCardsContract.Note.CONTENT_URI, FlashCardsContract.Model.CONTENT_URI,
            FlashCardsContract.Deck.CONTENT_ALL_URI,
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").appendPath("cards").build(), };
    for (Uri uri : updateUris) {
        try {
            cr.update(uri, dummyValues, null, null);
            fail("Update on " + uri + " was supposed to throw exception");
        } catch (UnsupportedOperationException e) {
            // This was expected ...
        } catch (IllegalArgumentException e) {
            // ... or this.
        }
    }
    Uri[] deleteUris = { FlashCardsContract.Note.CONTENT_URI,
            // Only note/<id> is supported
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").appendPath("cards").build(),
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").appendPath("cards")
                    .appendPath("2345").build(),
            FlashCardsContract.Model.CONTENT_URI,
            FlashCardsContract.Model.CONTENT_URI.buildUpon().appendPath("1234").build(), };
    for (Uri uri : deleteUris) {
        try {
            cr.delete(uri, null, null);
            fail("Delete on " + uri + " was supposed to throw exception");
        } catch (UnsupportedOperationException e) {
            // This was expected
        }
    }
    Uri[] insertUris = {
            // Can't do an insert with specific ID on the following tables
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").build(),
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").appendPath("cards").build(),
            FlashCardsContract.Note.CONTENT_URI.buildUpon().appendPath("1234").appendPath("cards")
                    .appendPath("2345").build(),
            FlashCardsContract.Model.CONTENT_URI.buildUpon().appendPath("1234").build(), };
    for (Uri uri : insertUris) {
        try {
            cr.insert(uri, dummyValues);
            fail("Insert on " + uri + " was supposed to throw exception");
        } catch (UnsupportedOperationException e) {
            // This was expected ...
        } catch (IllegalArgumentException e) {
            // ... or this.
        }
    }
}

From source file:can.yrt.onebusaway.ArrivalsListFragment.java

@Override
public void setUserStopName(String name) {
    ContentResolver cr = getActivity().getContentResolver();
    ContentValues values = new ContentValues();
    if (TextUtils.isEmpty(name)) {
        values.putNull(ObaContract.Stops.USER_NAME);
        mStopUserName = null;//from   w  ww . j  a va  2  s  .c om
    } else {
        values.put(ObaContract.Stops.USER_NAME, name);
        mStopUserName = name;
    }
    cr.update(mStopUri, values, null, null);
}

From source file:com.mycompany.popularmovies.DetailActivity.DetailFragment.java

@Override
public void onClick(View v) {
    if (v.getId() == R.id.favorite) {
        Uri uri = MovieContract.MovieTable.CONTENT_URI;
        ContentResolver resolver = mActivity.getContentResolver();
        Cursor favoriteStatusCursor = resolver.query(uri,
                new String[] { MovieContract.MovieTable.COLUMN_FAVORITED },
                MovieContract.MovieTable._ID + "== ?", new String[] { Integer.toString(mMovieId) }, null);
        if (favoriteStatusCursor != null && favoriteStatusCursor.moveToFirst()) {
            Integer favoriteStatus = favoriteStatusCursor
                    .getInt(favoriteStatusCursor.getColumnIndex(MovieContract.MovieTable.COLUMN_FAVORITED));
            Integer flippedFavoriteStatus = favoriteStatus == 0 ? 1 : 0;
            ContentValues updateFavoriteStatusValues = new ContentValues();
            updateFavoriteStatusValues.put(MovieContract.MovieTable.COLUMN_FAVORITED, flippedFavoriteStatus);
            resolver.update(uri, updateFavoriteStatusValues, MovieContract.MovieTable._ID + " == ?",
                    new String[] { Integer.toString(mMovieId) });
            favoriteStatusCursor.close();
        }/*  ww w .  j  ava2  s. c o  m*/
    } else if (v.getId() == R.id.trailer_thumbnail) {
        String link = (String) v.getTag();
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
    } else if (v.getId() == R.id.review) {
        final RelativeLayout reviewItem = (RelativeLayout) v;
        final TextView author = (TextView) v.findViewById(R.id.author_full_name);
        final TextView review = (TextView) v.findViewById(R.id.review_text);

        if (reviewItem.getTag() == DetailFragment.TAG_REVIEW_COLLAPSED) {
            author.setVisibility(View.VISIBLE);
            review.setMaxLines(Integer.MAX_VALUE);
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    int excess = mReviewList.getTop() + reviewItem.getBottom()
                            - (mScrollView.getScrollY() + mScrollView.getHeight());
                    if (excess > 0) {
                        if (reviewItem.getHeight() <= mScrollView.getHeight()) {
                            mScrollView.smoothScrollBy(0, excess);
                        } else {
                            mScrollView.smoothScrollTo(0, mReviewList.getTop() + reviewItem.getTop());
                        }
                    }
                }
            });
            reviewItem.setTag(DetailFragment.TAG_REVIEW_EXPANDED);
        } else {
            author.setVisibility(View.GONE);
            review.setMaxLines(REVIEW_MAXLINES);
            reviewItem.setTag(DetailFragment.TAG_REVIEW_COLLAPSED);
        }
    }
}

From source file:org.mariotaku.twidere.activity.HomeActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    final ContentResolver resolver = getContentResolver();
    ContentValues values;/*  w  ww  .  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.ACCOUNT_ID + " = " + account_id;
                    resolver.update(Accounts.CONTENT_URI, values, where, null);
                }
            }
            setDefaultAccount();
        } else if (resultCode == RESULT_CANCELED) {
            if (getActivatedAccountIds(this).length <= 0) {
                finish();
            } else {
                setDefaultAccount();
            }
        }
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}

From source file:org.mariotaku.twidere.util.DataStoreUtils.java

@WorkerThread
public static void updateActivity(ContentResolver cr, Uri uri, String where, String[] whereArgs,
        UpdateActivityAction action) {//from  w w w.  j a  v a2s  .c o m
    final Cursor c = cr.query(uri, Activities.COLUMNS, where, whereArgs, null);
    if (c == null)
        return;
    LongSparseArray<ContentValues> values = new LongSparseArray<>();
    try {
        ParcelableActivityCursorIndices ci = new ParcelableActivityCursorIndices(c);
        c.moveToFirst();
        while (!c.isAfterLast()) {
            final ParcelableActivity activity = ci.newObject(c);
            action.process(activity);
            values.put(activity._id, ParcelableActivityValuesCreator.create(activity));
            c.moveToNext();
        }
    } finally {
        c.close();
    }
    String updateWhere = Expression.equalsArgs(Activities._ID).getSQL();
    String[] updateWhereArgs = new String[1];
    for (int i = 0, j = values.size(); i < j; i++) {
        updateWhereArgs[0] = String.valueOf(values.keyAt(i));
        cr.update(uri, values.valueAt(i), updateWhere, updateWhereArgs);
    }
}