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

项目:haven    文件:SettingsFragment.java   
protected void save() {
    preferences.activateAccelerometer(true);

    preferences.activateCamera(true);

    preferences.activateMicrophone(true);

    setPhoneNumber();

    boolean remoteAccessActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked();

    preferences.activateRemoteAccess(remoteAccessActive);
    String password = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText();

    if (checkValidStrings(password, preferences.getRemoteAccessCredential()) && (TextUtils.isEmpty(preferences.getRemoteAccessCredential()) || !password.trim().equals(preferences.getRemoteAccessCredential().trim()))) {
        preferences.setRemoteAccessCredential(password.trim());
        app.stopServer();
        app.startServer();
    }

    mActivity.setResult(Activity.RESULT_OK);
    mActivity.finish();
}
项目:haven    文件:SettingsFragment.java   
private void setPhoneNumber() {
    boolean smsActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).isChecked();
    String phoneNumber = ((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).getText();
    if (smsActive && checkValidString(phoneNumber)) {
        preferences.activateSms(true);
    } else {
        preferences.activateSms(false);
    }

    if (checkValidString(phoneNumber)) {
        preferences.setSmsNumber(phoneNumber.trim());
        findPreference(PreferenceManager.SMS_NUMBER).setSummary(phoneNumber.trim());
    } else {
        preferences.setSmsNumber("");
        findPreference(PreferenceManager.SMS_NUMBER).setSummary(R.string.sms_dialog_message);
    }
}
项目:ConnectU    文件:NotificationsFragment.java   
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
    super.onViewCreated(view, savedInstanceState);
    app = (App) getContext().getApplicationContext();
    view.setBackgroundColor(Color.parseColor("#FFFFFF"));
    SwitchPreferenceCompat preference = (SwitchPreferenceCompat)findPreference("enableNotifications");
    preference.setOnPreferenceChangeListener(onSetAlarm);
    ListPreference delay = (ListPreference)findPreference("delayNotifications");
    delay.setOnPreferenceChangeListener(onDelayChange);
    CheckBoxPreference display = (CheckBoxPreference)findPreference("displaySilNotification");
    display.setOnPreferenceChangeListener(onDisplayChange);
    if (app.getPublicPreferenceB(Common.GLOBAL_SETTING_ISNOTIFON)) {
        preference.setChecked(true);
        delay.setEnabled(true);
        delay.setValueIndex(getIdByTime(app.account.getNotificationTime()));
        display.setEnabled(true);
        display.setChecked(app.getPublicPreferenceB(Common.GLOBAL_SETTING_NOTIFICATIONDISPLAY));
    } else {
        preference.setChecked(false);
        delay.setEnabled(false);
        display.setEnabled(false);
        display.setChecked(false);
    }
}
项目:RespawnIRC-Android    文件:SettingsFragment.java   
private static void updatePrefDefaultValue(Preference pref) {
    String realPrefKey = pref.getKey();
    pref.setPersistent(false);
    if (pref instanceof CheckBoxPreference) {
        pref.setKey("tmpKeyBool");
        CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
        checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof SwitchPreferenceCompat) {
        pref.setKey("tmpKeyBool");
        SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
        switchPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof EditTextPreference) {
        pref.setKey("tmpKeyString");
        EditTextPreference editTextPref = (EditTextPreference) pref;
        editTextPref.setText(PrefsManager.getString(realPrefKey));
    } else if (pref instanceof ListPreference) {
        pref.setKey("tmpKeyString");
        ListPreference listPref = (ListPreference) pref;
        listPref.setValue(PrefsManager.getString(realPrefKey));
    }
    pref.setPersistent(true);
    pref.setKey(realPrefKey);
}
项目:flavordex    文件:SettingsActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences);

    mPrefLocation = (CheckBoxPreference)findPreference(FlavordexApp.PREF_DETECT_LOCATION);
    mPrefAccount = (SwitchPreferenceCompat)findPreference(FlavordexApp.PREF_ACCOUNT);
    mPrefEditAccount = findPreference(PREF_EDIT_ACCOUNT);
    mPrefSyncData = (CheckBoxPreference)findPreference(FlavordexApp.PREF_SYNC_DATA);
    mPrefSyncPhotos = (CheckBoxPreference)findPreference(FlavordexApp.PREF_SYNC_PHOTOS);

    setupEditCatsPref();
    setupLocationPref();
    setupAccountPref();
    setupEditAccountPref();
    setupSyncDataPref();
    setupSyncPhotosPref();

    PreferenceManager.getDefaultSharedPreferences(getContext())
            .registerOnSharedPreferenceChangeListener(this);

    mAuth = FirebaseAuth.getInstance();
}
项目:libretorrent    文件:ProxySettingsFragment.java   
private void enableOrDisablePreferences(boolean enable)
{
    String keyAddress = getString(R.string.pref_key_proxy_address);
    EditTextPreference address = (EditTextPreference) findPreference(keyAddress);
    address.setEnabled(enable);

    String keyPort = getString(R.string.pref_key_proxy_port);
    EditTextPreference port = (EditTextPreference) findPreference(keyPort);
    port.setEnabled(enable);

    String keyProxyPeersToo = getString(R.string.pref_key_proxy_peers_too);
    SwitchPreferenceCompat proxyPeersToo = (SwitchPreferenceCompat) findPreference(keyProxyPeersToo);
    proxyPeersToo.setEnabled(enable);

    String keyForceProxy = getString(R.string.pref_key_force_proxy);
    SwitchPreferenceCompat forceProxy = (SwitchPreferenceCompat) findPreference(keyForceProxy);
    forceProxy.setEnabled(enable);

    String keyRequiresAuth = getString(R.string.pref_key_proxy_requires_auth);
    SwitchPreferenceCompat requiresAuth = (SwitchPreferenceCompat) findPreference(keyRequiresAuth);
    requiresAuth.setEnabled(enable);
}
项目:tazapp-android    文件:PreferencesFragment.java   
@Override
public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.app_preferences);
    PreferenceScreen mainPreferenceScreen = (PreferenceScreen) findPreference("mainPreferenceScreen");
    pushPreferenceCat = findPreference("pushCat");
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        Preference downloadNotificationCat = findPreference("downloadNotificationCat");
        mainPreferenceScreen.removePreference(downloadNotificationCat);

    }
    crashlyticsAlwaysSendPreference = (SwitchPreferenceCompat) findPreference(getString(R.string.pref_key_crashlytics_always_send));
    crashlyticsAlwaysSendPreference.setChecked(TazSettings.getInstance(getContext())
                                                          .getCrashlyticsAlwaysSend());
    crashlyticsAlwaysSendPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            TazSettings.getInstance(preference.getContext())
                       .setCrashlyticsAlwaysSend((Boolean) newValue);
            return true;
        }
    });
    setPushPrefState(!TextUtils.isEmpty(TazSettings.getInstance(getContext())
                                                   .getFirebaseToken()));
}
项目:discogsscrobbler    文件:SettingsActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.pref_discogs);

    SwitchPreferenceCompat sw = (SwitchPreferenceCompat) findPreference("enable_discogs");
    Discogs discogs = Discogs.getInstance(getContext());
    boolean loggedin = discogs.isLoggedIn();
    sw.setChecked(loggedin);
    if(loggedin) {
        sw.setSummaryOn("Signed in as " + discogs.getUser());
    }

    Preference preloadButton = findPreference("discogs_preload_collection");
    preloadButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            Discogs.getInstance(getActivity()).preloadCollection();
            return true;
        }
    });

}
项目:apps-android-wikipedia    文件:SettingsPreferenceLoader.java   
@Override public boolean onPreferenceChange(final Preference preference, Object newValue) {
    if (newValue == Boolean.TRUE) {
        ((SwitchPreferenceCompat) preference).setChecked(true);
        Prefs.setReadingListSyncEnabled(true);
        Prefs.setReadingListsRemoteSetupPending(true);
        Prefs.setReadingListsRemoteDeletePending(false);
        ReadingListSyncAdapter.manualSync();
    } else {
        new AlertDialog.Builder(getActivity())
                .setMessage(R.string.reading_lists_confirm_remote_delete)
                .setPositiveButton(R.string.reading_lists_confirm_remote_delete_yes, new DeleteRemoteListsYesListener(preference))
                .setNegativeButton(R.string.reading_lists_confirm_remote_delete_no, new DeleteRemoteListsNoListener(preference))
                .show();
    }
    // clicks are handled and preferences updated accordingly; don't pass the result through
    return false;
}
项目:CurrentActivity    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.settings);

    activity = this.getActivity();

    enableFloatWindowPreference = (SwitchPreferenceCompat) findPreference(ENABLE_FLOAT_WINDOW);
    bootCompletedPreference = (SwitchPreferenceCompat) findPreference(BOOT_COMPLETED);
    openMainActivityWhenQuickStartOrQuickStopPreference = (SwitchPreferenceCompat) findPreference(OPEN_MAIN_ACTIVITY_WHEN_QUICK_START_OR_QUICK_STOP);
    gestureClickPreference = (ListPreference) findPreference(GESTURE_CLICK);
    gestureLongPressPreference = (ListPreference) findPreference(GESTURE_LONG_PRESS);
    workingModePreference = (ListPreference) findPreference(WORKING_MODE);

    initFloatViewBroadcastReceiverHelper();
}
项目:WatchIt    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.app_preference);

    suggestions = (SwitchPreferenceCompat) findPreference("suggestions");

    suggestions.setOnPreferenceChangeListener(this);
}
项目:ProjectOxford-Apps-MimickerAlarm    文件:AlarmGlobalSettingsActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.pref_global);
    mSnoozeDuration = (ListPreference)findPreference(getString(R.string.pref_snooze_duration_key));
    mRingDuration = (ListPreference)findPreference(getString(R.string.pref_ring_duration_key));
    mAlarmVolume = (VolumeSliderPreference)findPreference(getString(R.string.pref_ring_volume_key));
    mEnableNotifications = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_notifications_key));
    mEnableReliability = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_reliability_key));
    mEnableReliability.setEnabled(mEnableNotifications.isChecked());
    setDefaultSummaryValues();
}
项目:DietDiaryApp    文件:SettingsSupportFragment.java   
private void activateBackup() {
    final SwitchPreferenceCompat backupActivePref = (SwitchPreferenceCompat) findPreference(KEY_BACKUP_ACTIVE_BOOL);
    if (!backupActivePref.isChecked()) {
        backupActivePref.setChecked(true);
    }

    changeProgressBarVisibility(false);
}
项目:libretorrent    文件:NetworkSettingsFragment.java   
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
    SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    if (preference instanceof SwitchPreferenceCompat) {
        pref.put(preference.getKey(), (boolean) newValue);
    } else if (preference.getKey().equals(getString(R.string.pref_key_port))) {
        int value = TorrentEngine.Settings.DEFAULT_PORT;
        if (!TextUtils.isEmpty((String) newValue)) {
            value = Integer.parseInt((String) newValue);
        }
        pref.put(preference.getKey(), value);
        preference.setSummary(Integer.toString(value));
    } else if (preference.getKey().equals(getString(R.string.pref_key_enc_mode))) {
        int type = Integer.parseInt((String) newValue);
        pref.put(preference.getKey(), type);
        String typesName[] = getResources().getStringArray(R.array.pref_enc_mode_entries);
        preference.setSummary(typesName[type]);

        boolean enableAdvancedEncryptSettings = type != Integer.parseInt(getString(R.string.pref_enc_mode_disable_value));

        String keyEncryptInConnections = getString(R.string.pref_key_enc_in_connections);
        SwitchPreferenceCompat encryptInConnections =
                (SwitchPreferenceCompat) findPreference(keyEncryptInConnections);
        encryptInConnections.setEnabled(enableAdvancedEncryptSettings);
        encryptInConnections.setChecked(enableAdvancedEncryptSettings);

        String keyEncryptOutConnections = getString(R.string.pref_key_enc_out_connections);
        SwitchPreferenceCompat encryptOutConnections =
                (SwitchPreferenceCompat) findPreference(keyEncryptOutConnections);
        encryptOutConnections.setEnabled(enableAdvancedEncryptSettings);
        encryptOutConnections.setChecked(enableAdvancedEncryptSettings);
    }

    return true;
}
项目:libretorrent    文件:StorageSettingsFragment.java   
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
    if (preference instanceof SwitchPreferenceCompat) {
        SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());
        pref.put(preference.getKey(), (boolean) newValue);
    }

    return true;
}
项目:libretorrent    文件:BehaviorSettingsFragment.java   
private void disableBatteryControl(SettingsManager pref)
{
    String keyBatteryControl = getString(R.string.pref_key_battery_control);
    SwitchPreferenceCompat batteryControl = (SwitchPreferenceCompat) findPreference(keyBatteryControl);
    batteryControl.setChecked(false);
    pref.put(batteryControl.getKey(), false);
    disableCustomBatteryControl(pref);
}
项目:libretorrent    文件:BehaviorSettingsFragment.java   
private void disableCustomBatteryControl(SettingsManager pref)
{
    String keyCustomBatteryControl = getString(R.string.pref_key_custom_battery_control);
    SwitchPreferenceCompat batteryControl = (SwitchPreferenceCompat) findPreference(keyCustomBatteryControl);
    batteryControl.setChecked(false);
    pref.put(batteryControl.getKey(), false);
}
项目:ProjectOxford-Apps-MimickerAlarm    文件:AlarmGlobalSettingsActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.pref_global);
    mSnoozeDuration = (ListPreference)findPreference(getString(R.string.pref_snooze_duration_key));
    mRingDuration = (ListPreference)findPreference(getString(R.string.pref_ring_duration_key));
    mAlarmVolume = (VolumeSliderPreference)findPreference(getString(R.string.pref_ring_volume_key));
    mEnableNotifications = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_notifications_key));
    mEnableReliability = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_reliability_key));
    mEnableReliability.setEnabled(mEnableNotifications.isChecked());
    setDefaultSummaryValues();
}
项目:ring-client-android    文件:GeneralAccountFragment.java   
@Override
public void accountChanged(Account account) {
    if (account == null) {
        Log.d(TAG, "accountChanged: Null account");
        return;
    }

    setPreferenceDetails(account.getConfig());

    SwitchPreferenceCompat pref = (SwitchPreferenceCompat) findPreference("Account.status");
    if (account.isSip() && pref != null) {
        String status;
        pref.setTitle(account.getAlias());
        if (account.isEnabled()) {
            if (account.isTrying()) {
                status = getString(R.string.account_status_connecting);
            } else if (account.needsMigration()) {
                status = getString(R.string.account_update_needed);
            } else if (account.isInError()) {
                status = getString(R.string.account_status_connection_error);
            } else if (account.isRegistered()) {
                status = getString(R.string.account_status_online);
            } else {
                status = getString(R.string.account_status_unknown);
            }
        } else {
            status = getString(R.string.account_status_offline);
        }
        pref.setSummary(status);
        pref.setChecked(account.isEnabled());

        // An ip2ip account is always ready
        pref.setEnabled(!account.isIP2IP());

        pref.setOnPreferenceChangeListener(changeAccountStatusListener);
    }

    setPreferenceListener(account.getConfig(), changeBasicPreferenceListener);
}
项目:GPSLogger    文件:FragmentSettings.java   
public void PrefEGM96SetToFalse() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor1 = settings.edit();
    editor1.putBoolean("prefEGM96AltitudeCorrection", false);
    editor1.commit();
    SwitchPreferenceCompat EGM96 = (SwitchPreferenceCompat) super.findPreference("prefEGM96AltitudeCorrection");
    EGM96.setChecked(false);
}
项目:GPSLogger    文件:FragmentSettings.java   
public void PrefEGM96SetToTrue() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor1 = settings.edit();
    editor1.putBoolean("prefEGM96AltitudeCorrection", true);
    editor1.commit();
    SwitchPreferenceCompat EGM96 = (SwitchPreferenceCompat) super.findPreference("prefEGM96AltitudeCorrection");
    EGM96.setChecked(true);
}
项目:android-money-manager-ex    文件:SyncPreferencesViewHolder.java   
public SyncPreferencesViewHolder(PreferenceFragmentCompat view) {

        syncEnabled = (SwitchPreferenceCompat) view.findPreference(view.getString(R.string.pref_sync_enabled));
        providerList = (ListPreference) view.findPreference(view.getString(R.string.pref_sync_provider));
        remoteFile = view.findPreference(view.getString(R.string.pref_remote_file));
        syncInterval = (ListPreference) view.findPreference(view.getString(R.string.pref_sync_interval));
        resetPreferences = view.findPreference(view.getString(R.string.pref_reset_preferences));
        download = (PreferenceScreen) view.findPreference(view.getString(R.string.pref_sync_download));
        upload = (PreferenceScreen) view.findPreference(view.getString(R.string.pref_sync_upload));
        syncOnStart = (SwitchPreferenceCompat) view.findPreference(view.getString(R.string.pref_sync_on_app_start));
    }
项目:Student    文件:Account.java   
void updatePreference()
{
    try
    {
        if(!mPref.getBoolean("isLogined",false))
        {
            findPreference("userId").setEnabled(true);
            findPreference("pwd").setEnabled(mPref.getString("userId","").length()>0);
            findPreference("login").setEnabled(mPref.getString("pwd","").length()>0);
            findPreference("login").setTitle(R.string.account_login);
            findPreference("login").setOnPreferenceClickListener(mLoginClick);
            findPreference("useAutoLogin").setEnabled(false);
            findPreference("useAutoLogin").setSummary(null);
            ((SwitchPreferenceCompat)findPreference("useAutoLogin")).setChecked(false);
        }
        else
        {
            findPreference("userId").setEnabled(false);
            findPreference("pwd").setEnabled(false);
            findPreference("login").setTitle(R.string.account_logout);
            findPreference("login").setOnPreferenceClickListener(mLogoutClick);
            findPreference("useAutoLogin").setEnabled(true);
            findPreference("useAutoLogin").setSummary(String.format(getString(R.string.account_useAutoLogin_summary),mPref.getString("userId","")));
        }
    }
    catch(Exception e)
    {
    }
}
项目:Student    文件:Account.java   
public void login()
{
    AccountManager.get(mContext).addAccountExplicitly(new android.accounts.Account(mPref.getString("userId",""),"kr.KENNYSOFT.Student.ACCOUNT"),null,null);
    ((SwitchPreferenceCompat)findPreference("useAutoLogin")).setChecked(true);
    SharedPreferences.Editor edit=mPref.edit();
    edit.putBoolean("isLogined",true);
    edit.putBoolean("useAutoLogin",true);
    edit.commit();
    updatePreference();
}
项目:discogsscrobbler    文件:SettingsActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.pref_lastfm);
    SwitchPreferenceCompat sw = (SwitchPreferenceCompat) findPreference("enable_lastfm");
    Lastfm lastfm = Lastfm.getInstance(getContext());
    boolean loggedin = lastfm.isLoggedIn();
    sw.setChecked(loggedin);
    if(loggedin) {
        sw.setSummaryOn("Signed in as " + lastfm.getUserName());
    }
}
项目:apps-android-wikipedia    文件:SettingsPreferenceLoader.java   
@Override public void onClick(DialogInterface dialog, int which) {
    ((SwitchPreferenceCompat) preference).setChecked(false);
    Prefs.setReadingListSyncEnabled(false);
    Prefs.setReadingListsRemoteSetupPending(false);
    Prefs.setReadingListsRemoteDeletePending(true);
    ReadingListSyncAdapter.manualSync();
}
项目:apps-android-wikipedia    文件:SettingsPreferenceLoader.java   
@Override public void onClick(DialogInterface dialog, int which) {
    ((SwitchPreferenceCompat) preference).setChecked(true);
    Prefs.setReadingListSyncEnabled(true);
    Prefs.setReadingListsRemoteSetupPending(true);
    Prefs.setReadingListsRemoteDeletePending(false);
    ReadingListSyncAdapter.manualSync();
}
项目:MTweaks-KernelAdiutorMOD    文件:SettingsFragment.java   
private void init() {
        addPreferencesFromResource(R.xml.settings);

        if (Utils.DONATED) {
            getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
        }

        SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
        if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
            getPreferenceScreen().removePreference(forceEnglish);
        } else {
            forceEnglish.setOnPreferenceChangeListener(this);
        }
/*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
        findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
        findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
        findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
        findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
        findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
        findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
        findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
        findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
        findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
        findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

        if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
            findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
        } else {
            ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
                    findPreference(KEY_LAST_KMSG));
        }

        findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
        findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
        findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
                || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
            ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(
                    findPreference(KEY_FINGERPRINT));
        } else {
            mFingerprint = findPreference(KEY_FINGERPRINT);
            mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
        }

        PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
        for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) {
            Fragment fragment = navigationFragment.mFragment;
            int id = navigationFragment.mId;

            if (fragment != null && fragment.getClass() != SettingsFragment.class) {
                SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                        new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
                switchPreference.setSummary(getString(id));
                switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled");
                switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName()
                        + "_enabled", true, getActivity()));
                switchPreference.setOnPreferenceChangeListener(this);
                switchPreference.setPersistent(false);
                sectionsCategory.addPreference(switchPreference);
            }
        }
    }
项目:KernelAdiutor-Mod    文件:SettingsFragment.java   
private void init() {
    addPreferencesFromResource(R.xml.settings);

    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }

    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }

    if (Utils.hideStartActivity()) {
        ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                .removePreference(findPreference(KEY_MATERIAL_ICON));
    } else {
        findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
    }

    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
                findPreference(KEY_LAST_KMSG));
    }

    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
            || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(
                findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
    }

    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;

        if (fragment != null && fragment.getClass() != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                    new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled");
            switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName()
                    + "_enabled", true, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(false);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}
项目:libretorrent    文件:ProxySettingsFragment.java   
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    boolean enableAdvancedSettings;

    String keyProxyType = getString(R.string.pref_key_proxy_type);
    ListPreference proxyType = (ListPreference) findPreference(keyProxyType);
    int type = pref.getInt(keyProxyType, SettingsManager.Default.proxyType);
    proxyType.setValueIndex(type);
    String typesName[] = getResources().getStringArray(R.array.pref_proxy_type_entries);
    proxyType.setSummary(typesName[type]);
    enableAdvancedSettings = type != Integer.parseInt(getString(R.string.pref_proxy_type_none_value));
    bindOnPreferenceChangeListener(proxyType);

    String keyAddress = getString(R.string.pref_key_proxy_address);
    EditTextPreference address = (EditTextPreference) findPreference(keyAddress);
    address.setEnabled(enableAdvancedSettings);
    String addressValue = pref.getString(keyAddress, SettingsManager.Default.proxyAddress);
    address.setText(addressValue);
    address.setSummary(addressValue);
    bindOnPreferenceChangeListener(address);

    String keyPort = getString(R.string.pref_key_proxy_port);
    EditTextPreference port = (EditTextPreference) findPreference(keyPort);
    port.setEnabled(enableAdvancedSettings);
    InputFilter[] portFilter =
            new InputFilter[]{new InputFilterMinMax(0, 10000)};
    int portNumber = pref.getInt(keyPort, SettingsManager.Default.proxyPort);
    String portValue = Integer.toString(portNumber);
    port.getEditText().setFilters(portFilter);
    port.setSummary(portValue);
    port.setText(portValue);
    bindOnPreferenceChangeListener(port);

    String keyProxyPeersToo = getString(R.string.pref_key_proxy_peers_too);
    SwitchPreferenceCompat proxyPeersToo = (SwitchPreferenceCompat) findPreference(keyProxyPeersToo);
    proxyPeersToo.setEnabled(enableAdvancedSettings);
    proxyPeersToo.setChecked(pref.getBoolean(keyProxyPeersToo, SettingsManager.Default.proxyPeersToo));
    bindOnPreferenceChangeListener(proxyPeersToo);

    String keyForceProxy = getString(R.string.pref_key_force_proxy);
    SwitchPreferenceCompat forceProxy = (SwitchPreferenceCompat) findPreference(keyForceProxy);
    forceProxy.setEnabled(enableAdvancedSettings);
    forceProxy.setChecked(pref.getBoolean(keyForceProxy, SettingsManager.Default.forceProxy));
    bindOnPreferenceChangeListener(forceProxy);

    String keyRequiresAuth = getString(R.string.pref_key_proxy_requires_auth);
    SwitchPreferenceCompat requiresAuth = (SwitchPreferenceCompat) findPreference(keyRequiresAuth);
    requiresAuth.setEnabled(enableAdvancedSettings);
    requiresAuth.setChecked(pref.getBoolean(keyRequiresAuth, SettingsManager.Default.proxyRequiresAuth));
    bindOnPreferenceChangeListener(requiresAuth);

    String keyLogin = getString(R.string.pref_key_proxy_login);
    EditTextPreference login = (EditTextPreference) findPreference(keyLogin);
    String loginValue = pref.getString(keyLogin, SettingsManager.Default.proxyLogin);
    login.setText(loginValue);
    login.setSummary(loginValue);
    bindOnPreferenceChangeListener(login);

    String keyPassword = getString(R.string.pref_key_proxy_password);
    EditTextPreference password = (EditTextPreference) findPreference(keyPassword);
    String passwordValue = pref.getString(keyPassword, SettingsManager.Default.proxyPassword);
    password.setText(passwordValue);
    EditText edit = password.getEditText();
    password.setSummary(edit.getTransformationMethod().getTransformation(passwordValue, edit).toString());
    bindOnPreferenceChangeListener(password);
}
项目:libretorrent    文件:ProxySettingsFragment.java   
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
    SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    if (preference.getKey().equals(getString(R.string.pref_key_proxy_type))) {
        int type = Integer.parseInt((String) newValue);
        pref.put(preference.getKey(), type);
        String typesName[] = getResources().getStringArray(R.array.pref_proxy_type_entries);
        preference.setSummary(typesName[type]);

        boolean enableAdvancedSettings = type != Integer.parseInt(getString(R.string.pref_proxy_type_none_value));
        enableOrDisablePreferences(enableAdvancedSettings);

    } else if (preference.getKey().equals(getString(R.string.pref_key_proxy_port))) {
        int value = SettingsManager.Default.proxyPort;
        if (!TextUtils.isEmpty((String) newValue))
            value = Integer.parseInt((String) newValue);

        pref.put(preference.getKey(), value);
        preference.setSummary(Integer.toString(value));

    } else if (preference.getKey().equals(getString(R.string.pref_key_proxy_address)) ||
            preference.getKey().equals(getString(R.string.pref_key_proxy_login))) {
        pref.put(preference.getKey(), (String) newValue);
        preference.setSummary((String) newValue);

    } else if (preference.getKey().equals(getString(R.string.pref_key_proxy_password))) {
        pref.put(preference.getKey(), (String) newValue);
        EditText edit = ((EditTextPreference) preference).getEditText();
        String passwordValue = edit.getTransformationMethod().getTransformation((String) newValue, edit).toString();
        preference.setSummary(passwordValue);

    } else if (preference instanceof SwitchPreferenceCompat) {
        pref.put(preference.getKey(), (boolean) newValue);
    }

    if (!proxyChanged) {
        proxyChanged = true;
        pref.put(getString(R.string.pref_key_proxy_changed), true);
    }

    return true;
}
项目:libretorrent    文件:BehaviorSettingsFragment.java   
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    final SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());

    String keyAutostart = getString(R.string.pref_key_autostart);
    SwitchPreferenceCompat autostart = (SwitchPreferenceCompat) findPreference(keyAutostart);
    autostart.setChecked(pref.getBoolean(keyAutostart, SettingsManager.Default.autostart));
    bindOnPreferenceChangeListener(autostart);

    String keyKeepAlive = getString(R.string.pref_key_keep_alive);
    SwitchPreferenceCompat keepAlive = (SwitchPreferenceCompat) findPreference(keyKeepAlive);
    keepAlive.setChecked(pref.getBoolean(keyKeepAlive, SettingsManager.Default.keepAlive));
    bindOnPreferenceChangeListener(keepAlive);

    String keyShutdownComplete = getString(R.string.pref_key_shutdown_downloads_complete);
    SwitchPreferenceCompat shutdownComplete = (SwitchPreferenceCompat) findPreference(keyShutdownComplete);
    shutdownComplete.setChecked(pref.getBoolean(keyShutdownComplete, SettingsManager.Default.shutdownDownloadsComplete));
    bindOnPreferenceChangeListener(shutdownComplete);

    String keyCpuSleep = getString(R.string.pref_key_cpu_do_not_sleep);
    SwitchPreferenceCompat cpuSleep = (SwitchPreferenceCompat) findPreference(keyCpuSleep);
    cpuSleep.setChecked(pref.getBoolean(keyCpuSleep, SettingsManager.Default.cpuDoNotSleep));
    bindOnPreferenceChangeListener(cpuSleep);

    String keyOnlyCharging = getString(R.string.pref_key_download_and_upload_only_when_charging);
    SwitchPreferenceCompat onlyCharging = (SwitchPreferenceCompat) findPreference(keyOnlyCharging);
    onlyCharging.setChecked(pref.getBoolean(keyOnlyCharging, SettingsManager.Default.onlyCharging));
    bindOnPreferenceChangeListener(onlyCharging);

    String keyBatteryControl = getString(R.string.pref_key_battery_control);
    SwitchPreferenceCompat batteryControl = (SwitchPreferenceCompat) findPreference(keyBatteryControl);
    batteryControl.setSummary(String.format(getString(R.string.pref_battery_control_summary),
                              Utils.getDefaultBatteryLowLevel()));
    batteryControl.setChecked(pref.getBoolean(keyBatteryControl, SettingsManager.Default.batteryControl));
    bindOnPreferenceChangeListener(batteryControl);

    String keyCustomBatteryControl = getString(R.string.pref_key_custom_battery_control);
    SwitchPreferenceCompat customBatteryControl = (SwitchPreferenceCompat) findPreference(keyCustomBatteryControl);
    customBatteryControl.setSummary(String.format(getString(R.string.pref_custom_battery_control_summary),
            Utils.getDefaultBatteryLowLevel()));
    customBatteryControl.setChecked(pref.getBoolean(keyCustomBatteryControl, SettingsManager.Default.customBatteryControl));
    bindOnPreferenceChangeListener(customBatteryControl);

    String keyCustomBatteryControlValue = getString(R.string.pref_key_custom_battery_control_value);
    SeekBarPreference customBatteryControlValue = (SeekBarPreference) findPreference(keyCustomBatteryControlValue);
    customBatteryControlValue.setValue(pref.getInt(keyCustomBatteryControlValue, Utils.getDefaultBatteryLowLevel()));
    customBatteryControlValue.setMin(10);
    customBatteryControlValue.setMax(90);
    bindOnPreferenceChangeListener(customBatteryControlValue);

    String keyWifiOnly = getString(R.string.pref_key_wifi_only);
    SwitchPreferenceCompat wifiOnly = (SwitchPreferenceCompat) findPreference(keyWifiOnly);
    wifiOnly.setChecked(pref.getBoolean(keyWifiOnly, SettingsManager.Default.wifiOnly));
    bindOnPreferenceChangeListener(wifiOnly);
}
项目:ureport-android    文件:GeneralSettingsFragment.java   
private void setupView() {
    publicProfilePreference = (SwitchPreferenceCompat)getPreferenceManager().findPreference(PUBLIC_PROFILE_KEY);
    publicProfilePreference.setOnPreferenceChangeListener(onPublicProfilePreferenceChangeListener);
}
项目:buseta    文件:SettingActivity.java   
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

    mActivity = super.getActivity();
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    // Set Default values from XML attribute
    PreferenceManager.setDefaultValues(mActivity, R.xml.preferences, false);
    // Set Summary
    initSummary(getPreferenceScreen());
    // Clear History
    Preference clearHistory = getPreferenceScreen().findPreference("clear_history");
    clearHistory.setOnPreferenceClickListener(this);
    // Clear Follow / Clear All Route Data
    Preference clearFollow = getPreferenceScreen().findPreference("clear_follow");
    clearFollow.setOnPreferenceClickListener(this);
    // Permission - Location
    locationPermission = (SwitchPreferenceCompat) getPreferenceScreen().findPreference("location_permission");
    if (locationPermission != null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            locationPermission.setEnabled(false);
            locationPermission.setChecked(true);
        } else {
            locationPermission.setOnPreferenceClickListener(this);
            Boolean granted = ContextCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
            locationPermission.setChecked(granted);
        }
    }
    // App Name
    Preference appName = getPreferenceScreen().findPreference("app_name");
    appName.setTitle(getString(R.string.title_app_name, getString(R.string.app_name)));
    // App Version
    Preference appVersion = getPreferenceScreen().findPreference("app_version");
    final int versionCode = BuildConfig.VERSION_CODE;
    final String versionName = BuildConfig.VERSION_NAME;
    appVersion.setSummary(versionName);
    if (BuildConfig.DEBUG) {
        appVersion.setSummary(versionName + "(" + versionCode +")");
    }
    // Developer
    Preference developer = getPreferenceScreen().findPreference("developer");
    developer.setSummary(getString(R.string.summary_developer) + " (" + getString(R.string.url_developer) + ")");
    //
    Preference shareApp = getPreferenceScreen().findPreference("share_app");
    shareApp.setOnPreferenceClickListener(this);
    // hide ad
    SwitchPreferenceCompat hideAd = (SwitchPreferenceCompat) getPreferenceScreen().findPreference(C.PREF.AD_HIDE);
    if (hideAd != null) {
        hideAd.setVisible(false);
        hideAd.setOnPreferenceClickListener(preference -> {
            SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) preference;
            if (switchPref.isChecked()) {
                final Snackbar snackbar = Snackbar.make(mActivity.findViewById(android.R.id.content),
                        R.string.message_hide_ad, Snackbar.LENGTH_LONG);
                snackbar.show();
            }
            return true;
        });
    }
    //
    Preference checkAppUpdate = getPreferenceScreen().findPreference("check_app_update");
    checkAppUpdate.setOnPreferenceClickListener(this);

    // Set up a listener whenever a key changes
    PreferenceManager.getDefaultSharedPreferences(mActivity)
            .registerOnSharedPreferenceChangeListener(this);
}
项目:KernelAdiutor    文件:SettingsFragment.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);

    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }

    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }

    if (Utils.hideStartActivity()) {
        ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                .removePreference(findPreference(KEY_MATERIAL_ICON));
    } else {
        findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
    }

    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
                findPreference(KEY_LAST_KMSG));
    }

    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
            || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(
                findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
    }

    NavigationActivity activity = (NavigationActivity) getActivity();
    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
        Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
        int id = navigationFragment.mId;

        if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                    new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
            switchPreference.setChecked(Prefs.getBoolean(fragmentClass.getSimpleName()
                    + "_enabled", true, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(false);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}
项目:siarhei.luskanau.gps.tracker.free    文件:GeneralSettingsFragment.java   
private void onAdPreferenceCreate() {
    SwitchPreferenceCompat switchPreferenceCompat = (SwitchPreferenceCompat) findPreference(getString(R.string.preference_key_disable_ad));
    switchPreferenceCompat.setIcon(getIcon(R.drawable.ic_settings_24dp));
    switchPreferenceCompat.setEnabled(false);
}
项目:apps-android-wikipedia    文件:SettingsFragment.java   
public void updateOfflineLibraryPref(boolean checked) {
    ((SwitchPreferenceCompat) preferenceLoader.findPreference(R.string.preference_key_enable_offline_library))
            .setChecked(checked);
}