Home | History | Annotate | Download | only in fmtxapp
      1 /*
      2  *
      3  * Copyright 2001-2011 Texas Instruments, Inc. - http://www.ti.com/
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *    http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.ti.fmtxapp;
     19 
     20 import android.app.Activity;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.view.Menu;
     24 import android.view.MenuItem;
     25 import android.view.View;
     26 import android.util.Log;
     27 import android.widget.CheckBox;
     28 import android.widget.EditText;
     29 import android.widget.Button;
     30 import android.widget.CompoundButton;
     31 import android.widget.CompoundButton.OnCheckedChangeListener;
     32 import android.app.AlertDialog;
     33 import android.view.KeyEvent;
     34 import android.view.View.OnKeyListener;
     35 import android.widget.Toast;
     36 import android.app.ProgressDialog;
     37 import android.content.BroadcastReceiver;
     38 import android.os.Handler;
     39 import android.os.Message;
     40 import android.content.Context;
     41 import android.content.Intent;
     42 import android.content.IntentFilter;
     43 import android.app.Notification;
     44 import android.app.NotificationManager;
     45 import android.app.PendingIntent;
     46 import android.content.SharedPreferences;
     47 import android.content.DialogInterface;
     48 
     49 /*************** For calling lower layer********************/
     50 import com.ti.fm.FmRadio;
     51 import com.ti.fm.FmRadioIntent;
     52 import com.ti.fm.IFmConstants;
     53 import android.server.*;
     54 /**************************************************************/
     55 
     56 public class FmTx extends Activity implements View.OnClickListener,
     57 OnCheckedChangeListener,OnKeyListener,FmTxAppConstants,FmRadio.ServiceListener{
     58     /** Called when the activity is first created. */
     59     public static final String TAG = "FmTxApp";
     60 
     61     /********************************************
     62      * Menu Constants
     63      ********************************************/
     64     public static final int MENU_CONFIGURE = Menu.FIRST + 1;
     65 //    public static final int MENU_ADVANCED = Menu.FIRST + 2;
     66     public static final int MENU_EXIT = Menu.FIRST + 2;
     67     public static final int MENU_ABOUT = Menu.FIRST + 3;
     68 
     69 
     70     /********************************************
     71      * Initail values
     72      ********************************************/
     73     private int mTxMode = INITIAL_VAL;
     74     private int mPiCode = INITIAL_VAL;
     75     private int mAfCode = INITIAL_VAL;
     76     private int mTuneFreq = INITIAL_VAL;
     77     private int mDeEmpFilter = INITIAL_VAL;
     78     private int mPowerLevel = INITIAL_VAL;
     79     private int mRepertoire = INITIAL_VAL;
     80     private int mMonoStereo = INITIAL_VAL;
     81     private int mDisplayMode = INITIAL_VAL;
     82     private int mEcc = INITIAL_VAL;
     83     private int mTxMusicSpeech = INITIAL_VAL;
     84     private int mTxEmpFilter = INITIAL_VAL;
     85     private int mTxPtyCode = INITIAL_VAL;
     86     private Float mFreq = (float)INITIAL_VAL;
     87     //private int mMute = INITIAL_VAL;
     88     /*Flag to check if service is connected*/
     89     boolean mFmServiceConnected = false;
     90 
     91 
     92     public SharedPreferences fmTxPreferences;
     93     private int mAppState = STATE_DEFAULT;
     94 
     95     public static Float freqValue = (float)0;
     96     private ProgressDialog pd = null,configPd;
     97 
     98         public static FmRadio sFmRadio;
     99     private CheckBox startTxBtn,enableRdsBtn,chbMute;
    100     private EditText textFreq;
    101     private boolean mStatus;
    102     private Button btnOk;
    103     private boolean isFmEnabled = false;
    104 
    105     /* Actvity result index */
    106     public static final int ACTIVITY_CONFIG = 1;
    107 
    108 
    109     private NotificationManager mNotificationManager;
    110 
    111 
    112     Context mContext;
    113 
    114     @Override
    115     public void onCreate(Bundle savedInstanceState) {
    116        super.onCreate(savedInstanceState);
    117        Log.d(TAG, "onCreate enter");
    118        mContext = this;
    119 
    120 
    121     // Register for FM TX intent broadcasts.
    122     IntentFilter intentFilter = new IntentFilter();
    123     intentFilter.addAction(FmRadioIntent.FM_TX_ENABLED_ACTION);
    124     intentFilter.addAction(FmRadioIntent.FM_TX_TUNE_ACTION);
    125     intentFilter.addAction(FmRadioIntent.FM_TX_DISABLED_ACTION);
    126     intentFilter.addAction(FmRadioIntent.FM_TX_START_TRANSMISSION_ACTION);
    127     intentFilter.addAction(FmRadioIntent.FM_TX_STOP_TRANSMISSION_ACTION);
    128     intentFilter.addAction(FmRadioIntent.FM_TX_DESTROY_ACTION);
    129     intentFilter.addAction(FmRadioIntent.FM_TX_ENABLE_RSD_ACTION);
    130     intentFilter.addAction(FmRadioIntent.FM_TX_DISABLE_RSD_ACTION);
    131     intentFilter.addAction(FmRadioIntent.FM_TX_PS_DISPLAY_MODE_ACTION);
    132     intentFilter.addAction(FmRadioIntent.FM_TX_SET_RDS_MUSIC_SPEECH_FLAG_ACTION);
    133     intentFilter.addAction(FmRadioIntent.FM_TX_SET_RDS_TEXT_REPERTOIRE_ACTION);
    134     intentFilter.addAction(FmRadioIntent.FM_TX_SET_TRANSMISSION_MODE_ACTION);
    135     intentFilter.addAction(FmRadioIntent.FM_TX_SET_POWER_LEVEL_ACTION);
    136     intentFilter.addAction(FmRadioIntent.FM_TX_SET_RDS_TEXT_PS_MSG_ACTION);
    137     intentFilter.addAction(FmRadioIntent.FM_TX_SET_MONO_STEREO_MODE_ACTION);
    138     intentFilter.addAction(FmRadioIntent.FM_TX_SET_MUTE_MODE_ACTION);
    139     intentFilter.addAction(FmRadioIntent.FM_TX_SET_RDS_TRANSMISSION_GROUPMASK_ACTION);
    140     registerReceiver(mReceiver, intentFilter);
    141 
    142 
    143         sFmRadio = new FmRadio(this, this);
    144 
    145        setContentView(R.layout.main);
    146     initControls();
    147     loadlastSaveddata();
    148 
    149 
    150     }
    151 
    152   @Override
    153     public void onPause() {
    154        super.onPause();
    155        Log.d(TAG, "onPause enter");
    156        saveLastData();
    157 }
    158 /******************************************
    159 *
    160 *        enableTx()
    161 *
    162 *******************************************/
    163        private void enableTx()
    164        {
    165 
    166        Log.i(TAG,"enableTx()");
    167 
    168     switch (sFmRadio.txGetFMState()){
    169 
    170     case STATE_DISABLED:
    171     case STATE_DEFAULT:
    172         mStatus = sFmRadio.txEnable();
    173         if (mStatus == false) {
    174             Log.i(TAG, "Fm Tx --> Cannot enable TX !!");
    175 
    176         CharSequence text = "Sorry!! Cannot enable TX";
    177         int duration = Toast.LENGTH_SHORT;
    178 
    179         Toast toast = Toast.makeText(mContext, text, duration);
    180         toast.setGravity(android.view.Gravity.CENTER_VERTICAL, 0, 0);
    181         toast.show();
    182 
    183         finish();
    184 
    185         }
    186         else{
    187             Log.i(TAG, "Fm Tx --> Enabling TX !!");
    188             pd = ProgressDialog.show(this, "Please wait..",    "Enabling FM TX", true, false);
    189         }
    190 
    191 
    192         break;
    193 
    194     case STATE_ENABLED:
    195              loadlastSaveddata();
    196         Log.i(TAG, "Fm Tx is already Enabled.");
    197         break;
    198 
    199     }
    200 
    201 
    202        }
    203 
    204 
    205 public void onServiceConnected() {
    206     Log.i(TAG, "onServiceConnected");
    207     mFmServiceConnected =true;
    208     enableTx();
    209 }
    210 
    211 public void onServiceDisconnected() {
    212     Log.d(TAG, "Lost connection to service");
    213     mFmServiceConnected =false;
    214     sFmRadio = null;
    215 }
    216 
    217 
    218 /******************************************
    219 *
    220 *        onCreateOptionsMenu()
    221 *
    222 *******************************************/
    223         public boolean onCreateOptionsMenu(Menu menu) {
    224 
    225             super.onCreateOptionsMenu(menu);
    226             MenuItem item;
    227 
    228             item = menu.add(0, MENU_CONFIGURE, 0, R.string.configure);
    229             item.setIcon(R.drawable.configure);
    230 
    231 
    232             /*item = menu.add(0, MENU_ADVANCED, 0, R.string.advanced);
    233             item.setIcon(R.drawable.configure);*/
    234 
    235             item = menu.add(0, MENU_ABOUT, 0, R.string.about);
    236             item.setIcon(R.drawable.icon);
    237 
    238             item = menu.add(0, MENU_EXIT, 0, R.string.exit);
    239             item.setIcon(R.drawable.icon);
    240 
    241             return true;
    242         }
    243 
    244 /******************************************
    245 *
    246 * onOptionsItemSelected()
    247 *Handles item selections
    248 *
    249 *******************************************/
    250 
    251         public boolean onOptionsItemSelected(MenuItem item) {
    252 
    253             switch (item.getItemId()) {
    254             case MENU_CONFIGURE:
    255 
    256             /* Start the configuration window */
    257             Intent irds = new Intent("android.intent.action.RDSPARAM_CONFIG");
    258             startActivityForResult(irds, ACTIVITY_CONFIG);
    259 
    260                 break;
    261 
    262      /*    case MENU_ADVANCED:
    263             Intent iAdvanced = new Intent("android.intent.action.TXPARAM_CONFIG");
    264             startActivityForResult(iAdvanced, ACTIVITY_ADVANCED);
    265 
    266 
    267              break;*/
    268 
    269             case MENU_EXIT:
    270                 saveLastData();
    271                 /*
    272                  * The exit from the FM application happens here The audio will be
    273                  * disabled and when he callback for this is recived, FM will be
    274                  * disabled
    275                  */
    276                 mStatus = sFmRadio.txDisable();
    277                 if (mStatus == false) {
    278                 Log.i(TAG, "Fm Tx--> Cannot Disable TX !!");
    279 
    280                 }
    281                 else{
    282                 Log.i(TAG, "Fm Tx--> Disabling TX !!");
    283                 }
    284             break;
    285 
    286             case MENU_ABOUT:
    287                 /* Start the help window */
    288                 Intent iTxHelp = new Intent("android.intent.action.START_TXABOUT");
    289                 startActivity(iTxHelp);
    290                 break;
    291 
    292 
    293             }
    294             return super.onOptionsItemSelected(item);
    295         }
    296 
    297 
    298     /** Adds Delay of 2 seconds */
    299     private void insertDelayThread() {
    300 
    301         new Thread() {
    302             public void run() {
    303                 try {
    304                     // Add some delay to make sure all configuration has been
    305                     // completed.
    306                     sleep(2000);
    307                 } catch (Exception e) {
    308                     Log.e(TAG, "InsertDelayThread()-- Exception !!");
    309                 }
    310                 // Dismiss the Dialog
    311                 configPd.dismiss();
    312             }
    313         }.start();
    314 
    315     }
    316 
    317 
    318     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    319         super.onActivityResult(requestCode, resultCode, data);
    320         Log.i(TAG, "onActivityResult");
    321         switch (requestCode) {
    322 
    323 /*        case (ACTIVITY_ADVANCED):{
    324             if (resultCode == Activity.RESULT_OK) {
    325                     setAdvancedConfig();
    326                     configPd = ProgressDialog.show(this, "Please wait..",
    327                             "Applying Advanced Configuration", true, false);
    328                     // The delay is inserted to make sure all the configurations
    329                     // have been completed.
    330                     insertDelayThread();
    331 
    332             }
    333         }
    334         break;
    335 
    336 */
    337 
    338         case (ACTIVITY_CONFIG): {
    339             if (resultCode == Activity.RESULT_OK) {
    340                 //Log.i(TAG, "ActivityFmRdsConfig configurationState "+ configurationState);
    341 
    342                     setRdsConfig();
    343                     setAdvancedConfig();
    344                     configPd = ProgressDialog.show(this, "Please wait..",
    345                             "Applying new Configuration", true, false);
    346                     // The delay is inserted to make sure all the configurations
    347                     // have been completed.
    348                     insertDelayThread();
    349 
    350             }
    351         }
    352             break;
    353 
    354         }
    355     }
    356 
    357 
    358 
    359 
    360 /*************************************
    361 
    362 setAdvancedConfig()
    363 
    364 *************************************/
    365 private void setAdvancedConfig()
    366 {
    367     Log.i(TAG, "setAdvancedConfig");
    368     SharedPreferences fmTxParamConfigPreferences = getSharedPreferences(                "fmConfigPreferences", MODE_PRIVATE);
    369 
    370 
    371     //Set Music-Speech Flag
    372 /*    int txMusicSpeech = fmTxParamConfigPreferences.getInt(MUSIC_SPEECH, DEFAULT_MUSICSPEECH);
    373     Log.i(TAG,"setAdvancedConfig-- >txMusicSpeech = "+txMusicSpeech);
    374     if (mTxMusicSpeech != txMusicSpeech) {
    375         mTxMusicSpeech = txMusicSpeech;
    376         mStatus = sFmRadio.txSetRdsMusicSpeechFlag(txMusicSpeech);
    377         if (mStatus == false) {
    378         Log.i(TAG, "Fm Tx--> txSetRdsMusicSpeechFlag TX failed !!");
    379         }
    380         else{
    381         Log.i(TAG, "Fm Tx--> TX txSetRdsMusicSpeechFlag is SUCCESSFUll !!");
    382         }
    383     }
    384 */
    385     //Set Pre-Emp Filter
    386 /*    int txEmpFilter = fmTxParamConfigPreferences.getInt(EMP_FILTER, DEFAULT_EMPFILTER);
    387     Log.i(TAG,"setAdvancedConfig-- >txEmpFilter = "+txMusicSpeech);
    388     if (mTxEmpFilter != txEmpFilter) {
    389         mTxEmpFilter = txEmpFilter;
    390         mStatus = sFmRadio.txSetPreEmphasisFilter(txEmpFilter);
    391         if (mStatus == false) {
    392         Log.i(TAG, "Fm Tx--> txSetPreEmphasisFilter TX failed !!");
    393         }
    394         else{
    395         Log.i(TAG, "Fm Tx--> TX txSetPreEmphasisFilter is SUCCESSFUll !!");
    396         }
    397     }
    398 */
    399 
    400     // Before Setting RT String , set the Tx group Mask
    401 
    402     Log.i(TAG, "txSetRdsTransmittedGroupsMask(RT)");
    403     mStatus = sFmRadio.txSetRdsTransmittedGroupsMask(RDS_RADIO_TRANSMITTED_GRP_RT_MASK | RDS_RADIO_TRANSMITTED_GRP_PS_MASK);
    404     if (mStatus == false) {
    405     Log.i(TAG, "Fm Tx--> txSetRdsTransmittedGroupsMask TX failed !!");
    406     }else{
    407     Log.i(TAG, "Fm Tx--> TX txSetRdsTransmittedGroupsMask is SUCCESSFUll !!");
    408     }
    409 
    410        //Set Radio Text Code
    411 
    412        String txRTCode = fmTxParamConfigPreferences.getString(RT_STRING, DEF_RT_STRING);
    413     boolean rtMask= fmTxParamConfigPreferences.getBoolean(RTENABLED,false);
    414     int rds_mode = 2;
    415 
    416        Log.i(TAG,"setAdvancedConfig-- >txRT = "+txRTCode);
    417        if (rtMask) {
    418              mStatus = sFmRadio.txSetRdsTextRtMsg(rds_mode, txRTCode, txRTCode.length());
    419              if (mStatus == false) {
    420              Log.i(TAG, "Fm Tx--> txSetRdsRadioText TX failed !!");
    421              }
    422              else{
    423              Log.i(TAG, "Fm Tx--> TX txSetRdsRadioText is SUCCESSFUll !!");
    424              }
    425      }else {
    426         txRTCode = "";
    427         mStatus = sFmRadio.txSetRdsTextRtMsg(rds_mode, txRTCode, txRTCode.length());
    428              if (mStatus == false) {
    429              Log.i(TAG, "Fm Tx--> txSetRdsRadioText TX failed !!");
    430              }
    431              else{
    432              Log.i(TAG, "Fm Tx--> TX txSetRdsRadioText is Emty!!");
    433              }
    434     }
    435 
    436        //Set PS Name
    437        String txPSName = fmTxParamConfigPreferences.getString(PS_STRING, DEF_PS_STRING);
    438     boolean psMask= fmTxParamConfigPreferences.getBoolean(PSENABLED,false);
    439 
    440        Log.i(TAG,"setAdvancedConfig-- >txPSName = "+txPSName);
    441        if (psMask) {
    442              mStatus = sFmRadio.txSetRdsTextPsMsg(txPSName);
    443              if (mStatus == false) {
    444              Log.i(TAG, "Fm Tx--> txSetRdsPSName TX failed !!");
    445              }
    446              else{
    447              Log.i(TAG, "Fm Tx--> TX txSetRdsPSName is SUCCESSFUll !!");
    448              }
    449      }else {
    450         txPSName = "";
    451              mStatus = sFmRadio.txSetRdsTextPsMsg(txPSName);
    452              if (mStatus == false) {
    453              Log.i(TAG, "Fm Tx--> txSetRdsPSName TX failed !!");
    454              }
    455              else{
    456              Log.i(TAG, "Fm Tx--> TX txSetRdsPSName is Empty !!");
    457         }
    458     }
    459 
    460     //Set Pty Code
    461     int txPtyCode = fmTxParamConfigPreferences.getInt(PTY,DEFAULT_PTY);
    462     Log.i(TAG,"setAdvancedConfig-- >txPtyCode = "+txPtyCode);
    463     if (mTxPtyCode != txPtyCode) {
    464         mTxPtyCode = txPtyCode;
    465         mStatus = sFmRadio.txSetRdsPtyCode(txPtyCode);
    466         if (mStatus == false) {
    467         Log.i(TAG, "Fm Tx--> txSetRdsPtyCode TX failed !!");
    468         }
    469         else{
    470         Log.i(TAG, "Fm Tx--> TX txSetRdsPtyCode is SUCCESSFUll !!");
    471         }
    472     }
    473 
    474 /*
    475     int ecc = fmTxParamConfigPreferences.getInt(ECC, DEFAULT_ECC);
    476     Log.i(TAG,"setAdvancedConfig-- >ecc ="+ecc);
    477     if (mEcc != ecc) {
    478         mEcc = ecc;
    479         mStatus = sFmRadio.txSetRdsECC(ecc);
    480         if (mStatus == false) {
    481         Log.i(TAG, "Fm Tx--> txSetRdsECC TX failed !!");
    482         }
    483         else{
    484         Log.i(TAG, "Fm Tx--> TX txSetRdsECC is SUCCESSFUll !!");
    485         }
    486     }
    487 */
    488 
    489 
    490 }
    491 
    492 
    493 
    494 /*************************************
    495 
    496 setRdsConfig()
    497 
    498 *************************************/
    499 private void setRdsConfig()
    500 {
    501     Log.i(TAG, "setRdsConfig");
    502         SharedPreferences fmConfigPreferences = getSharedPreferences(
    503                 "fmConfigPreferences", MODE_PRIVATE);
    504 
    505         String psStr = fmConfigPreferences.getString(PS_STRING,DEF_PS_STRING);
    506         Log.i(TAG, "setRdsConfig()--- psStr= " + psStr.toString());
    507 
    508 
    509         String rtstr = fmConfigPreferences.getString(RT_STRING,DEF_RT_STRING);
    510         Log.i(TAG, "setRdsConfig()--- RtStr= " + rtstr.toString());
    511 
    512         // Set TxMode
    513         int txMode = fmConfigPreferences.getInt(TX_MODE, DEFAULT_TXMODE);
    514         Log.i(TAG,"setRdsConfig-- >txMode = "+txMode);
    515 
    516             mStatus = sFmRadio.txSetRdsTransmissionMode(txMode);
    517         /*if (mTxMode != txMode) {
    518             mTxMode = txMode;
    519             mStatus = sFmRadio.txSetRdsTransmissionMode(txMode);
    520             if (mStatus == false) {
    521             Log.i(TAG, "Fm Tx--> txSetRdsTransmissionMode TX failed !!");
    522             }
    523             else{
    524             Log.i(TAG, "Fm Tx--> TX txSetRdsTransmissionMode is SUCCESSFUll !!");
    525             }
    526         }*/
    527 
    528         // Set Ps DispalyMode
    529         /*int psDisplayMode = fmConfigPreferences.getInt(DISPLAY_MODE, DEFAULT_DISPLAYMODE);
    530         Log.i(TAG,"setRdsConfig-- >psDisplayMode = "+psDisplayMode);
    531         if (mDisplayMode != psDisplayMode) {
    532             mDisplayMode = txMode;
    533             mStatus = sFmRadio.txSetRdsPsDisplayMode(psDisplayMode);
    534             if (mStatus == false) {
    535             Log.i(TAG, "Fm Tx--> txSetRdsPsDisplayMode TX failed !!");
    536             }
    537             else{
    538             Log.i(TAG, "Fm Tx--> TX txSetRdsPsDisplayMode is SUCCESSFUll !!");
    539             }
    540         }*/
    541 
    542 
    543 
    544         // Set Mono/Stereo Flag
    545         int monoStereo = fmConfigPreferences.getInt(MONO_STEREO, DEFAULT_MONOSTEREO);
    546         Log.i(TAG,"setRdsConfig-- >monoStereo = "+monoStereo);
    547         if (mMonoStereo != monoStereo) {
    548             mMonoStereo = monoStereo;
    549             mStatus = sFmRadio.txSetMonoStereoMode(monoStereo);
    550             if (mStatus == false) {
    551             Log.i(TAG, "Fm Tx--> txSetMonoStereoMode TX failed !!");
    552             }
    553             else{
    554             Log.i(TAG, "Fm Tx--> TX txSetMonoStereoMode is SUCCESSFUll !!");
    555             }
    556         }
    557 
    558 
    559         // Set Repetoire
    560         /*int repetoire = fmConfigPreferences.getInt(REPERTOIRE, DEFAULT_REPERTOIRE);
    561         Log.i(TAG,"setRdsConfig-- >repetoire = "+repetoire);
    562         if (mMonoStereo != repetoire) {
    563             mMonoStereo = repetoire;
    564             mStatus = sFmRadio.txSetRdsTextRepertoire(repetoire);
    565             if (mStatus == false) {
    566             Log.i(TAG, "Fm Tx--> txSetRdsTextRepertoire TX failed !!");
    567             }
    568             else{
    569             Log.i(TAG, "Fm Tx--> TX txSetRdsTextRepertoire is SUCCESSFUll !!");
    570             }
    571         }*/
    572 
    573 
    574         // Before Setting Ps String , set the Tx group Mask
    575         boolean rtMask= fmConfigPreferences.getBoolean(RTENABLED,false);
    576         boolean psMask= fmConfigPreferences.getBoolean(PSENABLED,false);
    577         int rdsMask=(int) RDS_RADIO_TRANSMITTED_GRP_RT_MASK;
    578         if(rtMask)
    579         rdsMask = (int) (rdsMask |RDS_RADIO_TRANSMITTED_GRP_RT_MASK) ;
    580         if(psMask)
    581         rdsMask = (int) (rdsMask | RDS_RADIO_TRANSMITTED_GRP_PS_MASK);
    582 
    583         Log.i(TAG, "txSetRdsTransmittedGroupsMask(rdsMask )" +rdsMask );
    584         mStatus = sFmRadio.txSetRdsTransmittedGroupsMask(RDS_RADIO_TRANSMITTED_GRP_PS_MASK);
    585         if (mStatus == false) {
    586         Log.i(TAG, "Fm Tx--> txSetRdsTransmittedGroupsMask TX failed !!");
    587         }else{
    588         Log.i(TAG, "Fm Tx--> TX txSetRdsTransmittedGroupsMask is SUCCESSFUll !!");
    589         }
    590 
    591 
    592 
    593 
    594         // Set Power Level
    595         int powerLevel = fmConfigPreferences.getInt(POWER,DEFAULT_POWER);
    596         Log.i(TAG,"setRdsConfig-- >powerLevel ="+powerLevel);
    597         if (mPowerLevel != powerLevel) {
    598             mPowerLevel = powerLevel;
    599             mStatus = sFmRadio.txSetPowerLevel(powerLevel);
    600             if (mStatus == false) {
    601             Log.i(TAG, "Fm Tx--> txSetPowerLevel TX failed !!");
    602             }
    603             else{
    604             Log.i(TAG, "Fm Tx--> TX txSetPowerLevel is SUCCESSFUll !!");
    605             }
    606         }
    607 
    608 
    609 
    610         // Set Pi Code
    611         int piCode = fmConfigPreferences.getInt(PI_CODE,DEFAULT_PICODE);
    612         Log.i(TAG,"setRdsConfig-- >piCode =" +    piCode );
    613 
    614         if (mPiCode != piCode) {
    615             mPiCode = piCode;
    616             mStatus = sFmRadio.txSetRdsPiCode(piCode);
    617             if (mStatus == false) {
    618             Log.i(TAG, "Fm Tx--> txSetRdsPiCode TX failed !!");
    619             }
    620             else{
    621             Log.i(TAG, "Fm Tx--> TX txSetRdsPiCode is SUCCESSFUll !!");
    622             }
    623         }
    624 
    625 
    626         // Set Af Code
    627         int afCode = fmConfigPreferences.getInt(AF_CODE,DEFAULT_AFCODE);
    628         Log.i(TAG,"setRdsConfig-- >afCode = "+afCode);
    629         if (mAfCode != afCode) {
    630             mAfCode = afCode;
    631             mStatus = sFmRadio.txSetRdsAfCode(afCode);
    632             if (mStatus == false) {
    633             Log.i(TAG, "Fm Tx--> txSetRdsAfCode TX failed !!");
    634             }
    635             else{
    636             Log.i(TAG, "Fm Tx--> TX txSetRdsAfCode is SUCCESSFUll !!");
    637             }
    638         }
    639 
    640 
    641 
    642 }
    643 /************************************************************************************
    644 *
    645 * initControls()
    646 * Initialize all the UI controls
    647 *
    648 *************************************************************************************/
    649         public void initControls()
    650         {
    651          startTxBtn  = (CheckBox)findViewById(R.id.ChbTx);
    652          startTxBtn.setOnCheckedChangeListener(this);
    653 
    654          enableRdsBtn  = (CheckBox)findViewById(R.id.chbEnableRds);
    655          enableRdsBtn.setOnCheckedChangeListener(this);
    656 
    657         chbMute = (CheckBox)findViewById(R.id.chbMute);
    658               chbMute.setOnCheckedChangeListener(this);
    659 
    660         textFreq = (EditText)findViewById(R.id.edtTxFreq);
    661 
    662         btnOk = (Button) findViewById(R.id.btnOk);
    663         btnOk.setOnKeyListener(this);
    664         btnOk.setOnClickListener(this);
    665 
    666         // Get the notification manager service.
    667         mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    668 
    669 
    670         }
    671 
    672 
    673 /************************************************************************************
    674 *
    675 * onCheckedChanged()
    676 *
    677 *************************************************************************************/
    678 
    679         public void onCheckedChanged(CompoundButton btn, boolean checkedState) {
    680             // TODO Auto-generated method stub
    681             /*if (checkedState ){
    682             startTxBtn.setText("Uncheck to stop Tx");
    683             }
    684             else{
    685 
    686             //sFmRadio.txStopTransmission();
    687             startTxBtn.setText("Check to start Tx");
    688 
    689             }*/
    690 
    691         int id = btn.getId();
    692         switch (id) {
    693         case R.id.ChbTx:
    694             if (checkedState ){
    695             startTxBtn.setText("Uncheck to stop Tx");
    696             }else{
    697             startTxBtn.setText("Check to start Tx");
    698             }
    699             break;
    700 
    701         case R.id.chbEnableRds:
    702             if (checkedState ){
    703             enableRdsBtn.setText("Uncheck to Disable Rds");
    704             }else{
    705             enableRdsBtn.setText("Check to Enable Rds");
    706             }
    707             break;
    708 
    709         default:
    710             break;
    711         }
    712         }
    713 
    714 /************************************************************************************
    715 *
    716 * BaseFreq()
    717 *
    718 *************************************************************************************/
    719     static float BaseFreq() {
    720         return APP_FM_FIRST_FREQ_US_EUROPE_KHZ;
    721     }
    722 
    723 
    724 /************************************************************************************
    725 *
    726 *LastFreq()
    727 *
    728 *************************************************************************************/
    729     static float LastFreq() {
    730         return APP_FM_LAST_FREQ_US_EUROPE_KHZ;
    731     }
    732 
    733 
    734 /************************************************************************************
    735 * Update the Frequency label with the given value
    736 *
    737 *************************************************************************************/
    738 
    739 
    740     float UpdateFrequency(float freq) {
    741         Log.d(TAG, "FM App: UpdateFrequency %d." + freq);
    742         if (freq < BaseFreq() || freq > LastFreq()) {
    743             freq = 0;
    744         }
    745         Log.d(TAG, "FM App: returned %d." + freq);
    746         return (float) freq;
    747     }
    748 
    749 /************************************************************************************
    750 *       writeFrequency()
    751 *
    752 *************************************************************************************/
    753     private void writeFrequency() {
    754         // get the text entered in edit box
    755         String text = textFreq.getText().toString();
    756         Log.d("writeFrequency()","--> text ="+text);
    757         try {
    758 
    759             float iFreq = Float.parseFloat(text);
    760             Log.d("writeFrequency()","--> iFreq ="+iFreq);
    761             Float validFreq = UpdateFrequency(iFreq);
    762             if (validFreq != 0) {
    763                 freqValue = validFreq;
    764 
    765             }
    766             else {
    767                 new AlertDialog.Builder(this).setIcon(
    768                         android.R.drawable.ic_dialog_alert).setMessage(
    769                         "Enter valid frequency!!").setNegativeButton(
    770                         android.R.string.ok, null).show();
    771                 textFreq.setText(null);
    772             }
    773         } catch (NumberFormatException nfe) {
    774             Log.d(TAG, "NumberFormatException:" + nfe.getMessage());
    775             new AlertDialog.Builder(this).setIcon(
    776                     android.R.drawable.ic_dialog_alert).setMessage(
    777                     "Enter valid number!!").setNegativeButton(
    778                     android.R.string.ok, null).show();
    779             textFreq.setText(null);
    780                    freqValue = (float) 0;
    781         }
    782 
    783     }
    784 
    785 /*************************************************************************
    786 *
    787 * This is a method implementation of OnKeyListener
    788 *
    789 *************************************************************************/
    790     public boolean onKey(View v, int keyCode, KeyEvent event) {
    791             Log.i(TAG,"onKey()");
    792         if (event.getAction() == KeyEvent.ACTION_DOWN) {
    793             switch (keyCode) {
    794             case KeyEvent.KEYCODE_DPAD_CENTER:
    795             case KeyEvent.KEYCODE_ENTER:
    796                 writeFrequency();
    797                 if (startTxBtn.isChecked()){
    798                  // Tune TX
    799         Log.i(TAG, "Fm Tx--> TX Tune is (long)(freqValue.floatValue()*1000) !!"+(long)(freqValue.floatValue()*1000));
    800 
    801                      mStatus =  sFmRadio.txTune((long)(freqValue.floatValue()*1000));
    802                 if (mStatus == false) {
    803                 Log.i(TAG, "Fm Tx--> Tune TX failed !!");
    804                 }
    805                 else{
    806                 Log.i(TAG, "Fm Tx--> TX Tune is SUCCESSFUll !!");
    807                 }
    808                 }
    809                 return true;
    810             }
    811         }
    812         return false;
    813     }
    814 
    815 
    816 /*************************************************************************
    817 *
    818 * This is a method implementation of onKeyDown
    819 *
    820 *************************************************************************/
    821     public boolean onKeyDown(int keyCode, KeyEvent event) {
    822         Log.i(TAG,"onKeyDown()");
    823         switch (keyCode) {
    824         case KeyEvent.KEYCODE_DPAD_CENTER:
    825             writeFrequency();
    826             if (startTxBtn.isChecked()){
    827                  /* Tune TX */
    828                      mStatus =  sFmRadio.txTune((long)(freqValue.floatValue()*1000));
    829                 if (mStatus == false) {
    830                 Log.i(TAG, "Fm Tx--> Tune TX failed !!");
    831                 }
    832                 else{
    833                 Log.i(TAG, "Fm Tx--> TX Tune is SUCCESSFUll !!");
    834                 }
    835 
    836             }
    837             return true;
    838 
    839         case KeyEvent.KEYCODE_DPAD_UP:
    840             return true;
    841 
    842         case KeyEvent.KEYCODE_BACK:
    843         Log.i("onKeyDown()","KEYCODE_BACK");
    844             finish();
    845             return true;
    846 
    847         case KeyEvent.KEYCODE_HOME:
    848         Log.i("onKeyDown()","KEYCODE_HOME");
    849             //this.showNotification(R.drawable.radio, R.string.app_name,textFreq.getText(), false);
    850             //moved the notification to TX
    851             //finish();
    852             return true;
    853 
    854 
    855 
    856             /* Keys A to L are mapped to different get APIs for Testing */
    857         case KeyEvent.KEYCODE_A:
    858                Log.i("onKeyDown()","KEYCODE_A");
    859             Log.i(TAG, "Testing txSetRdsTextPsMsg(psStr)    returned  = "
    860                     + sFmRadio.txSetRdsTextPsMsg("psStr"));
    861             return true;
    862 
    863         case KeyEvent.KEYCODE_B:
    864         Log.i("onKeyDown()","KEYCODE_B");
    865             Log.i(TAG, "Testing txWriteRdsRawData(RawData)    returned= "
    866                     + sFmRadio.txWriteRdsRawData("RdsRawData"));
    867             return true;
    868 
    869         case KeyEvent.KEYCODE_C:
    870         Log.i("onKeyDown()","KEYCODE_C");
    871             sFmRadio.txSetRdsTransmissionMode(1);
    872 
    873             return true;
    874 
    875         case KeyEvent.KEYCODE_D:
    876         Log.i("onKeyDown()","KEYCODE_D");
    877             Log.i(TAG, "Testing txSetMonoStereoMode(0)    returned= "
    878                     + sFmRadio.txSetMonoStereoMode(0));
    879             return true;
    880 
    881         case KeyEvent.KEYCODE_E:
    882         Log.i("onKeyDown()","KEYCODE_E");
    883             Log.i(TAG, "Testing txSetPreEmphasisFilter(1)    returned = "
    884                     + sFmRadio.txSetPreEmphasisFilter(1));
    885         return true;
    886 
    887         case KeyEvent.KEYCODE_F:
    888         Log.i("onKeyDown()","KEYCODE_F");
    889               Log.i(TAG, "Testing txSetMuteMode(0) returned = "
    890                     + sFmRadio.txSetMuteMode(0));
    891         return true;
    892 
    893         case KeyEvent.KEYCODE_G:
    894         Log.i("onKeyDown()","KEYCODE_G");
    895             Log.i(TAG, "Testing txSetRdsAfCode(224)  returned = "
    896                     + sFmRadio.txSetRdsAfCode(224));
    897             return true;
    898 
    899         case KeyEvent.KEYCODE_H:
    900         Log.i("onKeyDown()","KEYCODE_H");
    901             Log.i(TAG,"Testing txSetRdsPiCode(5)    returned = "
    902                             + sFmRadio.txSetRdsPiCode(5));
    903             return true;
    904 
    905         case KeyEvent.KEYCODE_I:
    906         Log.i("onKeyDown()","KEYCODE_I");
    907             Log.i(TAG, "Testing txSetRdsPtyCode(0) returned  = "
    908                     + sFmRadio.txSetRdsPtyCode(0));
    909             return true;
    910 
    911         case KeyEvent.KEYCODE_J:
    912         Log.i("onKeyDown()","KEYCODE_J");
    913             Log.i(TAG, "Testing txSetRdsTextRepertoire(0) returned = "
    914                     + sFmRadio.txSetRdsTextRepertoire(0));
    915             return true;
    916 
    917         case KeyEvent.KEYCODE_K:
    918         Log.i("onKeyDown()","KEYCODE_K");
    919             Log.i(TAG,"Testing txSetRdsPsDisplayMode(0) returned = "
    920                             + sFmRadio.txSetRdsPsDisplayMode(0));
    921             return true;
    922 
    923         case KeyEvent.KEYCODE_L:
    924         Log.i("onKeyDown()","KEYCODE_L");
    925             Log.i(TAG, "Testing txChangeDigitalSourceConfiguration(1)    returned  = "
    926                     + sFmRadio.txChangeDigitalSourceConfiguration(1));
    927 
    928             return true;
    929 
    930         case KeyEvent.KEYCODE_M:
    931         Log.i("onKeyDown()","KEYCODE_M");
    932             Log.i(TAG, "Testing txSetRdsPsScrollSpeed(3)    returned  = "
    933                     + sFmRadio.txSetRdsPsScrollSpeed(3));
    934             return true;
    935 
    936         case KeyEvent.KEYCODE_N:
    937         Log.i("onKeyDown()","KEYCODE_N");
    938             Log.i(TAG, "Testing txSetRdsTextRtMsg(2,RtMsg,5)    returned  = "
    939                     + sFmRadio.txSetRdsTextRtMsg(2,"RtMsg",5));
    940             return true;
    941 
    942         case KeyEvent.KEYCODE_O:
    943         Log.i("onKeyDown()","KEYCODE_O");
    944                     Log.i(TAG,
    945                     "Testing txSetRdsTransmittedGroupsMask(1) returned = "
    946                             + sFmRadio.txSetRdsTransmittedGroupsMask(7));
    947             return true;
    948 
    949         case KeyEvent.KEYCODE_P:
    950         Log.i("onKeyDown()","KEYCODE_P");
    951             Log.i(TAG,
    952                     "Testing txSetRdsTrafficCodes(0,0)    returned = "
    953                             + sFmRadio.txSetRdsTrafficCodes(0,0));
    954 
    955             return true;
    956 
    957         case KeyEvent.KEYCODE_Q:
    958         Log.i("onKeyDown()","KEYCODE_Q");
    959             Log.i(TAG,
    960                     "Testing txSetRdsMusicSpeechFlag(1)    returned = "
    961                             + sFmRadio.txSetRdsMusicSpeechFlag(1));
    962 
    963             return true;
    964 
    965         case KeyEvent.KEYCODE_R:
    966         Log.i("onKeyDown()","KEYCODE_R");
    967             Log.i(TAG, "Testing txSetRdsECC(0)    returned  = "
    968                     + sFmRadio.txSetRdsECC(0));
    969 
    970             return true;
    971 
    972         case KeyEvent.KEYCODE_S:
    973         Log.i("onKeyDown()","KEYCODE_S");
    974             Log.i(TAG,
    975                     "Testing txChangeAudioSource(0,0)    returned = "
    976                             + sFmRadio.txChangeAudioSource(0,0));
    977             return true;
    978 
    979         case KeyEvent.KEYCODE_T:
    980         Log.i("onKeyDown()","KEYCODE_T");
    981             Log.i(TAG,
    982                     "Testing txEnableRds()    returned = "
    983                             + sFmRadio.txEnableRds());
    984             return true;
    985 
    986         case KeyEvent.KEYCODE_U:
    987         Log.i("onKeyDown()","KEYCODE_U");
    988             Log.i(TAG,
    989                     "Testing txDisableRds()    returned = "
    990                             + sFmRadio.txDisableRds());
    991             return true;
    992 
    993         case KeyEvent.KEYCODE_V:
    994         Log.i("onKeyDown()","KEYCODE_V");
    995             Log.i(TAG,
    996                     "Testing txStartTransmission()    returned = "
    997                             + sFmRadio.txStartTransmission());
    998             return true;
    999 
   1000         case KeyEvent.KEYCODE_W:
   1001         Log.i("onKeyDown()","KEYCODE_W");
   1002             Log.i(TAG,
   1003                     "Testing txStopTransmission()    returned = "
   1004                             + sFmRadio.txStopTransmission());
   1005             return true;
   1006 
   1007         case KeyEvent.KEYCODE_X:
   1008         Log.i("onKeyDown()","KEYCODE_X");
   1009             Log.i(TAG,
   1010                     "Testing txSetPowerLevel()    returned = "
   1011                             + sFmRadio.txSetPowerLevel(0));
   1012             return true;
   1013 
   1014         case KeyEvent.KEYCODE_Y:
   1015         Log.i("onKeyDown()","KEYCODE_Y");
   1016             Log.i(TAG,
   1017                     "Testing txTune()    returned = "
   1018                             + sFmRadio.txTune(104000));
   1019             return true;
   1020 
   1021          }
   1022         return false;
   1023     }
   1024 
   1025 
   1026 
   1027 private void setMuteMode()
   1028 {
   1029 
   1030     Log.i(TAG,"setMuteMode()");
   1031     // Mute
   1032     if(chbMute.isChecked()== true){
   1033     mStatus = sFmRadio.txSetMuteMode(0);
   1034     }else{
   1035     mStatus = sFmRadio.txSetMuteMode(1);
   1036     }
   1037 
   1038     if (mStatus == false) {
   1039     Log.i(TAG, "Fm Tx--> Cannot Mute TX !!");
   1040     }else{
   1041     Log.i(TAG, "Fm Tx--> Muting TX !!");
   1042     }
   1043 
   1044 }
   1045 
   1046 
   1047 /*************************************************************************
   1048 *
   1049 * This is a method implementation of onClick
   1050 *
   1051 *************************************************************************/
   1052     public void onClick(View view) {
   1053         Log.i(TAG, "onClick()");
   1054         int id = view.getId();
   1055         switch (id) {
   1056         case R.id.btnOk:
   1057             setMuteMode();
   1058             writeFrequency();
   1059             fmTxPreferences = getSharedPreferences("fmTxPreferences", MODE_PRIVATE);
   1060 
   1061             if (startTxBtn.isChecked() && freqValue != 0 ){
   1062                           Log.i(TAG, " FM-------> mFreq:" + mFreq);
   1063                           Log.i(TAG, " FM-------> freqValue" + freqValue);
   1064                 if(((mFreq-freqValue) < -.00001) ||((mFreq-freqValue) > .00001)) {
   1065                      /* Tune TX */
   1066                      mFreq = freqValue;
   1067                                 Log.i(TAG, " FM-------> mFreq:" + mFreq);
   1068                     mStatus =  sFmRadio.txTune((long)(freqValue.floatValue()*1000));
   1069                     Log.i(TAG, "Fm Tx--> Tune TX freqValue !!" +(long)(freqValue.floatValue()*1000));
   1070                     if (mStatus == false) {
   1071                     Log.i(TAG, "Fm Tx--> Tune TX failed !!");
   1072                     }
   1073                     else{
   1074                     Log.i(TAG, "Fm Tx--> TX Tune is SUCCESSFUll !!");
   1075                     }
   1076                 } else {
   1077                      /* Already Tuned */
   1078                   mStatus = sFmRadio.txStartTransmission();
   1079                   if (mStatus == false) {
   1080                     Log.i(TAG, "Fm Tx--> Stop Tx failed !!");
   1081                   }else {
   1082                     Log.i(TAG, "Fm Tx--> Stop Transmission is SUCCESSFUll !!");
   1083                   }
   1084             }
   1085             }else{
   1086                 mStatus = sFmRadio.txStopTransmission();
   1087                 if (mStatus == false) {
   1088                 Log.i(TAG, "Fm Tx--> Stop Tx failed !!");
   1089                 }
   1090                 else{
   1091                 Log.i(TAG, "Fm Tx--> Stop Transmission is SUCCESSFUll !!");
   1092                 }
   1093 
   1094             }
   1095 
   1096             if(enableRdsBtn.isChecked()){
   1097             sFmRadio.txEnableRds();
   1098             }else{
   1099             sFmRadio.txDisableRds();
   1100             }
   1101 
   1102 
   1103 
   1104             break;
   1105 
   1106         default:
   1107             break;
   1108         }
   1109     }
   1110 
   1111 
   1112 
   1113 /*************************************************************************
   1114 *
   1115 *
   1116 *
   1117 *************************************************************************/
   1118     private Handler mHandler = new Handler() {
   1119 
   1120         public void handleMessage(Message msg) {
   1121 
   1122             switch (msg.what) {
   1123 
   1124 
   1125             case EVENT_FM_TX_ENABLED:
   1126                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_ENABLED");
   1127                 isFmEnabled = true;
   1128                 mAppState = STATE_ENABLED;
   1129                 if (pd != null){
   1130                 pd.dismiss();
   1131                 }
   1132                 pd =null;
   1133                 break;
   1134 
   1135             case EVENT_FM_TX_DISABLED:
   1136                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_DISABLED");
   1137                 isFmEnabled = false;
   1138                  mAppState = STATE_DISABLED;
   1139                           startTxBtn.setChecked(false);
   1140                 finish(); //Close the Activity
   1141                 break;
   1142 
   1143 
   1144             case EVENT_FM_TX_STARTTRANSMISSION:
   1145                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_STARTTRANSMISSION");
   1146                 break;
   1147 
   1148             case EVENT_FM_TX_STOPTRANSMISSION:
   1149                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_STOPTRANSMISSION");
   1150                 break;
   1151 
   1152             case EVENT_FM_TX_TUNE:
   1153                 mStatus = sFmRadio.txStartTransmission();
   1154                 if (mStatus == false) {
   1155                 Log.i(TAG, "Fm Tx--> TX txStartTransmission failed !!");
   1156                 }
   1157                 else{
   1158                 Log.i(TAG, "Fm Tx--> TX is Transmitting..");
   1159                 }
   1160                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_TUNE");
   1161                 break;
   1162 
   1163 
   1164             case EVENT_FM_TX_ENABLE_RDS:
   1165                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_ENABLE_RDS");
   1166                 break;
   1167 
   1168 
   1169             case EVENT_FM_TX_DISABLE_RDS:
   1170                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_DISABLE_RDS");
   1171                 break;
   1172 
   1173             case EVENT_FM_TX_SET_TRANSMISSION_MODE:
   1174                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_TRANSMISSION_MODE");
   1175                 break;
   1176 
   1177             case EVENT_FM_TX_SET_PS_DISPLAY_MODE:
   1178                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_PS_DISPLAY_MODE");
   1179                 break;
   1180 
   1181             case EVENT_FM_TX_SET_RDS_MUSIC_SPEECH_FLAG:
   1182                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_RDS_MUSIC_SPEECH_FLAG");
   1183                 break;
   1184 
   1185             case EVENT_FM_TX_SET_MONO_STEREO_MODE:
   1186                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_MONO_STEREO_MODE");
   1187                 break;
   1188 
   1189             case EVENT_FM_TX_SET_POWER_LEVEL:
   1190                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_POWER_LEVEL");
   1191                 break;
   1192 
   1193             case EVENT_FM_TX_SET_MUTE_MODE:
   1194                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_MUTE_MODE");
   1195                 break;
   1196 
   1197             case EVENT_FM_TX_SET_RDS_TEXT_PS_MSG:
   1198                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_RDS_TEXT_PS_MSG");
   1199                 break;
   1200 
   1201             case EVENT_FM_TX_SET_RDS_TX_GRP_MASK_PS:
   1202                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_RDS_TX_GRP_MASK_PS");
   1203 
   1204                 SharedPreferences fmConfigPreferences = getSharedPreferences(
   1205                 "fmConfigPreferences", MODE_PRIVATE);
   1206 
   1207                 String psStr = fmConfigPreferences.getString(PS_STRING,DEF_PS_STRING);
   1208                 Log.i(TAG, "txSetRdsTextPsMsg()--- psStr= " + psStr.toString());
   1209                 mStatus = sFmRadio.txSetRdsTextPsMsg(psStr);
   1210                 if (mStatus == false) {
   1211                 Log.i(TAG, "Fm Tx--> txSetRdsTextPsMsg TX failed !!");
   1212                 }else{
   1213                 Log.i(TAG, "Fm Tx--> TX txSetRdsTextPsMsg is SUCCESSFUll !!");
   1214                 }
   1215                 break;
   1216 
   1217             case EVENT_FM_TX_SET_RDS_TX_GRP_MASK_RT:
   1218                 Log.i(TAG, "enter handleMessage ----EVENT_FM_TX_SET_RDS_TX_GRP_MASK_RT");
   1219 
   1220                 SharedPreferences fmTxParamConfigPreferences = getSharedPreferences(
   1221                 "fmTxParamConfigPreferences", MODE_PRIVATE);
   1222 
   1223                 String rtStr = fmTxParamConfigPreferences.getString(RT_STRING,DEF_RT_STRING);
   1224                 Log.i(TAG, "txSetRdsTextRtMsg()--- rtStr= " + rtStr.toString());
   1225                 mStatus = sFmRadio.txSetRdsTextRtMsg(RDS_TEXT_TYPE_RT_B,rtStr,rtStr.length()); //msgType =4
   1226                 if (mStatus == false) {
   1227                 Log.i(TAG, "Fm Tx--> txSetRdsTextRtMsg TX failed !!");
   1228                 }else{
   1229                 Log.i(TAG, "Fm Tx--> TX txSetRdsTextRtMsg is SUCCESSFUll !!");
   1230                 }
   1231                 break;
   1232 
   1233 
   1234  }}};
   1235 
   1236 
   1237 /*************************************************************************
   1238 *
   1239 *
   1240 *
   1241 *************************************************************************/
   1242      private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
   1243         public void onReceive(Context context, Intent intent) {
   1244             String fmAction = intent.getAction();
   1245             Log.i(TAG, "enter onReceive" + fmAction);
   1246             if (fmAction.equals(FmRadioIntent.FM_TX_ENABLED_ACTION)) {
   1247                 Log.i(TAG, "enter onReceive FM_TX_ENABLED_ACTION " + fmAction);
   1248                 mHandler.sendMessage(mHandler
   1249                         .obtainMessage(EVENT_FM_TX_ENABLED, 0));
   1250             }
   1251 
   1252             if (fmAction.equals(FmRadioIntent.FM_TX_DISABLED_ACTION)) {
   1253                 Log.i(TAG, "enter onReceive FM_TX_DISABLED_ACTION " + fmAction);
   1254                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_DISABLED,
   1255                         0));
   1256             }
   1257 
   1258             if (fmAction.equals(FmRadioIntent.FM_TX_TUNE_ACTION)) {
   1259                 Log.i(TAG, "enter onReceive FM_TX_TUNE_ACTION " + fmAction);
   1260                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_TUNE,
   1261                         0));
   1262             }
   1263 
   1264             if (fmAction.equals(FmRadioIntent.FM_TX_START_TRANSMISSION_ACTION)) {
   1265                 Log.i(TAG, "enter onReceive FM_TX_START_TRANSMISSION_ACTION " + fmAction);
   1266                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_STARTTRANSMISSION,
   1267                         0));
   1268             }
   1269 
   1270             if (fmAction.equals(FmRadioIntent.FM_TX_STOP_TRANSMISSION_ACTION)) {
   1271                 Log.i(TAG, "enter onReceive FM_TX_STOP_TRANSMISSION_ACTION " + fmAction);
   1272                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_STOPTRANSMISSION,
   1273                         0));
   1274             }
   1275 
   1276             if (fmAction.equals(FmRadioIntent.FM_TX_DESTROY_ACTION)) {
   1277                 Log.i(TAG, "enter onReceive FM_TX_DESTROY_ACTION " + fmAction);
   1278                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_DESTROY,
   1279                         0));
   1280             }
   1281 
   1282             if (fmAction.equals(FmRadioIntent.FM_TX_ENABLE_RSD_ACTION)) {
   1283                 Log.i(TAG, "enter onReceive FM_TX_ENABLE_RSD_ACTION " + fmAction);
   1284                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_ENABLE_RDS,
   1285                         0));
   1286             }
   1287 
   1288             if (fmAction.equals(FmRadioIntent.FM_TX_DISABLE_RSD_ACTION)) {
   1289                 Log.i(TAG, "enter onReceive FM_TX_DISABLE_RSD_ACTION " + fmAction);
   1290                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_DISABLE_RDS,
   1291                         0));
   1292             }
   1293 
   1294 
   1295             if (fmAction.equals(FmRadioIntent.FM_TX_SET_TRANSMISSION_MODE_ACTION)) {
   1296                 Log.i(TAG, "enter onReceive FM_TX_SET_TRANSMISSION_MODE_ACTION " + fmAction);
   1297                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_TRANSMISSION_MODE,
   1298                         0));
   1299             }
   1300 
   1301             if (fmAction.equals(FmRadioIntent.FM_TX_PS_DISPLAY_MODE_ACTION)) {
   1302                 Log.i(TAG, "enter onReceive FM_TX_PS_DISPLAY_MODE_ACTION " + fmAction);
   1303                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_PS_DISPLAY_MODE,
   1304                         0));
   1305             }
   1306 
   1307             if (fmAction.equals(FmRadioIntent.FM_TX_SET_RDS_MUSIC_SPEECH_FLAG_ACTION)) {
   1308                 Log.i(TAG, "enter onReceive FM_TX_SET_RDS_MUSIC_SPEECH_FLAG_ACTION " + fmAction);
   1309                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_RDS_MUSIC_SPEECH_FLAG,
   1310                         0));
   1311             }
   1312 
   1313             if (fmAction.equals(FmRadioIntent.FM_TX_SET_RDS_TEXT_REPERTOIRE_ACTION)) {
   1314                 Log.i(TAG, "enter onReceive FM_TX_SET_RDS_TEXT_REPERTOIRE_ACTION " + fmAction);
   1315                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_RDS_TEXT_REPERTOIRE,
   1316                         0));
   1317             }
   1318 
   1319             if (fmAction.equals(FmRadioIntent.FM_TX_SET_TRANSMISSION_MODE_ACTION)) {
   1320                 Log.i(TAG, "enter onReceive FM_TX_SET_TRANSMISSION_MODE_ACTION " + fmAction);
   1321                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_TRANSMISSION_MODE,
   1322                         0));
   1323             }
   1324 
   1325             if (fmAction.equals(FmRadioIntent.FM_TX_SET_POWER_LEVEL_ACTION)) {
   1326                 Log.i(TAG, "enter onReceive FM_TX_SET_POWER_LEVEL_ACTION " + fmAction);
   1327                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_POWER_LEVEL,
   1328                         0));
   1329             }
   1330 
   1331             if (fmAction.equals(FmRadioIntent.FM_TX_SET_RDS_TEXT_PS_MSG_ACTION)) {
   1332                 Log.i(TAG, "enter onReceive FM_TX_SET_RDS_TEXT_PS_MSG_ACTION " + fmAction);
   1333                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_RDS_TEXT_PS_MSG,
   1334                         0));
   1335             }
   1336 
   1337             if (fmAction.equals(FmRadioIntent.FM_TX_SET_MONO_STEREO_MODE_ACTION)) {
   1338                 Log.i(TAG, "enter onReceive FM_TX_SET_MONO_STEREO_MODE_ACTION " + fmAction);
   1339                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_MONO_STEREO_MODE,
   1340                         0));
   1341             }
   1342 
   1343 
   1344             if (fmAction.equals(FmRadioIntent.FM_TX_SET_MUTE_MODE_ACTION)) {
   1345                 Log.i(TAG, "enter onReceive FM_TX_SET_MUTE_MODE_ACTION " + fmAction);
   1346                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_MUTE_MODE,
   1347                         0));
   1348             }
   1349 
   1350             if (fmAction.equals(FmRadioIntent.FM_TX_SET_RDS_TRANSMISSION_GROUPMASK_ACTION)) {
   1351                 Log.i(TAG, "enter onReceive FM_TX_SET_RDS_TRANSMISSION_GROUPMASK_ACTION " + fmAction);
   1352 
   1353                 Long grpMask = intent.getLongExtra(
   1354                         FmRadioIntent.RDS_GRP_MASK, 0);
   1355             /*
   1356                 if(grpMask == RDS_RADIO_TRANSMITTED_GRP_PS_MASK){
   1357                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_RDS_TX_GRP_MASK_PS,
   1358                         0));
   1359                 }else if(grpMask == RDS_RADIO_TRANSMITTED_GRP_RT_MASK){
   1360                 mHandler.sendMessage(mHandler.obtainMessage(EVENT_FM_TX_SET_RDS_TX_GRP_MASK_RT,
   1361                         0));
   1362                 }
   1363             */
   1364 
   1365             }
   1366 
   1367 
   1368 
   1369         }
   1370     };
   1371 
   1372 
   1373 
   1374 
   1375     /* Save the values to the preference when the application exits */
   1376     private void saveLastData() {
   1377         Log.i(TAG, "saveLastData()---Entered");
   1378         fmTxPreferences = getSharedPreferences("fmTxPreferences", MODE_PRIVATE);
   1379         SharedPreferences.Editor editor = fmTxPreferences.edit();
   1380 
   1381         editor.putBoolean(FMENABLED, startTxBtn.isChecked());
   1382         editor.putBoolean(RDSENABLED, enableRdsBtn.isChecked());
   1383         editor.putBoolean(MUTE, chbMute.isChecked());
   1384 
   1385         editor.putString(FREQUENCY_STRING, textFreq.getText().toString());
   1386         editor.putString(FREQUENCY, DEFAULT_FREQ);
   1387 
   1388         Log.d(TAG, " save FMENABLED " +isFmEnabled + "FREQUENCY_STRING"+freqValue);
   1389         editor.commit();
   1390         Log.i(TAG, "saveLastData()---Exit");
   1391     }
   1392 
   1393     /* Load the last saved values from the preference when the application starts */
   1394     private void loadlastSaveddata() {
   1395 
   1396         Log.i(TAG, "loadlastSaveddata()-entered");
   1397         fmTxPreferences = getSharedPreferences("fmTxPreferences", MODE_PRIVATE);
   1398 
   1399         isFmEnabled = fmTxPreferences.getBoolean(FMENABLED,false);
   1400         if(isFmEnabled == true)
   1401         {
   1402             startTxBtn.setChecked(true);
   1403             startTxBtn.setEnabled(true);
   1404 
   1405         }else{
   1406             startTxBtn.setChecked(false);
   1407             startTxBtn.setEnabled(true);
   1408         }
   1409 
   1410         enableRdsBtn.setChecked(fmTxPreferences.getBoolean(RDSENABLED,false));
   1411         enableRdsBtn.setEnabled(true);
   1412 
   1413         chbMute.setChecked(fmTxPreferences.getBoolean(MUTE,false));
   1414         chbMute.setEnabled(true);
   1415 
   1416         textFreq.setText(fmTxPreferences.getString(FREQUENCY_STRING,null));
   1417 
   1418         Log.d(TAG, " Load FMENABLED " +isFmEnabled + "FREQUENCY_STRING"+freqValue);
   1419 
   1420         Log.i(TAG, "loadlastSaveddata()-exit");
   1421     }
   1422 
   1423 
   1424 
   1425 
   1426      public void onStart() {
   1427         Log.i(TAG, "onStart");
   1428         super.onStart();
   1429     }
   1430 
   1431 
   1432     public void onResume() {
   1433         Log.i(TAG, "onResume");
   1434         super.onResume();
   1435         if(mFmServiceConnected == true)
   1436         enableTx();
   1437 
   1438 
   1439     }
   1440 
   1441      public void onDestroy() {
   1442         Log.i(TAG, "onDestroy");
   1443         super.onDestroy();
   1444         /*
   1445          * Unregistering the receiver , so that we dont handle any FM events
   1446          * when out of the FM application screen
   1447          */
   1448 
   1449         unregisterReceiver(mReceiver);
   1450     }
   1451 
   1452     public int getFmTxAppState() {
   1453         Log.d(TAG, "getFmTxAppState()");
   1454         return mAppState;
   1455 
   1456     }
   1457 
   1458 
   1459 }
   1460