List of usage examples for android.content ContentValues containsKey
public boolean containsKey(String key)
From source file:org.wheelmap.android.fragment.POIDetailEditableFragment.java
public void save() { ContentValues values = retrieveContentValues(); if (values == null) { return;/* w ww . ja va 2 s .c o m*/ } if (!values.containsKey(POIs.NODETYPE_ID)) { showErrorMessage(getString(R.string.error_category_missing_title), getString(R.string.error_category_missing_message), Extra.UNKNOWN); return; } else if (mWheelchairFilterState == WheelchairFilterState.UNKNOWN) { showErrorMessage(getString(R.string.error_wheelchairstate_missing_title), getString(R.string.error_wheelchairstate_missing_message), Extra.UNKNOWN); return; } if (values.containsKey(POIs.WEBSITE)) { String website = values.getAsString(POIs.WEBSITE); website = website.toLowerCase(Locale.US); if (!website.startsWith("http://") && !website.startsWith("https://")) { website = "http://" + website; } if (!android.util.Patterns.WEB_URL.matcher(website).matches()) { showErrorMessage(null, getString(android.R.string.httpErrorBadUrl), -1); return; } values.put(POIs.WEBSITE, website); } values.put(POIs.DIRTY, POIs.DIRTY_ALL); PrepareDatabaseHelper.editCopy(getActivity().getContentResolver(), poiID, values); RestServiceHelper.executeUpdateServer(getActivity(), mReceiver); }
From source file:com.goliathonline.android.kegbot.io.RemoteKegHandler.java
/** {@inheritDoc} */ @Override/*from ww w . j a v a 2 s . c o m*/ public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver) throws JSONException, IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); // Walk document, parsing any incoming entries JSONObject result = parser.getJSONObject("result"); JSONObject keg = result.getJSONObject("keg"); JSONObject type = result.getJSONObject("type"); JSONObject image = type.getJSONObject("image"); final String kegId = sanitizeId(keg.getString("id")); final Uri kegUri = Kegs.buildKegUri(kegId); // Check for existing details, only update when changed final ContentValues values = queryKegDetails(kegUri, resolver); final long localUpdated = values.getAsLong(SyncColumns.UPDATED); final long serverUpdated = 500; //entry.getUpdated(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "found keg " + kegId); Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated); } // Clear any existing values for this session, treating the // incoming details as authoritative. batch.add(ContentProviderOperation.newDelete(kegUri).build()); final ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(Kegs.CONTENT_URI); builder.withValue(SyncColumns.UPDATED, serverUpdated); builder.withValue(Kegs.KEG_ID, kegId); // Inherit starred value from previous row if (values.containsKey(Kegs.KEG_STARRED)) { builder.withValue(Kegs.KEG_STARRED, values.getAsInteger(Kegs.KEG_STARRED)); } if (keg.has("status")) builder.withValue(Kegs.STATUS, keg.getString("status")); if (keg.has("volume_ml_remain")) builder.withValue(Kegs.VOLUME_REMAIN, keg.getDouble("volume_ml_remain")); if (keg.has("description")) builder.withValue(Kegs.DESCRIPTION, keg.getString("description")); if (keg.has("type_id")) builder.withValue(Kegs.TYPE_ID, keg.getString("type_id")); if (keg.has("size_id")) builder.withValue(Kegs.SIZE_ID, keg.getInt("size_id")); if (keg.has("percent_full")) builder.withValue(Kegs.PERCENT_FULL, keg.getDouble("percent_full")); if (keg.has("size_name")) builder.withValue(Kegs.SIZE_NAME, keg.getString("size_name")); if (keg.has("spilled_ml")) builder.withValue(Kegs.VOLUME_SPILL, keg.getDouble("spilled_ml")); if (keg.has("size_volume_ml")) builder.withValue(Kegs.VOLUME_SIZE, keg.getDouble("size_volume_ml")); if (type.has("name")) builder.withValue(Kegs.KEG_NAME, type.getString("name")); if (type.has("abv")) builder.withValue(Kegs.KEG_ABV, type.getDouble("abv")); if (image.has("url")) builder.withValue(Kegs.IMAGE_URL, image.getString("url")); // Normal keg details ready, write to provider batch.add(builder.build()); return batch; }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populatePhoto(Contact c, ContentValues row) throws RemoteException { if (row.containsKey(Photo.PHOTO_FILE_ID)) { Uri photoUri = Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()), RawContacts.DisplayPhoto.CONTENT_DIRECTORY); try {// w w w . ja v a2s .c o m @Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r"); @Cleanup InputStream is = fd.createInputStream(); c.photo = IOUtils.toByteArray(is); } catch (IOException ex) { Log.w(TAG, "Couldn't read high-res contact photo", ex); } } else c.photo = row.getAsByteArray(Photo.PHOTO); }
From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java
protected void populatePhoto(Contact c, ContentValues row) throws RemoteException { if (row.containsKey(Photo.PHOTO_FILE_ID)) { Uri photoUri = Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()), RawContacts.DisplayPhoto.CONTENT_DIRECTORY); try {// ww w . java 2s . c om @Cleanup AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r"); @Cleanup InputStream is = fd.createInputStream(); c.setPhoto(IOUtils.toByteArray(is)); } catch (IOException ex) { Log.w(TAG, "Couldn't read high-res contact photo", ex); } } else c.setPhoto(row.getAsByteArray(Photo.PHOTO)); }
From source file:org.mozilla.gecko.tests.BaseTest.java
public boolean CursorMatches(Cursor c, ContentValues cv) { for (int i = 0; i < c.getColumnCount(); i++) { String column = c.getColumnName(i); if (cv.containsKey(column)) { mAsserter.info("Comparing", "Column values for: " + column); Object value = cv.get(column); if (value == null) { if (!c.isNull(i)) { return false; }/*from w ww . j ava 2 s. c om*/ } else { if (c.isNull(i) || !value.toString().equals(c.getString(i))) { return false; } } } } return true; }
From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java
@Override public synchronized Uri insert(Uri uri, ContentValues initialValues) { List<String> segments = uri.getPathSegments(); if (segments.size() != 1) { throw new IllegalArgumentException("Unknown URI (too many segments!) " + uri); }/* w w w .ja v a2s . com*/ String appName = segments.get(0); ODKFileUtils.verifyExternalStorageAvailability(); ODKFileUtils.assertDirectoryStructure(appName); WebLogger log = WebLogger.getLogger(appName); ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } // ODK2: require FORM_MEDIA_PATH (different behavior -- ODK1 and // required FORM_FILE_PATH) if (!values.containsKey(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)) { throw new IllegalArgumentException(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + " must be specified."); } // Normalize path... File mediaPath = ODKFileUtils.asAppFile(appName, values.getAsString(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)); // require that the form directory actually exists if (!mediaPath.exists()) { throw new IllegalArgumentException(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + " directory does not exist: " + mediaPath.getAbsolutePath()); } patchUpValues(appName, values); if (values.containsKey(FormsColumns.DISPLAY_SUBTEXT) == false) { Date today = new Date(); String ts = new SimpleDateFormat(getContext().getString(R.string.added_on_date_at_time), Locale.getDefault()).format(today); values.put(FormsColumns.DISPLAY_SUBTEXT, ts); } if (values.containsKey(FormsColumns.DISPLAY_NAME) == false) { values.put(FormsColumns.DISPLAY_NAME, mediaPath.getName()); } // first try to see if a record with this filename already exists... String[] projection = { FormsColumns.FORM_ID, FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH }; String[] selectionArgs = { ODKFileUtils.asRelativePath(appName, mediaPath) }; String selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "=?"; Cursor c = null; SQLiteDatabase db = null; try { db = DatabaseFactory.get().getDatabase(getContext(), appName); db.beginTransaction(); try { c = db.query(DatabaseConstants.FORMS_TABLE_NAME, projection, selection, selectionArgs, null, null, null); if (c == null) { throw new SQLException("FAILED Insert into " + uri + " -- unable to query for existing records: " + mediaPath.getAbsolutePath()); } if (c.getCount() > 0) { // already exists throw new SQLException("FAILED Insert into " + uri + " -- row already exists for form directory: " + mediaPath.getAbsolutePath()); } } catch (Exception e) { log.w(t, "FAILED Insert into " + uri + " -- query for existing row failed: " + e.toString()); if (e instanceof SQLException) { throw (SQLException) e; } else { throw new SQLException( "FAILED Insert into " + uri + " -- query for existing row failed: " + e.toString()); } } finally { if (c != null) { c.close(); } } try { long rowId = db.insert(DatabaseConstants.FORMS_TABLE_NAME, null, values); db.setTransactionSuccessful(); if (rowId > 0) { Uri formUri = Uri.withAppendedPath( Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), appName), values.getAsString(FormsColumns.FORM_ID)); getContext().getContentResolver().notifyChange(formUri, null); Uri idUri = Uri.withAppendedPath( Uri.withAppendedPath(Uri.parse("content://" + getFormsAuthority()), appName), Long.toString(rowId)); getContext().getContentResolver().notifyChange(idUri, null); return formUri; } } catch (Exception e) { log.w(t, "FAILED Insert into " + uri + " -- insert of row failed: " + e.toString()); if (e instanceof SQLException) { throw (SQLException) e; } else { throw new SQLException( "FAILED Insert into " + uri + " -- insert of row failed: " + e.toString()); } } } finally { if (db != null) { db.endTransaction(); db.close(); } } throw new SQLException("Failed to insert row into " + uri); }
From source file:org.thomnichols.android.gmarks.GmarksProvider.java
@Override public Uri insert(Uri uri, ContentValues initialValues) { // Validate the requested uri if (sUriMatcher.match(uri) != BOOKMARKS_URI) { throw new IllegalArgumentException("Unknown URI " + uri); }/*from w w w . j av a2 s.c o m*/ ContentValues values; if (initialValues != null) { values = new ContentValues(initialValues); } else { values = new ContentValues(); } Long now = Long.valueOf(System.currentTimeMillis()); // Make sure that the fields are all set if (values.containsKey(Bookmark.Columns.CREATED_DATE) == false) { values.put(Bookmark.Columns.CREATED_DATE, now); } if (values.containsKey(Bookmark.Columns.MODIFIED_DATE) == false) { values.put(Bookmark.Columns.MODIFIED_DATE, now); } if (values.containsKey(Bookmark.Columns.TITLE) == false) { Resources r = Resources.getSystem(); values.put(Bookmark.Columns.TITLE, r.getString(android.R.string.untitled)); } if (values.containsKey(Bookmark.Columns.DESCRIPTION) == false) { values.put(Bookmark.Columns.DESCRIPTION, ""); } SQLiteDatabase db = dbHelper.getWritableDatabase(); long rowId = db.insert(BOOKMARKS_TABLE_NAME, "", values); if (rowId > 0) { Uri noteUri = ContentUris.withAppendedId(Bookmark.CONTENT_URI, rowId); getContext().getContentResolver().notifyChange(noteUri, null); return noteUri; } throw new SQLException("Failed to insert row into " + uri); }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populateEmailAddress(Contact c, ContentValues row) { ezvcard.property.Email email = new ezvcard.property.Email(row.getAsString(Email.ADDRESS)); if (row.containsKey(Email.TYPE)) switch (row.getAsInteger(Email.TYPE)) { case Email.TYPE_HOME: email.addType(EmailType.HOME); break; case Email.TYPE_WORK: email.addType(EmailType.WORK); break; case Email.TYPE_MOBILE: email.addType(Contact.EMAIL_TYPE_MOBILE); break; case Email.TYPE_CUSTOM: String customType = row.getAsString(Email.LABEL); if (StringUtils.isNotEmpty(customType)) email.addType(EmailType.get(labelToXName(customType))); }//from w ww .j a va 2s . com if (row.getAsInteger(Email.IS_PRIMARY) != 0) email.addType(EmailType.PREF); c.getEmails().add(email); }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populateSipAddress(Contact c, ContentValues row) { try {// www.j a v a2 s .c o m Impp impp = new Impp("sip:" + row.getAsString(SipAddress.SIP_ADDRESS)); if (row.containsKey(SipAddress.TYPE)) switch (row.getAsInteger(SipAddress.TYPE)) { case SipAddress.TYPE_HOME: impp.addType(ImppType.HOME); break; case SipAddress.TYPE_WORK: impp.addType(ImppType.WORK); break; case SipAddress.TYPE_CUSTOM: String customType = row.getAsString(SipAddress.LABEL); if (StringUtils.isNotEmpty(customType)) impp.addType(ImppType.get(labelToXName(customType))); } c.getImpps().add(impp); } catch (IllegalArgumentException e) { Log.e(TAG, "Illegal SIP URI", e); } }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populatePostalAddress(Contact c, ContentValues row) { Address address = new Address(); address.setLabel(row.getAsString(StructuredPostal.FORMATTED_ADDRESS)); if (row.containsKey(StructuredPostal.TYPE)) switch (row.getAsInteger(StructuredPostal.TYPE)) { case StructuredPostal.TYPE_HOME: address.addType(AddressType.HOME); break; case StructuredPostal.TYPE_WORK: address.addType(AddressType.WORK); break; case StructuredPostal.TYPE_CUSTOM: String customType = row.getAsString(StructuredPostal.LABEL); if (StringUtils.isNotEmpty(customType)) address.addType(AddressType.get(labelToXName(customType))); break; }/*from w w w . j a v a 2 s . c om*/ address.setStreetAddress(row.getAsString(StructuredPostal.STREET)); address.setPoBox(row.getAsString(StructuredPostal.POBOX)); address.setExtendedAddress(row.getAsString(StructuredPostal.NEIGHBORHOOD)); address.setLocality(row.getAsString(StructuredPostal.CITY)); address.setRegion(row.getAsString(StructuredPostal.REGION)); address.setPostalCode(row.getAsString(StructuredPostal.POSTCODE)); address.setCountry(row.getAsString(StructuredPostal.COUNTRY)); c.getAddresses().add(address); }