Merge "FM: Fix the audio noise issue"
diff --git a/FMRecord/res/values-zh-rCN/strings.xml b/FMRecord/res/values-zh-rCN/strings.xml
index a55ae4b..660f743 100644
--- a/FMRecord/res/values-zh-rCN/strings.xml
+++ b/FMRecord/res/values-zh-rCN/strings.xml
@@ -41,4 +41,6 @@
     <!-- all recordings will show up in the media database in a playlist with this name -->
     <string name="audio_db_playlist_name">FM 录音</string>
     <string name="fm_record_progress">FM 录音进行中</string>
+    <string name="FMRecording_reach_size_limit">已到达最长限制.</string>
+    <string name="unable_to_store">无法保存已录音频</string>
 </resources>
diff --git a/FMRecord/res/values/strings.xml b/FMRecord/res/values/strings.xml
index ff11d19..244d41c 100644
--- a/FMRecord/res/values/strings.xml
+++ b/FMRecord/res/values/strings.xml
@@ -47,4 +47,5 @@
     <string name="audio_db_playlist_name">FM recordings</string>
     <string name="save_record_file">FM Recorded file saved to "<xliff:g id="record_file">%1$s</xliff:g>"</string>
     <string name="fm_record_progress">FM Recording in progress</string>
+    <string name="unable_to_store">Unable to save recorded audio</string>
 </resources>
diff --git a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
index fc0fc21..62f4a94 100644
--- a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
+++ b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
@@ -259,7 +259,10 @@
 
         }
         mSampleFile = null;
-        File sampleDir = Environment.getExternalStorageDirectory();
+        File sampleDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/FMRecording");
+
+        if(!(sampleDir.mkdirs() || sampleDir.isDirectory()))
+            return false;
 
         try {
              mSampleFile = File.createTempFile("FMRecording", ".3gpp", sampleDir);
@@ -309,9 +312,12 @@
                          Log.d(TAG, "Maximum file size/duration reached, stopping the recording");
                          stopRecord();
                      }
-                     // Show the toast.
-                     Toast.makeText(FMRecordingService.this, R.string.FMRecording_reach_size_limit,
-                               Toast.LENGTH_LONG).show();
+                     if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
+                         // Show the toast.
+                         Toast.makeText(FMRecordingService.this,
+                                        R.string.FMRecording_reach_size_limit,
+                                        Toast.LENGTH_LONG).show();
+                     }
                  }
              }
              // from MediaRecorder.OnErrorListener
@@ -417,7 +423,7 @@
         Log.d(TAG, "ContentURI: " + base);
         Uri result = resolver.insert(base, cv);
         if (result == null) {
-            Toast.makeText(this, "Unable to save recorded audio", Toast.LENGTH_SHORT).show();
+            Toast.makeText(this, R.string.unable_to_store, Toast.LENGTH_SHORT).show();
             return null;
         }
         if (getPlaylistId(res) == -1) {
@@ -469,7 +475,7 @@
         cv.put(MediaStore.Audio.Playlists.NAME, res.getString(R.string.audio_db_playlist_name));
         Uri uri = resolver.insert(MediaStore.Audio.Playlists.getContentUri("external"), cv);
         if (uri == null) {
-            Toast.makeText(this, "Unable to save recorded audio", Toast.LENGTH_SHORT).show();
+            Toast.makeText(this, R.string.unable_to_store, Toast.LENGTH_SHORT).show();
         }
         return uri;
     }
diff --git a/fmapp2/res/values-zh-rCN/strings.xml b/fmapp2/res/values-zh-rCN/strings.xml
index 76936b7..d32c0cd 100644
--- a/fmapp2/res/values-zh-rCN/strings.xml
+++ b/fmapp2/res/values-zh-rCN/strings.xml
@@ -115,5 +115,6 @@
     <string name="chanl_spacing">信道间隔</string>
     <string name="set">设置</string>
     <string name="cancel">取消</string>
-	<string name="rt_plus_tags">标签</string>
+    <string name="rt_plus_tags">标签</string>
+    <string name="user_defind_band_msg">请输入有效的频段范围 76.0 - 108.0</string>
 </resources>
diff --git a/fmapp2/res/values/strings.xml b/fmapp2/res/values/strings.xml
index 146866a..a2bf1d4 100644
--- a/fmapp2/res/values/strings.xml
+++ b/fmapp2/res/values/strings.xml
@@ -263,5 +263,6 @@
     <string name="band_sweep_choose">Choose Band Sweep Method</string>
     <string name="set">Set</string>
     <string name="cancel">Cancel</string>
+    <string name="user_defind_band_msg">Enter Freq from range 76.0 - 108.0</string>
 
 </resources>
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index 9e9cb74..1f2f60f 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -1777,6 +1777,12 @@
       if (isFmRecordingOn())
       {
           stopRecording();
+          try {
+               Thread.sleep(300);
+          } catch (Exception ex) {
+               Log.d( LOGTAG, "RunningThread InterruptedException");
+               return;
+          }
       }
       AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
       if(audioManager != null)
diff --git a/fmapp2/src/com/caf/fmradio/HorizontalNumberPicker.java b/fmapp2/src/com/caf/fmradio/HorizontalNumberPicker.java
index ac886bb..505097f 100644
--- a/fmapp2/src/com/caf/fmradio/HorizontalNumberPicker.java
+++ b/fmapp2/src/com/caf/fmradio/HorizontalNumberPicker.java
@@ -1600,7 +1600,11 @@
         for (int i = 0; i < mSelectorIndices.length; i++) {
             int selectorIndex = current + (i - mSelectorMiddleItemIndex);
             if (mWrapSelectorWheel) {
-                selectorIndex = getWrappedSelectorIndex(selectorIndex);
+                try {
+                    selectorIndex = getWrappedSelectorIndex(selectorIndex);
+                } catch(RuntimeException e) {
+                    e.printStackTrace();
+                }
             }
             mSelectorIndices[i] = selectorIndex;
             ensureCachedScrollSelectorValue(mSelectorIndices[i]);
@@ -1622,7 +1626,11 @@
         }
         // Wrap around the values if we go past the start or end
         if (mWrapSelectorWheel) {
-            current = getWrappedSelectorIndex(current);
+            try {
+                current = getWrappedSelectorIndex(current);
+            } catch(RuntimeException e) {
+                e.printStackTrace();
+            }
         }
         int previous = mValue;
         setValue(current);
diff --git a/fmapp2/src/com/caf/fmradio/Settings.java b/fmapp2/src/com/caf/fmradio/Settings.java
index d64621b..03f88c1 100644
--- a/fmapp2/src/com/caf/fmradio/Settings.java
+++ b/fmapp2/src/com/caf/fmradio/Settings.java
@@ -317,7 +317,8 @@
                   setBandSummary(summaryBandItems.length - 1);
                   clearStationList();
                }else {
-                  displayToast(USR_BAND_MSG);
+                  Toast.makeText(this, getString(R.string.user_defind_band_msg),
+                                                            Toast.LENGTH_SHORT).show();
                }
            }else if(key.equals(USER_DEFINED_BAND_MAX_KEY)) {
                String valStr = mUserBandMaxPref.getText();
@@ -336,7 +337,8 @@
                   setBandSummary(summaryBandItems.length - 1);
                   clearStationList();
                }else {
-                  displayToast(USR_BAND_MSG);
+                  Toast.makeText(this, getString(R.string.user_defind_band_msg),
+                                                            Toast.LENGTH_SHORT).show();
                }
           }else {
               if(mRxMode) {