Example usage for android.preference ListPreference setEnabled

List of usage examples for android.preference ListPreference setEnabled

Introduction

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

Prototype

public void setEnabled(boolean enabled) 

Source Link

Document

Sets whether this Preference is enabled.

Usage

From source file:Main.java

public static void PopulateList(Preference preference, String[] List) {
    ListPreference PrefList = (ListPreference) preference;
    if (List == null) {
        PrefList.setEnabled(false);
    } else {/*from  w ww  .  j a va  2s.  c om*/
        PrefList.setEntryValues(List);
        PrefList.setEntries(List);
        PrefList.setEnabled(true);
    }
}

From source file:com.syncedsynapse.kore2.ui.SettingsFragment.java

/**
 * Sets up the preferences state and summaries
 * @param hasBoughtCoffee Whether the user has bought me a coffee
 */// w w w.  j a  va 2  s.c o m
private void setupPreferences(boolean hasBoughtCoffee) {
    final Settings settings = Settings.getInstance(getActivity());

    LogUtils.LOGD(TAG, "Setting up preferences. Has bought coffee? " + hasBoughtCoffee);

    // Coffee upgrade
    final Preference coffeePref = findPreference(Settings.KEY_PREF_COFFEE);
    if (coffeePref != null) {
        if (hasBoughtCoffee) {
            if (settings.showThanksForCofeeMessage) {
                coffeePref.setTitle(getResources().getString(R.string.thanks_for_coffe));
                coffeePref.setSummary(getResources().getString(R.string.remove_coffee_message));
                coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        settings.showThanksForCofeeMessage = false;
                        settings.save();
                        getPreferenceScreen().removePreference(coffeePref);
                        return true;
                    }
                });
            } else {
                getPreferenceScreen().removePreference(coffeePref);
            }
        } else {
            coffeePref.setTitle(getResources().getString(R.string.buy_me_coffee));
            coffeePref.setSummary(getResources().getString(R.string.expresso_please));
            coffeePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    launchCoffeePurchase();
                    return true;
                }
            });
        }
    }

    // Theme preferences
    ListPreference themePref = (ListPreference) findPreference(Settings.KEY_PREF_THEME);
    if (hasBoughtCoffee) {
        themePref.setEnabled(true);
        themePref.setSummary(themePref.getEntry());
    } else {
        themePref.setEnabled(false);
        themePref.setSummary(getActivity().getString(R.string.buy_coffee_to_unlock_themes));
    }

    // About preference
    String nameAndVersion = getActivity().getString(R.string.app_name);
    try {
        nameAndVersion += " v" + getActivity().getPackageManager()
                .getPackageInfo(getActivity().getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException exc) {
    }
    Preference aboutPreference = findPreference(Settings.KEY_PREF_ABOUT);
    aboutPreference.setSummary(nameAndVersion);
    aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AboutDialogFragment aboutDialog = new AboutDialogFragment();
            aboutDialog.show(getActivity().getFragmentManager(), null);
            return true;
        }
    });

}

From source file:com.p3authentication.preferences.Prefs.java

@SuppressWarnings("deprecation")
@Override/*from  w ww.  ja  v  a  2s  .c om*/
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    addPreferencesFromResource(R.xml.pref);

    AccessPin = (EditTextPreference) getPreferenceManager().findPreference("KeypadKey");
    final Preference ResetPreference = getPreferenceManager().findPreference("reset_data");
    final Preference EULAPreference = getPreferenceManager().findPreference("eula");
    final Preference AboutUsPreference = getPreferenceManager().findPreference("about_us");
    final Preference UnlockAppsPreference = getPreferenceManager().findPreference("unlock_apps");
    final Preference TouchTolerance = getPreferenceManager().findPreference("touch_tolerance");
    final Preference RedownloadImage = getPreferenceManager().findPreference("redownload_images");
    final Preference RateApp = getPreferenceManager().findPreference("rate_app");
    final CheckBoxPreference GhostStatusPref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("GhostStatus");
    final CheckBoxPreference StartServicePref = (CheckBoxPreference) getPreferenceManager()
            .findPreference("startup_service");
    final ListPreference patterntype = (ListPreference) getPreferenceManager().findPreference("PatternType");
    final ListPreference PatternStealth = (ListPreference) getPreferenceManager()
            .findPreference("PatternStealth");
    if (patterntype.getValue().toString().equals("No Pattern")) {
        PatternStealth.setEnabled(false);
    } else {
        PatternStealth.setEnabled(true);
    }

    if (GhostStatusPref.isChecked()) {
        AccessPin.setEnabled(true);
    } else {
        AccessPin.setEnabled(false);
    }
    AccessPin.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (newValue.toString().trim().equals("")) {

                Toast.makeText(Prefs.this, "Your Custom PIN cannot be empty.", Toast.LENGTH_LONG).show();

                return false;
            } else if (newValue.toString().length() < 5) {
                Toast.makeText(Prefs.this, "Your Custom PIN must be atleast 5 Digits.", Toast.LENGTH_LONG)
                        .show();

                return false;
            }
            Toast.makeText(Prefs.this, "Your Custom PIN is set.", Toast.LENGTH_LONG).show();
            return true;
        }

    });
    GhostStatusPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                hideLauncherIcon();
                Toast.makeText(Prefs.this, "P3 hidden from App Menu", Toast.LENGTH_SHORT).show();
            } else {
                showLauncherIcon();
                Toast.makeText(Prefs.this, "P3 visible on App Menu", Toast.LENGTH_SHORT).show();
            }
            return true;
        }

    });
    StartServicePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);

            } else {
                ComponentName receiver = new ComponentName(Prefs.this, Startup.class);
                PackageManager pm = getPackageManager();

                pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
            return true;
        }

    });
    patterntype.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // TODO Auto-generated method stub
            if (!newValue.toString().equals("No Pattern")) {
                PatternStealth.setEnabled(true);
            } else {
                PatternStealth.setEnabled(false);
            }
            return true;
        }
    });
    ResetPreference.setOnPreferenceClickListener(this);
    UnlockAppsPreference.setOnPreferenceClickListener(this);
    TouchTolerance.setOnPreferenceClickListener(this);
    RedownloadImage.setOnPreferenceClickListener(this);
    RateApp.setOnPreferenceClickListener(this);
    AboutUsPreference.setOnPreferenceClickListener(this);
    EULAPreference.setOnPreferenceClickListener(this);

}

From source file:org.span.manager.ChangeSettingsActivity.java

private void updateView() {

    // user id//from   ww  w . j  av  a 2 s.  c o  m
    EditTextPreference uidEditTextPref = (EditTextPreference) findPreference("uidpref");
    uidEditTextPref.setText(manetcfg.getUserId());

    // wifi group
    wifiGroupPref = (PreferenceGroup) findPreference("wifiprefs");
    boolean bluetoothOn = manetcfg.isUsingBluetooth();
    wifiGroupPref.setEnabled(!bluetoothOn);

    // wifi encryption algorithm
    WifiEncryptionAlgorithmEnum encAlgorithm = manetcfg.getWifiEncryptionAlgorithm();
    ListPreference wifiEncAlgorithmPref = (ListPreference) findPreference("encalgorithmpref");
    wifiEncAlgorithmPref.setEnabled(false); // TODO: disable until tested
    wifiEncAlgorithmPref.setEntries(WifiEncryptionAlgorithmEnum.descriptionValues());
    wifiEncAlgorithmPref.setEntryValues(WifiEncryptionAlgorithmEnum.stringValues());
    wifiEncAlgorithmPref.setValueIndex(encAlgorithm.ordinal());

    // wifi encryption setup method
    ListPreference wifiEncSetupMethodPref = (ListPreference) findPreference("encsetuppref");
    wifiEncSetupMethodPref.setEnabled(false); // TODO: disable until tested
    if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) {
        wifiEncSetupMethodPref.setEnabled(false);
    } else {
        wifiEncSetupMethodPref.setEnabled(true);
        if (manetcfg.getWifiDriver().startsWith("softap")
                || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) {
            if (wifiEncSetupMethodPref != null) {
                wifiGroupPref.removePreference(wifiEncSetupMethodPref);
            }
        } else {
            wifiEncSetupMethodPref.setEntries(WifiEncryptionSetupMethodEnum.descriptionValues());
            wifiEncSetupMethodPref.setEntryValues(WifiEncryptionSetupMethodEnum.stringValues());
            wifiEncSetupMethodPref.setValueIndex(manetcfg.getWifiEncryptionSetupMethod().ordinal());
        }
    }

    // wifi encryption password
    final EditTextPreference wifiEncPasswordEditTextPref = (EditTextPreference) findPreference("passwordpref");
    wifiEncPasswordEditTextPref.setEnabled(false); // TODO: disable until tested
    if (encAlgorithm == WifiEncryptionAlgorithmEnum.NONE) {
        wifiEncPasswordEditTextPref.setEnabled(false);
    } else {
        wifiEncPasswordEditTextPref.setEnabled(true);
        final int origTextColorWifiEncKey = wifiEncPasswordEditTextPref.getEditText().getCurrentTextColor();
        if (manetcfg.getWifiDriver().startsWith("softap")
                || manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) {
            Validation.setupWpaEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey);
        } else {
            Validation.setupWepEncryptionValidators(wifiEncPasswordEditTextPref, origTextColorWifiEncKey);
        }
        wifiEncPasswordEditTextPref.setText(manetcfg.getWifiEncryptionPassword());
    }

    // wifi SSID
    EditTextPreference wifiSsidEditTextPref = (EditTextPreference) findPreference("ssidpref");
    Validation.setupWifiSsidValidator(wifiSsidEditTextPref);
    wifiSsidEditTextPref.setText(manetcfg.getWifiSsid());

    // wifi channel
    ListPreference channelpref = (ListPreference) findPreference("channelpref");
    channelpref.setEnabled(false); // TODO: disable until tested
    String[] channelStrValues = WifiChannelEnum.stringValues();
    String[] channelDescValues = WifiChannelEnum.descriptionValues();
    // remove auto channel option if not supported by device
    if (!manetcfg.getWifiDriver().startsWith("softap")
            || !manetcfg.getWifiDriver().equals(DeviceConfig.DRIVER_HOSTAP)) {
        // auto channel option at first index
        String[] newChannelStrValues = new String[channelStrValues.length - 1];
        String[] newChannelDescValues = new String[channelStrValues.length - 1];
        for (int i = 1; i < channelStrValues.length; i++) {
            newChannelStrValues[i - 1] = channelStrValues[i];
            newChannelDescValues[i - 1] = channelDescValues[i];
        }
        channelpref.setEntries(newChannelDescValues);
        channelpref.setEntryValues(newChannelStrValues);
        WifiChannelEnum wifiChannel = manetcfg.getWifiChannel();
        if (wifiChannel == WifiChannelEnum.AUTO) {
            channelpref.setValueIndex(WifiChannelEnum.CHANNEL_1.ordinal() - 1);
        } else {
            channelpref.setValueIndex(wifiChannel.ordinal() - 1);
        }
    } else {
        channelpref.setEntries(channelDescValues);
        channelpref.setEntryValues(channelStrValues);
        channelpref.setValueIndex(manetcfg.getWifiChannel().ordinal());
    }

    // wifi transmit power
    ListPreference txpowerPreference = (ListPreference) findPreference("txpowerpref");
    if (!manetcfg.isTransmitPowerSupported()) { // DEBUG
        if (txpowerPreference != null) {
            wifiGroupPref.removePreference(txpowerPreference);
        }
    } else {
        txpowerPreference.setEntries(WifiTxpowerEnum.descriptionValues());
        txpowerPreference.setEntryValues(WifiTxpowerEnum.stringValues());
        txpowerPreference.setValueIndex(manetcfg.getWifiTxpower().ordinal());
    }

    // bluetooth group        
    // disable bluetooth adhoc if not supported by the kernel
    if (true) { // !manetcfg.isBluetoothSupported() // TODO: disable until tested
        PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs");
        btGroup.setEnabled(false);
    }

    // bluetooth
    // NOTE: bluetooth dependencies are specified in the layout XML
    // CheckBoxPreference bluetoothCheckboxPref = (CheckBoxPreference)findPreference("bluetoothonpref");

    // bluetooth keep wifi
    CheckBoxPreference btKeepWifiCheckBoxPref = (CheckBoxPreference) findPreference("bluetoothkeepwifipref");
    if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) {
        PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs");
        if (btKeepWifiCheckBoxPref != null) {
            btGroup.removePreference(btKeepWifiCheckBoxPref);
        }
    } else {
        btKeepWifiCheckBoxPref.setChecked(!manetcfg.isWifiDisabledWhenUsingBluetooth());
    }

    // bluetooth discoverable
    CheckBoxPreference btdiscoverablePreference = (CheckBoxPreference) findPreference(
            "bluetoothdiscoverablepref");
    if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.ECLAIR) {
        PreferenceGroup btGroup = (PreferenceGroup) findPreference("btprefs");
        if (btdiscoverablePreference != null) {
            btGroup.removePreference(btdiscoverablePreference);
        }
    } else {
        btdiscoverablePreference.setChecked(manetcfg.isBluetoothDiscoverableWhenInAdhocMode());
    }

    // ip address
    EditTextPreference ipAddressEditTextPref = (EditTextPreference) findPreference("ippref");
    Validation.setupIpAddressValidator(ipAddressEditTextPref);
    ipAddressEditTextPref.setText(manetcfg.getIpAddress());

    // dns server
    EditTextPreference dnsServerEditTextPref = (EditTextPreference) findPreference("dnspref");
    Validation.setupIpAddressValidator(dnsServerEditTextPref);
    dnsServerEditTextPref.setText(manetcfg.getDnsServer());

    // routing protocol
    String currRoutingProtocol = manetcfg.getRoutingProtocol();
    List<String> routingProtocolList = CoreTask.getRoutingProtocols();
    String[] routingProtocols = new String[routingProtocolList.size()];
    routingProtocolList.toArray(routingProtocols);

    ListPreference routingProtocolPreference = (ListPreference) findPreference("routingprotocolpref");
    routingProtocolPreference.setEntries(routingProtocols);
    routingProtocolPreference.setEntryValues(routingProtocols);
    routingProtocolPreference.setValue(currRoutingProtocol);

    // routing ignore list
    JSONArray array = new JSONArray(manetcfg.getRoutingIgnoreList());
    sharedPreferences.edit().putString("ignorepref", array.toString()).commit();

    // wifi interface
    String currInterface = manetcfg.getWifiInterface();
    String defaultInterface = DeviceConfig.getWifiInterface(manetcfg.getDeviceType());
    List<String> interfaceList = CoreTask.getNetworkInterfaces();
    if (!interfaceList.contains(defaultInterface)) {
        interfaceList.add(defaultInterface);
    }
    String[] interfaces = new String[interfaceList.size()];
    interfaceList.toArray(interfaces);

    ListPreference interfacePreference = (ListPreference) findPreference("interfacepref");
    interfacePreference.setEntries(interfaces);
    interfacePreference.setEntryValues(interfaces);

    if (interfaceList.contains(currInterface)) {
        interfacePreference.setValue(currInterface);
    } else {
        interfacePreference.setValue(defaultInterface);
        currInterface = defaultInterface;
    }

    // routing gateway
    String currGatewayInterface = manetcfg.getGatewayInterface();
    interfaceList.remove(currInterface); // remove ad-hoc interface
    interfaceList.add(0, ManetConfig.GATEWAY_INTERFACE_NONE);
    interfaces = new String[interfaceList.size()];
    interfaceList.toArray(interfaces);

    ListPreference gatewayPreference = (ListPreference) findPreference("gatewaypref");
    gatewayPreference.setEntries(interfaces);
    gatewayPreference.setEntryValues(interfaces);
    gatewayPreference.setValue(currGatewayInterface);

    if (interfaceList.contains(currGatewayInterface)) {
        gatewayPreference.setValue(currGatewayInterface);
    } else {
        gatewayPreference.setValue(ManetConfig.GATEWAY_INTERFACE_NONE);
    }

    // screen on
    CheckBoxPreference screenOnPreference = (CheckBoxPreference) findPreference("screenonpref");
    screenOnPreference.setChecked(manetcfg.isScreenOnWhenInAdhocMode());

    // battery temperature

    setupFlag = true;
}

From source file:com.android.leanlauncher.SettingsActivity.java

private void displayIconThemePref(ListPreference lpIconSetting) {
    ArrayMap<String, String> iconPacks = LauncherAppState.getInstance().getIconCache().getAvailableIconPacks();

    if (iconPacks != null && iconPacks.size() != 0) {
        String iconPackValues[] = iconPacks.keySet().toArray(new String[iconPacks.size() + 1]);
        iconPackValues[iconPacks.size()] = "";

        String[] iconPackTitles = new String[iconPacks.size() + 1];
        for (int i = 0; i < iconPacks.size(); i++) {
            iconPackTitles[i] = iconPacks.get(iconPacks.keyAt(i));
        }//  ww  w.java 2s  . c om
        iconPackTitles[iconPacks.size()] = getString(R.string.pref_no_icon_theme);

        lpIconSetting.setEntries(iconPackTitles);
        lpIconSetting.setEntryValues(iconPackValues);
    } else {
        lpIconSetting.setEnabled(false);
        lpIconSetting.setShouldDisableView(true);
        lpIconSetting.setSummary(R.string.pref_icon_theme_summary_disabled);
    }
}

From source file:org.tvheadend.tvhclient.fragments.SettingsProfileFragment.java

/**
 * //from   ww  w  .j ava 2s. c om
 * @param preferenceList
 * @param profileList
 */
protected void addProfiles(ListPreference preferenceList, final List<Profiles> profileList) {
    // Initialize the arrays that contain the profile values
    final int size = profileList.size();
    CharSequence[] entries = new CharSequence[size];
    CharSequence[] entryValues = new CharSequence[size];

    // Add the available profiles to list preference
    for (int i = 0; i < size; i++) {
        entries[i] = profileList.get(i).name;
        entryValues[i] = profileList.get(i).uuid;
    }
    preferenceList.setEntries(entries);
    preferenceList.setEntryValues(entryValues);

    // Enable the preference for use selection
    preferenceList.setEnabled(true);
}

From source file:org.linphone.SettingsFragment.java

private void initMediaEncryptionPreference(ListPreference pref) {
    List<CharSequence> entries = new ArrayList<CharSequence>();
    List<CharSequence> values = new ArrayList<CharSequence>();
    entries.add(getString(R.string.media_encryption_none));
    values.add(getString(R.string.pref_media_encryption_key_none));

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
        setListPreferenceValues(pref, entries, values);
        return;/*from   ww w. ja  v  a 2s . c o m*/
    }

    boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
    boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
    if (!hasSrtp && !hasZrtp) {
        pref.setEnabled(false);
    } else {
        if (hasSrtp) {
            entries.add(getString(R.string.media_encryption_srtp));
            values.add(getString(R.string.pref_media_encryption_key_srtp));
        }
        if (hasZrtp) {
            entries.add(getString(R.string.media_encryption_zrtp));
            values.add(getString(R.string.pref_media_encryption_key_zrtp));
        }
        setListPreferenceValues(pref, entries, values);
    }

    MediaEncryption value = mPrefs.getMediaEncryption();
    pref.setSummary(value.toString());

    String key = getString(R.string.pref_media_encryption_key_none);
    if (value.toString().equals(getString(R.string.media_encryption_srtp)))
        key = getString(R.string.pref_media_encryption_key_srtp);
    else if (value.toString().equals(getString(R.string.media_encryption_zrtp)))
        key = getString(R.string.pref_media_encryption_key_zrtp);
    pref.setValue(key);
}