List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.stockita.popularmovie.utility.Utilities.java
/** * Parse and insert cast names and pictures into CreditEntry table //from w ww . ja v a 2s . c o m */ public static void parseAndInsertCredits(Context context, String jsonData, String id) throws JSONException { // Timestamp. final long currentTime = System.currentTimeMillis(); // String to the root of JSONObject, the argument s is a String in JSON format. JSONObject rootObject = new JSONObject(jsonData); // call the rootObjet and get the key assign to String variable String rootObj = rootObject.get("cast").toString(); // now the rootObj has the value of "cast" which is a JSON Array // then assign it as argument into JSONArray object JSONArray ar = new JSONArray(rootObj); final int arSize = ar.length(); // Containers ContentValues lContentValueCredits = new ContentValues(); // iterate for each element in the JSONArray for (int i = 0; i < arSize; i++) { // convert each element in ar into JSONOject // and pass the argument i which i is the index of each element JSONObject obj = ar.getJSONObject(i); // Packing into ContentValues object lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_MOVIE_ID, String.valueOf(id)); lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_CAST_ID, obj.getString("cast_id")); lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_CHARACTER, obj.getString("character")); lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_NAME, obj.getString("name")); lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_PROFILE_PATH, obj.getString("profile_path")); lContentValueCredits.put(ContractMovies.CreditEntry.COLUMN_POSTING_TIME, currentTime); // Do insert now try { context.getContentResolver().insert(ContractMovies.CreditEntry.CONTENT_URI, lContentValueCredits); } catch (Exception e) { Log.e(LOG_TAG, e.toString()); } } }
From source file:com.fanfou.app.opensource.api.bean.Photo.java
@Override public ContentValues toContentValues() { final ContentValues cv = new ContentValues(); cv.put("id", this.id); cv.put("createdAt", this.createdAt.getTime()); cv.put("imageUrl", this.imageUrl); cv.put("thumbUrl", this.thumbUrl); cv.put("largeUrl", this.largeUrl); return cv;// ww w. java2 s .c o m }
From source file:android.database.DatabaseUtils.java
/** * Reads a String out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The TEXT field to read/*from ww w. j a va 2s. co m*/ * @param values The {@link ContentValues} to put the value into, with the field as the key * @param key The key to store the value with in the map */ public static void cursorStringToContentValues(Cursor cursor, String field, ContentValues values, String key) { values.put(key, cursor.getString(cursor.getColumnIndexOrThrow(field))); }
From source file:com.android.erowser.DownloadTouchIcon.java
@Override public void onPostExecute(Bitmap icon) { // Do this first in case the download failed. if (mActivity != null) { // Remove the touch icon loader from the ErowserActivity. mActivity.mTouchIconLoader = null; }// w w w.j a va 2 s . c o m if (icon == null || mCursor == null || isCancelled()) { return; } final ByteArrayOutputStream os = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.PNG, 100, os); ContentValues values = new ContentValues(); values.put(ErowserP.BookmarkColumns.TOUCH_ICON, os.toByteArray()); if (mCursor.moveToFirst()) { do { mContentResolver.update(ContentUris.withAppendedId(ErowserP.BOOKMARKS_URI, mCursor.getInt(0)), values, null, null); } while (mCursor.moveToNext()); } mCursor.close(); }
From source file:com.android.browser.DownloadTouchIcon.java
private void storeIcon(Bitmap icon) { // Do this first in case the download failed. if (mTab != null) { // Remove the touch icon loader from the BrowserActivity. mTab.mTouchIconLoader = null;/*w ww . ja v a 2 s.c o m*/ } if (icon == null || mCursor == null || isCancelled()) { return; } final ByteArrayOutputStream os = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.PNG, 100, os); ContentValues values = new ContentValues(); values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray()); if (mCursor.moveToFirst()) { do { mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)), values, null, null); } while (mCursor.moveToNext()); } }
From source file:com.android.browser.kai.DownloadTouchIcon.java
@Override public void onPostExecute(Bitmap icon) { // Do this first in case the download failed. if (mActivity != null) { // Remove the touch icon loader from the BrowserActivity. mActivity.mTouchIconLoader = null; }/* ww w .java 2 s. c om*/ if (icon == null || mCursor == null || isCancelled()) { return; } final ByteArrayOutputStream os = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.PNG, 100, os); ContentValues values = new ContentValues(); values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray()); if (mCursor.moveToFirst()) { do { mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)), values, null, null); } while (mCursor.moveToNext()); } mCursor.close(); }
From source file:com.csipsimple.utils.SipProfileJson.java
private static boolean restoreSipProfile(Context ctxt, JSONObject jsonObj, DBAdapter db) { //Restore accounts Columns cols;//from w w w. j a v a 2 s.co m ContentValues cv; cols = new Columns(SipProfile.full_projection, SipProfile.full_projection_types); cv = cols.jsonToContentValues(jsonObj); SipProfile profile = new SipProfile(); profile.createFromContentValue(cv); if (profile.id >= 0) { db.insertAccount(profile); } //Restore filters cols = new Columns(Filter.full_projection, Filter.full_projection_types); try { JSONArray filtersObj = jsonObj.getJSONArray(FILTER_KEY); Log.d(THIS_FILE, "We have filters for " + profile.id + " > " + filtersObj.length()); for (int i = 0; i < filtersObj.length(); i++) { JSONObject filterObj = filtersObj.getJSONObject(i); //Log.d(THIS_FILE, "restoring "+filterObj.toString(4)); cv = cols.jsonToContentValues(filterObj); cv.put(Filter.FIELD_ACCOUNT, profile.id); Filter filter = new Filter(); filter.createFromContentValue(cv); db.insertFilter(filter); } } catch (JSONException e) { Log.e(THIS_FILE, "Error while restoring filters", e); } return false; }
From source file:net.nordist.lloydproof.CorrectionStorage.java
public int save(String currentText) { ContentValues values = new ContentValues(); values.put("current_text", currentText); openWriteDB();/*from www .j a v a2s . c om*/ int savedId = (int) writeDB.insert(TABLE_NAME, null, values); if (savedId > 0) { Log.d(TAG, "saved correction as id=" + savedId); } else { Log.e(TAG, "error saving correction"); } return savedId; }
From source file:net.peterkuterna.android.apps.devoxxsched.service.NewsSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start news sync"); final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { mLocalExecutor.execute(context, "cache-news.json", new NewsHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(News.NEWS_NEW, 0); getContentResolver().update(News.CONTENT_NEW_URI, values, null, null); }//w w w .j a v a 2 s.c o m Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); mRemoteExecutor.executeGet(NEWS_URL, new NewsHandler()); Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewNewsItems(); Log.d(TAG, "News sync finished"); }
From source file:net.naonedbus.manager.impl.CommentaireManager.java
@Override protected ContentValues getContentValues(final Commentaire commentaire) { final ContentValues values = new ContentValues(); values.put(CommentaireTable.CODE_LIGNE, commentaire.getCodeLigne()); values.put(CommentaireTable.CODE_SENS, commentaire.getCodeSens()); values.put(CommentaireTable.CODE_ARRET, commentaire.getCodeArret()); values.put(CommentaireTable.MESSAGE, commentaire.getMessage()); values.put(CommentaireTable.SOURCE, commentaire.getSource()); values.put(CommentaireTable.TIMESTAMP, commentaire.getTimestamp()); return values; }