本文整理匯總了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));
}