本文整理了Java中androidx.preference.Preference
类的一些代码示例,展示了Preference
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preference
类的具体详情如下:
包路径:androidx.preference.Preference
类名称:Preference
暂无
代码示例来源:origin: cSploit/android
mSavePath.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
代码示例来源:origin: cSploit/android
private void startDirectoryPicker(Preference preference) {
Intent i = new Intent(getActivity(), DirectoryPicker.class);
i.putExtra(DirectoryPicker.AFFECTED_PREF, preference.getKey());
startActivityForResult(i, DirectoryPicker.PICK_DIRECTORY);
}
代码示例来源:origin: guardianproject/haven
findPreference(PreferenceManager.SMS_NUMBER).setOnPreferenceClickListener(preference -> {
if (preferences.getSmsNumber().isEmpty()) {
((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).setText(getCountryCode());
findPreference(PreferenceManager.REGISTER_SIGNAL).setOnPreferenceClickListener(preference -> {
if (preferences.getSignalUsername() == null) {
((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).setText(getCountryCode());
findPreference(PreferenceManager.SMS_NUMBER).setSummary(preferences.getSmsNumber().trim());
} else {
findPreference(PreferenceManager.SMS_NUMBER).setSummary(R.string.sms_dialog_summary);
findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
} else {
findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint);
findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.bullets);
} else {
findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.remote_access_credential_hint);
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(signalNum);
} else {
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc);
findPreference(PreferenceManager.NOTIFICATION_TIME).setSummary(preferences.getNotificationTimeMs()/60000 + " " + getString(R.string.minutes));
findPreference(PreferenceManager.HEARTBEAT_MONITOR_DELAY).setSummary(preferences.getHeartbeatNotificationTimeMs() / 60000 + " " + getString(R.string.minutes));
findPreference(PreferenceManager.HEARTBEAT_MONITOR_DELAY).setSummary(R.string.heartbeat_time_dialog);
代码示例来源:origin: cSploit/android
mRubyDir.setDefaultValue(System.getDefaultRubyPath());
mRubyDir.setOnPreferenceClickListener(directoryPickerWithDefaultPath);
mMsfDir.setDefaultValue(System.getDefaultMsfPath());
mMsfDir.setOnPreferenceClickListener(directoryPickerWithDefaultPath);
mWipeMSF.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
代码示例来源:origin: proninyaroslav/libretorrent
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
SharedPreferences pref = SettingsManager.getPreferences(getActivity());
if (preference.getKey().equals(getString(R.string.pref_key_streaming_hostname))) {
pref.edit().putString(preference.getKey(), (String)newValue).apply();
preference.setSummary((String)newValue);
} else if (preference.getKey().equals(getString(R.string.pref_key_streaming_port))) {
int value = SettingsManager.Default.streamingPort;
if (!TextUtils.isEmpty((String)newValue))
value = Integer.parseInt((String)newValue);
pref.edit().putInt(preference.getKey(), value).apply();
preference.setSummary(Integer.toString(value));
}
return true;
}
}
代码示例来源:origin: 8enet/AppOpsX
findPreference("ignore_premission").setOnPreferenceClickListener(this);
findPreference("show_sysapp").setOnPreferenceClickListener(this);
mUseAdb.setOnPreferenceClickListener(this);
findPreference("allow_bg_remote").setOnPreferenceClickListener(this);
findPreference("project").setOnPreferenceClickListener(this);
findPreference("opensource_licenses").setOnPreferenceClickListener(this);
findPreference("help").setOnPreferenceClickListener(this);
findPreference("translate").setOnPreferenceClickListener(this);
findPreference("shell_start").setOnPreferenceClickListener(this);
version.setSummary(BuildConfig.VERSION_NAME);
version.setOnPreferenceClickListener(this);
appLanguage.setOnPreferenceClickListener(this);
appLanguage.setSummary(
getResources().getStringArray(R.array.languages)[LangHelper.getLocalIndex(getContext())]);
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
代码示例来源:origin: guardianproject/haven
private void checkSignalUsername() {
if (checkValidString(preferences.getSignalUsername())) {
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(preferences.getSignalUsername().trim());
((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).setText(preferences.getSignalUsername().trim());
} else {
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.signal_dialog_summary);
}
}
代码示例来源:origin: jruesga/rview
private void configureSearch() {
mSearchHistoryClear = findPreference(PREF_ACCOUNT_SEARCH_CLEAR);
mSearchHistoryClear.setOnPreferenceClickListener(this);
mSearchHistoryClear.setEnabled(Preferences.hasAccountSearchHistory(getContext(), mAccount));
}
代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD
findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this);
findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);
findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
} else {
((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);
} else {
mFingerprint = findPreference(KEY_FINGERPRINT);
mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty());
代码示例来源:origin: proninyaroslav/libretorrent
private void bindOnPreferenceChangeListener(Preference preference)
{
preference.setOnPreferenceChangeListener(this);
}
代码示例来源:origin: bfabiszewski/ulogger-android
/**
* Set various listeners
*/
private void setListeners() {
final Preference prefLiveSync = findPreference(KEY_LIVE_SYNC);
final Preference prefUsername = findPreference(KEY_USERNAME);
final Preference prefPass = findPreference(KEY_PASS);
final Preference prefHost = findPreference(KEY_HOST);
// on change listeners
if (prefLiveSync != null) {
prefLiveSync.setOnPreferenceChangeListener(liveSyncChanged);
}
if (prefUsername != null) {
prefUsername.setOnPreferenceChangeListener(serverSetupChanged);
}
if (prefPass != null) {
prefPass.setOnPreferenceChangeListener(serverSetupChanged);
}
if (prefHost != null) {
prefHost.setOnPreferenceChangeListener(serverSetupChanged);
}
// on click listeners
if (prefUsername != null) {
prefUsername.setOnPreferenceClickListener(serverSetupClicked);
}
if (prefHost != null) {
prefHost.setOnPreferenceClickListener(serverSetupClicked);
}
}
代码示例来源:origin: andstatus/andstatus
@Override
public boolean onPreferenceTreeClick(Preference preference) {
switch (preference.getKey()) {
case MyPreferences.KEY_USE_EXTERNAL_STORAGE_NEW:
if (CheckBoxPreference.class.isInstance(preference)) {
preference.setEnabled(false);
DialogFactory.showYesCancelDialog(this, R.string.check_and_fix_data,
R.string.full_check, ActivityRequestCode.CHECK_DATA_INCLUDE_LONG);
代码示例来源:origin: cSploit/android
private void onMsfPathChanged() {
measureMsfSize();
boolean haveMsf = false;
File dir;
File[] content;
if ((dir = new File(System.getRubyPath())).isDirectory() ||
(dir = new File(System.getMsfPath())).isDirectory()) {
content = dir.listFiles();
haveMsf = content != null && content.length > 2;
}
mWipeMSF.setEnabled(haveMsf);
}
代码示例来源:origin: KDE/kdeconnect-android
private void updateFilePickerStatus(boolean enabled) {
filePicker.setEnabled(enabled);
String path = PreferenceManager
.getDefaultSharedPreferences(requireContext())
.getString(PREFERENCE_DESTINATION, null);
if (enabled && path != null) {
filePicker.setSummary(Uri.parse(path).getPath());
} else {
filePicker.setSummary(getDefaultDestinationDirectory().getAbsolutePath());
}
}
代码示例来源:origin: 8enet/AppOpsX
@Override
public boolean onPreferenceClick(Preference preference) {
String key = preference.getKey();
if ("opensource_licenses".equals(key)) {
Intent intent = new Intent(getContext(), HtmlActionActivity.class);
intent.putExtra(Intent.EXTRA_TITLE, preference.getTitle());
intent.putExtra(HtmlActionActivity.EXTRA_URL, "file:///android_res/raw/licenses.html");
getActivity().startActivity(intent);
} else if ("help".equals(key)) {
Intent intent = new Intent(getContext(), HtmlActionActivity.class);
intent.putExtra(Intent.EXTRA_TITLE, preference.getTitle());
intent.putExtra(HtmlActionActivity.EXTRA_URL, "file:///android_res/raw/help.html");
getActivity().startActivity(intent);
} else if ("pref_app_language".equals(key)) {
showLanguageDialog(preference);
} else if ("shell_start".equals(key)){
showShellStart();
}
return false;
}
}
代码示例来源:origin: KDE/kdeconnect-android
@Override
public boolean onPreferenceTreeClick(Preference preference) {
/*
* There is no RingtonePreference in support library nor androidx, this is the workaround proposed here:
* https://issuetracker.google.com/issues/37057453
*/
if (preference.hasKey() && preference.getKey().equals(preferenceKeyRingtone)) {
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI);
String existingValue = sharedPreferences.getString(preferenceKeyRingtone, null);
if (existingValue != null) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue));
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_RINGTONE_URI);
}
startActivityForResult(intent, REQUEST_CODE_SELECT_RINGTONE);
return true;
}
return super.onPreferenceTreeClick(preference);
}
代码示例来源:origin: andstatus/andstatus
@Override
public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
final Bundle args = pref.getExtras();
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey());
MySettingsFragment fragment = new MySettingsFragment();
fragment.setArguments(args);
fragment.setTargetFragment(caller, 0);
getSupportFragmentManager().beginTransaction()
.replace(R.id.settings_container, fragment, pref.getKey())
.addToBackStack(pref.getKey())
.commit();
return true;
}
代码示例来源:origin: jaredrummler/ColorPicker
@Override public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
ColorPanelView preview = (ColorPanelView) holder.itemView.findViewById(R.id.cpv_preference_preview_color_panel);
if (preview != null) {
preview.setColor(color);
}
}
代码示例来源:origin: 8enet/AppOpsX
@Override
public void onClick(DialogInterface dialog, int which) {
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
.putInt(preference.getKey(), selected[0]).apply();
mPrefAppSort.setSummary(getString(R.string.app_sort_type_summary,
getResources().getStringArray(R.array.app_sort_type)[selected[0]]));
}
});
代码示例来源:origin: guardianproject/haven
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && data != null) {
String onionHost = data.getStringExtra("hs_host");
if (checkValidString(onionHost)) {
preferences.setRemoteAccessOnion(onionHost.trim());
((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).setText(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
if (checkValidString(preferences.getRemoteAccessOnion())) {
findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
} else {
findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!