Java 类android.support.v7.preference.TwoStatePreference 实例源码

项目:haystack    文件:DevelopmentSettings.java   
@DexAppend
@Override
public void onCreate(Bundle icicle) {
    try {
        PreferenceGroup pg = (PreferenceGroup) findPreference(
                FakeSignatureGlobalUI.DEBUG_APPLICATIONS_CATEGORY_KEY);
        if (pg != null) {
            TwoStatePreference p = createTwoStatePreference(pg.getContext());
            p.setKey(FakeSignatureGlobalUI.SETTING_SECURE_KEY);
            p.setTitle(FakeSignatureGlobalUI.SETTING_TITLE);
            p.setSummary(FakeSignatureGlobalUI.SETTING_SUMMARY);
            p.setPersistent(false);
            mResetTwoStatePrefsAdd(p);
            mAllPrefs.add(p);
            //pg.setOrderingAsAdded(true);
            pg.addPreference(p);
            mAllowFakeSignatureGlobal = p;
        } else {
            Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "cannot find 'applications' preference category");
        }
    } catch (Throwable t) {
        Log.e("DevelopmentSettings_FakeSignatureGlobalUI", "onCreate exception", t);
    }
}
项目:ring-client-android    文件:MediaPreferenceFragment.java   
private void setPreferenceDetails(AccountConfig details) {
    for (ConfigKey confKey : details.getKeys()) {
        Preference pref = findPreference(confKey.key());

        if (pref != null) {
            if (pref instanceof TwoStatePreference) {
                ((TwoStatePreference) pref).setChecked(details.getBool(confKey));
            } else if (confKey == ConfigKey.ACCOUNT_DTMF_TYPE) {
                pref.setDefaultValue(details.get(confKey).contentEquals("overrtp") ? "RTP" : "SIP");
                pref.setSummary(details.get(confKey).contentEquals("overrtp") ? "RTP" : "SIP");
            } else if (confKey == ConfigKey.RINGTONE_PATH) {
                File tmp = new File(details.get(confKey));
                pref.setSummary(tmp.getName());
            } else {
                pref.setSummary(details.get(confKey));
            }
        }
    }
}
项目:ring-client-android    文件:GeneralAccountFragment.java   
private void setPreferenceDetails(AccountConfig details) {
    for (ConfigKey confKey : details.getKeys()) {
        Preference pref = findPreference(confKey.key());
        if (pref == null) {
            continue;
        }
        if (!confKey.isTwoState()) {
            String val = details.get(confKey);
            ((EditTextPreference) pref).setText(val);
            if (pref instanceof PasswordPreference) {
                StringBuilder tmp = new StringBuilder();
                for (int i = 0; i < val.length(); ++i) {
                    tmp.append("*");
                }
                pref.setSummary(tmp.toString());
            } else {
                pref.setSummary(val);
            }
        } else {
            ((TwoStatePreference) pref).setChecked(details.getBool(confKey));
        }
    }
}
项目:ring-client-android    文件:AdvancedAccountFragment.java   
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    final ConfigKey key = ConfigKey.fromString(preference.getKey());

    presenter.preferenceChanged(key, newValue);


    if (preference instanceof TwoStatePreference) {
        presenter.twoStatePreferenceChanged(key, newValue);
    } else if (preference instanceof PasswordPreference) {
        presenter.passwordPreferenceChanged(key, newValue);
        preference.setSummary(TextUtils.isEmpty(newValue.toString()) ? "" : "******");
    } else {
        presenter.preferenceChanged(key, newValue);
        preference.setSummary(newValue.toString());
    }
    return true;
}
项目:Camera-Roll-Android-App    文件:SettingsActivity.java   
private void initMediaRetrieverPref(boolean storageRetriever) {
    TwoStatePreference mediaRetrieverPref =
            (TwoStatePreference) findPreference(getString(R.string.pref_key_media_retriever));

    mediaRetrieverPref.setChecked(storageRetriever);
    mediaRetrieverPref.setOnPreferenceChangeListener(this);
}
项目:Camera-Roll-Android-App    文件:SettingsActivity.java   
private void init8BitColorPref(boolean use8BitColor) {
    TwoStatePreference use8BitColorPref =
            (TwoStatePreference) findPreference(getString(R.string.pref_key_8_bit_color));

    use8BitColorPref.setChecked(use8BitColor);
    use8BitColorPref.setOnPreferenceChangeListener(this);
}
项目:Camera-Roll-Android-App    文件:SettingsActivity.java   
private void initCameraShortcutPref(boolean cameraShortcut) {
    TwoStatePreference cameraShortcutPref =
            (TwoStatePreference) findPreference(getString(R.string.pref_key_camera_shortcut));

    cameraShortcutPref.setChecked(cameraShortcut);
    cameraShortcutPref.setOnPreferenceChangeListener(this);
}
项目:rview    文件:AccountSettingsFragment.java   
private void configureHandleLinks() {
    PreferenceCategory category =
            (PreferenceCategory) findPreference(PREF_ACCOUNT_EXTERNAL_CATEGORY);
    mHandleLinks = (TwoStatePreference) findPreference(PREF_ACCOUNT_HANDLE_LINKS);
    if (!ModelHelper.canAccountHandleUrls(getContext(), mAccount)) {
        if (mHandleLinks != null) {
            category.removePreference(mHandleLinks);
            mHandleLinks = null;
        }
    } else {
        mHandleLinks.setChecked(Preferences.isAccountHandleLinks(getContext(), mAccount)
                && ModelHelper.isAccountUrlHandlingEnabled(getContext(), mAccount));
        mHandleLinks.setOnPreferenceChangeListener(this);
    }
}
项目:haystack    文件:DevelopmentSettings.java   
@DexAdd
private TwoStatePreference createTwoStatePreference(Context context) {
    if (useSwitchPreference()) {
        return new SwitchPreference(context);
    } else {
        return new CheckBoxPreference(context);
    }
}
项目:haystack    文件:DevelopmentSettings.java   
@DexAdd
private boolean mResetTwoStatePrefsAdd(TwoStatePreference preference) {
    if (useSwitchPreference()) {
        return mResetSwitchPrefs.add((SwitchPreference) preference);
    } else {
        return mResetCbPrefs.add((CheckBoxPreference) preference);
    }
}
项目:haystack    文件:DevelopmentSettings.java   
@DexAdd
private void updateTwoStatePreference(TwoStatePreference preference, boolean value) {
    if (useSwitchPreference()) {
        updateSwitchPreference((SwitchPreference) preference, value);
    } else {
        updateCheckBox((CheckBoxPreference) preference, value);
    }
}
项目:RememBirthday    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);
    remindersDaysEditTextPreference = (EditTextPreference) findPreference(getString(R.string.pref_reminders_days_key));

    Preference openCalendar = findPreference(getString(R.string.pref_open_calendar_key));
    openCalendar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @SuppressLint("NewApi")
        @Override
        public boolean onPreferenceClick(Preference preference) {
            IntentCall.openCalendarAt(getContext(), new Date());
            return true;
        }
    });

    accountResolver = CalendarAccount.getAccount(getContext());
    preferenceCreateCalendar = (TwoStatePreference) findPreference(getString(R.string.pref_create_calendar_key));
    preferenceCreateCalendar.setDefaultValue(false);
    preferenceCreateCalendar.setOnPreferenceClickListener(onPreferenceCalendarClick);

    preferenceSpecial = (TwoStatePreference) findPreference(getString(R.string.pref_special_service_key));
    preferenceSpecial.setDefaultValue(false);
    if (!BuildConfig.FULL_VERSION) {
        // Disable switch and show pro dialog if free version
        preferenceSpecial.setOnPreferenceClickListener(onPreferenceProFeatureClick);
    } else {
        preferenceSpecial.setOnPreferenceClickListener(onPreferenceSendSmsClick);
    }

    TwoStatePreference preferenceHideInactive = (TwoStatePreference) findPreference(getString(R.string.pref_hide_inactive_features_key));
    if (!BuildConfig.FULL_VERSION) {
        preferenceHideInactive.setOnPreferenceClickListener(onPreferenceProFeatureClick);
    }
}
项目:VCL-Android    文件:PreferencesUi.java   
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference.getKey() == null)
        return false;
    switch (preference.getKey()){
        case "enable_headset_detection":
            ((PreferencesActivity)getActivity()).detectHeadset(((TwoStatePreference) preference).isChecked());
            return true;
        case "enable_steal_remote_control":
            PlaybackService.Client.restartService(getActivity());
            return true;
    }
    return super.onPreferenceTreeClick(preference);
}
项目:android-testdpc    文件:LockScreenPolicyFragment.java   
/**
 * Set an initial value. Updates the summary to match.
 */
private void setup(String key, Object adminSetting) {
    final Preference pref = findPreference(key);
    final DpcPreferenceBase dpcPref = (DpcPreferenceBase) pref;

    // Disable preferences that don't apply to the parent profile
    dpcPref.setCustomConstraint(
            () -> Keys.NOT_APPLICABLE_TO_PARENT.contains(key) && isParentProfileInstance()
                    ? R.string.not_for_parent_profile
                    : NO_CUSTOM_CONSTRIANT
    );

    // We do not allow user to add trust agent config in pre-N devices in managed profile.
    if (!BuildCompat.isAtLeastN() && key.equals(Keys.SET_TRUST_AGENT_CONFIG)) {
        dpcPref.setAdminConstraint(DpcPreferenceHelper.ADMIN_DEVICE_OWNER);
        return;
    }

    // Set up initial state and possibly a descriptive summary of said state.
    if (pref instanceof EditTextPreference) {
        String stringValue = (adminSetting != null ? adminSetting.toString() : null);
        if (adminSetting instanceof Number && "0".equals(stringValue)) {
            stringValue = null;
        }
        ((EditTextPreference) pref).setText(stringValue);
        pref.setSummary(stringValue);
    } else if (pref instanceof TwoStatePreference) {
        ((TwoStatePreference) pref).setChecked((Boolean) adminSetting);
    }

    // Start listening for change events.
    pref.setOnPreferenceChangeListener(this);
    pref.setOnPreferenceClickListener(this);
}
项目:apps-android-wikipedia    文件:DeveloperSettingsPreferenceLoader.java   
private void setUpMediaWikiSettings() {
    Preference uriPreference = findPreference(context.getString(R.string.preference_key_mediawiki_base_uri));
    uriPreference.setOnPreferenceChangeListener(setMediaWikiBaseUriChangeListener);
    TwoStatePreference multiLangPreference
            = (TwoStatePreference) findPreference(context.getString(R.string.preference_key_mediawiki_base_uri_supports_lang_code));
    multiLangPreference.setOnPreferenceChangeListener(setMediaWikiMultiLangSupportChangeListener);
}
项目:RememBirthday    文件:SettingsFragment.java   
@Override
public boolean onPreferenceClick(Preference preference) {
    ((TwoStatePreference) preference).setChecked(false);
    new ProFeatureDialogFragment().show(getFragmentManager(), "PRO_FEATURE_TAG");
    return false;
}
项目:ring-client-android    文件:SecurityAccountFragment.java   
@Override
public void setDetails(AccountConfig config, String[] tlsMethods) {
    for (int i = 0; i < tlsCategory.getPreferenceCount(); ++i) {
        final Preference current = tlsCategory.getPreference(i);
        final ConfigKey key = ConfigKey.fromString(current.getKey());

        if (current instanceof TwoStatePreference) {
            ((TwoStatePreference) current).setChecked(config.getBool(key));
        } else {
            if (key == ConfigKey.TLS_CA_LIST_FILE) {
                File crt = new File(config.get(ConfigKey.TLS_CA_LIST_FILE));
                current.setSummary(crt.getName());
                setFeedbackIcon(current);
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_PRIVATE_KEY_FILE) {
                current.setSummary(new File(config.get(ConfigKey.TLS_PRIVATE_KEY_FILE)).getName());
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_CERTIFICATE_FILE) {
                File pem = new File(config.get(ConfigKey.TLS_CERTIFICATE_FILE));
                current.setSummary(pem.getName());
                setFeedbackIcon(current);
                checkForRSAKey();
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_METHOD) {
                ListPreference listPref = (ListPreference) current;
                String curVal = config.get(key);
                listPref.setEntries(tlsMethods);
                listPref.setEntryValues(tlsMethods);
                listPref.setValue(curVal);
                current.setSummary(curVal);
            } else if (current instanceof EditTextPreference) {
                String val = config.get(key);
                ((EditTextPreference) current).setText(val);
                current.setSummary(val);
            } else {
                current.setSummary(config.get(key));
            }
        }

        current.setOnPreferenceChangeListener(tlsListener);
    }
}
项目:apps-android-wikipedia    文件:DeveloperSettingsPreferenceLoader.java   
private void setUpRestBaseCheckboxes() {
    TwoStatePreference manualPreference = (TwoStatePreference) findPreference(getManualKey());
    manualPreference.setOnPreferenceChangeListener(setRestBaseManuallyChangeListener);
    setUseRestBasePreference(manualPreference.isChecked());
}
项目:apps-android-wikipedia    文件:DeveloperSettingsPreferenceLoader.java   
private void setUseRestBasePreference(boolean manualMode) {
    RbSwitch.INSTANCE.update();
    TwoStatePreference useRestBasePref = getUseRestBasePreference();
    useRestBasePref.setEnabled(manualMode);
    useRestBasePref.setChecked(RbSwitch.INSTANCE.isRestBaseEnabled());
}
项目:apps-android-wikipedia    文件:DeveloperSettingsPreferenceLoader.java   
private TwoStatePreference getUseRestBasePreference() {
    return (TwoStatePreference) findPreference(getUseRestBaseKey());
}