Merge "FM-APP2: Fix the issue Setting always displays stereo"
diff --git a/fmapp/res/values/arrays.xml b/fmapp/res/values/arrays.xml
index c453c6a..2fbe0d2 100644
--- a/fmapp/res/values/arrays.xml
+++ b/fmapp/res/values/arrays.xml
@@ -311,7 +311,7 @@
     <item>Netherlands (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>New Zealand (88.0MHz To 107.0MHz In 100 Khz Steps)</item>
     <item>Norway (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
-    <item>Poland (88.0MHz To 108.0MHz In 50 Khz Steps)</item>
+    <item>Poland (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>Portugal (87.5MHz To 108.0MHz In 50 Khz Steps)</item>
     <item>Russia (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>Singapore (88.0MHz To 108.0MHz In 100 Khz Steps)</item>
diff --git a/fmapp/src/com/codeaurora/fmradio/FMRadioService.java b/fmapp/src/com/codeaurora/fmradio/FMRadioService.java
index b3a2b42..3ca96e9 100644
--- a/fmapp/src/com/codeaurora/fmradio/FMRadioService.java
+++ b/fmapp/src/com/codeaurora/fmradio/FMRadioService.java
@@ -744,8 +744,10 @@
            //ACTION_FM=1 to AudioManager, the previous state of Speaker we set
            //need not be retained by the Audio Manager.
            if (isSpeakerEnabled()) {
-                   mSpeakerPhoneOn = true;
-                   AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_SPEAKER);
+               mSpeakerPhoneOn = true;
+               AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_SPEAKER);
+           } else {
+               AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_NONE);
            }
            AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM,
                                      AudioSystem.DEVICE_STATE_AVAILABLE, "");
diff --git a/fmapp/src/com/codeaurora/fmradio/FmSharedPreferences.java b/fmapp/src/com/codeaurora/fmradio/FmSharedPreferences.java
index ac4ac2c..247969c 100644
--- a/fmapp/src/com/codeaurora/fmradio/FmSharedPreferences.java
+++ b/fmapp/src/com/codeaurora/fmradio/FmSharedPreferences.java
@@ -990,11 +990,11 @@
         }
         case REGIONAL_BAND_POLAND:
         {
-          /*POLAND : 87500 TO 108000 IN 50 KHZ STEPS*/
+          /*POLAND : 87500 TO 108000 IN 100 KHZ STEPS*/
           mFMConfiguration.setRadioBand(FmReceiver.FM_EU_BAND);
-          mFMConfiguration.setChSpacing(FmReceiver.FM_CHSPACE_50_KHZ);
+          mFMConfiguration.setChSpacing(FmReceiver.FM_CHSPACE_100_KHZ);
           mFMConfiguration.setLowerLimit(87500);
-          mFrequencyBand_Stepsize = 50;
+          mFrequencyBand_Stepsize = 100;
           break;
         }
         case REGIONAL_BAND_PORTUGAL:
diff --git a/fmapp2/res/layout/band_sweep_setting.xml b/fmapp2/res/layout/band_sweep_setting.xml
new file mode 100644
index 0000000..777332c
--- /dev/null
+++ b/fmapp2/res/layout/band_sweep_setting.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     * Copyright (c) 2013 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:scrollbars="vertical"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_gravity="center_horizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent">
+
+        <TextView
+            android:id="@+id/lbl_band_sweep_spinner"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:text="@string/band_sweep_choose"/>
+
+        <Spinner
+            android:id="@+id/band_sweep_spinner"
+            android:layout_width="fill_parent"
+            android:layout_height="75dp"
+            android:layout_below="@id/lbl_band_sweep_spinner"
+            android:prompt="@string/band_method_prompt"
+            android:textSize="25sp"/>
+
+        <TextView
+            android:id="@+id/LabelStartdelay"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:layout_below="@id/band_sweep_spinner"
+            android:text="@string/enter_start_delay_time"/>
+
+        <EditText
+            android:id="@+id/txtboxDelayTime"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:inputType="number"
+            android:layout_toRightOf="@id/LabelStartdelay"/>
+
+        <TextView
+            android:id="@+id/LabelDwellTime"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:layout_below="@id/LabelStartdelay"
+            android:text="@string/enter_dwell_time"/>
+
+        <EditText
+            android:id="@+id/txtboxDwellTime"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:textSize="15sp"
+            android:inputType="number"
+            android:layout_toRightOf="@id/LabelDwellTime"/>
+
+    </LinearLayout>
+
+</ScrollView>
diff --git a/fmapp2/res/layout/fmstats.xml b/fmapp2/res/layout/fmstats.xml
index 2501a51..1cf8023 100644
--- a/fmapp2/res/layout/fmstats.xml
+++ b/fmapp2/res/layout/fmstats.xml
@@ -50,9 +50,18 @@
 
            <Button
                android:id= "@+id/Runbutton"
-               android:text="@string/test_run"
+               android:text="@string/band_sweep_setting"
                android:layout_width="wrap_content"
                android:layout_height="100dp"
+               android:textSize="25dp"
+               android:visibility="gone"/>
+
+           <TextView
+               android:id= "@+id/BandSweepSetting"
+               android:text="@string/band_sweep_setting"
+               android:layout_width="wrap_content"
+               android:layout_height="wrap_content"
+               android:layout_toRightOf="@id/Runbutton"
                android:textSize="25sp"
                android:visibility="gone"/>
 
diff --git a/fmapp2/res/values/arrays.xml b/fmapp2/res/values/arrays.xml
index d7904be..2fbe0d2 100644
--- a/fmapp2/res/values/arrays.xml
+++ b/fmapp2/res/values/arrays.xml
@@ -243,6 +243,7 @@
     <item>Turkey</item>
     <item>United Kingdom </item>
     <item>United States</item>
+    <item>User Defined Band</item>
   </string-array>
 
   <string-array name="regional_band_values">
@@ -282,6 +283,7 @@
     <item>33</item>
     <item>34</item>
     <item>35</item>
+    <item>36</item>
   </string-array>
 
   <string-array name="regional_band_summary">
@@ -309,7 +311,7 @@
     <item>Netherlands (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>New Zealand (88.0MHz To 107.0MHz In 100 Khz Steps)</item>
     <item>Norway (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
-    <item>Poland (88.0MHz To 108.0MHz In 50 Khz Steps)</item>
+    <item>Poland (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>Portugal (87.5MHz To 108.0MHz In 50 Khz Steps)</item>
     <item>Russia (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>Singapore (88.0MHz To 108.0MHz In 100 Khz Steps)</item>
@@ -321,6 +323,7 @@
     <item>Turkey (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>United Kingdom (87.5MHz To 108.0MHz In 100 Khz Steps)</item>
     <item>United States (88.1MHz To 107.9MHz In 200 Khz Steps)</item>
+    <item>User Defined Band</item>
   </string-array>
 
   <string-array name="rf_cfg">
@@ -368,4 +371,21 @@
       <item> RF Statistics</item>
   </string-array>
 
+  <string-array name="channel_spacing_val">
+      <item>2</item>
+      <item>1</item>
+      <item>0</item>
+  </string-array>
+
+  <string-array name="channel_spacing_entries">
+      <item>50 Khz</item>
+      <item>100 Khz</item>
+      <item>200 Khz</item>
+  </string-array>
+
+  <string-array name="band_sweep_methods">
+      <item>Manual</item>
+      <item>From File</item>
+  </string-array>
+
 </resources>
diff --git a/fmapp2/res/values/strings.xml b/fmapp2/res/values/strings.xml
index 12c9778..8fdc938 100644
--- a/fmapp2/res/values/strings.xml
+++ b/fmapp2/res/values/strings.xml
@@ -247,4 +247,17 @@
     <string name="enter_RxRePeatCount">Enter RxRePeat count</string>
     <string name="set_RxRePeatCount">Config RxRePeat count</string>
 
+    <string name="usr_def_band_min">Lower Freq Limit(In Mhz)</string>
+    <string name="usr_def_band_max">Higher Freq Limit(In Mhz)</string>
+    <string name="sel_chanl_spacing">Select Channel Spacing</string>
+    <string name="chanl_spacing">Channel Spacing</string>
+
+    <string name="band_method_prompt">Select Method</string>
+    <string name="enter_start_delay_time">Start Delay Time</string>
+    <string name="enter_dwell_time">Dwell Time</string>
+    <string name="band_sweep_setting">Sweep Setting</string>
+    <string name="band_sweep_setting_set">Set</string>
+    <string name="band_sweep_setting_cancel">Cancel</string>
+    <string name="band_sweep_choose">Choose Band Sweep Method</string>
+
 </resources>
diff --git a/fmapp2/src/com/caf/fmradio/FMRadioService.java b/fmapp2/src/com/caf/fmradio/FMRadioService.java
index df52734..a0df1ef 100644
--- a/fmapp2/src/com/caf/fmradio/FMRadioService.java
+++ b/fmapp2/src/com/caf/fmradio/FMRadioService.java
@@ -731,8 +731,10 @@
            //ACTION_FM=1 to AudioManager, the previous state of Speaker we set
            //need not be retained by the Audio Manager.
            if (isSpeakerEnabled()) {
-                   mSpeakerPhoneOn = true;
-                   AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_SPEAKER);
+               mSpeakerPhoneOn = true;
+               AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_SPEAKER);
+           } else {
+               AudioSystem.setForceUse(AudioSystem.FOR_MEDIA, AudioSystem.FORCE_NONE);
            }
            AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM,
                                AudioSystem.DEVICE_STATE_AVAILABLE, "");
diff --git a/fmapp2/src/com/caf/fmradio/FMStats.java b/fmapp2/src/com/caf/fmradio/FMStats.java
index 4014b8e..e587c08 100644
--- a/fmapp2/src/com/caf/fmradio/FMStats.java
+++ b/fmapp2/src/com/caf/fmradio/FMStats.java
@@ -55,6 +55,10 @@
 import android.widget.AdapterView.OnItemSelectedListener;
 import qcom.fmradio.FmReceiver;
 import android.os.SystemProperties;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.view.LayoutInflater;
+import android.content.DialogInterface;
 
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -62,7 +66,8 @@
 import java.io.OutputStreamWriter;
 import java.util.HashMap;
 import android.os.SystemProperties;
-
+import java.io.BufferedReader;
+import java.io.FileReader;
 
 public class FMStats extends Activity  {
 
@@ -77,12 +82,13 @@
 
     private FmReceiver mReceiver;
 
+    TextView  bandSweepSettingButton;
+
     /*Data structure for band*/
     private class Band {
-
-        public int lFreq;
-        public int hFreq;
-        public int Spacing;
+      public int lFreq;
+      public int hFreq;
+      public int Spacing;
     }
     /* Data structure for Result*/
     private class Result {
@@ -141,47 +147,51 @@
       public String getSINR() {
          return mSINR;
       }
-
     };
 
     /*constant column header*/
     Result mColumnHeader = new Result();
 
     boolean mTestRunning = false;
-    FmRfItemSelectedListener mSpinFmRfListener = new FmRfItemSelectedListener();
-    RfCfgItemSelectedListener mSpinRfCfgListener = new RfCfgItemSelectedListener();
+    FmRfItemSelectedListener mSpinFmRfListener =
+                                     new FmRfItemSelectedListener();
+    RfCfgItemSelectedListener mSpinRfCfgListener =
+                                     new RfCfgItemSelectedListener();
     CfgRfItemSelectedListener1 mSpinCfgRfListener1 = null;
     CfgRfItemSelectedListener2 mSpinCfgRfListener2 = null;
-
+    BandSweepMthdsSelectedListener mSweepMthdsListener =
+                                     new BandSweepMthdsSelectedListener();
 
     int  mTestSelected = 0;
     boolean mIsSearching = false;
     private static String LOGTAG = "FMStats";
     private static IFMRadioService mService = null;
-    private Thread mMultiUpdateThread =null;
-    private static final int STATUS_UPDATE =1;
-    private static final int STATUS_DONE =2;
-    private static final int STOP_ROW_ID =200;
+    private Thread mMultiUpdateThread = null;
+    private static final int STATUS_UPDATE = 1;
+    private static final int STATUS_DONE = 2;
+    private static final int STOP_ROW_ID = 200;
     private static final int NEW_ROW_ID = 300;
     private int mStopIds = STOP_ROW_ID;
     private int mNewRowIds = NEW_ROW_ID;
     private static final int SCAN_DWELL_PERIOD = 1;
 
-    private static final int CUR_FREQ_TEST =0;
+    private static final int CUR_FREQ_TEST = 0;
     private static final int CUR_MULTI_TEST = 1;
     private static final int SEARCH_TEST =2;
-    private static final int SWEEP_TEST =3;
-    private Band mBand =null;
+    private static final int SWEEP_TEST = 3;
+    private Band mBand = null;
     private Band mSync = null;
     int Lo = 1, Auto = 0;
 
-    private FileOutputStream mFileCursor =null;
+    private FileOutputStream mFileCursor = null;
     private String mCurrentFileName = null;
 
     Spinner spinOptionFmRf;
+    Spinner spinOptionBandSweepMthds;
     ArrayAdapter<CharSequence> adaptCfgRf;
     ArrayAdapter<CharSequence> adaptRfCfg;
     ArrayAdapter<CharSequence> adaptFmRf;
+    ArrayAdapter<CharSequence> bandSweepMthds;
 
     private static boolean mIsTransportSMD = false;
 
@@ -204,27 +214,42 @@
     private static final int MIN_AF_JMP_RMSSI_SAMPLES = 0;
     private static final int MAX_AF_JMP_RMSSI_SAMPLES = 255;
 
+    private static final int DIALOG_BAND_SWEEP_SETTING = 1;
+
+    private int prevDwellTime = 2; //2secs
+    private int prevDelayTime = 0;//0secs
+    private int prevSweepMthd = 0; //Manual (using band min, max)
+
+    private int curSweepMthd = 0;
+
+    private final String FREQ_LIST_FILE_NAME = "/freq_list_comma_separated.txt";
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         this.setContentView(R.layout.fmstats);
 
-        spinOptionFmRf = (Spinner) findViewById(R.id.spinner);
-        adaptFmRf = ArrayAdapter.createFromResource(
-            this, R.array.stats_options, android.R.layout.simple_spinner_item);
-        adaptFmRf.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+        spinOptionFmRf = (Spinner)findViewById(R.id.spinner);
+        adaptFmRf = ArrayAdapter.createFromResource
+                       (this, R.array.stats_options
+                         , android.R.layout.simple_spinner_item);
+        adaptFmRf.setDropDownViewResource
+                   (android.R.layout.simple_spinner_dropdown_item);
         if (spinOptionFmRf != null) {
            spinOptionFmRf.setAdapter(adaptFmRf);
            spinOptionFmRf.setOnItemSelectedListener(mSpinFmRfListener);
         }
 
+        bandSweepMthds = ArrayAdapter.createFromResource
+                          (this, R.array.band_sweep_methods,
+                            android.R.layout.simple_spinner_item);
+
         checkTransportLayer();
         if (!isTransportLayerSMD()) {
             mSpinCfgRfListener1 = new CfgRfItemSelectedListener1();
             adaptCfgRf = ArrayAdapter.createFromResource(
                            this, R.array.cfg_rf1,
                            android.R.layout.simple_spinner_item);
-        } else {
+        }else {
             mSpinCfgRfListener2 = new CfgRfItemSelectedListener2();
             adaptCfgRf = ArrayAdapter.createFromResource(
                            this, R.array.cfg_rf2,
@@ -238,194 +263,206 @@
         if(mReceiver == null)
             mReceiver = new FmReceiver();
 
-        long  curTime = System.currentTimeMillis();
-        mCurrentFileName = "FMStats_".concat(Long.toString(curTime).concat(".txt"));
-        Log.e(LOGTAG,"Filename is "+mCurrentFileName);
+        long curTime = System.currentTimeMillis();
+        mCurrentFileName = "FMStats_".concat(
+                                 Long.toString(curTime).concat(".txt")
+                              );
+        Log.e(LOGTAG,"Filename is " + mCurrentFileName);
         try {
-            mFileCursor = openFileOutput(mCurrentFileName, Context.MODE_PRIVATE);
+            mFileCursor = openFileOutput(
+                                 mCurrentFileName,
+                                 Context.MODE_PRIVATE);
             if(null != mFileCursor) {
                Log.e(LOGTAG, "location of the file is"+getFilesDir());
             }
-        } catch (IOException e) {
-             e.printStackTrace();
+        }catch (IOException e) {
+            e.printStackTrace();
             Log.e(LOGTAG,"Couldn't create the file to writeLog");
             mCurrentFileName = null;
         }
 
-        if (false == bindToService(this, osc))
-        {
-           Log.d(LOGTAG, "onCreate: Failed to Start Service");
-        }
-        else
-        {
-           Log.d(LOGTAG, "onCreate: Start Service completed successfully");
+        if (false == bindToService(this, osc)) {
+            Log.d(LOGTAG, "onCreate: Failed to Start Service");
+        }else {
+            Log.d(LOGTAG, "onCreate: Start Service completed successfully");
         }
 
-	/*Initialize the column header with
-	constant values*/
-	mColumnHeader.setFreq("Freq");
-	mColumnHeader.setRSSI("RMSSI");
-	mColumnHeader.setIoC("IoC");
+        /*Initialize the column header with
+        constant values*/
+        mColumnHeader.setFreq("Freq");
+        mColumnHeader.setRSSI("RMSSI");
+        mColumnHeader.setIoC("IoC");
         mColumnHeader.setSINR("SINR");
-	mColumnHeader.setMpxDcc("Offset");
-	mColumnHeader.setIntDet("IntDet");
+        mColumnHeader.setMpxDcc("Offset");
+        mColumnHeader.setIntDet("IntDet");
+
+        bandSweepSettingButton = (TextView)findViewById(R.id.BandSweepSetting);
+        if(bandSweepSettingButton != null) {
+           bandSweepSettingButton.setOnClickListener(mClicktBandSweepSettingListener);
+        }
     }
 
     public void onDestroy() {
         if(null != mFileCursor ) {
-	    try {
-		mFileCursor.close();
+            try {
+                mFileCursor.close();
             } catch (IOException e) {
-
                 e.printStackTrace();
             }
         }
-	/*Stop the thread by interrupting it*/
-	if(mMultiUpdateThread != null) {
-		mMultiUpdateThread.interrupt();
-		mMultiUpdateThread = null;
-	}
-	/*Stop the search/scan if there is an ongoing*/
+        /*Stop the thread by interrupting it*/
+        if(mMultiUpdateThread != null) {
+           mMultiUpdateThread.interrupt();
+           mMultiUpdateThread = null;
+        }
+        /*Stop the search/scan if there is an ongoing*/
         if(SEARCH_TEST == mTestSelected)
         {
-		Log.d(LOGTAG, "Stop Search\n");
-		try {
-                    mService.cancelSearch();
-                } catch (RemoteException e) {
-                     e.printStackTrace();
-                }
+           Log.d(LOGTAG, "Stop Search\n");
+           try {
+                 mService.cancelSearch();
+           } catch (RemoteException e) {
+                 e.printStackTrace();
+           }
         }
 
         unbindFromService(this);
         Log.d(LOGTAG, "onDestroy: unbindFromService completed");
         mReceiver = null;
         mService = null;
+        removeDialog(DIALOG_BAND_SWEEP_SETTING);
         super.onDestroy();
     }
 
     private View.OnClickListener mOnRunListener = new View.OnClickListener() {
-       public void onClick(View v) {
-          if(false == mTestRunning)
-          {
+        public void onClick(View v) {
+           if(false == mTestRunning) {
               clearPreviousTestResults();
               mTestRunning = true;
+              if(mTestSelected == SWEEP_TEST) {
+                 disableBandSweepSetting();
+              }
               runCurrentTest();
-          }
-          else
-          {
+           }else {
               mTestRunning = false;
               /*Set it back to ready to Run*/
               SetButtonState(true);
-		/*Stop the thread by interrupting it*/
-	      if(mMultiUpdateThread != null) {
-	            mMultiUpdateThread.interrupt();
-		    mMultiUpdateThread = null;
-	      }
+              /*Stop the thread by interrupting it*/
+              if(mMultiUpdateThread != null) {
+                 mMultiUpdateThread.interrupt();
+                 mMultiUpdateThread = null;
+              }
 
-              if(SEARCH_TEST == mTestSelected )
-              {
+              if(SEARCH_TEST == mTestSelected) {
                  try {
                       mService.cancelSearch();
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                       e.printStackTrace();
                  }
               }
-          }
+              if(mTestSelected == SWEEP_TEST) {
+                 enableBandSweepSetting();
+              }
+           }
        }
     };
 
-   private void clearPreviousTestResults()
-   {
-       TableLayout tl = (TableLayout) findViewById(R.id.maintable);
+    private void clearPreviousTestResults() {
+       TableLayout tl = (TableLayout)findViewById(R.id.maintable);
        if (tl != null) {
-          tl.removeAllViewsInLayout();
+           tl.removeAllViewsInLayout();
        }
        mNewRowIds = NEW_ROW_ID;
-   }
+    }
 
-
-    private void SetButtonState(boolean state)
-    {
-        // Get the TableRow
-        Button RunButton = (Button)findViewById(R.id.Runbutton);
-        ProgressBar  pbar = (ProgressBar) findViewById(R.id.progressbar);
-        /*Update the state of the button based on
+    private void SetButtonState(boolean state) {
+       // Get the TableRow
+       Button RunButton = (Button)findViewById(R.id.Runbutton);
+       ProgressBar  pbar = (ProgressBar)findViewById(R.id.progressbar);
+       /*Update the state of the button based on
         state*/
-        if( state )
-        {
-            if (RunButton != null) {
-               RunButton.setText(R.string.test_run);
-            }
-            if (pbar != null) {
-               pbar.setVisibility(View.INVISIBLE);
-            }
-        }
-        else
-        {
-            if (RunButton != null) {
-               RunButton.setText("Stop Test");
-            }
-            if (pbar != null) {
-               pbar.setVisibility(View.VISIBLE);
-            }
-        }
+       if(state) {
+          if(RunButton != null) {
+             RunButton.setText(R.string.test_run);
+          }
+          if(pbar != null) {
+             pbar.setVisibility(View.INVISIBLE);
+          }
+          if(mTestSelected == SWEEP_TEST) {
+             enableBandSweepSetting();
+          }
+       }else {
+          if(RunButton != null) {
+             RunButton.setText("Stop Test");
+          }
+          if(pbar != null) {
+             pbar.setVisibility(View.VISIBLE);
+          }
+       }
     }
 
     private void chooseFMRFoption(){
-        String[] szTestInformation = getResources().getStringArray(
+       String[] szTestInformation = getResources().getStringArray(
                         R.array.stats_options);
-        final StringBuilder szbTestHeader = new StringBuilder();
-        szbTestHeader.append("running test:").append(szTestInformation[mTestSelected]);
-        String szTestHeader = new String(szbTestHeader);
-        switch(mTestSelected){
-            case 1:
-                RunButton = (Button)findViewById(R.id.Runbutton);
-                if (RunButton != null) {
-                   RunButton.setVisibility(View.INVISIBLE);
-                }
-                pbar = (ProgressBar) findViewById(R.id.progressbar);
-                if (pbar != null) {
-                   pbar.setVisibility(View.INVISIBLE);
-                }
-                adaptCfgRf.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-                spinOptionFmRf.setAdapter(adaptCfgRf);
-                if(isTransportLayerSMD())
-                   spinOptionFmRf.setOnItemSelectedListener(mSpinCfgRfListener2);
-                else
-                   spinOptionFmRf.setOnItemSelectedListener(mSpinCfgRfListener1);
-                break;
-            case 2:
-                txtbox1 = (EditText) findViewById(R.id.txtbox1);
-                tv1 = (TextView) findViewById(R.id.label);
-                if (txtbox1 != null) {
-                   txtbox1.setVisibility(View.INVISIBLE);
-                }
-                if (tv1 != null) {
-                   tv1.setVisibility(View.INVISIBLE);
-                }
-                Button SetButton = (Button)findViewById(R.id.Setbutton);
-                if (SetButton != null) {
-                   SetButton.setVisibility(View.INVISIBLE);
-                }
-                adaptRfCfg.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-                spinOptionFmRf.setAdapter(adaptRfCfg);
-                spinOptionFmRf.setOnItemSelectedListener(mSpinRfCfgListener);
-                break;
+       final StringBuilder szbTestHeader = new StringBuilder();
+       szbTestHeader.append("running test:").append
+                              (szTestInformation[mTestSelected]);
+       String szTestHeader = new String(szbTestHeader);
+       switch(mTestSelected)
+       {
+       case 1:
+               RunButton = (Button)findViewById(R.id.Runbutton);
+               if(RunButton != null) {
+                  RunButton.setVisibility(View.INVISIBLE);
+               }
+               pbar = (ProgressBar) findViewById(R.id.progressbar);
+               if(pbar != null) {
+                  pbar.setVisibility(View.INVISIBLE);
+               }
+               adaptCfgRf.setDropDownViewResource
+                           (android.R.layout.simple_spinner_dropdown_item);
+               spinOptionFmRf.setAdapter(adaptCfgRf);
+               if(isTransportLayerSMD())
+                  spinOptionFmRf.setOnItemSelectedListener
+                                   (mSpinCfgRfListener2);
+               else
+                  spinOptionFmRf.setOnItemSelectedListener
+                                   (mSpinCfgRfListener1);
+               break;
+       case 2:
+               txtbox1 = (EditText)findViewById(R.id.txtbox1);
+               tv1 = (TextView)findViewById(R.id.label);
+               if(txtbox1 != null) {
+                  txtbox1.setVisibility(View.INVISIBLE);
+               }
+               if(tv1 != null) {
+                  tv1.setVisibility(View.INVISIBLE);
+               }
+               Button SetButton = (Button)findViewById(R.id.Setbutton);
+               if(SetButton != null) {
+                  SetButton.setVisibility(View.INVISIBLE);
+               }
+               adaptRfCfg.setDropDownViewResource
+                               (android.R.layout.simple_spinner_dropdown_item);
+               spinOptionFmRf.setAdapter(adaptRfCfg);
+               spinOptionFmRf.setOnItemSelectedListener(mSpinRfCfgListener);
+               break;
         }
     }
 
-    private View.OnClickListener mOnSetRmssitListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetRmssitListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
                int rdel = Integer.parseInt(a);
                Log.d(LOGTAG, "Value of RMSSI DELTA is : " + rdel);
                mReceiver.setRmssiDel(rdel);
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
                Log.e(LOGTAG, "Value entered is not in correct format: " + a);
                txtbox1.setText("");
-          } catch (NullPointerException e) {
+          }catch (NullPointerException e) {
                e.printStackTrace();
           }
        }
@@ -455,108 +492,116 @@
         }
     };
 
-    private View.OnClickListener mOnSetSigThListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetSigThListener =
+     new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rdel = Integer.parseInt(a);
               Log.d(LOGTAG, "Value of Signal Th. is : " + rdel);
               mReceiver.setSignalThreshold(rdel);
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format: " + a);
               txtbox1.setText("");
-          } catch (NullPointerException e) {
+          }catch (NullPointerException e) {
               e.printStackTrace();
           }
       }
     };
 
-    private View.OnClickListener mOnSetSinrSmplCntListener  = new View.OnClickListener() {
+    private View.OnClickListener mOnSetSinrSmplCntListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rdel = Integer.parseInt(a);
               Log.d(LOGTAG, "Value of Sinr Samples count is : " + rdel);
               if(mService != null) {
                  try {
                      mService.setSinrSamplesCnt(rdel);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format: " + a);
               txtbox1.setText("");
           }
       }
     };
-    private View.OnClickListener mOnSetSinrThListener = new View.OnClickListener() {
+
+    private View.OnClickListener mOnSetSinrThListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rdel = Integer.parseInt(a);
               Log.d(LOGTAG, "Value of Sinr Th is : " + rdel);
               if(mService != null) {
                  try {
                      mService.setSinrTh(rdel);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format: " + a);
               txtbox1.setText("");
           }
       }
     };
-    private View.OnClickListener mOnSetIntfLowThListener = new View.OnClickListener() {
+
+    private View.OnClickListener mOnSetIntfLowThListener =
+     new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rdel = Integer.parseInt(a);
               Log.d(LOGTAG, "Value of Intf Det Low Th is : " + rdel);
               if(mService != null) {
                  try {
                      mService.setIntfDetLowTh(rdel);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format: " + a);
               txtbox1.setText("");
           }
       }
     };
-    private View.OnClickListener mOnSetIntfHighThListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetIntfHighThListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rdel = Integer.parseInt(a);
               Log.d(LOGTAG, "Value of Intf Det Low Th is : " + rdel);
               if(mService != null) {
                  try {
                      mService.setIntfDetHighTh(rdel);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
 
-    private View.OnClickListener mOnSetSinrFirstStageListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetSinrFirstStageListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int sinr = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for SINR FIRST STAGE is : " + sinr);
@@ -566,20 +611,22 @@
               if(mService != null) {
                  try {
                      mService.setSinrFirstStage(sinr);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
-    private View.OnClickListener mOnSetRmssiFirstStageListener = new View.OnClickListener() {
+
+    private View.OnClickListener mOnSetRmssiFirstStageListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int rmssi = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for RMSSI FIRST STAGE is: " + rmssi);
@@ -589,21 +636,22 @@
               if(mService != null) {
                  try {
                      mService.setRmssiFirstStage(rmssi);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
 
-    private View.OnClickListener mOnSetCFOMeanThListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetCFOMeanThListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int cf0 = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for CF0TH12 is: " + cf0);
@@ -613,46 +661,50 @@
               if(mService != null) {
                  try {
                      mService.setCFOMeanTh(cf0);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
 
-    private View.OnClickListener mOnSetSearchMPXDCCListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetSearchMPXDCCListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
-              Log.d(LOGTAG, "Value entered for search is: MPX DCC");
-              if(mService != null) {
-                 try {
-                     mService.setSearchAlgoType(MPX_DCC);
-                 } catch (RemoteException e) {
-                     e.printStackTrace();
-                 }
-              }
-       }
-    };
-    private View.OnClickListener mOnSetSearchSinrIntfListener = new View.OnClickListener() {
-       public void onClick(View v) {
-              Log.d(LOGTAG, "Value entered for search is: SINR INTF");
-              if(mService != null) {
-                 try {
-                     mService.setSearchAlgoType(SINR_INTF);
-                 } catch (RemoteException e) {
-                     e.printStackTrace();
-                 }
-              }
+          Log.d(LOGTAG, "Value entered for search is: MPX DCC");
+          if(mService != null) {
+             try {
+                  mService.setSearchAlgoType(MPX_DCC);
+             }catch (RemoteException e) {
+                  e.printStackTrace();
+             }
+          }
        }
     };
 
-    private View.OnClickListener mOnSetAfJmpRmssiThListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetSearchSinrIntfListener =
+    new View.OnClickListener() {
+       public void onClick(View v) {
+          Log.d(LOGTAG, "Value entered for search is: SINR INTF");
+          if(mService != null) {
+             try {
+                  mService.setSearchAlgoType(SINR_INTF);
+             }catch (RemoteException e) {
+                  e.printStackTrace();
+             }
+          }
+       }
+    };
+
+    private View.OnClickListener mOnSetAfJmpRmssiThListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int th = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for AfJmpRmssiTh is: " + th);
@@ -662,21 +714,22 @@
               if(mService != null) {
                  try {
                      mService.setAfJmpRmssiTh(th);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
 
-    private View.OnClickListener mOnSetGdChRmssiThListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetGdChRmssiThListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int th = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for Good channel Rmssi Th is: " + th);
@@ -686,21 +739,22 @@
               if(mService != null) {
                  try {
                      mService.setGoodChRmssiTh(th);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
        }
     };
 
-    private View.OnClickListener mOnSetAfJmpRmssiSmplsCntListener = new View.OnClickListener() {
+    private View.OnClickListener mOnSetAfJmpRmssiSmplsCntListener =
+    new View.OnClickListener() {
        public void onClick(View v) {
           String a;
-          a =  txtbox1.getText().toString();
+          a = txtbox1.getText().toString();
           try {
               int cnt = Integer.parseInt(a);
               Log.d(LOGTAG, "Value entered for AfJmpRmssiSamples is: " + cnt);
@@ -710,11 +764,11 @@
               if(mService != null) {
                  try {
                      mService.setAfJmpRmssiSamplesCnt(cnt);
-                 } catch (RemoteException e) {
+                 }catch (RemoteException e) {
                      e.printStackTrace();
                  }
               }
-          } catch (NumberFormatException e) {
+          }catch (NumberFormatException e) {
               Log.e(LOGTAG, "Value entered is not in correct format : " + a);
               txtbox1.setText("");
           }
@@ -722,61 +776,64 @@
     };
 
     public class CfgRfItemSelectedListener1 implements OnItemSelectedListener {
-        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+        public void onItemSelected(
+                     AdapterView<?> parent, View view, int pos, long id) {
             Log.d("Table","onItemSelected is hit with " + pos);
-            txtbox1 = (EditText) findViewById(R.id.txtbox1);
-            tv1 = (TextView) findViewById(R.id.label);
+            txtbox1 = (EditText)findViewById(R.id.txtbox1);
+            tv1 = (TextView)findViewById(R.id.label);
             Button SetButton = (Button)findViewById(R.id.Setbutton);
             tLayout.setVisibility(View.INVISIBLE);
             switch(pos)
             {
-                case 0:
-                    if (txtbox1 != null) {
+            case 0:
+                   if (txtbox1 != null) {
                        txtbox1.setText(R.string.type_rd);
                        txtbox1.setVisibility(View.VISIBLE);
-                    }
-                    if (tv1 != null) {
+                   }
+                   if (tv1 != null) {
                        tv1.setText(R.string.enter_rssi);
                        tv1.setVisibility(View.VISIBLE);
-                    }
-                    if (SetButton != null) {
+                   }
+                   if (SetButton != null) {
                        SetButton.setText(R.string.set_rmmsi_delta);
                        SetButton.setVisibility(View.VISIBLE);
                        SetButton.setOnClickListener(mOnSetRmssitListener);
-                    }
-                    break;
-                case 1:
-                    if (txtbox1 != null) {
+                   }
+                   break;
+            case 1:
+                   if (txtbox1 != null) {
                        txtbox1.setText(R.string.type_rd);
                        txtbox1.setVisibility(View.VISIBLE);
-                    }
-                    if (tv1 != null) {
+                   }
+                   if (tv1 != null) {
                        tv1.setText(R.string.enter_sigth);
                        tv1.setVisibility(View.VISIBLE);
-                    }
-                    if (SetButton != null) {
+                   }
+                   if (SetButton != null) {
                        SetButton.setText(R.string.set_sigth);
                        SetButton.setVisibility(View.VISIBLE);
                        SetButton.setOnClickListener(mOnSetSigThListener);
-                    }
-                    break;
-                case 2:
-                    tLayout.removeAllViewsInLayout();
-                    mNewRowIds = NEW_ROW_ID;
-                    tLayout.setVisibility(View.VISIBLE);
-                    if (txtbox1 != null) {
+                   }
+                   break;
+            case 2:
+                   tLayout.removeAllViewsInLayout();
+                   mNewRowIds = NEW_ROW_ID;
+                   tLayout.setVisibility(View.VISIBLE);
+                   if (txtbox1 != null) {
                        txtbox1.setVisibility(View.INVISIBLE);
-                    }
-                    if (tv1 != null) {
+                   }
+                   if (tv1 != null) {
                        tv1.setVisibility(View.INVISIBLE);
-                    }
-                    if (SetButton != null) {
+                   }
+                   if (SetButton != null) {
                        SetButton.setVisibility(View.INVISIBLE);
-                    }
-                    adaptRfCfg.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
-                    spinOptionFmRf.setAdapter(adaptRfCfg);
-                    spinOptionFmRf.setOnItemSelectedListener(mSpinRfCfgListener);
-                    break;
+                   }
+                   adaptRfCfg.setDropDownViewResource(
+                              android.R.layout.simple_spinner_dropdown_item);
+                   spinOptionFmRf.setAdapter(adaptRfCfg);
+                   spinOptionFmRf.setOnItemSelectedListener(
+                                                 mSpinRfCfgListener);
+                   break;
             }
         }
 
@@ -786,7 +843,8 @@
     }
 
     public class CfgRfItemSelectedListener2 implements OnItemSelectedListener {
-        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+        public void onItemSelected(AdapterView<?> parent,
+                                    View view, int pos, long id) {
             Log.d("Table","onItemSelected is hit with " + pos);
             int ret = Integer.MAX_VALUE;
             txtbox1 = (EditText) findViewById(R.id.txtbox1);
@@ -1306,7 +1364,8 @@
                     if(button2 != null) {
                        button2.setVisibility(View.INVISIBLE);
                     }
-                    adaptRfCfg.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+                    adaptRfCfg.setDropDownViewResource(
+                              android.R.layout.simple_spinner_dropdown_item);
                     spinOptionFmRf.setAdapter(adaptRfCfg);
                     spinOptionFmRf.setOnItemSelectedListener(mSpinRfCfgListener);
                     break;
@@ -1324,6 +1383,12 @@
                         SetButton.setVisibility(View.VISIBLE);
                         SetButton.setOnClickListener(mOnSetRxRePeatCount);
                     }
+                    if(button1 != null) {
+                       button1.setVisibility(View.INVISIBLE);
+                    }
+                    if(button2 != null) {
+                       button2.setVisibility(View.INVISIBLE);
+                    }
                     break;
             }
         }
@@ -1333,7 +1398,8 @@
     }
 
     public class RfCfgItemSelectedListener implements OnItemSelectedListener {
-        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+        public void onItemSelected(AdapterView<?> parent,
+                                    View view, int pos, long id) {
             Log.d("Table","onItemSelected is hit with "+pos);
             tLayout.setVisibility(View.INVISIBLE);
             if (mTestRunning)
@@ -1354,6 +1420,11 @@
                        RunButton.setVisibility(View.VISIBLE);
                        RunButton.setOnClickListener(mOnRunListener);
                     }
+                    if(mTestSelected == SWEEP_TEST) {
+                       enableBandSweepSetting();
+                    }else {
+                       disableBandSweepSetting();
+                    }
                     break;
                 case 4:
                     RunButton = (Button)findViewById(R.id.Runbutton);
@@ -1364,12 +1435,14 @@
                     if (pbar != null) {
                        pbar.setVisibility(View.INVISIBLE);
                     }
-                    adaptCfgRf.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+                    adaptCfgRf.setDropDownViewResource(
+                                     android.R.layout.simple_spinner_dropdown_item);
                     spinOptionFmRf.setAdapter(adaptCfgRf);
                     if(isTransportLayerSMD())
                        spinOptionFmRf.setOnItemSelectedListener(mSpinCfgRfListener2);
                     else
                        spinOptionFmRf.setOnItemSelectedListener(mSpinCfgRfListener1);
+                    disableBandSweepSetting();
                     break;
             }
         }
@@ -1384,9 +1457,7 @@
             mTestSelected = pos;
             tLayout.setVisibility(View.INVISIBLE);
             chooseFMRFoption();
-
         }
-
         public void onNothingSelected(AdapterView<?> parent) {
             // Do Nothing
         }
@@ -1479,8 +1550,7 @@
         }
     }
 
-
-    private void runCurrentTest(){
+    private void runCurrentTest() {
         Log.d(LOGTAG, "The test being run is" +mTestSelected);
 
         //get test summary
@@ -1490,118 +1560,107 @@
         szbTestHeader.append("running test:").append(szTestInformation[mTestSelected]);
         szbTestHeader.append("\r\n");
         String szTestHeader = new String(szbTestHeader);
-        if(null != mFileCursor )
-        {
-            try {
+        if(null != mFileCursor ) {
+           try {
                 mFileCursor.write(szTestHeader.getBytes());
-            } catch (IOException ioe) {
+           } catch (IOException ioe) {
                 ioe.printStackTrace();
-            }
+           }
         }
-        switch(mTestSelected){
-            case CUR_FREQ_TEST:
-                Log.d(LOGTAG,"Current Freq test is going to run");
-                int freq = FmSharedPreferences.getTunedFrequency();
-                Result res = GetFMStatsForFreq(freq);
-                createResult(mColumnHeader);
-                if(res != null)
-                   createResult(res);
+        switch(mTestSelected)
+        {
+        case CUR_FREQ_TEST:
+             Log.d(LOGTAG,"Current Freq test is going to run");
+             int freq = FmSharedPreferences.getTunedFrequency();
+             Result res = GetFMStatsForFreq(freq);
+             createResult(mColumnHeader);
+             if(res != null)
+                createResult(res);
+              mTestRunning = false;
+              break;
+        case CUR_MULTI_TEST:
+             /*Set it to ready to Stop*/
+             SetButtonState(false);
+             createResult(mColumnHeader);
+
+             if(mMultiUpdateThread == null) {
+                mMultiUpdateThread = new Thread(null, getMultipleResults,
+                                                 "MultiResultsThread");
+             }
+             /* Launch dummy thread to simulate the transfer progress */
+             Log.d(LOGTAG, "Thread State: " + mMultiUpdateThread.getState());
+             if(mMultiUpdateThread.getState() == Thread.State.TERMINATED) {
+                mMultiUpdateThread = new Thread(null, getMultipleResults,
+                                                 "MultiResultsThread");
+             }
+             /* If the thread state is "new" then the thread has not yet started */
+             if(mMultiUpdateThread.getState() == Thread.State.NEW) {
+                mMultiUpdateThread.start();
+             }
+             // returns and UI in different thread.
+             break;
+        case SEARCH_TEST:
+             try {
+                 Log.d(LOGTAG, "start scanning\n");
+                 if(isTransportLayerSMD()) {
+                    Log.d(LOGTAG,"Scanning with 0 scan time");
+                    if (mReceiver != null)
+                        mIsSearching = mReceiver.searchStations(FmReceiver.FM_RX_SRCH_MODE_SCAN,
+                                           SCAN_DWELL_PERIOD, FmReceiver.FM_RX_SEARCHDIR_UP);
+                 }else {
+                    mIsSearching = mService.scan(0);
+                 }
+             }catch (RemoteException e) {
+                 e.printStackTrace();
+             }
+
+             if(mIsSearching) {
+                 /*Set it to Ready to Stop*/
+                 SetButtonState(false);
+                 createResult(mColumnHeader);
+                 Log.d(LOGTAG, "Created the results and cancel UI\n");
+             }else {
                  mTestRunning = false;
-                break;
-            case CUR_MULTI_TEST:
-                /*Set it to ready to Stop*/
-                SetButtonState(false);
-                createResult(mColumnHeader);
-
-                if (mMultiUpdateThread == null)
-                {
-                   mMultiUpdateThread = new Thread(null, getMultipleResults,
-                                                          "MultiResultsThread");
-                }
-                /* Launch dummy thread to simulate the transfer progress */
-                Log.d(LOGTAG, "Thread State: " + mMultiUpdateThread.getState());
-                if (mMultiUpdateThread.getState() == Thread.State.TERMINATED)
-                {
-                    mMultiUpdateThread = new Thread(null, getMultipleResults,
-                                                          "MultiResultsThread");
-                }
-                /* If the thread state is "new" then the thread has not yet started */
-                if (mMultiUpdateThread.getState() == Thread.State.NEW)
-                {
-                    mMultiUpdateThread.start();
-                }
-                // returns and UI in different thread.
-                break;
-            case SEARCH_TEST:
-                try {
-                    Log.d(LOGTAG, "start scanning\n");
-                    if(isTransportLayerSMD()) {
-                         Log.d(LOGTAG,"Scanning with 0 scan time");
-                         if (mReceiver != null)
-                              mIsSearching = mReceiver.searchStations(FmReceiver.FM_RX_SRCH_MODE_SCAN,
-                                             SCAN_DWELL_PERIOD, FmReceiver.FM_RX_SEARCHDIR_UP);
-                    } else {
-                        mIsSearching = mService.scan(0);
-                    }
-                } catch (RemoteException e) {
-
-                    e.printStackTrace();
-                }
-
-                if(mIsSearching)
-                {
-                    /*Set it to Ready to Stop*/
-                    SetButtonState(false);
-                    createResult(mColumnHeader);
-                    Log.d(LOGTAG, "Created the results and cancel UI\n");
-                }
-                else
-                {
-                    mTestRunning = false;
-                }
-                break;
-            case SWEEP_TEST:
-                int Spacing = FmSharedPreferences.getChSpacing();
-                int lowerFreq = FmSharedPreferences.getLowerLimit();
-                int higherFreq = FmSharedPreferences.getUpperLimit();
-                try {
-                    Log.d(LOGTAG, "Going to set low side injection\n");
-                    mService.setHiLoInj(Lo);
-                } catch (RemoteException e) {
-
-                    e.printStackTrace();
-                }
-                /* Set it to Ready to stop*/
-                SetButtonState(false);
-                createResult(mColumnHeader);
-                getFMStatsInBand(lowerFreq,higherFreq,Spacing);
-                break;
+             }
+             break;
+        case SWEEP_TEST:
+             int Spacing = FmSharedPreferences.getChSpacing();
+             int lowerFreq = FmSharedPreferences.getLowerLimit();
+             int higherFreq = FmSharedPreferences.getUpperLimit();
+             try {
+                 Log.d(LOGTAG, "Going to set low side injection\n");
+                 mService.setHiLoInj(Lo);
+             }catch (RemoteException e) {
+                 e.printStackTrace();
+             }
+             /* Set it to Ready to stop*/
+             SetButtonState(false);
+             createResult(mColumnHeader);
+             getFMStatsInBand(lowerFreq, higherFreq, Spacing);
+             break;
         }
     }
 
     /* Thread processing */
     private Runnable getMultipleResults = new Runnable() {
        public void run() {
-            /*Collect the data for the current frequency
-            20 times*/
-            int freq = FmSharedPreferences.getTunedFrequency();
+          /*Collect the data for the current frequency
+           20 times*/
+          int freq = FmSharedPreferences.getTunedFrequency();
 
-            for (int i = 0; i < 20; i++)
-            {
-                try
-                {
-                    Thread.sleep(500);
-                    Message updateUI = new Message();
-                    updateUI.what = STATUS_UPDATE;
-                    updateUI.obj = (Object)GetFMStatsForFreq(freq);
-                    if (updateUI.obj == null)
+          for(int i = 0; i < 20; i++) {
+              try {
+                   Thread.sleep(500);
+                   Message updateUI = new Message();
+                   updateUI.what = STATUS_UPDATE;
+                   updateUI.obj = (Object)GetFMStatsForFreq(freq);
+                   if(updateUI.obj == null)
                         break;
-                    mUIUpdateHandlerHandler.sendMessage(updateUI);
-		} catch (InterruptedException e)
-		{
-			/*break the loop*/
-			break;
-		}
+                   mUIUpdateHandlerHandler.sendMessage(updateUI);
+              }catch (InterruptedException e) {
+                   /*break the loop*/
+                   break;
+              }
             }
             mTestRunning = false;
             Message updateStop = new Message();
@@ -1610,93 +1669,168 @@
        }
     };
 
-    private void getFMStatsInBand(int lFreq, int hFreq, int Spacing)
-    {
-        if( null == mBand) {
-            mBand = new Band();
-        }
-        mBand.lFreq = lFreq;
-        mBand.hFreq = hFreq;
-        if(Spacing == 0)
-        {
-            mBand.Spacing = 200; // 200KHz
-        }
-        else if( Spacing == 1)
-        {
-            mBand.Spacing = 100; // 100KHz
-        }
-        else
-        {
-            mBand.Spacing = 50;
-        }
+    private void getFMStatsInBand(int lFreq, int hFreq, int Spacing) {
+       if(null == mBand) {
+          mBand = new Band();
+       }
+       mBand.lFreq = lFreq;
+       mBand.hFreq = hFreq;
+       if(Spacing == 0) {
+          mBand.Spacing = 200; // 200KHz
+       }else if(Spacing == 1) {
+          mBand.Spacing = 100; // 100KHz
+       }else {
+          mBand.Spacing = 50;
+       }
 
-        if (mMultiUpdateThread == null)
-        {
-           mMultiUpdateThread = new Thread(null, getSweepResults,
+       if(mMultiUpdateThread == null) {
+          if(prevSweepMthd == 0) {
+             mMultiUpdateThread = new Thread(null, getManualSweepResults,
+                                           "MultiResultsThread");
+          }else {
+             mMultiUpdateThread = new Thread(null, getFileSweepResults,
+                                           "MultiResultsThread");
+          }
+       }
+       /* Launch he dummy thread to simulate the transfer progress */
+       Log.d(LOGTAG, "Thread State: " + mMultiUpdateThread.getState());
+       if((mMultiUpdateThread.getState() == Thread.State.TERMINATED)) {
+          if(prevSweepMthd == 0) {
+             mMultiUpdateThread = new Thread(null, getManualSweepResults,
                                                   "MultiResultsThread");
-        }
-        /* Launch he dummy thread to simulate the transfer progress */
-        Log.d(LOGTAG, "Thread State: " + mMultiUpdateThread.getState());
-        if (mMultiUpdateThread.getState() == Thread.State.TERMINATED)
-        {
-            mMultiUpdateThread = new Thread(null, getSweepResults,
-                                                  "MultiResultsThread");
-        }
-        /* If the thread state is "new" then the thread has not yet started */
-        if (mMultiUpdateThread.getState() == Thread.State.NEW)
-        {
-            mMultiUpdateThread.start();
-        }
+          }else {
+             mMultiUpdateThread = new Thread(null, getFileSweepResults,
+                                           "MultiResultsThread");
+          }
+       }
+       /* If the thread state is "new" then the thread has not yet started */
+       if(mMultiUpdateThread.getState() == Thread.State.NEW) {
+          mMultiUpdateThread.start();
+       }
     }
 
     /* Thread processing */
-    private Runnable getSweepResults = new Runnable() {
+    private Runnable getManualSweepResults = new Runnable() {
        public void run() {
-            for (int i = mBand.lFreq; (i <= mBand.hFreq) && (mService != null);
-                                                            i += mBand.Spacing)
-            {
-                 try {
-                      if (!mService.tune(i)) {
-                          Log.e(LOGTAG, "tune failed");
-                          break;
-                      }
-                      mSync = new Band();
-                      synchronized(mSync) {
-                         mSync.wait(); //wait till notified
-                      }
-                      mSync = null;
-                      Message updateUI = new Message();
-                      updateUI.what = STATUS_UPDATE;
-                      updateUI.obj = (Object)GetFMStatsForFreq(i);
-                      if (updateUI.obj == null) {
-                          break;
-                      } else {
-                          mUIUpdateHandlerHandler.sendMessage(updateUI);
-                          Log.d(LOGTAG,"highFerq is "+mBand.hFreq);
-                      }
-                 }
-                 catch (RemoteException e) {
-		      Log.e(LOGTAG, "SweepResults:Tune failed\n");
-		 }
-
-                catch (InterruptedException e) {
-			/*Stop the thrad*/
-		       break;
-                }
-            }
-            mTestRunning = false;
-            Message updateStop = new Message();
-            updateStop.what = STATUS_DONE;
             try {
-                 Log.d(LOGTAG, "Going to set auto hi-lo injection\n");
-                 mService.setHiLoInj(Auto);
-            } catch (RemoteException e) {
-                 e.printStackTrace();
+                Thread.sleep(prevDelayTime * 1000);
+            }catch(InterruptedException e) {
             }
-            mUIUpdateHandlerHandler.sendMessage(updateStop);
+            for (int i = mBand.lFreq; (i <= mBand.hFreq) &&
+                                     (mService != null); i += mBand.Spacing) {
+                 if(!tuneAndUpdateSweepResult(i)) {
+                    break;
+                 }
+                 try {
+                     Thread.sleep(prevDwellTime * 1000);
+                 }catch (InterruptedException e) {
+                     /*Stop the thrad*/
+                     break;
+                 }
+            }
+            sendStatusDoneMsg();
        }
     };
 
+    private void sendStatusDoneMsg() {
+       mTestRunning = false;
+       Message updateStop = new Message();
+       updateStop.what = STATUS_DONE;
+       try {
+           Log.d(LOGTAG, "Going to set auto hi-lo injection\n");
+           mService.setHiLoInj(Auto);
+       } catch (RemoteException e) {
+           e.printStackTrace();
+       }
+       if(mUIUpdateHandlerHandler != null) {
+          Log.d(LOGTAG, "Sending message to stop test");
+          mUIUpdateHandlerHandler.sendMessage(updateStop);
+       }
+    }
+
+    private Runnable getFileSweepResults = new Runnable() {
+       public void run() {
+          boolean status = true;
+          try {
+               BufferedReader reader = new BufferedReader
+                               (new FileReader(getFilesDir()
+                                                + FREQ_LIST_FILE_NAME));
+               String curLine = null;
+               try {
+                    Thread.sleep(prevDelayTime * 1000);
+               }catch(InterruptedException e) {
+               }
+               while((reader != null) && (curLine = reader.readLine()) != null) {
+                     String[] freq_list = curLine.split(",");
+                     for(int i = 0; (freq_list != null ) &&
+                                      (i < freq_list.length); i++) {
+                         int freq =
+                             (int)(Double.parseDouble(freq_list[i]) * 1000);
+                         if(validFreq(freq)) {
+                            if(!tuneAndUpdateSweepResult(freq)) {
+                               status = false;
+                               break;
+                            }else {
+                               try {
+                                   Thread.sleep(prevDwellTime * 1000);
+                               }catch (InterruptedException e) {
+                                   /*Stop the thrad*/
+                                   status = false;
+                                   break;
+                               }
+                            }
+                         }
+                     }
+                     if(!status) {
+                        break;
+                     }
+               }
+               reader.close();
+          }catch(IOException e) {
+               e.printStackTrace();
+          }
+          sendStatusDoneMsg();
+       }
+    };
+
+    private boolean validFreq(int freq) {
+       if((freq >= mBand.lFreq) &&
+          (((freq - mBand.lFreq) / mBand.Spacing) >= 0)) {
+           return true;
+       }else {
+           return false;
+       }
+    }
+
+    private boolean tuneAndUpdateSweepResult(int freq) {
+       try {
+            if(!mService.tune(freq)) {
+               Log.e(LOGTAG, "tune failed");
+               return false;
+            }
+            mSync = new Band();
+            synchronized(mSync) {
+                mSync.wait(); //wait till notified
+            }
+            mSync = null;
+            Message updateUI = new Message();
+            updateUI.what = STATUS_UPDATE;
+            updateUI.obj = (Object)GetFMStatsForFreq(freq);
+            if(updateUI.obj == null) {
+               return false;
+            }else {
+               mUIUpdateHandlerHandler.sendMessage(updateUI);
+               Log.d(LOGTAG,"highFerq is " + mBand.hFreq);
+            }
+       }catch (RemoteException e) {
+            Log.e(LOGTAG, "SweepResults:Tune failed\n");
+            return false;
+       }catch (InterruptedException e) {
+            return false;
+       }
+       return true;
+    }
+
     private Result GetFMStatsForFreq(int freq)
     {
         Result result = new Result();
@@ -2015,4 +2149,90 @@
              mTestRunning = false;
          }
      }
+
+     @Override
+     protected Dialog onCreateDialog(int id) {
+         AlertDialog.Builder dlgBuilder = new AlertDialog.Builder(this);
+         switch(id)
+         {
+         case DIALOG_BAND_SWEEP_SETTING:
+              return createBandSweepDialog(id, dlgBuilder);
+         }
+         return null;
+     }
+
+     private Dialog createBandSweepDialog(int id, AlertDialog.Builder dlgBuilder) {
+         LayoutInflater inflater = LayoutInflater.from(this);
+         final View listview = inflater.inflate(R.layout.band_sweep_setting, null);
+         spinOptionBandSweepMthds = (Spinner)listview.findViewById(R.id.band_sweep_spinner);
+         final EditText delayBox = (EditText)listview.findViewById(R.id.txtboxDelayTime);
+         final EditText dwellBox = (EditText)listview.findViewById(R.id.txtboxDwellTime);
+
+         if(delayBox != null) {
+            delayBox.setText("" + prevDelayTime);
+         }
+         if(dwellBox != null) {
+            dwellBox.setText("" + prevDwellTime);
+         }
+         if(spinOptionBandSweepMthds != null) {
+            spinOptionBandSweepMthds.setAdapter(bandSweepMthds);
+            spinOptionBandSweepMthds.setOnItemSelectedListener(mSweepMthdsListener);
+            spinOptionBandSweepMthds.setSelection(prevSweepMthd);
+         }else {
+            Log.e(LOGTAG, "could not find spinner for methods\n");
+         }
+         dlgBuilder.setView(listview)
+                .setPositiveButton(R.string.band_sweep_setting_set, new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int id) {
+                        prevSweepMthd = curSweepMthd;
+                        if(delayBox != null) {
+                           String s = delayBox.getText().toString();
+                           prevDelayTime = Integer.parseInt(s);
+                        }
+                        if(dwellBox != null) {
+                           String s = dwellBox.getText().toString();
+                           prevDwellTime = Integer.parseInt(s);
+                        }
+                        removeDialog(DIALOG_BAND_SWEEP_SETTING);
+                    }
+                })
+                .setNegativeButton(R.string.band_sweep_setting_cancel, new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int id) {
+                        removeDialog(DIALOG_BAND_SWEEP_SETTING);
+                    }
+                });
+         return dlgBuilder.create();
+     }
+
+    private View.OnClickListener mClicktBandSweepSettingListener = new View.OnClickListener() {
+         public void onClick(View v) {
+            showDialog(DIALOG_BAND_SWEEP_SETTING);
+         }
+    };
+
+    private void enableBandSweepSetting() {
+         if(bandSweepSettingButton != null) {
+            bandSweepSettingButton.setEnabled(true);
+            bandSweepSettingButton.setVisibility(View.VISIBLE);
+         }
+    }
+
+    private void disableBandSweepSetting() {
+         if(bandSweepSettingButton != null) {
+            bandSweepSettingButton.setEnabled(false);
+            bandSweepSettingButton.setVisibility(View.INVISIBLE);
+         }
+    }
+
+    public class BandSweepMthdsSelectedListener implements OnItemSelectedListener {
+        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+            Log.d("Band Sweep Methods","onItemSelected is hit with " + pos);
+            curSweepMthd = pos;
+        }
+
+        public void onNothingSelected(AdapterView<?> parent) {
+            // Do Nothing
+        }
+    }
+
  }
diff --git a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
index 3bbeeca..9835090 100644
--- a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
+++ b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
@@ -78,6 +78,7 @@
    public static final int REGIONAL_BAND_TURKEY          = 33;
    public static final int REGIONAL_BAND_UNITEDKINGDOM   = 34;
    public static final int REGIONAL_BAND_UNITED_STATES   = 35;
+   public static final int REGIONAL_BAND_USER_DEFINED    = 36;
 
    public static final int RECORD_DUR_INDEX_0_VAL        = 5;
    public static final int RECORD_DUR_INDEX_1_VAL       = 15;
@@ -98,9 +99,9 @@
 
    private static final String FMCONFIG_COUNTRY = "fmconfig_country";
    //private static final String FMCONFIG_BAND = "fmconfig_band";
-   //private static final String FMCONFIG_MIN = "fmconfig_min";
-   //private static final String FMCONFIG_MAX = "fmconfig_max";
-   //private static final String FMCONFIG_STEP = "fmconfig_step";
+   private static final String FMCONFIG_MIN = "fmconfig_min";
+   private static final String FMCONFIG_MAX = "fmconfig_max";
+   private static final String FMCONFIG_STEP = "fmconfig_step";
    //private static final String FMCONFIG_EMPH = "fmconfig_emphasis";
    //private static final String FMCONFIG_RDSSTD = "fmconfig_rdsstd";
    /* Storage key String */
@@ -153,6 +154,9 @@
    private static int mListIndex;
    private Context mContext;
    private static int mTunedFrequency = 98100;
+   private static int mBandMinFreq = 76000;
+   private static int mBandMaxFreq = 108000;
+   private static int mChanSpacing = 0;
    private static int mFrequencyBand_Stepsize = 200;
 
    private static int mCountry = 0;
@@ -448,6 +452,12 @@
      /* Reset the Lists before reading the preferences */
       mListOfPlists.clear();
 
+      if(sp.getInt(FMCONFIG_COUNTRY, 0) == REGIONAL_BAND_USER_DEFINED) {
+         mBandMinFreq = sp.getInt(FMCONFIG_MIN, mBandMinFreq);
+         mBandMaxFreq = sp.getInt(FMCONFIG_MAX, mBandMaxFreq);
+         mChanSpacing = sp.getInt(FMCONFIG_STEP, mChanSpacing);
+      }
+
       int num_lists = sp.getInt(LIST_NUM, 1);
       if (mListOfPlists.size() == 0) {
 
@@ -541,6 +551,11 @@
 
       /* Save Configuration */
       ed.putInt(FMCONFIG_COUNTRY, mCountry);
+      if(mCountry == REGIONAL_BAND_USER_DEFINED) {
+         ed.putInt(FMCONFIG_MIN, mBandMinFreq);
+         ed.putInt(FMCONFIG_MAX, mBandMaxFreq);
+         ed.putInt(FMCONFIG_STEP, mChanSpacing);
+      }
       ed.putInt(LAST_RECORD_DURATION, mRecordDuration);
       ed.putBoolean(LAST_AF_JUMP_VALUE, mAFAutoSwitch);
       ed.commit();
@@ -682,8 +697,8 @@
 
    public static void setChSpacing(int spacing)
    {
-      if((spacing>=FmReceiver.FM_CHSPACE_200_KHZ)
-          && (spacing<=FmReceiver.FM_CHSPACE_50_KHZ))
+      if( (spacing >= FmReceiver.FM_CHSPACE_200_KHZ)
+          && (spacing <= FmReceiver.FM_CHSPACE_50_KHZ))
       {
          mFrequencyBand_Stepsize = 200;
          switch (spacing)
@@ -699,6 +714,7 @@
                break;
             }
          }
+         mChanSpacing = spacing;
          mFMConfiguration.setChSpacing(spacing);
       }
    }
@@ -761,10 +777,16 @@
    }
    public static void setLowerLimit(int lowLimit){
       mFMConfiguration.setLowerLimit(lowLimit);
+      if(mCountry == REGIONAL_BAND_USER_DEFINED) {
+         mBandMinFreq = lowLimit;
+      }
    }
 
    public static void setUpperLimit(int upLimit){
       mFMConfiguration.setUpperLimit(upLimit);
+      if(mCountry == REGIONAL_BAND_USER_DEFINED) {
+         mBandMaxFreq = upLimit;
+      }
    }
 
    public static void setCountry(int nCountryCode){
@@ -968,11 +990,11 @@
         }
         case REGIONAL_BAND_POLAND:
         {
-          /*POLAND : 87500 TO 108000 IN 50 KHZ STEPS*/
+          /*POLAND : 87500 TO 108000 IN 100 KHZ STEPS*/
           mFMConfiguration.setRadioBand(FmReceiver.FM_EU_BAND);
-          mFMConfiguration.setChSpacing(FmReceiver.FM_CHSPACE_50_KHZ);
+          mFMConfiguration.setChSpacing(FmReceiver.FM_CHSPACE_100_KHZ);
           mFMConfiguration.setLowerLimit(87500);
-          mFrequencyBand_Stepsize = 50;
+          mFrequencyBand_Stepsize = 100;
           break;
         }
         case REGIONAL_BAND_PORTUGAL:
@@ -1050,6 +1072,23 @@
           mFrequencyBand_Stepsize = 200;
           break;
         }
+        case REGIONAL_BAND_USER_DEFINED:
+        {
+          mFMConfiguration.setRadioBand(FmReceiver.FM_USER_DEFINED_BAND);
+          mFMConfiguration.setChSpacing(mChanSpacing);
+          mFMConfiguration.setEmphasis(FmReceiver.FM_DE_EMP75);
+          mFMConfiguration.setRdsStd(FmReceiver.FM_RDS_STD_RDS);
+          mFMConfiguration.setLowerLimit(mBandMinFreq);
+          mFMConfiguration.setUpperLimit(mBandMaxFreq);
+          if(mChanSpacing == 0) {
+             mFrequencyBand_Stepsize = 200;
+          }else if(mChanSpacing == 1) {
+             mFrequencyBand_Stepsize = 100;
+          }else {
+             mFrequencyBand_Stepsize = 50;
+          }
+          break;
+        }
         default:
         {
           Log.d(LOGTAG, "Invalid: countryCode: "+nCountryCode);
diff --git a/fmapp2/src/com/caf/fmradio/Settings.java b/fmapp2/src/com/caf/fmradio/Settings.java
index f5c5d07..c5683f1 100644
--- a/fmapp2/src/com/caf/fmradio/Settings.java
+++ b/fmapp2/src/com/caf/fmradio/Settings.java
@@ -42,6 +42,9 @@
 import android.preference.PreferenceCategory;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.EditTextPreference;
+import android.text.InputType;
+import android.widget.Toast;
 import java.util.Locale;
 
 import android.util.Log;
@@ -55,19 +58,34 @@
         public static final String AUTO_AF = "af_checkbox_preference";
         public static final String RESTORE_FACTORY_DEFAULT = "revert_to_fac";
         public static final int RESTORE_FACTORY_DEFAULT_INT = 1;
+        public static final String USER_DEFINED_BAND_MIN_KEY = "user_defined_band_min";
+        public static final String USER_DEFINED_BAND_MAX_KEY = "user_defined_band_max";
+        public static final String CHAN_SPACING_KEY = "chanl_spacing";
         public static final String RESTORE_FACTORY_DEFAULT_ACTION = "com.caf.fmradio.settings.revert_to_defaults";
 
         private static final String LOGTAG = FMRadio.LOGTAG;
+        private static final String USR_BAND_MSG = "Enter Freq from range 76.0 - 108.0";
 
         private ListPreference mBandPreference;
         private ListPreference mAudioPreference;
         private ListPreference mRecordDurPreference;
         private CheckBoxPreference mAfPref;
+        private EditTextPreference mUserBandMinPref;
+        private EditTextPreference mUserBandMaxPref;
+        private ListPreference mChannelSpacingPref;
         private Preference mRestoreDefaultPreference;
 
         private FmSharedPreferences mPrefs = null;
         private boolean mRxMode = false;
 
+        private int min_freq;
+        private int max_freq;
+        private int chan_spacing;
+        private String[] summaryBandItems;
+        private String[] chSpacingItems;
+        private String[] summaryAudioModeItems;
+        private String[] summaryRecordItems;
+
         @Override
         protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
@@ -90,62 +108,87 @@
           PreferenceScreen root = getPreferenceManager().createPreferenceScreen(
                                 this);
 
-          // Band/Country
-          String[] summaryBandItems = getResources().getStringArray(
+           summaryBandItems = getResources().getStringArray(
                                 R.array.regional_band_summary);
-          mBandPreference = new ListPreference(this);
-          mBandPreference.setEntries(R.array.regional_band_entries);
-          mBandPreference.setEntryValues(R.array.regional_band_values);
-          mBandPreference.setDialogTitle(R.string.sel_band_menu);
-          mBandPreference.setKey(REGIONAL_BAND_KEY);
-          mBandPreference.setTitle(R.string.regional_band);
-          index = FmSharedPreferences.getCountry();
-          Log.d(LOGTAG, "createPreferenceHierarchy: Country: " + index);
-          // Get the preference and list the value.
-          if ((index < 0) || (index >= summaryBandItems.length)) {
+           chSpacingItems = getResources().getStringArray(
+                                R.array.channel_spacing_entries);
+           mBandPreference = new ListPreference(this);
+           mBandPreference.setEntries(R.array.regional_band_entries);
+           mBandPreference.setEntryValues(R.array.regional_band_values);
+           mBandPreference.setDialogTitle(R.string.sel_band_menu);
+           mBandPreference.setKey(REGIONAL_BAND_KEY);
+           mBandPreference.setTitle(R.string.regional_band);
+           index = FmSharedPreferences.getCountry();
+           Log.d(LOGTAG, "createPreferenceHierarchy: Country: " + index);
+           // Get the preference and list the value.
+           if ((index < 0) || (index >= summaryBandItems.length)) {
                 index = 0;
-          }
-          Log.d(LOGTAG, "createPreferenceHierarchy: CountrySummary: "
-                               + summaryBandItems[index]);
-          mBandPreference.setSummary(summaryBandItems[index]);
-          mBandPreference.setValueIndex(index);
-          root.addPreference(mBandPreference);
+           }
+           mBandPreference.setValueIndex(index);
+           root.addPreference(mBandPreference);
 
-          if (mRxMode) {
-             // Audio Output (Stereo or Mono)
-             String[] 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);
-             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);
-             root.addPreference(mAudioPreference);
+           mChannelSpacingPref = new ListPreference(this);
+           mChannelSpacingPref.setEntries(R.array.channel_spacing_entries);
+           mChannelSpacingPref.setEntryValues(R.array.channel_spacing_val);
+           mChannelSpacingPref.setDialogTitle(R.string.sel_chanl_spacing);
+           mChannelSpacingPref.setTitle(R.string.chanl_spacing);
+           mChannelSpacingPref.setKey(CHAN_SPACING_KEY);
 
-             // AF Auto Enable (Checkbox)
-             mAfPref = new CheckBoxPreference(this);
-             mAfPref.setKey(AUTO_AF);
-             mAfPref.setTitle(R.string.auto_select_af);
-             mAfPref.setSummaryOn(R.string.auto_select_af_enabled);
-             mAfPref.setSummaryOff(R.string.auto_select_af_disabled);
-             boolean bAFAutoSwitch = FmSharedPreferences.getAutoAFSwitch();
-             Log.d(LOGTAG, "createPreferenceHierarchy: bAFAutoSwitch: "
-                                   + bAFAutoSwitch);
-             mAfPref.setChecked(bAFAutoSwitch);
-             root.addPreference(mAfPref);
+           mUserBandMinPref = new EditTextPreference(this);
+           mUserBandMinPref.setKey(USER_DEFINED_BAND_MIN_KEY);
+           mUserBandMinPref.setTitle(R.string.usr_def_band_min);
+           mUserBandMinPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER |
+                                                        InputType.TYPE_NUMBER_FLAG_DECIMAL);
+           mUserBandMinPref.setDialogTitle(R.string.usr_def_band_min);
+
+           mUserBandMaxPref = new EditTextPreference(this);
+           mUserBandMaxPref.setKey(USER_DEFINED_BAND_MAX_KEY);
+           mUserBandMaxPref.setTitle(R.string.usr_def_band_max);
+           mUserBandMaxPref.setDialogTitle(R.string.usr_def_band_max);
+           mUserBandMaxPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER |
+                                                        InputType.TYPE_NUMBER_FLAG_DECIMAL);
+
+           setBandSummary(index);
+
+           root.addPreference(mChannelSpacingPref);
+           root.addPreference(mUserBandMinPref);
+           root.addPreference(mUserBandMaxPref);
+
+           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);
+               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);
+               root.addPreference(mAudioPreference);
+
+               // AF Auto Enable (Checkbox)
+               mAfPref = new CheckBoxPreference(this);
+               mAfPref.setKey(AUTO_AF);
+               mAfPref.setTitle(R.string.auto_select_af);
+               mAfPref.setSummaryOn(R.string.auto_select_af_enabled);
+               mAfPref.setSummaryOff(R.string.auto_select_af_disabled);
+               boolean bAFAutoSwitch = FmSharedPreferences.getAutoAFSwitch();
+               Log.d(LOGTAG, "createPreferenceHierarchy: bAFAutoSwitch: "
+                              + bAFAutoSwitch);
+               mAfPref.setChecked(bAFAutoSwitch);
+               root.addPreference(mAfPref);
 
              if(FMRadio.RECORDING_ENABLE) {
-                String[] summaryRecordItems = getResources().getStringArray(
+                  summaryRecordItems = getResources().getStringArray(
                    R.array.record_durations_entries);
                 int nRecordDuration = 0;
                 mRecordDurPreference = new ListPreference(this);
@@ -197,40 +240,92 @@
           root.addPreference(mRestoreDefaultPreference);
           return root;
         }
-	public void clearStationList() {
+
+        public void clearStationList() {
           SharedPreferences sp = getSharedPreferences(FMRadio.SCAN_STATION_PREFS_NAME, 0);
           SharedPreferences.Editor editor = sp.edit();
           editor.clear();
           editor.commit();
         }
+
         public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                         String key) {
           int mTunedFreq = 0;
           boolean bStatus = false;
           if (key.equals(REGIONAL_BAND_KEY)) {
-	      int curListIndex = FmSharedPreferences.getCurrentListIndex();
-	      PresetList curList = FmSharedPreferences.getStationList(curListIndex);
-              String[] summaryBandItems = getResources().getStringArray(
-                                       R.array.regional_band_summary);
+              int curListIndex = FmSharedPreferences.getCurrentListIndex();
+              PresetList curList = FmSharedPreferences.getStationList(curListIndex);
               String valueStr = sharedPreferences.getString(key, "");
               int index = 0;
-              if (valueStr != null) {
+              if(valueStr != null) {
                   index = mBandPreference.findIndexOfValue(valueStr);
               }
-              if ((index < 0) || (index >= summaryBandItems.length)) {
+              if((index < 0) || (index >= summaryBandItems.length)) {
                   index = 0;
                   mBandPreference.setValueIndex(0);
+              }else if((index + 1) == summaryBandItems.length) {
+                   mChannelSpacingPref.setEnabled(true);
+              }else {
+                   mChannelSpacingPref.setEnabled(false);
               }
               Log.d(LOGTAG, "onSharedPreferenceChanged: Country Change: "
                                                         + index);
-              mBandPreference.setSummary(summaryBandItems[index]);
               FmSharedPreferences.setCountry(index);
+              setBandSummary(index);
               bStatus = FMRadio.fmConfigure();
               FMTransmitterActivity.fmConfigure();
               if (curList != null) {
                   curList.clear();
               }
               clearStationList();
+           }else if(key.equals(CHAN_SPACING_KEY)) {
+               int curListIndex = FmSharedPreferences.getCurrentListIndex();
+               PresetList curList = FmSharedPreferences.getStationList(curListIndex);
+               String valStr = mChannelSpacingPref.getValue();
+               int index = 0;
+               if(valStr != null) {
+                  index  = mChannelSpacingPref.findIndexOfValue(valStr);
+               }
+               if ((index < 0) || (index >= summaryRecordItems.length)) {
+                   index = 0;
+                   mChannelSpacingPref.setValueIndex(0);
+               }
+               mChannelSpacingPref.setSummary(chSpacingItems[index]);
+               FmSharedPreferences.setChSpacing(2 - index);
+               FMRadio.fmConfigure();
+               FMTransmitterActivity.fmConfigure();
+               if(curList != null) {
+                  curList.clear();
+               }
+               clearStationList();
+           }else if(key.equals(USER_DEFINED_BAND_MIN_KEY)) {
+               String valStr = mUserBandMinPref.getText();
+               double freq = Double.parseDouble(valStr) * 1000;
+               max_freq = FmSharedPreferences.getUpperLimit();
+               min_freq = FmSharedPreferences.getLowerLimit();
+               if((freq > 0) && (freq < max_freq) && (freq >= 76000)) {
+                  FmSharedPreferences.setLowerLimit((int)freq);
+                  FMRadio.fmConfigure();
+                  FMTransmitterActivity.fmConfigure();
+                  setBandSummary(summaryBandItems.length - 1);
+                  clearStationList();
+               }else {
+                  displayToast(USR_BAND_MSG);
+               }
+           }else if(key.equals(USER_DEFINED_BAND_MAX_KEY)) {
+               String valStr = mUserBandMaxPref.getText();
+               double freq = Double.parseDouble(valStr) * 1000;
+               min_freq = FmSharedPreferences.getLowerLimit();
+               max_freq = FmSharedPreferences.getUpperLimit();
+               if((freq > 0) && (freq > min_freq) && (freq <= 108000)) {
+                  FmSharedPreferences.setUpperLimit((int)freq);
+                  FMRadio.fmConfigure();
+                  FMTransmitterActivity.fmConfigure();
+                  setBandSummary(summaryBandItems.length - 1);
+                  clearStationList();
+               }else {
+                  displayToast(USR_BAND_MSG);
+               }
           }else {
               if(mRxMode) {
                  if (key.equals(AUTO_AF)) {
@@ -242,40 +337,36 @@
                      mPrefs.Save();
                  }else if(key.equals(RECORD_DURATION_KEY)) {
                      if(FMRadio.RECORDING_ENABLE) {
-                        String[] recordItems = getResources().getStringArray(
-                                                    R.array.record_durations_entries);
                         String valueStr = mRecordDurPreference.getValue();
                         int index = 0;
                         if (valueStr != null) {
                             index = mRecordDurPreference.findIndexOfValue(valueStr);
                         }
-                        if ((index < 0) || (index >= recordItems.length)) {
+                          if ((index < 0) || (index >= summaryRecordItems.length)) {
                              index = 0;
                              mRecordDurPreference.setValueIndex(index);
                         }
                         Log.d(LOGTAG, "onSharedPreferenceChanged: recorddur: "
-                                                 + recordItems[index]);
-                        mRecordDurPreference.setSummary(recordItems[index]);
-                        FmSharedPreferences.setRecordDuration(index);
-                     }
-                 }else if (key.equals(AUDIO_OUTPUT_KEY)) {
-                     String[] bandItems = getResources().getStringArray(
-                                                R.array.ster_mon_entries);
-                     String valueStr = mAudioPreference.getValue();
-                     int index = 0;
-                     if (valueStr != null) {
-                         index = mAudioPreference.findIndexOfValue(valueStr);
-                     }
-                     if (index != 1) {
-                         if (index != 0) {
-                             index = 0;
-                             /* It shud be 0(Stereo) or 1(Mono) */
-                             mAudioPreference.setValueIndex(index);
-                         }
-                     }
-                     Log.d(LOGTAG, "onSharedPreferenceChanged: audiomode: "
-                                              + bandItems[index]);
-                     mAudioPreference.setSummary(bandItems[index]);
+                                     + summaryRecordItems[index]);
+                          mRecordDurPreference.setSummary(summaryRecordItems[index]);
+                          FmSharedPreferences.setRecordDuration(index);
+                       }
+                   } else if (key.equals(AUDIO_OUTPUT_KEY)) {
+                       String valueStr = mAudioPreference.getValue();
+                       int index = 0;
+                       if (valueStr != null) {
+                           index = mAudioPreference.findIndexOfValue(valueStr);
+                       }
+                       if (index != 1) {
+                          if (index != 0) {
+                              index = 0;
+                              /* It shud be 0(Stereo) or 1(Mono) */
+                              mAudioPreference.setValueIndex(index);
+                          }
+                       }
+                       Log.d(LOGTAG, "onSharedPreferenceChanged: audiomode: "
+                                      + summaryAudioModeItems[index]);
+                       mAudioPreference.setSummary(summaryAudioModeItems[index]);
                      if (index == 0) {
                          // Stereo
                          FmSharedPreferences.setAudioOutputMode(true);
@@ -394,4 +485,32 @@
               sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
           }
         }
+        private void setBandSummary(int index) {
+           if((index + 1) == summaryBandItems.length) {
+              min_freq = FmSharedPreferences.getLowerLimit();
+              max_freq = FmSharedPreferences.getUpperLimit();
+              chan_spacing = FmSharedPreferences.getChSpacing();
+              if(chan_spacing < 0) {
+                 chan_spacing = 0;
+              }
+              mBandPreference.setSummary(summaryBandItems[index] + "( "
+                       + (min_freq / 1000.0) +"Mhz To " + (max_freq / 1000.0) +
+                       "Mhz)");
+              mChannelSpacingPref.setValueIndex(2 - chan_spacing);
+              mChannelSpacingPref.setSummary(chSpacingItems[2 - chan_spacing]);
+              mChannelSpacingPref.setEnabled(true);
+              mUserBandMinPref.setEnabled(true);
+              mUserBandMaxPref.setEnabled(true);
+              mUserBandMinPref.setSummary((min_freq / 1000.0) + "Mhz");
+              mUserBandMaxPref.setSummary((max_freq / 1000.0) + "Mhz");
+           }else {
+              mBandPreference.setSummary(summaryBandItems[index]);
+              mChannelSpacingPref.setEnabled(false);
+              mUserBandMinPref.setEnabled(false);
+              mUserBandMaxPref.setEnabled(false);
+           }
+        }
+        private void displayToast(String msg) {
+           Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
+        }
 }