List of usage examples for android.content ContentValues putNull
public void putNull(String key)
From source file:com.example.easyvoice.MessageDetail.java
public void onSave(View view) { Log.i("MessageDetail", "onSave"); SQLiteDatabase sampleDB = null;// w ww. jav a 2 s . co m try { sampleDB = this.openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null); ContentValues values = new ContentValues(); values.putNull("msg_id"); values.put("disp_name", displayEdit.getText().toString()); values.put("content", contentEdit.getText().toString()); long insertId = sampleDB.insert(TABLE_NAME, null, values); Log.i(getClass().getSimpleName(), "inserted " + Long.toString(insertId)); // invalidate? // go back Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } catch (SQLiteException se) { Log.e(getClass().getSimpleName(), "Could not create or Open the database"); } }
From source file:io.github.mkjung.ivi.media.MediaDatabase.java
private static void safePut(ContentValues values, String key, String value) { if (value == null) values.putNull(key); else/*from w w w.j a v a2s.co m*/ values.put(key, value); }
From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java
protected static ContentValues getValuesForEvent(LocalEventCollection hack, Long calendarId, ComponentETagPair<Calendar> component) throws InvalidComponentException, RemoteException { VEvent vEvent = (VEvent) component.getComponent().getComponent(VEvent.VEVENT); if (vEvent != null) { ContentValues values = new ContentValues(); handleAddValuesForRecurrenceProperties(vEvent, values); values.put(CalendarContract.Events.CALENDAR_ID, calendarId); if (vEvent.getUid() != null && vEvent.getUid().getValue() != null) values.put(CalendarContract.Events._SYNC_ID, vEvent.getUid().getValue()); else/*w ww.j a va2s . co m*/ values.putNull(CalendarContract.Events._SYNC_ID); if (component.getETag().isPresent()) values.put(CalendarContract.Events.SYNC_DATA1, component.getETag().get()); DtStart dtStart = vEvent.getStartDate(); if (dtStart != null && dtStart.getDate() != null) { if (dtStart.getTimeZone() != null) values.put(CalendarContract.Events.EVENT_TIMEZONE, dtStart.getTimeZone().getID()); values.put(CalendarContract.Events.DTSTART, dtStart.getDate().getTime()); } else { Log.e(TAG, "no start date found on event"); throw new InvalidComponentException("no start date found on event", false, CalDavConstants.CALDAV_NAMESPACE, hack.getPath()); } Status status = vEvent.getStatus(); Property originalInstanceTimeProp = vEvent.getProperty(PROPERTY_NAME_FLOCK_ORIGINAL_INSTANCE_TIME); if (status != null && status != Status.VEVENT_CANCELLED && originalInstanceTimeProp != null) handleAddValuesForEditExceptionToRecurring(hack, vEvent, values); if (status != null && status == Status.VEVENT_CONFIRMED) values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED); else if (status != null && status == Status.VEVENT_CANCELLED) handleAddValuesForDeletionExceptionToRecurring(hack, vEvent, values); else values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_TENTATIVE); Summary summary = vEvent.getSummary(); if (summary != null) values.put(CalendarContract.Events.TITLE, summary.getValue()); Location location = vEvent.getLocation(); if (location != null) values.put(CalendarContract.Events.EVENT_LOCATION, location.getValue()); Description description = vEvent.getDescription(); if (description != null) values.put(CalendarContract.Events.DESCRIPTION, description.getValue()); Transp transparency = vEvent.getTransparency(); if (transparency != null && transparency == Transp.OPAQUE) values.put(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY); else values.put(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_FREE); Organizer organizer = vEvent.getOrganizer(); if (organizer != null && organizer.getCalAddress() != null) { URI organizerAddress = organizer.getCalAddress(); if (organizerAddress.getScheme() != null && organizerAddress.getScheme().equalsIgnoreCase("mailto")) values.put(CalendarContract.Events.ORGANIZER, organizerAddress.getSchemeSpecificPart()); } RRule rRule = (RRule) vEvent.getProperty(RRule.RRULE); RDate rDate = (RDate) vEvent.getProperty(RDate.RDATE); ExRule exRule = (ExRule) vEvent.getProperty(ExRule.EXRULE); ExDate exDate = (ExDate) vEvent.getProperty(ExDate.EXDATE); if (rRule != null) values.put(CalendarContract.Events.RRULE, rRule.getValue()); if (rDate != null) values.put(CalendarContract.Events.RDATE, rDate.getValue()); if (exRule != null) values.put(CalendarContract.Events.EXRULE, exRule.getValue()); if (exDate != null) values.put(CalendarContract.Events.EXDATE, exDate.getValue()); if (rRule == null && rDate == null) { DtEnd dtEnd = vEvent.getEndDate(); if (dtEnd != null && dtEnd.getDate() != null) { if (dtEnd.getTimeZone() != null) values.put(CalendarContract.Events.EVENT_TIMEZONE, dtEnd.getTimeZone().getID()); values.put(CalendarContract.Events.DTEND, dtEnd.getDate().getTime()); } else if (vEvent.getDuration() != null) { Duration duration = vEvent.getDuration(); java.util.Date endDate = duration.getDuration().getTime(dtStart.getDate()); values.put(CalendarContract.Events.DTEND, endDate.getTime()); } else values.put(CalendarContract.Events.ALL_DAY, 1); } else if (vEvent.getDuration() != null) values.put(CalendarContract.Events.DURATION, vEvent.getDuration().getValue()); else values.put(CalendarContract.Events.ALL_DAY, 1); PropertyList attendees = vEvent.getProperties(Attendee.ATTENDEE); if (attendees != null && attendees.size() > 0) values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, 1); else values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, 0); PropertyList alarms = vEvent.getProperties(VAlarm.VALARM); if (alarms != null && alarms.size() > 0) values.put(CalendarContract.Events.HAS_ALARM, 1); else values.put(CalendarContract.Events.HAS_ALARM, 0); return values; } Log.e(TAG, "no VEVENT found in component"); throw new InvalidComponentException("no VEVENT found in component", false, CalDavConstants.CALDAV_NAMESPACE, hack.getPath()); }
From source file:org.droidparts.persist.sql.EntityManager.java
protected void putToContentValues(ContentValues cv, String key, Class<?> valueType, Class<?> arrCollItemType, Object value) throws IllegalArgumentException { if (value == null) { cv.putNull(key); } else if (isBoolean(valueType)) { cv.put(key, ((Boolean) value)); } else if (isByte(valueType)) { cv.put(key, (Byte) value); } else if (isByteArray(valueType)) { cv.put(key, (byte[]) value); } else if (isDouble(valueType)) { cv.put(key, (Double) value); } else if (isFloat(valueType)) { cv.put(key, (Float) value); } else if (isInteger(valueType)) { cv.put(key, (Integer) value); } else if (isLong(valueType)) { cv.put(key, (Long) value); } else if (isShort(valueType)) { cv.put(key, (Short) value); } else if (isString(valueType)) { cv.put(key, (String) value); } else if (isUUID(valueType)) { cv.put(key, value.toString());/*from www . j ava 2 s . c o m*/ } else if (isDate(valueType)) { cv.put(key, ((Date) value).getTime()); } else if (isBitmap(valueType)) { Bitmap bm = (Bitmap) value; ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(CompressFormat.PNG, 0, baos); cv.put(key, baos.toByteArray()); } else if (isEnum(valueType)) { cv.put(key, value.toString()); } else if (isJsonObject(valueType) || isJsonArray(valueType)) { cv.put(key, value.toString()); } else if (isEntity(valueType)) { Long id = value != null ? ((Entity) value).id : null; cv.put(key, id); } else if (isArray(valueType) || isCollection(valueType)) { final ArrayList<Object> list = new ArrayList<Object>(); if (isArray(valueType)) { list.addAll(Arrays.asList(toObjectArr(value))); } else { list.addAll((Collection<?>) value); } if (isDate(arrCollItemType)) { for (int i = 0; i < list.size(); i++) { Long timestamp = ((Date) list.get(i)).getTime(); list.set(i, timestamp); } } String val = Strings.join(list, SEP, null); cv.put(key, val); } else { throw new IllegalArgumentException("Need to manually put " + valueType.getName() + " to cursor."); } }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null;/* w ww .jav a 2s. co m*/ try { cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }
From source file:org.tint.firefoximporter.SyncRunnable.java
private Map<String, Long> createFoldersRecursive(String weaveParent, long id, Map<String, Long> foldersMap) { if (foldersMap == null) { foldersMap = new HashMap<String, Long>(); }/*from w w w. ja va2s. c o m*/ Cursor c = WeaveWrapper.getFoldersByParent(mContentResolver, weaveParent); if (c != null) { if (c.moveToFirst()) { int weaveIdIndex = c.getColumnIndex(WeaveColumns.WEAVE_BOOKMARKS_WEAVE_ID); int titleIndex = c.getColumnIndex(WeaveColumns.WEAVE_BOOKMARKS_TITLE); do { String title = c.getString(titleIndex); ContentValues values = new ContentValues(); values.put(BookmarksWrapper.Columns.TITLE, title); values.putNull(BookmarksWrapper.Columns.URL); values.put(BookmarksWrapper.Columns.BOOKMARK, 0); values.put(BookmarksWrapper.Columns.IS_FOLDER, 1); values.put(BookmarksWrapper.Columns.PARENT_FOLDER_ID, id); long insertedId = BookmarksWrapper.insert(mContentResolver, values); String weaveId = c.getString(weaveIdIndex); foldersMap.put(weaveId, insertedId); if (insertedId != -1) { foldersMap = createFoldersRecursive(weaveId, insertedId, foldersMap); } } while (c.moveToNext()); } c.close(); } return foldersMap; }
From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java
public void onClickOk(View view) { // only in insert mode String url = mUrlEditText.getText().toString(); ContentResolver cr = getContentResolver(); if (!url.startsWith(Constants.HTTP) && !url.startsWith(Constants.HTTPS)) { url = Constants.HTTP + url;//from ww w . j a v a2 s. c om } Cursor cursor = cr.query(FeedColumns.CONTENT_URI, null, FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null); if (cursor.moveToFirst()) { cursor.close(); Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Toast.LENGTH_LONG).show(); } else { cursor.close(); ContentValues values = new ContentValues(); values.put(FeedColumns.URL, url); values.putNull(FeedColumns.ERROR); String name = mNameEditText.getText().toString(); if (name.trim().length() > 0) { values.put(FeedColumns.NAME, name); } values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null); cr.insert(FeedColumns.CONTENT_URI, values); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); cr.notifyChange(FeedColumns.GROUPED_FEEDS_CONTENT_URI, null); } setResult(RESULT_OK); finish(); }
From source file:co.nerdart.ourss.activity.EditFeedActivity.java
public void onClickOk(View view) { // only in insert mode String url = mUrlEditText.getText().toString(); ContentResolver cr = getContentResolver(); if (!url.startsWith(Constants.HTTP) && !url.startsWith(Constants.HTTPS)) { url = Constants.HTTP + url;// ww w .j a v a2 s. c om } Cursor cursor = cr.query(FeedColumns.CONTENT_URI, null, FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null); if (cursor.moveToFirst()) { cursor.close(); Crouton.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Style.INFO); } else { cursor.close(); ContentValues values = new ContentValues(); values.put(FeedColumns.URL, url); values.putNull(FeedColumns.ERROR); String name = mNameEditText.getText().toString(); if (name.trim().length() > 0) { values.put(FeedColumns.NAME, name); } values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null); cr.insert(FeedColumns.CONTENT_URI, values); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } setResult(RESULT_OK); finish(); }
From source file:com.app.uafeed.activity.EditFeedActivity.java
public void onClickOk(View view) { // only in insert mode String url = mUrlEditText.getText().toString(); ContentResolver cr = getContentResolver(); if (!url.startsWith(Constants.HTTP_SCHEME) && !url.startsWith(Constants.HTTPS_SCHEME)) { url = Constants.HTTP_SCHEME + url; }/* w w w . j ava2s .co m*/ Cursor cursor = cr.query(FeedColumns.CONTENT_URI, null, FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null); if (cursor.moveToFirst()) { cursor.close(); Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Toast.LENGTH_LONG).show(); } else { cursor.close(); ContentValues values = new ContentValues(); values.put(FeedColumns.URL, url); values.putNull(FeedColumns.ERROR); String name = mNameEditText.getText().toString(); if (name.trim().length() > 0) { values.put(FeedColumns.NAME, name); } values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null); cr.insert(FeedColumns.CONTENT_URI, values); } setResult(RESULT_OK); finish(); }
From source file:org.totschnig.myexpenses.model.Account.java
private ContentProviderOperation updateTransferPeersForTransactionDelete(String rowSelect, String[] selectionArgs) { ContentValues args = new ContentValues(); args.put(KEY_COMMENT, MyApplication.getInstance().getString(R.string.peer_transaction_deleted, label)); args.putNull(KEY_TRANSFER_ACCOUNT); args.putNull(KEY_TRANSFER_PEER);/*from w ww .j a va 2 s .co m*/ return ContentProviderOperation.newUpdate(Transaction.CONTENT_URI).withValues(args) .withSelection(KEY_TRANSFER_PEER + " IN (" + rowSelect + ")", selectionArgs).build(); }