Example usage for android.preference CheckBoxPreference setChecked

List of usage examples for android.preference CheckBoxPreference setChecked

Introduction

In this page you can find the example usage for android.preference CheckBoxPreference setChecked.

Prototype

public void setChecked(boolean checked) 

Source Link

Document

Sets the checked state and saves it to the SharedPreferences .

Usage

From source file:org.linphone.LinphoneService.java

public void ecCalibrationStatus(final LinphoneCore lc, final EcCalibratorStatus status, final int delay_ms,
        final Object data) {
    final CheckBoxPreference pref = (CheckBoxPreference) data;
    mHandler.post(new Runnable() {
        public void run() {
            if (status == EcCalibratorStatus.Done) {
                pref.setSummary(String.format(getString(R.string.ec_calibrated), delay_ms));
                pref.setChecked(true);

            } else if (status == EcCalibratorStatus.Failed) {
                pref.setSummary(R.string.failed);
                pref.setChecked(false);/*from   w  w w  .ja  v  a  2s.  co m*/
            }
        }
    });
}

From source file:com.googlecode.mindbell.MindBellPreferences.java

private void handleMuteHookOffAndStatusPermissionRequestResult(CheckBoxPreference one, int[] grantResults) {
    if (grantResults.length == 0) {
        // if request is cancelled, the result arrays are empty, so leave this option "off" and don't explain it
    } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        // User granted the needed permission therefore this option is set to "on"
        if (one.getOnPreferenceChangeListener().onPreferenceChange(one, Boolean.TRUE)) {
            one.setChecked(true); // WARNING: This does NOT call the onPreferenceValueChangeListener
        }/*  www  .j  a  v  a2  s  . co  m*/
    } else if (ActivityCompat.shouldShowRequestPermissionRationale(MindBellPreferences.this,
            Manifest.permission.READ_PHONE_STATE)) {
        // User denied the needed permission and can be given an explanation, so we show an explanation
        new AlertDialog.Builder(MindBellPreferences.this) //
                .setTitle(R.string.reasonReadPhoneStateTitle) //
                .setMessage(R.string.reasonReadPhoneStateText) //
                .setPositiveButton(android.R.string.ok, null) //
                .create() //
                .show();
    } else {
        // User denied the needed permission and checked never ask again
        new AlertDialog.Builder(MindBellPreferences.this) //
                .setTitle(R.string.neverAskAgainReadPhoneStateTitle) //
                .setMessage(R.string.neverAskAgainReadPhoneStateText) //
                .setPositiveButton(android.R.string.ok, null) //
                .create()//
                .show();
    }
}

From source file:org.linphone.SettingsFragment.java

private void initAudioSettings() {
    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_codecs_key));
    if (codecs == null)
        return;/*from  w  ww. j ava2  s  .c o  m*/

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getAudioCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());
        codec.setSummary(pt.getRate() + " Hz");
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(
            getString(R.string.pref_echo_cancellation_key));
    echoCancellation.setChecked(mPrefs.isEchoCancellationEnabled());

    if (mPrefs.isEchoCancellationEnabled()) {
        Preference echoCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
        echoCalibration
                .setSummary(String.format(getString(R.string.ec_calibrated), mPrefs.getEchoCalibration()));
    }

    CheckBoxPreference adaptiveRateControl = (CheckBoxPreference) findPreference(
            getString(R.string.pref_adaptive_rate_control_key));
    adaptiveRateControl.setChecked(mPrefs.isAdaptiveRateControlEnabled());

    ListPreference adaptiveRateAlgorithm = (ListPreference) findPreference(
            getString(R.string.pref_adaptive_rate_algorithm_key));
    adaptiveRateAlgorithm.setSummary(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));
    adaptiveRateAlgorithm.setValue(String.valueOf(mPrefs.getAdaptiveRateAlgorithm()));

    ListPreference bitrateLimit = (ListPreference) findPreference(
            getString(R.string.pref_codec_bitrate_limit_key));
    bitrateLimit.setSummary(String.valueOf(mPrefs.getCodecBitrateLimit()));
    bitrateLimit.setValue(String.valueOf(mPrefs.getCodecBitrateLimit()));
}

From source file:org.linphone.SettingsFragment.java

private void setCallPreferencesListener() {
    findPreference(getString(R.string.pref_rfc2833_dtmf_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override//from   w w  w  .  j  av a 2  s .c  o m
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean use = (Boolean) newValue;
                    CheckBoxPreference sipInfo = (CheckBoxPreference) findPreference(
                            getString(R.string.pref_sipinfo_dtmf_key));
                    sipInfo.setEnabled(!use);
                    sipInfo.setChecked(false);
                    mPrefs.sendDtmfsAsRfc2833(use);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_sipinfo_dtmf_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean use = (Boolean) newValue;
                    CheckBoxPreference rfc2833 = (CheckBoxPreference) findPreference(
                            getString(R.string.pref_rfc2833_dtmf_key));
                    rfc2833.setEnabled(!use);
                    rfc2833.setChecked(false);
                    mPrefs.sendDTMFsAsSipInfo(use);
                    return true;
                }
            });
}

From source file:org.linphone.SettingsFragment.java

private void initNetworkSettings() {
    initMediaEncryptionPreference(/* www  .j  a  v  a 2s  .  c o  m*/
            (ListPreference) findPreference(getString(R.string.pref_media_encryption_key)));

    ((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key)))
            .setChecked(mPrefs.isWifiOnlyEnabled());

    // Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled
    CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key));
    CheckBoxPreference upnp = (CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key));
    ice.setChecked(mPrefs.isIceEnabled());
    if (mPrefs.isIceEnabled()) {
        upnp.setEnabled(false);
    } else {
        upnp.setChecked(mPrefs.isUpnpEnabled());
        if (mPrefs.isUpnpEnabled()) {
            ice.setEnabled(false);
        }
    }

    CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(
            getString(R.string.pref_transport_use_random_ports_key));
    randomPort.setChecked(mPrefs.isUsingRandomPort());

    // Disable sip port choice if port is random
    EditTextPreference sipPort = (EditTextPreference) findPreference(getString(R.string.pref_sip_port_key));
    sipPort.setEnabled(!randomPort.isChecked());
    sipPort.setSummary(mPrefs.getSipPort());
    sipPort.setText(mPrefs.getSipPort());

    EditTextPreference stun = (EditTextPreference) findPreference(getString(R.string.pref_stun_server_key));
    stun.setSummary(mPrefs.getStunServer());
    stun.setText(mPrefs.getStunServer());

    ((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key)))
            .setChecked(mPrefs.isPushNotificationEnabled());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6());
}

From source file:org.linphone.SettingsFragment.java

private void initCallSettings() {
    CheckBoxPreference rfc2833 = (CheckBoxPreference) findPreference(getString(R.string.pref_rfc2833_dtmf_key));
    CheckBoxPreference sipInfo = (CheckBoxPreference) findPreference(getString(R.string.pref_sipinfo_dtmf_key));
    if (mPrefs.useRfc2833Dtmfs()) {
        rfc2833.setChecked(true);
        sipInfo.setChecked(false);//from w ww  .  j a v a 2 s  .  c  o  m
        sipInfo.setEnabled(false);
    } else if (mPrefs.useSipInfoDtmfs()) {
        sipInfo.setChecked(true);
        rfc2833.setChecked(false);
        rfc2833.setEnabled(false);
    }
}

From source file:org.linphone.SettingsFragment.java

private void setNetworkPreferencesListener() {
    findPreference(getString(R.string.pref_wifi_only_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override/*from  ww  w  . j  a va  2 s . c om*/
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mPrefs.setWifiOnlyEnabled((Boolean) newValue);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_stun_server_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mPrefs.setStunServer(newValue.toString());
                    preference.setSummary(newValue.toString());
                    return true;
                }
            });

    findPreference(getString(R.string.pref_ice_enable_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    CheckBoxPreference upnp = (CheckBoxPreference) findPreference(
                            getString(R.string.pref_upnp_enable_key));
                    boolean value = (Boolean) newValue;
                    upnp.setChecked(false);
                    upnp.setEnabled(!value);
                    mPrefs.setIceEnabled((Boolean) newValue);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_upnp_enable_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    CheckBoxPreference ice = (CheckBoxPreference) findPreference(
                            getString(R.string.pref_ice_enable_key));
                    boolean value = (Boolean) newValue;
                    ice.setChecked(false);
                    ice.setEnabled(!value);
                    mPrefs.setUpnpEnabled(value);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_transport_use_random_ports_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean randomPort = (Boolean) newValue;
                    mPrefs.useRandomPort((Boolean) newValue);
                    findPreference(getString(R.string.pref_sip_port_key)).setEnabled(!randomPort);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_sip_port_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    int port = -1;
                    try {
                        port = Integer.parseInt(newValue.toString());
                    } catch (NumberFormatException nfe) {
                    }

                    mPrefs.setSipPort(port);
                    preference.setSummary(newValue.toString());
                    return true;
                }
            });

    findPreference(getString(R.string.pref_media_encryption_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    String value = newValue.toString();
                    MediaEncryption menc = MediaEncryption.None;
                    if (value.equals(getString(R.string.pref_media_encryption_key_srtp)))
                        menc = MediaEncryption.SRTP;
                    else if (value.equals(getString(R.string.pref_media_encryption_key_zrtp)))
                        menc = MediaEncryption.ZRTP;
                    mPrefs.setMediaEncryption(menc);

                    preference.setSummary(mPrefs.getMediaEncryption().toString());
                    return true;
                }
            });

    findPreference(getString(R.string.pref_push_notification_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mPrefs.setPushNotificationEnabled((Boolean) newValue);
                    return true;
                }
            });

    findPreference(getString(R.string.pref_ipv6_key))
            .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    mPrefs.useIpv6((Boolean) newValue);
                    return true;
                }
            });
}

From source file:org.linphone.SettingsFragment.java

@Override
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
    //getActivity().setTheme(R.style.Holo_Theme_Light);
    mHandler.post(new Runnable() {
        public void run() {
            CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(
                    getString(R.string.pref_echo_cancellation_key));
            Preference echoCancellerCalibration = findPreference(
                    getString(R.string.pref_echo_canceller_calibration_key));

            if (status == EcCalibratorStatus.DoneNoEcho) {
                echoCancellerCalibration.setSummary(R.string.no_echo);
                echoCancellation.setChecked(false);
                LinphonePreferences.instance().setEchoCancellation(false);
            } else if (status == EcCalibratorStatus.Done) {
                echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
                echoCancellation.setChecked(true);
                LinphonePreferences.instance().setEchoCancellation(true);
            } else if (status == EcCalibratorStatus.Failed) {
                echoCancellerCalibration.setSummary(R.string.failed);
                echoCancellation.setChecked(true);
                LinphonePreferences.instance().setEchoCancellation(true);
            }//w w  w.  j a  v  a  2  s  .  co m
        }
    });
}

From source file:org.linphone.SettingsFragment.java

private void initVideoSettings() {
    initializePreferredVideoSizePreferences(
            (ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));

    PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));

    if (codecs == null)
        return;//from w w w.j a  va2  s .  com

    codecs.removeAll();

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    for (final PayloadType pt : lc.getVideoCodecs()) {
        CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
        codec.setTitle(pt.getMime());

        if (!pt.getMime().equals("VP8")) {
            if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
                continue;
            } else {
                if (!Version.hasFastCpuWithAsmOptim() && pt.getMime().equals("H264")) {
                    // Android without neon doesn't support H264
                    Log.w("CPU does not have asm optimisations available, disabling H264");
                    continue;
                }
            }
        }
        codec.setChecked(lc.isPayloadTypeEnabled(pt));

        codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enable = (Boolean) newValue;
                try {
                    LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
                } catch (LinphoneCoreException e) {
                    e.printStackTrace();
                }
                return true;
            }
        });

        codecs.addPreference(codec);
    }

    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_enable_key)))
            .setChecked(mPrefs.isVideoEnabled());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_use_front_camera_key)))
            .setChecked(mPrefs.useFrontCam());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_initiate_call_with_video_key)))
            .setChecked(mPrefs.shouldInitiateVideoCall());
    //((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_share_my_video_key))).setChecked(mPrefs.shouldAutomaticallyShareMyVideo());
    ((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key)))
            .setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}

From source file:com.nttec.everychan.chans.fourchan.FourchanModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasscodePreference(preferenceGroup);

    CheckBoxPreference newRecaptchaPref = new LazyPreferences.CheckBoxPreference(context);
    newRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha);
    newRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_summary);
    newRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA));
    newRecaptchaPref.setDefaultValue(NEW_RECAPTCHA_DEFAULT);
    preferenceGroup.addPreference(newRecaptchaPref);

    final CheckBoxPreference fallbackRecaptchaPref = new LazyPreferences.CheckBoxPreference(context);
    fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback);
    fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary);
    fallbackRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA_FALLBACK));
    fallbackRecaptchaPref.setDefaultValue(false);
    preferenceGroup.addPreference(fallbackRecaptchaPref);
    fallbackRecaptchaPref.setDependency(getSharedKey(PREF_KEY_NEW_RECAPTCHA));

    addPasswordPreference(preferenceGroup);
    addHttpsPreference(preferenceGroup, true);
    addProxyPreferences(preferenceGroup);

    final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup
            .findPreference(getSharedKey(PREF_KEY_USE_PROXY));
    fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
    proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from w w w . j  a va2 s  . co  m
        public boolean onPreferenceClick(Preference preference) {
            fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
            if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked())
                fallbackRecaptchaPref.setChecked(true);
            return false;
        }
    });
}