List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:Main.java
/** * Store a picture that has just been saved to disk in the MediaStore. * // w w w . j a v a 2s.c o m * @param imageFile * The File of the picture * @return The Uri provided by the MediaStore. */ public static Uri storePicture(Context ctx, File imageFile, String imageName) { ContentResolver cr = ctx.getContentResolver(); imageName = imageName.substring(imageName.lastIndexOf('/') + 1); ContentValues values = new ContentValues(7); values.put(Images.Media.TITLE, imageName); values.put(Images.Media.DISPLAY_NAME, imageName); values.put(Images.Media.DESCRIPTION, ""); values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, "image/jpeg"); values.put(Images.Media.ORIENTATION, 0); File parentFile = imageFile.getParentFile(); String path = parentFile.toString().toLowerCase(); String name = parentFile.getName().toLowerCase(); values.put(Images.ImageColumns.BUCKET_ID, path.hashCode()); values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name); values.put("_data", imageFile.toString()); Uri uri = cr.insert(sStorageURI, values); return uri; }
From source file:Main.java
/** * A copy of the Android internals StoreThumbnail method, it used with the insertImage to * populate the android.provider.MediaStore.Images.Media#insertImage with all the correct * meta data. The StoreThumbnail method is private so it must be duplicated here. * @see android.provider.MediaStore.Images.Media (StoreThumbnail private method) *//*from w ww .ja v a 2 s. c om*/ private static final Bitmap storeThumbnail(ContentResolver cr, Bitmap source, long id, float width, float height, int kind) { // create the matrix to scale it Matrix matrix = new Matrix(); float scaleX = width / source.getWidth(); float scaleY = height / source.getHeight(); matrix.setScale(scaleX, scaleY); Bitmap thumb = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); ContentValues values = new ContentValues(4); values.put(MediaStore.Images.Thumbnails.KIND, kind); values.put(MediaStore.Images.Thumbnails.IMAGE_ID, (int) id); values.put(MediaStore.Images.Thumbnails.HEIGHT, thumb.getHeight()); values.put(MediaStore.Images.Thumbnails.WIDTH, thumb.getWidth()); Uri url = cr.insert(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, values); try { OutputStream thumbOut = cr.openOutputStream(url); thumb.compress(Bitmap.CompressFormat.JPEG, 100, thumbOut); thumbOut.close(); return thumb; } catch (FileNotFoundException ex) { return null; } catch (IOException ex) { return null; } }
From source file:io.trigger.forge.android.modules.contprov.API.java
public static void stickEmployeeInThere(final ForgeTask task, @ForgeParam("name") final String name, @ForgeParam("status") final String status) { try {/* w w w .ja va2 s .co m*/ ContentValues cv = new ContentValues(); cv.put(MyContentDescriptor.Categories.Cols.key_2_catname, name); cv.put(MyContentDescriptor.Categories.Cols.key_3_catstatus, status); resolver.insert(URI, cv); task.success(); } catch (Exception e) { task.error(e); } }
From source file:Main.java
public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime, long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) { ContentResolver cr = activityObj.getContentResolver(); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startTime); values.put(Events.DTEND, endTime);//from w w w. ja va 2 s . c o m values.put(Events.TITLE, title); values.put(Events.DESCRIPTION, description); values.put(Events.CALENDAR_ID, calendarId); if (allDay == 1) { values.put(Events.ALL_DAY, true); } if (hasAlarm == 1) { values.put(Events.HAS_ALARM, true); } //Get current timezone values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID()); Uri uri = cr.insert(Events.CONTENT_URI, values); Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString()); // get the event ID that is the last element in the Uri long eventID = Long.parseLong(uri.getLastPathSegment()); if (hasAlarm == 1) { ContentValues reminders = new ContentValues(); reminders.put(Reminders.EVENT_ID, eventID); reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT); reminders.put(Reminders.MINUTES, selectedReminderValue); Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders); } }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID.//from w w w. j a v a 2 s. c o m */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:cn.newgxu.android.notty.util.Processor.java
public static ContentValues json2User(JSONObject u) { ContentValues v = new ContentValues(); try {//from w ww . j a v a2s . co m v.put(C._ID, u.getLong(C.ID)); v.put(C.user.ABOUT, u.getString(C.user.ABOUT)); v.put(C.user.AUTHED_NAME, u.getString(C.user.AUTHED_NAME)); v.put(C.user.CONTACT, u.getString(C.user.CONTACT)); v.put(C.user.JOIN_TIME, u.getLong(C.user.JOIN_TIME)); v.put(C.user.ORG, u.getString(C.user.ORG)); } catch (JSONException e) { throw new RuntimeException("resolve json wrong -> " + u); } return v; }
From source file:cn.newgxu.android.notty.util.Processor.java
public static ContentValues json2Notice(JSONObject n) { ContentValues v = new ContentValues(); try {/*from w w w . ja va 2 s. c om*/ v.put(C._ID, n.getLong(C.ID)); v.put(C.notice.ADDED_DATE, n.getLong(C.notice.ADDED_DATE)); v.put(C.notice.CLICK_TIMES, n.getInt(C.notice.CLICK_TIMES)); v.put(C.notice.CONTENT, n.getString(C.notice.CONTENT)); v.put(C.notice.DOC_NAME, n.getString(C.notice.DOC_NAME)); v.put(C.notice.DOC_URL, n.getString(C.notice.DOC_URL)); v.put(C.notice.LAST_MODIFIED_DATE, n.getLong(C.notice.LAST_MODIFIED_DATE)); v.put(C.notice.TITLE, n.getString(C.notice.TITLE)); JSONObject u = n.getJSONObject(C.USER); v.put(C.notice.USER_ID, u.getLong(C.ID)); v.put(C.notice.USER_NAME, u.getString(C.user.AUTHED_NAME)); } catch (JSONException e) { throw new RuntimeException("resolve json wrong -> " + n); } return v; }
From source file:Main.java
/** * Put an arbitrary object into a {@link ContentValues} *///w w w. j a v a 2 s .co m public static void putInto(ContentValues target, String key, Object value) { if (value instanceof Boolean) { target.put(key, (Boolean) value); } else if (value instanceof Byte) { target.put(key, (Byte) value); } else if (value instanceof Double) { target.put(key, (Double) value); } else if (value instanceof Float) { target.put(key, (Float) value); } else if (value instanceof Integer) { target.put(key, (Integer) value); } else if (value instanceof Long) { target.put(key, (Long) value); } else if (value instanceof Short) { target.put(key, (Short) value); } else if (value instanceof String) { target.put(key, (String) value); } else { throw new UnsupportedOperationException("Could not handle type " + //$NON-NLS-1$ value.getClass()); } }
From source file:Main.java
public static ContentValues getContentValuesFromWeatherDataMap(HashMap<String, String> weatherDataMap) { if (weatherDataMap == null) return null; ContentValues contentValues = new ContentValues(); for (Map.Entry<String, String> entry : weatherDataMap.entrySet()) { contentValues.put(entry.getKey(), entry.getValue()); }// ww w . j a v a2s . c o m return contentValues; }
From source file:Main.java
private static void insertClientToWedding(SQLiteDatabase db, String nameClient, boolean weddingType, long weddingDate, String weddingPlace, String groomFullName, String groomPhone, String groomSoc, String brideFullName, String bridePhone, String brideSoc, int weddingBegin, int weddingEnd, String weddingMeet, int visaj, int visArr, int barber, int barberArr, int videoOp, int vidArr, int groomArr, String zagsName, int zagsFillTime, String walkDesc, String walkPlace, String banketPlace, int banketBegin, String wit1, String wit1Soc, String wit2, String wit2Soc, int photoAuthorCount, String photoFormat, String photoBook, int photoBookSize, int pbookTurns, int weddingCost, int garant, long dateOfPact, String weddingNote) { ContentValues cv = new ContentValues(); cv.put("NAME", nameClient); cv.put("WEDDING_TYPE", weddingType); cv.put("WEDDING_DATE", weddingDate); cv.put("WEDDING_DATE_STRING", new SimpleDateFormat("dd MMM yy E", Locale.getDefault()).format(new Date(weddingDate))); cv.put("WEDDING_PLACE", weddingPlace); cv.put("WEDDING_GROOM", groomFullName); cv.put("WEDDING_GROOM_PHONE", groomPhone); cv.put("WEDDING_GROOM_SOC", groomSoc); cv.put("WEDDING_BRIDE", brideFullName); cv.put("WEDDING_BRIDE_PHONE", bridePhone); cv.put("WEDDING_BRIDE_SOC", brideSoc); cv.put("WEDDING_BEGIN", weddingBegin); cv.put("WEDDING_END", weddingEnd); cv.put("WEDDING_MEET", weddingMeet); cv.put("WEDDING_VIS", visaj); cv.put("WEDDING_VIS_ARR", visArr); cv.put("WEDDING_BARBER", barber); cv.put("WEDDING_BARBER_ARR", barberArr); cv.put("WEDDING_CAMOP", videoOp); cv.put("WEDDING_CAMOP_ARR", vidArr); cv.put("WEDDING_GROOM_ARR", groomArr); cv.put("WEDDING_ZAGS", zagsName); cv.put("WEDDING_ZAGS_FILLTIME", zagsFillTime); cv.put("WEDDING_WALK", walkDesc); cv.put("WEDDING_WALK_PLACE", walkPlace); cv.put("WEDDING_BANKET_PLACE", banketPlace); cv.put("WEDDING_BANKET_START", banketBegin); cv.put("WEDDING_WIT1", wit1); cv.put("WEDDING_WIT1_SOC", wit1Soc); cv.put("WEDDING_WIT2", wit2); cv.put("WEDDING_WIT2_SOC", wit2Soc); cv.put("WEDDING_PHOT_AUT", photoAuthorCount); cv.put("WEDDING_PHOT_FORMAT", photoFormat); cv.put("WEDDING_PHOT_BOOK", photoBook); cv.put("WEDDING_PBOOK_SIZE", photoBookSize); cv.put("WEDDING_PBOOK_TURNS", pbookTurns); cv.put("WEDDING_COST", weddingCost); cv.put("WEDDING_GARANT", garant); cv.put("WEDDING_PACT_DATE", dateOfPact); cv.put("WEDDING_NOTE", weddingNote); db.insert("WEDDING", null, cv); }