List of usage examples for android.preference EditTextPreference setSummary
public void setSummary(CharSequence summary)
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) ? ? ? ? ?///from w w w. j a v a 2 s. c om * @param group , ??? */ protected void addPasswordPreference(PreferenceGroup group) { final Context context = group.getContext(); EditTextPreference passwordPref = new EditTextPreference(context); // ? passwordPref.setTitle(R.string.pref_password_title); passwordPref.setDialogTitle(R.string.pref_password_title); passwordPref.setSummary(R.string.pref_password_summary); passwordPref.setKey(getSharedKey(PREF_KEY_PASSWORD)); passwordPref.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passwordPref.getEditText().setSingleLine(); passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) }); group.addPreference(passwordPref); }
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) ? ?-?/*from w w w . j a va 2 s . c om*/ * @param group , ??? */ protected void addProxyPreferences(PreferenceGroup group) { final Context context = group.getContext(); PreferenceCategory proxyCat = new PreferenceCategory(context); //? ? ? proxyCat.setTitle(R.string.pref_cat_proxy); group.addPreference(proxyCat); CheckBoxPreference useProxyPref = new CheckBoxPreference(context); //? "? ? " useProxyPref.setTitle(R.string.pref_use_proxy); useProxyPref.setSummary(R.string.pref_use_proxy_summary); useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY)); useProxyPref.setDefaultValue(false); useProxyPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(useProxyPref); EditTextPreference proxyHostPref = new EditTextPreference(context); // ? ?-? proxyHostPref.setTitle(R.string.pref_proxy_host); proxyHostPref.setDialogTitle(R.string.pref_proxy_host); proxyHostPref.setSummary(R.string.pref_proxy_host_summary); proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST)); proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST); proxyHostPref.getEditText().setSingleLine(); proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); proxyHostPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPref); proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); EditTextPreference proxyHostPort = new EditTextPreference(context); // ?-? proxyHostPort.setTitle(R.string.pref_proxy_port); proxyHostPort.setDialogTitle(R.string.pref_proxy_port); proxyHostPort.setSummary(R.string.pref_proxy_port_summary); proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT)); proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT); proxyHostPort.getEditText().setSingleLine(); proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); proxyHostPort.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPort); proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); }
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 ww . j a v a 2 s . c o m 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:nya.miku.wishmaster.chans.cirno.CirnoModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { final Context context = preferenceGroup.getContext(); EditTextPreference passwordPref = new EditTextPreference(context); passwordPref.setTitle(R.string.iichan_prefs_report_thread); passwordPref.setDialogTitle(R.string.iichan_prefs_report_thread); passwordPref.setSummary(R.string.iichan_prefs_report_thread_summary); passwordPref.setKey(getSharedKey(PREF_KEY_REPORT_THREAD)); passwordPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); passwordPref.getEditText().setSingleLine(); passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) }); preferenceGroup.addPreference(passwordPref); super.addPreferencesOnScreen(preferenceGroup); }
From source file:com.nttec.everychan.chans.dvach.DvachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addPasswordPreference(preferenceGroup); CheckBoxPreference onionPref = new LazyPreferences.CheckBoxPreference(context); onionPref.setTitle(R.string.pref_use_onion); onionPref.setSummary(R.string.pref_use_onion_summary); onionPref.setKey(getSharedKey(PREF_KEY_USE_ONION)); onionPref.setDefaultValue(false);//w ww . j ava 2s . c om onionPref.setDisableDependentsState(true); preferenceGroup.addPreference(onionPref); EditTextPreference domainPref = new EditTextPreference(context); domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT)); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.getEditText().setHint(DEFAULT_DOMAIN); domainPref.getEditText().setSingleLine(); domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); preferenceGroup.addPreference(domainPref); domainPref.setDependency(getSharedKey(PREF_KEY_USE_ONION)); addProxyPreferences(preferenceGroup); }
From source file:be.ppareit.swiftp.gui.PreferenceFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); Resources resources = getResources(); TwoStatePreference runningPref = findPref("running_switch"); updateRunningState();//from www .j av a 2s .c o m runningPref.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { startServer(); } else { stopServer(); } return true; }); PreferenceScreen prefScreen = findPref("preference_screen"); Preference marketVersionPref = findPref("market_version"); marketVersionPref.setOnPreferenceClickListener(preference -> { // start the market at our application Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse("market://details?id=be.ppareit.swiftp")); try { // this can fail if there is no market installed startActivity(intent); } catch (Exception e) { Cat.e("Failed to launch the market."); e.printStackTrace(); } return false; }); if (!App.isFreeVersion()) { prefScreen.removePreference(marketVersionPref); } updateLoginInfo(); EditTextPreference usernamePref = findPref("username"); usernamePref.setOnPreferenceChangeListener((preference, newValue) -> { String newUsername = (String) newValue; if (preference.getSummary().equals(newUsername)) return false; if (!newUsername.matches("[a-zA-Z0-9]+")) { Toast.makeText(getActivity(), R.string.username_validation_error, Toast.LENGTH_LONG).show(); return false; } stopServer(); return true; }); mPassWordPref = findPref("password"); mPassWordPref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); mAutoconnectListPref = findPref("autoconnect_preference"); mAutoconnectListPref.setOnPopulateListener(pref -> { Cat.d("autoconnect populate listener"); WifiManager wifiManager = (WifiManager) getActivity().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) { Cat.e("Unable to receive wifi configurations, bark at user and bail"); Toast.makeText(getActivity(), R.string.autoconnect_error_enable_wifi_for_access_points, Toast.LENGTH_LONG).show(); return; } CharSequence[] ssids = new CharSequence[configs.size()]; CharSequence[] niceSsids = new CharSequence[configs.size()]; for (int i = 0; i < configs.size(); ++i) { ssids[i] = configs.get(i).SSID; String ssid = configs.get(i).SSID; if (ssid.length() > 2 && ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } niceSsids[i] = ssid; } pref.setEntries(niceSsids); pref.setEntryValues(ssids); }); mAutoconnectListPref.setOnPreferenceClickListener(preference -> { Cat.d("Clicked"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) { new AlertDialog.Builder(getContext()).setTitle(R.string.request_coarse_location_dlg_title) .setMessage(R.string.request_coarse_location_dlg_message) .setPositiveButton(android.R.string.ok, (dialog, which) -> { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); }).setOnCancelListener(dialog -> { mAutoconnectListPref.getDialog().cancel(); }).create().show(); } else { requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, ACCESS_COARSE_LOCATION_REQUEST_CODE); } } } return false; }); EditTextPreference portnum_pref = findPref("portNum"); portnum_pref.setSummary(sp.getString("portNum", resources.getString(R.string.portnumber_default))); portnum_pref.setOnPreferenceChangeListener((preference, newValue) -> { String newPortnumString = (String) newValue; if (preference.getSummary().equals(newPortnumString)) return false; int portnum = 0; try { portnum = Integer.parseInt(newPortnumString); } catch (Exception e) { Cat.d("Error parsing port number! Moving on..."); } if (portnum <= 0 || 65535 < portnum) { Toast.makeText(getActivity(), R.string.port_validation_error, Toast.LENGTH_LONG).show(); return false; } preference.setSummary(newPortnumString); stopServer(); return true; }); Preference chroot_pref = findPref("chrootDir"); chroot_pref.setSummary(FsSettings.getChrootDirAsString()); chroot_pref.setOnPreferenceClickListener(preference -> { AlertDialog folderPicker = new FolderPickerDialogBuilder(getActivity(), FsSettings.getChrootDir()) .setSelectedButton(R.string.select, path -> { if (preference.getSummary().equals(path)) return; if (!FsSettings.setChrootDir(path)) return; // TODO: this is a hotfix, create correct resources, improve UI/UX final File root = new File(path); if (!root.canRead()) { Toast.makeText(getActivity(), "Notice that we can't read/write in this folder.", Toast.LENGTH_LONG).show(); } else if (!root.canWrite()) { Toast.makeText(getActivity(), "Notice that we can't write in this folder, reading will work. Writing in sub folders might work.", Toast.LENGTH_LONG).show(); } preference.setSummary(path); stopServer(); }).setNegativeButton(R.string.cancel, null).create(); folderPicker.show(); return true; }); final CheckBoxPreference wakelock_pref = findPref("stayAwake"); wakelock_pref.setOnPreferenceChangeListener((preference, newValue) -> { stopServer(); return true; }); final CheckBoxPreference writeExternalStorage_pref = findPref("writeExternalStorage"); String externalStorageUri = FsSettings.getExternalStorageUri(); if (externalStorageUri == null) { writeExternalStorage_pref.setChecked(false); } writeExternalStorage_pref.setOnPreferenceChangeListener((preference, newValue) -> { if ((boolean) newValue) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, ACTION_OPEN_DOCUMENT_TREE); return false; } else { FsSettings.setExternalStorageUri(null); return true; } }); ListPreference theme = findPref("theme"); theme.setSummary(theme.getEntry()); theme.setOnPreferenceChangeListener((preference, newValue) -> { theme.setSummary(theme.getEntry()); getActivity().recreate(); return true; }); Preference help = findPref("help"); help.setOnPreferenceClickListener(preference -> { Cat.v("On preference help clicked"); Context context = getActivity(); AlertDialog ad = new AlertDialog.Builder(context).setTitle(R.string.help_dlg_title) .setMessage(R.string.help_dlg_message).setPositiveButton(android.R.string.ok, null).create(); ad.show(); Linkify.addLinks((TextView) ad.findViewById(android.R.id.message), Linkify.ALL); return true; }); Preference about = findPref("about"); about.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), AboutActivity.class)); return true; }); }
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! *///w w w . j a v a 2 s.c o m 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:nya.miku.wishmaster.chans.krautchan.KrautModule.java
public void addKompturcodePreference(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); EditTextPreference kompturcodePreference = new EditTextPreference(context); kompturcodePreference.setTitle(R.string.kraut_prefs_kompturcode); kompturcodePreference.setDialogTitle(R.string.kraut_prefs_kompturcode); kompturcodePreference.setSummary(R.string.kraut_prefs_kompturcode_summary); kompturcodePreference.setKey(getSharedKey(PREF_KEY_KOMPTURCODE_COOKIE)); kompturcodePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override//w ww . j av a 2 s . co m public boolean onPreferenceChange(Preference preference, Object newValue) { setKompturcodeCookie((String) newValue); return true; } }); preferenceGroup.addPreference(kompturcodePreference); }
From source file:com.nttec.everychan.chans.dobrochan.DobroModule.java
private void addDomainPreferences(PreferenceGroup group) { Context context = group.getContext(); Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() { @Override//ww w. j av a 2 s. co m public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) { domain = (String) newValue; if (domain.length() == 0) domain = DEFAULT_DOMAIN; loadHanabiraCookie(); return true; } return false; } }; EditTextPreference domainPref = new EditTextPreference(context); domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT)); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.getEditText().setHint(DEFAULT_DOMAIN); domainPref.getEditText().setSingleLine(); domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); domainPref.setOnPreferenceChangeListener(updateDomainListener); group.addPreference(domainPref); }
From source file:com.nttec.everychan.chans.makaba.MakabaModule.java
/** ? ( .. https) */ private void addDomainPreferences(PreferenceGroup group) { Context context = group.getContext(); Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() { @Override/* w ww. j a v a2 s. c om*/ public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) { updateDomain((String) newValue, preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true)); return true; } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) { updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN), (boolean) newValue); return true; } return false; } }; PreferenceCategory domainCat = new PreferenceCategory(context); domainCat.setTitle(R.string.makaba_prefs_domain_category); group.addPreference(domainCat); EditTextPreference domainPref = new EditTextPreference(context); // domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT)); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.getEditText().setHint(DEFAULT_DOMAIN); domainPref.getEditText().setSingleLine(); domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); domainPref.setOnPreferenceChangeListener(updateDomainListener); domainCat.addPreference(domainPref); CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //? "? https" httpsPref.setTitle(R.string.pref_use_https); httpsPref.setSummary(R.string.pref_use_https_summary); httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA)); httpsPref.setDefaultValue(true); httpsPref.setOnPreferenceChangeListener(updateDomainListener); domainCat.addPreference(httpsPref); }