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:bander.notepad.PrefsFragment.java

private void setSortAscendingEnabled(boolean enabled) {
    CheckBoxPreference sortAscendingPreference = (CheckBoxPreference) findPreference(KEY_SORTASCENDING);
    sortAscendingPreference.setEnabled(enabled);
    if (!enabled)
        sortAscendingPreference.setChecked(true);
}

From source file:com.tinfoil.sms.settings.QuickPrefsActivity.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void setKitKatPref() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        CheckBoxPreference p = (CheckBoxPreference) findPreference(NATIVE_SAVE_SETTING_KEY);
        p.setChecked(false);
        p.setEnabled(false);/*from w  w w.  jav  a  2 s  .  co  m*/
    }
}

From source file:com.adam.aslfms.MusicAppsActivity.java

private void update() {
    mSupportedMusicAppsList.removeAll();
    mPrefsToMapisMap.clear();/*w ww  .  ja v a2  s.co  m*/
    mMapisToPrefsMap.clear();

    MusicAPI[] mapis = MusicAPI.all(this);
    for (MusicAPI mapi : mapis) {
        CheckBoxPreference appPref = new CheckBoxPreference(this, null);
        appPref.setTitle(mapi.getName());
        appPref.setPersistent(false);
        appPref.setChecked(mapi.isEnabled());

        mSupportedMusicAppsList.addPreference(appPref);
        mPrefsToMapisMap.put(appPref, mapi);
        mMapisToPrefsMap.put(mapi, appPref);
        setSMASummary(appPref, mapi);
    }

    // explanation text, for what this screen does
    Preference detect = new Preference(this);
    if (mapis.length == 0)
        detect.setTitle(R.string.no_supported_mapis_title);
    else if (mapis.length == 1)
        detect.setTitle(R.string.find_supported_mapis_one_title);
    else
        detect.setTitle(getString(R.string.find_supported_mapis_many_title).replace("%1",
                Integer.toString(mapis.length)));
    detect.setSummary(R.string.find_supported_mapis_summary);
    mSupportedMusicAppsList.addPreference(detect);
}

From source file:com.android.settings.locationprivacy.LocationPrivacyAdvancedSettings.java

private void refresh() {
    for (int i = 0; i < screen.getPreferenceCount(); i++) {
        Preference pref = screen.getPreference(i);
        if (pref != null) {
            System.out.println(pref);
            String key = pref.getKey();
            if (key != null) {
                System.out.println(key);
                if (key.equals("lp_settings_advanced_useonlinealgorithm")) {
                    CheckBoxPreference checkPref = (CheckBoxPreference) pref;
                    checkPref.setChecked(lpManager.isUseOnlineAlgorithm());
                } else if (key.equals("lp_settings_advanced_shareprivacyaettings")) {
                    CheckBoxPreference checkPref = (CheckBoxPreference) pref;
                    checkPref.setChecked(lpManager.isSharePrivacySettings());
                    checkPref.setEnabled(GooglePlayServicesUtil
                            .isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS
                            && lpManager.isWebhostShareSettings()
                            && AccountManager.get(getActivity()).getAccountsByType("com.google").length >= 1);
                } else if (key.equals("lp_settings_advanced_showcommunityadvice")) {
                    CheckBoxPreference checkPref = (CheckBoxPreference) pref;
                    checkPref.setChecked(lpManager.isShowCommunityAdvice());
                    checkPref.setEnabled(lpManager.isShowCommunityAdvice());
                } else if (key.equals("lp_settings_advanced_stars")) {
                    CheckBoxPreference checkPref = (CheckBoxPreference) pref;
                    checkPref.setChecked(lpManager.isUseStarsInDialog());
                } else if (key.equals("lp_settings_advanced_webservice")) {
                    EditTextPreference editTextPref = (EditTextPreference) pref;
                    editTextPref.setText("" + lpManager.getWebserviceHostAdress());
                } else if (key.equals("lp_settings_advanced_setpreset_min")) {
                    EditTextPreference editTextPref = (EditTextPreference) pref;
                    editTextPref.setText("" + lpManager.getMinDistance());
                }//from www .  j  a  v a2  s  .co m
                pref.setOnPreferenceChangeListener(this);
                pref.setOnPreferenceClickListener(this);
            }

        }
    }

}

From source file:com.chess.genesis.activity.Settings.java

@Override
public boolean handleMessage(final Message msg) {
    final JSONObject json = (JSONObject) msg.obj;
    try {/*from  ww w.  j a va2 s  . co m*/
        if (json.getString("result").equals("error")) {
            progress.remove();
            Toast.makeText(context, "ERROR:\n" + json.getString("reason"), Toast.LENGTH_LONG).show();
            return true;
        }
        switch (msg.what) {
        case NetworkClient.GET_OPTION:
            // only emailnote supported
            final CheckBoxPreference email = (CheckBoxPreference) findPreference(
                    Pref.key(context, R.array.pf_emailNoteEnabled));
            email.setChecked(json.getBoolean("value"));

            progress.remove();
            break;
        case NetworkClient.SET_OPTION:
            progress.remove();
            break;
        case SyncClient.MSG:
            final GameDataDB db = new GameDataDB(context);
            db.recalcYourTurn();
            db.close();
            progress.remove();
            break;
        }
        return true;
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:de.badaix.snapcast.GroupSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.group_preferences);
    PreferenceScreen screen = this.getPreferenceScreen();

    prefStreams = (ListPreference) findPreference("pref_stream");

    Bundle bundle = getArguments();/*ww w.ja v a  2s.  c  om*/
    try {
        group = new Group(new JSONObject(bundle.getString("group")));
        serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus")));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    final ArrayList<Stream> streams = serverStatus.getStreams();
    final CharSequence[] streamNames = new CharSequence[streams.size()];
    final CharSequence[] streamIds = new CharSequence[streams.size()];
    for (int i = 0; i < streams.size(); ++i) {
        streamNames[i] = streams.get(i).getName();
        streamIds[i] = streams.get(i).getId();
    }

    prefStreams.setEntries(streamNames);
    prefStreams.setEntryValues(streamIds);

    for (int i = 0; i < streams.size(); ++i) {
        if (streamIds[i].equals(group.getStreamId())) {
            prefStreams.setTitle(streamNames[i]);
            prefStreams.setValueIndex(i);
            oldStream = prefStreams.getValue();
            break;
        }
    }

    prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            for (int i = 0; i < streams.size(); ++i) {
                if (streamIds[i].equals(newValue)) {
                    prefStreams.setTitle(streamNames[i]);
                    //                        client.getConfig().setStream(streamIds[i].toString());
                    prefStreams.setValueIndex(i);
                    break;
                }
            }

            return false;
        }
    });

    prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients");
    ArrayList<CheckBoxPreference> allClients = new ArrayList<>();
    for (Group g : serverStatus.getGroups()) {
        for (Client client : g.getClients()) {
            CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext());
            checkBoxPref.setKey(client.getId());
            checkBoxPref.setTitle(client.getVisibleName());
            checkBoxPref.setChecked(g.getId().equals(group.getId()));
            checkBoxPref.setPersistent(false);
            allClients.add(checkBoxPref);
        }
    }
    Collections.sort(allClients, new Comparator<CheckBoxPreference>() {
        @Override
        public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) {
            return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString());
        }
    });
    for (CheckBoxPreference pref : allClients)
        prefCatClients.addPreference(pref);

    oldClients = getClients().toString();
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java

private CheckBoxPreference getIsActivePreference() {
    final CheckBoxPreference active = new CheckBoxPreference(getActivity());
    active.setTitle(R.string.special_list_active);
    active.setChecked(mItem.isActive());
    active.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from w ww . ja v  a 2 s .  com
        public boolean onPreferenceClick(Preference preference) {
            boolean a = !active.isChecked();
            mItem.setActive(a);
            mItem.save();
            active.setChecked(mItem.isActive());
            mAdapter.notifyDataSetChanged();
            return true;
        }
    });
    return active;
}

From source file:se.bitcraze.crazyfliecontrol.PreferencesActivity.java

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(KEY_PREF_RADIO_CHANNEL)) {
        setSummaryInt(key, radioChannelDefaultValue, RADIOCHANNEL_UPPER_LIMIT, "Radio channel");
    }//from w  w  w.  ja v a  2 s .co  m
    if (key.equals(KEY_PREF_RADIO_DATARATE)) {
        Preference radioDataratePref = findPreference(key);
        String[] stringArray = getResources().getStringArray(R.array.radioDatarateEntries);
        String keyString = sharedPreferences.getString(key, "");
        radioDataratePref.setSummary(stringArray[Integer.parseInt(keyString)]);
    }
    if (key.equals(KEY_PREF_MODE)) {
        Preference modePref = findPreference(key);
        modePref.setSummary(sharedPreferences.getString(key, modeDefaultValue));
    }
    if (key.equals(KEY_PREF_DEADZONE)) {
        Preference deadzonePref = findPreference(key);
        try {
            float deadzone = Float.parseFloat(sharedPreferences.getString(key, deadzoneDefaultValue));
            if (deadzone < 0.0 || deadzone > DEADZONE_UPPER_LIMIT) {
                resetPreference(key, deadzoneDefaultValue,
                        "Deadzone must be a float value between 0.0 and " + DEADZONE_UPPER_LIMIT + ".");
            }
        } catch (NumberFormatException nfe) {
            resetPreference(key, deadzoneDefaultValue,
                    "Deadzone must be a float value between 0.0 and " + DEADZONE_UPPER_LIMIT + ".");
        }
        deadzonePref.setSummary(sharedPreferences.getString(key, ""));
    }

    if (key.equals(KEY_PREF_RIGHT_ANALOG_X_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rightAnalogXAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_RIGHT_ANALOG_Y_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rightAnalogYAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_LEFT_ANALOG_X_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, leftAnalogXAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_LEFT_ANALOG_Y_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, leftAnalogYAxisDefaultValue));
    }

    if (key.equals(KEY_PREF_SPLITAXIS_YAW_BOOL)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
        findPreference(KEY_PREF_SPLITAXIS_YAW_LEFT_AXIS).setEnabled(sharedPreferences.getBoolean(key, false));
        findPreference(KEY_PREF_SPLITAXIS_YAW_RIGHT_AXIS).setEnabled(sharedPreferences.getBoolean(key, false));
    }

    if (key.equals(KEY_PREF_SPLITAXIS_YAW_LEFT_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, splitAxisLeftAxisDefaultValue));
    }
    if (key.equals(KEY_PREF_SPLITAXIS_YAW_RIGHT_AXIS)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, splitAxisRightAxisDefaultValue));
    }

    if (key.equals(KEY_PREF_ROLLTRIM) || key.equals(KEY_PREF_PITCHTRIM)) {
        Preference trimPref = findPreference(key);
        try {
            float trim = Float.parseFloat(sharedPreferences.getString(key, trimDefaultValue));
            if (Math.abs(trim) < 0.0 || Math.abs(trim) > TRIM_UPPER_LIMIT) {
                resetPreference(key, trimDefaultValue,
                        "Roll/Pitch trim must be a float value between 0.0 and " + TRIM_UPPER_LIMIT + ".");
            }
        } catch (NumberFormatException nfe) {
            resetPreference(key, trimDefaultValue,
                    "Roll/Pitch trim must be a float value between 0.0 and " + TRIM_UPPER_LIMIT + ".");
        }
        trimPref.setSummary(sharedPreferences.getString(key, ""));
    }
    if (key.equals(KEY_PREF_EMERGENCY_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, emergencyBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_ROLLTRIM_PLUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rollTrimPlusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_ROLLTRIM_MINUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, rollTrimMinusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_PITCHTRIM_PLUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, pitchTrimPlusBtnDefaultValue));
    }
    if (key.equals(KEY_PREF_PITCHTRIM_MINUS_BTN)) {
        findPreference(key).setSummary(sharedPreferences.getString(key, pitchTrimMinusBtnDefaultValue));
    }

    if (key.equals(KEY_PREF_AFC_BOOL)) {
        Preference afcScreenPref = findPreference(KEY_PREF_AFC_SCREEN);
        afcScreenPref.setEnabled(sharedPreferences.getBoolean(key, false));
        if (!sharedPreferences.getBoolean(key, false)) {
            Toast.makeText(this,
                    "Resetting to default values:\n" + "Max roll/pitch angle: " + maxRollPitchAngleDefaultValue
                            + "\n" + "Max yaw angle: " + maxYawAngleDefaultValue + "\n" + "Max thrust: "
                            + maxThrustDefaultValue + "\n" + "Min thrust: " + minThrustDefaultValue,
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "You have been warned!", Toast.LENGTH_LONG).show();
        }
    }
    if (key.equals(KEY_PREF_MAX_ROLLPITCH_ANGLE)) {
        setSummaryInt(key, maxRollPitchAngleDefaultValue, MAX_ROLLPITCH_ANGLE_UPPER_LIMIT,
                "Max roll/pitch angle");
    }
    if (key.equals(KEY_PREF_MAX_YAW_ANGLE)) {
        setSummaryInt(key, maxYawAngleDefaultValue, MAX_YAW_ANGLE_UPPER_LIMIT, "Max yaw angle");
    }
    if (key.equals(KEY_PREF_MAX_THRUST)) {
        setSummaryInt(key, maxThrustDefaultValue, MAX_THRUST_UPPER_LIMIT, "Max thrust");
    }
    if (key.equals(KEY_PREF_MIN_THRUST)) {
        setSummaryInt(key, minThrustDefaultValue, MIN_THRUST_UPPER_LIMIT, "Min thrust");
    }
    if (key.equals(KEY_PREF_XMODE)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
    }

    if (key.equals(KEY_PREF_SCREEN_ROTATION_LOCK_BOOL)) {
        CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
        pref.setChecked(sharedPreferences.getBoolean(key, false));
    }
}

From source file:org.teleportr.activity.Autocompletion.java

/** Called when the activity is first created. */
@Override//from   w  w w  .  j a  v a2s  . com
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setTitle(getString(R.string.downloads_activity_titel));
    getPreferenceManager().setSharedPreferencesName("autocompletion");
    setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));

    File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/teleporter");
    if (!dir.exists())
        dir.mkdir();

    final Map<String, ?> vals = getPreferenceManager().getSharedPreferences().getAll();
    if (vals.isEmpty() && dir.list().length > 0)
        Toast.makeText(this, getString(R.string.inform_sdcard), Toast.LENGTH_LONG).show();
    // clean up (autocompletion downloads deleted on sdcard)
    getPreferenceManager().getSharedPreferences().edit().clear().commit();

    for (String file : dir.list()) {
        CheckBoxPreference c = new CheckBoxPreference(this);
        getPreferenceScreen().addItemFromInflater(c);
        c.setKey(file);
        c.setTitle(file.split("_")[0]);
        c.setSummary(file.substring(file.indexOf("_") + 1, file.lastIndexOf(".")));
        if (vals.containsKey(file)) {
            c.setChecked((Boolean) vals.get(file));
        }
    }
    if (getPreferenceScreen().getPreferenceCount() == 0)
        new FetchNearbyDownloads().execute("");

}

From source file:com.harshad.linconnectclient.ApplicationSettingsActivity.java

private void setupSimplePreferencesScreen() {
    addPreferencesFromResource(R.xml.pref_application);

    applicationCategory = (PreferenceCategory) findPreference("header_application");

    // Listen for check/uncheck all tap
    findPreference("pref_all").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override//w  w w.  ja  v a 2 s .  c  o m
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            for (int i = 0; i < applicationCategory.getPreferenceCount(); i++) {
                // Uncheck or check all items
                ((CheckBoxPreference) (applicationCategory.getPreference(i))).setChecked((Boolean) arg1);
            }
            return true;
        }
    });

    class ApplicationTask extends AsyncTask<String, Void, List<ApplicationInfo>> {
        private PackageManager packageManager;

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(ApplicationSettingsActivity.this, null, "Loading...", true);
        }

        @Override
        protected List<ApplicationInfo> doInBackground(String... notif) {

            packageManager = getApplicationContext().getPackageManager();

            // Comparator used to sort applications by name
            class CustomComparator implements Comparator<ApplicationInfo> {
                @Override
                public int compare(ApplicationInfo arg0, ApplicationInfo arg1) {
                    return arg0.loadLabel(packageManager).toString()
                            .compareTo(arg1.loadLabel(packageManager).toString());
                }
            }

            // Get installed applications
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            List<ApplicationInfo> appList = getApplicationContext().getPackageManager()
                    .getInstalledApplications(PackageManager.GET_META_DATA);

            // Sort by application name
            Collections.sort(appList, new CustomComparator());

            return appList;
        }

        @Override
        protected void onPostExecute(List<ApplicationInfo> result) {
            // Add each application to screen
            for (ApplicationInfo appInfo : result) {
                CheckBoxPreference c = new CheckBoxPreference(ApplicationSettingsActivity.this);
                c.setTitle(appInfo.loadLabel(packageManager).toString());
                c.setSummary(appInfo.packageName);
                c.setIcon(appInfo.loadIcon(packageManager));
                c.setKey(appInfo.packageName);
                c.setChecked(true);

                c.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                    @Override
                    public boolean onPreferenceChange(Preference arg0, Object arg1) {
                        // On tap, show an enabled/disabled notification on the desktop
                        Object[] notif = new Object[3];

                        if (arg1.toString().equals("true")) {
                            notif[0] = arg0.getTitle().toString() + " notifications enabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        } else {
                            notif[0] = arg0.getTitle().toString() + " notifications disabled";
                            notif[1] = "via LinConnect";
                            notif[2] = arg0.getIcon();
                        }

                        new TestTask().execute(notif);

                        return true;
                    }

                });

                applicationCategory.addPreference(c);
            }
            progressDialog.dismiss();
        }
    }

    new ApplicationTask().execute();

}