Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

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

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:com.przyjaznyplan.utils.CsvConverter.java

private void CreateSlide(String[] values, String idActivity, int pos) {

    ContentValues sqlValues = new ContentValues();

    sqlValues.put(Czynnosc.STATUS, 0);/*  ww  w .ja  va2  s . c  o  m*/

    for (String value : values) {

        ifImageGetIt(value, sqlValues);
        ifAudioGetIt(value, sqlValues);
        ifTextGetIt(value, sqlValues);
    }

    SlideDto slideDto = new SlideDto();

    Slide slide = new Slide();
    slide.setPosition(pos);
    slide.setIdActivity(idActivity);
    slideDto.setContentValues(sqlValues);
    slideDto.setSlide(slide);

    slideDao.create(slideDto);

    if (slide.getId().equals("")) {
        Log.e("SQL INSERT", "INSERT WASN EXECUTED");
    }

}

From source file:info.dc585.hpt.sa.SyncAdapter.java

private void syncTopHackers(ContentProviderClient provider, SyncResult syncResult) {

    try {/*from   w  w w .  j  a v  a2  s .  c o m*/

        Log.d(TAG, "Calling something to sync up hackerpoint db");

        JSONArray hackers = NetworkUtilities.getTopHackers();
        if (hackers == null) {
            Log.e(TAG, "somehow got null hackers, explode please");
            syncResult.stats.numParseExceptions++;
        }
        if (hackers.length() == 0) {
            return;
        }

        Log.i(TAG, "Updateing content provider");
        Log.i(TAG, "hackers.length():" + hackers.length());
        for (int i = 0; i < hackers.length(); i++) {
            JSONObject jo = hackers.getJSONObject(i);
            String name = jo.getString("name");

            String selection = TopHackerTable.COLUMN_NAME + " like ?";
            String[] selectionArgs = { name };

            String[] projection = { TopHackerTable.COLUMN_ID, TopHackerTable.COLUMN_NAME };

            ContentValues values = new ContentValues();

            // FIXME:  Dear self, WTF would i trust network returned data without verifying limits ;)
            // TODO: See FIXME above.
            Cursor c = provider.query(HackerPointsContentProvider.HACKERS_URI, projection, selection,
                    selectionArgs, null);
            if (c.getCount() == 0) {
                Log.d(TAG, "performing insert for new name:" + name);

                int points = jo.getInt("points");
                values.put(TopHackerTable.COLUMN_POINTS, points);

                int pool = jo.getInt("pool");
                values.put(TopHackerTable.COLUMN_POOL, pool);

                int internets = jo.getInt("internets");
                values.put(TopHackerTable.COLUMN_INTERNETS, internets);

                String pictureURL = jo.getString("pictureURL");
                values.put(TopHackerTable.COLUMN_PICTUREURL, pictureURL);

                values.put(TopHackerTable.COLUMN_NAME, name);
                values.put(TopHackerTable.COLUMN_UPDATE, System.currentTimeMillis());
                provider.insert(HackerPointsContentProvider.HACKERS_URI, values);
                syncResult.stats.numInserts++;

            } else if (c.getCount() == 1) {
                Log.d(TAG, "performing update for name:" + name);
                if (name == null || name.isEmpty()) {
                    Log.e(TAG, "null or empty name");
                    continue;
                }

                int points = jo.getInt("points");
                values.put(TopHackerTable.COLUMN_POINTS, points);

                int pool = jo.getInt("pool");
                values.put(TopHackerTable.COLUMN_POOL, pool);

                int internets = jo.getInt("internets");
                values.put(TopHackerTable.COLUMN_INTERNETS, internets);

                String pictureURL = jo.getString("pictureURL");
                values.put(TopHackerTable.COLUMN_PICTUREURL, pictureURL);

                int rows = provider.update(HackerPointsContentProvider.HACKERS_URI, values, selection,
                        selectionArgs);

                Log.d(TAG, "Updated:" + rows + ": rows");
                syncResult.stats.numUpdates += rows;

            } else {
                Log.e(TAG, "Cursor count was not 0 or 1 was:" + c.getCount());
                continue;
            }
        }

        // Now run through both lists and figure out which one to delete.
        String[] projection = { TopHackerTable.COLUMN_NAME };
        Cursor c = provider.query(HackerPointsContentProvider.HACKERS_URI, projection, null, null, null);
        if (c.getCount() == 0) {
            return;
        }

        ArrayList<String> goodNames = new ArrayList<String>();
        ArrayList<String> rmNames = new ArrayList<String>();

        for (int i = 0; i < hackers.length(); i++) {
            JSONObject jo = hackers.getJSONObject(i);
            String name = jo.getString("name");
            goodNames.add(name);
        }

        while (c.moveToNext()) {
            int namec = c.getColumnIndex(TopHackerTable.COLUMN_NAME);
            String dbName = c.getString(namec);

            if (goodNames.contains(dbName) == false) {
                Log.d(TAG, "Adding name:" + dbName + ": to the delete list");
                rmNames.add(dbName);
            }
        }

        for (String nextName : rmNames) {
            Log.d(TAG, "deleting name:" + nextName + ":");
            // FIXME: use column name from Table class
            String where = " name = ? ";
            String[] whereArgs = { nextName };
            int rows = provider.delete(HackerPointsContentProvider.HACKERS_URI, where, whereArgs);
            syncResult.stats.numDeletes += rows;
        }

    } catch (final AuthenticationException e) {
        Log.e(TAG, "AuthenticationException", e);
    } catch (final JSONException e) {
        Log.e(TAG, "JSONException", e);
    } catch (final IOException e) {
        Log.e(TAG, "IOException", e);
    } catch (final ParseException e) {
        Log.e(TAG, "ParseException", e);
        syncResult.stats.numParseExceptions++;
    } catch (final RemoteException e) {
        Log.e(TAG, "RemoteException", e);
    }
}

From source file:com.textuality.lifesaver.Columns.java

public ContentValues jsonToContentValues(JSONObject j) {
    ContentValues cv = new ContentValues();
    for (int i = 0; i < names.length; i++) {
        switch (types[i]) {
        case STRING:
            j2cvString(j, cv, names[i]);
            break;
        case INT:
            j2cvInt(j, cv, names[i]);//  www  .j  av a2  s  . c  om
            break;
        case LONG:
            j2cvLong(j, cv, names[i]);
            break;
        case FLOAT:
            j2cvFloat(j, cv, names[i]);
            break;
        case DOUBLE:
            j2cvDouble(j, cv, names[i]);
            break;
        }
    }

    return cv;
}

From source file:com.openerp.addons.note.NoteDBHelper.java

public LinkedHashMap<String, String> writeNoteTags(String tagname) {

    LinkedHashMap<String, String> noteTags = new LinkedHashMap<String, String>();
    ContentValues values = new ContentValues();

    values.put("name", tagname);
    NoteDBHelper.NoteTags notetagObj = new NoteTags(mContext);
    int newId = notetagObj.createRecordOnserver(notetagObj, values);
    values.put("id", newId);
    notetagObj.create(notetagObj, values);
    noteTags.put("newID", String.valueOf(newId));
    noteTags.put("tagName", tagname);
    return noteTags;
}

From source file:com.android.erowser.DownloadTouchIcon.java

@Override
public void onPostExecute(Bitmap icon) {
    // Do this first in case the download failed.
    if (mActivity != null) {
        // Remove the touch icon loader from the ErowserActivity.
        mActivity.mTouchIconLoader = null;
    }//from www. jav a  2  s  .c  om

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.PNG, 100, os);
    ContentValues values = new ContentValues();
    values.put(ErowserP.BookmarkColumns.TOUCH_ICON, os.toByteArray());

    if (mCursor.moveToFirst()) {
        do {
            mContentResolver.update(ContentUris.withAppendedId(ErowserP.BOOKMARKS_URI, mCursor.getInt(0)),
                    values, null, null);
        } while (mCursor.moveToNext());
    }
    mCursor.close();
}

From source file:com.android.browser.kai.DownloadTouchIcon.java

@Override
public void onPostExecute(Bitmap icon) {
    // Do this first in case the download failed.
    if (mActivity != null) {
        // Remove the touch icon loader from the BrowserActivity.
        mActivity.mTouchIconLoader = null;
    }/*from w  w  w.ja  v a 2 s  . co m*/

    if (icon == null || mCursor == null || isCancelled()) {
        return;
    }

    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    icon.compress(Bitmap.CompressFormat.PNG, 100, os);
    ContentValues values = new ContentValues();
    values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());

    if (mCursor.moveToFirst()) {
        do {
            mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)),
                    values, null, null);
        } while (mCursor.moveToNext());
    }
    mCursor.close();
}

From source file:com.alchemiasoft.common.model.Book.java

public ContentValues toValues() {
    final ContentValues cv = new ContentValues();
    cv.put(BookDB.Book.SERVER_ID, mServerId);
    cv.put(BookDB.Book.TITLE, mTitle);
    cv.put(BookDB.Book.AUTHOR, mAuthor);
    cv.put(BookDB.Book.SOURCE, mSource);
    cv.put(BookDB.Book.DESCRIPTION, mDescription);
    cv.put(BookDB.Book.PAGES, mPages);
    cv.put(BookDB.Book.NOTES, mNotes);
    cv.put(BookDB.Book.OWNED, mOwned);
    return cv;//  w w w. j a va  2s .co m
}

From source file:net.bible.service.db.mynote.MyNoteDBAdapter.java

public MyNoteDto updateMyNote(MyNoteDto mynote) {
    // Create a new row of values to insert.
    Log.d(TAG, "about to updateMyNote: " + mynote.getVerse());
    Verse verse = mynote.getVerse();//w w w . j a va 2s .  com
    String v11nName = getVersification(verse);
    // Gets the current system time in milliseconds
    Long now = Long.valueOf(System.currentTimeMillis());

    ContentValues newValues = new ContentValues();
    newValues.put(MyNoteColumn.KEY, verse.getOsisID());
    newValues.put(MyNoteColumn.VERSIFICATION, v11nName);
    newValues.put(MyNoteColumn.MYNOTE, mynote.getNoteText());
    newValues.put(MyNoteColumn.LAST_UPDATED_ON, now);

    long rowsUpdated = db.update(Table.MYNOTE, newValues, "_id=?",
            new String[] { String.valueOf(mynote.getId()) });
    Log.d(TAG, "Rows updated:" + rowsUpdated);

    return getMyNoteDto(mynote.getId());
}

From source file:com.kku.apps.pricesearch.util.Utils.java

public static void entryFavorites(Context context, ListItem item) {
    final ContentValues cv = new ContentValues();
    cv.put(FavoritesColumns.KEYWORDS, item.getKeywords());
    cv.put(FavoritesColumns.NAME, item.getName());
    if (item.getImage() != null) {
        cv.put(FavoritesColumns.IMAGE, getByteImage(item.getImage()));
    }/*  w w  w  .j  a  v a 2s  .c  o  m*/
    cv.put(FavoritesColumns.ITEMURL, item.getItemUrl());
    cv.put(FavoritesColumns.PRICE, item.getPrice());
    cv.put(FavoritesColumns.SHOP, item.getShop());
    cv.put(FavoritesColumns.LOGO, item.getLogo());
    cv.put(FavoritesColumns.DATE, Utils.getDate());
    final AsyncQueryHandler dbHandler = new AsyncQueryHandler(context.getContentResolver()) {

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            super.onQueryComplete(token, cookie, cursor);
        }
    };
    dbHandler.startInsert(0, null, SearchContract.URI_FAVORITES, cv);
}