Android Open Source - ponyville-live-android Boolean Preference

From Project

Back to project page ponyville-live-android.


The source code is released under:

Apache License

If you think the Android project ponyville-live-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//from   w w  w  .  j  a  v a2 m
import android.content.SharedPreferences;

public class BooleanPreference {
  private final SharedPreferences preferences;
  private final String key;
  private final boolean defaultValue;

  public BooleanPreference(SharedPreferences preferences, String key) {
    this(preferences, key, false);

  public BooleanPreference(SharedPreferences preferences, String key, boolean defaultValue) {
    this.preferences = preferences;
    this.key = key;
    this.defaultValue = defaultValue;

  public boolean get() {
    return preferences.getBoolean(key, defaultValue);

  public boolean isSet() {
    return preferences.contains(key);

  public void set(boolean value) {
    preferences.edit().putBoolean(key, value).apply();

  public void delete() {

Java Source Code List