Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of The Linux Foundation nor |
| 12 | * the names of its contributors may be used to endorse or promote |
| 13 | * products derived from this software without specific prior written |
| 14 | * permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | package com.caf.fmradio; |
| 30 | |
| 31 | import android.app.AlertDialog; |
| 32 | import android.app.Dialog; |
| 33 | import android.content.DialogInterface; |
| 34 | import android.content.SharedPreferences; |
| 35 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
| 36 | import android.content.Intent; |
| 37 | import android.os.Bundle; |
| 38 | import android.preference.PreferenceActivity; |
| 39 | import android.preference.PreferenceScreen; |
| 40 | import android.preference.ListPreference; |
| 41 | import android.preference.CheckBoxPreference; |
| 42 | import android.preference.PreferenceCategory; |
| 43 | import android.preference.Preference; |
| 44 | import android.preference.Preference.OnPreferenceClickListener; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 45 | import android.preference.EditTextPreference; |
| 46 | import android.text.InputType; |
| 47 | import android.widget.Toast; |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 48 | import java.util.Locale; |
| 49 | |
| 50 | import android.util.Log; |
| 51 | |
| 52 | public class Settings extends PreferenceActivity implements |
| 53 | OnSharedPreferenceChangeListener, OnPreferenceClickListener { |
| 54 | public static final String RX_MODE = "rx_mode"; |
| 55 | public static final String REGIONAL_BAND_KEY = "regional_band"; |
| 56 | public static final String AUDIO_OUTPUT_KEY = "audio_output_mode"; |
| 57 | public static final String RECORD_DURATION_KEY = "record_duration"; |
| 58 | public static final String AUTO_AF = "af_checkbox_preference"; |
| 59 | public static final String RESTORE_FACTORY_DEFAULT = "revert_to_fac"; |
| 60 | public static final int RESTORE_FACTORY_DEFAULT_INT = 1; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 61 | public static final String USER_DEFINED_BAND_MIN_KEY = "user_defined_band_min"; |
| 62 | public static final String USER_DEFINED_BAND_MAX_KEY = "user_defined_band_max"; |
| 63 | public static final String CHAN_SPACING_KEY = "chanl_spacing"; |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 64 | public static final String RESTORE_FACTORY_DEFAULT_ACTION = "com.caf.fmradio.settings.revert_to_defaults"; |
| 65 | |
| 66 | private static final String LOGTAG = FMRadio.LOGTAG; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 67 | private static final String USR_BAND_MSG = "Enter Freq from range 76.0 - 108.0"; |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 68 | |
| 69 | private ListPreference mBandPreference; |
| 70 | private ListPreference mAudioPreference; |
| 71 | private ListPreference mRecordDurPreference; |
| 72 | private CheckBoxPreference mAfPref; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 73 | private EditTextPreference mUserBandMinPref; |
| 74 | private EditTextPreference mUserBandMaxPref; |
| 75 | private ListPreference mChannelSpacingPref; |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 76 | private Preference mRestoreDefaultPreference; |
| 77 | |
| 78 | private FmSharedPreferences mPrefs = null; |
| 79 | private boolean mRxMode = false; |
| 80 | |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 81 | private int min_freq; |
| 82 | private int max_freq; |
| 83 | private int chan_spacing; |
| 84 | private String[] summaryBandItems; |
| 85 | private String[] chSpacingItems; |
| 86 | private String[] summaryAudioModeItems; |
| 87 | private String[] summaryRecordItems; |
| 88 | |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 89 | @Override |
| 90 | protected void onCreate(Bundle savedInstanceState) { |
| 91 | super.onCreate(savedInstanceState); |
| 92 | Intent intent = getIntent(); |
| 93 | if (intent != null) { |
| 94 | mRxMode = intent.getBooleanExtra(RX_MODE, false); |
| 95 | } |
| 96 | mPrefs = new FmSharedPreferences(this); |
| 97 | if (mPrefs != null) { |
| 98 | setPreferenceScreen(createPreferenceHierarchy()); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | private PreferenceScreen createPreferenceHierarchy() { |
| 103 | int index = 0; |
| 104 | if (mPrefs == null) { |
| 105 | return null; |
| 106 | } |
| 107 | // Root |
| 108 | PreferenceScreen root = getPreferenceManager().createPreferenceScreen( |
| 109 | this); |
| 110 | |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 111 | summaryBandItems = getResources().getStringArray( |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 112 | R.array.regional_band_summary); |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 113 | chSpacingItems = getResources().getStringArray( |
| 114 | R.array.channel_spacing_entries); |
| 115 | mBandPreference = new ListPreference(this); |
| 116 | mBandPreference.setEntries(R.array.regional_band_entries); |
| 117 | mBandPreference.setEntryValues(R.array.regional_band_values); |
| 118 | mBandPreference.setDialogTitle(R.string.sel_band_menu); |
| 119 | mBandPreference.setKey(REGIONAL_BAND_KEY); |
| 120 | mBandPreference.setTitle(R.string.regional_band); |
| 121 | index = FmSharedPreferences.getCountry(); |
| 122 | Log.d(LOGTAG, "createPreferenceHierarchy: Country: " + index); |
| 123 | // Get the preference and list the value. |
| 124 | if ((index < 0) || (index >= summaryBandItems.length)) { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 125 | index = 0; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 126 | } |
| 127 | mBandPreference.setValueIndex(index); |
| 128 | root.addPreference(mBandPreference); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 129 | |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 130 | mChannelSpacingPref = new ListPreference(this); |
| 131 | mChannelSpacingPref.setEntries(R.array.channel_spacing_entries); |
| 132 | mChannelSpacingPref.setEntryValues(R.array.channel_spacing_val); |
| 133 | mChannelSpacingPref.setDialogTitle(R.string.sel_chanl_spacing); |
| 134 | mChannelSpacingPref.setTitle(R.string.chanl_spacing); |
| 135 | mChannelSpacingPref.setKey(CHAN_SPACING_KEY); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 136 | |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 137 | mUserBandMinPref = new EditTextPreference(this); |
| 138 | mUserBandMinPref.setKey(USER_DEFINED_BAND_MIN_KEY); |
| 139 | mUserBandMinPref.setTitle(R.string.usr_def_band_min); |
| 140 | mUserBandMinPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | |
| 141 | InputType.TYPE_NUMBER_FLAG_DECIMAL); |
| 142 | mUserBandMinPref.setDialogTitle(R.string.usr_def_band_min); |
| 143 | |
| 144 | mUserBandMaxPref = new EditTextPreference(this); |
| 145 | mUserBandMaxPref.setKey(USER_DEFINED_BAND_MAX_KEY); |
| 146 | mUserBandMaxPref.setTitle(R.string.usr_def_band_max); |
| 147 | mUserBandMaxPref.setDialogTitle(R.string.usr_def_band_max); |
| 148 | mUserBandMaxPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | |
| 149 | InputType.TYPE_NUMBER_FLAG_DECIMAL); |
| 150 | |
| 151 | setBandSummary(index); |
| 152 | |
| 153 | root.addPreference(mChannelSpacingPref); |
| 154 | root.addPreference(mUserBandMinPref); |
| 155 | root.addPreference(mUserBandMaxPref); |
| 156 | |
| 157 | if (mRxMode) { |
| 158 | // Audio Output (Stereo or Mono) |
| 159 | summaryAudioModeItems = getResources().getStringArray( |
| 160 | R.array.ster_mon_entries); |
| 161 | mAudioPreference = new ListPreference(this); |
| 162 | mAudioPreference.setEntries(R.array.ster_mon_entries); |
| 163 | mAudioPreference.setEntryValues(R.array.ster_mon_values); |
| 164 | mAudioPreference.setDialogTitle(R.string.sel_audio_output); |
| 165 | mAudioPreference.setKey(AUDIO_OUTPUT_KEY); |
| 166 | mAudioPreference.setTitle(R.string.aud_output_mode); |
| 167 | boolean audiomode = FmSharedPreferences.getAudioOutputMode(); |
| 168 | if (audiomode) { |
| 169 | index = 0; |
| 170 | } else { |
| 171 | index = 1; |
| 172 | } |
| 173 | Log.d(LOGTAG, "createPreferenceHierarchy: audiomode: " + audiomode); |
| 174 | mAudioPreference.setSummary(summaryAudioModeItems[index]); |
| 175 | mAudioPreference.setValueIndex(index); |
| 176 | root.addPreference(mAudioPreference); |
| 177 | |
| 178 | // AF Auto Enable (Checkbox) |
| 179 | mAfPref = new CheckBoxPreference(this); |
| 180 | mAfPref.setKey(AUTO_AF); |
| 181 | mAfPref.setTitle(R.string.auto_select_af); |
| 182 | mAfPref.setSummaryOn(R.string.auto_select_af_enabled); |
| 183 | mAfPref.setSummaryOff(R.string.auto_select_af_disabled); |
| 184 | boolean bAFAutoSwitch = FmSharedPreferences.getAutoAFSwitch(); |
| 185 | Log.d(LOGTAG, "createPreferenceHierarchy: bAFAutoSwitch: " |
| 186 | + bAFAutoSwitch); |
| 187 | mAfPref.setChecked(bAFAutoSwitch); |
| 188 | root.addPreference(mAfPref); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 189 | |
| 190 | if(FMRadio.RECORDING_ENABLE) { |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 191 | summaryRecordItems = getResources().getStringArray( |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 192 | R.array.record_durations_entries); |
| 193 | int nRecordDuration = 0; |
| 194 | mRecordDurPreference = new ListPreference(this); |
| 195 | mRecordDurPreference.setEntries(R.array.record_durations_entries); |
| 196 | mRecordDurPreference.setEntryValues(R.array.record_duration_values); |
| 197 | mRecordDurPreference.setDialogTitle(R.string.sel_rec_dur); |
| 198 | mRecordDurPreference.setKey(RECORD_DURATION_KEY); |
| 199 | mRecordDurPreference.setTitle(R.string.record_dur); |
| 200 | nRecordDuration = FmSharedPreferences.getRecordDuration(); |
| 201 | Log.d(LOGTAG, "createPreferenceHierarchy: recordDuration: " |
| 202 | + nRecordDuration); |
| 203 | switch(nRecordDuration) { |
| 204 | case FmSharedPreferences.RECORD_DUR_INDEX_0_VAL: |
| 205 | index = 0; |
| 206 | break; |
| 207 | case FmSharedPreferences.RECORD_DUR_INDEX_1_VAL: |
| 208 | index = 1; |
| 209 | break; |
| 210 | case FmSharedPreferences.RECORD_DUR_INDEX_2_VAL: |
| 211 | index = 2; |
| 212 | break; |
| 213 | case FmSharedPreferences.RECORD_DUR_INDEX_3_VAL: |
| 214 | index = 3; |
| 215 | break; |
| 216 | } |
| 217 | // Get the preference and list the value. |
| 218 | if ((index < 0) || (index >= summaryRecordItems.length)) { |
| 219 | index = 0; |
| 220 | } |
| 221 | Log.d(LOGTAG, "createPreferenceHierarchy: recordDurationSummary: " |
| 222 | + summaryRecordItems[index]); |
| 223 | mRecordDurPreference.setSummary(summaryRecordItems[index]); |
| 224 | mRecordDurPreference.setValueIndex(index); |
| 225 | root.addPreference(mRecordDurPreference); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Add a new category |
| 230 | PreferenceCategory prefCat = new PreferenceCategory(this); |
| 231 | root.addPreference(prefCat); |
| 232 | |
| 233 | mRestoreDefaultPreference = new Preference(this); |
| 234 | mRestoreDefaultPreference.setTitle( |
| 235 | R.string.settings_revert_defaults_title); |
| 236 | mRestoreDefaultPreference.setKey(RESTORE_FACTORY_DEFAULT); |
| 237 | mRestoreDefaultPreference |
| 238 | .setSummary(R.string.settings_revert_defaults_summary); |
| 239 | mRestoreDefaultPreference.setOnPreferenceClickListener(this); |
| 240 | root.addPreference(mRestoreDefaultPreference); |
| 241 | return root; |
| 242 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 243 | |
| 244 | public void clearStationList() { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 245 | SharedPreferences sp = getSharedPreferences(FMRadio.SCAN_STATION_PREFS_NAME, 0); |
| 246 | SharedPreferences.Editor editor = sp.edit(); |
| 247 | editor.clear(); |
| 248 | editor.commit(); |
| 249 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 250 | |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 251 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, |
| 252 | String key) { |
| 253 | int mTunedFreq = 0; |
| 254 | boolean bStatus = false; |
| 255 | if (key.equals(REGIONAL_BAND_KEY)) { |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 256 | int curListIndex = FmSharedPreferences.getCurrentListIndex(); |
| 257 | PresetList curList = FmSharedPreferences.getStationList(curListIndex); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 258 | String valueStr = sharedPreferences.getString(key, ""); |
| 259 | int index = 0; |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 260 | if(valueStr != null) { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 261 | index = mBandPreference.findIndexOfValue(valueStr); |
| 262 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 263 | if((index < 0) || (index >= summaryBandItems.length)) { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 264 | index = 0; |
| 265 | mBandPreference.setValueIndex(0); |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 266 | }else if((index + 1) == summaryBandItems.length) { |
| 267 | mChannelSpacingPref.setEnabled(true); |
| 268 | }else { |
| 269 | mChannelSpacingPref.setEnabled(false); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 270 | } |
| 271 | Log.d(LOGTAG, "onSharedPreferenceChanged: Country Change: " |
| 272 | + index); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 273 | FmSharedPreferences.setCountry(index); |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 274 | setBandSummary(index); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 275 | bStatus = FMRadio.fmConfigure(); |
| 276 | FMTransmitterActivity.fmConfigure(); |
| 277 | if (curList != null) { |
| 278 | curList.clear(); |
| 279 | } |
| 280 | clearStationList(); |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 281 | }else if(key.equals(CHAN_SPACING_KEY)) { |
| 282 | int curListIndex = FmSharedPreferences.getCurrentListIndex(); |
| 283 | PresetList curList = FmSharedPreferences.getStationList(curListIndex); |
| 284 | String valStr = mChannelSpacingPref.getValue(); |
| 285 | int index = 0; |
| 286 | if(valStr != null) { |
| 287 | index = mChannelSpacingPref.findIndexOfValue(valStr); |
| 288 | } |
| 289 | if ((index < 0) || (index >= summaryRecordItems.length)) { |
| 290 | index = 0; |
| 291 | mChannelSpacingPref.setValueIndex(0); |
| 292 | } |
| 293 | mChannelSpacingPref.setSummary(chSpacingItems[index]); |
| 294 | FmSharedPreferences.setChSpacing(2 - index); |
| 295 | FMRadio.fmConfigure(); |
| 296 | FMTransmitterActivity.fmConfigure(); |
| 297 | if(curList != null) { |
| 298 | curList.clear(); |
| 299 | } |
| 300 | clearStationList(); |
| 301 | }else if(key.equals(USER_DEFINED_BAND_MIN_KEY)) { |
| 302 | String valStr = mUserBandMinPref.getText(); |
Ayaz Ahmad | 9aaa16e | 2013-08-30 14:33:38 +0530 | [diff] [blame] | 303 | double freq = 0; |
| 304 | try { |
| 305 | freq = Double.parseDouble(valStr) * 1000; |
| 306 | }catch(NumberFormatException e) { |
| 307 | e.printStackTrace(); |
| 308 | return; |
| 309 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 310 | max_freq = FmSharedPreferences.getUpperLimit(); |
| 311 | min_freq = FmSharedPreferences.getLowerLimit(); |
| 312 | if((freq > 0) && (freq < max_freq) && (freq >= 76000)) { |
| 313 | FmSharedPreferences.setLowerLimit((int)freq); |
| 314 | FMRadio.fmConfigure(); |
| 315 | FMTransmitterActivity.fmConfigure(); |
| 316 | setBandSummary(summaryBandItems.length - 1); |
| 317 | clearStationList(); |
| 318 | }else { |
| 319 | displayToast(USR_BAND_MSG); |
| 320 | } |
| 321 | }else if(key.equals(USER_DEFINED_BAND_MAX_KEY)) { |
| 322 | String valStr = mUserBandMaxPref.getText(); |
Ayaz Ahmad | 9aaa16e | 2013-08-30 14:33:38 +0530 | [diff] [blame] | 323 | double freq = 0; |
| 324 | try { |
| 325 | freq = Double.parseDouble(valStr) * 1000; |
| 326 | }catch(NumberFormatException e) { |
| 327 | e.printStackTrace(); |
| 328 | return; |
| 329 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 330 | min_freq = FmSharedPreferences.getLowerLimit(); |
| 331 | max_freq = FmSharedPreferences.getUpperLimit(); |
| 332 | if((freq > 0) && (freq > min_freq) && (freq <= 108000)) { |
| 333 | FmSharedPreferences.setUpperLimit((int)freq); |
| 334 | FMRadio.fmConfigure(); |
| 335 | FMTransmitterActivity.fmConfigure(); |
| 336 | setBandSummary(summaryBandItems.length - 1); |
| 337 | clearStationList(); |
| 338 | }else { |
| 339 | displayToast(USR_BAND_MSG); |
| 340 | } |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 341 | }else { |
| 342 | if(mRxMode) { |
| 343 | if (key.equals(AUTO_AF)) { |
| 344 | boolean bAFAutoSwitch = mAfPref.isChecked(); |
| 345 | Log.d(LOGTAG, "onSharedPreferenceChanged: Auto AF Enable: " |
| 346 | + bAFAutoSwitch); |
| 347 | FmSharedPreferences.setAutoAFSwitch(bAFAutoSwitch); |
| 348 | FMRadio.fmAutoAFSwitch(); |
| 349 | mPrefs.Save(); |
| 350 | }else if(key.equals(RECORD_DURATION_KEY)) { |
| 351 | if(FMRadio.RECORDING_ENABLE) { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 352 | String valueStr = mRecordDurPreference.getValue(); |
| 353 | int index = 0; |
| 354 | if (valueStr != null) { |
| 355 | index = mRecordDurPreference.findIndexOfValue(valueStr); |
| 356 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 357 | if ((index < 0) || (index >= summaryRecordItems.length)) { |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 358 | index = 0; |
| 359 | mRecordDurPreference.setValueIndex(index); |
| 360 | } |
| 361 | Log.d(LOGTAG, "onSharedPreferenceChanged: recorddur: " |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 362 | + summaryRecordItems[index]); |
| 363 | mRecordDurPreference.setSummary(summaryRecordItems[index]); |
| 364 | FmSharedPreferences.setRecordDuration(index); |
| 365 | } |
| 366 | } else if (key.equals(AUDIO_OUTPUT_KEY)) { |
| 367 | String valueStr = mAudioPreference.getValue(); |
| 368 | int index = 0; |
| 369 | if (valueStr != null) { |
| 370 | index = mAudioPreference.findIndexOfValue(valueStr); |
| 371 | } |
| 372 | if (index != 1) { |
| 373 | if (index != 0) { |
| 374 | index = 0; |
| 375 | /* It shud be 0(Stereo) or 1(Mono) */ |
| 376 | mAudioPreference.setValueIndex(index); |
| 377 | } |
| 378 | } |
| 379 | Log.d(LOGTAG, "onSharedPreferenceChanged: audiomode: " |
| 380 | + summaryAudioModeItems[index]); |
| 381 | mAudioPreference.setSummary(summaryAudioModeItems[index]); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 382 | if (index == 0) { |
| 383 | // Stereo |
| 384 | FmSharedPreferences.setAudioOutputMode(true); |
| 385 | }else { |
| 386 | // Mono |
| 387 | FmSharedPreferences.setAudioOutputMode(false); |
| 388 | } |
Ayaz Ahmad | d97a0bb | 2013-09-02 12:17:33 +0530 | [diff] [blame] | 389 | mPrefs.Save(); |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 390 | FMRadio.fmAudioOutputMode(); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | if (mPrefs != null) { |
| 395 | if(bStatus) { |
| 396 | mPrefs.Save(); |
| 397 | }else { |
| 398 | mTunedFreq = FmSharedPreferences.getTunedFrequency(); |
| 399 | if (mTunedFreq > FmSharedPreferences.getUpperLimit() || |
| 400 | mTunedFreq < FmSharedPreferences.getLowerLimit()) { |
| 401 | FmSharedPreferences.setTunedFrequency( |
| 402 | FmSharedPreferences.getLowerLimit()); |
| 403 | } |
| 404 | mPrefs.Save(); |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | public boolean onPreferenceClick(Preference preference) { |
| 410 | boolean handled = false; |
| 411 | if (preference == mRestoreDefaultPreference) { |
| 412 | showDialog(RESTORE_FACTORY_DEFAULT_INT); |
| 413 | } |
| 414 | return handled; |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | protected Dialog onCreateDialog(int id) { |
| 419 | switch (id) { |
| 420 | case RESTORE_FACTORY_DEFAULT_INT: |
| 421 | return new AlertDialog.Builder(this).setIcon( |
| 422 | R.drawable.alert_dialog_icon).setTitle( |
| 423 | R.string.settings_revert_confirm_title).setMessage( |
| 424 | R.string.settings_revert_confirm_msg).setPositiveButton( |
| 425 | R.string.alert_dialog_ok, |
| 426 | new DialogInterface.OnClickListener() { |
| 427 | public void onClick(DialogInterface dialog, |
| 428 | int whichButton) { |
| 429 | Intent data = new Intent( |
| 430 | RESTORE_FACTORY_DEFAULT_ACTION); |
| 431 | setResult(RESULT_OK, data); |
| 432 | restoreSettingsDefault(); |
| 433 | finish(); |
| 434 | } |
| 435 | }).setNegativeButton(R.string.alert_dialog_cancel, |
| 436 | new DialogInterface.OnClickListener() { |
| 437 | public void onClick(DialogInterface dialog, |
| 438 | int whichButton) { |
| 439 | } |
| 440 | }).create(); |
| 441 | default: |
| 442 | break; |
| 443 | } |
| 444 | return null; |
| 445 | } |
| 446 | |
| 447 | private void restoreSettingsDefault() { |
| 448 | if (mPrefs != null) { |
| 449 | if (Locale.getDefault().equals(Locale.CHINA)) { |
| 450 | mBandPreference |
| 451 | .setValueIndex(FmSharedPreferences.REGIONAL_BAND_CHINA); |
| 452 | }else { |
| 453 | mBandPreference |
| 454 | .setValueIndex(FmSharedPreferences.REGIONAL_BAND_NORTH_AMERICA); |
| 455 | } |
| 456 | if (mRxMode) { |
| 457 | mAudioPreference.setValueIndex(0); |
| 458 | if (FMRadio.RECORDING_ENABLE) { |
| 459 | mRecordDurPreference.setValueIndex(0); |
| 460 | } |
| 461 | mAfPref.setChecked(true); |
| 462 | FmSharedPreferences.SetDefaults(); |
| 463 | }else { |
| 464 | if (Locale.getDefault().equals(Locale.CHINA)) { |
| 465 | FmSharedPreferences |
| 466 | .setCountry(FmSharedPreferences.REGIONAL_BAND_CHINA); |
| 467 | }else{ |
| 468 | FmSharedPreferences |
| 469 | .setCountry(FmSharedPreferences.REGIONAL_BAND_NORTH_AMERICA); |
| 470 | } |
| 471 | } |
| 472 | mPrefs.Save(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | protected void onResume() { |
| 478 | super.onResume(); |
| 479 | PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 480 | SharedPreferences sharedPreferences = null; |
| 481 | if (preferenceScreen != null) { |
| 482 | sharedPreferences = preferenceScreen.getSharedPreferences(); |
| 483 | } |
| 484 | if (sharedPreferences != null) { |
| 485 | sharedPreferences.registerOnSharedPreferenceChangeListener(this); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | protected void onPause() { |
| 491 | super.onPause(); |
| 492 | PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 493 | SharedPreferences sharedPreferences = null; |
| 494 | if (preferenceScreen != null) { |
| 495 | sharedPreferences = preferenceScreen.getSharedPreferences(); |
| 496 | } |
| 497 | if (sharedPreferences != null) { |
| 498 | sharedPreferences.unregisterOnSharedPreferenceChangeListener(this); |
| 499 | } |
| 500 | } |
Ayaz Ahmad | 8204f71 | 2013-08-01 15:40:16 +0530 | [diff] [blame] | 501 | private void setBandSummary(int index) { |
| 502 | if((index + 1) == summaryBandItems.length) { |
| 503 | min_freq = FmSharedPreferences.getLowerLimit(); |
| 504 | max_freq = FmSharedPreferences.getUpperLimit(); |
| 505 | chan_spacing = FmSharedPreferences.getChSpacing(); |
| 506 | if(chan_spacing < 0) { |
| 507 | chan_spacing = 0; |
| 508 | } |
| 509 | mBandPreference.setSummary(summaryBandItems[index] + "( " |
| 510 | + (min_freq / 1000.0) +"Mhz To " + (max_freq / 1000.0) + |
| 511 | "Mhz)"); |
| 512 | mChannelSpacingPref.setValueIndex(2 - chan_spacing); |
| 513 | mChannelSpacingPref.setSummary(chSpacingItems[2 - chan_spacing]); |
| 514 | mChannelSpacingPref.setEnabled(true); |
| 515 | mUserBandMinPref.setEnabled(true); |
| 516 | mUserBandMaxPref.setEnabled(true); |
| 517 | mUserBandMinPref.setSummary((min_freq / 1000.0) + "Mhz"); |
| 518 | mUserBandMaxPref.setSummary((max_freq / 1000.0) + "Mhz"); |
| 519 | }else { |
| 520 | mBandPreference.setSummary(summaryBandItems[index]); |
| 521 | mChannelSpacingPref.setEnabled(false); |
| 522 | mUserBandMinPref.setEnabled(false); |
| 523 | mUserBandMaxPref.setEnabled(false); |
| 524 | } |
| 525 | } |
| 526 | private void displayToast(String msg) { |
| 527 | Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show(); |
| 528 | } |
Venkateshwarlu Domakonda | 56262fb | 2013-07-24 19:56:59 +0530 | [diff] [blame] | 529 | } |