List of usage examples for android.preference EditTextPreference setSummary
public void setSummary(CharSequence summary)
From source file:com.hichinaschool.flashcards.anki.Preferences.java
private void updateEditTextPreference(String key) { EditTextPreference pref = (EditTextPreference) getPreferenceScreen().findPreference(key); String entry;/*w w w . j a va 2 s .co m*/ try { entry = pref.getText(); } catch (NullPointerException e) { Log.e(AnkiDroidApp.TAG, "Error getting set preference value of " + key + ": " + e); entry = "?"; } if (mListsToUpdate.containsKey(key)) { pref.setSummary(replaceString(mListsToUpdate.get(key), entry)); } else { String oldsum = (String) pref.getSummary(); if (oldsum.contains("XXX")) { mListsToUpdate.put(key, oldsum); pref.setSummary(replaceString(oldsum, entry)); } else { pref.setSummary(entry); } } }
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()); }// w ww. j a va 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)); } 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()); }/*from w w w. j ava 2 s.com*/ 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:it.feio.android.omninotes.SettingsFragment.java
@SuppressWarnings("deprecation") @Override//from w w w.j a va 2 s . c om public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), this::importNotes); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { BaseActivity.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { OmniNotes.updateLanguage(getActivity(), value.toString()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName; } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }
From source file:com.dycody.android.idealnote.SettingsFragment.java
@SuppressWarnings("deprecation") @Override//w w w . j ava2 s . co m public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { importNotes(); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { PasswordHelper.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { IdealNote.updateLanguage(getActivity(), value.toString()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName + getString(R.string.version_postfix); } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }
From source file:org.linphone.SettingsFragment.java
private void setPreferenceDefaultValueAndSummary(int pref, String value) { if (value != null) { EditTextPreference etPref = (EditTextPreference) findPreference(getString(pref)); if (etPref != null) { etPref.setText(value);/*w ww.j a v a 2s . com*/ etPref.setSummary(value); } } }
From source file:org.linphone.SettingsFragment.java
private void initNetworkSettings() { initMediaEncryptionPreference(/*from w ww .j a v a 2s. c om*/ (ListPreference) findPreference(getString(R.string.pref_media_encryption_key))); ((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))) .setChecked(mPrefs.isWifiOnlyEnabled()); // Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key)); CheckBoxPreference upnp = (CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key)); ice.setChecked(mPrefs.isIceEnabled()); if (mPrefs.isIceEnabled()) { upnp.setEnabled(false); } else { upnp.setChecked(mPrefs.isUpnpEnabled()); if (mPrefs.isUpnpEnabled()) { ice.setEnabled(false); } } CheckBoxPreference randomPort = (CheckBoxPreference) findPreference( getString(R.string.pref_transport_use_random_ports_key)); randomPort.setChecked(mPrefs.isUsingRandomPort()); // Disable sip port choice if port is random EditTextPreference sipPort = (EditTextPreference) findPreference(getString(R.string.pref_sip_port_key)); sipPort.setEnabled(!randomPort.isChecked()); sipPort.setSummary(mPrefs.getSipPort()); sipPort.setText(mPrefs.getSipPort()); EditTextPreference stun = (EditTextPreference) findPreference(getString(R.string.pref_stun_server_key)); stun.setSummary(mPrefs.getStunServer()); stun.setText(mPrefs.getStunServer()); ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))) .setChecked(mPrefs.isPushNotificationEnabled()); ((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6()); }
From source file:github.popeen.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }//from ww w. j a v a 2s. c om serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }
From source file:github.daneren2005.dsub.fragments.SettingsFragment.java
private PreferenceScreen expandServer(final int instance) { final PreferenceScreen screen = this.getPreferenceManager().createPreferenceScreen(context); screen.setTitle(R.string.settings_server_unused); screen.setKey(Constants.PREFERENCES_KEY_SERVER_KEY + instance); final EditTextPreference serverNamePreference = new EditTextPreference(context); serverNamePreference.setKey(Constants.PREFERENCES_KEY_SERVER_NAME + instance); serverNamePreference.setDefaultValue(getResources().getString(R.string.settings_server_unused)); serverNamePreference.setTitle(R.string.settings_server_name); serverNamePreference.setDialogTitle(R.string.settings_server_name); if (serverNamePreference.getText() == null) { serverNamePreference.setText(getResources().getString(R.string.settings_server_unused)); }/* w ww .java2 s .c om*/ serverNamePreference.setSummary(serverNamePreference.getText()); final EditTextPreference serverUrlPreference = new EditTextPreference(context); serverUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_URL + instance); serverUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverUrlPreference.setDefaultValue("http://yourhost"); serverUrlPreference.setTitle(R.string.settings_server_address); serverUrlPreference.setDialogTitle(R.string.settings_server_address); if (serverUrlPreference.getText() == null) { serverUrlPreference.setText("http://yourhost"); } serverUrlPreference.setSummary(serverUrlPreference.getText()); screen.setSummary(serverUrlPreference.getText()); final EditTextPreference serverLocalNetworkSSIDPreference = new EditTextPreference(context) { @Override protected void onAddEditTextToDialogView(View dialogView, final EditText editText) { super.onAddEditTextToDialogView(dialogView, editText); ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0); Button defaultButton = new Button(getContext()); defaultButton.setText(internalSSIDDisplay); defaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editText.setText(internalSSID); } }); root.addView(defaultButton); } }; serverLocalNetworkSSIDPreference.setKey(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance); serverLocalNetworkSSIDPreference.setTitle(R.string.settings_server_local_network_ssid); serverLocalNetworkSSIDPreference.setDialogTitle(R.string.settings_server_local_network_ssid); final EditTextPreference serverInternalUrlPreference = new EditTextPreference(context); serverInternalUrlPreference.setKey(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance); serverInternalUrlPreference.getEditText().setInputType(InputType.TYPE_TEXT_VARIATION_URI); serverInternalUrlPreference.setDefaultValue(""); serverInternalUrlPreference.setTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setDialogTitle(R.string.settings_server_internal_address); serverInternalUrlPreference.setSummary(serverInternalUrlPreference.getText()); final EditTextPreference serverUsernamePreference = new EditTextPreference(context); serverUsernamePreference.setKey(Constants.PREFERENCES_KEY_USERNAME + instance); serverUsernamePreference.setTitle(R.string.settings_server_username); serverUsernamePreference.setDialogTitle(R.string.settings_server_username); final EditTextPreference serverPasswordPreference = new EditTextPreference(context); serverPasswordPreference.setKey(Constants.PREFERENCES_KEY_PASSWORD + instance); serverPasswordPreference.getEditText() .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); serverPasswordPreference.setSummary("***"); serverPasswordPreference.setTitle(R.string.settings_server_password); final CheckBoxPreference serverTagPreference = new CheckBoxPreference(context); serverTagPreference.setKey(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance); serverTagPreference.setChecked(Util.isTagBrowsing(context, instance)); serverTagPreference.setSummary(R.string.settings_browse_by_tags_summary); serverTagPreference.setTitle(R.string.settings_browse_by_tags); serverPasswordPreference.setDialogTitle(R.string.settings_server_password); final CheckBoxPreference serverSyncPreference = new CheckBoxPreference(context); serverSyncPreference.setKey(Constants.PREFERENCES_KEY_SERVER_SYNC + instance); serverSyncPreference.setChecked(Util.isSyncEnabled(context, instance)); serverSyncPreference.setSummary(R.string.settings_server_sync_summary); serverSyncPreference.setTitle(R.string.settings_server_sync); final Preference serverOpenBrowser = new Preference(context); serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER); serverOpenBrowser.setPersistent(false); serverOpenBrowser.setTitle(R.string.settings_server_open_browser); serverOpenBrowser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { openInBrowser(instance); return true; } }); Preference serverRemoveServerPreference = new Preference(context); serverRemoveServerPreference.setKey(Constants.PREFERENCES_KEY_SERVER_REMOVE + instance); serverRemoveServerPreference.setPersistent(false); serverRemoveServerPreference.setTitle(R.string.settings_servers_remove); serverRemoveServerPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.confirmDialog(context, R.string.common_delete, screen.getTitle().toString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Reset values to null so when we ask for them again they are new serverNamePreference.setText(null); serverUrlPreference.setText(null); serverUsernamePreference.setText(null); serverPasswordPreference.setText(null); // Don't use Util.getActiveServer since it is 0 if offline int activeServer = Util.getPreferences(context) .getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); for (int i = instance; i <= serverCount; i++) { Util.removeInstanceName(context, i, activeServer); } serverCount--; SharedPreferences.Editor editor = settings.edit(); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.commit(); removeCurrent(); SubsonicFragment parentFragment = context.getCurrentFragment(); if (parentFragment instanceof SettingsFragment) { SettingsFragment serverSelectionFragment = (SettingsFragment) parentFragment; serverSelectionFragment.checkForRemoved(); } } }); return true; } }); Preference serverTestConnectionPreference = new Preference(context); serverTestConnectionPreference.setKey(Constants.PREFERENCES_KEY_TEST_CONNECTION + instance); serverTestConnectionPreference.setPersistent(false); serverTestConnectionPreference.setTitle(R.string.settings_test_connection_title); serverTestConnectionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { testConnection(instance); return false; } }); screen.addPreference(serverNamePreference); screen.addPreference(serverUrlPreference); screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverLocalNetworkSSIDPreference); screen.addPreference(serverUsernamePreference); screen.addPreference(serverPasswordPreference); screen.addPreference(serverTagPreference); screen.addPreference(serverSyncPreference); screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverOpenBrowser); screen.addPreference(serverRemoveServerPreference); return screen; }