List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:Main.java
public static void shiftTableIdsExceptWhen(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, long topTableId, String exceptionColumn, String exceptionValue) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations || null == exceptionValue) { return;/* w w w .j ava 2s .co m*/ } for (ContentValues restoreCv : restoreOperations) { if (!exceptionValue.equals(restoreCv.getAsString(exceptionColumn))) { restoreCv.put(idColumnName, restoreCv.getAsLong(idColumnName) + topTableId); } } }
From source file:Main.java
public static ArrayList<ContentValues> removeEntriesWhenEquals( HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, String compareValue) {/*from w w w. j a va2s . c o m*/ ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations || null == compareValue) { return null; } ArrayList<ContentValues> removeOperations = new ArrayList<ContentValues>(); for (ContentValues restoreCv : restoreOperations) { if (restoreCv.containsKey(idColumnName) && compareValue.equals(restoreCv.getAsString(idColumnName))) { removeOperations.add(restoreCv); } } for (ContentValues removeCv : removeOperations) { restoreOperations.remove(removeCv); } return removeOperations; }
From source file:Main.java
public static void shiftTableUriIds(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, String authority, String path, long topTableId) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations) { return;//from ww w . jav a 2 s . c o m } for (ContentValues restoreCv : restoreOperations) { if (restoreCv.containsKey(idColumnName) && null != restoreCv.getAsString(idColumnName)) { Uri uri = Uri.parse(restoreCv.getAsString(idColumnName)); if ("content".equalsIgnoreCase(uri.getScheme()) && authority.equals(uri.getAuthority()) && uri.getPath().substring(0, uri.getPath().lastIndexOf('/')).equals(path)) { Uri.Builder newUri = uri.buildUpon() .path(uri.getPath().substring(0, uri.getPath().lastIndexOf('/'))) .appendPath(String.valueOf( Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1)) + topTableId)); // Log.v("URI", uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)); // Log.v("URI", String.valueOf(Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)) + topTableId)); restoreCv.put(idColumnName, newUri.build().toString()); } } } }
From source file:Main.java
public static String logContentValue(String prefix, ContentValues cv) { StringBuilder sb = new StringBuilder().append(prefix + ": "); for (String key : cv.keySet()) sb.append(key).append("=").append(cv.getAsString(key)).append(" "); return sb.toString(); }
From source file:Main.java
/** * Returns String[] containing address information based on vCard spec * (PO Box, Extended Address, Street, Locality, Region, Postal Code, Country Name). * All String objects are non-null ("" is used when the relevant data is empty). * //from w ww . j a v a 2 s.c om * Note that the data structure of ContactsContract is different from that defined in vCard. * So some conversion may be performed in this method. See also * {{@link #insertStructuredPostalDataUsingContactsStruct(int, * android.content.ContentProviderOperation.Builder, * android.pim.vcard.ContactStruct.PostalData)} */ public static String[] getVCardPostalElements(ContentValues contentValues) { String[] dataArray = new String[7]; dataArray[0] = contentValues.getAsString(StructuredPostal.POBOX); if (dataArray[0] == null) { dataArray[0] = ""; } // Extended addr. There's no relevant data in ContactsContract. dataArray[1] = ""; dataArray[2] = contentValues.getAsString(StructuredPostal.STREET); if (dataArray[2] == null) { dataArray[2] = ""; } // Assume that localty == city dataArray[3] = contentValues.getAsString(StructuredPostal.CITY); if (dataArray[3] == null) { dataArray[3] = ""; } String region = contentValues.getAsString(StructuredPostal.REGION); if (!TextUtils.isEmpty(region)) { dataArray[4] = region; } else { dataArray[4] = ""; } dataArray[5] = contentValues.getAsString(StructuredPostal.POSTCODE); if (dataArray[5] == null) { dataArray[5] = ""; } dataArray[6] = contentValues.getAsString(StructuredPostal.COUNTRY); if (dataArray[6] == null) { dataArray[6] = ""; } return dataArray; }
From source file:at.bitfire.davdroid.model.CollectionInfo.java
public static CollectionInfo fromDB(ContentValues values) { CollectionInfo info = new CollectionInfo(); info.id = values.getAsLong(Collections.ID); info.serviceID = values.getAsLong(Collections.SERVICE_ID); info.url = values.getAsString(Collections.URL); info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0; info.displayName = values.getAsString(Collections.DISPLAY_NAME); info.description = values.getAsString(Collections.DESCRIPTION); info.color = values.getAsInteger(Collections.COLOR); info.timeZone = values.getAsString(Collections.TIME_ZONE); info.supportsVEVENT = getAsBooleanOrNull(values, Collections.SUPPORTS_VEVENT); info.supportsVTODO = getAsBooleanOrNull(values, Collections.SUPPORTS_VTODO); info.selected = values.getAsInteger(Collections.SYNC) != 0; return info;/*ww w.jav a2s. c o m*/ }
From source file:Main.java
public static void addCallLog(Context context, ContentValues values, ContentValues extraValues) { ContentResolver contentResolver = context.getContentResolver(); Uri result = contentResolver.insert(CallLog.Calls.CONTENT_URI, values); if (result != null) { // Announce that to other apps final Intent broadcast = new Intent(ACTION_ANNOUNCE_SIP_CALLLOG); broadcast.putExtra(EXTRA_CALL_LOG_URI, result.toString()); String provider = extraValues.getAsString(EXTRA_SIP_PROVIDER); if (provider != null) { broadcast.putExtra(EXTRA_SIP_PROVIDER, provider); }/*from w ww .j ava2s. co m*/ context.sendBroadcast(broadcast); } }
From source file:com.github.michalbednarski.intentslab.Utils.java
public static JSONObject contentValuesToJsonObject(ContentValues contentValues) throws JSONException { if (contentValues == null) { return null; }//from w ww . ja v a 2s . c om JSONObject jsonObject = new JSONObject(); for (String key : getKeySet(contentValues)) { jsonObject.put(key, contentValues.getAsString(key)); } return jsonObject; }
From source file:com.android.browser.FetchUrlMimeType.java
@Override public void onPostExecute(ContentValues values) { final String mimeType = values.getAsString("Content-Type"); final String contentDisposition = values.getAsString("Content-Disposition"); if (mimeType != null) { String url = mValues.getAsString(Downloads.Impl.COLUMN_URI); if (mimeType.equalsIgnoreCase("text/plain") || mimeType.equalsIgnoreCase("application/octet-stream")) { String newMimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)); if (newMimeType != null) { mValues.put(Downloads.Impl.COLUMN_MIME_TYPE, newMimeType); }/*from w w w. j a va2 s .co m*/ } String filename = URLUtil.guessFileName(url, contentDisposition, mimeType); mValues.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename); } // Start the download final Uri contentUri = mActivity.getContentResolver().insert(Downloads.Impl.CONTENT_URI, mValues); }
From source file:com.partypoker.poker.engagement.reach.EngagementAbstractAnnouncement.java
/** * Parse an announcement.// w w w. j a va2s . c om * @param campaignId already parsed campaign id. * @param values campaign data. * @param params special parameters to inject in the action URL of the announcement. * @throws JSONException if a parsing error occurs. */ EngagementAbstractAnnouncement(com.microsoft.azure.engagement.reach.CampaignId campaignId, ContentValues values, Map<String, String> params) throws JSONException { super(campaignId, values); String actionURL = values.getAsString(ACTION_URL); for (Map.Entry<String, String> param : params.entrySet()) { if (actionURL != null) actionURL = actionURL.replace(param.getKey(), param.getValue()); } mActionURL = actionURL; }