List of usage examples for android.content ContentValues size
public int size()
From source file:com.tct.emailcommon.utility.AttachmentUtilities.java
public static void saveAttachmentToExternal(Context context, Attachment attachment, String path) { final Uri uri = ContentUris.withAppendedId(Attachment.CONTENT_URI, attachment.mId); final ContentValues cv = new ContentValues(); final long attachmentId = attachment.mId; final long accountId = attachment.mAccountKey; //TS: wenggangjin 2014-12-11 EMAIL BUGFIX_868520 MOD_S String contentUri = null;/*ww w. j av a 2s . co m*/ //TS: wenggangjin 2014-12-11 EMAIL BUGFIX_868520 MOD_S final long size; InputStream in = null; OutputStream out = null; try { ContentResolver resolver = context.getContentResolver(); if (Utility.isExternalStorageMounted()) { if (TextUtils.isEmpty(attachment.mFileName)) { // TODO: This will prevent a crash but does not surface the underlying problem // to the user correctly. LogUtils.w(Logging.LOG_TAG, "Trying to save an attachment with no name: %d", attachmentId); throw new IOException("Can't save an attachment with no name"); } // TS: Gantao 2015-07-29 EMAIL BUGFIX-1055568 MOD_S try { String cachedFileUri = attachment.getCachedFileUri(); if (TextUtils.isEmpty(cachedFileUri)) { throw new IOException(); } in = resolver.openInputStream(Uri.parse(cachedFileUri)); } catch (IOException e) { String contentUriForOpen = attachment.getContentUri(); if (TextUtils.isEmpty(contentUriForOpen)) { throw new IOException(); } in = resolver.openInputStream(Uri.parse(contentUriForOpen)); //TS: junwei-xu 2016-03-31 EMAIL BUGFIX-1886442 ADD_S } catch (IllegalArgumentException e) { String contentUriForOpen = attachment.getContentUri(); if (TextUtils.isEmpty(contentUriForOpen)) { throw new IOException(); } in = resolver.openInputStream(Uri.parse(contentUriForOpen)); } //TS: junwei-xu 2016-03-31 EMAIL BUGFIX-1886442 ADD_E //TS: jian.xu 2016-01-20 EMAIL FEATURE-1477377 MOD_S //Note: we support save attachment at user designated location. File downloads; if (path != null) { downloads = new File(path); } else { downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); } //TS: jian.xu 2016-01-20 EMAIL FEATURE-1477377 MOD_E downloads.mkdirs(); File file = Utility.createUniqueFile(downloads, attachment.mFileName); out = new FileOutputStream(file); size = copyFile(in, out); String absolutePath = file.getAbsolutePath(); // Although the download manager can scan media files, scanning only happens // after the user clicks on the item in the Downloads app. So, we run the // attachment through the media scanner ourselves so it gets added to // gallery / music immediately. MediaScannerConnection.scanFile(context, new String[] { absolutePath }, null, null); final String mimeType = TextUtils.isEmpty(attachment.mMimeType) ? "application/octet-stream" : attachment.mMimeType; try { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); //TS: junwei-xu 2016-02-04 EMAIL BUGFIX-1531245 MOD_S //Note: should use media scanner, it will allow update the //media provider uri column in download manager's database. long id = dm.addCompletedDownload(attachment.mFileName, attachment.mFileName, true /* use media scanner */, mimeType, absolutePath, size, true /* show notification */); //TS: junwei-xu 2016-02-04 EMAIL BUGFIX-1531245 MOD_E contentUri = dm.getUriForDownloadedFile(id).toString(); } catch (final IllegalArgumentException e) { LogUtils.d(LogUtils.TAG, e, "IAE from DownloadManager while saving attachment"); throw new IOException(e); } } else { LogUtils.w(Logging.LOG_TAG, "Trying to save an attachment without external storage?"); throw new IOException(); } // Update the attachment cv.put(AttachmentColumns.SIZE, size); cv.put(AttachmentColumns.UI_STATE, UIProvider.UIPROVIDER_ATTACHMENTSTATE_SAVED); // TS: Gantao 2015-06-30 EMAIL BUGFIX-1031608 ADD_S //Note:we have saved the attachment to sd card,so should update the attachment destination external cv.put(AttachmentColumns.UI_DESTINATION, UIProvider.UIPROVIDER_ATTACHMENTDESTINATION_EXTERNAL); // TS: Gantao 2015-06-30 EMAIL BUGFIX-1031608 ADD_E } catch (IOException e) { // Handle failures here... LogUtils.e(Logging.LOG_TAG, "IOException while save an attachment to external storage"); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException e) { LogUtils.e(Logging.LOG_TAG, "ioexception while close the stream"); } } // TS: Gantao 2015-07-29 EMAIL BUGFIX-1055568 MOD_E //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_871936 MOD_S // context.getContentResolver().update(uri, cv, null, null); if (cv.size() > 0) { context.getContentResolver().update(uri, cv, null, null); } //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_871936 MOD_E //TS: wenggangjin 2014-12-11 EMAIL BUGFIX_868520 MOD_S if (contentUri != null && attachment.mContentId != null && attachment.mContentId.length() > 0) { Body body = Body.restoreBodyWithMessageId(context, attachment.mMessageKey); if (body != null && body.mHtmlContent != null) { cv.clear(); String html = body.mHtmlContent; String contentIdRe = "\\s+(?i)src=\"cid(?-i):\\Q" + attachment.mContentId + "\\E\""; String srcContentUri = " src=\"" + contentUri + "\""; //TS: zhaotianyong 2015-04-15 EMAIL BUGFIX_976967 MOD_S try { html = html.replaceAll(contentIdRe, srcContentUri); } catch (PatternSyntaxException e) { LogUtils.w(Logging.LOG_TAG, "Unrecognized backslash escape sequence in pattern"); } //TS: zhaotianyong 2015-04-15 EMAIL BUGFIX_976967 MOD_E cv.put(BodyColumns.HTML_CONTENT, html); Body.updateBodyWithMessageId(context, attachment.mMessageKey, cv); Body.restoreBodyHtmlWithMessageId(context, attachment.mMessageKey); } } //TS: wenggangjin 2014-12-11 EMAIL BUGFIX_868520 MOD_E }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Insert a row into a local only table/*from w ww .ja v a 2 s .c om*/ * * @param db * @param tableId * @param rowValues * @throws ActionNotAuthorizedException */ public void insertLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } if (!tableId.startsWith("L_")) { tableId = "L_" + tableId; } db.insertOrThrow(tableId, null, cvDataTableVal); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Update a row in a local only table//www.j a va2 s .c om * * @param db * @param tableId * @param rowValues * @param whereClause * @param bindArgs * @throws ActionNotAuthorizedException */ public void updateLocalOnlyRow(OdkConnectionInterface db, String tableId, ContentValues rowValues, String whereClause, Object[] bindArgs) throws IllegalArgumentException { if (rowValues == null || rowValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); for (String key : rowValues.keySet()) { cvDataTableVal.put(key, rowValues.get(key)); } boolean dbWithinTransaction = db.inTransaction(); try { if (!dbWithinTransaction) { db.beginTransactionNonExclusive(); } if (!tableId.startsWith("L_")) { tableId = "L_" + tableId; } db.update(tableId, cvDataTableVal, whereClause, bindArgs); if (!dbWithinTransaction) { db.setTransactionSuccessful(); } } finally { if (!dbWithinTransaction) { db.endTransaction(); } } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Insert the given rowId with the values in the cvValues. All metadata field * values must be specified in the cvValues. This is called from Sync for inserting * a row verbatim from the server.//from w w w.ja v a 2 s . co m * <p/> * If a row with this rowId is present, then an exception is thrown. * * @param db * @param tableId * @param orderedColumns * @param cvValues * @param rowId * @param activeUser * @param locale * @param asCsvRequestedChange */ public void privilegedInsertRowWithId(OdkConnectionInterface db, String tableId, OrderedColumns orderedColumns, ContentValues cvValues, String rowId, String activeUser, String locale, boolean asCsvRequestedChange) { String rolesList = RoleConsts.ADMIN_ROLES_LIST; if (cvValues == null || cvValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); cvDataTableVal.put(DataTableColumns.ID, rowId); for (String key : cvValues.keySet()) { cvDataTableVal.put(key, cvValues.get(key)); } // TODO: verify that all fields are specified try { upsertDataIntoExistingTable(db, tableId, orderedColumns, cvDataTableVal, false, true, activeUser, rolesList, locale, asCsvRequestedChange); } catch (ActionNotAuthorizedException e) { WebLogger.getLogger(db.getAppName()).printStackTrace(e); throw new IllegalStateException(e); } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Update the given rowId with the values in the cvValues. If certain metadata * values are not specified in the cvValues, then suitable default values may * be supplied for them. Furthermore, if the cvValues do not specify certain * metadata fields, then an exception may be thrown if there are more than one * row matching this rowId./*from w ww.j a v a 2 s. c om*/ * * @param db * @param tableId * @param orderedColumns * @param cvValues * @param rowId * @param activeUser * @param rolesList * @param locale */ public void updateRowWithId(OdkConnectionInterface db, String tableId, OrderedColumns orderedColumns, ContentValues cvValues, String rowId, String activeUser, String rolesList, String locale) throws ActionNotAuthorizedException { // TODO: make sure caller passes in the correct roleList for the use case. // TODO: for multi-step sync actions, we probably need an internal variant of this. if (cvValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); cvDataTableVal.put(DataTableColumns.ID, rowId); for (String key : cvValues.keySet()) { cvDataTableVal.put(key, cvValues.get(key)); } upsertDataIntoExistingTable(db, tableId, orderedColumns, cvDataTableVal, true, false, activeUser, rolesList, locale, false); }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Inserts a checkpoint row for the given rowId in the tableId. Checkpoint * rows are created by ODK Survey to hold intermediate values during the * filling-in of the form. They act as restore points in the Survey, should * the application die./* www .j a v a 2 s . co m*/ * * @param db * @param tableId * @param orderedColumns * @param cvValues * @param rowId * @param activeUser * @param rolesList * @param locale */ public void insertCheckpointRowWithId(OdkConnectionInterface db, String tableId, OrderedColumns orderedColumns, ContentValues cvValues, String rowId, String activeUser, String rolesList, String locale) throws ActionNotAuthorizedException { if (cvValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table for checkpoint" + tableId); } // these are all managed in the database layer... // the user should NOT set them... if (cvValues.containsKey(DataTableColumns.SAVEPOINT_TIMESTAMP)) { throw new IllegalArgumentException( t + ": No user supplied savepoint timestamp can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.SAVEPOINT_TYPE)) { throw new IllegalArgumentException( t + ": No user supplied savepoint type can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.ROW_ETAG)) { throw new IllegalArgumentException(t + ": No user supplied row ETag can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.SYNC_STATE)) { throw new IllegalArgumentException( t + ": No user supplied sync state can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.CONFLICT_TYPE)) { throw new IllegalArgumentException( t + ": No user supplied conflict type can be included for a checkpoint"); } // If a rowId is specified, a cursor will be needed to // get the current row to create a checkpoint with the relevant data Cursor c = null; try { // Allow the user to pass in no rowId if this is the first // checkpoint row that the user is adding if (rowId == null) { // TODO: is this even valid any more? I think we disallow this in the AIDL flow. String rowIdToUse = LocalizationUtils.genUUID(); HashMap<String, Object> currValues = new HashMap<String, Object>(); for (String key : cvValues.keySet()) { currValues.put(key, cvValues.get(key)); } currValues.put(DataTableColumns._ID, rowIdToUse); currValues.put(DataTableColumns.SYNC_STATE, SyncState.new_row.name()); insertCheckpointIntoExistingTable(db, tableId, orderedColumns, currValues, activeUser, rolesList, locale, true, null, null, null, null, null); return; } StringBuilder b = new StringBuilder(); b.append(K_DATATABLE_ID_EQUALS_PARAM).append(S_AND).append(DataTableColumns.SAVEPOINT_TIMESTAMP) .append(" IN (SELECT MAX(").append(DataTableColumns.SAVEPOINT_TIMESTAMP).append(") FROM ") .append(tableId).append(K_WHERE).append(K_DATATABLE_ID_EQUALS_PARAM).append(")"); c = db.query(tableId, null, b.toString(), new Object[] { rowId, rowId }, null, null, null, null); c.moveToFirst(); if (c.getCount() > 1) { throw new IllegalStateException(t + ": More than one checkpoint at a timestamp"); } // Inserting a checkpoint for the first time if (c.getCount() <= 0) { HashMap<String, Object> currValues = new HashMap<String, Object>(); for (String key : cvValues.keySet()) { currValues.put(key, cvValues.get(key)); } currValues.put(DataTableColumns._ID, rowId); currValues.put(DataTableColumns.SYNC_STATE, SyncState.new_row.name()); insertCheckpointIntoExistingTable(db, tableId, orderedColumns, currValues, activeUser, rolesList, locale, true, null, null, null, null, null); return; } else { // Make sure that the conflict_type of any existing row // is null, otherwise throw an exception int conflictIndex = c.getColumnIndex(DataTableColumns.CONFLICT_TYPE); if (!c.isNull(conflictIndex)) { throw new IllegalStateException( t + ": A checkpoint cannot be added for a row that is in conflict"); } // these are all managed in the database layer... // the user should NOT set them... if (cvValues.containsKey(DataTableColumns.DEFAULT_ACCESS)) { throw new IllegalArgumentException( t + ": No user supplied default access can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.ROW_OWNER)) { throw new IllegalArgumentException( t + ": No user supplied row owner can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.GROUP_READ_ONLY)) { throw new IllegalArgumentException( t + ": No user supplied group read only can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.GROUP_MODIFY)) { throw new IllegalArgumentException( t + ": No user supplied group modify can be included for a checkpoint"); } if (cvValues.containsKey(DataTableColumns.GROUP_PRIVILEGED)) { throw new IllegalArgumentException( t + ": No user supplied group privileged can be included for a checkpoint"); } HashMap<String, Object> currValues = new HashMap<String, Object>(); for (String key : cvValues.keySet()) { currValues.put(key, cvValues.get(key)); } // This is unnecessary // We should only have one row at this point //c.moveToFirst(); String priorDefaultAccess = null; String priorOwner = null; String priorGroupReadOnly = null; String priorGroupModify = null; String priorGroupPrivileged = null; // Get the number of columns to iterate over and add // those values to the content values for (int i = 0; i < c.getColumnCount(); i++) { String name = c.getColumnName(i); if (name.equals(DataTableColumns.DEFAULT_ACCESS)) { priorDefaultAccess = c.getString(i); } if (name.equals(DataTableColumns.ROW_OWNER)) { priorOwner = c.getString(i); } if (name.equals(DataTableColumns.GROUP_READ_ONLY)) { priorGroupReadOnly = c.getString(i); } if (name.equals(DataTableColumns.GROUP_MODIFY)) { priorGroupModify = c.getString(i); } if (name.equals(DataTableColumns.GROUP_PRIVILEGED)) { priorGroupPrivileged = c.getString(i); } if (currValues.containsKey(name)) { continue; } // omitting savepoint timestamp will generate a new timestamp. if (name.equals(DataTableColumns.SAVEPOINT_TIMESTAMP)) { continue; } // set savepoint type to null to mark this as a checkpoint if (name.equals(DataTableColumns.SAVEPOINT_TYPE)) { currValues.put(name, null); continue; } // sync state (a non-null field) should either remain 'new_row' // or be set to 'changed' for all other existing values. if (name.equals(DataTableColumns.SYNC_STATE)) { String priorState = c.getString(i); if (priorState.equals(SyncState.new_row.name())) { currValues.put(name, SyncState.new_row.name()); } else { currValues.put(name, SyncState.changed.name()); } continue; } if (c.isNull(i)) { currValues.put(name, null); continue; } // otherwise, just copy the values over... Class<?> theClass = CursorUtils.getIndexDataType(c, i); Object object = CursorUtils.getIndexAsType(c, theClass, i); insertValueIntoContentValues(currValues, theClass, name, object); } insertCheckpointIntoExistingTable(db, tableId, orderedColumns, currValues, activeUser, rolesList, locale, false, priorDefaultAccess, priorOwner, priorGroupReadOnly, priorGroupModify, priorGroupPrivileged); } } finally { if (c != null && !c.isClosed()) { c.close(); } } }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * Update the given rowId with the values in the cvValues. All field * values are specified in the cvValues. This is a server-induced update * of the row to match all fields from the server. An error is thrown if * there isn't a row matching this rowId or if there are checkpoint or * conflict entries for this rowId./*from w ww .j a v a 2 s . com*/ * * @param db * @param tableId * @param orderedColumns * @param cvValues * @param rowId * @param activeUser * @param locale * @param asCsvRequestedChange */ private void privilegedUpdateRowWithId(OdkConnectionInterface db, String tableId, OrderedColumns orderedColumns, ContentValues cvValues, String rowId, String activeUser, String locale, boolean asCsvRequestedChange) { // TODO: make sure caller passes in the correct roleList for the use case. // TODO: for multi-step sync actions, we probably need an internal variant of this. String rolesList = RoleConsts.ADMIN_ROLES_LIST; if (cvValues.size() <= 0) { throw new IllegalArgumentException(t + ": No values to add into table " + tableId); } HashMap<String, Object> cvDataTableVal = new HashMap<String, Object>(); cvDataTableVal.put(DataTableColumns.ID, rowId); for (String key : cvValues.keySet()) { cvDataTableVal.put(key, cvValues.get(key)); } try { upsertDataIntoExistingTable(db, tableId, orderedColumns, cvDataTableVal, true, true, activeUser, rolesList, locale, asCsvRequestedChange); } catch (ActionNotAuthorizedException e) { WebLogger.getLogger(db.getAppName()).printStackTrace(e); throw new IllegalStateException(e); } }
From source file:com.aniruddhc.acemusic.player.Dialogs.ID3sSongEditorDialog.java
public boolean saveSongTags(String uri) { File file = new File(uri); AudioFile audioFile = null;//from w w w . ja v a 2s . c o m //Update the DB entries. DBAccessHelper dbHelper = new DBAccessHelper(mContext.getApplicationContext()); //Escape any rogue apostrophes. if (SONG_URI.contains("'")) { SONG_URI = SONG_URI.replace("'", "''"); } String whereClause = DBAccessHelper.SONG_FILE_PATH + "=" + "'" + SONG_URI + "'"; ContentValues values = new ContentValues(); try { audioFile = AudioFileIO.read(file); } catch (CannotReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TagException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ReadOnlyFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidAudioFrameException e) { // TODO Auto-generated catch block e.printStackTrace(); } Tag tag = audioFile.getTag(); if (tag != null) { if (titleEdited == false) { //Don't do anything here. The user didn't change the title. } else { try { tag.setField(FieldKey.TITLE, titleEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } String title = titleEditText.getText().toString(); if (title.contains("'")) { title = title.replace("'", "''"); } values.put(DBAccessHelper.SONG_TITLE, title); } if (albumEdited == false) { //Don't do anything here. The user didn't change the album. } else { try { tag.setField(FieldKey.ALBUM, albumEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } String album = albumEditText.getText().toString(); if (album.contains("'")) { album = album.replace("'", "''"); } values.put(DBAccessHelper.SONG_ALBUM, album); } if (artistEdited == false) { //Don't do anything here. The user didn't change the artist. } else { try { tag.setField(FieldKey.ARTIST, artistEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } String artist = artistEditText.getText().toString(); if (artist.contains("'")) { artist = artist.replace("'", "''"); } values.put(DBAccessHelper.SONG_ARTIST, artist); } if (albumArtistEdited == false) { //Don't do anything here. The user didn't change the album artist. } else { try { tag.setField(FieldKey.ALBUM_ARTIST, albumArtistEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } String albumArtist = albumArtistEditText.getText().toString(); if (albumArtist.contains("'")) { albumArtist = albumArtist.replace("'", "''"); } values.put(DBAccessHelper.SONG_ALBUM_ARTIST, albumArtist); } if (genreEdited == false) { //Don't do anything here. The user didn't change the genre. } else { try { tag.setField(FieldKey.GENRE, genreEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (producerEdited == false) { //Don't do anything here. The user didn't change the producer. } else { try { tag.setField(FieldKey.PRODUCER, producerEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (yearEdited == false) { //Don't do anything here. The user didn't change the year. } else { try { tag.setField(FieldKey.YEAR, yearEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } String year = yearEditText.getText().toString(); if (year.contains("'")) { year = year.replace("'", "''"); } values.put(DBAccessHelper.SONG_YEAR, year); } if (trackEdited == false) { //Don't do anything here. The user didn't change the track number. } else { try { tag.setField(FieldKey.TRACK, trackEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } String track = trackEditText.getText().toString(); if (track.contains("'")) { track = track.replace("'", "''"); } values.put(DBAccessHelper.SONG_TRACK_NUMBER, track); } try { tag.setField(FieldKey.TRACK_TOTAL, trackTotalEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (commentEdited == false) { //Don't do anything here. The user didn't change the comments. } else { try { tag.setField(FieldKey.COMMENT, commentsEditText.getText().toString()); } catch (KeyNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FieldDataInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { audioFile.commit(); } catch (CannotWriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Write the values to the DB. if (values.size() != 0) { //Write the values to the DB. try { dbHelper.getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE, values, whereClause, null); dbHelper.close(); dbHelper = null; } catch (Exception e) { e.printStackTrace(); } } } else { Toast.makeText(mContext, R.string.unable_to_edit_song_tags, Toast.LENGTH_SHORT).show(); } return true; }