List of usage examples for android.content ContentValues containsKey
public boolean containsKey(String key)
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) { Context context = getContext(); if (context == null) { return null; }/* w ww . j a v a2s . c o m*/ if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME) || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name " + initialValues); } ComponentName componentName = ComponentName .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); } ApplicationInfo info; try { // Ensure the service is valid and extract the application info info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("Invalid component name " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e); } // Make sure they are using the short string format initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); // Only Muzei can set the IS_SELECTED field if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) { if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " column. Ignoring the value in " + initialValues); initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED); } } // Disable network access callbacks if we're running on an API 24 device and the source app // targets API 24. This is to be consistent with the Behavior Changes in Android N if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE) && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) { if (info.targetSdkVersion >= Build.VERSION_CODES.N) { Log.w(TAG, "Sources targeting API 24 cannot receive network access callbacks. Changing " + componentName + " to false for " + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false); } } final SQLiteDatabase db = databaseHelper.getWritableDatabase(); final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the source ID pattern and the new row ID appended to it. final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId); notifyChange(sourceUri); return sourceUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateNickname(ContentValues row) { if (row.containsKey(Nickname.NAME)) { ezvcard.property.Nickname nick = new ezvcard.property.Nickname(); nick.addValue(row.getAsString(Nickname.NAME)); Integer type = row.getAsInteger(Nickname.TYPE); if (type != null) switch (type) { case Nickname.TYPE_MAIDEN_NAME: nick.setType(Contact.NICKNAME_TYPE_MAIDEN_NAME); break; case Nickname.TYPE_SHORT_NAME: nick.setType(Contact.NICKNAME_TYPE_SHORT_NAME); break; case Nickname.TYPE_INITIALS: nick.setType(Contact.NICKNAME_TYPE_INITIALS); break; case Nickname.TYPE_OTHER_NAME: nick.setType(Contact.NICKNAME_TYPE_OTHER_NAME); break; case Nickname.TYPE_CUSTOM: String label = row.getAsString(Nickname.LABEL); if (!TextUtils.isEmpty(label)) nick.setType(labelToXName(label)); }/* w ww. j a v a2s .c o m*/ contact.nickName = nick; } }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populatePhoto(ContentValues row) throws RemoteException { if (row.containsKey(Photo.PHOTO_FILE_ID)) { Uri photoUri = Uri.withAppendedPath(rawContactSyncURI(), RawContacts.DisplayPhoto.CONTENT_DIRECTORY); try {//w w w .j a v a2 s. co m @Cleanup AssetFileDescriptor fd = addressBook.provider.openAssetFile(photoUri, "r"); @Cleanup InputStream stream = fd.createInputStream(); if (stream != null) contact.photo = IOUtils.toByteArray(stream); else Constants.log.warn("Ignoring inaccessible local contact photo file"); } catch (IOException e) { Constants.log.warn("Couldn't read local contact photo file", e); } } else contact.photo = row.getAsByteArray(Photo.PHOTO); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateWebsite(ContentValues row) { Url url = new Url(row.getAsString(Website.URL)); if (row.containsKey(Website.TYPE)) switch (row.getAsInteger(Website.TYPE)) { case Website.TYPE_HOMEPAGE: url.setType(Contact.URL_TYPE_HOMEPAGE); break; case Website.TYPE_BLOG: url.setType(Contact.URL_TYPE_BLOG); break; case Website.TYPE_PROFILE: url.setType(Contact.URL_TYPE_PROFILE); break; case Website.TYPE_HOME: url.setType("home"); break; case Website.TYPE_WORK: url.setType("work"); break; case Website.TYPE_FTP: url.setType(Contact.URL_TYPE_FTP); break; case Website.TYPE_CUSTOM: String label = row.getAsString(Website.LABEL); if (!TextUtils.isEmpty(label)) url.setType(labelToXName(label)); break; }/*from w w w .j ava2 s .co m*/ contact.getURLs().add(url); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private int updateSource(@NonNull final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) { Context context = getContext(); if (context == null) { return 0; }/*from ww w. ja va 2 s .c om*/ // Only Muzei can set the IS_SELECTED field if (values.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) { if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " column. Ignoring the value in " + values); values.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED); } } final SQLiteDatabase db = databaseHelper.getWritableDatabase(); String finalWhere = selection; String[] finalSelectionArgs = selectionArgs; if (MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) { // If the incoming URI matches a single source ID, does the update based on the incoming data, but // modifies the where clause to restrict it to the particular source ID. finalWhere = DatabaseUtils.concatenateWhere(finalWhere, BaseColumns._ID + " = " + uri.getLastPathSegment()); } String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName)) { // Only allow other apps to update their own source finalWhere = DatabaseUtils.concatenateWhere(finalWhere, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + " LIKE ?"); finalSelectionArgs = DatabaseUtils.appendSelectionArgs(finalSelectionArgs, new String[] { callingPackageName + "/%" }); } int count = db.update(MuzeiContract.Sources.TABLE_NAME, values, finalWhere, finalSelectionArgs); if (count > 0) { notifyChange(uri); } else if (values.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)) { insertSource(MuzeiContract.Sources.CONTENT_URI, values); count = 1; } return count; }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateSipAddress(ContentValues row) { try {// w ww. j a va2 s . co 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 (!TextUtils.isEmpty(customType)) impp.addType(ImppType.get(labelToXName(customType))); } contact.getImpps().add(impp); } catch (IllegalArgumentException e) { Constants.log.warn("Ignoring invalid locally stored SIP address"); } }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateStructuredPostal(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 (!TextUtils.isEmpty(customType)) address.addType(AddressType.get(labelToXName(customType))); break; }/*from w w w .j av a2s . c o m*/ 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)); contact.getAddresses().add(address); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) { Context context = getContext(); if (context == null) { return null; }//from ww w .j a va 2s .c o m if (values == null) { throw new IllegalArgumentException("Invalid ContentValues: must not be null"); } if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME) || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name: " + values); } // Check to make sure the component name is valid ComponentName componentName = ComponentName .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); } // Make sure they are using the short string format values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString()); // Ensure the app inserting the artwork is either Muzei or the same app as the source String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName) && !TextUtils.equals(callingPackageName, componentName.getPackageName())) { throw new IllegalArgumentException("Calling package name (" + callingPackageName + ") must match the source's package name (" + componentName.getPackageName() + ")"); } if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) { String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); Intent viewIntent; try { if (!TextUtils.isEmpty(viewIntentString)) { // Make sure it is a valid Intent URI viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME); // Make sure we can construct a PendingIntent for the Intent PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); } } catch (URISyntaxException e) { Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } catch (RuntimeException e) { // This is actually meant to catch a FileUriExposedException, but you can't // have catch statements for exceptions that don't exist at your minSdkVersion Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } } // Ensure the related source has been added to the database. // This should be true in 99.9% of cases, but the insert will fail if this isn't true Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { componentName.flattenToShortString() }, null); if (sourceQuery == null || sourceQuery.getCount() == 0) { ContentValues initialValues = new ContentValues(); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues); } if (sourceQuery != null) { sourceQuery.close(); } values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis()); final SQLiteDatabase db = databaseHelper.getWritableDatabase(); long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, values); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the artwork ID pattern and the new row ID appended to it. final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId); File artwork = getCacheFileForArtworkUri(artworkUri); if (artwork != null && artwork.exists()) { // The image already exists so we'll notifyChange() to say the new artwork is ready // Otherwise, this will be called when the file is written with openFile() // using this Uri and the actual artwork is written successfully notifyChange(artworkUri); } return artworkUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateEvent(ContentValues row) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); try {/*from w w w . j ava 2 s.c o m*/ Date date = formatter.parse(row.getAsString(CommonDataKinds.Event.START_DATE)); if (row.containsKey(Event.TYPE)) switch (row.getAsInteger(Event.TYPE)) { case Event.TYPE_ANNIVERSARY: contact.anniversary = new Anniversary(date); break; case Event.TYPE_BIRTHDAY: contact.birthDay = new Birthday(date); break; } } catch (ParseException e) { Constants.log.warn("Couldn't parse birthday/anniversary date from database", e); } }
From source file:org.runnerup.view.DetailActivity.java
void requery() { {// w w w . j a v a 2 s. c o m /** * Laps */ String[] from = new String[] { "_id", DB.LAP.LAP, DB.LAP.INTENSITY, DB.LAP.TIME, DB.LAP.DISTANCE, DB.LAP.PLANNED_TIME, DB.LAP.PLANNED_DISTANCE, DB.LAP.PLANNED_PACE, DB.LAP.AVG_HR }; Cursor c = mDB.query(DB.LAP.TABLE, from, DB.LAP.ACTIVITY + " == " + mID, null, null, null, "_id", null); laps = DBHelper.toArray(c); c.close(); lapHrPresent = false; for (ContentValues v : laps) { if (v.containsKey(DB.LAP.AVG_HR) && v.getAsInteger(DB.LAP.AVG_HR) > 0) { lapHrPresent = true; break; } } } { /** * Accounts/reports */ String sql = new String("SELECT DISTINCT " + " acc._id, " // 0 + (" acc." + DB.ACCOUNT.NAME + ", ") + (" acc." + DB.ACCOUNT.DESCRIPTION + ", ") + (" acc." + DB.ACCOUNT.FLAGS + ", ") + (" acc." + DB.ACCOUNT.AUTH_METHOD + ", ") + (" acc." + DB.ACCOUNT.AUTH_CONFIG + ", ") + (" acc." + DB.ACCOUNT.ENABLED + ", ") + (" rep._id as repid, ") + (" rep." + DB.EXPORT.ACCOUNT + ", ") + (" rep." + DB.EXPORT.ACTIVITY + ", ") + (" rep." + DB.EXPORT.STATUS) + (" FROM " + DB.ACCOUNT.TABLE + " acc ") + (" LEFT OUTER JOIN " + DB.EXPORT.TABLE + " rep ") + (" ON ( acc._id = rep." + DB.EXPORT.ACCOUNT) + (" AND rep." + DB.EXPORT.ACTIVITY + " = " + mID + " )") + (" WHERE acc." + DB.ACCOUNT.ENABLED + " != 0 ") + (" AND acc." + DB.ACCOUNT.AUTH_CONFIG + " is not null")); Cursor c = mDB.rawQuery(sql, null); alreadyUploadedUploaders.clear(); pendingUploaders.clear(); reports.clear(); if (c.moveToFirst()) { do { ContentValues tmp = DBHelper.get(c); Uploader uploader = uploadManager.add(tmp); if (!uploader.checkSupport(Feature.UPLOAD)) { continue; } reports.add(tmp); if (tmp.containsKey("repid")) { alreadyUploadedUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME)); } else if (tmp.containsKey(DB.ACCOUNT.FLAGS) && Bitfield.test(tmp.getAsLong(DB.ACCOUNT.FLAGS), DB.ACCOUNT.FLAG_UPLOAD)) { pendingUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME)); } } while (c.moveToNext()); } c.close(); } if (mode == MODE_DETAILS) { if (pendingUploaders.isEmpty()) { uploadButton.setVisibility(View.GONE); } else { uploadButton.setVisibility(View.VISIBLE); } } for (BaseAdapter a : adapters) { a.notifyDataSetChanged(); } }