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