List of usage examples for android.preference EditTextPreference setText
public void setText(String text)
From source file:fr.free.nrw.commons.settings.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { AndroidInjection.inject(this); super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); // Update spinner to show selected value as summary ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE); licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue()))); // Keep summary updated when changing value licensePreference.setOnPreferenceChangeListener((preference, newValue) -> { preference.setSummary(getString(Utils.licenseNameFor((String) newValue))); return true; });//w w w .jav a2s. c o m CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme"); themePreference.setOnPreferenceChangeListener((preference, newValue) -> { getActivity().recreate(); return true; }); final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads"); int uploads = prefs.getInt(Prefs.UPLOADS_SHOWING, 100); uploadLimit.setText(uploads + ""); uploadLimit.setSummary(uploads + ""); uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> { int value = Integer.parseInt(newValue.toString()); final SharedPreferences.Editor editor = prefs.edit(); if (value > 500) { new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit) .setMessage(R.string.maximum_limit_alert) .setPositiveButton(android.R.string.yes, (dialog, which) -> { }).setIcon(android.R.drawable.ic_dialog_alert).show(); editor.putInt(Prefs.UPLOADS_SHOWING, 500); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(500 + ""); uploadLimit.setText(500 + ""); } else { editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString())); editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true); uploadLimit.setSummary(newValue.toString()); } editor.apply(); return true; }); Preference sendLogsPreference = findPreference("sendLogFile"); sendLogsPreference.setOnPreferenceClickListener(preference -> { //first we need to check if we have the necessary permissions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { sendAppLogsViaEmail(); } else { //first get the necessary permission requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_CODE_WRITE_EXTERNAL_STORAGE); } } else { sendAppLogsViaEmail(); } return true; }); }
From source file:com.android.settings.locationprivacy.LocationPrivacyAdvancedSettings.java
private void refresh() { for (int i = 0; i < screen.getPreferenceCount(); i++) { Preference pref = screen.getPreference(i); if (pref != null) { System.out.println(pref); String key = pref.getKey(); if (key != null) { System.out.println(key); if (key.equals("lp_settings_advanced_useonlinealgorithm")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isUseOnlineAlgorithm()); } else if (key.equals("lp_settings_advanced_shareprivacyaettings")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isSharePrivacySettings()); checkPref.setEnabled(GooglePlayServicesUtil .isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS && lpManager.isWebhostShareSettings() && AccountManager.get(getActivity()).getAccountsByType("com.google").length >= 1); } else if (key.equals("lp_settings_advanced_showcommunityadvice")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isShowCommunityAdvice()); checkPref.setEnabled(lpManager.isShowCommunityAdvice()); } else if (key.equals("lp_settings_advanced_stars")) { CheckBoxPreference checkPref = (CheckBoxPreference) pref; checkPref.setChecked(lpManager.isUseStarsInDialog()); } else if (key.equals("lp_settings_advanced_webservice")) { EditTextPreference editTextPref = (EditTextPreference) pref; editTextPref.setText("" + lpManager.getWebserviceHostAdress()); } else if (key.equals("lp_settings_advanced_setpreset_min")) { EditTextPreference editTextPref = (EditTextPreference) pref; editTextPref.setText("" + lpManager.getMinDistance()); }//from ww w . j av a2 s . c o m pref.setOnPreferenceChangeListener(this); pref.setOnPreferenceClickListener(this); } } } }
From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java
private EditTextPreference getNamePreference() { final EditTextPreference name = new EditTextPreference(getActivity()); name.setTitle(R.string.special_list_name); name.setSummary(mItem.getName());//from ww w .j ava 2s . c om name.setText(mItem.getName()); name.setSummary(mItem.getName()); name.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final EditText input = new EditText(getActivity()); input.setSingleLine(true); input.setText(mItem.getName()); new AlertDialog.Builder(getActivity()).setTitle(R.string.special_list_name).setView(input) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mItem.setName(input.getText().toString()); mItem.save(); name.setSummary(mItem.getName()); mAdapter.notifyDataSetChanged(); } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } }); return name; }
From source file:com.hichinaschool.flashcards.anki.CramDeckOptions.java
protected void buildLists() { ListPreference newOrderPref = (ListPreference) findPreference("order"); newOrderPref.setEntries(R.array.cram_deck_conf_order_labels); newOrderPref.setEntryValues(R.array.cram_deck_conf_order_values); newOrderPref.setValue(mPref.getString("order", "0")); if (mPresetSearchSuffix != null) { EditTextPreference searchPref = (EditTextPreference) findPreference("search"); searchPref.setText(mPresetSearchSuffix); }//from w w w. jav a2 s .co m }
From source file:com.mantz_it.rfanalyzer.SettingsFragment.java
/** * Will go through each preference element and initialize/update the summary according to its value. * @note this will also correct invalid user inputs on EdittextPreferences! *///from www .j av a 2 s. com public void updateSummaries() { // Source Type ListPreference listPref = (ListPreference) findPreference(getString(R.string.pref_sourceType)); listPref.setSummary(getString(R.string.pref_sourceType_summ, listPref.getEntry())); // Direct Sampling listPref = (ListPreference) findPreference(getString(R.string.pref_rtlsdr_directSamp)); listPref.setSummary(getString(R.string.pref_rtlsdr_directSamp_summ, listPref.getEntry())); // Frequency display listPref = (ListPreference) findPreference(getString(R.string.pref_surface_unit)); listPref.setSummary(getString(R.string.pref_surface_unit_summ, listPref.getEntry())); // FileSource Frequency EditTextPreference editTextPref = (EditTextPreference) findPreference( getString(R.string.pref_filesource_frequency)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_filesource_frequency_default)); editTextPref.setSummary(getString(R.string.pref_filesource_frequency_summ, editTextPref.getText())); // FileSource Sample Rate editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_sampleRate)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_filesource_sampleRate_default)); editTextPref.setSummary(getString(R.string.pref_filesource_sampleRate_summ, editTextPref.getText())); // FileSource File editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_filesource_file)); editTextPref.setSummary(getString(R.string.pref_filesource_file_summ, editTextPref.getText())); // FileSource Format listPref = (ListPreference) findPreference(getString(R.string.pref_filesource_format)); listPref.setSummary(getString(R.string.pref_filesource_format_summ, listPref.getEntry())); // HackRF frequency shift editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_hackrf_frequencyOffset)); if (editTextPref.getText().length() == 0) editTextPref.setText("0"); editTextPref.setSummary(getString(R.string.pref_hackrf_frequencyOffset_summ, editTextPref.getText())); // RTL-SDR IP editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_ip)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_ip_summ, editTextPref.getText())); // RTL-SDR Port editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_port)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_port_summ, editTextPref.getText())); // RTL-SDR frequency correction editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyCorrection)); if (editTextPref.getText().length() == 0) editTextPref.setText(getString(R.string.pref_rtlsdr_frequencyCorrection_default)); editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyCorrection_summ, editTextPref.getText())); // RTL-SDR frequency shift editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_rtlsdr_frequencyOffset)); if (editTextPref.getText().length() == 0) editTextPref.setText("0"); editTextPref.setSummary(getString(R.string.pref_rtlsdr_frequencyOffset_summ, editTextPref.getText())); // FFT size listPref = (ListPreference) findPreference(getString(R.string.pref_fftSize)); listPref.setSummary(getString(R.string.pref_fftSize_summ, listPref.getEntry())); // Color map type listPref = (ListPreference) findPreference(getString(R.string.pref_colorMapType)); listPref.setSummary(getString(R.string.pref_colorMapType_summ, listPref.getEntry())); // FFT drawing type listPref = (ListPreference) findPreference(getString(R.string.pref_fftDrawingType)); listPref.setSummary(getString(R.string.pref_fftDrawingType_summ, listPref.getEntry())); // Averaging listPref = (ListPreference) findPreference(getString(R.string.pref_averaging)); listPref.setSummary(getString(R.string.pref_averaging_summ, listPref.getEntry())); // Screen Orientation listPref = (ListPreference) findPreference(getString(R.string.pref_screenOrientation)); listPref.setSummary(getString(R.string.pref_screenOrientation_summ, listPref.getEntry())); // Spectrum Waterfall Ratio listPref = (ListPreference) findPreference(getString(R.string.pref_spectrumWaterfallRatio)); listPref.setSummary(getString(R.string.pref_spectrumWaterfallRatio_summ, listPref.getEntry())); // Font Size listPref = (ListPreference) findPreference(getString(R.string.pref_fontSize)); listPref.setSummary(getString(R.string.pref_fontSize_summ, listPref.getEntry())); // Frame Rate SwitchPreference switchPref = (SwitchPreference) findPreference(getString(R.string.pref_dynamicFrameRate)); listPref = (ListPreference) findPreference(getString(R.string.pref_frameRate)); if (switchPref.isChecked()) listPref.setSummary(getString(R.string.pref_frameRate_summ, "auto")); else listPref.setSummary(getString(R.string.pref_frameRate_summ, listPref.getEntry())); // Logfile editTextPref = (EditTextPreference) findPreference(getString(R.string.pref_logfile)); editTextPref.setSummary(getString(R.string.pref_logfile_summ, editTextPref.getText())); // Shared preferences updated in e.g. the onRequestPermissionResult() method are // not automatically updated in the preference fragment gui. do it manually: SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); switchPref = (SwitchPreference) findPreference(getString(R.string.pref_logging)); switchPref.setChecked(preferences.getBoolean(getString(R.string.pref_logging), false)); }
From source file:net.freifunk.android.discover.SettingsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_data_sync); // get data via the key ArrayList<NodeMap> nodeMapArrayList = new ArrayList<NodeMap>(MapMaster.getInstance().getMaps().values()); PreferenceCategory communities = (PreferenceCategory) findPreference("communities"); // sort by Name Collections.sort(nodeMapArrayList, new NodeMapComparator()); if (nodeMapArrayList != null && communities != null) { for (final NodeMap nm : nodeMapArrayList) { PreferenceScreen communityPreferenceScreen = getPreferenceManager() .createPreferenceScreen(SettingsActivity.this); communityPreferenceScreen.setTitle(nm.getMapName()); communityPreferenceScreen.setKey(nm.getMapName()); final CheckBoxPreference deactivateCommunityPreference = new CheckBoxPreference( SettingsActivity.this); // TODO: move Strings to resources deactivateCommunityPreference.setTitle("Community aktiv"); deactivateCommunityPreference .setSummary("deaktivieren, falls Community nicht auf der Karte angezeigt werden soll"); deactivateCommunityPreference.setKey("community_deactivate_" + nm.getMapName()); deactivateCommunityPreference.setChecked(nm.isActive()); deactivateCommunityPreference .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); boolean newActive = newValue.toString().equals("true") ? true : false; nm.setActive(newActive); db.addNodeMap(nm); // reload if set to active if (newActive) { nm.loadNodes(); } else { nm.updateNodes(); }//w w w. j a v a2 s .c om return true; } }); EditTextPreference editCommunityPreference = new EditTextPreference(SettingsActivity.this); // TODO: move Strings to resources editCommunityPreference.setTitle("URL bearbeiten"); editCommunityPreference.setSummary("aendern, falls eine andere Quelle genutzt werden soll."); editCommunityPreference.setKey("community_edit_" + nm.getMapName()); editCommunityPreference.setText(nm.getMapUrl()); editCommunityPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Database db = Database.getInstance(null); // remove old nodes from map nm.setActive(false); EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_NODES, nm)); // we should probably do this async as well db.deleteAllNodesForMap(nm); // load new nodes NodeMap newMap = new NodeMap(nm.getMapName(), (String) newValue, true); db.addNodeMap(newMap); //HashMap<String, NodeMap> nodeResult = new HashMap<String, NodeMap>(1); //nodeResult.put(nm.getMapName(), nm); newMap.updateNodes(); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.LOAD_NODES, nm)); //EventBus.getInstance().post(new NodeResult(NodeResult.NodeResultType.UPDATE_MAP, nodeResult)); return true; } }); communityPreferenceScreen.addPreference(deactivateCommunityPreference); communityPreferenceScreen.addPreference(editCommunityPreference); communities.addPreference(communityPreferenceScreen); } } setupActionBar(); }
From source file:org.span.manager.ChangeSettingsActivity.java
private void updateView() { // user id/*from w w w .j av a 2s .c om*/ EditTextPreference uidEditTextPref = (EditTextPreference) findPreference("uidpref"); uidEditTextPref.setText(manetcfg.getUserId()); // wifi group wifiGroupPref = (PreferenceGroup) findPreference("wifiprefs"); boolean bluetoothOn = manetcfg.isUsingBluetooth(); wifiGroupPref.setEnabled(!bluetoothOn); // wifi encryption algorithm WifiEncryptionAlgorithmEnum encAlgorithm = manetcfg.getWifiEncryptionAlgorithm(); ListPreference wifiEncAlgorithmPref = (ListPreference) findPreference("encalgorithmpref"); wifiEncAlgorithmPref.setEnabled(false); // TODO: disable until tested wifiEncAlgorithmPref.setEntries(WifiEncryptionAlgorithmEnum.descriptionValues()); wifiEncAlgorithmPref.setEntryValues(WifiEncryptionAlgorithmEnum.stringValues()); wifiEncAlgorithmPref.setValueIndex(encAlgorithm.ordinal()); // wifi encryption setup method ListPreference wifiEncSetupMethodPref = (ListPreference) findPreference("encsetuppref"); wifiEncSetupMethodPref.setEnabled(false); // TODO: disable until tested if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) { wifiEncSetupMethodPref.setEnabled(false); } else { wifiEncSetupMethodPref.setEnabled(true); if (manetcfg.getWifiDriver().startsWith("softap") || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { if (wifiEncSetupMethodPref != null) { wifiGroupPref.removePreference(wifiEncSetupMethodPref); } } else { wifiEncSetupMethodPref.setEntries(WifiEncryptionSetupMethodEnum.descriptionValues()); wifiEncSetupMethodPref.setEntryValues(WifiEncryptionSetupMethodEnum.stringValues()); wifiEncSetupMethodPref.setValueIndex(manetcfg.getWifiEncryptionSetupMethod().ordinal()); } } // wifi encryption password final EditTextPreference wifiEncPasswordEditTextPref = (EditTextPreference) findPreference("passwordpref"); wifiEncPasswordEditTextPref.setEnabled(false); // TODO: disable until tested if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) { wifiEncPasswordEditTextPref.setEnabled(false); } else { wifiEncPasswordEditTextPref.setEnabled(true); final int origTextColorWifiEncKey = wifiEncPasswordEditTextPref.getEditText().getCurrentTextColor(); if (manetcfg.getWifiDriver().startsWith("softap") || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { Validation.setupWpaEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey); } else { Validation.setupWepEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey); } wifiEncPasswordEditTextPref.setText(manetcfg.getWifiEncryptionPassword()); } // wifi SSID EditTextPreference wifiSsidEditTextPref = (EditTextPreference) findPreference("ssidpref"); Validation.setupWifiSsidValidator(wifiSsidEditTextPref); wifiSsidEditTextPref.setText(manetcfg.getWifiSsid()); // wifi channel ListPreference channelpref = (ListPreference) findPreference("channelpref"); channelpref.setEnabled(false); // TODO: disable until tested String[] channelStrValues = WifiChannelEnum.stringValues(); String[] channelDescValues = WifiChannelEnum.descriptionValues(); // remove auto channel option if not supported by device if (!manetcfg.getWifiDriver().startsWith("softap") || !manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) { // auto channel option at first index String[] newChannelStrValues = new String[channelStrValues.length - 1]; String[] newChannelDescValues = new String[channelStrValues.length - 1]; for (int i = 1; i < channelStrValues.length; i++) { newChannelStrValues[i - 1] = channelStrValues[i]; newChannelDescValues[i - 1] = channelDescValues[i]; } channelpref.setEntries(newChannelDescValues); channelpref.setEntryValues(newChannelStrValues); WifiChannelEnum wifiChannel = manetcfg.getWifiChannel(); if (wifiChannel == WifiChannelEnum.AUTO) { channelpref.setValueIndex(WifiChannelEnum.CHANNEL_1.ordinal() - 1); } else { channelpref.setValueIndex(wifiChannel.ordinal() - 1); } } else { channelpref.setEntries(channelDescValues); channelpref.setEntryValues(channelStrValues); channelpref.setValueIndex(manetcfg.getWifiChannel().ordinal()); } // wifi transmit power ListPreference txpowerPreference = (ListPreference) findPreference("txpowerpref"); if (!manetcfg.isTransmitPowerSupported()) { // DEBUG if (txpowerPreference != null) { wifiGroupPref.removePreference(txpowerPreference); } } else { txpowerPreference.setEntries(WifiTxpowerEnum.descriptionValues()); txpowerPreference.setEntryValues(WifiTxpowerEnum.stringValues()); txpowerPreference.setValueIndex(manetcfg.getWifiTxpower().ordinal()); } // bluetooth group // disable bluetooth adhoc if not supported by the kernel if (true) { // !manetcfg.isBluetoothSupported() // TODO: disable until tested PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); btGroup.setEnabled(false); } // bluetooth // NOTE: bluetooth dependencies are specified in the layout XML // CheckBoxPreference bluetoothCheckboxPref = (CheckBoxPreference)findPreference("bluetoothonpref"); // bluetooth keep wifi CheckBoxPreference btKeepWifiCheckBoxPref = (CheckBoxPreference) findPreference("bluetoothkeepwifipref"); if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) { PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); if (btKeepWifiCheckBoxPref != null) { btGroup.removePreference(btKeepWifiCheckBoxPref); } } else { btKeepWifiCheckBoxPref.setChecked(!manetcfg.isWifiDisabledWhenUsingBluetooth()); } // bluetooth discoverable CheckBoxPreference btdiscoverablePreference = (CheckBoxPreference) findPreference( "bluetoothdiscoverablepref"); if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) { PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs"); if (btdiscoverablePreference != null) { btGroup.removePreference(btdiscoverablePreference); } } else { btdiscoverablePreference.setChecked(manetcfg.isBluetoothDiscoverableWhenInAdhocMode()); } // ip address EditTextPreference ipAddressEditTextPref = (EditTextPreference) findPreference("ippref"); Validation.setupIpAddressValidator(ipAddressEditTextPref); ipAddressEditTextPref.setText(manetcfg.getIpAddress()); // dns server EditTextPreference dnsServerEditTextPref = (EditTextPreference) findPreference("dnspref"); Validation.setupIpAddressValidator(dnsServerEditTextPref); dnsServerEditTextPref.setText(manetcfg.getDnsServer()); // routing protocol String currRoutingProtocol = manetcfg.getRoutingProtocol(); List<String> routingProtocolList = CoreTask.getRoutingProtocols(); String[] routingProtocols = new String[routingProtocolList.size()]; routingProtocolList.toArray(routingProtocols); ListPreference routingProtocolPreference = (ListPreference) findPreference("routingprotocolpref"); routingProtocolPreference.setEntries(routingProtocols); routingProtocolPreference.setEntryValues(routingProtocols); routingProtocolPreference.setValue(currRoutingProtocol); // routing ignore list JSONArray array = new JSONArray(manetcfg.getRoutingIgnoreList()); sharedPreferences.edit().putString("ignorepref", array.toString()).commit(); // wifi interface String currInterface = manetcfg.getWifiInterface(); String defaultInterface = DeviceConfig.getWifiInterface(manetcfg.getDeviceType()); List<String> interfaceList = CoreTask.getNetworkInterfaces(); if (!interfaceList.contains(defaultInterface)) { interfaceList.add(defaultInterface); } String[] interfaces = new String[interfaceList.size()]; interfaceList.toArray(interfaces); ListPreference interfacePreference = (ListPreference) findPreference("interfacepref"); interfacePreference.setEntries(interfaces); interfacePreference.setEntryValues(interfaces); if (interfaceList.contains(currInterface)) { interfacePreference.setValue(currInterface); } else { interfacePreference.setValue(defaultInterface); currInterface = defaultInterface; } // routing gateway String currGatewayInterface = manetcfg.getGatewayInterface(); interfaceList.remove(currInterface); // remove ad-hoc interface interfaceList.add(0, ManetConfig.GATEWAY_INTERFACE_NONE); interfaces = new String[interfaceList.size()]; interfaceList.toArray(interfaces); ListPreference gatewayPreference = (ListPreference) findPreference("gatewaypref"); gatewayPreference.setEntries(interfaces); gatewayPreference.setEntryValues(interfaces); gatewayPreference.setValue(currGatewayInterface); if (interfaceList.contains(currGatewayInterface)) { gatewayPreference.setValue(currGatewayInterface); } else { gatewayPreference.setValue(ManetConfig.GATEWAY_INTERFACE_NONE); } // screen on CheckBoxPreference screenOnPreference = (CheckBoxPreference) findPreference("screenonpref"); screenOnPreference.setChecked(manetcfg.isScreenOnWhenInAdhocMode()); // battery temperature setupFlag = true; }
From source file:org.linphone.AccountPreferencesFragment.java
private void initAccountPreferencesFields(PreferenceScreen parent) { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n; accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl()); accountCreator.setListener(this); PreferenceCategory account = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_sipaccount_key)); EditTextPreference username = (EditTextPreference) account.getPreference(0); username.setOnPreferenceChangeListener(usernameChangedListener); if (!isNewAccount) { username.setText(mPrefs.getAccountUsername(n)); username.setSummary(username.getText()); }/*from ww w .j a va 2 s . c o m*/ EditTextPreference userid = (EditTextPreference) account.getPreference(1); userid.setOnPreferenceChangeListener(useridChangedListener); if (!isNewAccount) { userid.setText(mPrefs.getAccountUserId(n)); userid.setSummary(userid.getText()); } EditTextPreference password = (EditTextPreference) account.getPreference(2); password.setOnPreferenceChangeListener(passwordChangedListener); if (!isNewAccount) { password.setText(mPrefs.getAccountPassword(n)); } EditTextPreference domain = (EditTextPreference) account.getPreference(3); domain.setOnPreferenceChangeListener(domainChangedListener); if (!isNewAccount) { domain.setText(mPrefs.getAccountDomain(n)); domain.setSummary(domain.getText()); } EditTextPreference displayName = (EditTextPreference) account.getPreference(4); displayName.setOnPreferenceChangeListener(displayNameChangedListener); if (!isNewAccount) { displayName.setText(mPrefs.getAccountDisplayName(n)); displayName.setSummary(displayName.getText()); } PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_advanced_key)); mTransportPreference = (ListPreference) advanced.getPreference(0); initializeTransportPreference(mTransportPreference); mTransportPreference.setOnPreferenceChangeListener(transportChangedListener); if (!isNewAccount) { mTransportPreference.setSummary(mPrefs.getAccountTransportString(n)); } mProxyPreference = (EditTextPreference) advanced.getPreference(1); mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener); if (!isNewAccount) { mProxyPreference.setText(mPrefs.getAccountProxy(n)); mProxyPreference .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null) ? getString(R.string.pref_help_proxy) : mProxyPreference.getText()); } CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2); outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); if (!isNewAccount) { outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n)); } EditTextPreference expires = (EditTextPreference) advanced.getPreference(3); expires.setOnPreferenceChangeListener(expiresChangedListener); if (!isNewAccount) { expires.setText(mPrefs.getExpires(n)); expires.setSummary(mPrefs.getExpires(n)); } EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4); prefix.setOnPreferenceChangeListener(prefixChangedListener); if (!isNewAccount) { String prefixValue = mPrefs.getPrefix(n); prefix.setText(prefixValue); prefix.setSummary(prefixValue); } CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5); avpf.setOnPreferenceChangeListener(avpfChangedListener); if (!isNewAccount) { avpf.setChecked(mPrefs.avpfEnabled(n)); } EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6); avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener); if (!isNewAccount) { avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n)); avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n)); } CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7); escape.setOnPreferenceChangeListener(escapeChangedListener); if (!isNewAccount) { escape.setChecked(mPrefs.getReplacePlusByZeroZero(n)); } Preference linkAccount = advanced.getPreference(8); linkAccount.setOnPreferenceClickListener(linkAccountListener); PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_manage_key)); final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0); disable.setEnabled(true); disable.setOnPreferenceChangeListener(disableChangedListener); if (!isNewAccount) { disable.setChecked(!mPrefs.isAccountEnabled(n)); } CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1); mainAccount.setChecked(isDefaultAccount); mainAccount.setEnabled(!mainAccount.isChecked()); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.setDefaultAccount(n); disable.setEnabled(false); disable.setChecked(false); preference.setEnabled(false); return true; } }); if (!isNewAccount) { mainAccount.setEnabled(!mainAccount.isChecked()); } final Preference changePassword = manage.getPreference(2); if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) { changePassword.setEnabled(!isNewAccount); changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance()); LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater(); View layout = inflater.inflate(R.layout.new_password, null); final EditText pass1 = (EditText) layout.findViewById(R.id.password1); final EditText pass2 = (EditText) layout.findViewById(R.id.password2); alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinphoneAccountCreator.PasswordCheck status = accountCreator .setPassword(pass1.getText().toString()); if (status.equals(LinphoneAccountCreator.PasswordCheck.Ok)) { if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) { accountCreator.setUsername(mPrefs.getAccountUsername(n)); accountCreator.setHa1(mPrefs.getAccountHa1(n)); LinphoneAccountCreator.RequestStatus req_status = accountCreator .updatePassword(pass1.getText().toString()); if (!req_status.equals(LinphoneAccountCreator.RequestStatus.Ok)) { LinphoneUtils.displayErrorAlert( LinphoneUtils.errorForRequestStatus(req_status), LinphoneActivity.instance()); } else { progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); Drawable d = new ColorDrawable(ContextCompat .getColor(LinphoneActivity.instance(), R.color.colorE)); d.setAlpha(200); progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); progress.getWindow().setBackgroundDrawable(d); progress.setContentView(R.layout.progress_dialog); progress.show(); } } else { LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched), LinphoneActivity.instance()); } return; } LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForPasswordStatus(status), LinphoneActivity.instance()); } }); alert.setView(layout); alert.show(); return true; } }); } else { changePassword.setEnabled(false); } final Preference delete = manage.getPreference(3); delete.setEnabled(!isNewAccount); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.deleteAccount(n); LinphoneActivity.instance().refreshAccounts(); LinphoneActivity.instance().displaySettings(); return true; } }); }
From source file:co.taqat.call.AccountPreferencesFragment.java
private void initAccountPreferencesFields(PreferenceScreen parent) { boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n; accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl()); accountCreator.setListener(this); PreferenceCategory account = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_sipaccount_key)); EditTextPreference username = (EditTextPreference) account.getPreference(0); username.setOnPreferenceChangeListener(usernameChangedListener); if (!isNewAccount) { username.setText(mPrefs.getAccountUsername(n)); username.setSummary(username.getText()); }/* w ww.j a v a 2 s.co m*/ EditTextPreference userid = (EditTextPreference) account.getPreference(1); userid.setOnPreferenceChangeListener(useridChangedListener); if (!isNewAccount) { userid.setText(mPrefs.getAccountUserId(n)); userid.setSummary(userid.getText()); } EditTextPreference password = (EditTextPreference) account.getPreference(2); password.setOnPreferenceChangeListener(passwordChangedListener); if (!isNewAccount) { password.setText(mPrefs.getAccountPassword(n)); } EditTextPreference domain = (EditTextPreference) account.getPreference(3); domain.setOnPreferenceChangeListener(domainChangedListener); if (!isNewAccount) { domain.setText(mPrefs.getAccountDomain(n)); domain.setSummary(domain.getText()); } EditTextPreference displayName = (EditTextPreference) account.getPreference(4); displayName.setOnPreferenceChangeListener(displayNameChangedListener); if (!isNewAccount) { displayName.setText(mPrefs.getAccountDisplayName(n)); displayName.setSummary(displayName.getText()); } PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_advanced_key)); mTransportPreference = (ListPreference) advanced.getPreference(0); initializeTransportPreference(mTransportPreference); mTransportPreference.setOnPreferenceChangeListener(transportChangedListener); if (!isNewAccount) { mTransportPreference.setSummary(mPrefs.getAccountTransportString(n)); } mProxyPreference = (EditTextPreference) advanced.getPreference(1); mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener); if (!isNewAccount) { mProxyPreference.setText(mPrefs.getAccountProxy(n)); mProxyPreference .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null) ? getString(R.string.pref_help_proxy) : mProxyPreference.getText()); } CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2); outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener); if (!isNewAccount) { outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n)); } EditTextPreference expires = (EditTextPreference) advanced.getPreference(3); expires.setOnPreferenceChangeListener(expiresChangedListener); if (!isNewAccount) { expires.setText(mPrefs.getExpires(n)); expires.setSummary(mPrefs.getExpires(n)); } EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4); prefix.setOnPreferenceChangeListener(prefixChangedListener); if (!isNewAccount) { String prefixValue = mPrefs.getPrefix(n); prefix.setText(prefixValue); prefix.setSummary(prefixValue); } CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5); avpf.setOnPreferenceChangeListener(avpfChangedListener); if (!isNewAccount) { avpf.setChecked(mPrefs.avpfEnabled(n)); } EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6); avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener); if (!isNewAccount) { avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n)); avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n)); } CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7); escape.setOnPreferenceChangeListener(escapeChangedListener); if (!isNewAccount) { escape.setChecked(mPrefs.getReplacePlusByZeroZero(n)); } CheckBoxPreference friendlistSubscribe = (CheckBoxPreference) advanced.getPreference(8); friendlistSubscribe.setOnPreferenceChangeListener(friendlistSubscribeListener); if (!isNewAccount) { friendlistSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled()); } Preference linkAccount = advanced.getPreference(9); linkAccount.setOnPreferenceClickListener(linkAccountListener); PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen() .findPreference(getString(R.string.pref_manage_key)); final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0); disable.setEnabled(true); disable.setOnPreferenceChangeListener(disableChangedListener); if (!isNewAccount) { disable.setChecked(!mPrefs.isAccountEnabled(n)); } CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1); mainAccount.setChecked(isDefaultAccount); mainAccount.setEnabled(!mainAccount.isChecked()); mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.setDefaultAccount(n); disable.setEnabled(false); disable.setChecked(false); preference.setEnabled(false); return true; } }); if (!isNewAccount) { mainAccount.setEnabled(!mainAccount.isChecked()); } final Preference changePassword = manage.getPreference(2); if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) { changePassword.setEnabled(!isNewAccount); changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance()); LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater(); View layout = inflater.inflate(R.layout.new_password, null); final EditText pass1 = (EditText) layout.findViewById(R.id.password1); final EditText pass2 = (EditText) layout.findViewById(R.id.password2); alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinphoneAccountCreator.Status status = accountCreator .setPassword(pass1.getText().toString()); if (status.equals(LinphoneAccountCreator.Status.Ok)) { if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) { accountCreator.setUsername(mPrefs.getAccountUsername(n)); accountCreator.setHa1(mPrefs.getAccountHa1(n)); status = accountCreator.updatePassword(pass1.getText().toString()); if (!status.equals(LinphoneAccountCreator.Status.Ok)) { LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } else { progress = ProgressDialog.show(LinphoneActivity.instance(), null, null); Drawable d = new ColorDrawable(ContextCompat .getColor(LinphoneActivity.instance(), R.color.colorE)); d.setAlpha(200); progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); progress.getWindow().setBackgroundDrawable(d); progress.setContentView(R.layout.progress_dialog); progress.show(); } } else { LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched), LinphoneActivity.instance()); } return; } LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status), LinphoneActivity.instance()); } }); alert.setView(layout); alert.show(); return true; } }); } else { changePassword.setEnabled(false); } final Preference delete = manage.getPreference(3); delete.setEnabled(!isNewAccount); delete.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { mPrefs.deleteAccount(n); LinphoneActivity.instance().refreshAccounts(); LinphoneActivity.instance().displaySettings(); return true; } }); }
From source file:com.wanikani.androidnotifier.SettingsActivity.java
private void setString(Preference pref, String key, String value) { EditTextPreference etp; pref.getEditor().putString(key, value).commit(); etp = (EditTextPreference) pref;/*from w ww . j a va 2 s . c om*/ etp.setText(value); }