本文整理汇总了Java中android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences方法的典型用法代码示例。如果您正苦于以下问题:Java PreferenceManager.getDefaultSharedPreferences方法的具体用法?Java PreferenceManager.getDefaultSharedPreferences怎么用?Java PreferenceManager.getDefaultSharedPreferences使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.preference.PreferenceManager
的用法示例。
在下文中一共展示了PreferenceManager.getDefaultSharedPreferences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showSortingDialog
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
public static void showSortingDialog(final Fragment fragment) {
RadioDialogCallback callback = new RadioDialogCallback() {
@Override
public void which(int position) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.getContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(KEY_PREF_SORTING, position);
editor.apply();
SortingDialogCallback fragmentCallback = (SortingDialogCallback) fragment;
fragmentCallback.sortBy(Sortation.parse(position));
}
};
CharSequence[] items = new CharSequence[]{
getString(fragment, R.string.sort_most_used),
getString(fragment, R.string.sort_last_change),
getString(fragment, R.string.sort_creation),
getString(fragment, R.string.sort_alphabetically)
};
showRadioDialog(fragment.getContext(), getString(fragment, R.string.sort_dialog), items, callback);
}
示例2: onDonePressed
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public void onDonePressed(Fragment currentFragment) {
super.onDonePressed(currentFragment);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
switch (type) {
case KEY_PREVIEW:
editor.putBoolean(KEY_PREF_PREVIEW_INTRO_SHOWN, true);
break;
case KEY_TODO_LIST:
editor.putBoolean(KEY_PREF_TODO_LIST_INTRO_SHOWN, true);
break;
default:
throw new IllegalArgumentException(String.format("Unknown type %s", type));
}
editor.apply();
startActivity(MainActivity.newInstace(this, type, uuid, title));
finish();
}
示例3: isThemeNightMode
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public boolean isThemeNightMode() {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return DisplayPreferenceUtilities.getDisplayPreference(SettingsFragment.KEY_IS_THEME_NIGHT_MODE,
AppConstants.DISPLAY_PREFERENCES_DEFAULTS.IS_THEME_NIGHT_MODE,
defaultSharedPreferences,
mUserDataDBHelper);
}
示例4: saveWidgetToSharedPrefs
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
private void saveWidgetToSharedPrefs(int appWidgetId, String uuid) {
// add widget id's to sharedPrefs
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(KEY_PREF_WIDGET_REALM_PREFIX + appWidgetId,
sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM));
editor.putString(KEY_PREF_WIDGET_UUID_PREFIX + appWidgetId, uuid);
editor.apply();
}
示例5: onDeleted
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove((KEY_PREF_WIDGET_REALM_PREFIX + appWidgetId));
editor.remove(KEY_PREF_WIDGET_UUID_PREFIX + appWidgetId);
editor.apply();
}
super.onDeleted(context, appWidgetIds);
}
示例6: setThemeNightMode
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public void setThemeNightMode(boolean isDesiredThemeLight) {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
DisplayPreferenceUtilities.setDisplayPreference(SettingsFragment.KEY_IS_THEME_NIGHT_MODE,
isDesiredThemeLight,
defaultSharedPreferences, mUserDataDBHelper);
restartOnThemeChange();
}
示例7: loadValues
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
public void loadValues(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
for (String key: mKeyList) {
String value = sharedPreferences.getString(key, "");
// Keep default value if the preference is not set
if (value.isEmpty())
continue;
updateValue(key, value);
}
}
示例8: ensureShown
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
public static void ensureShown(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean isNotificationShown = prefs.getBoolean(SettingsFragment.KEY_NOTIFICATION_ENABLED, false);
if (isNotificationShown) {
ToggleNotification.show(context);
} else {
ToggleNotification.cancel(context);
}
}
示例9: setPinchZoom
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
public void setPinchZoom(boolean checked) {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
DisplayPreferenceUtilities.setDisplayPreference(SettingsFragment.KEY_IS_PINCH_ZOOM_ON,
checked,
defaultSharedPreferences, mUserDataDBHelper);
for (DisplayPrefChangeListener listener : displayPrefChangeListeners) {
listener.setPinchZoom(checked);
}
}
示例10: setupSharedPreferences
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
private void setupSharedPreferences() {
// Get all of the values from shared preferences to set it up
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mVisualizerView.setShowBass(sharedPreferences.getBoolean(getString(R.string.pref_show_bass_key),
getResources().getBoolean(R.bool.pref_show_bass_default)));
mVisualizerView.setShowMid(sharedPreferences.getBoolean(getString(R.string.pref_show_mid_key),
getResources().getBoolean(R.bool.pref_show_mid_default)));
mVisualizerView.setShowTreble(sharedPreferences.getBoolean(getString(R.string.pref_show_treble_key),
getResources().getBoolean(R.bool.pref_show_treble_default)));
mVisualizerView.setMinSizeScale(1);
mVisualizerView.setColor(getString(R.string.pref_color_red_value));
// Register the listener
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
示例11: getDisplayZoom
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
public int getDisplayZoom() {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return DisplayPreferenceUtilities.getDisplayPreference(
SettingsFragment.KEY_DISPLAY_TEXT_SIZE,
AppConstants.DISPLAY_PREFERENCES_DEFAULTS.DEFAULT_TEXT_ZOOM,
defaultSharedPreferences, mUserDataDBHelper);
}
示例12: setupSharedPreferences
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
private void setupSharedPreferences() {
// Get all of the values from shared preferences to set it up
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mVisualizerView.setShowBass(sharedPreferences.getBoolean(getString(R.string.pref_show_bass_key),
getResources().getBoolean(R.bool.pref_show_bass_default)));
mVisualizerView.setShowMid(true);
mVisualizerView.setShowTreble(true);
mVisualizerView.setMinSizeScale(1);
mVisualizerView.setColor(getString(R.string.pref_color_red_value));
// COMPLETED (3) Register the listener
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
示例13: getTriggeredTaskList
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
public static List<Integer> getTriggeredTaskList(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String json = preferences.getString(context.getResources().getString(R.string.settings_triggered_task_list_key), null);
List<Integer> tasks = new ArrayList<>();
if(json != null) {
try {
Type listType = new TypeToken<List<Integer>>() {}.getType();
Gson gson = new Gson();
tasks = gson.fromJson(json, listType);
} catch (Exception e) { /* Do nothing */}
}
return tasks;
}
示例14: onCreate
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setupActionBar();
mPref = PreferenceManager.getDefaultSharedPreferences(this);
mSetting = new Setting(this);
}
示例15: instantiatePresenterUsing
import android.support.v7.preference.PreferenceManager; //导入方法依赖的package包/类
private static NotePresenter instantiatePresenterUsing(Fragment fragment) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(fragment.getActivity());
String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
return new NotePresenterImpl(
ThreadExecutor.getInstance(),
MainThreadImpl.getInstance(),
(NotePresenter.View) fragment,
new RepositoryImpl(repositoryName));
}