List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:Main.java
/** * Update content./*from w w w . j a v a2s . c o m*/ * * @param context * context * @param sourceUri * source uri * @param file * output file * @return source uri */ public static Uri updateContent(Context context, Uri sourceUri, File file) { long now = System.currentTimeMillis() / MILLISEC_PER_SEC; final ContentValues values = new ContentValues(); values.put(Images.Media.DATE_MODIFIED, now); values.put(Images.Media.DATE_ADDED, now); values.put(Images.Media.SIZE, file.length()); context.getContentResolver().update(sourceUri, values, null, null); return sourceUri; }
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 {/*ww w .ja v a2 s . c om*/ 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:cn.newgxu.android.notty.util.Processor.java
public static ContentValues json2Notice(JSONObject n) { ContentValues v = new ContentValues(); try {/*from ww w . jav a 2 s . co m*/ 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:gxu.software_engineering.market.android.util.Processor.java
public static ContentValues toCategory(JSONObject json) throws JSONException { ContentValues values = new ContentValues(); values.put(C._ID, json.getLong(C.ID)); values.put(C.category.NAME, json.getString(C.category.NAME)); values.put(C.category.EXTRA, json.getString(C.category.EXTRA)); values.put(C.category.ADDED_TIME, json.getLong(C.category.ADDED_TIME)); values.put(C.category.DESCRIPTION, json.getString(C.category.DESCRIPTION)); return values; }
From source file:mx.com.adolfogarcia.popularmovies.data.TestUtilities.java
/** * Returns the values of a row that may be inserted into the movie database. * * @return the values of a row that may be inserted into the movie database. *//*from w w w . j a va 2 s .co m*/ static ContentValues createMadMaxMovieValues() { ContentValues testValues = new ContentValues(); testValues.put(CachedMovieEntry.COLUMN_API_ID, 76341); testValues.put(CachedMovieEntry.COLUMN_BACKDROP_PATH, "/tbhdm8UJAb4ViCTsulYFL3lxMCd.jpg"); testValues.put(CachedMovieEntry.COLUMN_RELEASE_DATE, 1431648000000L); testValues.put(CachedMovieEntry.COLUMN_ORIGINAL_TITLE, "Mad Max: Fury Road"); testValues.put(CachedMovieEntry.COLUMN_OVERVIEW, "An apocalyptic story..."); testValues.put(CachedMovieEntry.COLUMN_POPULARITY, 55.32); testValues.put(CachedMovieEntry.COLUMN_POSTER_PATH, "/kqjL17yufvn9OVLyXYpvtyrFfak.jpg"); testValues.put(CachedMovieEntry.COLUMN_VOTE_AVERAGE, 7.7); testValues.put(CachedMovieEntry.COLUMN_MOST_POPULAR, BooleanUtils.toInteger(true)); testValues.put(CachedMovieEntry.COLUMN_HIGHEST_RATED, BooleanUtils.toInteger(false)); testValues.put(CachedMovieEntry.COLUMN_USER_FAVORITE, BooleanUtils.toInteger(false)); return testValues; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.SharedSecretObj.java
public static byte[] getOrPushSecret(Context context, Contact other) { if (other.secret != null) { return other.secret; }//from w w w . j av a 2 s . com //TODO: this really needs to be refactored into the contentprovider/helpers etc ContentValues values = new ContentValues(); byte[] ss = new byte[32]; random.nextBytes(ss); values.put(Contact.SHARED_SECRET, ss); context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values, "_id=?", new String[] { String.valueOf(other.id) }); Helpers.sendMessage(context, other.id, json(ss), TYPE); return ss; }
From source file:Main.java
public static boolean installRingtone(final Context context, int resid, final String toneName) { String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); String filename = toneName + ".mp3"; File fileAlarms = new File(exStoragePath, "/Notifications"); final File fileTone = new File(fileAlarms, filename); if (fileTone.exists()) return false; boolean exists = fileAlarms.exists(); if (!exists) { fileAlarms.mkdirs();//w w w . j a v a 2 s . com } if (fileTone.exists()) return false; byte[] buffer = null; InputStream fIn = context.getResources().openRawResource(resid); int size = 0; try { size = fIn.available(); buffer = new byte[size]; fIn.read(buffer); fIn.close(); } catch (IOException e) { return false; } FileOutputStream save; try { save = new FileOutputStream(fileTone); save.write(buffer); save.flush(); save.close(); } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } MediaScannerConnection.scanFile(context, new String[] { fileTone.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uriTone) { ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, fileTone.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, toneName); values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, "zom"); //new values.put(MediaStore.Audio.Media.IS_RINGTONE, true); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true); values.put(MediaStore.Audio.Media.IS_ALARM, true); values.put(MediaStore.Audio.Media.IS_MUSIC, false); // Insert it into the database Uri newUri = context.getContentResolver().insert(uriTone, values); // RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri); // Settings.System.putString(context.getContentResolver(), // Settings.System.RINGTONE, uri.toString()); } }); return true; }
From source file:org.muckebox.android.net.RefreshHelper.java
public static Integer refreshTracks(long albumId) { try {//from www. j a v a2 s . c o m ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(1); JSONArray json = ApiHelper.callApiForArray("tracks", null, new String[] { "album" }, new String[] { Long.toString(albumId) }); operations.ensureCapacity(operations.size() + json.length() + 1); operations.add(ContentProviderOperation .newDelete(Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS_ALBUM, Long.toString(albumId))) .build()); for (int j = 0; j < json.length(); ++j) { JSONObject o = json.getJSONObject(j); ContentValues values = new ContentValues(); values.put(TrackEntry.SHORT_ID, o.getInt("id")); values.put(TrackEntry.SHORT_ARTIST_ID, o.getInt("artist_id")); values.put(TrackEntry.SHORT_ALBUM_ID, o.getInt("album_id")); values.put(TrackEntry.SHORT_TITLE, o.getString("title")); if (!o.isNull("tracknumber")) values.put(TrackEntry.SHORT_TRACKNUMBER, o.getInt("tracknumber")); if (!o.isNull("discnumber")) values.put(TrackEntry.SHORT_DISCNUMBER, o.getInt("discnumber")); values.put(TrackEntry.SHORT_LABEL, o.getString("label")); values.put(TrackEntry.SHORT_CATALOGNUMBER, o.getString("catalognumber")); values.put(TrackEntry.SHORT_LENGTH, o.getInt("length")); values.put(TrackEntry.SHORT_DATE, o.getString("date")); operations.add(ContentProviderOperation .newDelete( Uri.withAppendedPath(MuckeboxProvider.URI_TRACKS, Integer.toString(o.getInt("id")))) .build()); operations.add( ContentProviderOperation.newInsert(MuckeboxProvider.URI_TRACKS).withValues(values).build()); } Log.d(LOG_TAG, "Got " + json.length() + " Tracks"); Muckebox.getAppContext().getContentResolver().applyBatch(MuckeboxProvider.AUTHORITY, operations); } catch (AuthenticationException e) { return R.string.error_authentication; } catch (SSLException e) { return R.string.error_ssl; } catch (IOException e) { Log.d(LOG_TAG, "IOException: " + e.getMessage()); return R.string.error_reload_tracks; } catch (JSONException e) { return R.string.error_json; } catch (RemoteException e) { e.printStackTrace(); return R.string.error_reload_tracks; } catch (OperationApplicationException e) { e.printStackTrace(); return R.string.error_reload_tracks; } return null; }
From source file:DictionaryDatabase.java
public long addRecord(String word, String definition) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FIELD_WORD, word);/*w ww . j a va 2s . c om*/ values.put(FIELD_DEFINITION, definition); return db.insert(TABLE_DICTIONARY, null, values); }
From source file:gxu.software_engineering.market.android.util.Processor.java
public static ContentValues toUser(JSONObject json) throws JSONException { ContentValues values = new ContentValues(); values.put(C._ID, json.getLong(C.ID)); values.put(C.user.ACCOUNT, json.getString(C.user.ACCOUNT)); values.put(C.user.CONTACT, json.getString(C.user.CONTACT)); values.put(C.user.LAST_LOGIN_TIME, json.getLong(C.user.LAST_LOGIN_TIME)); values.put(C.user.LOGIN_TIMES, json.getLong(C.user.LOGIN_TIMES)); values.put(C.user.REAL_NAME, json.getString(C.user.REAL_NAME)); values.put(C.user.NICK, json.getString(C.user.NICK)); values.put(C.user.REGISTER_TIME, json.getLong(C.user.REGISTER_TIME)); return values; }