List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testCrashReport() throws Exception { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); // Log a test (fake) crash report. Checkin.reportCrash(r, new CrashData("Test", "Test Activity", new BuildData("Test Build", "123", start), new ThrowableData(new RuntimeException("Test Exception")))); // Crashes aren't indexed; go through them all to find the one we added. Cursor c = r.query(Checkin.Crashes.CONTENT_URI, null, null, null, null); Uri uri = null;/*from ww w . j a v a2s .com*/ while (c.moveToNext()) { String coded = c.getString(c.getColumnIndex(Checkin.Crashes.DATA)); byte[] bytes = Base64.decodeBase64(coded.getBytes()); CrashData crash = new CrashData(new DataInputStream(new ByteArrayInputStream(bytes))); // Should be exactly one recently added "Test" crash. if (crash.getId().equals("Test") && crash.getTime() > start) { assertEquals("Test Activity", crash.getActivity()); assertEquals("Test Build", crash.getBuildData().getFingerprint()); assertEquals("Test Exception", crash.getThrowableData().getMessage()); assertNull(uri); uri = ContentUris.withAppendedId(Checkin.Crashes.CONTENT_URI, c.getInt(c.getColumnIndex(Checkin.Crashes._ID))); } } assertNotNull(uri); c.close(); // Update the "logs" column. ContentValues values = new ContentValues(); values.put(Checkin.Crashes.LOGS, "Test Logs"); assertEquals(1, r.update(uri, values, null, null)); c = r.query(uri, null, null, null, null); assertTrue(c.moveToNext()); String logs = c.getString(c.getColumnIndex(Checkin.Crashes.LOGS)); assertEquals("Test Logs", logs); c.deleteRow(); c.close(); c.requery(); assertFalse(c.moveToNext()); c.close(); }
From source file:com.clevertrail.mobile.Database_SavedTrails.java
public long insert(String sName, String sJSON) { ContentValues contentValues = new ContentValues(); contentValues.put("name", sName.replace("_", " ")); contentValues.put("json", sJSON); return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues); }
From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java
public int deleteTodo(ContentResolver contentResolver, Long id) { int ret = 0;/*from w w w.java2 s.co m*/ /* Using the local id */ int status = getTodoStatus(contentResolver, id); switch (status) { case StatusFlag.ADD: ret = contentResolver.delete(TodoContentProvider.CONTENT_URI, TodoContentProvider.COLUMN_ID + "=" + id, null); break; case StatusFlag.MOD: case StatusFlag.CLEAN: ContentValues cv = new ContentValues(); cv.put(TodoContentProvider.COLUMN_STATUS_FLAG, StatusFlag.DELETE); contentResolver.update(TodoContentProvider.CONTENT_URI, cv, TodoContentProvider.COLUMN_ID + "=" + id, null); break; default: throw new RuntimeException("Tried to delete a todo with invalid status"); } return ret; }
From source file:com.nicolacimmino.expensestracker.tracker.data_sync.ExpenseDataSyncAdapter.java
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//w w w .ja v a2 s . co m // Get expenses that are not yet synced with the server. Cursor expenses = getContext().getContentResolver().query( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ALL, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC + "=?", new String[] { "0" }, null); while (expenses.moveToNext()) { HttpURLConnection connection = null; try { JSONObject expense = new JSONObject(); expense.put(ExpensesApiContract.Expense.NOTES, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESCRIPTION))); expense.put(ExpensesApiContract.Expense.CURRENCY, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_CURRENCY))); expense.put(ExpensesApiContract.Expense.AMOUNT, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_AMOUNT))); expense.put(ExpensesApiContract.Expense.DESTINATION, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESTINATION))); expense.put(ExpensesApiContract.Expense.SOURCE, expenses.getString( expenses.getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SOURCE))); expense.put(ExpensesApiContract.Expense.TIMESTAMP, expenses.getString(expenses .getColumnIndex(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP))); expense.put(ExpensesApiContract.Expense.REPORTER_GCM_REG_ID, GcmRegistration.getRegistration_id()); ExpensesApiNewExpenseRequest request = new ExpensesApiNewExpenseRequest(expense); if (request.performRequest()) { syncResult.stats.numEntries++; ContentValues values = new ContentValues(); values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC, "1"); getContext().getContentResolver().update( ExpensesDataContentProvider.Contract.Expense.CONTENT_URI, values, ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID + "=?", new String[] { expenses.getString(expenses.getColumnIndex( ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_ID)) }); } else { syncResult.stats.numIoExceptions++; } } catch (JSONException e) { Log.e(TAG, "Error building json doc: " + e.toString()); syncResult.stats.numIoExceptions++; return; } finally { if (connection != null) { connection.disconnect(); } } } expenses.close(); fetchExpensesFromServer(); Log.i(TAG, "Sync done"); }
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); for (String value : values) { ifImageGetIt(value, sqlValues);//from w ww . j ava 2 s.co m 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:de.vanita5.twittnuker.task.CacheUsersStatusesTask.java
@Override protected Void doInBackground(final Void... args) { if (responses == null || responses.length == 0) return null; final ContentResolver resolver = context.getContentResolver(); final Extractor extractor = new Extractor(); final Set<ContentValues> usersValues = new HashSet<>(); final Set<ContentValues> statusesValues = new HashSet<>(); final Set<ContentValues> hashTagValues = new HashSet<>(); final Set<Long> allStatusIds = new HashSet<>(); final Set<String> allHashTags = new HashSet<>(); final Set<User> users = new HashSet<>(); for (final TwitterListResponse<twitter4j.Status> response : responses) { if (response == null || response.list == null) { continue; }/*from ww w. j av a 2 s .c o m*/ final List<twitter4j.Status> list = response.list; final Set<Long> userIds = new HashSet<>(); for (final twitter4j.Status status : list) { if (status == null || status.getId() <= 0) { continue; } if (status.isRetweet()) { final User retweetUser = status.getRetweetedStatus().getUser(); userIds.add(retweetUser.getId()); } allStatusIds.add(status.getId()); statusesValues.add(createStatus(status, response.account_id)); allHashTags.addAll(extractor.extractHashtags(status.getText())); final User user = status.getUser(); users.add(user); userIds.add(user.getId()); final ContentValues filtered_users_values = new ContentValues(); filtered_users_values.put(Filters.Users.NAME, user.getName()); filtered_users_values.put(Filters.Users.SCREEN_NAME, user.getScreenName()); final String filtered_users_where = Expression.equals(Filters.Users.USER_ID, user.getId()).getSQL(); resolver.update(Filters.Users.CONTENT_URI, filtered_users_values, filtered_users_where, null); } } bulkDelete(resolver, CachedStatuses.CONTENT_URI, CachedStatuses.STATUS_ID, allStatusIds, null, false); bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues); for (final String hashtag : allHashTags) { final ContentValues values = new ContentValues(); values.put(CachedHashtags.NAME, hashtag); hashTagValues.add(values); } bulkDelete(resolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, allHashTags, null, true); bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues); for (final User user : users) { usersValues.add(createCachedUser(user)); } bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues); return null; }
From source file:at.bitfire.davdroid.model.CollectionInfo.java
public ContentValues toDB() { ContentValues values = new ContentValues(); // Collections.SERVICE_ID is never changed values.put(Collections.URL, url); values.put(Collections.READ_ONLY, readOnly ? 1 : 0); values.put(Collections.DISPLAY_NAME, displayName); values.put(Collections.DESCRIPTION, description); values.put(Collections.COLOR, color); values.put(Collections.TIME_ZONE, timeZone); if (supportsVEVENT != null) values.put(Collections.SUPPORTS_VEVENT, supportsVEVENT ? 1 : 0); if (supportsVTODO != null) values.put(Collections.SUPPORTS_VTODO, supportsVTODO ? 1 : 0); values.put(Collections.SYNC, selected ? 1 : 0); return values; }
From source file:com.textuality.lifesaver.Restorer.java
private int restore(BufferedReader file, HashMap<String, Boolean> logged, Columns r, Uri uri, ProgressBar progress, String zeroField, int total) throws Exception { int added = 0; ContentResolver cr = getContentResolver(); int count = 0; String line;/* www .j a v a2s. co m*/ float denominator = ((float) total) / 100.0F; while ((line = file.readLine()) != null) { JSONObject json = new JSONObject(line); String key = r.jsonToKey(json); if (logged.get(key) == null) { ContentValues cv = r.jsonToContentValues(json); if (zeroField != null) cv.put(zeroField, 0); cr.insert(uri, cv); added++; } count += 1; progress.setProgress((int) (count / denominator)); } file.close(); return added; }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Marks messages as read.", returns = "number of messages marked read") public Integer smsMarkMessageRead( @RpcParameter(name = "ids", description = "List of message IDs to mark as read.") JSONArray ids, @RpcParameter(name = "read") Boolean read) throws JSONException { Integer result = 0;//w ww. j a v a 2s . c o m ContentValues values = new ContentValues(); values.put("read", read); for (int i = 0; i < ids.length(); i++) { Uri uri = buildMessageUri(ids.getInt(i)); result += mContentResolver.update(uri, values, null, null); } return result; }
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;//from w ww . j a v a 2s. c o m }