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 Double out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The REAL field to read/*from w ww.ja va 2 s.co m*/ * @param values The {@link ContentValues} to put the value into * @param key The key to store the value with in the map */ public static void cursorDoubleToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { values.put(key, cursor.getDouble(colIndex)); } else { values.put(key, (Double) null); } }
From source file:grytsenko.coworkers.web.Employee.java
/** * Returns data about full name for {@link ContentResolver}. * //from ww w. jav a 2 s . c om * @param preferNative * shows that name in native language is preferred. * * @return the set of values. */ public ContentValues getFullName(boolean preferNative) { if (preferNative && hasNative()) { ContentValues values = new ContentValues(); values.put(StructuredName.GIVEN_NAME, firstNameNative); values.put(StructuredName.FAMILY_NAME, lastNameNative); return values; } ContentValues values = new ContentValues(); values.put(StructuredName.GIVEN_NAME, firstName); values.put(StructuredName.FAMILY_NAME, lastName); return values; }
From source file:com.example.android.popularmoviesist2.data.FetchMovieTask.java
private void getMoviesDataFromJson(String moviesJsonStr) throws JSONException { final String JSON_LIST = "results"; final String JSON_POSTER = "poster_path"; final String JSON_TITLE = "original_title"; final String JSON_OVERVIEW = "overview"; final String JSON_VOTE = "vote_average"; final String JSON_RELEASE = "release_date"; final String JSON_ID = "id"; try {/*from www.j a v a 2 s . c o m*/ JSONObject moviesJson = new JSONObject(moviesJsonStr); JSONArray moviesArray = moviesJson.getJSONArray(JSON_LIST); Vector<ContentValues> cVVector = new Vector<ContentValues>(moviesArray.length()); for (int i = 0; i < moviesArray.length(); i++) { JSONObject movie = moviesArray.getJSONObject(i); String overview = movie.getString(JSON_OVERVIEW); String release = movie.getString(JSON_RELEASE); String poster = movie.getString(JSON_POSTER); String id = movie.getString(JSON_ID); String title = movie.getString(JSON_TITLE); String vote = movie.getString(JSON_VOTE); ContentValues movieValues = new ContentValues(); movieValues.put(MovieEntry.COLUMN_ID, id); movieValues.put(MovieEntry.COLUMN_POSTER, poster); movieValues.put(MovieEntry.COLUMN_TITLE, title); movieValues.put(MovieEntry.COLUMN_OVERVIEW, overview); movieValues.put(MovieEntry.COLUMN_VOTE, vote); movieValues.put(MovieEntry.COLUMN_RELEASE, release); cVVector.add(movieValues); } int inserted = 0; //delete database int rowdeleted = mContext.getContentResolver().delete(MovieEntry.CONTENT_URI, null, null); // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(MovieEntry.CONTENT_URI, cvArray); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.codebutler.farebot.activities.AddKeyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_key); getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT); findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { @Override/* w w w. j av a2 s .c o m*/ public void onClick(View view) { setResult(RESULT_CANCELED); finish(); } }); findViewById(R.id.add).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final String keyType = ((RadioButton) findViewById(R.id.is_key_a)).isChecked() ? ClassicSectorKey.TYPE_KEYA : ClassicSectorKey.TYPE_KEYB; new BetterAsyncTask<Void>(AddKeyActivity.this, true, false) { @Override protected Void doInBackground() throws Exception { ClassicCardKeys keys = ClassicCardKeys.fromDump(keyType, mKeyData); ContentValues values = new ContentValues(); values.put(KeysTableColumns.CARD_ID, mTagId); values.put(KeysTableColumns.CARD_TYPE, mCardType); values.put(KeysTableColumns.KEY_DATA, keys.toJSON().toString()); getContentResolver().insert(CardKeyProvider.CONTENT_URI, values); return null; } @Override protected void onResult(Void unused) { Intent intent = new Intent(AddKeyActivity.this, KeysActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }.execute(); } }); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); Utils.checkNfcEnabled(this, mNfcAdapter); Intent intent = getIntent(); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0); if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW) && getIntent().getData() != null) { try { InputStream stream = getContentResolver().openInputStream(getIntent().getData()); mKeyData = IOUtils.toByteArray(stream); } catch (IOException e) { Utils.showErrorAndFinish(this, e); } } else { finish(); } }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
@Override public void updateFileNameAndUID(String uid) throws ContactsStorageException { String newFileName = uid + ".vcf"; ContentValues values = new ContentValues(2); values.put(COLUMN_FILENAME, newFileName); values.put(COLUMN_UID, uid);/*from w w w . j a va 2 s . c o m*/ update(values); fileName = newFileName; }
From source file:com.example.google.touroflondon.data.TourDbHelper.java
/** * Extract Route data from a {@link JSONArray} of save it in the database. * //from ww w .j a v a 2 s . c o m * @param data */ public void loadRoute(JSONArray data) throws JSONException { SQLiteDatabase db = this.getWritableDatabase(); // Empty the route table to remove all existing data db.delete(TourContract.RouteEntry.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 location in array for (int i = 0; i < data.length(); i++) { // extract data JSONObject poi = data.getJSONObject(i); final double lat = poi.getDouble("lat"); final double lng = poi.getDouble("lng"); // Construct insert statement ContentValues cv = new ContentValues(); cv.put(TourContract.RouteEntry.COLUMN_NAME_LAT, lat); cv.put(TourContract.RouteEntry.COLUMN_NAME_LNG, lng); // Insert data db.insert(TourContract.RouteEntry.TABLE_NAME, null, cv); } if (db != null) { // All insert statement have been submitted, mark transaction as // successful db.setTransactionSuccessful(); db.endTransaction(); } }
From source file:com.example.android.touroflondon.data.TourDbHelper.java
/** * Extract Route data from a {@link JSONArray} of save it in the database. * * @param data/*from w w w .ja v a 2 s . c om*/ */ public void loadRoute(JSONArray data) throws JSONException { SQLiteDatabase db = this.getWritableDatabase(); // Empty the route table to remove all existing data db.delete(TourContract.RouteEntry.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 location in array for (int i = 0; i < data.length(); i++) { // extract data JSONObject poi = data.getJSONObject(i); final double lat = poi.getDouble("lat"); final double lng = poi.getDouble("lng"); // Construct insert statement ContentValues cv = new ContentValues(); cv.put(TourContract.RouteEntry.COLUMN_NAME_LAT, lat); cv.put(TourContract.RouteEntry.COLUMN_NAME_LNG, lng); // Insert data db.insert(TourContract.RouteEntry.TABLE_NAME, null, cv); } if (db != null) { // All insert statement have been submitted, mark transaction as successful db.setTransactionSuccessful(); db.endTransaction(); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a String 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 a v a 2s . com*/ * @param values The {@link ContentValues} to put the value into */ public static void cursorStringToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getString(index)); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Long 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 . j a v a2 s. c o m*/ * @param values The {@link ContentValues} to put the value into */ public static void cursorLongToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getLong(index)); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Short 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 ww w . j a v a2s. c o m * @param values The {@link ContentValues} to put the value into */ public static void cursorShortToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getShort(index)); } }