private void restoreSettingsDefault() { if (mPrefs != null) { mBandPreference.setValueIndex(0); if (mRxMode) { mAudioPreference.setValueIndex(0); if (FMRadio.RECORDING_ENABLE) { mRecordDurPreference.setValueIndex(0); } mAfPref.setChecked(false); FmSharedPreferences.SetDefaults(); } else { FmSharedPreferences.setCountry(FmSharedPreferences.REGIONAL_BAND_NORTH_AMERICA); } mPrefs.Save(); } }
private PreferenceScreen createPreferenceHierarchy() { int index = 0; if (mPrefs == null) { return null; } // Root PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); // Band/Country String[] summaryBandItems = getResources().getStringArray(R.array.regional_band_summary); mBandPreference = new ListPreference(this); mBandPreference.setEntries(R.array.regional_band_entries); mBandPreference.setEntryValues(R.array.regional_band_values); mBandPreference.setDialogTitle(R.string.sel_band_menu); mBandPreference.setKey(REGIONAL_BAND_KEY); mBandPreference.setTitle(R.string.regional_band); index = FmSharedPreferences.getCountry(); Log.d(LOGTAG, "createPreferenceHierarchy: Country: " + index); // Get the preference and list the value. if ((index < 0) || (index >= summaryBandItems.length)) { index = 0; } Log.d(LOGTAG, "createPreferenceHierarchy: CountrySummary: " + summaryBandItems[index]); mBandPreference.setSummary(summaryBandItems[index]); mBandPreference.setValueIndex(index); root.addPreference(mBandPreference); if (mRxMode) { // Audio Output (Stereo or Mono) String[] summaryAudioModeItems = getResources().getStringArray(R.array.ster_mon_entries); mAudioPreference = new ListPreference(this); mAudioPreference.setEntries(R.array.ster_mon_entries); mAudioPreference.setEntryValues(R.array.ster_mon_values); mAudioPreference.setDialogTitle(R.string.sel_audio_output); mAudioPreference.setKey(AUDIO_OUTPUT_KEY); mAudioPreference.setTitle(R.string.aud_output_mode); boolean audiomode = FmSharedPreferences.getAudioOutputMode(); if (audiomode) { index = 0; } else { index = 1; } Log.d(LOGTAG, "createPreferenceHierarchy: audiomode: " + audiomode); mAudioPreference.setSummary(summaryAudioModeItems[index]); mAudioPreference.setValueIndex(index); root.addPreference(mAudioPreference); // AF Auto Enable (Checkbox) mAfPref = new CheckBoxPreference(this); mAfPref.setKey(AUTO_AF); mAfPref.setTitle(R.string.auto_select_af); mAfPref.setSummaryOn(R.string.auto_select_af_enabled); mAfPref.setSummaryOff(R.string.auto_select_af_disabled); boolean bAFAutoSwitch = FmSharedPreferences.getAutoAFSwitch(); Log.d(LOGTAG, "createPreferenceHierarchy: bAFAutoSwitch: " + bAFAutoSwitch); mAfPref.setChecked(bAFAutoSwitch); root.addPreference(mAfPref); if (FMRadio.RECORDING_ENABLE) { String[] summaryRecordItems = getResources().getStringArray(R.array.record_durations_entries); mRecordDurPreference = new ListPreference(this); mRecordDurPreference.setEntries(R.array.record_durations_entries); mRecordDurPreference.setEntryValues(R.array.record_duration_values); mRecordDurPreference.setDialogTitle(R.string.sel_rec_dur); mRecordDurPreference.setKey(RECORD_DURATION_KEY); mRecordDurPreference.setTitle(R.string.record_dur); index = FmSharedPreferences.getRecordDuration(); Log.d(LOGTAG, "createPreferenceHierarchy: recordDuration: " + index); // Get the preference and list the value. if ((index < 0) || (index >= summaryRecordItems.length)) { index = 0; } Log.d( LOGTAG, "createPreferenceHierarchy: recordDurationSummary: " + summaryRecordItems[index]); mRecordDurPreference.setSummary(summaryRecordItems[index]); mRecordDurPreference.setValueIndex(index); root.addPreference(mRecordDurPreference); } } mBluetoothBehaviour = new ListPreference(this); mBluetoothBehaviour.setEntries(R.array.bt_exit_behaviour_entries); mBluetoothBehaviour.setEntryValues(R.array.bt_exit_behaviour_values); mBluetoothBehaviour.setDialogTitle(R.string.pref_bt_behaviour_on_exit_dialog_title); mBluetoothBehaviour.setKey(BT_EXIT_BEHAVIOUR); mBluetoothBehaviour.setTitle(R.string.pref_bt_behaviour_on_exit_title); mBluetoothBehaviour.setSummary(R.string.pref_bt_behaviour_on_exit_summary); root.addPreference(mBluetoothBehaviour); mRemoveHeadset = new CheckBoxPreference(this); mRemoveHeadset.setKey(HEADSET_DC_BEHAVIOUR); mRemoveHeadset.setTitle(R.string.pref_headset_behaviour_title); mRemoveHeadset.setSummary(R.string.pref_headset_behaviour_summary); mRemoveHeadset.setChecked(FmSharedPreferences.getHeadsetDcBehaviour()); root.addPreference(mRemoveHeadset); mRestoreDefaultPreference = new Preference(this); mRestoreDefaultPreference.setTitle(R.string.settings_revert_defaults_title); mRestoreDefaultPreference.setKey(RESTORE_FACTORY_DEFAULT); mRestoreDefaultPreference.setSummary(R.string.settings_revert_defaults_summary); mRestoreDefaultPreference.setOnPreferenceClickListener(this); root.addPreference(mRestoreDefaultPreference); // Add a new category PreferenceCategory prefCat = new PreferenceCategory(this); prefCat.setTitle(R.string.about_title); root.addPreference(prefCat); mAboutPreference = new Preference(this); mAboutPreference.setTitle(R.string.about_title); mAboutPreference.setKey(ABOUT_KEY); mAboutPreference.setSummary(R.string.about_summary); mAboutPreference.setOnPreferenceClickListener(this); root.addPreference(mAboutPreference); return root; }
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(REGIONAL_BAND_KEY)) { String[] summaryBandItems = getResources().getStringArray(R.array.regional_band_summary); String valueStr = sharedPreferences.getString(key, ""); int index = 0; if (valueStr != null) { index = mBandPreference.findIndexOfValue(valueStr); } if ((index < 0) || (index >= summaryBandItems.length)) { index = 0; mBandPreference.setValueIndex(0); } Log.d(LOGTAG, "onSharedPreferenceChanged: Country Change: " + index); mBandPreference.setSummary(summaryBandItems[index]); FmSharedPreferences.setCountry(index); FMRadio.fmConfigure(); } else { if (mRxMode) { if (key.equals(AUTO_AF)) { boolean bAFAutoSwitch = mAfPref.isChecked(); Log.d(LOGTAG, "onSharedPreferenceChanged: Auto AF Enable: " + bAFAutoSwitch); FmSharedPreferences.setAutoAFSwitch(bAFAutoSwitch); FMRadio.fmAutoAFSwitch(); } else if (key.equals(RECORD_DURATION_KEY)) { if (FMRadio.RECORDING_ENABLE) { String[] recordItems = getResources().getStringArray(R.array.record_durations_entries); String valueStr = mRecordDurPreference.getValue(); int index = 0; if (valueStr != null) { index = mRecordDurPreference.findIndexOfValue(valueStr); } if ((index < 0) || (index >= recordItems.length)) { index = 0; mRecordDurPreference.setValueIndex(index); } Log.d(LOGTAG, "onSharedPreferenceChanged: recorddur: " + recordItems[index]); mRecordDurPreference.setSummary(recordItems[index]); FmSharedPreferences.setRecordDuration(index); } } else if (key.equals(AUDIO_OUTPUT_KEY)) { String[] bandItems = getResources().getStringArray(R.array.ster_mon_entries); String valueStr = mAudioPreference.getValue(); int index = 0; if (valueStr != null) { index = mAudioPreference.findIndexOfValue(valueStr); } if (index != 1) { if (index != 0) { index = 0; /* It shud be 0(Stereo) or 1(Mono) */ mAudioPreference.setValueIndex(index); } } Log.d(LOGTAG, "onSharedPreferenceChanged: audiomode: " + bandItems[index]); mAudioPreference.setSummary(bandItems[index]); if (index == 0) { // Stereo FmSharedPreferences.setAudioOutputMode(true); } else { // Mono FmSharedPreferences.setAudioOutputMode(false); } FMRadio.fmAudioOutputMode(); } else if (key.equals(BT_EXIT_BEHAVIOUR)) { String[] btChoices = getResources().getStringArray(R.array.bt_exit_behaviour_entries); String valueStr = mBluetoothBehaviour.getValue(); Log.d( LOGTAG, "onSharedPreferenceChanged: BT behaviour: " + btChoices[mBluetoothBehaviour.findIndexOfValue(valueStr)]); FmSharedPreferences.setBluetoothExitBehaviour(Integer.parseInt(valueStr)); } else if (key.equals(HEADSET_DC_BEHAVIOUR)) { boolean bRemoveHeadset = mRemoveHeadset.isChecked(); Log.d(LOGTAG, "onSharedPreferenceChanged: Remove Headset Enable: " + bRemoveHeadset); FmSharedPreferences.setHeadsetDcBehaviour(bRemoveHeadset); } } } if (mPrefs != null) { mPrefs.Save(); } }