diff options
author | Xuebo Li <xuebol@codeaurora.org> | 2015-11-03 16:37:16 +0800 |
---|---|---|
committer | Arne Coucheron <arco68@gmail.com> | 2016-03-22 00:14:08 +0100 |
commit | 40a5d4be4ec96d589f419f48349677dc7c0d89ea (patch) | |
tree | 2164c58f604402cf8bdf4c4adabf56a4c588452a /fmapp2/src/com | |
parent | bd28479d329965aefbf5c7a2472ace6c9c578d74 (diff) | |
download | android_hardware_qcom_fm-40a5d4be4ec96d589f419f48349677dc7c0d89ea.tar.gz android_hardware_qcom_fm-40a5d4be4ec96d589f419f48349677dc7c0d89ea.tar.bz2 android_hardware_qcom_fm-40a5d4be4ec96d589f419f48349677dc7c0d89ea.zip |
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: I5d547ec691d44621b19b2c8435c290b8eafeabc5
CRs-Fixed: 933506
Diffstat (limited to 'fmapp2/src/com')
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FMRadioService.java | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 61aabd7..478fedf 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -1145,6 +1145,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; @@ -1181,12 +1207,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", ".aac", 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(); |