/** Helper function that formats and displays the current frequency. */ private void displayFreq() { String a = Double.toString((double) mCurrentfrequency / 1000); if (mFmBand.getChannelOffset() == CHANNEL_OFFSET_50KHZ) { mFrequencyTextView.setText(String.format(a, "%.2f")); } else { mFrequencyTextView.setText(String.format(a, "%.1f")); } }
/** * Required method from parent class * * @param icicle - The previous instance of this app */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); mFmTransmitter = (FmTransmitter) getSystemService(Context.RADIO_FM_TRANSMITTER_SERVICE); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); mSelectedBand = settings.getInt("selectedBand", 1); mFmBand = new FmBand(mSelectedBand); mFrequencyIncrement = mFmBand.getChannelOffset(); setupButtons(); setupAnimation(); }
/** React to a selection in the option menu */ @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getGroupId() == BAND_SELECTION_MENU) { switch (item.getItemId()) { case BAND_US: mSelectedBand = FmBand.BAND_US; item.setChecked(true); break; case BAND_EU: mSelectedBand = FmBand.BAND_EU; item.setChecked(true); break; case BAND_JAPAN: mSelectedBand = FmBand.BAND_JAPAN; item.setChecked(true); break; case BAND_CHINA: mSelectedBand = FmBand.BAND_CHINA; item.setChecked(true); break; default: break; } mFmBand = new FmBand(mSelectedBand); try { mFmTransmitter.reset(); ((Button) findViewById(R.id.Transmit)).setBackgroundResource(R.drawable.transmitgobutton); ((TextView) findViewById(R.id.FrequencyTextView)).setText("----"); mFrequencyIncrement = mFmBand.getChannelOffset() / 1000; mTransmitAnimation.stop(); } catch (Exception e) { showToast("Unable to restart the FM Radio", Toast.LENGTH_LONG); } } return super.onOptionsItemSelected(item); }