List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
/** * Updates a list of given quizzes./*from ww w . j a v a 2 s . co m*/ * * @param writableDatabase The database to write the quizzes to. * @param quizzes The quizzes to write. */ private static void updateQuizzes(SQLiteDatabase writableDatabase, List<Quiz> quizzes) { Quiz quiz; ContentValues quizValues = new ContentValues(); String[] quizArgs = new String[1]; for (int i = 0; i < quizzes.size(); i++) { quiz = quizzes.get(i); quizValues.clear(); quizValues.put(QuizTable.COLUMN_SOLVED, quiz.isSolved()); quizArgs[0] = quiz.getQuestion(); writableDatabase.update(QuizTable.NAME, quizValues, QuizTable.COLUMN_QUESTION + "=?", quizArgs); } }
From source file:alberthsu.sunshine.app.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us.//from ww w . j a va 2 s. c o m */ private void getWeatherDataFromJson(String forecastJsonStr, int numDays, String locationSetting) throws JSONException { // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; final String OWM_COORD_LAT = "lat"; final String OWM_COORD_LONG = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_DATETIME = "dt"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject coordJSON = cityJson.getJSONObject(OWM_COORD); double cityLatitude = coordJSON.getLong(OWM_COORD_LAT); double cityLongitude = coordJSON.getLong(OWM_COORD_LONG); Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude); // Insert the location into the database. long locationID = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Get and insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // The date/time is returned as a long. We need to convert that // into something human-readable, since most people won't read "1400356800" as // "this saturday". dateTime = dayForecast.getLong(OWM_DATETIME); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationID); weatherValues.put(WeatherEntry.COLUMN_DATETEXT, WeatherContract.getDbDateString(new Date(dateTime * 1000L))); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } }
From source file:com.hichinaschool.flashcards.libanki.Card.java
public void flushSched() { mMod = Utils.intNow();// w w w . j av a 2 s .c om mUsn = mCol.usn(); // bug check assert mQueue != 2 || mODue == 0 || mCol.getDecks().isDyn(mDid); ContentValues values = new ContentValues(); values.put("mod", mMod); values.put("usn", mUsn); values.put("type", mType); values.put("queue", mQueue); values.put("due", mDue); values.put("ivl", mIvl); values.put("factor", mFactor); values.put("reps", mReps); values.put("lapses", mLapses); values.put("left", mLeft); values.put("odue", mODue); values.put("odid", mODid); values.put("did", mDid); mCol.getDb().update("cards", values, "id = " + mId, null); }
From source file:com.plugin.camera.ForegroundCameraLauncher.java
/** * Called when the camera view exits./* w ww. jav a2 s . co m*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost // during compression ExifHelper exif = new ExifHelper(); exif.createInFile( getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg"); exif.readExifData(); // Read in bitmap of captured image Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); } catch (FileNotFoundException e) { Uri uri = intent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } bitmap = scaleBitmap(bitmap); // Create entry in media store for image // (Don't use insertImage() because it uses default compression // setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = null; try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver() .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); return; } } //This if block is added to the plugin to solve the issue which was saving portrait images in landscape with -90 degree rotetion if (intent.getBooleanExtra("portrait", false)) { Matrix matrix = new Matrix(); matrix.preRotate(90); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (Exception e) { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() / 2, bitmap.getHeight() / 2, matrix, true); e.printStackTrace(); } } // Add compressed version of captured image to returned media // store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file exif.createOutFile(getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext.success(getRealPathFromURI(uri, this.cordova)); bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } }
From source file:com.josenaves.sunshine.app.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w ww. j ava 2 s.co m*/ */ private void getWeatherDataFromJson(String forecastJsonStr, int numDays, String locationSetting) throws JSONException { // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; final String OWM_COORD_LAT = "lat"; final String OWM_COORD_LONG = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_DATETIME = "dt"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject coordJSON = cityJson.getJSONObject(OWM_COORD); double cityLatitude = coordJSON.getLong(OWM_COORD_LAT); double cityLongitude = coordJSON.getLong(OWM_COORD_LONG); Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude); // Insert the location into the database. long locationID = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Get and insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // The date/time is returned as a long. We need to convert that // into something human-readable, since most people won't read "1400356800" as // "this saturday". dateTime = dayForecast.getLong(OWM_DATETIME); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationID); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATETEXT, WeatherContract.getDbDateString(new Date(dateTime * 1000L))); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); mContext.getContentResolver().bulkInsert(WeatherContract.WeatherEntry.CONTENT_URI, cvArray); } }
From source file:com.markupartist.sthlmtraveling.FavoritesFragment.java
private void updateListPosition(long id, boolean increase) { Uri uri = ContentUris.withAppendedId(Journeys.CONTENT_URI, id); Cursor cursor = getActivity().managedQuery(uri, PROJECTION, null, null, null); cursor.moveToFirst();//from w w w. ja v a 2 s . com int position = cursor.getInt(COLUMN_INDEX_POSITION); if (increase) { position = position + 1; } else { position = position - 1; } ContentValues values = new ContentValues(); values.put(Journeys.POSITION, position); getActivity().getContentResolver().update(uri, values, null, null); }
From source file:com.ichi2.libanki.Card.java
public void flushSched() { mMod = Utils.intNow();/* ww w .j a va 2 s . c om*/ mUsn = mCol.usn(); // bug check if ((mQueue == 2 && mODue != 0) && !mCol.getDecks().isDyn(mDid)) { // TODO: runHook("odueInvalid"); } assert (mDue < Long.valueOf("4294967296")); ContentValues values = new ContentValues(); values.put("mod", mMod); values.put("usn", mUsn); values.put("type", mType); values.put("queue", mQueue); values.put("due", mDue); values.put("ivl", mIvl); values.put("factor", mFactor); values.put("reps", mReps); values.put("lapses", mLapses); values.put("left", mLeft); values.put("odue", mODue); values.put("odid", mODid); values.put("did", mDid); // TODO: The update DB call sets mod=true. Verify if this is intended. mCol.getDb().update("cards", values, "id = " + mId, null); mCol.log(this); }
From source file:com.groupe1.miage.ujf.tracestaroute.FetchTrackTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us.// ww w .ja v a 2 s .c om */ private void getTrackDataFromJson(String forecastJsonStr) throws JSONException { // These are the names of the JSON objects that need to be extracted. final String LT_RESPONSE = "response"; final String LT_ID = "id"; final String LT_SPORT = "sport"; final String LT_CREATION_DATE = "creation"; final String LT_NAME = "name"; final String LT_DESC = "description"; final String LT_LENGTH = "length"; final String LT_POSTALCODE = "postalcode"; final String LT_ALT_MIN = "altMin"; final String LT_ALT_MAX = "altMax"; final String LT_URL = "url"; final String LT_START = "start"; final String LT_STOP = "stop"; final String LT_Y = "y"; final String LT_X = "x"; final String LT_CITY = "city"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray trackArray = forecastJson.getJSONArray(LT_RESPONSE); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(trackArray.length()); for (int i = 0; i < trackArray.length(); i++) { // These are the values that will be collected. int id; String sport; String dateCreation; String name; String description; double length; int postalcode; double altMin; double altMax; String url; double yDepart; double xDepart; String cityDepart; double yArrivee; double xArrivee; String cityArrivee; // Get the JSON object representing the day JSONObject numTrackForecast = trackArray.getJSONObject(i); id = numTrackForecast.getInt(LT_ID); sport = numTrackForecast.getString(LT_SPORT); dateCreation = numTrackForecast.getString(LT_CREATION_DATE); name = numTrackForecast.getString(LT_NAME); description = numTrackForecast.getString(LT_DESC); length = numTrackForecast.getDouble(LT_LENGTH); postalcode = numTrackForecast.getInt(LT_POSTALCODE); altMin = numTrackForecast.getDouble(LT_ALT_MIN); altMax = numTrackForecast.getDouble(LT_ALT_MAX); url = numTrackForecast.getString(LT_URL); JSONObject start = numTrackForecast.getJSONObject(LT_START); yDepart = start.getDouble(LT_Y); xDepart = start.getDouble(LT_X); cityDepart = start.getString(LT_CITY); JSONObject stop = numTrackForecast.getJSONObject(LT_STOP); yArrivee = stop.getDouble(LT_Y); xArrivee = stop.getDouble(LT_X); cityArrivee = stop.getString(LT_CITY); //String tmp = formatMesure(length, altMin, altMax); //String tabMes[] = tmp.split("/"); //length = Double.valueOf(tabMes[0]); //altMin = Double.valueOf(tabMes[1]); //altMax = Double.valueOf(tabMes[2]); //Insertion des villes de dpart et d'arrive en BD long locationIdD = addLocation(cityDepart, yDepart, xDepart); long locationIdA = addLocation(cityArrivee, yArrivee, xArrivee); ContentValues trackValues = new ContentValues(); trackValues.put(TrackContract.TrackEntry.COLUMN_TRACK_ID, id); trackValues.put(TrackContract.TrackEntry.COLUMN_SPORT, sport); trackValues.put(TrackContract.TrackEntry.COLUMN_CREATION_DATE, dateCreation); trackValues.put(TrackContract.TrackEntry.COLUMN_NAME, name); trackValues.put(TrackContract.TrackEntry.COLUMN_SHORT_DESC, description); trackValues.put(TrackContract.TrackEntry.COLUMN_LENGTH, length); trackValues.put(TrackContract.TrackEntry.COLUMN_POSTALCODE, postalcode); trackValues.put(TrackContract.TrackEntry.COLUMN_MIN_ALTITUDE, altMin); trackValues.put(TrackContract.TrackEntry.COLUMN_MAX_ALTITUDE, altMax); trackValues.put(TrackContract.TrackEntry.COLUMN_URL, url); trackValues.put(TrackContract.TrackEntry.COLUMN_LOC_KEY_DEPART, locationIdD); trackValues.put(TrackContract.TrackEntry.COLUMN_LOC_KEY_ARRIVE, locationIdA); cVVector.add(trackValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(TrackEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchTrackTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.example.google.touroflondon.data.TourDbHelper.java
/** * Extract Route data from a {@link JSONArray} of save it in the database. * /*from www . j av 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.orangeweather.JSONWeatherParser.java
public static ContentValues getForecast(JSONObject jObj) throws JSONException { ContentValues cv = new ContentValues(); cv.put(ForecastTags.FORECAST_DT, getInt(ForecastTags.FORECAST_DT, jObj)); JSONObject tempObj = getObject("temp", jObj); cv.put(ForecastTags.FORECAST_TEMP_DAY, getTemperatureString(getFloat(ForecastTags.FORECAST_TEMP_DAY, tempObj))); cv.put(ForecastTags.FORECAST_TEMP_NIGHT, getTemperatureString(getFloat(ForecastTags.FORECAST_TEMP_NIGHT, tempObj))); JSONArray weatherObj = jObj.getJSONArray("weather"); cv.put(ForecastTags.FORECAST_COND_MAIN, weatherObj.getJSONObject(0).getString(ForecastTags.FORECAST_COND_MAIN)); return cv;//from ww w . ja v a2 s . c om }