Example usage for android.content ContentValues remove

List of usage examples for android.content ContentValues remove

Introduction

In this page you can find the example usage for android.content ContentValues remove.

Prototype

public void remove(String key) 

Source Link

Document

Remove a single value.

Usage

From source file:com.jimandreas.popularmovies.MovieDetailFragment.java

@Nullable
@Override/*w  w  w . j  av a 2  s.c  om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    if (arguments != null) {
        mUri = arguments.getParcelable(MovieDetailFragment.DETAIL_URI);
    }

    View rootView = inflater.inflate(R.layout.fragment_detail, container, false);

    /*
     * Yes yes my master, we have the Precious handle to the Layout!!
     *
     * NOTE: now obsolete - moved to the Constraint system for layout
     */
    //        mTheMasterGridLayout = (GridLayout) rootView.findViewById(R.id.movie_detail_grid_layout);
    //        mTheMasterGridLayout = (ConstraintLayout)
    //                rootView.findViewById(R.id.movie_detail_grid_layout);

    mMDSynopsis = (TextView) rootView.findViewById(R.id.movie_detail_synopsis);
    mMDTitleView = (TextView) rootView.findViewById(R.id.movie_detail_title);
    mMDPosterView = (ImageView) rootView.findViewById(R.id.movie_detail_poster_image);
    mMDYear = (TextView) rootView.findViewById(R.id.movie_detail_year);
    mMDRunningtime = (TextView) rootView.findViewById(R.id.movie_detail_runningtime);
    mMDRatingAndVotes = (TextView) rootView.findViewById(R.id.movie_detail_rating_and_votes);
    mMDSynopsis = (TextView) rootView.findViewById(R.id.movie_detail_synopsis);

    mMDLoadProgress = (ProgressBar) rootView.findViewById(R.id.movie_detail_progress_circle);

    // cache up all the Trailer and Review UX views - 
    //   these will get toggled into visibility based on their 
    // rather random presence in TheMovieDB...

    mMDTrailers = (TextView) rootView.findViewById(R.id.movie_detail_trailers);
    mMDPlay1 = (ImageView) rootView.findViewById(R.id.movie_detail_trailer_play_button);
    mMDPlay2 = (ImageView) rootView.findViewById(R.id.movie_detail_trailer_play_button2);
    mMDPlay3 = (ImageView) rootView.findViewById(R.id.movie_detail_trailer_play_button3);
    mMDTrailer1 = (TextView) rootView.findViewById(R.id.movie_detail_trailer1);
    mMDTrailer2 = (TextView) rootView.findViewById(R.id.movie_detail_trailer2);
    mMDTrailer3 = (TextView) rootView.findViewById(R.id.movie_detail_trailer3);
    mMDTrailer1.setOnClickListener(mTrailerClickListener);
    mMDTrailer2.setOnClickListener(mTrailerClickListener);
    mMDTrailer3.setOnClickListener(mTrailerClickListener);

    mMDReviews = (TextView) rootView.findViewById(R.id.movie_detail_reviews);
    mMDRev1 = (ImageView) rootView.findViewById(R.id.play_rev1);
    mMDRev2 = (ImageView) rootView.findViewById(R.id.play_rev2);
    mMDRev3 = (ImageView) rootView.findViewById(R.id.play_rev3);

    mMovieReview1 = (TextView) rootView.findViewById(R.id.movie_review1);
    mMovieReview2 = (TextView) rootView.findViewById(R.id.movie_review2);
    mMovieReview3 = (TextView) rootView.findViewById(R.id.movie_review3);
    mMovieReview1.setOnClickListener(mReviewClickListener);
    mMovieReview2.setOnClickListener(mReviewClickListener);
    mMovieReview3.setOnClickListener(mReviewClickListener);

    mMDFavoriteButton = (ImageView) rootView.findViewById(R.id.movie_detail_favorite_imageviewbutton);
    mMDFavoriteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int favorite_state;

            //                Snackbar.make(v, "clicky", Snackbar.LENGTH_SHORT)
            //                        .setAction("Action", null).show();

            if (mCursor == null || !mCursor.moveToFirst()) {
                return;
            }

            // pull the favorite table entry if it exists
            int movie_id = mCursor.getInt(COL_MOVIE_ID);
            Uri uri = MovieFavorites.buildMovieDetailsUri(movie_id);
            Cursor fav_cursor = getContext().getContentResolver().query(uri, null, null, null, null);

            // debugging
            ContentValues testValues = new ContentValues();
            if (fav_cursor.moveToFirst()) {
                DatabaseUtils.cursorRowToContentValues(fav_cursor, testValues);
            }

            // dump in the current movie table entry into the new
            // favorite row info
            ContentValues favoriteValues = new ContentValues();
            DatabaseUtils.cursorRowToContentValues(mCursor, favoriteValues);

            // OK if the favorite row already exists, then toggle its state
            // otherwise set it to "1" or true - it IS a favorite now
            int fav_status = 0;
            if (fav_cursor.moveToFirst()) {
                fav_status = fav_cursor.getInt(COL_FAVORITE);
            }
            favoriteValues.put(MovieFavorites.COLUMN_MYNAME, "favorites");

            if (fav_status == 0) {
                favorite_state = 1;
                favoriteValues.remove(MovieFavorites.COLUMN_FAVORITE);
                favoriteValues.put(MovieFavorites.COLUMN_FAVORITE, 1);
                favoriteValues.put(MovieFavorites.COLUMN_FAVORITE_TIMESTAMP, mCalendar.getTimeInMillis());
                Timber.i("favorites - added " + movie_id + " to favorites");
            } else {
                favorite_state = 0;
                favoriteValues.remove(MovieFavorites.COLUMN_FAVORITE);
                favoriteValues.put(MovieFavorites.COLUMN_FAVORITE, 0);
                Timber.i("favorites - removed " + movie_id + " from favorites");
            }

            /*
             * stuff this favorite row into the favorites table
             * but first remove the _id key or sqlite will crash
             */
            favoriteValues.remove("_id");

            Uri updated = getContext().getContentResolver().insert(MovieFavorites.CONTENT_URI, favoriteValues);

            ContentValues movieValues = new ContentValues();

            if (favorite_state == 1) {
                mMDFavoriteButton.setImageResource(R.drawable.ic_favorite_selected);
                movieValues.put(MoviePopular.COLUMN_FAVORITE, 1);
                mTM.addFavoriteID(movie_id);
            } else {
                mMDFavoriteButton.setImageResource(R.drawable.ic_favorite_unselected);
                movieValues.put(MoviePopular.COLUMN_FAVORITE, 0);
                mTM.removeFavoriteID(movie_id);
            }

            /*
             * do an update selecting on the movie_id in BOTH popular and top_rated
             * tables.   The same movie_id might be in both tables.
             */
            String myMode = MoviePopular.getMovieModeFromUri(mUri);
            int result;

            uri = MoviePopular.buildMovieDetailsUri(movie_id);
            result = getContext().getContentResolver().update(uri, movieValues,
                    MoviePopular.COLUMN_MOVIE_ID + " = " + String.valueOf(movie_id), null);

            uri = MovieTopRated.buildMovieDetailsUri(movie_id);
            result = getContext().getContentResolver().update(uri, movieValues,
                    MoviePopular.COLUMN_MOVIE_ID + " = " + String.valueOf(movie_id), null);
        }
    });

    mTM = TrafficManager.getInstance(getContext());

    return rootView;
}

From source file:org.kontalk.provider.UsersProvider.java

private Uri insertUser(ContentValues values, boolean offline, boolean discardName) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();

    String table = offline ? TABLE_USERS_OFFLINE : TABLE_USERS;
    long id = 0;/*from w w w  .j a va  2s  .  c  o  m*/

    try {
        id = db.insertOrThrow(table, null, values);
    } catch (SQLException e) {
        String jid = values.getAsString(Users.JID);
        if (jid != null) {
            // discard display_name if requested
            if (discardName) {
                values.remove(Users.DISPLAY_NAME);
                values.remove(Users.NUMBER);
            }

            db.update(table, values, Users.JID + "=?", new String[] { jid });
        }
    }

    if (id >= 0)
        return ContentUris.withAppendedId(Users.CONTENT_URI, id);
    return null;
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private int updateSource(@NonNull final Uri uri, final ContentValues values, final String selection,
        final String[] selectionArgs) {
    Context context = getContext();
    if (context == null) {
        return 0;
    }//from  w w  w  . j  av  a2s  .  c om

    // Only Muzei can set the IS_SELECTED field
    if (values.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) {
        if (!context.getPackageName().equals(getCallingPackage())) {
            Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED
                    + " column. Ignoring the value in " + values);
            values.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED);
        }
    }

    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    String finalWhere = selection;
    String[] finalSelectionArgs = selectionArgs;
    if (MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) {
        // If the incoming URI matches a single source ID, does the update based on the incoming data, but
        // modifies the where clause to restrict it to the particular source ID.
        finalWhere = DatabaseUtils.concatenateWhere(finalWhere,
                BaseColumns._ID + " = " + uri.getLastPathSegment());
    }
    String callingPackageName = getCallingPackage();
    if (!context.getPackageName().equals(callingPackageName)) {
        // Only allow other apps to update their own source
        finalWhere = DatabaseUtils.concatenateWhere(finalWhere,
                MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + " LIKE ?");
        finalSelectionArgs = DatabaseUtils.appendSelectionArgs(finalSelectionArgs,
                new String[] { callingPackageName + "/%" });
    }
    int count = db.update(MuzeiContract.Sources.TABLE_NAME, values, finalWhere, finalSelectionArgs);
    if (count > 0) {
        notifyChange(uri);
    } else if (values.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)) {
        insertSource(MuzeiContract.Sources.CONTENT_URI, values);
        count = 1;
    }
    return count;
}

From source file:ru.orangesoftware.financisto2.db.DatabaseAdapter.java

private void saveRateInTransaction(SQLiteDatabase db, ExchangeRate r) {
    ContentValues values = r.toValues();
    values.remove("updated_on");
    values.put(CategoryColumns.updated_on.name(), System.currentTimeMillis());
    db.insert(EXCHANGE_RATES_TABLE, null, values);
}

From source file:com.openerp.orm.ORM.java

/**
 * Write.//from   w w  w  . j  a v  a2  s.  c o  m
 * 
 * @param dbHelper
 *            the db helper
 * @param values
 *            the values
 * @param id
 *            the id
 * @param fromServer
 *            the from server
 * @return true, if successful
 */
public boolean write(BaseDBHelper dbHelper, ContentValues values, int id, boolean fromServer) {

    // Handling many2one records
    HashMap<String, Object> many2onecols = dbHelper.getMany2OneColumns();
    // Handling Many2Many Records
    HashMap<String, Object> many2manycols = dbHelper.getMany2ManyColumns();
    for (String key : many2manycols.keySet()) {
        try {

            JSONArray m2mArray = new JSONArray(values.getAsString(key));
            Many2Many m2m = (Many2Many) many2manycols.get(key);
            updateM2MRecords(values.getAsString("id"), m2mArray, key, dbHelper, m2m, values);
        } catch (Exception e) {

        }
        values.remove(key);
    }
    // Handling many2one records. [id, "name"] to id
    for (String key : many2onecols.keySet()) {
        try {
            String tempVals = values.getAsString(key);
            if (!tempVals.equals("false")) {
                JSONArray m2oArray = new JSONArray(values.getAsString(key));
                int m2oid = m2oArray.getInt(0);
                values.put(key, m2oid);
            } else {
                values.put(key, "false");
            }
        } catch (Exception e) {
        }
    }

    boolean flag = false;
    SQLiteDatabase db = getWritableDatabase();
    try {
        if (OpenERPServerConnection.isNetworkAvailable(context)) {
            String table = modelToTable(dbHelper.getModelName());
            try {

                JSONObject arguments = new JSONObject();
                for (String key : values.keySet()) {
                    try {
                        int keyid = Integer.parseInt(values.getAsString(key));
                        arguments.put(key, keyid);
                    } catch (Exception e) {
                        String temp = values.getAsString(key);
                        if (temp.equals("true") || temp.equals("false")) {
                            arguments.put(key, ((temp.equals("true")) ? true : false));
                        } else {

                            arguments.put(key, values.get(key).toString());

                        }
                    }

                }
                if (fromServer) {
                    int res = db.update(table, values, "id = " + id, null);
                    flag = true;
                } else {

                    if (oe_obj.updateValues(dbHelper.getModelName(), arguments, id)) {
                        int res = db.update(table, values, "id = " + id, null);
                        flag = true;
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
                flag = false;
            }

        } else {
            Toast.makeText(context, "Unable to Connect server ! Please Try again Later. ", Toast.LENGTH_LONG)
                    .show();
            flag = false;
        }
    } catch (Exception e) {
    }
    db.close();
    return flag;
}

From source file:com.openerp.orm.ORM.java

/**
 * Creates the.//from  w  w w .  ja  v a2  s  .  c o m
 * 
 * @param dbHelper
 *            the db helper
 * @param values
 *            the values
 * @return the int
 */
public int create(BaseDBHelper dbHelper, ContentValues data_values) {
    int newId = 0;
    ContentValues values = new ContentValues();
    if (data_values.containsKey("id")) {
        newId = data_values.getAsInteger("id");
    } else {
        newId = createRecordOnserver(dbHelper, data_values);
        data_values.put("id", newId);
    }

    for (Fields field : dbHelper.getColumns()) {
        values.put(field.getName(), data_values.getAsString(field.getName()));
    }

    values.put("oea_name", OpenERPAccountManager.currentUser(context).getAndroidName());

    // Handling Many2Many Records
    HashMap<String, Object> many2manycols = dbHelper.getMany2ManyColumns();
    for (String key : many2manycols.keySet()) {
        try {
            JSONArray m2mArray = new JSONArray(values.getAsString(key));
            Many2Many m2m = (Many2Many) many2manycols.get(key);
            createM2MRecords(values.getAsString("id"), m2mArray, key, dbHelper, m2m, values);
        } catch (Exception e) {
        }
        values.remove(key);
    }

    // Handling Many2One Record
    HashMap<String, Object> many2onecols = dbHelper.getMany2OneColumns();
    for (String key : many2onecols.keySet()) {
        try {
            if (!values.getAsString(key).equals("false")) {
                JSONArray m2oArray = new JSONArray(values.getAsString(key));
                values.put(key, many2oneRecord(m2oArray));
                List<Integer> list = new ArrayList<Integer>();
                int m2o_id = Integer.parseInt(many2oneRecord(m2oArray));
                list.add(m2o_id);
                BaseDBHelper m2oDb = ((Many2One) many2onecols.get(key)).getM2OObject();
                if (!m2oDb.hasRecord(m2oDb, m2o_id)) {
                    oe_obj.syncReferenceTables(m2oDb, list, false);
                }
            }
        } catch (Exception e) {
        }

    }

    SQLiteDatabase db = getWritableDatabase();
    db.insert(modelToTable(dbHelper.getModelName()), null, values);
    db.close();
    return newId;
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_star:
        toggleStar(item);//from w  w  w  .j a v  a 2  s.com
        return true;
    case R.id.menu_edit:
        if (DirectoryContactUtil.isDirectoryContact(mContactData)) {
            // This action is used to launch the contact selector, with the option of
            // creating a new contact. Creating a new contact is an INSERT, while selecting
            // an exisiting one is an edit. The fields in the edit screen will be
            // prepopulated with data.

            final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
            intent.setType(Contacts.CONTENT_ITEM_TYPE);

            ArrayList<ContentValues> values = mContactData.getContentValues();

            // Only pre-fill the name field if the provided display name is an nickname
            // or better (e.g. structured name, nickname)
            if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) {
                intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName());
            } else if (mContactData.getDisplayNameSource() == DisplayNameSources.ORGANIZATION) {
                // This is probably an organization. Instead of copying the organization
                // name into a name entry, copy it into the organization entry. This
                // way we will still consider the contact an organization.
                final ContentValues organization = new ContentValues();
                organization.put(Organization.COMPANY, mContactData.getDisplayName());
                organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
                values.add(organization);
            }

            // Last time used and times used are aggregated values from the usage stat
            // table. They need to be removed from data values so the SQL table can insert
            // properly
            for (ContentValues value : values) {
                value.remove(Data.LAST_TIME_USED);
                value.remove(Data.TIMES_USED);
            }
            intent.putExtra(Intents.Insert.DATA, values);

            // If the contact can only export to the same account, add it to the intent.
            // Otherwise the ContactEditorFragment will show a dialog for selecting an
            // account.
            if (mContactData.getDirectoryExportSupport() == Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) {
                intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, new Account(
                        mContactData.getDirectoryAccountName(), mContactData.getDirectoryAccountType()));
                intent.putExtra(Intents.Insert.EXTRA_DATA_SET,
                        mContactData.getRawContacts().get(0).getDataSet());
            }

            // Add this flag to disable the delete menu option on directory contact joins
            // with local contacts. The delete option is ambiguous when joining contacts.
            intent.putExtra(ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, true);

            startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY);
        } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) {
            InvisibleContactUtil.addToDefaultGroup(mContactData, this);
        } else if (isContactEditable()) {
            editContact();
        }
        return true;
    case R.id.menu_delete:
        if (isContactEditable()) {
            deleteContact();
        }
        return true;
    case R.id.menu_share:
        if (isContactShareable()) {
            shareContact();
        }
        return true;
    case R.id.menu_create_contact_shortcut:
        if (isShortcutCreatable()) {
            createLauncherShortcutWithContact();
        }
        return true;
    case R.id.menu_help:
        HelpUtils.launchHelpAndFeedbackForContactScreen(this);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) {
    Context context = getContext();
    if (context == null) {
        return null;
    }/*from   www  .  jav a  2 s  .c o m*/
    if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)
            || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) {
        throw new IllegalArgumentException("Initial values must contain component name " + initialValues);
    }
    ComponentName componentName = ComponentName
            .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME));
    if (componentName == null) {
        throw new IllegalArgumentException("Invalid component name: "
                + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME));
    }
    ApplicationInfo info;
    try {
        // Ensure the service is valid and extract the application info
        info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo;
    } catch (PackageManager.NameNotFoundException e) {
        throw new IllegalArgumentException("Invalid component name "
                + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e);
    }
    // Make sure they are using the short string format
    initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString());

    // Only Muzei can set the IS_SELECTED field
    if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) {
        if (!context.getPackageName().equals(getCallingPackage())) {
            Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED
                    + " column. Ignoring the value in " + initialValues);
            initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED);
        }
    }

    // Disable network access callbacks if we're running on an API 24 device and the source app
    // targets API 24. This is to be consistent with the Behavior Changes in Android N
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)
            && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) {
        if (info.targetSdkVersion >= Build.VERSION_CODES.N) {
            Log.w(TAG,
                    "Sources targeting API 24 cannot receive network access callbacks. Changing "
                            + componentName + " to false for "
                            + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE);
            initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false);
        }
    }
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME,
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues);
    // If the insert succeeded, the row ID exists.
    if (rowId > 0) {
        // Creates a URI with the source ID pattern and the new row ID appended to it.
        final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId);
        notifyChange(sourceUri);
        return sourceUri;
    }
    // If the insert didn't succeed, then the rowID is <= 0
    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java

private ContentValues parseObject(JsonParser parser, SQLiteDatabase tempDb, String parentId, int seq)
        throws JsonParseException, IOException {
    // TODO : Grab id of root topic here, and store it in shared prefs, in case it ever
    //        changes. Currently we assume "root" and a change would be catastrophic.
    ContentValues result = new ContentValues();
    ChildArrayResults childResults = null;
    boolean badKind = false;

    result.put("parentTopic_id", parentId);
    result.put("seq", seq);

    while (parser.nextValue() != JsonToken.END_OBJECT) {

        // Allows us to burn through the rest of the object once we discover it's an exercise or something else we don't care about.
        if (badKind)
            continue;

        String fieldName = parser.getCurrentName();

        // Keys present will determine object type.
        if (stringFields.contains(fieldName)) {
            // Use getValueAsString over getText; getText returns "null" while getValueAsString returns null.
            String value = parser.getValueAsString();
            result.put(fieldName, value);

            if ("id".equals(fieldName)) {
                if (childResults != null) {
                    addParentIdToChildren(tempDb, childResults, value);
                }/*from  w  ww.j  a va 2s .com*/
            }
        } else if (intFields.contains(fieldName)) {
            result.put(fieldName, parser.getIntValue());
        } else if (booleanFields.contains(fieldName)) {
            result.put(fieldName, parser.getBooleanValue());
        } else if ("children".equals(fieldName)) {
            childResults = parseChildArray(parser, tempDb,
                    result.containsKey("id") ? result.getAsString("id") : null);
            result.put("video_count", childResults.videoCount);
            result.put("child_kind", childResults.childKind);
            result.put("thumb_id", childResults.thumbId);
        } else if ("download_urls".equals(fieldName)) {
            parseDownloadUrls(parser, result);
        } else if (null == fieldName) {
            // Noop. Just in case.
        } else {
            JsonToken next = parser.getCurrentToken();
            if (next == JsonToken.START_OBJECT || next == JsonToken.START_ARRAY) {
                // Skip this object or array, leaving us pointing at the matching end_object / end_array token.
                parser.skipChildren();
            }
        }
    }

    // Ignore types we don't need.
    if (badKind) {
        return null;
    }

    // Having parsed this whole object, we can insert it.
    if (result.containsKey("kind")) {
        String kind = result.getAsString("kind");
        if ("Topic".equals(kind)) {
            if (result.containsKey("id")) {
                result.put("_id", result.getAsString("id"));
                result.remove("id");
            }
            if (result.containsKey("child_kind")) {
                String child_kind = result.getAsString("child_kind");
                if ("Topic".equals(child_kind) || "Video".equals(child_kind)) {
                    insertTopic(tempDb, result);
                }
            }
        } else if ("Video".equals(kind)) {
            if (result.containsKey("id")) {
                result.put("video_id", result.getAsString("id"));
                result.remove("id");
            }
            insertTopicVideo(tempDb, result);
            insertVideo(tempDb, result);
        }
    }

    return result;
}

From source file:com.android.mail.browse.ConversationCursor.java

/**
 * Cache a column name/value pair for a given Uri
 * @param uriString the Uri for which the column name/value pair applies
 * @param columnName the column name//from  ww  w.  j  a va 2s .  c om
 * @param value the value to be cached
 */
private void cacheValue(String uriString, String columnName, Object value) {
    // Calling this method off the UI thread will mess with ListView's reading of the cursor's
    // count
    if (offUiThread()) {
        LogUtils.e(LOG_TAG, new Error(), "cacheValue incorrectly being called from non-UI thread");
    }

    synchronized (mCacheMapLock) {
        // Get the map for our uri
        ContentValues map = mCacheMap.get(uriString);
        // Create one if necessary
        if (map == null) {
            map = new ContentValues();
            mCacheMap.put(uriString, map);
        }
        // If we're caching a deletion, add to our count
        if (columnName.equals(DELETED_COLUMN)) {
            final boolean state = (Boolean) value;
            final boolean hasValue = map.get(columnName) != null;
            if (state && !hasValue) {
                mDeletedCount++;
                if (DEBUG) {
                    LogUtils.i(LOG_TAG, "Deleted %s, incremented deleted count=%d", uriString, mDeletedCount);
                }
            } else if (!state && hasValue) {
                mDeletedCount--;
                map.remove(columnName);
                if (DEBUG) {
                    LogUtils.i(LOG_TAG, "Undeleted %s, decremented deleted count=%d", uriString, mDeletedCount);
                }
                return;
            } else if (!state) {
                // Trying to undelete, but it's not deleted; just return
                if (DEBUG) {
                    LogUtils.i(LOG_TAG, "Undeleted %s, IGNORING, deleted count=%d", uriString, mDeletedCount);
                }
                return;
            }
        }
        putInValues(map, columnName, value);
        map.put(UPDATE_TIME_COLUMN, System.currentTimeMillis());
        if (DEBUG && (!columnName.equals(DELETED_COLUMN))) {
            LogUtils.i(LOG_TAG, "Caching value for %s: %s", uriString, columnName);
        }
    }
}