Java Code Examples for android.preference.ListPreference#setDefaultValue()

The following examples show how to use android.preference.ListPreference#setDefaultValue() . 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: SettingsFragment.java    From sms-ticket with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
    PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
    ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
    List<String> simIds = new ArrayList<>();
    List<String> simNames = new ArrayList<>();
    simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    simNames.add(getString(R.string.sim_default));
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
        simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
        simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
            .getDisplayName()));
    }
    preference.setEntries(simNames.toArray(new String[simNames.size()]));
    preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
    preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    preference.setSummary(preference.getEntry());
}
 
Example 2
Source File: SettingsFragment.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
private void setRpcServerPreferenceData(ListPreference lp) {
    NetworkInfo[] networks = ethereumNetworkRepository.getAvailableNetworkList();
    CharSequence[] entries = new CharSequence[networks.length];
    for (int ii = 0; ii < networks.length; ii++) {
        entries[ii] = networks[ii].name;
    }

    CharSequence[] entryValues = new CharSequence[networks.length];
    for (int ii = 0; ii < networks.length; ii++) {
        entryValues[ii] = networks[ii].name;
    }

    String currentValue = ethereumNetworkRepository.getDefaultNetwork().name;

    lp.setEntries(entries);
    lp.setDefaultValue(currentValue);
    lp.setValue(currentValue);
    lp.setSummary(currentValue);
    lp.setEntryValues(entryValues);
}
 
Example 3
Source File: AccountPreferencesFragment.java    From Linphone4Android with GNU General Public License v3.0 6 votes vote down vote up
private void initializeTransportPreference(ListPreference pref) {
	List<CharSequence> entries = new ArrayList<CharSequence>();
	List<CharSequence> values = new ArrayList<CharSequence>();
	entries.add(getString(R.string.pref_transport_udp));
	values.add(getString(R.string.pref_transport_udp_key));
	entries.add(getString(R.string.pref_transport_tcp));
	values.add(getString(R.string.pref_transport_tcp_key));

	if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
		entries.add(getString(R.string.pref_transport_tls));
		values.add(getString(R.string.pref_transport_tls_key));
	}
	setListPreferenceValues(pref, entries, values);

	if (! isNewAccount) {
		pref.setSummary(mPrefs.getAccountTransportString(n));
		pref.setDefaultValue(mPrefs.getAccountTransportKey(n));
		pref.setValueIndex(entries.indexOf(mPrefs.getAccountTransportString(n)));
	} else {

		pref.setSummary(getString(R.string.pref_transport_udp));
		pref.setDefaultValue(getString(R.string.pref_transport_udp));
		pref.setValueIndex(entries.indexOf(getString(R.string.pref_transport_udp)));
	}
}
 
Example 4
Source File: FetchingPrefFragment.java    From Onosendai with Apache License 2.0 6 votes vote down vote up
private void addBatLevel (final String key, final CharSequence title, final CharSequence defVal, final OnPreferenceChangeListener changeListener) {
	final ListPreference pref = new ListPreference(getActivity());
	pref.setKey(key);
	pref.setTitle(title);
	pref.setEntries(CollectionHelper.map(BATTERY_LEVELS, new Function<CharSequence, CharSequence>() {
		@Override
		public CharSequence exec (final CharSequence input) {
			return input + "%";
		}
	}, new ArrayList<CharSequence>()).toArray(new CharSequence[BATTERY_LEVELS.length]));
	pref.setEntryValues(BATTERY_LEVELS);
	pref.setSummary("%s");
	pref.setDefaultValue(defVal);
	pref.setOnPreferenceChangeListener(changeListener);
	getPreferenceScreen().addPreference(pref);
}
 
Example 5
Source File: ColorSettingsActivity.java    From LaunchTime with GNU General Public License v3.0 6 votes vote down vote up
private static void setListPreferenceIconsPacksData(ListPreference lp, Context context) {
    IconsHandler iph = GlobState.getIconsHandler(context);

    iph.loadAvailableIconsPacks();

    Map<String, String> iconsPacks = iph.getAllIconsThemes();

    CharSequence[] entries = new CharSequence[iconsPacks.size()];
    CharSequence[] entryValues = new CharSequence[iconsPacks.size()];

    int i = 0;
    for (String packageIconsPack : iconsPacks.keySet()) {
        entries[i] = iconsPacks.get(packageIconsPack);
        entryValues[i] = packageIconsPack;
        i++;
    }

    lp.setEntries(entries);
    lp.setDefaultValue(IconsHandler.DEFAULT_PACK);
    lp.setEntryValues(entryValues);
}
 
Example 6
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set up protocol selection
 */
void setupCommMediaSelection()
{
	ListPreference pref = (ListPreference) findPreference(KEY_COMM_MEDIUM);
	CommService.MEDIUM[] values = CommService.MEDIUM.values();
	CharSequence[] titles = new CharSequence[values.length];
	CharSequence[] keys = new CharSequence[values.length];
	int i = 0;
	for (CommService.MEDIUM proto : values)
	{
		titles[i] = proto.toString();
		keys[i] = String.valueOf(proto.ordinal());
		i++;
	}
	// set enries and keys
	pref.setEntries(titles);
	pref.setEntryValues(keys);
	pref.setDefaultValue(titles[0]);
	// show current selection
	pref.setSummary(pref.getEntry());
}
 
Example 7
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set up protocol selection
 */
void setupProtoSelection()
{
	ListPreference pref = (ListPreference) findPreference(KEY_PROT_SELECT);
	ElmProt.PROT[] values = ElmProt.PROT.values();
	CharSequence[] titles = new CharSequence[values.length];
	CharSequence[] keys = new CharSequence[values.length];
	int i = 0;
	for (ElmProt.PROT proto : values)
	{
		titles[i] = proto.toString();
		keys[i] = String.valueOf(proto.ordinal());
		i++;
	}
	// set enries and keys
	pref.setEntries(titles);
	pref.setEntryValues(keys);
	pref.setDefaultValue(titles[0]);
	// show current selection
	pref.setSummary(pref.getEntry());
}
 
Example 8
Source File: SettingsActivity.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
/**
 * set up protocol selection
 */
void setupElmTimingSelection()
{
    ListPreference pref = (ListPreference) findPreference(ELM_TIMING_SELECT);
    ElmProt.AdaptTimingMode[] values = ElmProt.AdaptTimingMode.values();
    CharSequence[] titles = new CharSequence[values.length];
    CharSequence[] keys = new CharSequence[values.length];
    int i = 0;
    for (ElmProt.AdaptTimingMode mode : values)
    {
        titles[i] = mode.toString();
        keys[i] = mode.toString();
     i++;
    }
    // set enries and keys
    pref.setEntries(titles);
    pref.setEntryValues(keys);
    pref.setDefaultValue(titles[0]);
    // show current selection
    pref.setSummary(pref.getEntry());
}
 
Example 9
Source File: FetchingPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addPrefetchMedia () {
	final ListPreference pref = new ListPreference(getActivity());
	pref.setKey(KEY_PREFETCH_MEDIA);
	pref.setTitle("Prefetch media"); //ES
	pref.setSummary("Fetch new pictures during background updates: %s"); //ES
	pref.setEntries(PrefetchMode.prefEntries());
	pref.setEntryValues(PrefetchMode.prefEntryValues());
	pref.setDefaultValue(PrefetchMode.NO.getValue());
	getPreferenceScreen().addPreference(pref);
}
 
Example 10
Source File: UiPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addColumnsCount (final String key, final String title) {
	final ListPreference pref = new ComboPreference(getActivity());
	pref.setKey(key);
	pref.setTitle(title);
	pref.setEntries(COUNTS);
	pref.setEntryValues(COUNTS);
	pref.setDefaultValue(DEFAULT_COUNT);
	getPreferenceScreen().addPreference(pref);
}
 
Example 11
Source File: UiPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addLocalePref () {
	final ListPreference pref = new ComboPreference(getActivity());
	pref.setKey(KEY_LOCALE);
	pref.setTitle("Locale"); //ES
	pref.setEntries(SupportedLocales.prefEntries());
	pref.setEntryValues(SupportedLocales.prefEntryValues());
	pref.setDefaultValue(SupportedLocales.DEFAULT.getValue());
	pref.setOnPreferenceChangeListener(this.onLocaleChangeListener);
	getPreferenceScreen().addPreference(pref);
}
 
Example 12
Source File: PluginActivity.java    From android-lockscreen-disabler with Apache License 2.0 5 votes vote down vote up
/** 
 * Replace the general preference of the application with a simpler preference for the
 * plugin
 */
private void setupSimplePreferencesScreen() {
  getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE);
  addPreferencesFromResource(R.xml.pref_plugin);

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
    ListPreference typePref = (ListPreference) findPreference(PLUGIN_LOCKSCREENTYPE);
    typePref.setEntries(R.array.lockscreenTypePreJellyBean);
    typePref.setEntryValues(R.array.lockscreenTypeValuesPreJellyBean);
    typePref.setDefaultValue("none");
  }
}
 
Example 13
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public ListPreference makeList(PreferenceGroup parent, String key, CharSequence[] values,
		String defaultValue, int titleResId, CharSequence[] entries) {
	ListPreference preference = new ListPreference(getActivity());
	preference.setKey(key);
	preference.setTitle(titleResId);
	preference.setDialogTitle(titleResId);
	preference.setEntries(entries);
	preference.setEntryValues(values);
	if (defaultValue != null) {
		preference.setDefaultValue(defaultValue);
	}
	addPreference(parent, preference);
	updateListSummary(preference);
	return preference;
}
 
Example 14
Source File: SynchModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setEntries(DOMAINS);
    domainPref.setEntryValues(DOMAINS);
    domainPref.setDefaultValue(DOMAINS[0]);
    preferenceGroup.addPreference(domainPref);
    super.addPreferencesOnScreen(preferenceGroup);
}
 
Example 15
Source File: Pref.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public static ListPreference List(Context context, PreferenceCategory category, int caption, int summary, int dialogCaption, String key, Object defaultValue, CharSequence[] entries, CharSequence[] entryValues, boolean enabled) {
	ListPreference retval = new ListPreference(context);
	if (caption > 0) retval.setTitle(caption);
	if (summary > 0) retval.setSummary(summary);
	retval.setEnabled(enabled);
	retval.setKey(key);
	retval.setDefaultValue(defaultValue);
	if (dialogCaption > 0) retval.setDialogTitle(dialogCaption);
	retval.setEntries(entries);
	retval.setEntryValues(entryValues);    	
	if (category != null) category.addPreference(retval);
	return retval;
}
 
Example 16
Source File: CRPreferenceActivity.java    From comfortreader with GNU General Public License v3.0 5 votes vote down vote up
protected static void setListPreferenceData(ListPreference lp, Context context) {
    //TODO performance lost here
    SettingsLoader settingslolo = new SettingsLoader(lp.getPreferenceManager().getSharedPreferences(), context);
    CharSequence[] entries = settingslolo.getLastBooks();
    CharSequence[] entryValues = settingslolo.getLastBooksValues();//{"2", "3", "4"};
    lp.setEntries(entries);
    lp.setDefaultValue("0");
    lp.setEntryValues(entryValues);
}
 
Example 17
Source File: FetchingPrefFragment.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void addPrefetchLinks () {
	final ListPreference pref = new ListPreference(getActivity());
	pref.setKey(KEY_PREFETCH_LINKS);
	pref.setTitle("Prefetch links"); //ES
	pref.setSummary("Fetch new link titles during background updates: %s"); //ES
	pref.setEntries(PrefetchMode.prefEntries());
	pref.setEntryValues(PrefetchMode.prefEntryValues());
	pref.setDefaultValue(PrefetchMode.NO.getValue());
	getPreferenceScreen().addPreference(pref);
}
 
Example 18
Source File: MyPreferences.java    From audio-analyzer-for-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    // Get list of default sources
    Intent intent = getIntent();
    final int[] asid = intent.getIntArrayExtra(AnalyzerActivity.MYPREFERENCES_MSG_SOURCE_ID);
    final String[] as = intent.getStringArrayExtra(AnalyzerActivity.MYPREFERENCES_MSG_SOURCE_NAME);

    int nExtraSources = 0;
    for (int id : asid) {
        // See SamplingLoop::run() for the magic number 1000
        if (id >= 1000) nExtraSources++;
    }

    // Get list of supported sources
    AnalyzerUtil au = new AnalyzerUtil(this);
    final int[] audioSourcesId = au.GetAllAudioSource(4);
    Log.i(TAG, " n_as = " + audioSourcesId.length);
    Log.i(TAG, " n_ex = " + nExtraSources);
    audioSourcesName = new String[audioSourcesId.length + nExtraSources];
    for (int i = 0; i < audioSourcesId.length; i++) {
        audioSourcesName[i] = au.getAudioSourceName(audioSourcesId[i]);
    }

    // Combine these two sources
    audioSources = new String[audioSourcesName.length];
    int j = 0;
    for (; j < audioSourcesId.length; j++) {
        audioSources[j] = String.valueOf(audioSourcesId[j]);
    }
    for (int i = 0; i < asid.length; i++) {
        // See SamplingLoop::run() for the magic number 1000
        if (asid[i] >= 1000) {
            audioSources[j] = String.valueOf(asid[i]);
            audioSourcesName[j] = as[i];
            j++;
        }
    }

    final ListPreference lp = (ListPreference) findPreference("audioSource");
    lp.setDefaultValue(MediaRecorder.AudioSource.VOICE_RECOGNITION);
    lp.setEntries(audioSourcesName);
    lp.setEntryValues(audioSources);

    getPreferenceScreen().getSharedPreferences()
            .registerOnSharedPreferenceChangeListener(prefListener);
}
 
Example 19
Source File: SettingsActivity.java    From javainstaller with GNU General Public License v3.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {

       CharSequence[] cs = new String[] { "Terminal Emulator", "Run Activity", "auto" };
       CharSequence[] cs2 = new String[] { "off", "on" };

       // Root
       PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
       PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
       dialogBasedPrefCat.setTitle("install");
       root.addPreference(dialogBasedPrefCat); // Adding a category

       // List preference under the category
       ListPreference listPref = new ListPreference(this);
       listPref.setKey("runmode");
       listPref.setDefaultValue(cs[2]);
       listPref.setEntries(cs);
       listPref.setEntryValues(cs);
       listPref.setDialogTitle("run install.sh in");
       listPref.setTitle("run install.sh in");
       listPref.setSummary("run install.sh in");
       dialogBasedPrefCat.addPreference(listPref);
       ListPreference rootmode = new ListPreference(this);
       rootmode.setKey("rootmode");
       rootmode.setDefaultValue(cs2[0]);
       rootmode.setEntries(cs2);
       rootmode.setEntryValues(cs2);
       rootmode.setDialogTitle("run install.sh as superuser");
       rootmode.setTitle("run install.sh as superuser");
       rootmode.setSummary("root required");
       dialogBasedPrefCat.addPreference(rootmode);
       
       PreferenceCategory dialogBasedPrefCat2 = new PreferenceCategory(this);
       dialogBasedPrefCat2.setTitle("run");
       root.addPreference(dialogBasedPrefCat2); // Adding a category

       // List preference under the category
       CharSequence[] csjar = new String[] { "Terminal Emulator", "Run Activity" };
       ListPreference listPref2 = new ListPreference(this);
       listPref2.setKey("runmode2");
       listPref2.setDefaultValue(csjar[1]);
       listPref2.setEntries(csjar);
       listPref2.setEntryValues(csjar);
       listPref2.setDialogTitle("run jar file in");
       listPref2.setTitle("run jar file in");
       listPref2.setSummary("run jar file in");
       dialogBasedPrefCat2.addPreference(listPref2);
       ListPreference rootmode2 = new ListPreference(this);
       rootmode2.setKey("rootmode2");
       rootmode2.setDefaultValue(cs2[0]);
       rootmode2.setEntries(cs2);
       rootmode2.setEntryValues(cs2);
       rootmode2.setDialogTitle("run jar file as superuser");
       rootmode2.setTitle("run jar file as superuser");
       rootmode2.setSummary("root required");
       dialogBasedPrefCat2.addPreference(rootmode2);
       
       PreferenceCategory dialogBasedPrefCat3 = new PreferenceCategory(this);
       dialogBasedPrefCat3.setTitle("path broadcast");
       root.addPreference(dialogBasedPrefCat3); // Adding a category

       // List preference under the category
       CharSequence[] cspath = new String[] { "on", "off", "if jamvm is installed" };
       ListPreference listPref3 = new ListPreference(this);
       listPref3.setKey("broadcast");
       listPref3.setDefaultValue(cspath[2]);
       listPref3.setEntries(cspath);
       listPref3.setEntryValues(cspath);
       listPref3.setDialogTitle("broadcast path to terminal emulator");
       listPref3.setTitle("broadcast path to terminal emulator");
       listPref3.setSummary("broadcast path to terminal emulator");
       dialogBasedPrefCat3.addPreference(listPref3);
       EditTextPreference path = new EditTextPreference(this);
       path.setKey("broadcastpath");
       path.setDefaultValue("/data/data/julianwi.javainstaller");
       path.setDialogTitle("path to broadcast");
       path.setTitle("path to broadcast");
       path.setSummary("path to broadcast");
       dialogBasedPrefCat3.addPreference(path);

       return root;
   }
 
Example 20
Source File: GeneralPreferenceFragment.java    From V2EX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(
            Config.getConfig(ConfigRefEnum.CONFIG_PREFERENCE_SETTING_FILE));
    addPreferencesFromResource(R.xml.pref_general);

    ListPreference themePreference = (ListPreference) findPreference(
            getString(R.string.key_theme));
    themePreference.setSummary(Config.getConfig(ConfigRefEnum.CONFIG_THEME));

    ListPreference dateFormatPreference = (ListPreference)findPreference(
            getString(R.string.key_date_format));
    String[] dateEntries = new String[dateFormatPreference.getEntryValues().length];
    int i = 0;
    for (CharSequence s:dateFormatPreference.getEntryValues()){
        String date = TimeUtil.getDateNow(String.valueOf(s));
        dateEntries[i++] = date;
    }
    dateFormatPreference.setEntries(dateEntries);
    dateFormatPreference.setSummary(TimeUtil.getDateNow(Config.getConfig(
            ConfigRefEnum.CONFIG_DATE_FORMAT)));

    ListPreference localePreference = (ListPreference) findPreference(getString(R.string.key_local));
    String[] localesEntryValue = new String[Config.LOCAL_LIST.size()];
    String[] localesEntries= new String[Config.LOCAL_LIST.size()];
    int index = 0;
    for (Locale locale:Config.LOCAL_LIST){
        localesEntryValue[index] = locale.toString();
        localesEntries[index++] = locale.getDisplayCountry();
    }
    localePreference.setDefaultValue(localesEntryValue[0]);
    localePreference.setEntryValues(localesEntryValue);
    localePreference.setEntries(localesEntries);

    Preference clearCachePreference = findPreference(getString(R.string.clear_cache));
    clearCachePreference.setOnPreferenceClickListener(this::clearCache);
    clearCachePreference.setSummary("缓存大小 12 MB");
    findPreference(getString(R.string.key_home_tabs)).setOnPreferenceClickListener(preference -> {
        CustomTabActivity.start(getActivity());
        return false;
    });
}