FM: Regional requirement for FM

1. Add resource to customize FM-recorder files name format;
2. Add resource to customize the save path of FM-recorder files;
3. Add resource to customize media type;
4. Add a new bool resource to seek next station by headset hook;
5. Add a new string resource to set FM radio default country;
6. Add a new bool resource to customize the output list;
7. Add resource to customize frequency range for india.

Change-Id: Ic794ff3c3040f18a5fe6f1e65960a8b89bcd8d37
diff --git a/FMRecord/res/values/customize.xml b/FMRecord/res/values/customize.xml
new file mode 100644
index 0000000..1ef358c
--- /dev/null
+++ b/FMRecord/res/values/customize.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (c) 2014, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+    <!-- enabled the prefix of recordings files name or not,default value is false -->
+    <bool name="def_save_name_prefix_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>
+
+    <!-- enabled the name format of recordings files or not,default value is false -->
+    <bool name="def_save_name_format_enabled">false</bool>
+
+    <!-- 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">/SoundRecorder</string>
+
+    <!-- the suffix of recordings files.default value is ".3gpp" -->
+    <string name="def_save_name_suffix" translatable="false">.3gpp</string>
+
+</resources>
diff --git a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
index e101584..2aa1684 100644
--- a/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
+++ b/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
@@ -233,11 +233,25 @@
         mSampleFile = null;
         File sampleDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/FMRecording");
 
+        if (getResources().getBoolean(R.bool.def_save_name_prefix_enabled)) {
+            String fmRecordSavePath = getApplicationContext().getResources()
+                    .getString(R.string.def_fmRecord_savePath);
+            sampleDir = new File(Environment.getExternalStorageDirectory().toString()
+                    + fmRecordSavePath);
+            if (!sampleDir.exists()) {
+                sampleDir.mkdirs();
+            }
+        }
         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;
+                mSampleFile = createTempFile("FMRecording", suffix, sampleDir);
+            }
         } catch (IOException e) {
              Log.e(TAG, "Not able to access SD Card");
              Toast.makeText(this, "Not able to access SD Card", Toast.LENGTH_SHORT).show();
@@ -602,4 +616,30 @@
        }
    }
 
+    public File createTempFile(String prefix, String suffix, File directory)
+            throws IOException {
+        prefix = getResources().getString(R.string.def_save_name_prefix) + '-';
+        // 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;
+   }
 }
diff --git a/fmapp2/res/values/arrays.xml b/fmapp2/res/values/arrays.xml
index 442ffc3..16b48e4 100644
--- a/fmapp2/res/values/arrays.xml
+++ b/fmapp2/res/values/arrays.xml
@@ -38,6 +38,14 @@
     <item>1</item>
   </string-array>
 
+  <string-array name="ster_entries">
+    <item>Stereo</item>
+  </string-array>
+
+  <string-array name="ster_values">
+    <item>0</item>
+  </string-array>
+
   <string-array name="record_durations_entries">
     <item>5 minutes</item>
     <item>15 minutes</item>
diff --git a/fmapp2/res/values/customize.xml b/fmapp2/res/values/customize.xml
new file mode 100644
index 0000000..f24c67c
--- /dev/null
+++ b/fmapp2/res/values/customize.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (c) 2014, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<resources>
+
+    <!-- enabled the headset button function to seek next station or not,default value is false -->
+    <bool name="def_headset_next_enabled">false</bool>
+
+    <!--
+        customize the the country for fm,
+        default value is false,true is for INDIA
+    -->
+    <bool name="def_fm_country_location_enabled">false</bool>
+
+    <!--
+        customize the the special carrier for fm,
+        default value is false,true is for Micromax
+    -->
+    <bool name="def_fm_special_carrier_enabled">false</bool>
+
+    <!--
+        customize the output list,true is stereo only, false is stereo and mono,
+            default value is false
+    -->
+    <bool name="def_only_stereo_enabled">false</bool>
+
+</resources>
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index f643ec3..71e59ed 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -440,6 +440,12 @@
                          int keycode = event.getKeyCode();
                          switch (keycode) {
                              case KeyEvent.KEYCODE_HEADSETHOOK :
+                                 if (isFmOn() && getResources()
+                                        .getBoolean(R.bool.def_headset_next_enabled)) {
+                                     Log.d(LOGTAG, "enabled the headset button function to seek next station");
+                                     seek(true);
+                                     break;
+                                 }
                                  toggleFM();
                                  if (isOrderedBroadcast()) {
                                      abortBroadcast();
diff --git a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
index 1bed45c..2e2aa70 100644
--- a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
+++ b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -39,6 +39,7 @@
 import android.content.SharedPreferences;
 import qcom.fmradio.FmReceiver;
 import qcom.fmradio.FmConfig;
+import android.os.SystemProperties;
 import android.util.Log;
 
 public class FmSharedPreferences
@@ -167,6 +168,7 @@
    private static boolean mAFAutoSwitch = true;
    private static int mRecordDuration = 0;
    private static int mLastAudioMode = -1;
+   private static boolean mSpecialCarrierFlag = false;
 
    FmSharedPreferences(Context context){
       mContext = context.getApplicationContext();
@@ -446,6 +448,8 @@
       {
          return;
       }
+      mSpecialCarrierFlag = mContext.getResources().getBoolean(
+              R.bool.def_fm_special_carrier_enabled);
       SharedPreferences sp = mContext.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
       mTunedFrequency = sp.getInt(PREF_LAST_TUNED_FREQUENCY, DEFAULT_NO_FREQUENCY);
       mRecordDuration = sp.getInt(LAST_RECORD_DURATION, RECORD_DUR_INDEX_0_VAL);
@@ -498,6 +502,9 @@
       /* Load Configuration */
       if (Locale.getDefault().equals(Locale.CHINA)) {
           setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_CHINA));
+        } else if (mContext.getResources()
+                .getBoolean(R.bool.def_fm_country_location_enabled)) {
+            setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_INDIA));
       } else {
           setCountry(sp.getInt(FMCONFIG_COUNTRY, REGIONAL_BAND_NORTH_AMERICA));
       }
@@ -929,9 +936,15 @@
         }
         case REGIONAL_BAND_INDIA:
         {
-          /*INDIA : 91000 TO 106400 IN 100 KHZ STEPS*/
-          mFMConfiguration.setLowerLimit(91000);
-          mFMConfiguration.setUpperLimit(106400);
+          if (mSpecialCarrierFlag) {
+              /*87500 TO 108000 IN 100 KHZ STEPS*/
+              mFMConfiguration.setLowerLimit(87500);
+              mFMConfiguration.setUpperLimit(108000);
+          } else {
+              /*91000 TO 106400 IN 100 KHZ STEPS*/
+              mFMConfiguration.setLowerLimit(91000);
+              mFMConfiguration.setUpperLimit(106400);
+          }
           mFrequencyBand_Stepsize = 100;
           break;
         }
diff --git a/fmapp2/src/com/caf/fmradio/Settings.java b/fmapp2/src/com/caf/fmradio/Settings.java
index 83df2e1..e6adb21 100644
--- a/fmapp2/src/com/caf/fmradio/Settings.java
+++ b/fmapp2/src/com/caf/fmradio/Settings.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -158,22 +158,32 @@
            root.addPreference(mUserBandMinPref);
            root.addPreference(mUserBandMaxPref);
 
+           boolean audiomode = FmSharedPreferences.getAudioOutputMode();
            if (mRxMode) {
                // Audio Output (Stereo or Mono)
-               summaryAudioModeItems = getResources().getStringArray(
-                                        R.array.ster_mon_entries);
-               mAudioPreference = new ListPreference(this);
-               mAudioPreference.setEntries(R.array.ster_mon_entries);
-               mAudioPreference.setEntryValues(R.array.ster_mon_values);
+               if (getResources().getBoolean(R.bool.def_only_stereo_enabled)) {
+                   summaryAudioModeItems = getResources()
+                           .getStringArray(R.array.ster_entries);
+                   mAudioPreference = new ListPreference(this);
+                   mAudioPreference.setEntries(R.array.ster_entries);
+                   mAudioPreference.setEntryValues(R.array.ster_values);
+                   index = 0;
+               } else {
+                   summaryAudioModeItems = getResources()
+                           .getStringArray(R.array.ster_mon_entries);
+                   mAudioPreference = new ListPreference(this);
+                   mAudioPreference.setEntries(R.array.ster_mon_entries);
+                   mAudioPreference.setEntryValues(R.array.ster_mon_values);
+                   if (audiomode) {
+                      index = 0;
+                   } else {
+                      index = 1;
+                   }
+               }
                mAudioPreference.setDialogTitle(R.string.sel_audio_output);
                mAudioPreference.setKey(AUDIO_OUTPUT_KEY);
                mAudioPreference.setTitle(R.string.aud_output_mode);
-               boolean audiomode = FmSharedPreferences.getAudioOutputMode();
-               if (audiomode) {
-                   index = 0;
-               } else {
-                   index = 1;
-               }
+
                Log.d(LOGTAG, "createPreferenceHierarchy: audiomode: " + audiomode);
                mAudioPreference.setSummary(summaryAudioModeItems[index]);
                mAudioPreference.setValueIndex(index);