List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
@SuppressLint("InlinedApi") public static void create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info) throws LocalStorageException { ContentProviderClient client = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY); if (client == null) throw new LocalStorageException("No Calendar Provider found (Calendar app disabled?)"); int color = 0xFFC3EA6E; // fallback: "DAVdroid green" if (info.getColor() != null) { Pattern p = Pattern.compile("#(\\p{XDigit}{6})(\\p{XDigit}{2})?"); Matcher m = p.matcher(info.getColor()); if (m.find()) { int color_rgb = Integer.parseInt(m.group(1), 16); int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF; color = (color_alpha << 24) | color_rgb; }//from ww w . j a v a2 s . c o m } ContentValues values = new ContentValues(); values.put(Calendars.ACCOUNT_NAME, account.name); values.put(Calendars.ACCOUNT_TYPE, account.type); values.put(Calendars.NAME, info.getURL()); values.put(Calendars.CALENDAR_DISPLAY_NAME, info.getTitle()); values.put(Calendars.CALENDAR_COLOR, color); values.put(Calendars.OWNER_ACCOUNT, account.name); values.put(Calendars.SYNC_EVENTS, 1); values.put(Calendars.VISIBLE, 1); values.put(Calendars.ALLOWED_REMINDERS, Reminders.METHOD_ALERT); if (info.isReadOnly()) values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); else { values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER); values.put(Calendars.CAN_ORGANIZER_RESPOND, 1); values.put(Calendars.CAN_MODIFY_TIME_ZONE, 1); } if (android.os.Build.VERSION.SDK_INT >= 15) { values.put(Calendars.ALLOWED_AVAILABILITY, Events.AVAILABILITY_BUSY + "," + Events.AVAILABILITY_FREE + "," + Events.AVAILABILITY_TENTATIVE); values.put(Calendars.ALLOWED_ATTENDEE_TYPES, Attendees.TYPE_NONE + "," + Attendees.TYPE_OPTIONAL + "," + Attendees.TYPE_REQUIRED + "," + Attendees.TYPE_RESOURCE); } if (info.getTimezone() != null) values.put(Calendars.CALENDAR_TIME_ZONE, info.getTimezone()); Log.i(TAG, "Inserting calendar: " + values.toString() + " -> " + calendarsURI(account).toString()); try { client.insert(calendarsURI(account), values); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static long ensureGroupExists(Context context, Account account) { final ContentResolver resolver = context.getContentResolver(); // Lookup the group long groupId = 0; final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[] { Groups._ID }, Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " + Groups.TITLE + "=?", new String[] { account.name, account.type, GROUP_NAME }, null); if (cursor != null) { try {/*from w ww . ja v a 2 s .co m*/ if (cursor.moveToFirst()) { groupId = cursor.getLong(0); } } finally { cursor.close(); } } if (groupId == 0) { // Group doesn't exist yet, so create it final ContentValues contentValues = new ContentValues(); contentValues.put(Groups.ACCOUNT_NAME, account.name); contentValues.put(Groups.ACCOUNT_TYPE, account.type); contentValues.put(Groups.TITLE, GROUP_NAME); // contentValues.put(Groups.GROUP_IS_READ_ONLY, true); contentValues.put(Groups.GROUP_VISIBLE, true); final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI, contentValues); groupId = ContentUris.parseId(newGroupUri); } return groupId; }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Parses and stores the JSON data in the TMDbContentProvider * @param jsonDataArray An array of raw JSON strings * @throws JSONException/*from www .ja v a 2s .c o m*/ */ private static void storeJsonReviews(String[] jsonDataArray, Context context) throws JSONException { ArrayList<ContentValues> contentValuesArrayList = new ArrayList<ContentValues>(40); for (String dataJSON : jsonDataArray) { try { JSONObject reviewsJSON = new JSONObject(dataJSON); JSONArray results = reviewsJSON.getJSONArray("results"); int movieId = reviewsJSON.getInt(TMDbContract.Movies.MOVIE_ID); int resultLength = results.length(); ContentValues value; for (int i = 0; i < resultLength; i++) { JSONObject movie = results.getJSONObject(i); value = new ContentValues(); value.put(TMDbContract.Reviews.AUTHOR, movie.getString(TMDbContract.Reviews.AUTHOR)); value.put(TMDbContract.Reviews.REVIEW_CONTENT, movie.getString(TMDbContract.Reviews.REVIEW_CONTENT)); value.put(TMDbContract.Reviews.REVIEW_ID, movie.getString(TMDbContract.Reviews.REVIEW_ID)); value.put(TMDbContract.Reviews.MOVIE_IDS, movieId); contentValuesArrayList.add(value); } } catch (JSONException e) { Log.d(TAG, e.getMessage(), e); e.printStackTrace(); } } ContentResolver contentResolver = context.getContentResolver(); ContentValues[] contentValues = new ContentValues[contentValuesArrayList.size()]; contentValues = contentValuesArrayList.toArray(contentValues); int numInserted = contentResolver.bulkInsert(TMDbContract.Reviews.URI, contentValues); if (numInserted != contentValues.length) { Log.e(TAG, "Not all of the result were inserted.\n Amount inserted: " + numInserted + "\nAmount from server: " + contentValues.length); } }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Parses and stores the JSON data in the TMDbContentProvider * @param jsonDataArray An array of raw JSON strings * @throws JSONException//www . j av a 2s . c o m */ private static void storeJsonVideos(String[] jsonDataArray, Context context) throws JSONException { ArrayList<ContentValues> contentValuesArrayList = new ArrayList<ContentValues>(40); for (String dataJSON : jsonDataArray) { try { JSONObject videosJSON = new JSONObject(dataJSON); JSONArray results = videosJSON.getJSONArray("results"); int movieId = videosJSON.getInt(TMDbContract.Movies.MOVIE_ID); int resultLength = results.length(); ContentValues values; for (int i = 0; i < resultLength; i++) { JSONObject video = results.getJSONObject(i); values = new ContentValues(); values.put(TMDbContract.Videos.NAME, video.getString(TMDbContract.Videos.NAME)); values.put(TMDbContract.Videos.KEY, video.getString(TMDbContract.Videos.KEY)); //TODO check what type of video and store the associated value (see contract) values.put(TMDbContract.Videos.TYPE, 0); values.put(TMDbContract.Videos.VIDEO_ID, video.getString(TMDbContract.Videos.VIDEO_ID)); values.put(TMDbContract.Videos.MOVIE_IDS, movieId); String printdata = video.getString(TMDbContract.Videos.VIDEO_ID); Log.d(TAG, "videoID " + printdata); contentValuesArrayList.add(values); } } catch (JSONException e) { Log.d(TAG, e.getMessage(), e); e.printStackTrace(); } } ContentResolver contentResolver = context.getContentResolver(); ContentValues[] contentValues = new ContentValues[contentValuesArrayList.size()]; contentValues = contentValuesArrayList.toArray(contentValues); int numInserted = contentResolver.bulkInsert(TMDbContract.Videos.URI, contentValues); if (numInserted != contentValues.length) { Log.e(TAG, "Not all of the result were inserted.\n Amount inserted: " + numInserted + "\nAmount from server: " + contentValues.length); } }
From source file:com.android.email.LegacyConversions.java
/** * Save the body part of a single attachment, to a file in the attachments directory. *//*from www .j a v a 2s. c om*/ public static void saveAttachmentBody(Context context, Part part, Attachment localAttachment, long accountId) throws MessagingException, IOException { if (part.getBody() != null) { long attachmentId = localAttachment.mId; InputStream in = part.getBody().getInputStream(); File saveIn = AttachmentProvider.getAttachmentDirectory(context, accountId); if (!saveIn.exists()) { saveIn.mkdirs(); } File saveAs = AttachmentProvider.getAttachmentFilename(context, accountId, attachmentId); saveAs.createNewFile(); FileOutputStream out = new FileOutputStream(saveAs); long copySize = IOUtils.copy(in, out); in.close(); out.close(); // update the attachment with the extra information we now know String contentUriString = AttachmentProvider.getAttachmentUri(accountId, attachmentId).toString(); localAttachment.mSize = copySize; localAttachment.mContentUri = contentUriString; // update the attachment in the database as well ContentValues cv = new ContentValues(); cv.put(AttachmentColumns.SIZE, copySize); cv.put(AttachmentColumns.CONTENT_URI, contentUriString); Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId); context.getContentResolver().update(uri, cv, null, null); } }
From source file:com.tct.email.LegacyConversions.java
/** * Save the body part of a single attachment, to a file in the attachments directory. *//*from w ww . ja v a2s.c o m*/ public static void saveAttachmentBody(final Context context, final Part part, final Attachment localAttachment, long accountId) throws MessagingException, IOException { if (part.getBody() != null) { final long attachmentId = localAttachment.mId; final File saveIn = AttachmentUtilities.getAttachmentDirectory(context, accountId); if (!saveIn.isDirectory() && !saveIn.mkdirs()) { throw new IOException("Could not create attachment directory"); } final File saveAs = AttachmentUtilities.getAttachmentFilename(context, accountId, attachmentId); InputStream in = null; FileOutputStream out = null; final long copySize; try { in = part.getBody().getInputStream(); out = new FileOutputStream(saveAs); copySize = IOUtils.copyLarge(in, out); //TS: Gantao 2016-02-18 EMAIL BUGFIX_1595378 ADD_S } catch (MessagingException me) { LogUtils.e(LogUtils.TAG, "Get the attachment %d failed", attachmentId); deleteDirtyAttachment(context, attachmentId); return; //TS: Gantao 2016-02-18 EMAIL BUGFIX_1595378 ADD_E } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } // update the attachment with the extra information we now know final String contentUriString = AttachmentUtilities.getAttachmentUri(accountId, attachmentId) .toString(); localAttachment.mSize = copySize; localAttachment.setContentUri(contentUriString); // update the attachment in the database as well final ContentValues cv = new ContentValues(3); cv.put(AttachmentColumns.SIZE, copySize); cv.put(AttachmentColumns.CONTENT_URI, contentUriString); cv.put(AttachmentColumns.UI_STATE, UIProvider.AttachmentState.SAVED); final Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId); context.getContentResolver().update(uri, cv, null, null); } //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_S else { String contentUriString = AttachmentUtilities.getAttachmentUri(accountId, localAttachment.mId) .toString(); localAttachment.setContentUri(contentUriString); } //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_E }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static void setIsCached(String resourcePath, boolean isCached) { ContentValues values = new ContentValues(2); values.put(Nodes.NODE_RESOURCE_PATH, resourcePath); values.put(Nodes.NODE_IS_CACHED, isCached); String where = Nodes.NODE_RESOURCE_PATH + "=?"; String[] selectionArgs = new String[] { resourcePath }; sResolver.update(Nodes.CONTENT_URI, values, where, selectionArgs); sResolver.notifyChange(Nodes.CONTENT_URI, null); }
From source file:com.mail163.email.LegacyConversions.java
/** * Save the body part of a single attachment, to a file in the attachments directory. *//*from w ww. j a v a 2 s . co m*/ public static void saveAttachmentBody(Context context, Part part, Attachment localAttachment, long accountId) throws MessagingException, IOException { if (part.getBody() != null) { long attachmentId = localAttachment.mId; InputStream in = part.getBody().getInputStream(); File saveIn = AttachmentProvider.getAttachmentDirectory(context, accountId); if (!saveIn.exists()) { saveIn.mkdirs(); } File saveAs = AttachmentProvider.getAttachmentFilename(context, accountId, attachmentId); saveAs.createNewFile(); FileOutputStream out = new FileOutputStream(saveAs); long copySize = IOUtils.copy(in, out); in.close(); out.close(); // update the attachment with the extra information we now know String contentUriString = AttachmentProvider.getAttachmentUri(accountId, attachmentId).toString(); localAttachment.mSize = copySize; localAttachment.mContentUri = contentUriString; // update the attachment in the database as well ContentValues cv = new ContentValues(); cv.put(AttachmentColumns.SIZE, copySize); cv.put(AttachmentColumns.CONTENT_URI, contentUriString); // cv.put(AttachmentColumns.MIME_TYPE, "image/png"); Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachmentId); context.getContentResolver().update(uri, cv, null, null); } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static void updateLongField(String resourcePath, String column, Long value) { final String[] selectionArgs = new String[] { resourcePath }; final ContentValues values = new ContentValues(); values.put(column, value); sResolver.update(Nodes.CONTENT_URI, values, sSelection, selectionArgs); }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static void updateStringField(String resourcePath, String column, String value) { final String[] selectionArgs = new String[] { resourcePath }; final ContentValues values = new ContentValues(); values.put(column, value); sResolver.update(Nodes.CONTENT_URI, values, sSelection, selectionArgs); }