java类android.preference.CheckBoxPreference的实例源码

SettingsFragment.java 文件源码 项目:ultrasonic 阅读 38 收藏 0 点赞 0 评论 0
private void setupGaplessControlSettingsV14() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        PreferenceCategory playbackControlSettings =
                (PreferenceCategory) findPreference(Constants.PREFERENCES_KEY_PLAYBACK_CONTROL_SETTINGS);
        CheckBoxPreference gaplessPlaybackEnabled =
                (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_GAPLESS_PLAYBACK);

        if (gaplessPlaybackEnabled != null) {
            gaplessPlaybackEnabled.setChecked(false);
            gaplessPlaybackEnabled.setEnabled(false);

            if (playbackControlSettings != null) {
                playbackControlSettings.removePreference(gaplessPlaybackEnabled);
            }
        }
    }
}
ServerSettingsFragment.java 文件源码 项目:ultrasonic 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    serverNamePref = (EditTextPreference) findPreference(getString(R.string.settings_server_name));
    serverUrlPref = (EditTextPreference) findPreference(getString(R.string.settings_server_address));
    serverUsernamePref = (EditTextPreference) findPreference(getString(R.string.settings_server_username));
    serverPasswordPref = (EditTextPreference) findPreference(getString(R.string.settings_server_password));
    equalizerPref = (CheckBoxPreference) findPreference(getString(R.string.equalizer_enabled));
    jukeboxPref = (CheckBoxPreference) findPreference(getString(R.string.jukebox_is_default));
    removeServerPref = findPreference(getString(R.string.settings_server_remove_server));
    testConnectionPref = findPreference(getString(R.string.settings_test_connection_title));
    allowSelfSignedCertificatePref = (CheckBoxPreference) findPreference(
            getString(R.string.settings_allow_self_signed_certificate));

    setupPreferencesValues();
    setupPreferencesListeners();
}
PreferencesFragment.java 文件源码 项目:keepass2android 阅读 33 收藏 0 点赞 0 评论 0
private void disableLastCheckedPref() {
  Collection<CheckBoxPreference> checked = new ArrayList<CheckBoxPreference>(3);
  if (decode1D.isChecked()) {
    checked.add(decode1D);
  }
  if (decodeQR.isChecked()) {
    checked.add(decodeQR);
  }
  if (decodeDataMatrix.isChecked()) {
    checked.add(decodeDataMatrix);
  }
  boolean disable = checked.size() < 2;
  CheckBoxPreference[] checkBoxPreferences = {decode1D, decodeQR, decodeDataMatrix};
  for (CheckBoxPreference pref : checkBoxPreferences) {
    pref.setEnabled(!(disable && checked.contains(pref)));
  }
}
InputLanguageSelection.java 文件源码 项目:keepass2android 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
PreferencesFragment.java 文件源码 项目:mobile-store 阅读 29 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    useTorCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_USE_TOR);
    enableProxyCheckPref = (CheckBoxPreference) findPreference(Preferences.PREF_ENABLE_PROXY);
    updateAutoDownloadPref = findPreference(Preferences.PREF_AUTO_DOWNLOAD_INSTALL_UPDATES);
    updatePrivilegedExtensionPref = findPreference(Preferences.PREF_UNINSTALL_PRIVILEGED_APP);

    AppCompatListPreference languagePref = (AppCompatListPreference) findPreference(Preferences.PREF_LANGUAGE);
    if (Build.VERSION.SDK_INT >= 24) {
        PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_display");
        category.removePreference(languagePref);
    } else {
        Languages languages = Languages.get(getActivity());
        languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT);
        languagePref.setEntries(languages.getAllNames());
        languagePref.setEntryValues(languages.getSupportedLocales());
    }
}
AppProtectionPreferenceFragment.java 文件源码 项目:PeSanKita-android 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);
  addPreferencesFromResource(R.xml.preferences_app_protection);

  masterSecret      = getArguments().getParcelable("master_secret");
  disablePassphrase = (CheckBoxPreference) this.findPreference("pref_enable_passphrase_temporary");

  this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
      .setOnPreferenceClickListener(new ChangePassphraseClickListener());
  this.findPreference(TextSecurePreferences.PASSPHRASE_TIMEOUT_INTERVAL_PREF)
      .setOnPreferenceClickListener(new PassphraseIntervalClickListener());
  this.findPreference(PREFERENCE_CATEGORY_BLOCKED)
      .setOnPreferenceClickListener(new BlockedContactsClickListener());
  disablePassphrase
      .setOnPreferenceChangeListener(new DisablePassphraseClickListener());
}
PreferenceFragment.java 文件源码 项目:SOS-The-Healthcare-Companion 阅读 31 收藏 0 点赞 0 评论 0
public void updatePreferenceSummary() {
    CheckBoxPreference bloodPreference = (CheckBoxPreference) findPreference("checkBoxBlood");
    bloodPreference.setChecked(sharedPreferences.getBoolean("checkBoxBlood", true));

    // Set nagging preference summary
    int nagMinutes = sharedPreferences.getInt("nagMinutes", getResources().getInteger(R.integer.default_nag_minutes));
    int nagSeconds = sharedPreferences.getInt("nagSeconds", getResources().getInteger(R.integer.default_nag_seconds));
    Preference nagPreference = findPreference("nagInterval");
    String nagMinutesText = String.format(getActivity().getResources().getQuantityString(R.plurals.time_minute, nagMinutes), nagMinutes);
    String nagSecondsText = String.format(getActivity().getResources().getQuantityString(R.plurals.time_second, nagSeconds), nagSeconds);
    nagPreference.setSummary(String.format("%s %s", nagMinutesText, nagSecondsText));

    SharedPreferences.Editor editor = s1.edit();
    editor.putBoolean("sos", sharedPreferences.getBoolean("checkBoxSOS", s1.getBoolean("sos", true)));
    editor.apply();

    ((MyApplication) getActivity().getApplication()).createSOSNotification();
}
TwoStatePreferenceHelper.java 文件源码 项目:simple-keyboard 阅读 24 收藏 0 点赞 0 评论 0
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
ServerPreferencesScreen.java 文件源码 项目:bananapeel 阅读 23 收藏 0 点赞 0 评论 0
private void setKeys(PreferenceScreen screen)
{
    for(int i = 0; i < screen.getPreferenceCount(); i++)
    {
        Preference preference = screen.getPreference(i);
        String key = server + ";" + preference.getKey();
        preference.setKey(key);
        if(preference instanceof EditIntPreference)
            ((EditIntPreference)preference).setInt(preference.getSharedPreferences().getInt(key, -1));
        else if(preference instanceof EditTextPreference)
            ((EditTextPreference)preference).setText(preference.getSharedPreferences().getString(key, null));
        else if(preference instanceof ListPreference)
            ((ListPreference)preference).setValue(preference.getSharedPreferences().getString(key, null));
        else if(preference instanceof CheckBoxPreference)
            ((CheckBoxPreference)preference).setChecked(preference.getSharedPreferences().getBoolean(key, false));
        if(preference instanceof PreferenceScreen)
            setKeys((PreferenceScreen)preference);
    }
}
SettingsActivity.java 文件源码 项目:MovieGuide 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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' current value.
    if (preference instanceof ListPreference
            || preference instanceof EditTextPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } else if (preference instanceof SwitchPreference
            || preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getBoolean(preference.getKey(),true));
    }
}
AppPreferences.java 文件源码 项目:Kasumi 阅读 26 收藏 0 点赞 0 评论 0
private CheckBoxPreference addCheckBox(String title, PreferenceCategory category, String key, Drawable icon, String onText, String offText, boolean defaultValue, Context context) {
    CheckBoxPreference c = new CheckBoxPreference(context);
    c.setTitle(title);
    c.setKey(key);
    if (null != icon) c.setIcon(icon);
    if (offText.equals(null) || onText.equals(null)) {
        if (offText.equals(null)) {
            c.setSummary(onText);
        } else if (onText.equals(null)) {
            c.setSummary(offText);
        }
    } else {
        c.setSummaryOn(onText);
        c.setSummaryOff(offText);
    }
    c.setDefaultValue(defaultValue);
    c.setChecked(KRFAM.sharedPreferences.getBoolean(key, defaultValue));
    category.addPreference(c);
    return c;
}
PreferencesActivity.java 文件源码 项目:ChatExchange-old 阅读 33 收藏 0 点赞 0 评论 0
private void setDynamicMsgBgColor(final CheckBoxPreference checkBoxPreference, final ColorPreference hue, final ColorPreference hueDark)
{
    hue.setEnabled(!checkBoxPreference.isChecked());
    hueDark.setEnabled(!checkBoxPreference.isChecked());
    final CheckBoxPreference darkThemePref = (CheckBoxPreference) findPreference("dark_theme");

    checkBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o)
        {
            if (darkThemePref.isChecked())
            {
                hueDark.setEnabled(!(boolean) o);
                hue.setEnabled(false);
            }
            else
            {
                hue.setEnabled(!(boolean) o);
                hueDark.setEnabled(false);
            }

            return true;
        }
    });
}
PreferencesActivity.java 文件源码 项目:ChatExchange-old 阅读 32 收藏 0 点赞 0 评论 0
private void setSameFabColor(final CheckBoxPreference sameFabColor, final ColorPreference hue)
{
    sameFabColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o)
        {
            if ((boolean) o)
            {
                hue.setEnabled(false);
            }
            else
            {
                hue.setEnabled(true);
            }
            return true;
        }
    });
}
CustomRestrictionsFragment.java 文件源码 项目:buildAPKsSamples 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.custom_prefs);

    // This sample app uses shared preferences to maintain app restriction settings.  Your app
    // can use other methods to maintain the settings.
    mBooleanPref = (CheckBoxPreference) findPreference(KEY_BOOLEAN_PREF);
    mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
    mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);

    mBooleanPref.setOnPreferenceChangeListener(this);
    mChoicePref.setOnPreferenceChangeListener(this);
    mMultiPref.setOnPreferenceChangeListener(this);

    setRetainInstance(true);
}
SettingsFragment.java 文件源码 项目:Minimal-Todo 阅读 33 收藏 0 点赞 0 评论 0
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    PreferenceKeys preferenceKeys = new PreferenceKeys(getResources());
    if(key.equals(preferenceKeys.night_mode_pref_key)){
        SharedPreferences themePreferences = getActivity().getSharedPreferences(MainActivity.THEME_PREFERENCES, Context.MODE_PRIVATE);
        SharedPreferences.Editor themeEditor = themePreferences.edit();
        //We tell our MainLayout to recreate itself because mode has changed
        themeEditor.putBoolean(MainActivity.RECREATE_ACTIVITY, true);

        CheckBoxPreference checkBoxPreference = (CheckBoxPreference)findPreference(preferenceKeys.night_mode_pref_key);
        if(checkBoxPreference.isChecked()){
            //Comment out this line if not using Google Analytics
            themeEditor.putString(MainActivity.THEME_SAVED, MainActivity.DARKTHEME);
        }
        else{
            themeEditor.putString(MainActivity.THEME_SAVED, MainActivity.LIGHTTHEME);
        }
        themeEditor.apply();

        getActivity().recreate();
    }
}
PreferencesActivity.java 文件源码 项目:Zxing 阅读 33 收藏 0 点赞 0 评论 0
private void disableLastCheckedPref()
{
    Collection<CheckBoxPreference> checked = new ArrayList<CheckBoxPreference>(3);
    if (decode1D.isChecked())
    {
        checked.add(decode1D);
    }
    if (decodeQR.isChecked())
    {
        checked.add(decodeQR);
    }
    if (decodeDataMatrix.isChecked())
    {
        checked.add(decodeDataMatrix);
    }
    boolean disable = checked.size() < 2;
    for (CheckBoxPreference pref : new CheckBoxPreference[]
    { decode1D, decodeQR, decodeDataMatrix })
    {
        pref.setEnabled(!(disable && checked.contains(pref)));
    }
}
PreferenceFragment.java 文件源码 项目:boohee_v5.6 阅读 37 收藏 0 点赞 0 评论 0
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.a);
    try {
        findPreference("pref_about_boohee").setSummary(getActivity().getPackageManager()
                .getPackageInfo(getActivity().getPackageName(), 16384).versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    this.mSharePreference = findPreference("pref_share");
    this.mSharePreference.setOnPreferenceClickListener(this);
    this.mTermsPreference = findPreference("pref_terms");
    this.mTermsPreference.setOnPreferenceClickListener(this);
    this.mAboutBooheePreference = findPreference("pref_about_boohee");
    this.mAboutBooheePreference.setOnPreferenceClickListener(this);
    this.mScorePreference = findPreference("pref_score");
    this.mScorePreference.setOnPreferenceClickListener(this);
    this.mPrivacyPreference = (CheckBoxPreference) findPreference(Const.PASSWORD);
    this.mPrivacyPreference.setOnPreferenceChangeListener(this);
    this.mIsReceivePushPreference = (CheckBoxPreference) findPreference("isReceivePush");
    this.mIsReceivePushPreference.setOnPreferenceChangeListener(this);
}
AppProtectionPreferenceFragment.java 文件源码 项目:Cable-Android 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle paramBundle) {
  super.onCreate(paramBundle);
  addPreferencesFromResource(R.xml.preferences_app_protection);

  masterSecret      = getArguments().getParcelable("master_secret");
  disablePassphrase = (CheckBoxPreference) this.findPreference("pref_enable_passphrase_temporary");

  this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
      .setOnPreferenceClickListener(new ChangePassphraseClickListener());
  this.findPreference(TextSecurePreferences.PASSPHRASE_TIMEOUT_INTERVAL_PREF)
      .setOnPreferenceClickListener(new PassphraseIntervalClickListener());
  this.findPreference(PREFERENCE_CATEGORY_BLOCKED)
      .setOnPreferenceClickListener(new BlockedContactsClickListener());
  disablePassphrase
      .setOnPreferenceChangeListener(new DisablePassphraseClickListener());
}
TwoStatePreferenceHelper.java 文件源码 项目:AOSP-Kayboard-7.1.2 阅读 17 收藏 0 点赞 0 评论 0
private static void replaceAllCheckBoxPreferencesBySwitchPreferences(
        final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference)preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup)preference);
            }
        }
    }
}
TwoStatePreferenceHelper.java 文件源码 项目:AOSP-Kayboard-7.1.2 阅读 21 收藏 0 点赞 0 评论 0
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
        final PreferenceGroup group) {
    final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
    switchPref.setTitle(checkBox.getTitle());
    switchPref.setKey(checkBox.getKey());
    switchPref.setOrder(checkBox.getOrder());
    switchPref.setPersistent(checkBox.isPersistent());
    switchPref.setEnabled(checkBox.isEnabled());
    switchPref.setChecked(checkBox.isChecked());
    switchPref.setSummary(checkBox.getSummary());
    switchPref.setSummaryOn(checkBox.getSummaryOn());
    switchPref.setSummaryOff(checkBox.getSummaryOff());
    switchPref.setSwitchTextOn(EMPTY_TEXT);
    switchPref.setSwitchTextOff(EMPTY_TEXT);
    group.addPreference(switchPref);
    switchPref.setDependency(checkBox.getDependency());
}
PreferencesFragment.java 文件源码 项目:KeePass2Android 阅读 32 收藏 0 点赞 0 评论 0
private void disableLastCheckedPref() {
  Collection<CheckBoxPreference> checked = new ArrayList<CheckBoxPreference>(3);
  if (decode1D.isChecked()) {
    checked.add(decode1D);
  }
  if (decodeQR.isChecked()) {
    checked.add(decodeQR);
  }
  if (decodeDataMatrix.isChecked()) {
    checked.add(decodeDataMatrix);
  }
  boolean disable = checked.size() < 2;
  CheckBoxPreference[] checkBoxPreferences = {decode1D, decodeQR, decodeDataMatrix};
  for (CheckBoxPreference pref : checkBoxPreferences) {
    pref.setEnabled(!(disable && checked.contains(pref)));
  }
}
InputLanguageSelection.java 文件源码 项目:KeePass2Android 阅读 17 收藏 0 点赞 0 评论 0
@Override
protected void onPause() {
    super.onPause();
    // Save the selected languages
    String checkedLanguages = "";
    PreferenceGroup parent = getPreferenceScreen();
    int count = parent.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i);
        if (pref.isChecked()) {
            Locale locale = mAvailableLanguages.get(i).locale;
            checkedLanguages += get5Code(locale) + ",";
        }
    }
    if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = sp.edit();
    editor.putString(KP2AKeyboard.PREF_SELECTED_LANGUAGES, checkedLanguages);
    SharedPreferencesCompat.apply(editor);
}
PrefFragment.java 文件源码 项目:NetUpDown 阅读 32 收藏 0 点赞 0 评论 0
@TargetApi(14)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    /*
     * SwitchPreferences calls multiple times the onPreferenceChange() method
     * It is due to the bug in SwitchPreference implementation.
     * And it's solved in API 21+
     */
    //if (C.SDK >= 14) {
    if (C.SDK >= 21) {
        switchPreference = (SwitchPreference) findPreference("run");
    } else {
        checkBoxPreference = (CheckBoxPreference) findPreference("run");
    }
    findPreference("run").setOnPreferenceChangeListener(this);

    serviceReceiver = new ServiceReceiver();

    sp = new SP(getActivity());
}
SettingsFragment.java 文件源码 项目:Beacon-Scanner-Android 阅读 26 收藏 0 点赞 0 评论 0
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
    } else if (preference instanceof CheckBoxPreference) {
        // Intentionally left blank.
    } else if (!(Integer.parseInt(value.toString()) < MAX_VALUE_ID)) {
        Toast.makeText(getActivity(), "Please enter a value between 0 - " + MAX_VALUE_ID, Toast.LENGTH_LONG).show();
        return false;
    } else preference.setSummary(stringValue);
    return true;
}
Setting.java 文件源码 项目:MaoMaoRobot 阅读 26 收藏 0 点赞 0 评论 0
private void bind(PreferenceGroup group) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    for (int i = 0; i < group.getPreferenceCount(); i++) {
        Preference p = group.getPreference(i);
        if (p instanceof PreferenceGroup) {
            bind((PreferenceGroup) p);
        } else {
            if (p instanceof CheckBoxPreference) {
                ;
            } else {
                Object val = sp.getAll().get(p.getKey());
                p.setSummary(val == null ? "" : ("" + val));
                p.setOnPreferenceChangeListener(this);
            }
        }
    }
}
DevOptionsFragment.java 文件源码 项目:science-journal 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.dev_options);

    CheckBoxPreference leakPref = (CheckBoxPreference) findPreference(KEY_LEAK_CANARY);
    if (isDebugVersion()) {
        leakPref.setChecked(isLeakCanaryEnabled(getActivity()));
        leakPref.setOnPreferenceChangeListener((preference, newValue) -> {
            final SharedPreferences prefs = getPrefs(preference.getContext());
            prefs.edit().putBoolean(KEY_LEAK_CANARY, (Boolean) newValue).apply();
            return true;
        });
    } else {
        getPreferenceScreen().removePreference(leakPref);
    }

    Preference prefTrackerPref = findPreference(KEY_PERF_DEBUG_SCREEN);
    prefTrackerPref.setOnPreferenceClickListener(preference -> {
        WhistlePunkApplication.getPerfTrackerProvider(getContext())
                .startPerfTrackerEventDebugActivity(getContext());
        return true;
    });
}
SettingsFragment.java 文件源码 项目:beacon-finder 阅读 41 收藏 0 点赞 0 评论 0
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);
    } else if (preference instanceof CheckBoxPreference) {
        // Intentionally left blank.
    } else if (!(Integer.parseInt(value.toString()) < MAX_VALUE_ID)){
        Toast.makeText(getActivity(), "Please enter a value between 0 - " + MAX_VALUE_ID, Toast.LENGTH_LONG).show();
        return false;
    } else preference.setSummary(stringValue);
    return true;
}
SettingsActivity.java 文件源码 项目:ebookmgr 阅读 32 收藏 0 点赞 0 评论 0
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity());

    PreferenceCategory category = new PreferenceCategory(getActivity());
    category.setTitle("Libraries");

    screen.addPreference(category);

    CheckBoxPreference checkBoxPref = new CheckBoxPreference(getActivity());
    checkBoxPref.setTitle("title");
    checkBoxPref.setSummary("summary");
    checkBoxPref.setChecked(true);

    category.addPreference(checkBoxPref);
    setPreferenceScreen(screen);
}
MiscellaneousPreferences.java 文件源码 项目:TaskApp 阅读 17 收藏 0 点赞 0 评论 0
private void initializeCalendarReminderPreference() {
    CheckBoxPreference calendarReminderPreference = (CheckBoxPreference) findPreference(getString(R.string.p_calendar_reminders));
    calendarReminderPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue == null) {
                return false;
            }
            if (!(Boolean) newValue) {
                return true;
            }
            if (permissionRequestor.requestCalendarPermissions()) {
                backgroundScheduler.scheduleCalendarNotifications();
                return true;
            }
            return false;
        }
    });
    calendarReminderPreference.setChecked(calendarReminderPreference.isChecked() && permissionChecker.canAccessCalendars());
}
SettingsActivity.java 文件源码 项目:MovieGuide 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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' current value.
    if (preference instanceof ListPreference
            || preference instanceof EditTextPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    } else if (preference instanceof SwitchPreference
            || preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getBoolean(preference.getKey(),true));
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号