diff options
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(); |