List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferDBUtil.java
/** * Updates the current bytes of a transfer record. * * @param id The id of the transfer//from w w w. java 2 s .c om * @param bytes The bytes currently transferred * @return Number of rows updated. */ public int updateBytesTransferred(int id, long bytes) { final ContentValues values = new ContentValues(); values.put(TransferTable.COLUMN_BYTES_CURRENT, bytes); return transferDBBase.update(getRecordUri(id), values, null, null); }
From source file:com.ubikod.urbantag.model.TagManager.java
/** * Update a tag on db/*from w ww. j a v a2 s . c o m*/ * @param t */ private void dbUpdate(Tag t) { this.open(); ContentValues values = new ContentValues(); values.put(DatabaseHelper.TAG_COL_NAME, t.getValue()); values.put(DatabaseHelper.TAG_COL_COLOR, t.getColor()); values.put(DatabaseHelper.TAG_COL_NOTIFY, t.isSelected() ? 1 : 0); mDB.update(DatabaseHelper.TABLE_TAGS, values, DatabaseHelper.TAG_COL_ID + " =? ", new String[] { String.valueOf(t.getId()) }); this.close(); }
From source file:com.example.premiereappandroid.BloaActivity.java
private ContentValues parseTimelineJSONObject(JSONObject object) throws Exception { ContentValues values = new ContentValues(); JSONObject user = object.getJSONObject("user"); values.put(UserStatusRecord.USER_NAME, user.getString("name")); values.put(UserStatusRecord.RECORD_ID, user.getInt("id_str")); values.put(UserStatusRecord.USER_CREATED_DATE, object.getString("created_at")); values.put(UserStatusRecord.USER_TEXT, object.getString("text")); return values; }
From source file:com.foregroundcameraplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits./*from w w w. jav a2 s. c o 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; } } // 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:github.popeen.dsub.util.SongDBHandler.java
protected synchronized void addSongsImpl(SQLiteDatabase db, int serverKey, List<Pair<String, String>> entries) { db.beginTransaction();// w ww . ja va 2 s .c om try { for (Pair<String, String> entry : entries) { ContentValues values = new ContentValues(); values.put(SONGS_SERVER_KEY, serverKey); values.put(SONGS_SERVER_ID, entry.getFirst()); values.put(SONGS_COMPLETE_PATH, entry.getSecond()); db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE); } db.setTransactionSuccessful(); } catch (Exception e) { } db.endTransaction(); }
From source file:com.mobile.system.db.abatis.AbatisService.java
public boolean update(String tableName, String sqlId, Map<String, Object> bindParams, String whereClause, String[] whereArgs) {//from ww w . j a v a 2s .c om getDbObject(); int pointer = context.getResources().getIdentifier(sqlId, "string", context.getPackageName()); if (pointer == 0) { Log.e(TAG, "undefined sql id : " + sqlId); return false; } String sql = context.getResources().getString(pointer); ContentValues initialValues = new ContentValues(); if (bindParams != null) { Iterator<String> mapIterator = bindParams.keySet().iterator(); while (mapIterator.hasNext()) { String key = mapIterator.next(); Object value = bindParams.get(key); if (value instanceof byte[]) { initialValues.put(key, (byte[]) value); } else { initialValues.put(key, value.toString()); } } } if (sql.indexOf('#') != -1) { Log.e(TAG, "undefined parameter sql : " + sql); return false; } int nInsertCnt = (int) dbObj.update(tableName, initialValues, whereClause, whereArgs); dbObj.close(); if (nInsertCnt <= 0) { return false; } return true; }
From source file:com.bt.download.android.gui.Librarian.java
public String renameFile(FileDescriptor fd, String newFileName) { try {//from www . ja va 2s . c o m String filePath = fd.filePath; File oldFile = new File(filePath); String ext = FilenameUtils.getExtension(filePath); File newFile = new File(oldFile.getParentFile(), newFileName + '.' + ext); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaColumns.DATA, newFile.getAbsolutePath()); values.put(MediaColumns.DISPLAY_NAME, FilenameUtils.getBaseName(newFileName)); values.put(MediaColumns.TITLE, FilenameUtils.getBaseName(newFileName)); TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType); cr.update(fetcher.getContentUri(), values, BaseColumns._ID + "=?", new String[] { String.valueOf(fd.id) }); oldFile.renameTo(newFile); return newFile.getAbsolutePath(); } catch (Throwable e) { Log.e(TAG, "Failed to rename file: " + fd, e); } return null; }
From source file:io.github.protino.codewatch.remote.FetchLeaderBoardData.java
private ContentValues[] parseLeaderDataFromJson(List<String> dataList) throws JSONException { final long start = System.currentTimeMillis(); final String ROOT_DATA = "data"; final String RANK = "rank"; final String ROOT_USER_DATA = "user"; final String ROOT_STATS = "running_total"; final String DAILY_AVERAGE = "daily_average"; final String TOTAL_SECONDS = "total_seconds"; final String LANGUAGE_LIST = "languages"; //keys under languages section final String LANGUAGE_NAME = "name"; //keys under user section final String DISPLAY_NAME = "display_name"; final String EMAIL = "email"; final String FULL_NAME = "full_name"; //most of time this is empty, ignoring it final String USER_ID = "id"; final String LOCATION = "location"; final String PHOTO_URL = "photo"; final String USERNAME = "username"; final String WEBSITE = "website"; List<ContentValues> leaderValues = new ArrayList<>(); for (String dataJsonStr : dataList) { JSONObject rootObject = new JSONObject(dataJsonStr); JSONArray dataArray = rootObject.getJSONArray(ROOT_DATA); ContentValues values;//from w ww.j a v a2s. com for (int i = 0; i < dataArray.length(); i++) { values = new ContentValues(); JSONObject rootUserData = dataArray.getJSONObject(i); values.put(LeaderContract.LeaderEntry.COLUMN_RANK, rootUserData.getInt(RANK)); /* User stats*/ JSONObject runningTotal = rootUserData.getJSONObject(ROOT_STATS); values.put(LeaderContract.LeaderEntry.COLUMN_TOTAL_SECONDS, runningTotal.getInt(TOTAL_SECONDS)); values.put(LeaderContract.LeaderEntry.COLUMN_DAILY_AVERAGE, runningTotal.getInt(DAILY_AVERAGE)); // transform language list to a simple name-seconds map // Doing so simplifies the structure and takes less storage space JSONArray languageList = runningTotal.getJSONArray(LANGUAGE_LIST); JSONObject languageMap = new JSONObject(); for (int j = 0; j < languageList.length(); j++) { JSONObject language = languageList.getJSONObject(j); languageMap.put(language.getString(LANGUAGE_NAME), language.getInt(TOTAL_SECONDS)); } values.put(LeaderContract.LeaderEntry.COLUMN_LANGUAGE_STATS, languageMap.toString()); /* User data*/ JSONObject userData = rootUserData.getJSONObject(ROOT_USER_DATA); values.put(LeaderContract.LeaderEntry.COLUMN_USER_ID, userData.getString(USER_ID)); values.put(LeaderContract.LeaderEntry.COLUMN_PHOTO, userData.getString(PHOTO_URL)); values.put(LeaderContract.LeaderEntry.COLUMN_USER_NAME, userData.getString(USERNAME)); values.put(LeaderContract.LeaderEntry.COLUMN_DISPLAY_NAME, userData.getString(DISPLAY_NAME)); values.put(LeaderContract.LeaderEntry.COLUMN_LOCATION, userData.getString(LOCATION)); values.put(LeaderContract.LeaderEntry.COLUMN_EMAIL, userData.getString(EMAIL)); values.put(LeaderContract.LeaderEntry.COLUMN_WEBSITE, userData.getString(WEBSITE)); leaderValues.add(values); } } Timber.d("Data parsed - " + (System.currentTimeMillis() - start) + "ms"); ContentValues[] contentValuesArray = new ContentValues[leaderValues.size()]; return leaderValues.toArray(contentValuesArray); }
From source file:com.easemob.chatuidemo.adapter.NewFriendsMsgAdapter.java
/** * ???//from w w w.jav a2s. c om * * @param button * @param username */ public void acceptInvitation(final Button button, final InviteMessage msg) { final ProgressDialog pd = new ProgressDialog(context); String str1 = context.getResources().getString(R.string.Are_agree_with); final String str2 = context.getResources().getString(R.string.Has_agreed_to); final String str3 = context.getResources().getString(R.string.Agree_with_failure); pd.setMessage(str1); pd.setCanceledOnTouchOutside(false); pd.show(); RequestQueue requestQueue = Volley.newRequestQueue(context); requestQueue.start(); requestQueue.add(new AutoLoginRequest(context, Request.Method.POST, Model.PathLoad, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { pd.dismiss(); button.setText(str2); msg.setStatus(InviteMesageStatus.AGREED); // db ContentValues values = new ContentValues(); values.put(InviteMessgeDao.COLUMN_NAME_STATUS, msg.getStatus().ordinal()); messgeDao.updateMessage(msg.getId(), values); button.setBackgroundDrawable(null); button.setEnabled(false); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(context, str3 + error.getMessage(), 1).show(); } }) { @Override protected void setParams(Map<String, String> params) { if (msg.getGroupId() == null) {//??? params.put("sys", "msg"); params.put("ctrl", "msger"); params.put("action", "add_friend"); params.put("friend_name", msg.getFrom()); } else //?? { params.put("sys", "msg"); params.put("ctrl", "msger"); params.put("action", "agree_group"); params.put("stranger", msg.getFrom()); params.put("group_sn", msg.getGroupId()); } } }); }