Example usage for android.preference ListPreference setEntryValues

List of usage examples for android.preference ListPreference setEntryValues

Introduction

In this page you can find the example usage for android.preference ListPreference setEntryValues.

Prototype

public void setEntryValues(@ArrayRes int entryValuesResId) 

Source Link

Usage

From source file:com.olearyp.gusto.Expsetup.java

/** Called when the activity is first created. */
@Override/* ww w .j a  va2  s  .com*/
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    settings = getSharedPreferences("serverState", MODE_PRIVATE);
    addPreferencesFromResource(R.xml.preferences);
    final Map<String, String> config = getCurrentConfig();

    // Tack version number on to titlebar at top level
    try {
        this.setTitle(getTitle() + " v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    } catch (final NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String ramhack_file;
    // ROM-specific settings
    if (config.get("GLB_EP_VERSION_EPDATA").contains("-TMO")) {
        findPreference("launcher").setEnabled(false);
        findPreference("phone").setEnabled(false);
        findPreference("contacts").setEnabled(false);
        findPreference("teeter").setEnabled(false);
        findPreference("quickoffice").setEnabled(false);
        ramhack_file = "10mb_kernel_patch_tmo262.zip";
    } else {
        ramhack_file = "10mb_kernel_patch_adp262.zip";
    }
    // QuickCommands menu
    {
        findPreference("reboot").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_msg, R.string.reboot));
        findPreference("reboot_recovery").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_recovery_msg, R.string.reboot_recovery));
        findPreference("reboot_bootloader").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.reboot_alert_title, R.string.reboot_bootloader_msg, R.string.reboot_bootload));
        findPreference("reboot_poweroff").setOnPreferenceClickListener(new RebootPreferenceListener(
                R.string.shutdown_alert_title, R.string.shutdown_msg, R.string.shutdown));
        findPreference("rwsystem").setOnPreferenceClickListener(
                new ExpPreferenceListener(R.string.rwsystem, "setting /system read-write"));
        findPreference("rosystem").setOnPreferenceClickListener(
                new ExpPreferenceListener(R.string.rosystem, "setting /system read-only"));
    }
    // CPU options
    {
        findPreference("freq_sample").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | set_ep_cyan_ond_mod", "setting frequency scaling"));
        ((CheckBoxPreference) findPreference("freq_sample"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_CYAN_OND_MOD"));
        final List<String> freqs = Arrays.asList(getResources().getStringArray(R.array.cpu_freqs_str));
        final ListPreference minFreqPref = (ListPreference) findPreference("cpu_freq_min");
        final ListPreference maxFreqPref = (ListPreference) findPreference("cpu_freq_max");
        minFreqPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("GLB_EP_MIN_CPU=" + newValue.toString() + " && " + "write_out_ep_config && "
                        + "echo \"$GLB_EP_MIN_CPU\" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq",
                        "setting minimum CPU frequency", "none");
                final String[] legalfreqs = freqs.subList(freqs.indexOf(newValue), freqs.size())
                        .toArray(new String[0]);
                maxFreqPref.setEntries(legalfreqs);
                maxFreqPref.setEntryValues(legalfreqs);
                return true;
            }
        });
        maxFreqPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("GLB_EP_MAX_CPU=" + newValue.toString() + " && " + "write_out_ep_config && "
                        + "echo \"$GLB_EP_MAX_CPU\" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq",
                        "setting maximum CPU frequency", "none");
                final String[] legalfreqs = freqs.subList(0, freqs.indexOf(newValue) + 1)
                        .toArray(new String[0]);
                minFreqPref.setEntries(legalfreqs);
                minFreqPref.setEntryValues(legalfreqs);
                return true;
            }
        });
        final String[] maxfreqs = freqs.subList(freqs.indexOf(config.get("GLB_EP_MIN_CPU")), freqs.size())
                .toArray(new String[0]);
        maxFreqPref.setEntries(maxfreqs);
        maxFreqPref.setEntryValues(maxfreqs);
        final String[] minfreqs = freqs.subList(0, freqs.indexOf(config.get("GLB_EP_MAX_CPU")) + 1)
                .toArray(new String[0]);
        minFreqPref.setEntries(minfreqs);
        minFreqPref.setEntryValues(minfreqs);
        maxFreqPref.setValue(config.get("GLB_EP_MAX_CPU"));
        minFreqPref.setValue(config.get("GLB_EP_MIN_CPU"));
    }
    // Downloadables
    {
        DownloadPreference p;
        p = ((DownloadPreference) findPreference("ramhack_kernel"));
        p.setParams(ASPIN_URL + "RESOURCE/" + ramhack_file, "/sdcard/" + ramhack_file);
        p.setOnPreferenceClickListener(new RamhackPreferenceListener(testRamhack(config), p));
        p = ((DownloadPreference) findPreference("kernel_mods"));
        p.setParams(ASPIN_URL + "ROM/kmods_v211_vsapp.zip", "/sdcard/epvsapps/available/kmods_v211_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/kmods_v211_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("teeter"));
        p.setParams(ASPIN_URL + "APPS/teeter_vsapp.zip", "/sdcard/epvsapps/available/teeter_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/teeter_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("quickoffice"));
        p.setParams(ASPIN_URL + "APPS/quickoffice_vsapp.zip",
                "/sdcard/epvsapps/available/quickoffice_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/quickoffice_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("ext_widgets"));
        p.setParams(ASPIN_URL + "APPS/widgetpack_v2_vsapp.zip",
                "/sdcard/epvsapps/available/widgetpack_v2_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/widgetpack_v2_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("xdan_java"));
        p.setParams(ASPIN_URL + "APPS/jbed_vsapp.zip", "/sdcard/epvsapps/available/jbed_vsapp.zip");
        p.setOnPreferenceClickListener(
                new VsappPreferenceListener(new File("/sdcard/epvsapps/available/jbed_vsapp.zip").exists(), p));
        p = ((DownloadPreference) findPreference("iwnn_ime_jp"));
        p.setParams(ASPIN_URL + "APPS/iwnnime_vsapp.zip", "/sdcard/epvsapps/available/iwnnime_vsapp.zip");
        p.setOnPreferenceClickListener(new VsappPreferenceListener(
                new File("/sdcard/epvsapps/available/iwnnime_vsapp.zip").exists(), p));
    }
    // Theme profile settings
    {
        findPreference("launcher").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Launcher.apk", "changing Launcher"));
        ((CheckBoxPreference) findPreference("launcher")).setChecked(isTrueish(config, "Launcher.apk"));
        findPreference("phone").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Phone.apk", "changing Phone"));
        ((CheckBoxPreference) findPreference("phone")).setChecked(isTrueish(config, "Phone.apk"));
        findPreference("contacts").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Contacts.apk", "changing Contacts"));
        ((CheckBoxPreference) findPreference("contacts")).setChecked(isTrueish(config, "Contacts.apk"));
        findPreference("browser").setOnPreferenceChangeListener(
                new ExpThemeProfileChangeListener("Browser.apk", "changing the Browser"));
        ((CheckBoxPreference) findPreference("browser")).setChecked(isTrueish(config, "Browser.apk"));
        findPreference("mms")
                .setOnPreferenceChangeListener(new ExpThemeProfileChangeListener("Mms.apk", "changing MMS"));
        ((CheckBoxPreference) findPreference("mms")).setChecked(isTrueish(config, "Mms.apk"));
    }
    // Advanced Options
    {
        // Swappiness
        findPreference("swappiness").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                sendCommand("yes '" + newValue.toString() + "' | set_ep_swappiness", "setting swappiness",
                        "none");
                return true;
            }
        });
        ((EditTextPreference) findPreference("swappiness")).setText(config.get("GLB_EP_SWAPPINESS"));
        ((EditTextPreference) findPreference("swappiness")).getEditText()
                .setKeyListener(new SwappinessKeyListener());
        // Compcache
        findPreference("compcache").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_compcache", "setting compcache", true));
        ((CheckBoxPreference) findPreference("compcache"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_COMPCACHE"));
        // Linux swap
        findPreference("linux_swap").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_linuxswap", "setting Linux-swap"));
        ((CheckBoxPreference) findPreference("linux_swap"))
                .setChecked(isTrueish(config, "GLB_EP_ENABLE_LINUXSWAP"));
        // userinit.sh
        findPreference("userinit").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_userinit", "setting userinit"));
        ((CheckBoxPreference) findPreference("userinit")).setChecked(isTrueish(config, "GLB_EP_RUN_USERINIT"));
        // Remove odex on boot
        findPreference("odex").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_odex_boot_removal", "setting ODEX removal"));
        ((CheckBoxPreference) findPreference("odex")).setChecked(isTrueish(config, "GLB_EP_ODEX_BOOT_REMOVAL"));
        // Odex now
        findPreference("reodex").setOnPreferenceClickListener(
                new ExpPreferenceListener("yes | odex_ep_data_apps", "re-ODEXing apps"));
        // Set pid priorities
        findPreference("pid_prioritize").setOnPreferenceChangeListener(
                new ExpPreferenceListener("yes | toggle_ep_pid_prioritizer", "setting PID prioritizer"));
        ((CheckBoxPreference) findPreference("pid_prioritize"))
                .setChecked(isTrueish(config, "GLB_EP_PID_PRIORITIZE"));
    }
    // Generate and send ep_log
    findPreference("ep_log").setOnPreferenceClickListener(new EpLogListener());
}

From source file:com.almalence.opencam.Fragment.java

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

    thiz = this;// w ww  .  jav a  2s. c  o m

    String settings = getArguments().getString("type");

    ApplicationScreen.getPluginManager().loadHeaderContent(settings, this);

    if (null == getPreferenceScreen())
        return;
    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        initSummary(getPreferenceScreen().getPreference(i));
    }

    Preference nightPreference = findPreference("night");
    if (nightPreference != null) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (prefs.getBoolean("useCamera2Pref", false)) {
            getPreferenceScreen().removePreference(nightPreference);
        } else {
            Preference superPreference = findPreference("super");
            getPreferenceScreen().removePreference(superPreference);
        }
    }

    final SeekBarPreference brightnessPref = (SeekBarPreference) this.findPreference("brightnessPref");
    if (brightnessPref != null) {
        // Set seekbar summary :
        float gamma = PreferenceManager.getDefaultSharedPreferences(getActivity()).getFloat("gammaPref", 0.5f);
        brightnessPref.setSummary(
                this.getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma));
        brightnessPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            private final Map<Integer, Float> gamma_map = new HashMap<Integer, Float>() {
                {
                    put(0, 0.5f);
                    put(1, 0.55f);
                    put(2, 0.6f);
                    put(3, 0.65f);
                    put(4, 0.7f);
                }
            };

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                int radius = (Integer) newValue;
                float gamma = gamma_map.get(radius);
                PreferenceManager
                        .getDefaultSharedPreferences(Fragment.thiz.getActivity().getApplicationContext()).edit()
                        .putFloat("gammaPref", gamma).commit();
                brightnessPref.setSummary(getActivity()
                        .getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma));
                return true;
            }
        });
    }

    final CheckBoxPreference upscalePref = (CheckBoxPreference) this.findPreference("upscaleResult");
    if (upscalePref != null) {
        Size size = CameraController.getMaxCameraImageSize(CameraController.YUV);
        long resMpx = 0;
        float mpix = 0.0f;
        if (size != null) {
            resMpx = (long) ((long) size.getWidth() * (long) size.getHeight() * 2.25);
            mpix = (float) resMpx / 1000000.f;
        }

        String name = String.format("%3.1f Mpix ", mpix);

        upscalePref.setSummary(
                getActivity().getString(R.string.Pref_Super_SummaryUpscale).replace("$1", "" + name));
    }

    Preference cameraParameters = findPreference("camera_parameters");
    if (cameraParameters != null) {
        cameraParameters.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                try {
                    showCameraParameters();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                return true;
            }
        });
    }

    CheckBoxPreference helpPref = (CheckBoxPreference) findPreference("showHelpPrefCommon");
    if (helpPref != null)
        helpPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (((CheckBoxPreference) preference).isChecked()) {
                    SharedPreferences prefs = PreferenceManager
                            .getDefaultSharedPreferences(MainScreen.getMainContext());
                    Editor prefsEditor = prefs.edit();
                    prefsEditor.putBoolean("droShowHelp", true);
                    prefsEditor.putBoolean("sequenceRemovalShowHelp", true);
                    prefsEditor.putBoolean("panoramaShowHelp", true);
                    prefsEditor.putBoolean("superShowHelp", true);
                    prefsEditor.putBoolean("groupshotRemovalShowHelp", true);
                    prefsEditor.putBoolean("objectRemovalShowHelp", true);
                    prefsEditor.putBoolean("bestShotShowHelp", true);
                    prefsEditor.commit();
                }

                return true;
            }
        });

    EditTextPreference prefix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue));
    EditTextPreference postfix = (EditTextPreference) this
            .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue));
    initExportName(null, null);

    if (prefix != null) {
        prefix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                initExportName(preference, newValue);
                return true;
            }
        });
    }

    if (postfix != null) {
        postfix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                initExportName(preference, newValue);
                return true;
            }
        });
    }

    Preference sonyPreference = findPreference(MainScreen.sSonyCamerasPref);
    if (sonyPreference != null) {
        sonyPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean sonyCamerasAvailable = (Boolean) newValue;
                if (sonyCamerasAvailable) {
                    Toast.makeText(getActivity(),
                            getActivity().getString(R.string.pref_general_more_sonyCamera_available),
                            Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });
    }

    ListPreference saveToPreference = (ListPreference) this
            .findPreference(getResources().getString(R.string.Preference_SaveToValue));

    // if android 5+, then remove "save to SD card" option. Because it's
    // equals to "save to custom folder" option.
    if (saveToPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CharSequence[] entries = saveToPreference.getEntries();
        CharSequence[] entriyValues = saveToPreference.getEntryValues();

        CharSequence[] newEntries = new String[2];
        CharSequence[] newEntriyValues = new String[2];

        newEntries[0] = entries[0];
        newEntries[1] = entries[2];
        newEntriyValues[0] = entriyValues[0];
        newEntriyValues[1] = entriyValues[2];

        saveToPreference.setEntries(newEntries);
        saveToPreference.setEntryValues(newEntriyValues);
    }
    if (saveToPreference != null) {

        saveToPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                int v = -1;

                int v_old = 0;

                try {
                    v = Integer.parseInt(newValue.toString());
                    v_old = Integer.parseInt(((ListPreference) preference).getValue());
                } catch (NumberFormatException e) {

                }

                if ((v == 2 || v == 1) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                        Toast.makeText(MainScreen.getInstance(),
                                MainScreen.getAppResources()
                                        .getString(R.string.pref_advanced_saving_saveToPref_CantSaveToSD),
                                Toast.LENGTH_LONG).show();

                        if (isDeviceRooted()) {
                            Intent intent = new Intent(Preferences.thiz, FolderPicker.class);

                            intent.putExtra(MainScreen.sSavePathPref, v_old);

                            Preferences.thiz.startActivity(intent);

                            return true;
                        } else
                            return false;
                    }
                }

                if (v == 2 || v == 1) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                        startActivityForResult(intent, CHOOSE_FOLDER_CODE);
                    } else if (v != 1) {
                        Intent intent = new Intent(Preferences.thiz, FolderPicker.class);

                        intent.putExtra(MainScreen.sSavePathPref, v_old);

                        Preferences.thiz.startActivity(intent);
                    }
                }

                return true;
            }
        });
    }

    PreferenceCategory cat = (PreferenceCategory) this.findPreference("Pref_VFCommon_Preference_Category");
    if (cat != null) {
        CheckBoxPreference cp = (CheckBoxPreference) cat.findPreference("maxScreenBrightnessPref");
        if (cp != null) {
            cp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    boolean value = Boolean.parseBoolean(newValue.toString());
                    setScreenBrightness(value);
                    return true;
                }
            });
        }
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    boolean MaxScreenBrightnessPreference = prefs.getBoolean("maxScreenBrightnessPref", false);
    setScreenBrightness(MaxScreenBrightnessPreference);
}