List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:org.opendatakit.common.android.provider.impl.FormsProviderImpl.java
private void patchUpValues(String appName, ContentValues values) { // don't let users put in a manual FORM_FILE_PATH if (values.containsKey(FormsColumns.APP_RELATIVE_FORM_FILE_PATH)) { values.remove(FormsColumns.APP_RELATIVE_FORM_FILE_PATH); }/*from w w w . j a v a 2 s. c om*/ // don't let users put in a manual FORM_PATH if (values.containsKey(FormsColumns.FORM_PATH)) { values.remove(FormsColumns.FORM_PATH); } // don't let users put in a manual DATE if (values.containsKey(FormsColumns.DATE)) { values.remove(FormsColumns.DATE); } // don't let users put in a manual md5 hash if (values.containsKey(FormsColumns.MD5_HASH)) { values.remove(FormsColumns.MD5_HASH); } // don't let users put in a manual json md5 hash if (values.containsKey(FormsColumns.JSON_MD5_HASH)) { values.remove(FormsColumns.JSON_MD5_HASH); } // if we are not updating FORM_MEDIA_PATH, we don't need to recalc any // of the above if (!values.containsKey(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH)) { return; } // Normalize path... // First, construct the full file path... String path = values.getAsString(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH); File mediaPath; if (path.startsWith(File.separator)) { mediaPath = new File(path); } else { mediaPath = ODKFileUtils.asAppFile(appName, 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()); } if (!ODKFileUtils.isPathUnderAppName(appName, mediaPath)) { throw new IllegalArgumentException( "Form definition is not contained within the application: " + appName); } values.put(FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH, ODKFileUtils.asRelativePath(appName, mediaPath)); // require that it contain a formDef file File formDefFile = new File(mediaPath, ODKFileUtils.FORMDEF_JSON_FILENAME); if (!formDefFile.exists()) { throw new IllegalArgumentException( ODKFileUtils.FORMDEF_JSON_FILENAME + " does not exist in: " + mediaPath.getAbsolutePath()); } // date is the last modification date of the formDef file Long now = formDefFile.lastModified(); values.put(FormsColumns.DATE, now); // ODK2: FILENAME_XFORMS_XML may not exist if non-ODK1 fetch path... File xformsFile = new File(mediaPath, ODKFileUtils.FILENAME_XFORMS_XML); if (xformsFile.exists()) { values.put(FormsColumns.APP_RELATIVE_FORM_FILE_PATH, ODKFileUtils.asRelativePath(appName, xformsFile)); } // compute FORM_PATH... String formPath = ODKFileUtils.getRelativeFormPath(appName, formDefFile); values.put(FormsColumns.FORM_PATH, formPath); String md5; if (xformsFile.exists()) { md5 = ODKFileUtils.getMd5Hash(appName, xformsFile); } else { md5 = "-none-"; } values.put(FormsColumns.MD5_HASH, md5); md5 = ODKFileUtils.getMd5Hash(appName, formDefFile); values.put(FormsColumns.JSON_MD5_HASH, md5); }
From source file:android.pim.vcard.VCardBuilder.java
/** * For safety, we'll emit just one value around StructuredName, as external importers * may get confused with multiple "N", "FN", etc. properties, though it is valid in * vCard spec.//from w w w .j a v a2 s .com */ public VCardBuilder appendNameProperties(final List<ContentValues> contentValuesList) { if (contentValuesList == null || contentValuesList.isEmpty()) { if (mIsDoCoMo) { appendLine(VCardConstants.PROPERTY_N, ""); } else if (mIsV30) { // vCard 3.0 requires "N" and "FN" properties. appendLine(VCardConstants.PROPERTY_N, ""); appendLine(VCardConstants.PROPERTY_FN, ""); } return this; } final ContentValues contentValues = getPrimaryContentValue(contentValuesList); final String familyName = contentValues.getAsString(StructuredName.FAMILY_NAME); final String middleName = contentValues.getAsString(StructuredName.MIDDLE_NAME); final String givenName = contentValues.getAsString(StructuredName.GIVEN_NAME); final String prefix = contentValues.getAsString(StructuredName.PREFIX); final String suffix = contentValues.getAsString(StructuredName.SUFFIX); final String displayName = contentValues.getAsString(StructuredName.DISPLAY_NAME); if (!TextUtils.isEmpty(familyName) || !TextUtils.isEmpty(givenName)) { final boolean reallyAppendCharsetParameterToName = shouldAppendCharsetParam(familyName, givenName, middleName, prefix, suffix); final boolean reallyUseQuotedPrintableToName = (!mRefrainsQPToNameProperties && !(VCardUtils.containsOnlyNonCrLfPrintableAscii(familyName) && VCardUtils.containsOnlyNonCrLfPrintableAscii(givenName) && VCardUtils.containsOnlyNonCrLfPrintableAscii(middleName) && VCardUtils.containsOnlyNonCrLfPrintableAscii(prefix) && VCardUtils.containsOnlyNonCrLfPrintableAscii(suffix))); final String formattedName; if (!TextUtils.isEmpty(displayName)) { formattedName = displayName; } else { formattedName = VCardUtils.constructNameFromElements(VCardConfig.getNameOrderType(mVCardType), familyName, middleName, givenName, prefix, suffix); } final boolean reallyAppendCharsetParameterToFN = shouldAppendCharsetParam(formattedName); final boolean reallyUseQuotedPrintableToFN = !mRefrainsQPToNameProperties && !VCardUtils.containsOnlyNonCrLfPrintableAscii(formattedName); final String encodedFamily; final String encodedGiven; final String encodedMiddle; final String encodedPrefix; final String encodedSuffix; if (reallyUseQuotedPrintableToName) { encodedFamily = encodeQuotedPrintable(familyName); encodedGiven = encodeQuotedPrintable(givenName); encodedMiddle = encodeQuotedPrintable(middleName); encodedPrefix = encodeQuotedPrintable(prefix); encodedSuffix = encodeQuotedPrintable(suffix); } else { encodedFamily = escapeCharacters(familyName); encodedGiven = escapeCharacters(givenName); encodedMiddle = escapeCharacters(middleName); encodedPrefix = escapeCharacters(prefix); encodedSuffix = escapeCharacters(suffix); } final String encodedFormattedname = (reallyUseQuotedPrintableToFN ? encodeQuotedPrintable(formattedName) : escapeCharacters(formattedName)); mBuilder.append(VCardConstants.PROPERTY_N); if (mIsDoCoMo) { if (reallyAppendCharsetParameterToName) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } if (reallyUseQuotedPrintableToName) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(VCARD_PARAM_ENCODING_QP); } mBuilder.append(VCARD_DATA_SEPARATOR); // DoCoMo phones require that all the elements in the "family name" field. mBuilder.append(formattedName); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); } else { if (reallyAppendCharsetParameterToName) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } if (reallyUseQuotedPrintableToName) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(VCARD_PARAM_ENCODING_QP); } mBuilder.append(VCARD_DATA_SEPARATOR); mBuilder.append(encodedFamily); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(encodedGiven); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(encodedMiddle); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(encodedPrefix); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(encodedSuffix); } mBuilder.append(VCARD_END_OF_LINE); // FN property mBuilder.append(VCardConstants.PROPERTY_FN); if (reallyAppendCharsetParameterToFN) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } if (reallyUseQuotedPrintableToFN) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(VCARD_PARAM_ENCODING_QP); } mBuilder.append(VCARD_DATA_SEPARATOR); mBuilder.append(encodedFormattedname); mBuilder.append(VCARD_END_OF_LINE); } else if (!TextUtils.isEmpty(displayName)) { final boolean reallyUseQuotedPrintableToDisplayName = (!mRefrainsQPToNameProperties && !VCardUtils.containsOnlyNonCrLfPrintableAscii(displayName)); final String encodedDisplayName = reallyUseQuotedPrintableToDisplayName ? encodeQuotedPrintable(displayName) : escapeCharacters(displayName); mBuilder.append(VCardConstants.PROPERTY_N); if (shouldAppendCharsetParam(displayName)) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } if (reallyUseQuotedPrintableToDisplayName) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(VCARD_PARAM_ENCODING_QP); } mBuilder.append(VCARD_DATA_SEPARATOR); mBuilder.append(encodedDisplayName); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(VCARD_END_OF_LINE); mBuilder.append(VCardConstants.PROPERTY_FN); // Note: "CHARSET" param is not allowed in vCard 3.0, but we may add it // when it would be useful for external importers, assuming no external // importer allows this vioration. if (shouldAppendCharsetParam(displayName)) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } mBuilder.append(VCARD_DATA_SEPARATOR); mBuilder.append(encodedDisplayName); mBuilder.append(VCARD_END_OF_LINE); } else if (mIsV30) { // vCard 3.0 specification requires these fields. appendLine(VCardConstants.PROPERTY_N, ""); appendLine(VCardConstants.PROPERTY_FN, ""); } else if (mIsDoCoMo) { appendLine(VCardConstants.PROPERTY_N, ""); } appendPhoneticNameFields(contentValues); return this; }
From source file:org.frc836.database.DBSyncService.java
private void processEvents(JSONArray events) { try {//from w w w . ja v a 2 s . c o m for (int i = 0; i < events.length(); i++) { JSONObject row = events.getJSONObject(i); Action action = Action.UPDATE; if (row.getInt(EVENT_LU_Entry.COLUMN_NAME_INVALID) != 0) { action = Action.DELETE; } ContentValues vals = new ContentValues(); vals.put(EVENT_LU_Entry.COLUMN_NAME_ID, row.getInt(EVENT_LU_Entry.COLUMN_NAME_ID)); vals.put(EVENT_LU_Entry.COLUMN_NAME_EVENT_NAME, row.getString(EVENT_LU_Entry.COLUMN_NAME_EVENT_NAME)); vals.put(EVENT_LU_Entry.COLUMN_NAME_EVENT_CODE, row.getString(EVENT_LU_Entry.COLUMN_NAME_EVENT_CODE)); vals.put(EVENT_LU_Entry.COLUMN_NAME_DATE_START, row.getString(EVENT_LU_Entry.COLUMN_NAME_DATE_START)); vals.put(EVENT_LU_Entry.COLUMN_NAME_TIMESTAMP, DB.dateParser.format(new Date(row.getLong(EVENT_LU_Entry.COLUMN_NAME_TIMESTAMP) * 1000))); // check if this entry exists already String[] projection = { EVENT_LU_Entry.COLUMN_NAME_EVENT_NAME }; String[] where = { vals.getAsString(EVENT_LU_Entry.COLUMN_NAME_ID) }; synchronized (ScoutingDBHelper.lock) { SQLiteDatabase db = ScoutingDBHelper.getInstance().getWritableDatabase(); Cursor c = db.query(EVENT_LU_Entry.TABLE_NAME, projection, // select EVENT_LU_Entry.COLUMN_NAME_ID + "=?", where, null, // don't // group null, // don't filter null, // don't order "0,1"); // limit to 1 try { if (!c.moveToFirst()) { if (action == Action.UPDATE) action = Action.INSERT; else if (action == Action.DELETE) action = Action.NOTHING; } switch (action) { case UPDATE: db.update(EVENT_LU_Entry.TABLE_NAME, vals, EVENT_LU_Entry.COLUMN_NAME_ID + " = ?", where); break; case INSERT: db.insert(EVENT_LU_Entry.TABLE_NAME, null, vals); break; case DELETE: db.delete(EVENT_LU_Entry.TABLE_NAME, EVENT_LU_Entry.COLUMN_NAME_ID + " = ?", where); break; default: } } finally { if (c != null) c.close(); ScoutingDBHelper.getInstance().close(); } } } } catch (JSONException e) { // TODO handle error } }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Raises a notification with a biggest earthquake with each sync * * @param notifyValues data with the biggest recent earthquake *//*from w ww .j a v a2 s. co m*/ private void sendNotification(ContentValues notifyValues) { Context context = getContext(); if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) { //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, DetailActivity.class); double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE); double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE); LatLng latLng = new LatLng(latitude, longitude); String distance = context.getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(context))); String magnitude = context.getString(R.string.earthquake_magnitude, notifyValues.getAsDouble(EarthquakeColumns.MAG)); String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME)); double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH); intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG)); intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE)); intent.putExtra(Feature.DATE, date); intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL)); intent.putExtra(Feature.LATLNG, latLng); intent.putExtra(Feature.DISTANCE, distance); intent.putExtra(Feature.DEPTH, depth); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.earthquake_statistics_largest)) .setContentText(context.getString(R.string.earthquake_magnitude, notifyValues.get(EarthquakeColumns.MAG))) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp) .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n" + distance + "\n" + date)) .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); //refreshing last sync boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit(); } } }
From source file:android.pim.vcard.VCardBuilder.java
public void appendAndroidSpecificProperty(final String mimeType, ContentValues contentValues) { if (!sAllowedAndroidPropertySet.contains(mimeType)) { return;//from www . j a va2 s . co m } final List<String> rawValueList = new ArrayList<String>(); for (int i = 1; i <= VCardConstants.MAX_DATA_COLUMN; i++) { String value = contentValues.getAsString("data" + i); if (value == null) { value = ""; } rawValueList.add(value); } boolean needCharset = (mShouldAppendCharsetParam && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawValueList)); boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawValueList)); mBuilder.append(VCardConstants.PROPERTY_X_ANDROID_CUSTOM); if (needCharset) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(mVCardCharsetParameter); } if (reallyUseQuotedPrintable) { mBuilder.append(VCARD_PARAM_SEPARATOR); mBuilder.append(VCARD_PARAM_ENCODING_QP); } mBuilder.append(VCARD_DATA_SEPARATOR); mBuilder.append(mimeType); // Should not be encoded. for (String rawValue : rawValueList) { final String encodedValue; if (reallyUseQuotedPrintable) { encodedValue = encodeQuotedPrintable(rawValue); } else { // TODO: one line may be too huge, which may be invalid in vCard 3.0 // (which says "When generating a content line, lines longer than // 75 characters SHOULD be folded"), though several // (even well-known) applications do not care this. encodedValue = escapeCharacters(rawValue); } mBuilder.append(VCARD_ITEM_SEPARATOR); mBuilder.append(encodedValue); } mBuilder.append(VCARD_END_OF_LINE); }
From source file:android.pim.vcard.VCardBuilder.java
/** * @return null when there's no information available to construct the data. *//*from w ww . j a v a 2s .c o m*/ private PostalStruct tryConstructPostalStruct(ContentValues contentValues) { // adr-value = 0*6(text-value ";") text-value // ; PO Box, Extended Address, Street, Locality, Region, Postal // ; Code, Country Name final String rawPoBox = contentValues.getAsString(StructuredPostal.POBOX); final String rawNeighborhood = contentValues.getAsString(StructuredPostal.NEIGHBORHOOD); final String rawStreet = contentValues.getAsString(StructuredPostal.STREET); final String rawLocality = contentValues.getAsString(StructuredPostal.CITY); final String rawRegion = contentValues.getAsString(StructuredPostal.REGION); final String rawPostalCode = contentValues.getAsString(StructuredPostal.POSTCODE); final String rawCountry = contentValues.getAsString(StructuredPostal.COUNTRY); final String[] rawAddressArray = new String[] { rawPoBox, rawNeighborhood, rawStreet, rawLocality, rawRegion, rawPostalCode, rawCountry }; if (!VCardUtils.areAllEmpty(rawAddressArray)) { final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawAddressArray)); final boolean appendCharset = !VCardUtils.containsOnlyPrintableAscii(rawAddressArray); final String encodedPoBox; final String encodedStreet; final String encodedLocality; final String encodedRegion; final String encodedPostalCode; final String encodedCountry; final String encodedNeighborhood; final String rawLocality2; // This looks inefficient since we encode rawLocality and rawNeighborhood twice, // but this is intentional. // // QP encoding may add line feeds when needed and the result of // - encodeQuotedPrintable(rawLocality + " " + rawNeighborhood) // may be different from // - encodedLocality + " " + encodedNeighborhood. // // We use safer way. if (TextUtils.isEmpty(rawLocality)) { if (TextUtils.isEmpty(rawNeighborhood)) { rawLocality2 = ""; } else { rawLocality2 = rawNeighborhood; } } else { if (TextUtils.isEmpty(rawNeighborhood)) { rawLocality2 = rawLocality; } else { rawLocality2 = rawLocality + " " + rawNeighborhood; } } if (reallyUseQuotedPrintable) { encodedPoBox = encodeQuotedPrintable(rawPoBox); encodedStreet = encodeQuotedPrintable(rawStreet); encodedLocality = encodeQuotedPrintable(rawLocality2); encodedRegion = encodeQuotedPrintable(rawRegion); encodedPostalCode = encodeQuotedPrintable(rawPostalCode); encodedCountry = encodeQuotedPrintable(rawCountry); } else { encodedPoBox = escapeCharacters(rawPoBox); encodedStreet = escapeCharacters(rawStreet); encodedLocality = escapeCharacters(rawLocality2); encodedRegion = escapeCharacters(rawRegion); encodedPostalCode = escapeCharacters(rawPostalCode); encodedCountry = escapeCharacters(rawCountry); encodedNeighborhood = escapeCharacters(rawNeighborhood); } final StringBuffer addressBuffer = new StringBuffer(); addressBuffer.append(encodedPoBox); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedStreet); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedLocality); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedRegion); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedPostalCode); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedCountry); return new PostalStruct(reallyUseQuotedPrintable, appendCharset, addressBuffer.toString()); } else { // VCardUtils.areAllEmpty(rawAddressArray) == true // Try to use FORMATTED_ADDRESS instead. final String rawFormattedAddress = contentValues.getAsString(StructuredPostal.FORMATTED_ADDRESS); if (TextUtils.isEmpty(rawFormattedAddress)) { return null; } final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawFormattedAddress)); final boolean appendCharset = !VCardUtils.containsOnlyPrintableAscii(rawFormattedAddress); final String encodedFormattedAddress; if (reallyUseQuotedPrintable) { encodedFormattedAddress = encodeQuotedPrintable(rawFormattedAddress); } else { encodedFormattedAddress = escapeCharacters(rawFormattedAddress); } // We use the second value ("Extended Address") just because Japanese mobile phones // do so. If the other importer expects the value be in the other field, some flag may // be needed. final StringBuffer addressBuffer = new StringBuffer(); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedFormattedAddress); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); return new PostalStruct(reallyUseQuotedPrintable, appendCharset, addressBuffer.toString()); } }
From source file:com.hualu.wifistart.vcardsrc.VCardBuilder.java
/** * @return null when there's no information available to construct the data. *//*from ww w . j av a 2 s . c o m*/ private PostalStruct tryConstructPostalStruct(ContentValues contentValues) { // adr-value = 0*6(text-value ";") text-value // ; PO Box, Extended Address, Street, Locality, Region, Postal // ; Code, Country Name final String rawPoBox = contentValues.getAsString(StructuredPostal.POBOX); final String rawNeighborhood = contentValues.getAsString(StructuredPostal.NEIGHBORHOOD); final String rawStreet = contentValues.getAsString(StructuredPostal.STREET); final String rawLocality = contentValues.getAsString(StructuredPostal.CITY); final String rawRegion = contentValues.getAsString(StructuredPostal.REGION); final String rawPostalCode = contentValues.getAsString(StructuredPostal.POSTCODE); final String rawCountry = contentValues.getAsString(StructuredPostal.COUNTRY); final String[] rawAddressArray = new String[] { rawPoBox, rawNeighborhood, rawStreet, rawLocality, rawRegion, rawPostalCode, rawCountry }; if (!VCardUtils.areAllEmpty(rawAddressArray)) { final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawAddressArray)); final boolean appendCharset = !VCardUtils.containsOnlyPrintableAscii(rawAddressArray); final String encodedPoBox; final String encodedStreet; final String encodedLocality; final String encodedRegion; final String encodedPostalCode; final String encodedCountry; //final String encodedNeighborhood; final String rawLocality2; // This looks inefficient since we encode rawLocality and rawNeighborhood twice, // but this is intentional. // // QP encoding may add line feeds when needed and the result of // - encodeQuotedPrintable(rawLocality + " " + rawNeighborhood) // may be different from // - encodedLocality + " " + encodedNeighborhood. // // We use safer way. if (TextUtils.isEmpty(rawLocality)) { if (TextUtils.isEmpty(rawNeighborhood)) { rawLocality2 = ""; } else { rawLocality2 = rawNeighborhood; } } else { if (TextUtils.isEmpty(rawNeighborhood)) { rawLocality2 = rawLocality; } else { rawLocality2 = rawLocality + " " + rawNeighborhood; } } if (reallyUseQuotedPrintable) { encodedPoBox = encodeQuotedPrintable(rawPoBox); encodedStreet = encodeQuotedPrintable(rawStreet); encodedLocality = encodeQuotedPrintable(rawLocality2); encodedRegion = encodeQuotedPrintable(rawRegion); encodedPostalCode = encodeQuotedPrintable(rawPostalCode); encodedCountry = encodeQuotedPrintable(rawCountry); } else { encodedPoBox = escapeCharacters(rawPoBox); encodedStreet = escapeCharacters(rawStreet); encodedLocality = escapeCharacters(rawLocality2); encodedRegion = escapeCharacters(rawRegion); encodedPostalCode = escapeCharacters(rawPostalCode); encodedCountry = escapeCharacters(rawCountry); //encodedNeighborhood = escapeCharacters(rawNeighborhood); } final StringBuffer addressBuffer = new StringBuffer(); addressBuffer.append(encodedPoBox); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedStreet); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedLocality); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedRegion); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedPostalCode); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedCountry); return new PostalStruct(reallyUseQuotedPrintable, appendCharset, addressBuffer.toString()); } else { // VCardUtils.areAllEmpty(rawAddressArray) == true // Try to use FORMATTED_ADDRESS instead. final String rawFormattedAddress = contentValues.getAsString(StructuredPostal.FORMATTED_ADDRESS); if (TextUtils.isEmpty(rawFormattedAddress)) { return null; } final boolean reallyUseQuotedPrintable = (mShouldUseQuotedPrintable && !VCardUtils.containsOnlyNonCrLfPrintableAscii(rawFormattedAddress)); final boolean appendCharset = !VCardUtils.containsOnlyPrintableAscii(rawFormattedAddress); final String encodedFormattedAddress; if (reallyUseQuotedPrintable) { encodedFormattedAddress = encodeQuotedPrintable(rawFormattedAddress); } else { encodedFormattedAddress = escapeCharacters(rawFormattedAddress); } // We use the second value ("Extended Address") just because Japanese mobile phones // do so. If the other importer expects the value be in the other field, some flag may // be needed. final StringBuffer addressBuffer = new StringBuffer(); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(encodedFormattedAddress); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); addressBuffer.append(VCARD_ITEM_SEPARATOR); return new PostalStruct(reallyUseQuotedPrintable, appendCharset, addressBuffer.toString()); } }
From source file:android.pim.vcard.VCardBuilder.java
private void appendPostalsForGeneric(final List<ContentValues> contentValuesList) { for (final ContentValues contentValues : contentValuesList) { if (contentValues == null) { continue; }//from www . j av a 2 s . com final Integer typeAsInteger = contentValues.getAsInteger(StructuredPostal.TYPE); final int type = (typeAsInteger != null ? typeAsInteger : DEFAULT_POSTAL_TYPE); final String label = contentValues.getAsString(StructuredPostal.LABEL); final Integer isPrimaryAsInteger = contentValues.getAsInteger(StructuredPostal.IS_PRIMARY); final boolean isPrimary = (isPrimaryAsInteger != null ? (isPrimaryAsInteger > 0) : false); appendPostalLine(type, label, contentValues, isPrimary, false); } }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
@Override public int bulkInsert(final Uri uri, @NonNull final ContentValues[] valuesArray) { try {/* www.j ava 2 s. c om*/ final int tableId = getTableId(uri); final String table = getTableNameById(tableId); checkWritePermission(tableId, table); switch (tableId) { case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: case TABLE_ID_DIRECT_MESSAGES: case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES: return 0; } int result = 0; final long[] newIds = new long[valuesArray.length]; if (table != null) { mDatabaseWrapper.beginTransaction(); if (tableId == TABLE_ID_CACHED_USERS) { for (final ContentValues values : valuesArray) { final Expression where = Expression.equals(CachedUsers.USER_ID, values.getAsLong(CachedUsers.USER_ID)); mDatabaseWrapper.update(table, values, where.getSQL(), null); newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } else if (tableId == TABLE_ID_SEARCH_HISTORY) { for (final ContentValues values : valuesArray) { values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis()); final Expression where = Expression.equalsArgs(SearchHistory.QUERY); final String[] args = { values.getAsString(SearchHistory.QUERY) }; mDatabaseWrapper.update(table, values, where.getSQL(), args); newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE); } } else if (shouldReplaceOnConflict(tableId)) { for (final ContentValues values : valuesArray) { newIds[result++] = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } else { for (final ContentValues values : valuesArray) { newIds[result++] = mDatabaseWrapper.insert(table, null, values); } } mDatabaseWrapper.setTransactionSuccessful(); mDatabaseWrapper.endTransaction(); } if (result > 0) { onDatabaseUpdated(tableId, uri); } onNewItemsInserted(uri, tableId, valuesArray, newIds); return result; } catch (final SQLException e) { Crashlytics.logException(e); throw new IllegalStateException(e); } }