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 java.util.ArrayList;
     21 
     22 import android.app.Activity;
     23 import android.app.AlertDialog;
     24 import android.content.SharedPreferences;
     25 import android.os.Bundle;
     26 import android.util.Log;
     27 import android.view.Gravity;
     28 import android.view.KeyEvent;
     29 import android.view.View;
     30 import android.widget.AdapterView;
     31 import android.widget.ArrayAdapter;
     32 import android.widget.Button;
     33 import android.widget.CheckBox;
     34 import android.widget.EditText;
     35 import android.widget.RadioButton;
     36 import android.widget.Spinner;
     37 import android.widget.Toast;
     38 import android.widget.AdapterView.OnItemSelectedListener;
     39 import android.content.Intent;
     40 import android.content.IntentFilter;
     41 import android.content.Context;
     42 import android.widget.CompoundButton;
     43 
     44 public class FmTxConfig extends Activity implements  View.OnKeyListener,
     45 View.OnClickListener,CompoundButton.OnCheckedChangeListener,FmTxAppConstants
     46 {
     47 
     48     public static final String TAG = "FmRxRdsConfig";
     49 
     50     /********************************************
     51     * Widgets
     52     ********************************************/
     53     private Button btnCancel,btnOk;
     54     private Spinner spnMonoStereo/*spnEcc,spnRepetoire,spnTxMode,spnDisplayMode*/;
     55     private EditText txtPsStr,textPower,edtPiCode,edtAfCode;
     56     private EditText edtRadioText,edtPty;
     57     private CheckBox rbtnPs,rbtnRt;
     58 /*    private CheckBox chbRdsMode;
     59     private CheckBox chbSetRdsAf;*/
     60     //private RadioButton rbtnTp,rbtnTa;
     61     private ArrayAdapter<String> monoStereoAdapter;
     62 //        private ArrayAdapter<String> eccAdapter;
     63         /*private ArrayAdapter<String> repertoireAdapter;
     64     private ArrayAdapter<String> txModeAdapter;
     65         private ArrayAdapter<String> emptyAdapter;
     66 
     67         private ArrayAdapter<String> displayAdapter;        */
     68     private ArrayList<String> monoStereoStrings = new ArrayList<String>();
     69     private ArrayList<String> eccStrings = new ArrayList<String>();
     70     /*private ArrayList<String> repertoireStrings = new ArrayList<String>();
     71     private ArrayList<String> emptyStrings = new ArrayList<String>();
     72     private ArrayList<String> txModeStrings = new ArrayList<String>();
     73     private ArrayList<String> displayStrings = new ArrayList<String>();    */
     74 
     75 
     76     /********************************************
     77     * private variables
     78     ********************************************/
     79     private Context mContext;
     80 
     81     /********************************************
     82     * public variables
     83     ********************************************/
     84     public SharedPreferences fmConfigPreferences;
     85 
     86         /** Called when the activity is first created. */
     87         @Override
     88         public void onCreate(Bundle savedInstanceState) {
     89           super.onCreate(savedInstanceState);
     90           setContentView(R.layout.fmtxrdsconfig);
     91           initControl();
     92           setSpinners();
     93 
     94 
     95         }
     96 
     97     /** Initialise the Widget controls of the Activity*/
     98     private void initControl()
     99         {
    100       btnCancel = (Button) findViewById(R.id.btnCancel);
    101        btnCancel.setOnKeyListener(this);
    102        btnCancel.setOnClickListener(this);
    103 
    104        btnOk = (Button) findViewById(R.id.btnOk);
    105        btnOk.setOnKeyListener(this);
    106        btnOk.setOnClickListener(this);
    107 
    108     /*    spnDisplayMode = (Spinner)findViewById(R.id.spnDisplayMode);
    109        spnTxMode = (Spinner)findViewById(R.id.spnTxMode);
    110        spnRepetoire = (Spinner)findViewById(R.id.spnRepetoire);*/
    111        spnMonoStereo= (Spinner)findViewById(R.id.spnMonoStereo);
    112       // spnEcc= (Spinner)findViewById(R.id.spnEcc);
    113 
    114        txtPsStr = (EditText)findViewById(R.id.EdtPSString);
    115     textPower = (EditText)findViewById(R.id.powLevel);
    116 
    117     edtPiCode = (EditText)findViewById(R.id.piCode);
    118     edtAfCode = (EditText)findViewById(R.id.afCode);
    119     //rbtnTp=(RadioButton)findViewById(R.id.rbtnTp);
    120     //rbtnTp.setOnCheckedChangeListener(this);
    121 
    122     //rbtnTa=(RadioButton)findViewById(R.id.rbtnTa);
    123     //rbtnTa.setOnCheckedChangeListener(this);
    124 
    125 
    126     //Edit Box
    127     edtRadioText = (EditText)findViewById(R.id.EdtRadioText);
    128     edtPty = (EditText)findViewById(R.id.EdtPty);
    129 
    130     rbtnPs = (CheckBox)findViewById(R.id.rbtnPs);
    131     rbtnRt = (CheckBox)findViewById(R.id.rbtnRt);
    132 
    133     rbtnPs.setOnCheckedChangeListener(this);
    134     rbtnRt.setOnCheckedChangeListener(this);
    135 
    136   }
    137 
    138 
    139     /** sets the Band , De-Emp Filter and Mode option  selections Spinner for the User*/
    140      private void setSpinners()
    141      {
    142          // Tx Mode Spinner
    143       /*    txModeAdapter = new ArrayAdapter<String>(this,
    144                        android.R.layout.simple_spinner_item, txModeStrings);
    145 
    146          txModeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    147          spnTxMode.setAdapter(txModeAdapter);
    148          txModeAdapter.add("Manual");
    149          txModeAdapter.add("Automatic");
    150          spnTxMode.setOnItemSelectedListener(gItemSelectedHandler);*/
    151 
    152 
    153          // Mono/Stereo Spinner
    154          monoStereoAdapter = new ArrayAdapter<String>(this,
    155                        android.R.layout.simple_spinner_item, monoStereoStrings);
    156 
    157          monoStereoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    158          spnMonoStereo.setAdapter(monoStereoAdapter);
    159          //monoStereoAdapter.add("Mono");
    160          monoStereoAdapter.add("Stereo");
    161          spnMonoStereo.setOnItemSelectedListener(gItemSelectedHandler);
    162 
    163 
    164          // Ecc Spinner
    165          //eccAdapter = new ArrayAdapter<String>(this,                   android.R.layout.simple_spinner_item, eccStrings);
    166 
    167          //eccAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    168          //spnEcc.setAdapter(eccAdapter);
    169          //eccAdapter.add("0");
    170          //spnEcc.setOnItemSelectedListener(gItemSelectedHandler);
    171 
    172 
    173          // Repetoire Spinner
    174       /*    repertoireAdapter = new ArrayAdapter<String>(this,
    175                        android.R.layout.simple_spinner_item, repertoireStrings);
    176 
    177          repertoireAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    178          spnRepetoire.setAdapter(repertoireAdapter);
    179          repertoireAdapter.add("G0");
    180          repertoireAdapter.add("G1");
    181          repertoireAdapter.add("G2");
    182          spnRepetoire.setOnItemSelectedListener(gItemSelectedHandler);*/
    183 
    184 
    185 
    186          // Display Mode
    187         /*  displayAdapter = new ArrayAdapter<String>(this,
    188                        android.R.layout.simple_spinner_item, displayStrings);
    189 
    190          displayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    191          spnDisplayMode.setAdapter(displayAdapter);
    192          displayAdapter.add("Static");
    193          displayAdapter.add("Scroll");
    194          spnDisplayMode.setOnItemSelectedListener(gItemSelectedHandler);*/
    195 
    196 
    197     }
    198 
    199 
    200 
    201     public OnItemSelectedListener gItemSelectedHandler = new OnItemSelectedListener()
    202     {
    203 //        @Override
    204         public void onItemSelected(AdapterView<?> arg0, View view, int arg2,long arg3) {
    205             Log.d(TAG,"mono selected"+arg0.getSelectedItemPosition() );
    206 
    207 
    208 
    209             // TODO Auto-generated method stub
    210 
    211         }
    212 
    213 //        @Override
    214         public void onNothingSelected(AdapterView<?> arg0) {
    215             // TODO Auto-generated method stub
    216         }
    217 
    218     };
    219 
    220     /** Pops up the alert Dialog */
    221         public void showAlert(Context context,String title,String msg)
    222     {
    223 
    224        new AlertDialog.Builder(context)
    225        .setTitle(title)
    226        .setIcon(android.R.drawable.ic_dialog_alert)
    227        .setMessage(msg)
    228        .setNegativeButton(android.R.string.ok, null)
    229        .show();
    230 
    231     }
    232 
    233     //@Override
    234     public void onClick(View view)
    235     {
    236          Log.i(TAG,"onClick()");
    237       int id = view.getId();
    238       switch (id)
    239     {
    240 
    241 
    242       case R.id.btnCancel:
    243            finish();
    244               break;
    245       case R.id.btnOk:
    246            savePrefernces();
    247                break;
    248 
    249        default:
    250         break;
    251       }
    252     }
    253 
    254 
    255     /** Send the Intent to Parent Activity */
    256     private void sendAdvanceConfigIntent(){
    257 
    258         Intent rdsIntent = new Intent();
    259         setResult(RESULT_OK, rdsIntent);
    260              finish();
    261 
    262     }
    263 
    264 
    265 
    266     /** Send the Intent to Parent Activity */
    267     private void sendRdsIntent(){
    268 
    269         Intent rdsIntent = new Intent();
    270         setResult(RESULT_OK, rdsIntent);
    271              finish();
    272 
    273     }
    274 
    275 
    276 
    277     public void onCheckedChanged(CompoundButton view, boolean isChecked)
    278     {
    279               Log.i(TAG,"onCheckedChanged()");
    280         int id = view.getId();
    281    switch(id)
    282         {
    283          case R.id.rbtnRt:
    284 
    285              Log.i(TAG,"onCheckedChanged() rbtnRt isChecked " +isChecked);
    286 
    287              break;
    288          case R.id.rbtnPs:
    289 
    290              Log.i(TAG,"onCheckedChanged() rbtnPs isChecked" +isChecked);
    291              }
    292 
    293     }
    294 
    295     //@Override
    296     public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    297        int action = keyEvent.getAction();
    298 
    299        if (keyCode == KeyEvent.KEYCODE_SOFT_RIGHT) {
    300            Log.v(TAG, "KEYCODE_SOFT_RIGHT " );
    301            finish();
    302           return true;
    303        }
    304 
    305        if (keyCode == KeyEvent.KEYCODE_SOFT_LEFT) {
    306             Log.v(TAG, "KEYCODE_SOFT_LEFT " );
    307             savePrefernces();
    308             //finish();
    309             return true;
    310          }
    311 
    312 
    313        if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER &&
    314           keyCode != KeyEvent.KEYCODE_DPAD_UP &&
    315           keyCode != KeyEvent.KEYCODE_DPAD_DOWN &&
    316           keyCode != KeyEvent.KEYCODE_ENTER) {
    317           return false;
    318        }
    319 
    320        if (action == KeyEvent.ACTION_UP) {
    321           switch (keyCode) {
    322           case KeyEvent.KEYCODE_ENTER:
    323           case KeyEvent.KEYCODE_DPAD_CENTER:
    324 
    325              break;
    326 
    327           case KeyEvent.KEYCODE_DPAD_UP:
    328 
    329              break;
    330 
    331           case KeyEvent.KEYCODE_DPAD_DOWN:
    332 
    333              break;
    334           }
    335        }
    336        return true;
    337     }
    338 
    339     public void onResume(){
    340         super.onResume();
    341         Log.i(TAG,"onResume()-Entered");
    342         updateUiFromPreference();
    343     }
    344 
    345     public void onPause(){
    346         super.onPause();
    347         Log.i(TAG,"onPause()-Entered");
    348 
    349     }
    350 
    351     public void onStop(){
    352         Log.i(TAG,"onStop()-Entered");
    353         super.onStop();
    354     }
    355 
    356     public void onRestart(){
    357         Log.i(TAG,"onRestart()-Entered");
    358         super.onRestart();
    359 
    360     }
    361 
    362 
    363     /** Updates the UI with Default/last saved values */
    364     private void updateUiFromPreference() {
    365         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",
    366                 MODE_PRIVATE);
    367         Log.i(TAG, "updateUiFromPreference()");
    368 
    369         edtRadioText.setText(fmConfigPreferences.getString(RT_STRING,DEF_RT_STRING));
    370         edtPty.setText(fmConfigPreferences.getString(PTY_STRING,DEF_PTY_STRING));
    371         edtPiCode.setText(fmConfigPreferences.getString(PICODE_STRING,DEFAULT_PICODE_STRING));
    372 
    373            rbtnPs.setChecked(fmConfigPreferences.getBoolean(PSENABLED,false));
    374            rbtnRt.setChecked(fmConfigPreferences.getBoolean(RTENABLED,false));
    375 
    376             Log.i(TAG,"updateUiFromPreference() --> PSENABLED = "+fmConfigPreferences.getBoolean(PSENABLED,false));
    377             Log.i(TAG,"updateUiFromPreference() --> RTENABLED = "+fmConfigPreferences.getBoolean(RTENABLED,false));
    378 
    379         textPower.setText(fmConfigPreferences.getString(POWER_STRING,DEF_POWER_STRING));
    380         txtPsStr.setText(fmConfigPreferences.getString(PS_STRING,DEF_PS_STRING));
    381         Log.i(TAG,"updateUiFromPreference() --> PS_STRING = "+txtPsStr.getText().toString());
    382         edtAfCode.setText(fmConfigPreferences.getString(AFCODE_STRING,DEFAULT_AFCODE_STRING));
    383 
    384         /*spnDisplayMode.setSelection(fmConfigPreferences.getInt(DISPLAY_MODE, DEFAULT_DISPLAYMODE));
    385         spnTxMode.setSelection(fmConfigPreferences.getInt(TX_MODE, DEFAULT_TXMODE));
    386         spnRepetoire.setSelection(fmConfigPreferences.getInt(REPERTOIRE, DEFAULT_REPERTOIRE));*/
    387         spnMonoStereo.setSelection(fmConfigPreferences.getInt(MONO_STEREO, DEFAULT_MONOSTEREO));
    388         //spnEcc.setSelection(fmConfigPreferences.getInt(ECC, DEFAULT_ECC));
    389 
    390         /*if(spnTxMode.getSelectedItemPosition() == 0) // If Tx Mode is MANUAL, Disable AF Code & PS Strg
    391         {
    392          edtAfCode.setEnabled(false);
    393          txtPsStr.setEnabled(false);
    394         }else{
    395          edtAfCode.setEnabled(true);
    396          txtPsStr.setEnabled(true);
    397 
    398         }*/
    399 
    400     }
    401 
    402 
    403     /** Saves Configuration  settings  in the Shared Preference */
    404     private void savePrefernces(){
    405         Log.i(TAG,"savePrefernces()");
    406 
    407         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",MODE_PRIVATE);
    408 
    409         SharedPreferences.Editor editor = fmConfigPreferences.edit();
    410 
    411 
    412        /*editor.putInt(DISPLAY_MODE, spnDisplayMode.getSelectedItemPosition());
    413         editor.putInt(TX_MODE, spnTxMode.getSelectedItemPosition());
    414         editor.putInt(REPERTOIRE, spnRepetoire.getSelectedItemPosition());*/
    415         editor.putInt(MONO_STEREO, spnMonoStereo.getSelectedItemPosition());
    416         //editor.putInt(ECC, spnEcc.getSelectedItemPosition());
    417 
    418         editor.putString(PS_STRING, txtPsStr.getText().toString());
    419         editor.putString(RT_STRING, edtRadioText.getText().toString());
    420         editor.putString(PTY_STRING, edtPty.getText().toString());
    421         editor.putString(PICODE_STRING, edtPiCode.getText().toString());
    422         editor.putBoolean(PSENABLED,rbtnPs.isChecked());
    423         editor.putBoolean(RTENABLED,rbtnRt.isChecked());
    424 
    425         editor.commit();
    426         Log.i(TAG,"savePrefernces() --> PS_STRING = "+txtPsStr.getText().toString());
    427         Log.i(TAG,"savePrefernces() --> RT_STRING = "+ edtRadioText.getText().toString());
    428 
    429         savePowerLevel();
    430         savePtyCode();
    431         sendAdvanceConfigIntent();
    432         savePiCode();
    433         saveAfCode();
    434     }
    435 
    436     /** Checks the Power value for validity */
    437     private boolean ptyValid(int value){
    438         Log.d(TAG,"ptyValid %d." +value );
    439         if (value < PTY_MIN || value > PTY_MAX)
    440         {
    441             Log.d(TAG,"TAG,ptyValid %d." +value );
    442 
    443             return false;
    444         }
    445         else
    446         return true;
    447 
    448     }
    449 
    450 /*********************************************************************
    451 
    452     savePtyCode()
    453 
    454 *********************************************************************/
    455     private void savePtyCode()
    456     {
    457         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",MODE_PRIVATE);
    458 
    459         SharedPreferences.Editor editor = fmConfigPreferences.edit();
    460 
    461          try{
    462              int ptyValue = Integer.parseInt(edtPty.getText().toString());
    463           boolean valid = ptyValid(ptyValue);
    464             if(valid || (edtPty.getText().toString()== null))
    465             {
    466                 editor.putString(PTY_STRING, edtPty.getText().toString());
    467                 if(edtPty.getText().toString()== null)
    468                 editor.putInt(PTY, DEFAULT_PTY);
    469             else
    470             {
    471                 editor.putInt(PTY, ptyValue);
    472             }
    473                 editor.commit();
    474             //sendAdvanceConfigIntent();
    475             }
    476             else
    477         {
    478            new AlertDialog.Builder(this)
    479            .setIcon(android.R.drawable.ic_dialog_alert)
    480            .setMessage("Enter valid Pty value in range 0-31!!")
    481            .setNegativeButton(android.R.string.ok, null)
    482            .show();
    483            edtPty.setText(null);
    484         }
    485          }
    486          catch(NumberFormatException nfe)
    487          {
    488              Log.d(TAG,"--> NumberFormatException:" + nfe.getMessage());
    489              new AlertDialog.Builder(this)
    490              .setIcon(android.R.drawable.ic_dialog_alert)
    491              .setMessage("--> Enter valid pty value in range 0-31!!")
    492              .setNegativeButton(android.R.string.ok, null)
    493              .show();
    494              edtPty.setText(null);
    495               }
    496 
    497     }
    498 
    499 
    500 /*********************************************************************
    501 
    502     savePowerLevel()
    503 
    504 *********************************************************************/
    505     private void savePowerLevel()
    506     {
    507         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",MODE_PRIVATE);
    508 
    509         SharedPreferences.Editor editor = fmConfigPreferences.edit();
    510 
    511          try{
    512              int powerValue = Integer.parseInt(textPower.getText().toString());
    513           boolean valid = powerValid(powerValue);
    514             if(valid || (textPower.getText().toString()== null))
    515             {
    516                 editor.putString(POWER_STRING, textPower.getText().toString());
    517                 if(textPower.getText().toString()== null)
    518                 editor.putInt(POWER, DEFAULT_POWER);
    519             else
    520             {
    521                 editor.putInt(POWER, powerValue);
    522             }
    523                 editor.commit();
    524             //sendRdsIntent();
    525             }
    526             else
    527         {
    528            new AlertDialog.Builder(this)
    529            .setIcon(android.R.drawable.ic_dialog_alert)
    530            .setMessage("Enter valid Power value in range 0-31!!")
    531            .setNegativeButton(android.R.string.ok, null)
    532            .show();
    533            textPower.setText(null);
    534         }
    535          }
    536          catch(NumberFormatException nfe)
    537          {
    538              Log.d(TAG,"--> NumberFormatException:" + nfe.getMessage());
    539              new AlertDialog.Builder(this)
    540              .setIcon(android.R.drawable.ic_dialog_alert)
    541              .setMessage("--> Enter valid power value in range 0-31!!")
    542              .setNegativeButton(android.R.string.ok, null)
    543              .show();
    544              textPower.setText(null);
    545               }
    546 
    547     }
    548 
    549 
    550 
    551 /*********************************************************************
    552 
    553     saveAfCode()
    554 
    555 *********************************************************************/
    556     private void saveAfCode()
    557     {
    558 
    559         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",MODE_PRIVATE);
    560 
    561         SharedPreferences.Editor editor = fmConfigPreferences.edit();
    562 
    563         Log.i(TAG,"saveAfCode()");
    564          try{
    565              int afCodeValue = Integer.parseInt(edtAfCode.getText().toString());
    566           boolean valid = afCodeValid(afCodeValue);
    567             if(valid || (edtAfCode.getText().toString()== null))
    568             {
    569                 editor.putString(AFCODE_STRING, edtAfCode.getText().toString());
    570                 if(edtAfCode.getText().toString()== null)
    571                 editor.putInt(AF_CODE, DEFAULT_AFCODE);
    572             else
    573             {
    574                 editor.putInt(AF_CODE, afCodeValue);
    575             }
    576                 editor.commit();
    577             //sendRdsIntent();
    578             }
    579             else
    580         {
    581            new AlertDialog.Builder(this)
    582            .setIcon(android.R.drawable.ic_dialog_alert)
    583            .setMessage("Enter valid AfCode value in range 1 - 204!!")
    584            .setNegativeButton(android.R.string.ok, null)
    585            .show();
    586            edtAfCode.setText(null);
    587         }
    588          }
    589          catch(NumberFormatException nfe)
    590          {
    591              Log.d(TAG,"--> NumberFormatException:" + nfe.getMessage());
    592              new AlertDialog.Builder(this)
    593              .setIcon(android.R.drawable.ic_dialog_alert)
    594              .setMessage("--> Enter valid AfCode value in range 1 - 204 !!")
    595              .setNegativeButton(android.R.string.ok, null)
    596              .show();
    597              edtAfCode.setText(null);
    598               }
    599 
    600     }
    601 
    602 /*********************************************************************
    603 
    604     savePiCode()
    605 
    606 *********************************************************************/
    607     private void savePiCode()
    608     {
    609 
    610         fmConfigPreferences = getSharedPreferences("fmConfigPreferences",MODE_PRIVATE);
    611 
    612         SharedPreferences.Editor editor = fmConfigPreferences.edit();
    613 
    614             Log.i(TAG,"savePiCode()");
    615 
    616          try{
    617              int piCodeValue = Integer.parseInt(edtPiCode.getText().toString());
    618              boolean valid = piCodeValid(piCodeValue);
    619              if(valid || (edtPiCode.getText().toString()== null))
    620              {
    621                 editor.putString(PICODE_STRING, edtPiCode.getText().toString());
    622                 if(edtPiCode.getText().toString()== null)
    623                 editor.putInt(PI_CODE, DEFAULT_PICODE);
    624              else
    625              {
    626                 editor.putInt(PI_CODE, piCodeValue);
    627              }
    628                 editor.commit();
    629                 sendRdsIntent();
    630              }
    631              else
    632         {
    633            new AlertDialog.Builder(this)
    634            .setIcon(android.R.drawable.ic_dialog_alert)
    635            .setMessage("Enter valid Pi Code value in range 0-65535!!")
    636            .setNegativeButton(android.R.string.ok, null)
    637            .show();
    638            edtPiCode.setText(null);
    639         }
    640          }
    641          catch(NumberFormatException nfe)
    642          {
    643              Log.d(TAG,"--> NumberFormatException:" + nfe.getMessage());
    644              new AlertDialog.Builder(this)
    645              .setIcon(android.R.drawable.ic_dialog_alert)
    646              .setMessage("--> Enter valid Pi Code value in range 0-65535!!")
    647              .setNegativeButton(android.R.string.ok, null)
    648              .show();
    649              edtPiCode.setText(null);
    650               }
    651 
    652     }
    653 
    654 
    655     /** Checks the Power value for validity */
    656     private boolean powerValid(int value){
    657         Log.d(TAG,"powerValid %d." +value );
    658         if (value < POWER_MIN || value > POWER_MAX)
    659         {
    660             Log.d(TAG,"TAG,powerValid %d." +value );
    661 
    662             return false;
    663         }
    664         else
    665         return true;
    666 
    667     }
    668 
    669     /** Checks the AF code value for validity */
    670     private boolean afCodeValid(int value){
    671         Log.d(TAG,"afCodeValid %d." +value );
    672         if ((value < AFCODE_MIN || value > AFCODE_MAX))
    673         {
    674             if(value != DEFAULT_AFCODE){
    675             Log.d(TAG,"TAG,afCodeValid %d." +value );
    676             return false;
    677             }else{
    678             return true;
    679             }
    680             //return false;
    681         }
    682         else
    683         return true;
    684 
    685     }
    686 
    687     /** Checks the pi Code value for validity */
    688     private boolean piCodeValid(int value){
    689         Log.d(TAG,"piCodeValid %d." +value );
    690         if (value < PICODE_MIN || value > PICODE_MAX)
    691         {
    692             Log.d(TAG,"TAG,piCodeValid %d." +value );
    693 
    694             return false;
    695         }
    696         else
    697         return true;
    698 
    699     }
    700 }
    701