Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

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

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

From source file:com.android.server.MaybeDatabaseHelper.java

public int setData(String packagename, String data) {
    Log.v(DBTAG, "packagename=" + packagename + " data=" + data);
    if (data == null || packagename == null)
        return 0;
    int ret;/*from  www.j  a  v a 2s.  c o  m*/
    synchronized (sAppTableLock) {
        final ContentValues c = new ContentValues();
        c.put(DATA_COL, data);
        c.put(PUSH_COL, true);
        ret = sDatabase.update(APP_TABLE_NAME, c, PACKAGE_COL + "='" + packagename + "'", null);
    }
    Log.v(DBTAG, "Database value inserted" + getAppDataFromDb(DATA_COL, packagename));
    return ret;
}

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);
    }/*w  w w  .  j  a  v  a 2  s  .c o  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:com.notifry.android.database.NotifrySource.java

@Override
protected ContentValues flatten() {
    ContentValues values = new ContentValues();
    values.put(NotifryDatabaseAdapter.KEY_ACCOUNT_NAME, this.getAccountName());
    values.put(NotifryDatabaseAdapter.KEY_SERVER_ENABLED, this.getServerEnabled() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_LOCAL_ENABLED, this.getLocalEnabled() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_TITLE, this.getTitle());
    values.put(NotifryDatabaseAdapter.KEY_SERVER_ID, this.getServerId());
    values.put(NotifryDatabaseAdapter.KEY_CHANGE_TIMESTAMP, this.getChangeTimestamp());
    values.put(NotifryDatabaseAdapter.KEY_SOURCE_KEY, this.getSourceKey());
    values.put(NotifryDatabaseAdapter.KEY_USE_GLOBAL_NOTIFICATION, this.getUseGlobalNotification() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_VIBRATE, this.getVibrate() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_RINGTONE, this.getRingtone() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_CUSTOM_RINGTONE, this.getCustomRingtone());
    values.put(NotifryDatabaseAdapter.KEY_LED_FLASH, this.getLedFlash() ? 1 : 0);
    values.put(NotifryDatabaseAdapter.KEY_SPEAK_MESSAGE, this.getSpeakMessage() ? 1 : 0);
    return values;
}

From source file:com.example.spatidar.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city/*from  w  w  w.  ja  v  a2  s .com*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    long locationId = -1;

    // Query if locationSetting entry exists in the table
    Cursor cur = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null,
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "= ?", new String[] { locationSetting },
            null);

    if (cur.moveToFirst()) {
        int idx = cur.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = cur.getLong(idx);
    } else {
        // Insert
        ContentValues values = new ContentValues();
        values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values);

        locationId = ContentUris.parseId(uri);
    }
    cur.close();

    return locationId;
}

From source file:com.cloudmine.api.db.BaseLocallySavableCMObject.java

/**
 * Used by the CMObjectDBOpenHelper to insert this object into the database
 * @return//ww w.jav a2  s . com
 */
ContentValues toContentValues() {
    ContentValues values = new ContentValues();
    values.put(CMObjectDBOpenHelper.OBJECT_ID_COLUMN, getObjectId());
    values.put(CMObjectDBOpenHelper.JSON_COLUMN, transportableRepresentation());
    values.put(CMObjectDBOpenHelper.SAVED_DATE_COLUMN, getLastLocalSavedDateAsSeconds());
    values.put(CMObjectDBOpenHelper.CLASS_NAME_COLUMN, getClassName());
    return values;
}

From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java

private void getData() {
    int sortByPreference = Utility.getSortByPreference(mContext);
    Uri contentUri = null;//from w  w w .j  a  v a  2 s  .co m

    if (sortByPreference != 4) {
        String sortType = null;
        switch (sortByPreference) {
        case 1:
            sortType = POPULARITY_DESC;
            contentUri = MovieByPopularity.CONTENT_URI;
            break;
        case 2:
            sortType = formatDate();
            contentUri = MovieByReleaseDate.CONTENT_URI;
            break;
        case 3:
            sortType = VOTE_AVG_DESC;
            contentUri = MovieByVotes.CONTENT_URI;
            break;
        }

        Cursor cursor = mContentResolver.query(contentUri, null, null, null, null);
        int page = Utility.getPagePreference(mContext);
        int count = cursor.getCount();
        if (count == 0)
            page = 1;
        Log.d(LOG_TAG, "onPerformSync: cursorCount " + count + " page: " + page);
        if (count < page * 20) {
            String jsonResponse = getJsonResponse(DISCOVER_MOVIES + SORT_BY + sortType + PAGE + page + API_KEY);

            if (jsonResponse != null) {
                JSONObject[] JsonMovies = getJsonMovies(jsonResponse);
                try {
                    Log.d(LOG_TAG, "INSERTING EXTRA DATA");
                    int i = 0;
                    for (JSONObject jsonMovie : JsonMovies) {
                        String poster = IMAGE_BASE + W_185 + jsonMovie.getString("poster_path");
                        String backdropPath = IMAGE_BASE + "/w500" + jsonMovie.getString("backdrop_path");
                        String title = jsonMovie.getString("title");
                        String releaseDate = jsonMovie.getString("release_date");
                        String vote = jsonMovie.getString("vote_average");
                        String plot = jsonMovie.getString("overview");
                        String genres = Utility.formatGenres(getGenres(jsonMovie));
                        String id = jsonMovie.getString("id");

                        ContentValues values = new ContentValues();
                        values.put(COLUMN_TITLE, title);
                        values.put(COLUMN_POSTER, poster);
                        values.put(COLUMN_RELEASE_DATE, releaseDate);
                        values.put(COLUMN_GENRES, genres);
                        values.put(COLUMN_MOVIE_ID, id);
                        values.put(COLUMN_BACKDROP_PATH, backdropPath);
                        values.put(COLUMN_AVERAGE_VOTE, vote);
                        values.put(COLUMN_PLOT, plot);

                        mContentValues[i++] = values;
                    }
                    int bulkInsert = mContentResolver.bulkInsert(contentUri, mContentValues);
                    Log.d(LOG_TAG, "onPerformSync: bulkInsert " + bulkInsert);
                    cursor.close();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:github.popeen.dsub.util.SongDBHandler.java

public void importData(JSONArray array) {
    SQLiteDatabase db = this.getReadableDatabase();
    try {/*from  w  w w .  j  a v  a2  s. c o  m*/
        for (int i = 0; i < array.length(); i++) {
            JSONObject row = array.getJSONObject(i);
            ContentValues values = new ContentValues();
            values.put(SONGS_ID, row.getInt("SONGS_ID"));
            values.put(SONGS_SERVER_KEY, row.getInt("SONGS_SERVER_KEY"));
            values.put(SONGS_SERVER_ID, row.getString("SONGS_SERVER_ID"));
            values.put(SONGS_COMPLETE_PATH, row.getString("SONGS_COMPLETE_PATH"));
            values.put(SONGS_LAST_PLAYED, row.getInt("SONGS_LAST_PLAYED"));
            values.put(SONGS_LAST_COMPLETED, row.getInt("SONGS_LAST_COMPLETED"));
            db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        }
    } catch (Exception e) {
    }
}

From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTask.java

/**
 * Returns a ContentValues hashmap suitable for database insertion in the
 * Lists table Includes modified flag and list id as specified in the
 * arguments//from w w w. j  a v  a  2  s  .c  o  m
 * 
 * @return
 */
public ContentValues toNotesContentValues(int modified, long listDbId) {
    ContentValues values = new ContentValues();
    if (title != null)
        values.put(NotePad.Notes.COLUMN_NAME_TITLE, title);
    if (dueDate != null)
        values.put(NotePad.Notes.COLUMN_NAME_DUE_DATE, dueDate);
    if (status != null)
        values.put(NotePad.Notes.COLUMN_NAME_GTASKS_STATUS, status);
    if (notes != null)
        values.put(NotePad.Notes.COLUMN_NAME_NOTE, notes);

    if (dbid > -1)
        values.put(NotePad.Notes._ID, dbid);

    values.put(NotePad.Notes.COLUMN_NAME_LIST, listDbId);
    values.put(NotePad.Notes.COLUMN_NAME_MODIFIED, modified);
    values.put(NotePad.Notes.COLUMN_NAME_DELETED, deleted);
    values.put(NotePad.Notes.COLUMN_NAME_POSITION, position);
    values.put(NotePad.Notes.COLUMN_NAME_PARENT, parent);
    //values.put(NotePad.Notes.COLUMN_NAME_HIDDEN, hidden);

    values.put(NotePad.Notes.COLUMN_NAME_POSSUBSORT, possort);
    //values.put(NotePad.Notes.COLUMN_NAME_INDENTLEVEL, indentLevel);

    return values;
}

From source file:github.popeen.dsub.util.SongDBHandler.java

protected synchronized void addSongsImpl(SQLiteDatabase db, int serverKey, List<Pair<String, String>> entries) {
    db.beginTransaction();//from   w w w. j av  a  2  s .com
    try {
        for (Pair<String, String> entry : entries) {
            ContentValues values = new ContentValues();
            values.put(SONGS_SERVER_KEY, serverKey);
            values.put(SONGS_SERVER_ID, entry.getFirst());
            values.put(SONGS_COMPLETE_PATH, entry.getSecond());

            db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        }

        db.setTransactionSuccessful();
    } catch (Exception e) {
    }

    db.endTransaction();
}

From source file:com.android.server.MaybeDatabaseHelper.java

public int updateDataInDb(String packagename, String column, String columndata) {
    Log.v(DBTAG, "Packagename|column|columdata:" + packagename + "|" + column + "|" + columndata);
    if (packagename == null || column == null) {
        return 0;

    }/* w  w w  .j a v  a2  s  .  c  o m*/
    if (column != URL_COL && column != GCM_COL && column != DATA_COL) {
        return 0;

    }
    int ret;
    synchronized (sAppTableLock) {
        final ContentValues c = new ContentValues();
        c.put(column, columndata);
        ret = sDatabase.update(APP_TABLE_NAME, c, PACKAGE_COL + "= ?", new String[] { packagename });
    }
    listTableContents();
    return ret;
}