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/FMRadio.java b/fmapp2/src/com/caf/fmradio/FMRadio.java index 20b1133784296a9a3e0d52ac9c8eff55296e60f2..909a14c0f63c73d291a2f4af2f4bc7d6be31916d 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadio.java +++ b/fmapp2/src/com/caf/fmradio/FMRadio.java @@ -1679,7 +1679,6 @@ public class FMRadio extends Activity private void disableRadio() { boolean bStatus = false; - boolean bSpeakerPhoneOn = isSpeakerEnabled(); cancelSearch(); endSleepTimer(); @@ -1698,11 +1697,6 @@ public class FMRadio extends Activity } enableRadioOnOffUI(); - // restore default wired headset on FM power off - if (bSpeakerPhoneOn) { - mService.enableSpeaker(false); - mSpeakerButton.setImageResource(R.drawable.btn_earphone); - } }catch (RemoteException e) { e.printStackTrace(); } @@ -3197,6 +3191,16 @@ public class FMRadio extends Activity Log.d(LOGTAG, "mServiceCallbacks.onA2DPConnectionstateChanged :"); A2DPConnectionState(state); } + public void onFmAudioPathStarted() { + Log.d(LOGTAG, "mServiceCallbacks.onFmAudioPathStarted:"); + mSpeakerButton.setClickable(true); + mMuteButton.setClickable(true); + } + public void onFmAudioPathStopped() { + Log.d(LOGTAG, "mServiceCallbacks.onFmAudioPathStopped:"); + mSpeakerButton.setClickable(false); + mMuteButton.setClickable(false); + } }; private void registerFMSettingListner() { diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java index 188a0685c8be4236c2f76a252becad103d905dc0..a4fce5d75a4086f71355c47856fa5d848705ea78 100644 --- a/fmapp2/src/com/caf/fmradio/FMRadioService.java +++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java @@ -967,7 +967,8 @@ public class FMRadioService extends Service if (isFmOn() && getResources() .getBoolean(R.bool.def_headset_next_enabled)) { try { - mCallbacks.onSeekNextStation(); + if ((mServiceInUse) && (mCallbacks != null)) + mCallbacks.onSeekNextStation(); }catch (RemoteException e) { } } @@ -1012,7 +1013,7 @@ public class FMRadioService extends Service } }; - private void startFM(){ + private void startFM() { Log.d(LOGTAG, "In startFM"); if(true == mAppShutdown) { // not to send intent to AudioManager in Shutdown return; @@ -1065,12 +1066,24 @@ public class FMRadioService extends Service } mPlaybackInProgress = true; configureAudioDataPath(true); + try { + if ((mServiceInUse) && (mCallbacks != null)) + mCallbacks.onFmAudioPathStarted(); + } catch(RemoteException e) { + e.printStackTrace(); + } } - private void stopFM(){ + private void stopFM() { Log.d(LOGTAG, "In stopFM"); configureAudioDataPath(false); mPlaybackInProgress = false; + try { + if ((mServiceInUse) && (mCallbacks != null)) + mCallbacks.onFmAudioPathStopped(); + } catch(RemoteException e) { + e.printStackTrace(); + } } private void resetFM(){ @@ -1094,6 +1107,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; @@ -1137,12 +1176,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(); @@ -2127,6 +2181,7 @@ public class FMRadioService extends Service * Turn OFF FM Operations: This disables all the current FM operations . */ private void fmOperationsOff() { + // stop recording if (isFmRecordingOn()) { stopRecording(); @@ -2137,14 +2192,19 @@ public class FMRadioService extends Service return; } } + // disable audio path AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if(audioManager != null) { Log.d(LOGTAG, "audioManager.setFmRadioOn = false \n" ); stopFM(); - //audioManager.setParameters("FMRadioOn=false"); Log.d(LOGTAG, "audioManager.setFmRadioOn false done \n" ); } + // reset FM audio settings + if (isSpeakerEnabled() == true) + enableSpeaker(false); + if (isMuted() == true) + unMute(); if (isAnalogModeEnabled()) { SystemProperties.set("hw.fm.isAnalog","false"); diff --git a/fmapp2/src/com/caf/fmradio/FMStats.java b/fmapp2/src/com/caf/fmradio/FMStats.java index 961f04b457a0cf0b94218bb673c1d72a33b5d43f..c035475b245b77d99737be43d4183d5df1050f2a 100644 --- a/fmapp2/src/com/caf/fmradio/FMStats.java +++ b/fmapp2/src/com/caf/fmradio/FMStats.java @@ -2719,6 +2719,12 @@ public class FMStats extends Activity { public void onA2DPConnectionstateChanged(boolean state){ Log.d(LOGTAG, "mServiceCallbacks.onA2DPConnectionstateChanged :"); } + public void onFmAudioPathStarted() { + Log.d(LOGTAG, "mServiceCallbacks.onFmAudioPathStarted:"); + } + public void onFmAudioPathStopped() { + Log.d(LOGTAG, "mServiceCallbacks.onFmAudioPathStopped:"); + } }; /* Radio Vars */ private Handler mHandler = new Handler(); diff --git a/fmapp2/src/com/caf/fmradio/IFMRadioServiceCallbacks.aidl b/fmapp2/src/com/caf/fmradio/IFMRadioServiceCallbacks.aidl index e6fded791bdd363d030c895f49d2e87ab7e05c7c..24aaa7001be7a5c70651f52056ccc9580934b14e 100644 --- a/fmapp2/src/com/caf/fmradio/IFMRadioServiceCallbacks.aidl +++ b/fmapp2/src/com/caf/fmradio/IFMRadioServiceCallbacks.aidl @@ -48,4 +48,6 @@ interface IFMRadioServiceCallbacks void onRecordingStarted(); void onSeekNextStation(); void onA2DPConnectionstateChanged(boolean state); + void onFmAudioPathStarted(); + void onFmAudioPathStopped(); } diff --git a/libfm_jni/LibfmJni.cpp b/libfm_jni/LibfmJni.cpp index d1a09428e1b2965b726b8b739b52a3c846cf4155..52ad029e9f3716ff6d9f1b155014984075414397 100644 --- a/libfm_jni/LibfmJni.cpp +++ b/libfm_jni/LibfmJni.cpp @@ -114,32 +114,18 @@ jboolean SetFreq(JNIEnv *env, jobject thiz, jfloat freq) jfloat Seek(JNIEnv *env, jobject thiz, jfloat freq, jboolean isUp) { - int ret = 0; - int tmp_freq; - int ret_freq; - float val; + int ret = JNI_FALSE; + float val = freq; - tmp_freq = (int)(freq * FREQ_MULT); //Eg, 87.55 * 100 --> 87550 - if (pFMRadio) + if (pFMRadio) { ret = pFMRadio->Set_mute(true); - else - ret = JNI_FALSE; - if (ret) { - ALOGE("%s, error, [ret=%d]\n", __func__, ret); - } - ALOGD("%s, [mute] [ret=%d]\n", __func__, ret); - if (pFMRadio) + ALOGD("%s, [mute] [ret=%d]\n", __func__, ret); ret = pFMRadio->Seek((int)isUp); - else - ret = JNI_FALSE; - if (ret < 0) { - ret_freq = tmp_freq; //seek error, so use original freq + ALOGD("%s, [freq=%f] [ret=%d]\n", __func__, freq, ret); + if (ret > 0) + val = (float)ret/FREQ_MULT; //Eg, 8755 / 100 --> 87.55 } - ALOGD("%s, [freq=%d] [ret=%d]\n", __func__, ret_freq, ret); - - val = (float)ret/FREQ_MULT; //Eg, 8755 / 100 --> 87.55 - return val; }