List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:android.database.DatabaseUtils.java
/** * Reads a Integer out of a column in a Cursor and writes it to a ContentValues. * Adds nothing to the ContentValues if the column isn't present or if its value is null. * * @param cursor The cursor to read from * @param column The column to read/*from w w w . j ava 2 s . c o m*/ * @param values The {@link ContentValues} to put the value into */ public static void cursorIntToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getInt(index)); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Float out of a column in a Cursor and writes it to a ContentValues. * Adds nothing to the ContentValues if the column isn't present or if its value is null. * * @param cursor The cursor to read from * @param column The column to read/* w w w .ja va2 s .c om*/ * @param values The {@link ContentValues} to put the value into */ public static void cursorFloatToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getFloat(index)); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Double out of a column in a Cursor and writes it to a ContentValues. * Adds nothing to the ContentValues if the column isn't present or if its value is null. * * @param cursor The cursor to read from * @param column The column to read//from www .j a va2 s. c om * @param values The {@link ContentValues} to put the value into */ public static void cursorDoubleToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getDouble(index)); } }
From source file:com.example.android.tvleanback.data.VideoDbBuilder.java
/** * Takes the contents of a JSON object and populates the database * @param jsonObj The JSON object of videos * @throws JSONException if the JSON object is invalid *//*from ww w . j a v a 2 s . c o m*/ public List<ContentValues> buildMedia(JSONObject jsonObj) throws JSONException { JSONArray categoryArray = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS); List<ContentValues> videosToInsert = new ArrayList<>(); for (int i = 0; i < categoryArray.length(); i++) { JSONArray videoArray; JSONObject category = categoryArray.getJSONObject(i); String categoryName = category.getString(TAG_CATEGORY); videoArray = category.getJSONArray(TAG_MEDIA); for (int j = 0; j < videoArray.length(); j++) { JSONObject video = videoArray.getJSONObject(j); // If there are no URLs, skip this video entry. JSONArray urls = video.optJSONArray(TAG_SOURCES); if (urls == null || urls.length() == 0) { continue; } String title = video.optString(TAG_TITLE); String description = video.optString(TAG_DESCRIPTION); String videoUrl = (String) urls.get(0); // Get the first video only. String bgImageUrl = video.optString(TAG_BACKGROUND); String cardImageUrl = video.optString(TAG_CARD_THUMB); String studio = video.optString(TAG_STUDIO); ContentValues videoValues = new ContentValues(); videoValues.put(VideoContract.VideoEntry.COLUMN_CATEGORY, categoryName); videoValues.put(VideoContract.VideoEntry.COLUMN_NAME, title); videoValues.put(VideoContract.VideoEntry.COLUMN_DESC, description); videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_URL, videoUrl); videoValues.put(VideoContract.VideoEntry.COLUMN_CARD_IMG, cardImageUrl); videoValues.put(VideoContract.VideoEntry.COLUMN_BG_IMAGE_URL, bgImageUrl); videoValues.put(VideoContract.VideoEntry.COLUMN_STUDIO, studio); // Fixed defaults. videoValues.put(VideoContract.VideoEntry.COLUMN_CONTENT_TYPE, "video/mp4"); videoValues.put(VideoContract.VideoEntry.COLUMN_IS_LIVE, false); videoValues.put(VideoContract.VideoEntry.COLUMN_AUDIO_CHANNEL_CONFIG, "2.0"); videoValues.put(VideoContract.VideoEntry.COLUMN_PRODUCTION_YEAR, 2014); videoValues.put(VideoContract.VideoEntry.COLUMN_DURATION, 0); videoValues.put(VideoContract.VideoEntry.COLUMN_RATING_STYLE, Rating.RATING_5_STARS); videoValues.put(VideoContract.VideoEntry.COLUMN_RATING_SCORE, 3.5f); if (mContext != null) { videoValues.put(VideoContract.VideoEntry.COLUMN_PURCHASE_PRICE, mContext.getResources().getString(R.string.buy_2)); videoValues.put(VideoContract.VideoEntry.COLUMN_RENTAL_PRICE, mContext.getResources().getString(R.string.rent_2)); videoValues.put(VideoContract.VideoEntry.COLUMN_ACTION, mContext.getResources().getString(R.string.global_search)); } // TODO: Get these dimensions. videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_WIDTH, 1280); videoValues.put(VideoContract.VideoEntry.COLUMN_VIDEO_HEIGHT, 720); videosToInsert.add(videoValues); } } return videosToInsert; }
From source file:com.rs.TCOfflineStatementCollection.java
/** * addStatement takes a statement and adds it to the local database * @param statement/*w w w. ja v a2 s . co m*/ * @param addInterface */ public void addStatement(Statement statement, addStatementInterface addInterface) { _statementArray.add(statement); Long now = Long.valueOf(System.currentTimeMillis()); ContentValues initialValues = new ContentValues(); try { initialValues.put(LocalStatements.CREATE_DATE, now); initialValues.put(LocalStatements.STATEMENT_JSON, statement.toJSON()); initialValues.put(LocalStatements.QUERY_STRING, ""); initialValues.put(LocalStatements.STATEMENT_ID, statement.getId().toString()); } catch (Exception e) { addInterface.errorBlock("initialValues" + e.toString()); return; } try { appContext.getContentResolver().insert(LocalStatements.CONTENT_URI, initialValues); } catch (Exception e) { addInterface.errorBlock("insert" + e.toString()); return; } addInterface.completionBlock(); }
From source file:me.ziccard.secureit.async.AudioRecorderTask.java
@Override public void run() { MicrophoneTaskFactory.pauseSampling(); while (MicrophoneTaskFactory.isSampling()) { try {/*from w w w .j a v a 2 s . c om*/ Thread.sleep(50); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } recording = true; final MediaRecorder recorder = new MediaRecorder(); ContentValues values = new ContentValues(3); values.put(MediaStore.MediaColumns.TITLE, filename); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); String audioPath = Environment.getExternalStorageDirectory().getPath() + filename + ".m4a"; recorder.setOutputFile(audioPath); try { recorder.prepare(); } catch (Exception e) { e.printStackTrace(); return; } Log.i("AudioRecorderTask", "Start recording"); recorder.start(); try { Thread.sleep(prefs.getAudioLenght()); } catch (InterruptedException e) { e.printStackTrace(); } recorder.stop(); Log.i("AudioRecorderTask", "Stopped recording"); recorder.release(); recording = false; MicrophoneTaskFactory.restartSampling(); /* * Uploading the audio */ Log.i("AudioRecorderTask", "Trying to upload"); HttpClient httpclient = new DefaultHttpClient(); HttpPost request = new HttpPost(Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.UPLOAD_AUDIO); Log.i("AudioRecorderTask", "URI: " + Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.UPLOAD_AUDIO); /* * Getting the audio from the file system */ MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File audio = new File(audioPath); reqEntity.addPart("audio", new FileBody(audio, "audio/mp3")); request.setEntity(reqEntity); /* * Authentication token */ request.setHeader("access_token", accessToken); try { HttpResponse response = httpclient.execute(request); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } Log.i("AudioRecorderTask", "Response:\n" + builder.toString()); if (response.getStatusLine().getStatusCode() != 200) { Log.i("AudioRecorderTask", "Error uploading audio: " + audioPath); throw new HttpException(); } } catch (Exception e) { Log.e("DataUploaderTask", "Error uploading audio: " + audioPath); } }
From source file:com.dwdesign.tweetings.fragment.SearchTweetsFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case MENU_SAVE: { final TweetingsApplication application = getApplication(); application.getServiceInterface().createSavedSearch(mAccountId, mQuery); break;/*from ww w. j av a 2 s. co m*/ } case MENU_DELETE: { final TweetingsApplication application = getApplication(); application.getServiceInterface().destroySavedSearch(mAccountId, mSearchId); break; } case MENU_ADD_TAB: { CustomTabsAdapter mAdapter; mAdapter = new CustomTabsAdapter(getActivity()); ContentResolver mResolver; mResolver = getContentResolver(); final String tabName = mQuery; final String tabType = AUTHORITY_SEARCH_TWEETS; final String tabIcon = "search"; final long account_id = mAccountId; final String tabArguments = "{\"account_id\":" + account_id + ",\"query\":" + JSONObject.quote(mQuery) + "}"; final ContentValues values = new ContentValues(); values.put(Tabs.ARGUMENTS, tabArguments); values.put(Tabs.NAME, tabName); values.put(Tabs.POSITION, mAdapter.getCount()); values.put(Tabs.TYPE, tabType); values.put(Tabs.ICON, tabIcon); mResolver.insert(Tabs.CONTENT_URI, values); Toast.makeText(this.getActivity(), R.string.search_tab_added, Toast.LENGTH_SHORT).show(); break; } } return super.onOptionsItemSelected(item); }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
@Override public void clearDirty(String eTag) throws ContactsStorageException { assertID();/*from w w w . ja va 2 s. c o m*/ ContentValues values = new ContentValues(2); values.put(Groups.DIRTY, 0); values.put(COLUMN_ETAG, this.eTag = eTag); update(values); // update cached group memberships BatchOperation batch = new BatchOperation(addressBook.provider); // delete cached group memberships batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newDelete(addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI)) .withSelection(CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?", new String[] { CachedGroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }))); // insert updated cached group memberships for (long member : getMembers()) batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newInsert(addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI)) .withValue(CachedGroupMembership.MIMETYPE, CachedGroupMembership.CONTENT_ITEM_TYPE) .withValue(CachedGroupMembership.RAW_CONTACT_ID, member) .withValue(CachedGroupMembership.GROUP_ID, id).withYieldAllowed(true))); batch.commit(); }
From source file:com.granita.contacticloudsync.resource.LocalCalendar.java
@Override public void setCTag(String cTag) throws CalendarStorageException, ContactsStorageException { try {/*from w w w .j a va2 s . c o m*/ ContentValues values = new ContentValues(1); values.put(COLUMN_CTAG, cTag); provider.update(calendarSyncURI(), values, null, null); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't write local (last known) CTag", e); } }
From source file:com.example.google.touroflondon.data.TourDbHelper.java
/** * Extract POI data from a {@link JSONArray} of points of interest and add * it to the POI table.//from w w w . j a v a2s .co m * * @param data */ public void loadPois(JSONArray data) throws JSONException { SQLiteDatabase db = this.getWritableDatabase(); // empty the POI table to remove all existing data db.delete(TourContract.PoiEntry.TABLE_NAME, null, null); // need to complete transaction first to clear data db.close(); // begin the insert transaction db = this.getWritableDatabase(); db.beginTransaction(); // Loop over each point of interest in array for (int i = 0; i < data.length(); i++) { JSONObject poi = data.getJSONObject(i); // Extract POI properties final String title = poi.getString("title"); final String type = poi.getString("type"); final String description = poi.getString("description"); final String pictureUrl = poi.getString("pictureUrl"); final String pictureAttr = poi.getString("pictureAttr"); // Location JSONObject location = poi.getJSONObject("location"); final double lat = location.getDouble("lat"); final double lng = location.getDouble("lng"); // Create content values object for insert ContentValues cv = new ContentValues(); cv.put(TourContract.PoiEntry.COLUMN_NAME_TITLE, title); cv.put(TourContract.PoiEntry.COLUMN_NAME_TYPE, type); cv.put(TourContract.PoiEntry.COLUMN_NAME_DESCRIPTION, description); cv.put(TourContract.PoiEntry.COLUMN_NAME_PICTURE_URL, pictureUrl); cv.put(TourContract.PoiEntry.COLUMN_NAME_LOCATION_LAT, lat); cv.put(TourContract.PoiEntry.COLUMN_NAME_LOCATION_LNG, lng); cv.put(TourContract.PoiEntry.COLUMN_NAME_PICTURE_ATTR, pictureAttr); // Insert data db.insert(TourContract.PoiEntry.TABLE_NAME, null, cv); } // All insert statement have been submitted, mark transaction as // successful db.setTransactionSuccessful(); if (db != null) { db.endTransaction(); } }