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.nbos.phonebook.sync.platform.ContactManager.java

public static void addPhoneNumberToExistingContact(Context context,
        com.nbos.phonebook.sync.client.contact.Phone phone, long rawContactId) {
    Log.i(tag, "Adding phone number " + phone.number);
    if (TextUtils.isEmpty(phone.number))
        return;/*from w w w  .j a va 2 s  . c o  m*/
    ContentValues values = new ContentValues();
    values.put(Phone.RAW_CONTACT_ID, rawContactId);
    values.put(Phone.NUMBER, phone.number);
    int type = phone.getIntType();
    values.put(Phone.TYPE, type);
    if (type == Phone.TYPE_CUSTOM)
        values.put(Phone.DATA3, phone.type);
    values.put(Phone.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
    context.getContentResolver().insert(SyncManager.addCallerIsSyncAdapterParameter(Data.CONTENT_URI), values);
}

From source file:Main.java

public static ContentValues objectToContentValues(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("please check your argument");
    }//from   w  ww.  j  av  a 2 s.  com
    ContentValues contentValues = new ContentValues();
    try {
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            Type type = field.getType();
            field.setAccessible(true);
            if (type.equals(String.class)) {
                contentValues.put(fieldName, field.get(object).toString());
            } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
                contentValues.put(fieldName, field.getInt(object));
            } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
                contentValues.put(fieldName, field.getFloat(object));
            } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
                contentValues.put(fieldName, field.getLong(object));
            } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
                contentValues.put(fieldName, field.getDouble(object));
            } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
                contentValues.put(fieldName, field.getBoolean(object));
            }
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
    return contentValues;
}

From source file:com.nbos.phonebook.sync.platform.ContactManager.java

public static void addEmailToExistingContact(Context context,
        com.nbos.phonebook.sync.client.contact.Email email, long rawContactId) {
    Log.i(tag, "adding email: " + email);
    if (TextUtils.isEmpty(email.address))
        return;// w w  w .  j  a v  a 2 s. com
    ContentValues values = new ContentValues();
    values.put(Email.RAW_CONTACT_ID, rawContactId);
    values.put(Email.DATA, email.address);
    int type = email.getIntType();
    values.put(Email.TYPE, type);
    if (type == Email.TYPE_CUSTOM)
        values.put(Email.DATA3, email.type);
    values.put(Email.MIMETYPE, Email.CONTENT_ITEM_TYPE);
    context.getContentResolver().insert(SyncManager.addCallerIsSyncAdapterParameter(Data.CONTENT_URI), values);

}

From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java

public static Uri addToFavorite(Cursor cursor, Context context) {
    ContentValues values = new ContentValues();
    values.put(MovieContract.COLUMN_TITLE, Utility.getTitle(cursor));
    values.put(MovieContract.COLUMN_RELEASE_DATE, Utility.getReleaseDate(cursor));
    values.put(MovieContract.COLUMN_POSTER, Utility.getPoster(cursor));
    values.put(MovieContract.COLUMN_GENRES, Utility.getGenres(cursor));
    values.put(MovieContract.COLUMN_AVERAGE_VOTE, Utility.getVote(cursor));
    values.put(MovieContract.COLUMN_PLOT, Utility.getPlot(cursor));
    values.put(MovieContract.COLUMN_MOVIE_ID, Utility.getMovieId(cursor));
    values.put(MovieContract.COLUMN_BACKDROP_PATH, Utility.getBackdrop(cursor));

    return context.getContentResolver().insert(FavoriteMovie.CONTENT_URI, values);
}

From source file:com.example.orangeweather.JSONWeatherParser.java

public static ContentValues getWeather2(JSONObject jObj) throws JSONException {
    ContentValues cv = new ContentValues();

    JSONObject coordObj = getObject("coord", jObj);
    //cv.put(CityTags.CITY_NAME, getString("name", jObj));
    cv.put("_id", getInt("id", jObj));
    cv.put(WeatherTags.WEATHER_DT, getInt("dt", jObj));
    //cv.put(CityTags.CITY_COORD, getDMSCoordinates(getFloat("lat", coordObj), getFloat("lon", coordObj)));

    JSONObject sysObj = getObject("sys", jObj);
    //cv.put(CityTags.CITY_SYS_COUNTRY, getString("country", sysObj));

    if (sysObj.has("sunrise")) {
        cv.put(WeatherTags.WEATHER_SYS_SUNRISE, getInt("sunrise", sysObj));
    }//  ww w .ja v a 2  s.  c om
    if (sysObj.has("sunset")) {
        cv.put(WeatherTags.WEATHER_SYS_SUNSET, getInt("sunset", sysObj));
    }

    JSONArray jArr = jObj.getJSONArray("weather");

    JSONObject JSONWeather = jArr.getJSONObject(0);

    cv.put(WeatherTags.WEATHER_CONDITION_DESC, getString("description", JSONWeather));
    cv.put(WeatherTags.WEATHER_CONDITION_MAIN, getString("main", JSONWeather));

    JSONObject mainObj = getObject("main", jObj);
    cv.put(WeatherTags.WEATHER_MAIN_HUMIDITY, getInt("humidity", mainObj));
    cv.put(WeatherTags.WEATHER_MAIN_PRESSURE, getInt("pressure", mainObj));
    cv.put(WeatherTags.WEATHER_MAIN_TEMP_MAX, getTemperatureString(getFloat("temp_max", mainObj)));
    cv.put(WeatherTags.WEATHER_MAIN_TEMP_MIN, getTemperatureString(getFloat("temp_min", mainObj)));
    cv.put(WeatherTags.WEATHER_MAIN_TEMP, getTemperatureString(getFloat("temp", mainObj)));

    JSONObject wObj = getObject("wind", jObj);
    cv.put(WeatherTags.WEATHER_WIND_SPEED, getFloat("speed", wObj));
    cv.put(WeatherTags.WEATHER_WIND_DEG, getInt("deg", wObj));

    if (wObj.has("var_beg")) {
        cv.put(WeatherTags.WEATHER_WIND_VAR_BEG, getInt("var_beg", wObj));
    }
    if (wObj.has("var_end")) {
        cv.put(WeatherTags.WEATHER_WIND_VAR_END, getInt("var_end", wObj));
    }

    JSONObject cObj = getObject("clouds", jObj);
    cv.put(WeatherTags.WEATHER_CLOUDS_ALL, getInt("all", cObj));

    return cv;
}

From source file:Main.java

public static ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        if (municipalities) {
            cursor.moveToNext();/*  w w w. j  a  v  a2  s  .c  om*/
        }
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("city_id", cursor.getInt(0));
            values.put("city", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:com.nbos.phonebook.sync.platform.ContactManager.java

public static void resetDirtySharedBooks(Context ctx) {
    ContentResolver cr = ctx.getContentResolver();
    int num = cr.delete(Constants.SHARE_BOOK_URI, BookTable.DELETED + " = 1", null);
    Log.i(tag, "Deleted " + num + " contacts sharing with");
    ContentValues values = new ContentValues();
    values = new ContentValues();
    values.put(BookTable.DIRTY, "0");
    num = cr.update(Constants.SHARE_BOOK_URI, values, null, null);
    Log.i(tag, "Updated " + num + " sharebooks to dirty = 0");
}

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

public static void sendGroupInvite(final Context c, Uri feed, final String group_name, Uri updateUri) {

    ContentValues cv = new ContentValues();
    cv.put(DbObject.JSON, InviteToGroupObj.json(group_name, updateUri).toString());
    cv.put(DbObject.TYPE, InviteToGroupObj.TYPE);
    c.getContentResolver().insert(feed, cv);
}

From source file:com.granita.icloudcalsync.resource.LocalTaskList.java

public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info)
        throws LocalStorageException {
    final ContentProviderClient client = resolver.acquireContentProviderClient(TASKS_AUTHORITY);
    if (client == null)
        throw new LocalStorageException("No tasks provider found");

    ContentValues values = new ContentValues();
    values.put(TaskContract.TaskLists.ACCOUNT_NAME, account.name);
    values.put(TaskContract.TaskLists.ACCOUNT_TYPE, account.type);
    values.put(TaskContract.TaskLists._SYNC_ID, info.getURL());
    values.put(TaskContract.TaskLists.LIST_NAME, info.getTitle());
    values.put(TaskContract.TaskLists.LIST_COLOR, DAVUtils.CalDAVtoARGBColor(info.getColor()));
    values.put(TaskContract.TaskLists.OWNER, account.name);
    values.put(TaskContract.TaskLists.ACCESS_LEVEL, 0);
    values.put(TaskContract.TaskLists.SYNC_ENABLED, 1);
    values.put(TaskContract.TaskLists.VISIBLE, 1);

    Log.i(TAG, "Inserting task list: " + values.toString());
    try {/*from w  w w . jav  a 2 s  .c  om*/
        return client.insert(taskListsURI(account), values);
    } catch (RemoteException e) {
        throw new LocalStorageException(e);
    }
}

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

public static void updateGroupVersion(final Context c, final long groupId, final int version) {
    Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/groups");
    ContentValues values = new ContentValues();
    values.put(Group.VERSION, version);
    c.getContentResolver().update(url, values, Group._ID + "=" + groupId, null);
}