diff --git a/fmapp2/res/values/customize.xml b/fmapp2/res/values/customize.xml index f24c67ca0bc5ccf7bc472c6fd4142f7833b1335a..f4dcdbca628ddcd5e58efb812d13269b2f223428 100644 --- a/fmapp2/res/values/customize.xml +++ b/fmapp2/res/values/customize.xml @@ -50,4 +50,19 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> <bool name="def_only_stereo_enabled">false</bool> + <!-- enabled the name format of recordings files or not, default value is false --> + <bool name="def_save_name_format_enabled">false</bool> + + <!-- the prefix of recordings files name, file name like this "FM-yyyy-MM-dd-HH-mm-ss.3gpp" --> + <string name="def_save_name_prefix" translatable="false">FM</string> + + <!-- the suffix of recordings files, default value is ".3gpp" --> + <string name="def_save_name_suffix" translatable="false">.3gpp</string> + + <!-- the name format of recordings files --> + <string name="def_save_name_format" translatable="false">yyyy-MM-dd-HH-mm-ss</string> + + <!-- the save path of recordings files --> + <string name="def_fmRecord_savePath" translatable="false"></string> + </resources> diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 83018f560ec5c24b91ec9f17bfc4ec276e2c8380..9afd671a63453e230c7b9ed7a8299057b03f3d50 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -1104,6 +1104,32 @@ public class FMRadioService extends Service return status; } + private File createTempFile(String prefix, String suffix, File directory) + throws IOException { + // Force a prefix null check first + if (prefix.length() < 3) { + throw new IllegalArgumentException("prefix must be at least 3 characters"); + } + if (suffix == null) { + suffix = ".tmp"; + } + File tmpDirFile = directory; + if (tmpDirFile == null) { + String tmpDir = System.getProperty("java.io.tmpdir", "."); + tmpDirFile = new File(tmpDir); + } + + String nameFormat = getResources().getString(R.string.def_save_name_format); + SimpleDateFormat df = new SimpleDateFormat(nameFormat); + String currentTime = df.format(System.currentTimeMillis()); + + File result; + do { + result = new File(tmpDirFile, prefix + currentTime + suffix); + } while (!result.createNewFile()); + return result; + } + public boolean startRecording() { int mRecordDuration = -1; @@ -1147,12 +1173,27 @@ public class FMRadioService extends Service } mSampleFile = null; - File sampleDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/FMRecording"); + File sampleDir = null; + if (!"".equals(getResources().getString(R.string.def_fmRecord_savePath))) { + String fmRecordSavePath = getResources().getString(R.string.def_fmRecord_savePath); + sampleDir = new File(Environment.getExternalStorageDirectory().toString() + + fmRecordSavePath); + } else { + sampleDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + + "/FMRecording"); + } + if(!(sampleDir.mkdirs() || sampleDir.isDirectory())) return false; try { - mSampleFile = File - .createTempFile("FMRecording", ".3gpp", sampleDir); + if (getResources().getBoolean(R.bool.def_save_name_format_enabled)) { + String suffix = getResources().getString(R.string.def_save_name_suffix); + suffix = "".equals(suffix) ? ".3gpp" : suffix; + String prefix = getResources().getString(R.string.def_save_name_prefix) + '-'; + mSampleFile = createTempFile(prefix, suffix, sampleDir); + } else { + mSampleFile = File.createTempFile("FMRecording", ".3gpp", sampleDir); + } } catch (IOException e) { Log.e(LOGTAG, "Not able to access SD Card"); Toast.makeText(this, "Not able to access SD Card", Toast.LENGTH_SHORT).show();