Java Code Examples for android.content.ContentValues#put()
The following examples show how to use
android.content.ContentValues#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbHelper.java From SmsScheduler with GNU General Public License v2.0 | 6 votes |
public void save(SmsModel sms) { ContentValues values = new ContentValues(); values.put(COLUMN_TIMESTAMP_SCHEDULED, sms.getTimestampScheduled()); values.put(COLUMN_RECIPIENT_NAME, sms.getRecipientName()); values.put(COLUMN_RECIPIENT_NUMBER, sms.getRecipientNumber()); values.put(COLUMN_MESSAGE, sms.getMessage()); values.put(COLUMN_STATUS, sms.getStatus()); values.put(COLUMN_RESULT, sms.getResult()); values.put(COLUMN_SUBSCRIPTION_ID, sms.getSubscriptionId()); values.put(COLUMN_RECURRING_MODE, sms.getRecurringMode()); if (sms.getTimestampCreated() > 0) { String whereClause = COLUMN_TIMESTAMP_CREATED + "=?"; String[] whereArgs = new String[] {sms.getTimestampCreated().toString()}; dbHelper.getWritableDatabase().update(TABLE_SMS, values, whereClause, whereArgs); } else { long timestampCreated = System.currentTimeMillis(); sms.setTimestampCreated(timestampCreated); values.put(COLUMN_TIMESTAMP_CREATED, timestampCreated); dbHelper.getWritableDatabase().insert(TABLE_SMS, null, values); } }
Example 2
Source File: ProfileManager.java From uPods-android with Apache License 2.0 | 6 votes |
public void addRecentMediaItem(MediaItem mediaItem) { if (mediaItem instanceof RadioItem) { if (!((RadioItem) mediaItem).isRecent) { if (!mediaItem.isExistsInDb) { ((RadioItem) mediaItem).save(); } ContentValues values = new ContentValues(); values.put("media_id", mediaItem.id); values.put("media_type", MediaListItem.TYPE_RADIO); values.put("list_type", MediaListItem.RECENT); UpodsApplication.getDatabaseManager().getWritableDatabase().insert("media_list", null, values); ((RadioItem) mediaItem).isRecent = true; notifyChanges(new ProfileUpdateEvent(MediaListItem.RECENT, mediaItem, false)); } } }
Example 3
Source File: DbHelper.java From Birdays with Apache License 2.0 | 5 votes |
public void addRecord(Person person) { ContentValues cv = new ContentValues(); cv.put(COLUMN_NAME, person.getName()); cv.put(COLUMN_DATE, person.getDate()); cv.put(COLUMN_IS_YEAR_KNOWN, Utils.boolToInt(person.isYearUnknown())); cv.put(COLUMN_PHONE_NUMBER, person.getPhoneNumber()); cv.put(COLUMN_EMAIL, person.getEmail()); cv.put(COLUMN_TIME_STAMP, person.getTimeStamp()); getWritableDatabase().insert(DB_PERSONS, null, cv); }
Example 4
Source File: Service.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
/** * Updates an existing streamer's info in the database */ public static void updateStreamerInfoDb(ChannelInfo aChannelInfo, Context context) { ContentValues values = new ContentValues(); values.put(SubscriptionsDbHelper.COLUMN_FOLLOWERS, aChannelInfo.getFollowers()); values.put(SubscriptionsDbHelper.COLUMN_UNIQUE_VIEWS, aChannelInfo.getViews()); updateStreamerInfoDbWithValues(values, context, aChannelInfo.getStreamerName()); }
Example 5
Source File: TrackHandler.java From Melophile with Apache License 2.0 | 5 votes |
public void save(Track track) { if (track != null) { insert(track); ContentValues values = new ContentValues(); values.put(MusicContract.History.HISTORY_ITEM_ID, track.getId()); provider.insert(MusicContract.History.buildTracksHistoryUri(), values); } }
Example 6
Source File: ContactDBHelper.java From Android-Debug-Database with Apache License 2.0 | 5 votes |
public boolean insertContact(String name, String phone, String email, String street, String place) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues contentValues = new ContentValues(); contentValues.put("name", name); contentValues.put("phone", phone); contentValues.put("email", email); contentValues.put("street", street); contentValues.put("place", place); contentValues.put(CONTACTS_CREATED_AT, Calendar.getInstance().getTimeInMillis()); db.insert("contacts", null, contentValues); return true; }
Example 7
Source File: DBMusicocoController.java From Musicoco with Apache License 2.0 | 5 votes |
public String updateSheet(int sheetID, String newName, String newRemark) { if (TextUtils.isEmpty(newName)) { return context.getString(R.string.error_name_required); } Sheet sheet = getSheet(sheetID); if (sheet == null) { return context.getString(R.string.error_non_sheet_existent); } List<Sheet> list = getSheets(); for (Sheet s : list) { if (s.id != sheetID && s.name.equals(newName)) { return context.getString(R.string.error_sheet_already_exits); } } newRemark = TextUtils.isEmpty(newRemark) ? "" : newRemark; ContentValues values = new ContentValues(); values.put(SHEET_NAME, newName); values.put(SHEET_REMARK, newRemark); String whereClause = SHEET_ID + " = ?"; String[] whereArgs = {sheetID + ""}; database.update(TABLE_SHEET, values, whereClause, whereArgs); return null; }
Example 8
Source File: ChromeBrowserProvider.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Uri insert(Uri uri, ContentValues values) { if (!canHandleContentProviderApiCall()) return null; int match = mUriMatcher.match(uri); Uri res = null; long id; switch (match) { case URI_MATCH_BOOKMARKS: id = addBookmark(values); if (id == INVALID_BOOKMARK_ID) return null; break; case URL_MATCH_API_BOOKMARK_CONTENT: values.put(BookmarkColumns.BOOKMARK, 1); //$FALL-THROUGH$ case URL_MATCH_API_BOOKMARK: case URL_MATCH_API_HISTORY_CONTENT: id = addBookmarkFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; case URL_MATCH_API_SEARCHES: id = addSearchTermFromAPI(values); if (id == INVALID_CONTENT_PROVIDER_ID) return null; break; default: throw new IllegalArgumentException(TAG + ": insert - unknown URL " + uri); } res = ContentUris.withAppendedId(uri, id); getContext().getContentResolver().notifyChange(res, null); return res; }
Example 9
Source File: StateSimulations.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Override public void simulate(SchemaManager schemaManager) { SQLiteDatabase db = schemaManager.getWritableDatabase(); ContentValues record = new ContentValues(); record.put("backend_name", "b1"); record.put("priority", PriorityMapping.toInt(Priority.DEFAULT)); record.put("next_request_ms", 0); long contextId = db.insert("transport_contexts", null, record); assertThat(contextId).isNotEqualTo(-1); ContentValues values = new ContentValues(); values.put("context_id", contextId); values.put("transport_name", "42"); values.put("timestamp_ms", 1); values.put("uptime_ms", 2); values.put( "payload", new EncodedPayload(PROTOBUF_ENCODING, "Hello".getBytes(Charset.defaultCharset())) .getBytes()); values.put("code", 1); values.put("num_attempts", 0); long newEventId = db.insert("events", null, values); assertThat(newEventId).isNotEqualTo(-1); ContentValues metadata = new ContentValues(); metadata.put("event_id", newEventId); metadata.put("name", "key1"); metadata.put("value", "value1"); long metadataId = db.insert("event_metadata", null, metadata); assertThat(metadataId).isNotEqualTo(-1); }
Example 10
Source File: FakeDataUtils.java From android-dev-challenge with Apache License 2.0 | 5 votes |
/** * Creates a single ContentValues object with random weather data for the provided date * @param date a normalized date * @return ContentValues object filled with random weather data */ private static ContentValues createTestWeatherContentValues(long date) { ContentValues testWeatherValues = new ContentValues(); testWeatherValues.put(WeatherEntry.COLUMN_DATE, date); testWeatherValues.put(WeatherEntry.COLUMN_DEGREES, Math.random()*2); testWeatherValues.put(WeatherEntry.COLUMN_HUMIDITY, Math.random()*100); testWeatherValues.put(WeatherEntry.COLUMN_PRESSURE, 870 + Math.random()*100); int maxTemp = (int)(Math.random()*100); testWeatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, maxTemp); testWeatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, maxTemp - (int) (Math.random()*10)); testWeatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, Math.random()*10); testWeatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherIDs[(int)(Math.random()*10)%5]); return testWeatherValues; }
Example 11
Source File: ChatSessionAdapter.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
public void markAsSeen() { Uri uriContact = ContentUris.withAppendedId(Imps.Contacts.CONTENT_URI, mContactId); Cursor c = mContentResolver.query(uriContact, new String[]{Imps.Contacts.TYPE}, null, null, null); if (c != null) { if (c.moveToFirst()) { int type = c.getInt(0); ContentValues contentValues = new ContentValues(); contentValues.put(Imps.Contacts.TYPE, type & (~Imps.Contacts.TYPE_FLAG_UNSEEN)); mContentResolver.update(uriContact, contentValues, null, null); } c.close(); } }
Example 12
Source File: TrustDB.java From trust with Apache License 2.0 | 5 votes |
public synchronized void addEntry(LogEntry e) { if (openWrite()) { mDB.beginTransaction(); ContentValues values = new ContentValues(); values.put("time", e.getTime()); values.put("ID", e.getID()); values.put("type", e.getType()); values.put("extra", "'" + e.getExtra() + "'"); mDB.insert(EVENT_TABLE, null, values); mDB.setTransactionSuccessful(); mDB.endTransaction(); } tryClose(); }
Example 13
Source File: DatabaseHelper.java From Android-Debug-Database with Apache License 2.0 | 5 votes |
public static UpdateRowResponse addRow(SQLiteDB db, String tableName, List<RowDataRequest> rowDataRequests) { UpdateRowResponse updateRowResponse = new UpdateRowResponse(); if (rowDataRequests == null || tableName == null) { updateRowResponse.isSuccessful = false; return updateRowResponse; } tableName = getQuotedTableName(tableName); ContentValues contentValues = new ContentValues(); for (RowDataRequest rowDataRequest : rowDataRequests) { if (Constants.NULL.equals(rowDataRequest.value)) { rowDataRequest.value = null; } switch (rowDataRequest.dataType) { case DataType.INTEGER: contentValues.put(rowDataRequest.title, Long.valueOf(rowDataRequest.value)); break; case DataType.REAL: contentValues.put(rowDataRequest.title, Double.valueOf(rowDataRequest.value)); break; case DataType.TEXT: contentValues.put(rowDataRequest.title, rowDataRequest.value); break; default: contentValues.put(rowDataRequest.title, rowDataRequest.value); break; } } long result = db.insert(tableName, null, contentValues); updateRowResponse.isSuccessful = result > 0; return updateRowResponse; }
Example 14
Source File: MoviesDetailsFragment.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
private long insertMovieInDatabase() { ContentValues cv = new ContentValues(); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_NAME, currentMovieTitle); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_GENRE, currentMovieGenre); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_TRAILER, youtubeUrl); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_POSTER, BitmapUtility.getBytes(imagePoster.getDrawingCache())); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_VIDEO_POSTER, BitmapUtility.getBytes(imageView.getDrawingCache())); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_RELEASE_DATE, currentMovieReleaseDate); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_RATING, currentMovieRating); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_PLOT, currentMoviePlot); cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_VOTE_COUNT, currentMovieVoteCount); return database.insert(MovieContract.MovieEntry.TABLE_NAME, null, cv); }
Example 15
Source File: ItemInfo.java From Trebuchet with GNU General Public License v3.0 | 4 votes |
static void writeBitmap(ContentValues values, Bitmap bitmap) { if (bitmap != null) { byte[] data = Utilities.flattenBitmap(bitmap); values.put(LauncherSettings.Favorites.ICON, data); } }
Example 16
Source File: VideoDbBuilder.java From tv-samples with Apache License 2.0 | 4 votes |
/** * 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 */ 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; }
Example 17
Source File: CacheFileInfoDao.java From MediaPlayerProxy with Apache License 2.0 | 4 votes |
public ContentValues packData(CacheFileInfo cacheFileSize) { ContentValues cv = new ContentValues(); cv.put("FileName", cacheFileSize.getFileName()); cv.put("FileSize", cacheFileSize.getFileSize()); return cv; }
Example 18
Source File: UserDatabase.java From MCPDict with MIT License | 4 votes |
public static void updateFavorite(char unicode, String comment) { ContentValues values = new ContentValues(); values.put("comment", comment); String[] args = {String.format("%04X", (int) unicode)}; db.update("favorite", values, "unicode = ?", args); }
Example 19
Source File: Queries.java From NClientV2 with Apache License 2.0 | 4 votes |
public static void resetAllStatus(){ ContentValues values=new ContentValues(1); values.put(STATUS,TagStatus.DEFAULT.ordinal()); db.updateWithOnConflict(TABLE_NAME,values,null,null,SQLiteDatabase.CONFLICT_IGNORE); }
Example 20
Source File: CategoryHandler.java From opentasks with Apache License 2.0 | 3 votes |
/** * Inserts a relation entry in the database to link task and category. * * @param db * The {@link SQLiteDatabase}. * @param taskId * The row id of the task. * @param categoryId * The row id of the category. * * @return The row id of the inserted relation. */ private long insertRelation(SQLiteDatabase db, long taskId, long categoryId, long propertyId) { ContentValues relationValues = new ContentValues(3); relationValues.put(CategoriesMapping.TASK_ID, taskId); relationValues.put(CategoriesMapping.CATEGORY_ID, categoryId); relationValues.put(CategoriesMapping.PROPERTY_ID, propertyId); return db.insert(Tables.CATEGORIES_MAPPING, "", relationValues); }