private void setMax(AudioManager audioManager, int catID, int key, int index) { PreferenceCategory cat = (PreferenceCategory)findPreference(getString(catID)); ((SeekBarPreference)cat.findPreference(getString(key))).setMax(audioManager.getStreamMaxVolume(index)); }
@Override public void onCreatePreferences(Bundle bundle, String s) { getPreferenceManager().setSharedPreferencesName(getString(R.string.app_name)); addPreferencesFromResource(R.xml.app_preferences); SeekBarPreference preference = (SeekBarPreference) findPreference("sound_volume"); int maxVolume = ((TalkActivity) getContext()).getMaxVolume(); preference.setMax(maxVolume); Session session = ((App) getActivity().getApplication()).getSession(); if (!session.isDefaultValueSet()) { preference.setValue(maxVolume); session.setDefaultSoundVolume(true); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final SettingsManager pref = new SettingsManager(getActivity().getApplicationContext()); String keyAutostart = getString(R.string.pref_key_autostart); SwitchPreferenceCompat autostart = (SwitchPreferenceCompat) findPreference(keyAutostart); autostart.setChecked(pref.getBoolean(keyAutostart, SettingsManager.Default.autostart)); bindOnPreferenceChangeListener(autostart); String keyKeepAlive = getString(R.string.pref_key_keep_alive); SwitchPreferenceCompat keepAlive = (SwitchPreferenceCompat) findPreference(keyKeepAlive); keepAlive.setChecked(pref.getBoolean(keyKeepAlive, SettingsManager.Default.keepAlive)); bindOnPreferenceChangeListener(keepAlive); String keyShutdownComplete = getString(R.string.pref_key_shutdown_downloads_complete); SwitchPreferenceCompat shutdownComplete = (SwitchPreferenceCompat) findPreference(keyShutdownComplete); shutdownComplete.setChecked(pref.getBoolean(keyShutdownComplete, SettingsManager.Default.shutdownDownloadsComplete)); bindOnPreferenceChangeListener(shutdownComplete); String keyCpuSleep = getString(R.string.pref_key_cpu_do_not_sleep); SwitchPreferenceCompat cpuSleep = (SwitchPreferenceCompat) findPreference(keyCpuSleep); cpuSleep.setChecked(pref.getBoolean(keyCpuSleep, SettingsManager.Default.cpuDoNotSleep)); bindOnPreferenceChangeListener(cpuSleep); String keyOnlyCharging = getString(R.string.pref_key_download_and_upload_only_when_charging); SwitchPreferenceCompat onlyCharging = (SwitchPreferenceCompat) findPreference(keyOnlyCharging); onlyCharging.setChecked(pref.getBoolean(keyOnlyCharging, SettingsManager.Default.onlyCharging)); bindOnPreferenceChangeListener(onlyCharging); String keyBatteryControl = getString(R.string.pref_key_battery_control); SwitchPreferenceCompat batteryControl = (SwitchPreferenceCompat) findPreference(keyBatteryControl); batteryControl.setSummary(String.format(getString(R.string.pref_battery_control_summary), Utils.getDefaultBatteryLowLevel())); batteryControl.setChecked(pref.getBoolean(keyBatteryControl, SettingsManager.Default.batteryControl)); bindOnPreferenceChangeListener(batteryControl); String keyCustomBatteryControl = getString(R.string.pref_key_custom_battery_control); SwitchPreferenceCompat customBatteryControl = (SwitchPreferenceCompat) findPreference(keyCustomBatteryControl); customBatteryControl.setSummary(String.format(getString(R.string.pref_custom_battery_control_summary), Utils.getDefaultBatteryLowLevel())); customBatteryControl.setChecked(pref.getBoolean(keyCustomBatteryControl, SettingsManager.Default.customBatteryControl)); bindOnPreferenceChangeListener(customBatteryControl); String keyCustomBatteryControlValue = getString(R.string.pref_key_custom_battery_control_value); SeekBarPreference customBatteryControlValue = (SeekBarPreference) findPreference(keyCustomBatteryControlValue); customBatteryControlValue.setValue(pref.getInt(keyCustomBatteryControlValue, Utils.getDefaultBatteryLowLevel())); customBatteryControlValue.setMin(10); customBatteryControlValue.setMax(90); bindOnPreferenceChangeListener(customBatteryControlValue); String keyWifiOnly = getString(R.string.pref_key_wifi_only); SwitchPreferenceCompat wifiOnly = (SwitchPreferenceCompat) findPreference(keyWifiOnly); wifiOnly.setChecked(pref.getBoolean(keyWifiOnly, SettingsManager.Default.wifiOnly)); bindOnPreferenceChangeListener(wifiOnly); }