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.goliathonline.android.kegbot.io.RemoteKegHandler.java

private static ContentValues queryKegDetails(Uri uri, ContentResolver resolver) {
    final ContentValues values = new ContentValues();
    final Cursor cursor = resolver.query(uri, KegsQuery.PROJECTION, null, null, null);
    try {/*  w ww .j ava  2  s . c  om*/
        if (cursor.moveToFirst()) {
            values.put(SyncColumns.UPDATED, cursor.getLong(KegsQuery.UPDATED));
            values.put(Kegs.KEG_STARRED, cursor.getInt(KegsQuery.STARRED));
        } else {
            values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER);
        }
    } finally {
        cursor.close();
    }
    return values;
}

From source file:com.ichi2.libanki.Tags.java

public void flush() {
    if (mChanged) {
        JSONObject tags = new JSONObject();
        for (Map.Entry<String, Integer> t : mTags.entrySet()) {
            try {
                tags.put(t.getKey(), t.getValue());
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }//  w  w w  .ja va 2 s.c  o  m
        }
        ContentValues val = new ContentValues();
        val.put("tags", Utils.jsonToString(tags));
        // TODO: the database update call here sets mod = true. Verify if this is intended.
        mCol.getDb().update("col", val);
        mChanged = false;
    }
}

From source file:com.google.android.net.GoogleHttpClient.java

/** Execute a request without applying and rewrite rules. */
public HttpResponse executeWithoutRewriting(HttpUriRequest request, HttpContext context) throws IOException {
    String code = "Error";
    long start = SystemClock.elapsedRealtime();
    try {/*from w  w  w . ja  v  a  2s.c  o  m*/
        HttpResponse response = mClient.execute(request, context);
        code = Integer.toString(response.getStatusLine().getStatusCode());
        return response;
    } catch (IOException e) {
        code = "IOException";
        throw e;
    } finally {
        // Record some statistics to the checkin service about the outcome.
        // Note that this is only describing execute(), not body download.
        try {
            long elapsed = SystemClock.elapsedRealtime() - start;
            ContentValues values = new ContentValues();
            values.put(Checkin.Stats.TAG, Checkin.Stats.Tag.HTTP_STATUS + ":" + mUserAgent + ":" + code);
            values.put(Checkin.Stats.COUNT, 1);
            values.put(Checkin.Stats.SUM, elapsed / 1000.0);
            mResolver.insert(Checkin.Stats.CONTENT_URI, values);
        } catch (Exception e) {
            Log.e(TAG, "Error recording stats", e);
        }
    }
}

From source file:com.ultramegatech.ey.UpdateService.java

/**
 * Convert a JSONObject to a ContentValues object.
 * /*from w ww .j  a v a  2 s  .  c o  m*/
 * @param object
 * @return ContentValues containing data from the JSONObject
 * @throws JSONException 
 */
private static ContentValues parseJsonObject(JSONObject object) throws JSONException {
    final ContentValues values = new ContentValues();

    final Iterator keys = object.keys();
    while (keys.hasNext()) {
        addValue(values, object, keys.next().toString());
    }

    return values;
}

From source file:com.bellman.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.getVerseRange());
    VerseRange verserange = mynote.getVerseRange();
    String v11nName = getVersification(verserange);
    // Gets the current system time in milliseconds
    Long now = Long.valueOf(System.currentTimeMillis());

    ContentValues newValues = new ContentValues();
    newValues.put(MyNoteColumn.KEY, verserange.getOsisRef());
    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:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert new metric group into MetricInfo table, or replace if the id already exist.
 * // w  w w .j ava  2s .  c om
 * @param id             id which identifies metric group to insert
 * @param title          name of metric group
 * @param description    short description of metric
 * @param supported      metric support status on system [1-supported/0-not supported]
 * @param power          power used to monitor this metric (milliAmps)
 * @param mininterval    minimum possible interval between readings (milliseconds)
 * @param maxrange       maximum range measurable by metric, including units
 * @param resolution     resolution of measurements, including units
 * @param type           value representing metric type [system/sensor/user]
 * @return    rowid of inserted row, -1 on failure
 * 
 * @see MetricInfoTable
 */
public synchronized long insertOrReplaceMetricInfo(int id, String title, String description, int supported,
        float power, int mininterval, String maxrange, String resolution, int type) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertOrReplaceMetricInfo - insert into MetricInfo table: metric-"
                + title);
    ContentValues values = new ContentValues();
    values.put(MetricInfoTable.COLUMN_ID, id);
    values.put(MetricInfoTable.COLUMN_TITLE, title);
    values.put(MetricInfoTable.COLUMN_DESCRIPTION, description);
    values.put(MetricInfoTable.COLUMN_SUPPORTED, supported);
    values.put(MetricInfoTable.COLUMN_POWER, power);
    values.put(MetricInfoTable.COLUMN_MININTERVAL, mininterval);
    values.put(MetricInfoTable.COLUMN_MAXRANGE, maxrange);
    values.put(MetricInfoTable.COLUMN_RESOLUTION, resolution);
    values.put(MetricInfoTable.COLUMN_TYPE, type);
    //      SQLiteDatabase sqlDB = database.getWritableDatabase();
    long rowid = database.replace(MetricInfoTable.TABLE_METRICINFO, null, values);
    if (rowid >= 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.INFO_URI, String.valueOf(id));
        context.getContentResolver().notifyChange(uri, null);
        uri = Uri.withAppendedPath(CimonContentProvider.CATEGORY_URI, String.valueOf(type));
        context.getContentResolver().notifyChange(uri, null);
    }
    return rowid;
}

From source file:it.bradipao.berengar.DbTool.java

public static int json2table(SQLiteDatabase mDB, JSONObject jsonTable) {

    // vars//from  w  w  w .  j ava 2  s .co  m
    JSONArray jsonRows = new JSONArray();
    JSONArray jsonColsName = new JSONArray();
    JSONArray jsonCols = null;
    ContentValues cv = null;

    int iRes = 0;
    try {
        // init database transaction
        mDB.beginTransaction();
        // fetch table name and drop if exists
        String sTableName = jsonTable.getString("table_name");
        mDB.execSQL("DROP TABLE IF EXISTS " + sTableName);
        if (GOLOG)
            Log.d(LOGTAG, "TABLE NAME : " + sTableName);
        // fetch and execute create sql
        String sTableSql = jsonTable.getString("table_sql");
        mDB.execSQL(sTableSql);
        // fetch columns name
        jsonColsName = jsonTable.getJSONArray("cols_name");
        // fetch rows array
        jsonRows = jsonTable.getJSONArray("rows");
        // iterate through rows
        for (int i = 0; i < jsonRows.length(); i++) {
            // fetch columns
            jsonCols = jsonRows.getJSONArray(i);
            // perform insert
            cv = new ContentValues();
            for (int j = 0; j < jsonCols.length(); j++)
                cv.put(jsonColsName.getString(j), jsonCols.getString(j));
            mDB.insert(sTableName, null, cv);
            if (GOLOG)
                Log.d(LOGTAG, "INSERT IN " + sTableName + " ID=" + jsonCols.getString(0));
        }
        iRes++;
        // set transaction successful
        mDB.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(LOGTAG, "error in json2table", e);
    } finally {
        // end transaction, commit if successful else rollback
        mDB.endTransaction();
    }

    return iRes;
}

From source file:com.marvin.webvox.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;
    }/* w w w. ja v  a 2s .  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.example.android.tvleanback.data.VideoDbBuilder.java

/**
 * Takes the contents of a JSON object and populates the database
 * @param jsonObj The JSON object of videos
 * @throws JSONException if the JSON object is invalid
 *//*from   w ww .  ja  v  a2  s.co  m*/
public List<ContentValues> buildMedia(JSONObject jsonObj) throws JSONException {

    JSONArray categoryArray = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS);
    List<ContentValues> videosToInsert = new ArrayList<>();

    for (int i = 0; i < categoryArray.length(); i++) {
        JSONArray videoArray;

        JSONObject category = categoryArray.getJSONObject(i);
        String categoryName = category.getString(TAG_CATEGORY);
        videoArray = category.getJSONArray(TAG_MEDIA);

        for (int j = 0; j < videoArray.length(); j++) {
            JSONObject video = videoArray.getJSONObject(j);

            // If there are no URLs, skip this video entry.
            JSONArray urls = video.optJSONArray(TAG_SOURCES);
            if (urls == null || urls.length() == 0) {
                continue;
            }

            String title = video.optString(TAG_TITLE);
            String description = video.optString(TAG_DESCRIPTION);
            String videoUrl = (String) urls.get(0); // Get the first video only.
            String bgImageUrl = video.optString(TAG_BACKGROUND);
            String cardImageUrl = video.optString(TAG_CARD_THUMB);
            String studio = video.optString(TAG_STUDIO);

            ContentValues videoValues = new ContentValues();
            videoValues.put(VideoContract.VideoEntry.COLUMN_CATEGORY, categoryName);
            videoValues.put(VideoContract.VideoEntry.COLUMN_NAME, title);
            videoValues.put(VideoContract.VideoEntry.COLUMN_DESC, description);
            videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_URL, videoUrl);
            videoValues.put(VideoContract.VideoEntry.COLUMN_CARD_IMG, cardImageUrl);
            videoValues.put(VideoContract.VideoEntry.COLUMN_BG_IMAGE_URL, bgImageUrl);
            videoValues.put(VideoContract.VideoEntry.COLUMN_STUDIO, studio);

            // Fixed defaults.
            videoValues.put(VideoContract.VideoEntry.COLUMN_CONTENT_TYPE, "video/mp4");
            videoValues.put(VideoContract.VideoEntry.COLUMN_IS_LIVE, false);
            videoValues.put(VideoContract.VideoEntry.COLUMN_AUDIO_CHANNEL_CONFIG, "2.0");
            videoValues.put(VideoContract.VideoEntry.COLUMN_PRODUCTION_YEAR, 2014);
            videoValues.put(VideoContract.VideoEntry.COLUMN_DURATION, 0);
            videoValues.put(VideoContract.VideoEntry.COLUMN_RATING_STYLE, Rating.RATING_5_STARS);
            videoValues.put(VideoContract.VideoEntry.COLUMN_RATING_SCORE, 3.5f);
            if (mContext != null) {
                videoValues.put(VideoContract.VideoEntry.COLUMN_PURCHASE_PRICE,
                        mContext.getResources().getString(R.string.buy_2));
                videoValues.put(VideoContract.VideoEntry.COLUMN_RENTAL_PRICE,
                        mContext.getResources().getString(R.string.rent_2));
                videoValues.put(VideoContract.VideoEntry.COLUMN_ACTION,
                        mContext.getResources().getString(R.string.global_search));
            }

            // TODO: Get these dimensions.
            videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_WIDTH, 1280);
            videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_HEIGHT, 720);

            videosToInsert.add(videoValues);
        }
    }
    return videosToInsert;
}

From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java

public static void insertGroupMember(final Context c, final long groupId, final long contactId,
        final String idInGroup) {
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/group_members");
    ContentValues values = new ContentValues();
    values.put(GroupMember.GROUP_ID, groupId);
    values.put(GroupMember.CONTACT_ID, contactId);
    values.put(GroupMember.GLOBAL_CONTACT_ID, idInGroup);
    c.getContentResolver().insert(url, values);
}