本文整理汇总了Java中android.support.v7.preference.Preference.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java Preference.getKey方法的具体用法?Java Preference.getKey怎么用?Java Preference.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.preference.Preference
的用法示例。
在下文中一共展示了Preference.getKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPreferenceTreeClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceTreeClick(Preference preference) {
switch (preference.getKey()) {
case RESET_SETUP_WIZARD:
LocalBroadcastUtils.send(activity, new Intent(ACTION_FLOAT_VIEW_SERVICE_STOP));
intentGuideActivity(PAGE_WELCOME, MODE_NONE);
break;
case HISTORY:
ActivityUtils.startActivity(activity, HistoryActivity.class);
break;
case ABOUT:
ActivityUtils.startActivity(activity, AboutActivity.class);
break;
}
return super.onPreferenceTreeClick(preference);
}
示例2: setPreferenceSummary
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
private void setPreferenceSummary(Preference preference, Object value) {
String stringValue = value.toString();
String key = preference.getKey();
if (preference instanceof ListPreference) {
/* For list preferences, look up the correct display value in */
/* the preference's 'entries' list (since they have separate labels/values). */
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(stringValue);
if (prefIndex >= 0) {
preference.setSummary(listPreference.getEntries()[prefIndex]);
}
} else {
// For other preferences, set the summary to the value's simple string representation.
preference.setSummary(stringValue);
}
}
示例3: bindPreferenceSummaryToValue
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key,
new HashSet<>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof ColorPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((ColorPreference) preference).getColor());
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例4: onPreferenceClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) {
case PrefUtils.THEME:
showThemeChooser();
return true;
case PrefUtils.LANGUAGE:
showLanguageList();
return true;
case PrefUtils.LOGOUT:
logout();
return true;
case PrefUtils.START_PAGE:
showChooseStartPageDialog();
return true;
}
return false;
}
示例5: onPreferenceClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceClick(Preference preference) {
Intent activityIntent = new Intent(getActivity(), WebViewExtrasActivity.class);
switch (preference.getKey()) {
case "about":
activityIntent.putExtra(WebViewExtrasActivity.EXTRA_ASSET_FILE, "about.html");
break;
case "help":
activityIntent.putExtra(WebViewExtrasActivity.EXTRA_ASSET_FILE, "help.html");
break;
}
startActivity(activityIntent);
return true;
}
示例6: bindPreferenceSummaryToValue
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
final String key = preference.getKey();
if (preference instanceof MultiSelectListPreference) {
Set<String> summary = SharedPreferencesCompat.getStringSet(
PreferenceManager.getDefaultSharedPreferences(preference.getContext()),
key, new HashSet<String>());
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, summary);
} else if (preference instanceof SeekBarPreference) {
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, ((SeekBarPreference) preference).getValue());
} else {
String value = PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(key, "");
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, value);
}
}
示例7: onPreferenceTreeClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceTreeClick(Preference preference) {
switch (preference.getKey()) {
case KEY_CLEAR_DISK_CACHE:
onClearDiskCachePreferenceClicked();
return true;
case KEY_URI_OVERRIDE:
onUriOverrideClicked();
return true;
default:
return super.onPreferenceTreeClick(preference);
}
}
示例8: onPreferenceChange
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
switch (preference.getKey()) {
case "dark_theme": {
Colorful.config(getContext())
.dark(((boolean) o))
.apply();
getActivity().recreate();
break;
}
case "animations": {
Media.setUseAnimations((boolean) o);
break;
}
case "staggered": {
Media.setStaggered((boolean) o);
}
case "primary" : {
getActivity().recreate();
break;
}
case "accent" : {
getActivity().recreate();
break;
}
}
return true;
}
示例9: onPreferenceChange
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
boolean checked = (boolean) o;
String key = preference.getKey();
switch (key) {
case KEY_FORCE_ENGLISH:
if (!checked) {
Utils.setLocale(Resources.getSystem().getConfiguration().locale.getLanguage(), getActivity());
}
case KEY_DARK_THEME:
getActivity().finish();
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
case KEY_MATERIAL_ICON:
Utils.setStartActivity(checked, getActivity());
return true;
case KEY_HIDE_BANNER:
if (!Utils.DONATED) {
ViewUtils.dialogDonate(getActivity()).show();
return false;
}
return true;
default:
if (key.equals(KEY_SECTIONS_ICON) || key.endsWith("_enabled")) {
if (key.equals(KEY_SECTIONS_ICON) && !Utils.DONATED) {
ViewUtils.dialogDonate(getActivity()).show();
return false;
}
Prefs.saveBoolean(key, checked, getActivity());
((NavigationActivity) getActivity()).appendFragments();
return true;
}
break;
}
return false;
}
示例10: onPreferenceDisplayDialog
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceDisplayDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) {
final String key = preference.getKey();
DialogFragment f;
if (preference instanceof ColorPreference) {
f = XpColorPreferenceDialogFragment.newInstance(key);
} else {
return false;
}
f.setTargetFragment(preferenceFragmentCompat, 0);
f.show(this.getSupportFragmentManager(), key);
return true;
}
示例11: onPreferenceChange
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
switch (preference.getKey()) {
case ENABLE_FLOAT_WINDOW:
if (Settings.getString(Settings.Mode.SELECTION, Settings.Mode.NONE).equals(Settings.Mode.NONE)) {
ActivityCollector.getActivityCollector().removeAllActivity();
intentGuideActivity(PAGE_WELCOME, MODE_NONE);
} else if ((boolean) newValue) {
activity.startService(new Intent(activity, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SERVICE_START));
} else {
LocalBroadcastUtils.send(activity, new Intent(ACTION_FLOAT_VIEW_SERVICE_STOP));
}
break;
case BOOT_COMPLETED:
Settings.putBoolean(BOOT_COMPLETED, (boolean) newValue);
break;
case OPEN_MAIN_ACTIVITY_WHEN_QUICK_START_OR_QUICK_STOP:
Settings.putBoolean(OPEN_MAIN_ACTIVITY_WHEN_QUICK_START_OR_QUICK_STOP, (boolean) newValue);
break;
case GESTURE_CLICK:
Settings.putString(GESTURE_CLICK, (String) newValue);
break;
case GESTURE_LONG_PRESS:
Settings.putString(GESTURE_LONG_PRESS, (String) newValue);
break;
case WORKING_MODE:
switch ((String) newValue) {
case Settings.Mode.ROOT:
intentGuideActivity(PAGE_GETTING_MODE_PERMISSION, MODE_ROOT);
break;
case Settings.Mode.ACCESSIBILITY_SERVICE:
intentGuideActivity(PAGE_GETTING_MODE_PERMISSION, MODE_ACCESSIBILITY_SERVICE);
break;
case Settings.Mode.NONE:
intentGuideActivity(PAGE_WELCOME, MODE_NONE);
break;
}
break;
}
return true;
}
示例12: onPreferenceTreeClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceTreeClick(Preference preference) {
SettingsHelper settingsHelper = new SettingsHelper(getContext());
String key = preference.getKey();
if (key.equals(getString(R.string.about_dialog))) {
DialogHelper dialogHelper = new DialogHelper(getContext());
dialogHelper.buildAboutDialog();
}
if (key.equals((getString(R.string.pref_recycler_left_color)))) {
settingsHelper.setColorForViews(SettingsHelper.KEY_LEFT_LIST);
settingsHelper.setPref(SettingsHelper.PREF_LEFT_LIST);
}
if (key.equals(getString(R.string.pref_recycler_right_color))) {
settingsHelper.setColorForViews(SettingsHelper.KEY_RIGHT_LIST);
settingsHelper.setPref(SettingsHelper.PREF_RIGHT_LIST);
}
if (key.equals((getString(R.string.pref_search_bar_color)))) {
settingsHelper.setColorForViews(SettingsHelper.KEY_SEARCHBAR);
settingsHelper.setPref(SettingsHelper.PREF_SEARCHBAR);
}
if (key.equals((getString(R.string.pref_search_list_color)))) {
settingsHelper.setColorForViews(SettingsHelper.KEY_SEARCHLIST);
settingsHelper.setPref(SettingsHelper.PREF_SEARCHLIST);
}
if (key.equals((getString(R.string.pref_menu_fragment_color)))) {
settingsHelper.setColorForViews(SettingsHelper.KEY_MENU);
settingsHelper.setPref(SettingsHelper.PREF_MENU);
}
if (key.equals((getString(R.string.seekbar_size_main_elems)))) {
settingsHelper.setSeekbarEndpointValue(SettingsHelper.KEY_SEEKBAR_SIZE_MAIN,
getString(R.string.seekbar_main_title), 400);
settingsHelper.setPref(SettingsHelper.PREF_SEEKBAR_SIZE_MAIN);
}
if (key.equals((getString(R.string.seekbar_alpha_main_elems)))) {
settingsHelper.setSeekbarEndpointValue(SettingsHelper.KEY_SEEKBAR_ALPHA_MAIN,
getString(R.string.seekbar_main_title), 10);
settingsHelper.setPref(SettingsHelper.PREF_SEEKBAR_ALPHA_MAIN);
}
if (key.equals((getString(R.string.seekbar_alpha_search_button)))) {
settingsHelper.setSeekbarEndpointValue(SettingsHelper.KEY_SEEKBAR_ALPHA_SEARCH_BUTTON,
getString(R.string.seekbar_main_title), 10);
settingsHelper.setPref(SettingsHelper.PREF_SEEKBAR_ALPHA_SEARCH_BUTTON);
}
return super.onPreferenceTreeClick(preference);
}
示例13: onPreferenceChange
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
boolean checked = (boolean) o;
String key = preference.getKey();
switch (key) {
case KEY_UPDATE_NOTIFICATION:
Prefs.saveBoolean("show_update_notif", checked, getActivity());
return true;
case KEY_FORCE_ENGLISH:
if (!checked) {
Utils.setLocale(Resources.getSystem().getConfiguration().locale.getLanguage(), getActivity());
}
case KEY_DARK_THEME:
getActivity().finish();
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
/*
case KEY_MATERIAL_ICON:
Utils.setStartActivity(checked, getActivity());
return true;
*/
case KEY_HIDE_BANNER:
if (!Utils.DONATED) {
ViewUtils.dialogDonate(getActivity()).show();
return false;
}
return true;
default:
if (key.equals(KEY_SECTIONS_ICON) || key.endsWith("_enabled")) {
if (key.equals(KEY_SECTIONS_ICON) && !Utils.DONATED) {
ViewUtils.dialogDonate(getActivity()).show();
return false;
}
Prefs.saveBoolean(key, checked, getActivity());
((NavigationActivity) getActivity()).appendFragments();
return true;
}
break;
}
return false;
}
示例14: onPreferenceClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) {
// case PREFERENCE_ICONS_NOTE:
// break;
case PREFERENCE_ICONS_AUTHOR:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_icons_summary_author));
break;
case PREFERENCE_ICONS_CONTACT:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_icons_summary_contact));
break;
case PREFERENCE_ICONS_TODO_1:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_icons_summary_todo_1));
break;
case PREFERENCE_ICONS_COPYRIGHT:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_icons_summary_copyright));
break;
case PREFERENCE_SUPPORT_DONATE:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_support_summary_donate));
break;
case PREFERENCE_SUPPORT_TODO_1:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_support_summary_todo_1));
break;
case PREFERENCE_SUPPORT_SPONSORS:
showDonate();
break;
// case PREFERENCE_APP_APP:
// executeCode(preference.getTitle().toString(), preference.getSummary().toString());
// break;
case PREFERENCE_APP_TODO_1:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_app_summary_todo_1));
break;
case PREFERENCE_APP_DASHBOARD:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_app_summary_dashboard));
break;
case PREFERENCE_DEV_STATS:
enterStats();
break;
case PREFERENCE_DEV_QUERY:
executeCode(preference.getTitle().toString(),
getString(R.string.preference_dev_summary_query));
break;
}
return true;
}
示例15: onPreferenceTreeClick
import android.support.v7.preference.Preference; //导入方法依赖的package包/类
@Override
public boolean onPreferenceTreeClick(Preference preference) {
View preferenceView = getListView().findViewHolderForAdapterPosition(preference.getOrder()).itemView;
switch (preference.getKey()) {
case Common.PREF_LOCATION_UPDATE_INTERVAL:
ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setAnchorView(preferenceView);
listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), android.support.design.R.layout.support_simple_spinner_dropdown_item, getResources().getStringArray(R.array.location_update_interval_summaries)));
listPopupWindow.setContentWidth(getResources().getDimensionPixelSize(R.dimen.popup_window_width));
listPopupWindow.setHorizontalOffset(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin));
listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
Log.d("Selected", String.valueOf(position));
prefs.edit().putInt(Common.PREF_LOCATION_UPDATE_INTERVAL,
getResources().getIntArray(R.array.location_update_interval_values)[position]).apply();
listPopupWindow.dismiss();
updatePreferenceSummaries();
updateLocationTracker();
});
listPopupWindow.show();
return true;
case Common.PREF_RESET_HOST_MISMATCHES:
prefs.edit().remove(Common.PREF_ALLOWED_HOST_MISMATCHES_KEY).apply();
Toast.makeText(getActivity(), R.string.toast_ignored_ssl_mismatches_cleared, Toast.LENGTH_SHORT).show();
updatePreferenceSummaries();
return true;
case Common.HELP_TRANSLATE:
CustomTabsSession session = ((SettingsActivity) getActivity()).getCustomTabsSession();
if (session != null) {
@SuppressWarnings("deprecation") CustomTabsIntent intent = new CustomTabsIntent.Builder(session)
.setShowTitle(true)
.enableUrlBarHiding()
.setToolbarColor(getResources().getColor(R.color.primary))
.build();
intent.launchUrl(getActivity(), Uri.parse(Common.CROWDIN_URL));
}
return true;
default:
return super.onPreferenceTreeClick(preference);
}
}