Example usage for android.preference PreferenceGroup removeAll

List of usage examples for android.preference PreferenceGroup removeAll

Introduction

In this page you can find the example usage for android.preference PreferenceGroup removeAll.

Prototype

public void removeAll() 

Source Link

Document

Removes all Preference Preferences from this group.

Usage

From source file:Main.java

private static void replaceAllCheckBoxPreferencesBySwitchPreferences(final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }/*ww  w  . java2 s .  c  om*/
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference) preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup) preference);
            }
        }
    }
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static void putDebugInformation(PreferenceGroup container) {

    if (container == null) {
        return;/*from ww  w .  j  a  v a 2 s.com*/
    }

    container.removeAll();

    PreferenceTreeBuilder tree = new PreferenceTreeBuilder(container);
    JSONObject json = getDebugInformationJSON(container.getContext());

    tree.addString("Application Version", json, "application", "version_name");
    tree.addInt("Version Code", json, "application", "version_code");
    tree.addString("Build Date", json, "build", "date");
    tree.addString("Build Version", json, "build", "version");
    tree.addString("Commit", json, "build", "commit");
    tree.addString("Installed", json, "application", "installed");
    tree.addString("Last Updated", json, "application", "updated");
    tree.addString("Locale", json, "device", "locale");
    tree.addString("Screen Orientation", json, "device", "orientation");

    tree.open("Hardware");
    tree.addString("Android Version", json, "android", "version");
    tree.addString("API Level", json, "android", "api");
    tree.addString("Build Version", json, "android", "build");
    tree.addString("Manufacturer", json, "device", "manufacturer");
    tree.addString("Model", json, "device", "model");
    tree.add("Screen Dimensions", getScreenDimensionsLabel(json));
    tree.add("Device Encryption", getEncryptionLabel(json));
    tree.close();

    tree.open("Jabber / XMPP");

    tree.addString("Domain", json, "configuration", "xmpp.service_name");
    tree.addBoolean("Auto-detect", json, "configuration", "xmpp.perform_srv_lookup");
    tree.addString("Host", json, "configuration", "xmpp.host");
    tree.addInt("Port", json, "configuration", "xmpp.port");
    tree.addBoolean("Run in background", json, "configuration", "xmpp.background");
    tree.addBoolean("Online", json, "connection", "xmpp", "online");
    tree.addString("Status", json, "connection", "xmpp", "status");
    tree.addString("Host", json, "connection", "xmpp", "host");
    tree.addInt("Port", json, "connection", "xmpp", "port");
    tree.addString("Username", json, "connection", "xmpp", "user");

    tree.close();

    tree.open("Accounts Web API");
    tree.addString("Domain", json, "configuration", "api.service_name");
    tree.addBoolean("Auto-detect", json, "configuration", "api.perform_srv_lookup");
    tree.addString("Host", json, "configuration", "api.host");
    tree.addInt("Port", json, "configuration", "api.port");
    tree.close();

    tree.open("Miscellaneous");
    tree.addBoolean("Debug Mode", json, "configuration", "debug");
    tree.addBoolean("Experimental", json, "configuration", "experimental");
    tree.addBoolean("Generate Default Avatars", json, "configuration", "feature.generate_default_avatars");
    tree.addBoolean("Check User Availability", json, "configuration", "feature.check_user_availability");
    tree.addBoolean("Validate Certificates", json, "configuration", "validate_certificates");
    tree.addBoolean("Passphrase Active", json, "configuration", "passcode_set");
    tree.addBoolean("SCimp PKI Enabled", json, "configuration", "scimp.enable_pki");
    tree.addBoolean("Logging Enabled", json, "configuration", "logging_enabled");
    tree.addBoolean("Silent Contacts (v1)", json, "configuration", "silent_contacts_v1");
    tree.addBoolean("Silent Contacts (v2)", json, "configuration", "silent_contacts_v2");
    tree.addBoolean("Silent Phone", json, "configuration", "silent_phone");
    tree.addString("GCM Sender ID", json, "configuration", "gcm.sender_id");
    tree.addString("GCM Target", json, "configuration", "gcm.target");
    tree.addString("SCloud URL", json, "configuration", "scloud.url");
    tree.close();

    tree.addString("Timestamp", json, "timestamp");

}

From source file:com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment.java

private void setPrefSubtypes(final String prefSubtypes, final Context context) {
    final PreferenceGroup group = getPreferenceScreen();
    group.removeAll();
    final InputMethodSubtype[] subtypesArray = AdditionalSubtypeUtils
            .createAdditionalSubtypesArray(prefSubtypes);
    for (final InputMethodSubtype subtype : subtypesArray) {
        final CustomInputStylePreference pref = new CustomInputStylePreference(context, subtype, this);
        group.addPreference(pref);/* w w  w . j  ava 2  s  .com*/
    }
}

From source file:de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java

private void loadRules() {
    new AsyncTask<Void, Void, JSONObject>() {
        @Override/* w  ww .  ja v  a  2s.  com*/
        protected JSONObject doInBackground(final Void... params) {
            try {
                String l;
                StringBuilder sb = new StringBuilder();

                File f = new File(PreferencesPlain.this.getCacheDir(), "ub0rrules.json");
                if (f.exists() && f.lastModified() + CACHE_TIMEOUT > System.currentTimeMillis()) {
                    Log.i(TAG, "found cached data: " + f.getAbsolutePath());
                    BufferedReader r = new BufferedReader(new FileReader(f));
                    while ((l = r.readLine()) != null) {
                        sb.append(l);
                    }
                    r.close();
                }
                if (sb.length() == 0) {
                    if (f.exists()) {
                        f.delete();
                    }
                    HttpURLConnection c = (HttpURLConnection) new URL(
                            "http://ub0r.de/android/callmeter/rulesets/rulesets.json").openConnection();
                    Log.i(TAG, "load new data: " + c.getURL());
                    BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream()));
                    FileWriter w = new FileWriter(f);
                    while ((l = r.readLine()) != null) {
                        sb.append(l);
                        w.write(l);
                    }
                    r.close();
                    w.close();
                }
                try {
                    return new JSONObject(sb.toString());
                } catch (JSONException e) {
                    Log.e(TAG, "JSON Error", e);
                    Log.e(TAG, "JSON: " + sb.toString());
                    return null;
                }
            } catch (IOException e) {
                Log.e(TAG, "IOError", e);
            }
            return null;
        }

        @SuppressWarnings({ "deprecation", "rawtypes" })
        @Override
        protected void onPostExecute(final JSONObject result) {
            if (result == null) {
                Toast.makeText(PreferencesPlain.this, R.string.err_export_read, Toast.LENGTH_LONG).show();
                return;
            }
            PreferenceGroup base = (PreferenceGroup) PreferencesPlain.this.findPreference("import_rules_users");
            PreferenceManager pm = base.getPreferenceManager();
            // delete old
            base.removeAll();
            base = (PreferenceGroup) PreferencesPlain.this.findPreference("import_rules_base");
            // build list
            ArrayList<String> keys = new ArrayList<String>(result.length());

            Iterator it = result.keys();
            while (it.hasNext()) {
                keys.add(it.next().toString());
            }
            Collections.sort(keys);
            keys.remove("common");
            keys.add(0, "common");

            OnPreferenceClickListener opcl = new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(final Preference preference) {
                    Intent intent = new Intent(PreferencesPlain.this, PreferencesRules.class);
                    intent.putExtra(PreferencesRules.EXTRA_JSON, result.toString());
                    intent.putExtra(PreferencesRules.EXTRA_COUNTRY, preference.getKey());
                    PreferencesPlain.this.startActivity(intent);
                    return true;
                }
            };

            for (String k : keys) {
                PreferenceScreen p = pm.createPreferenceScreen(PreferencesPlain.this);
                p.setPersistent(false);
                p.setKey(k);
                p.setTitle(k);
                p.setOnPreferenceClickListener(opcl);
                base.addPreference(p);
            }
        }

        ;
    }.execute((Void) null);
}

From source file:com.mobiletin.inputmethod.indic.settings.CustomInputStyleSettingsFragment.java

private void setPrefSubtypes(final String prefSubtypes, final Context context) {
    final PreferenceGroup group = getPreferenceScreen();
    group.removeAll();
    final InputMethodSubtype[] subtypesArray = AdditionalSubtypeUtils
            .createAdditionalSubtypesArray(prefSubtypes);
    for (final InputMethodSubtype subtype : subtypesArray) {
        final SubtypePreference pref = new SubtypePreference(context, subtype, mSubtypeProxy);
        group.addPreference(pref);//w w w .j  a  va2s . c o m
    }
}