本文整理汇总了Java中android.support.v7.preference.PreferenceManager类的典型用法代码示例。如果您正苦于以下问题:Java PreferenceManager类的具体用法?Java PreferenceManager怎么用?Java PreferenceManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PreferenceManager类属于android.support.v7.preference包,在下文中一共展示了PreferenceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindPreferenceSummaryToValue
import android.support.v7.preference.PreferenceManager; //导入依赖的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);
}
}
示例2: onResume
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean newIsNightMode = DisplayPreferenceUtilities.getDisplayPreference(
SettingsFragment.KEY_IS_THEME_NIGHT_MODE,
AppConstants.DISPLAY_PREFERENCES_DEFAULTS.IS_THEME_NIGHT_MODE,
defaultSharedPreferences,
mUserDataDBHelper);
if (newIsNightMode != isThemeNightMode)
restartOnThemeChange();
int newZoom = getDisplayZoom();
zoomUpdatedByValue(newZoom);
Util.restartIfLocaleChanged(this, mIsArabic);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean keepScreenOn = sharedPreferences.
getBoolean(SettingsFragment.PREF_KEEP_SCREEN_ON, false);
if (keepScreenOn)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
示例3: 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);
}
示例4: showRepositoryDialog
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
public static void showRepositoryDialog(final FragmentActivity activity) {
final CharSequence[] repositoryNames = RepositoryManager.readRepositoryNames(activity.getApplicationContext().getFilesDir());
RadioDialogCallback callback = new RadioDialogCallback() {
@Override
public void which(int position) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(KEY_PREF_ACTIVE_REPO, repositoryNames[position].toString());
editor.apply();
Toast.makeText(activity, activity.getResources().getString(R.string.switched_database, repositoryNames[position]), Toast.LENGTH_SHORT).show();
}
};
showRadioDialog(activity, getString(activity, R.string.switch_database), repositoryNames, callback);
}
示例5: bindPreferenceSummaryToValue
import android.support.v7.preference.PreferenceManager; //导入依赖的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);
}
}
示例6: onCreate
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
mPresenter = new DisplayNotePresenterImpl(
ThreadExecutor.getInstance(),
MainThreadImpl.getInstance(),
this,
new RepositoryImpl(repositoryName)
);
Bundle bundle = getArguments();
if (bundle != null) {
uuid = bundle.getString(KEY_UUID);
title = bundle.getString(KEY_TITLE);
}
}
示例7: onCreate
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
Bundle bundle = getArguments();
if (bundle != null) {
uuid = bundle.getString(KEY_UUID);
title = bundle.getString(KEY_TITLE);
}
String repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
// create a presenter for this view
mPresenter = new DisplayTodoListPresenterImpl(
ThreadExecutor.getInstance(),
MainThreadImpl.getInstance(),
this,
new RepositoryImpl(repositoryName)
);
}
示例8: 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();
}
示例9: onCreatePreferences
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
settingsPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
// Load the Preferences from the XML file
addPreferencesFromResource(R.xml.settings_preferences);
Preference backgroundPreference = (Preference) findPreference(SettingsPreferencesKeys.
BACKGROUND_PREFERENCE_KEY);
backgroundPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE_REQUEST);
return true;
}
});
}
示例10: redrawLocationOnMap
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
private void redrawLocationOnMap()
{
if(locationMarker!=null)
{
LatLng markerLocation = locationMarker.getPosition();
if (!followed) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markerLocation, 15));
followed = true;
}
locationMarker = mMap.addMarker(new MarkerOptions().position(markerLocation).title("Your location"));
if (radiusCircle != null) {
radiusCircle.remove();
}
radiusCircle = mMap.addCircle(new CircleOptions().center(locationMarker.getPosition()).radius(Double.parseDouble(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default)))).fillColor(Color.argb(195, 102, 147, 173)));
}
else
{
Log.d("MapsActivity", "redrawLocationOnMap called with null==locationMarker");
}
}
示例11: updateLocationOnMap
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
private void updateLocationOnMap(@NonNull Location location) {
if (locationMarker != null) {
locationMarker.remove();
}
LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());
if (!followed) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 15));
followed = true;
}
locationMarker = mMap.addMarker(new MarkerOptions().position(userLocation).title("Your location"));
if (radiusCircle != null) {
radiusCircle.remove();
}
radiusCircle = mMap.addCircle(new CircleOptions().center(locationMarker.getPosition()).radius(Double.parseDouble(PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_radius_key), getString(R.string.pref_radius_default)))).fillColor(Color.argb(195, 102, 147, 173)));
}
示例12: onCreate
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
bookId = args.getInt(BooksInformationDBContract.BooksAuthors.COLUMN_NAME_BOOK_ID, 0);
pageId = args.getInt(BookDatabaseContract.TitlesEntry.COLUMN_NAME_PAGE_ID, 0);
mPagerPosition = args.getInt(KEY_PAGER_POSITION, 0);
userDataDBHelper = UserDataDBHelper.getInstance(getContext(), bookId);
BookDatabaseHelper bookDatabaseHelperInstance = BookDatabaseHelper.getInstance(getContext(), bookId);
mSharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
page_content = bookDatabaseHelperInstance.getPageContentByPageId(pageId);
mPageCitation = bookDatabaseHelperInstance.getCitationInformation(pageId);
mPageCitation.setResources(getResources());
pageInfo = mPageCitation.pageInfo;
setHasOptionsMenu(false);
}
示例13: getTriggerMinutesBeforeNotification
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
public static TriggerMinutesBeforeNotificationType getTriggerMinutesBeforeNotification(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String tmPref = preferences.getString(context.getResources().getString(R.string.settings_trigger_minutes_before_notification_key), null);
TriggerMinutesBeforeNotificationType pref;
try {
pref = TriggerMinutesBeforeNotificationType.valueOf(tmPref);
} catch (Exception e) {
pref = null;
}
if(pref == null) {
Log.d("SharedPreferenceUtil", "getTriggerMinutesBeforeNotification() found null, setting 5 minutes");
TriggerMinutesBeforeNotificationType tm = TriggerMinutesBeforeNotificationType.MINUTES_5;
setTriggerMinutesBeforeNotification(tm, context);
return tm;
}
else return pref;
}
示例14: onActivityResult
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
if(mCurrentPhotoPath != null && mCurrentDiaryUri != null) {
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".fileprovider",
new File(mCurrentPhotoPath));
ContentValues values = new ContentValues();
values.put(ActivityDiaryContract.DiaryImage.URI, photoURI.toString());
values.put(ActivityDiaryContract.DiaryImage.DIARY_ID, mCurrentDiaryUri.getLastPathSegment());
mQHandler.startInsert(0,
null,
ActivityDiaryContract.DiaryImage.CONTENT_URI,
values);
if(PreferenceManager
.getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
.getBoolean(SettingsActivity.KEY_PREF_TAG_IMAGES, true)) {
try {
ExifInterface exifInterface = new ExifInterface(mCurrentPhotoPath);
if (mCurrentActivity != null) {
/* TODO: #24: when using hierarchical activities tag them all here, seperated with comma */
/* would be great to use IPTC keywords instead of EXIF UserComment, but
* at time of writing (2017-11-24) it is hard to find a library able to write IPTC
* to JPEG for android.
* pixymeta-android or apache/commons-imaging could be interesting for this.
* */
exifInterface.setAttribute(ExifInterface.TAG_USER_COMMENT, mCurrentActivity.getName());
exifInterface.saveAttributes();
}
} catch (IOException e) {
Log.e(TAG, "writing exif data to " + mCurrentPhotoPath + " failed");
}
}
}
}
}
示例15: updateTagImageSummary
import android.support.v7.preference.PreferenceManager; //导入依赖的package包/类
private void updateTagImageSummary() {
if(PreferenceManager
.getDefaultSharedPreferences(ActivityDiaryApplication.getAppContext())
.getBoolean(KEY_PREF_TAG_IMAGES, true)){
tagImagesPref.setSummary(getResources().getString(R.string.setting_tag_yes));
}else{
tagImagesPref.setSummary(getResources().getString(R.string.setting_tag_no));
}
}