FM: Regional requirement for FM
Add resource to customize FM-recorder files name format.
Add resource to customize the save path of FM-recorder files.
Add resource to customize media type.
Change-Id: I348424f3184b2603492db285695b95070e434037
CRs-Fixed: 979034
diff --git a/fmapp2/res/values/customize.xml b/fmapp2/res/values/customize.xml
index f24c67c..f4dcdbc 100644
--- a/fmapp2/res/values/customize.xml
+++ b/fmapp2/res/values/customize.xml
@@ -50,4 +50,19 @@
-->
<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 83018f5..9afd671 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -1104,6 +1104,32 @@
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 @@
}
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();