Example usage for android.preference ListPreference getEntryValues

List of usage examples for android.preference ListPreference getEntryValues

Introduction

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

Prototype

public CharSequence[] getEntryValues() 

Source Link

Document

Returns the array of values to be saved for the preference.

Usage

From source file:com.ovrhere.android.currencyconverter.ui.fragments.SettingsFragment.java

/** Finds and sets the update summary. Additionally sets default
 * value based on interval /*from   w ww . ja  va  2  s . co m*/
 * @param interval The interval to show 
 * @param updateList The preference to update the summary */
private void findAndSetUpdateSummary(final int interval, ListPreference updateList) {
    CharSequence[] labels = updateList.getEntries();
    CharSequence[] values = updateList.getEntryValues();

    if (labels.length != values.length) {
        Log.w(CLASS_NAME, "Labels and values mismatch!");
        //if there is a mismatch, we know nothing.
        return;
    }
    final int SIZE = labels.length;
    for (int index = 0; index < SIZE; index++) {
        if (values[index].equals(String.valueOf(interval))) {
            //same value, so label it as such.
            updateList.setSummary(labels[index]);
            updateList.setValueIndex(index);
            return;
        }
    }
}

From source file:net.bible.android.view.activity.settings.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // change theme according to light sensor
    UiUtils.applyTheme(this);

    super.onCreate(savedInstanceState);

    // allow partial integration with And Bible framework - without this TTS stops
    // putting this before the below ensures any error dialog will be displayed in front of the settings screen and not the previous screen
    // see onStop for paired iAmNoLongerCurrent method call
    CurrentActivityHolder.getInstance().setCurrentActivity(this);

    try {//from   www  . j  ava 2  s  . c  om
        addPreferencesFromResource(R.xml.settings);

        //If no light sensor exists switch to old boolean check box
        // see here for method: http://stackoverflow.com/questions/4081533/how-to-remove-android-preferences-from-the-screen
        Preference unusedNightModePreference = getPreferenceScreen()
                .findPreference(ScreenSettings.getUnusedNightModePreferenceKey());
        getPreferenceScreen().removePreference(unusedNightModePreference);

        // if no tilt sensor then remove tilt-to-scroll setting
        if (!PageTiltScrollControl.isTiltSensingPossible()) {
            Preference tiltToScrollPreference = getPreferenceScreen()
                    .findPreference(PageTiltScrollControl.TILT_TO_SCROLL_PREFERENCE_KEY);
            getPreferenceScreen().removePreference(tiltToScrollPreference);
        }

        // only JellyBean supports Malayalam so remove ml for older versions of Android
        if (!CommonUtils.isJellyBeanPlus()) {
            ListPreference localePref = (ListPreference) getPreferenceScreen().findPreference(LOCALE_PREF);
            CharSequence[] entries = localePref.getEntries();
            CharSequence[] entryValues = localePref.getEntryValues();
            int mlIndex = ArrayUtils.indexOf(entryValues, "ml");
            if (mlIndex != -1) {
                Log.d(TAG, "removing Malayalam from preference list");
                localePref.setEntries(ArrayUtils.remove(entries, mlIndex));
                localePref.setEntryValues(ArrayUtils.remove(entryValues, mlIndex));
            }
        }

        addScreenTimeoutSettings();

    } catch (Exception e) {
        Log.e(TAG, "Error preparing preference screen", e);
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred);
    }
}

From source file:com.bellman.bible.android.view.activity.settings.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // change theme according to light sensor
    UiUtils.applyTheme(this);

    super.onCreate(savedInstanceState);

    // allow partial integration with Embedded Bible framework - without this TTS stops
    // putting this before the below ensures any error dialog will be displayed in front of the settings screen and not the previous screen
    // see onStop for paired iAmNoLongerCurrent method call
    CurrentActivityHolder.getInstance().setCurrentActivity(this);

    try {//from  ww w .  ja  v  a 2 s .  c o m
        addPreferencesFromResource(R.xml.settings);

        //If no light sensor exists switch to old boolean check box
        // see here for method: http://stackoverflow.com/questions/4081533/how-to-remove-android-preferences-from-the-screen
        Preference unusedNightModePreference = getPreferenceScreen()
                .findPreference(ScreenSettings.getUnusedNightModePreferenceKey());
        getPreferenceScreen().removePreference(unusedNightModePreference);

        // if no tilt sensor then remove tilt-to-scroll setting
        if (!PageTiltScrollControl.isTiltSensingPossible()) {
            Preference tiltToScrollPreference = getPreferenceScreen()
                    .findPreference(PageTiltScrollControl.TILT_TO_SCROLL_PREFERENCE_KEY);
            getPreferenceScreen().removePreference(tiltToScrollPreference);
        }

        // only JellyBean supports Malayalam so remove ml for older versions of Android
        if (!CommonUtils.isJellyBeanPlus()) {
            ListPreference localePref = (ListPreference) getPreferenceScreen().findPreference(LOCALE_PREF);
            CharSequence[] entries = localePref.getEntries();
            CharSequence[] entryValues = localePref.getEntryValues();
            int mlIndex = ArrayUtils.indexOf(entryValues, "ml");
            if (mlIndex != -1) {
                Log.d(TAG, "removing Malayalam from preference list");
                localePref.setEntries(ArrayUtils.remove(entries, mlIndex));
                localePref.setEntryValues(ArrayUtils.remove(entryValues, mlIndex));
            }
        }

        addScreenTimeoutSettings();

    } catch (Exception e) {
        Log.e(TAG, "Error preparing preference screen", e);
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, e);
    }
}

From source file:com.ichi2.anki.PreferenceContext.java

public void updateNotificationPreference(ListPreference listpref) {
    CharSequence[] entries = listpref.getEntries();
    CharSequence[] values = listpref.getEntryValues();
    for (int i = 0; i < entries.length; i++) {
        int value = Integer.parseInt(values[i].toString());
        if (entries[i].toString().contains("%d")) {
            entries[i] = String.format(entries[i].toString(), value);
        }/* w  w w  .  j a  v a2 s. c  o m*/
    }
    listpref.setEntries(entries);
    listpref.setSummary(listpref.getEntry().toString());
}

From source file:com.schoentoon.connectbot.HostEditorActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    getSupportActionBar().setSubtitle("Host editor");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    long hostId = this.getIntent().getLongExtra(Intent.EXTRA_TITLE, -1);

    // TODO: we could pass through a specific ContentProvider uri here
    //this.getPreferenceManager().setSharedPreferencesName(uri);

    this.hostdb = new HostDatabase(this);
    this.pubkeydb = new PubkeyDatabase(this);

    host = hostdb.findHostById(hostId);//from   w ww .  j  av  a  2s .co m

    connection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService();

            hostBridge = bound.getConnectedBridge(host);
        }

        public void onServiceDisconnected(ComponentName name) {
            hostBridge = null;
        }
    };

    this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId);
    this.pref.registerOnSharedPreferenceChangeListener(this);

    this.addPreferencesFromResource(R.xml.host_prefs);

    // add all existing pubkeys to our listpreference for user to choose from
    // TODO: may be an issue here when this activity is recycled after adding a new pubkey
    // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once
    ListPreference pubkeyPref = (ListPreference) this.findPreference(HostDatabase.FIELD_HOST_PUBKEYID);

    List<CharSequence> pubkeyNicks = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntries()));
    pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME));
    pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()]));

    List<CharSequence> pubkeyIds = new LinkedList<CharSequence>(Arrays.asList(pubkeyPref.getEntryValues()));
    pubkeyIds.addAll(pubkeydb.allValues("_id"));
    pubkeyPref.setEntryValues(pubkeyIds.toArray(new CharSequence[pubkeyIds.size()]));

    // Populate the character set encoding list with all available
    final ListPreference charsetPref = (ListPreference) findPreference(HostDatabase.FIELD_HOST_ENCODING);

    if (CharsetHolder.isInitialized()) {
        initCharsetPref(charsetPref);
    } else {
        String[] currentCharsetPref = new String[1];
        currentCharsetPref[0] = charsetPref.getValue();
        charsetPref.setEntryValues(currentCharsetPref);
        charsetPref.setEntries(currentCharsetPref);

        new Thread(new Runnable() {
            public void run() {
                initCharsetPref(charsetPref);
            }
        }).start();
    }

    this.updateSummaries();
}

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

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

    thiz = this;/* w  w w .  j av a 2s  . co 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);
}

From source file:fr.pasteque.client.Configure.java

private void updateCardProcessorPreferences(String newValue) {
    if (newValue == null) {
        newValue = Configure.getCardProcessor(this);
    }//from  w  w w.j  ava  2 s  . co m

    ListPreference card_processor = (ListPreference) this.findPreference("card_processor");

    EditTextPreference atos_address = (EditTextPreference) this.findPreference("worldline_address");
    EditTextPreference xengo_userid = (EditTextPreference) this.findPreference("xengo_userid");
    EditTextPreference xengo_password = (EditTextPreference) this.findPreference("xengo_password");
    EditTextPreference xengo_terminalid = (EditTextPreference) this.findPreference("xengo_terminalid");

    atos_address.setEnabled("atos_classic".equals(newValue));
    xengo_userid.setEnabled("atos_xengo".equals(newValue));
    xengo_password.setEnabled("atos_xengo".equals(newValue));
    xengo_terminalid.setEnabled("atos_xengo".equals(newValue));

    card_processor.setSummary(newValue);
    int i = 0;
    for (CharSequence entry : card_processor.getEntryValues()) {
        if (newValue.equals(entry)) {
            card_processor.setSummary(card_processor.getEntries()[i]);
        }
        i++;
    }
}