Java Code Examples for android.preference.CheckBoxPreference#setPersistent()

The following examples show how to use android.preference.CheckBoxPreference#setPersistent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 2
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 3
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 4
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public CheckBoxPreference makeCheckBox(PreferenceGroup parent, boolean persistent, String key,
		boolean defaultValue, CharSequence title, CharSequence summary) {
	CheckBoxPreference preference = new CheckBoxPreference(getActivity());
	preference.setPersistent(persistent);
	preference.setKey(key);
	preference.setTitle(title);
	if (summary != null) {
		preference.setSummary(summary);
	}
	preference.setDefaultValue(defaultValue);
	addPreference(parent, preference);
	return preference;
}
 
Example 5
Source File: GroupSettingsFragment.java    From snapdroid with GNU General Public License v3.0 4 votes vote down vote up
@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();
        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();
    }