Java Code Examples for android.preference.EditTextPreference#setSummary()

The following examples show how to use android.preference.EditTextPreference#setSummary() . 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: PreferencesUtil.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 2
Source File: PreferencesActivity.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void adjustUnitDependentPrefs(Preference pref) {
    // convert preferences values to current units
    String[] unitDependent = new String[]{
            MainApp.gs(R.string.key_hypo_target),
            MainApp.gs(R.string.key_activity_target),
            MainApp.gs(R.string.key_eatingsoon_target),
            MainApp.gs(R.string.key_high_mark),
            MainApp.gs(R.string.key_low_mark)
    };
    if (Arrays.asList(unitDependent).contains(pref.getKey())) {
        EditTextPreference editTextPref = (EditTextPreference) pref;
        String converted = Profile.toCurrentUnitsString(SafeParse.stringToDouble(editTextPref.getText()));
        editTextPref.setSummary(converted);
        editTextPref.setText(converted);
    }
}
 
Example 3
Source File: SettingsActivity.java    From nitroshare-android with MIT License 6 votes vote down vote up
/**
 * Create an EditTextPreference for the specified preference
 * @param titleResId resource ID to use for the title
 * @param key preference key
 * @return newly created preference
 */
private EditTextPreference createEditTextPreference(@StringRes int titleResId, Settings.Key key) {
    final EditTextPreference editTextPreference = new EditTextPreference(getActivity());
    editTextPreference.setDefaultValue(mSettings.getDefault(key));
    editTextPreference.setKey(key.name());
    editTextPreference.setSummary(mSettings.getString(key));
    editTextPreference.setTitle(titleResId);
    editTextPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            editTextPreference.setSummary((String) newValue);
            return true;
        }
    });
    return editTextPreference;
}
 
Example 4
Source File: PreferencesUtil.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 5
Source File: KrautModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
public void addKompturcodePreference(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    EditTextPreference kompturcodePreference = new EditTextPreference(context);
    kompturcodePreference.setTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setDialogTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setSummary(R.string.kraut_prefs_kompturcode_summary);
    kompturcodePreference.setKey(getSharedKey(PREF_KEY_KOMPTURCODE_COOKIE));
    kompturcodePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            setKompturcodeCookie((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(kompturcodePreference);
}
 
Example 6
Source File: GroupPreferenceFragment.java    From tickmate with GNU General Public License v3.0 6 votes vote down vote up
private void loadGroup() {
    // Consider adding more features here, such as those in Track and TrackPreferenceFragment
    name = (EditTextPreference) findPreference("name");
    name.setText(group.getName());
    name.setSummary(group.getName());

    description = (EditTextPreference) findPreference("description");
    description.setText(group.getDescription());
    description.setSummary(group.getDescription());

    mTracksPref = (MultiSelectListPreference) findPreference("tracks");
    mTracksPref.setValues(getTrackIdsForGroupAsSet(group.getId()));

    mTracksPref.setEntries(getAllTrackNamesAsCharSeq());
    mTracksPref.setEntryValues(getAllTrackIdsAsCharSeq());
    mTracksPref.setSummary(getTrackNamesForSummary());

}
 
Example 7
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) параметр задания пароля для удаления постов/файлов
 * @param group группа, на которую добавляется параметр
 */
protected void addPasswordPreference(PreferenceGroup group) {
    final Context context = group.getContext();
    EditTextPreference passwordPref = new EditTextPreference(context) {
        @Override
        protected void showDialog(Bundle state) {
            if (createPassword()) {
                setText(getDefaultPassword());
            }
            super.showDialog(state);
        }
    };
    passwordPref.setTitle(R.string.pref_password_title);
    passwordPref.setDialogTitle(R.string.pref_password_title);
    passwordPref.setSummary(R.string.pref_password_summary);
    passwordPref.setKey(getSharedKey(PREF_KEY_PASSWORD));
    passwordPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    passwordPref.getEditText().setSingleLine();
    passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) });
    group.addPreference(passwordPref);
}
 
Example 8
Source File: DvachModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasswordPreference(preferenceGroup);
    CheckBoxPreference onionPref = new LazyPreferences.CheckBoxPreference(context);
    onionPref.setTitle(R.string.pref_use_onion);
    onionPref.setSummary(R.string.pref_use_onion_summary);
    onionPref.setKey(getSharedKey(PREF_KEY_USE_ONION));
    onionPref.setDefaultValue(false);
    onionPref.setDisableDependentsState(true);
    preferenceGroup.addPreference(onionPref);
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    preferenceGroup.addPreference(domainPref);
    domainPref.setDependency(getSharedKey(PREF_KEY_USE_ONION));
    addProxyPreferences(preferenceGroup);
}
 
Example 9
Source File: PreferencesUtil.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();

    if (preference instanceof ListPreference) {
        // For list preferences, look up the correct display value in
        // the preference's 'entries' list.
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);

        // Set the summary to reflect the new value.
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (preference instanceof RingtonePreference) {
    } else if (preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    } else {
        // For all other preferences, set the summary to the value's
        // simple string representation.
        preference.setSummary(stringValue);
    }
    return true;
}
 
Example 10
Source File: PBServerPreferenceFragment.java    From client-android with GNU General Public License v2.0 6 votes vote down vote up
private void setSummaries() {
    final EditTextPreference urlPreference = (EditTextPreference) findPreference(PREF_SERVER_URL);
    urlPreference.setSummary(preferences.getString(PREF_SERVER_URL, this.getResources().getString(R.string.server_url_summary)));

    final String serverPassHash = preferences.getString(PREF_SERVER_PASS_HASH, "");
    final EditTextPreference serverPassTextPreference = (EditTextPreference) findPreference(PREF_SERVER_PASS);
    if (serverPassHash.isEmpty()) {
        serverPassTextPreference.setSummary(getResources().getString(R.string.server_password_summary));
    } else {
        serverPassTextPreference.setSummary(getResources().getString(R.string.server_password_summary_set));
    }

    final EditTextPreference httpLoginPreference = (EditTextPreference) findPreference(PREF_SERVER_HTTP_AUTH_LOGIN);
    httpLoginPreference.setSummary(preferences.getString(PREF_SERVER_HTTP_AUTH_LOGIN, ""));

    final String httpPass = preferences.getString(PREF_SERVER_HTTP_AUTH_PASS,"");
    if (!httpPass.isEmpty()) {
        final EditTextPreference httpPassPreference = (EditTextPreference) findPreference(PREF_SERVER_HTTP_AUTH_PASS);
        httpPassPreference.setSummary(getResources().getString(R.string.server_password_summary_set));
    }
}
 
Example 11
Source File: SetupActivity.java    From trigger with GNU General Public License v2.0 6 votes vote down vote up
private void setText(String key, String value) {
    Preference p = findAnyPreference(key, null);
    if (p instanceof EditTextPreference) {
        EditTextPreference etp = (EditTextPreference) p;
        etp.setText(value);

        // show value as summary
        etp.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
            preference.setSummary(getSummaryValue(key, newValue.toString()));
            return true;
        });
        etp.setSummary(getSummaryValue(key, value));
    } else if (p instanceof ListPreference) {
        ListPreference lp = (ListPreference) p;
        lp.setValue(value);
        // set summary field to "%s" in xml
    } else {
        Log.w("SetupActivity.setText", "Cannot find EditTextPreference/ListPreference in PreferenceGroup with key: " + key);
    }
}
 
Example 12
Source File: SettingsFragment.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void initNetworkSettings() {
	((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))).setChecked(mPrefs.isWifiOnlyEnabled());

	// Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled
	CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key));
	CheckBoxPreference turn = (CheckBoxPreference) findPreference(getString(R.string.pref_turn_enable_key));
	ice.setChecked(mPrefs.isIceEnabled());
	turn.setEnabled(mPrefs.getStunServer() != null);
	turn.setChecked(mPrefs.isTurnEnabled());

	EditTextPreference turnUsername = (EditTextPreference) findPreference(getString(R.string.pref_turn_username_key));
	EditTextPreference turnPassword = (EditTextPreference) findPreference(getString(R.string.pref_turn_passwd_key));
	turnUsername.setEnabled(mPrefs.isTurnEnabled());
	turnUsername.setSummary(mPrefs.getTurnUsername());
	turnUsername.setText(mPrefs.getTurnUsername());
	turnPassword.setEnabled(mPrefs.isTurnEnabled());

	CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(getString(R.string.pref_transport_use_random_ports_key));
	randomPort.setChecked(mPrefs.isUsingRandomPort());

	// Disable sip port choice if port is random
	EditTextPreference sipPort = (EditTextPreference) findPreference(getString(R.string.pref_sip_port_key));
	sipPort.setEnabled(!randomPort.isChecked());
	sipPort.setSummary(mPrefs.getSipPort());
	sipPort.setText(mPrefs.getSipPort());

	EditTextPreference stun = (EditTextPreference) findPreference(getString(R.string.pref_stun_server_key));
	stun.setSummary(mPrefs.getStunServer());
	stun.setText(mPrefs.getStunServer());

	((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))).setChecked(mPrefs.isPushNotificationEnabled());
	((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6());
}
 
Example 13
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) новую категорию настроек прокси-сервера
 * @param group группа, на которую добавляются параметры
 */
protected void addProxyPreferences(PreferenceGroup group) {
    final Context context = group.getContext();
    PreferenceCategory proxyCat = new PreferenceCategory(context); //категория настроек прокси
    proxyCat.setTitle(R.string.pref_cat_proxy);
    group.addPreference(proxyCat);
    CheckBoxPreference useProxyPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать ли прокси вообще"
    useProxyPref.setTitle(R.string.pref_use_proxy);
    useProxyPref.setSummary(R.string.pref_use_proxy_summary);
    useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY));
    useProxyPref.setDefaultValue(false);
    useProxyPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(useProxyPref);
    EditTextPreference proxyHostPref = new LazyPreferences.EditTextPreference(context); //поле ввода адреса прокси-сервера
    proxyHostPref.setTitle(R.string.pref_proxy_host);
    proxyHostPref.setDialogTitle(R.string.pref_proxy_host);
    proxyHostPref.setSummary(R.string.pref_proxy_host_summary);
    proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST));
    proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST);
    proxyHostPref.getEditText().setSingleLine();
    proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    proxyHostPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPref);
    proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
    EditTextPreference proxyHostPort = new LazyPreferences.EditTextPreference(context); //поле ввода порта прокси-сервера
    proxyHostPort.setTitle(R.string.pref_proxy_port);
    proxyHostPort.setDialogTitle(R.string.pref_proxy_port);
    proxyHostPort.setSummary(R.string.pref_proxy_port_summary);
    proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT));
    proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT);
    proxyHostPort.getEditText().setSingleLine();
    proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    proxyHostPort.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPort);
    proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
}
 
Example 14
Source File: ChanFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
private void updateDefaultBoardSummary() {
	EditTextPreference preference = defaultBoardPreference;
	String text = preference.getText();
	if (!StringUtils.isEmpty(text)) {
		String boardName = StringUtils.validateBoardName(text);
		if (boardName != null) {
			text = StringUtils.formatBoardTitle(chanName, boardName,
					ChanConfiguration.get(chanName).getBoardTitle(boardName));
		} else {
			text = null;
		}
	}
	preference.setSummary(text);
}
 
Example 15
Source File: SettingsFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * Show IP Address.
 */
private void showIPAddress() {
    String ipAddress = DConnectUtil.getIPAddress(getActivity());

    // Set Host IP Address.
    EditTextPreference editHostPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_host));
    editHostPreferences.setSummary(ipAddress);
    
    // Set Host IP Address.
    EditTextPreference webHostPref = (EditTextPreference)
            getPreferenceScreen().findPreference(getString(R.string.key_settings_web_server_host));
    webHostPref.setSummary(ipAddress);
}
 
Example 16
Source File: AlarmPreferencesFragment.java    From boilr with GNU General Public License v3.0 5 votes vote down vote up
protected void disableDependentOnPairHitAlarm() {
	EditTextPreference[] edits = { mUpperLimitPref, mLowerLimitPref };
	for (EditTextPreference edit : edits) {
		edit.setEnabled(false);
		edit.setSummary(null);
	}
}
 
Example 17
Source File: SettingsFragment.java    From developerWorks with Apache License 2.0 4 votes vote down vote up
private void updatePreference(Preference preference) {
    if (preference != null && preference instanceof EditTextPreference) {
        EditTextPreference editTextPreference = (EditTextPreference) preference;
        editTextPreference.setSummary(editTextPreference.getText());
    }
}
 
Example 18
Source File: SettingsActivity.java    From matlog with GNU General Public License v3.0 4 votes vote down vote up
private void setUpPreferences() {
    setCurrentValue("ui.theme");
    setCurrentValue("theme");

    displayLimitPreference = (EditTextPreference) findPreference(getString(R.string.pref_display_limit));

    int displayLimitValue = PreferenceHelper.getDisplayLimitPreference(getActivity());

    displayLimitPreference.setSummary(getString(R.string.pref_display_limit_summary,
            displayLimitValue, getString(R.string.pref_display_limit_default)));
    displayLimitPreference.setOnPreferenceChangeListener(this);

    filterPatternPreference = (EditTextPreference) findPreference(getString(R.string.pref_filter_pattern));
    filterPatternPreference.setSummary(getString(R.string.pref_filter_pattern_summary));
    filterPatternPreference.setOnPreferenceChangeListener(this);

    logLinePeriodPreference = (EditTextPreference) findPreference(getString(R.string.pref_log_line_period));

    int logLinePrefValue = PreferenceHelper.getLogLinePeriodPreference(getActivity());

    logLinePeriodPreference.setSummary(getString(R.string.pref_log_line_period_summary,
            logLinePrefValue, getString(R.string.pref_log_line_period_default)));

    logLinePeriodPreference.setOnPreferenceChangeListener(this);

    textSizePreference = (ListPreference) findPreference(getString(R.string.pref_text_size));
    textSizePreference.setSummary(textSizePreference.getEntry());
    textSizePreference.setOnPreferenceChangeListener(this);

    defaultLevelPreference = (ListPreference) findPreference(getString(R.string.pref_default_log_level));
    defaultLevelPreference.setOnPreferenceChangeListener(this);
    setDefaultLevelPreferenceSummary(defaultLevelPreference.getEntry());

    mThemePreference = findPreference("ui.theme");
    mThemePreference.setOnPreferenceChangeListener(this);

    bufferPreference = (MultipleChoicePreference) findPreference(getString(R.string.pref_buffer));
    bufferPreference.setOnPreferenceChangeListener(this);
    setBufferPreferenceSummary(bufferPreference.getValue());

    mThemePreference.setOnPreferenceChangeListener(this);

    mAboutPreference = findPreference(getString(R.string.pref_about));
    mAboutPreference.setOnPreferenceClickListener(preference -> {
        // launch about activity
        Intent intent = new Intent(getActivity(), AboutDialogActivity.class);
        startActivity(intent);
        return true;
    });
    mAboutPreference.setSummary(getString(R.string.version, PackageHelper.getVersionName(getActivity())));

    scrubberPreference = (SwitchPreference) getPreferenceScreen().findPreference("scrubber");
    scrubberPreference.setOnPreferenceChangeListener((preference, newValue) -> {
        LogLine.isScrubberEnabled = (boolean) newValue;
        return true;
    });
}
 
Example 19
Source File: SettingsFragment.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = SimplicityApplication.getContextOfApplication();
    mAuth = FirebaseAuth.getInstance();
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    addPreferencesFromResource(R.xml.settings);
    sync = findPreference("sync_click");
    EditTextPreference pref = (EditTextPreference) findPreference("homepage");
    pref.setSummary(UserPreferences.getString("homepage",""));


    myPrefListner = (prefs, key) -> {
        UserPreferences.putString("should_sync", "true");
        switch (key) {
            case "homepage":
                EditTextPreference pref1 = (EditTextPreference) findPreference("homepage");

                if (pref1.getText().contains("http://") || pref1.getText().contains("https://")) {
                    pref1.setSummary(pref1.getText());
                    preferences.edit().putString("homepage", pref1.getText()).apply();
                } else if (!pref1.getText().contains("http://") || !pref1.getText().contains("https://")) {
                    pref1.setSummary("http://" + pref1.getText());
                    preferences.edit().putString("homepage", "http://" + pref1.getText()).apply();
                }
                break;
            case "enable_location":
                if (preferences.getBoolean("enable_location", false)) {
                    requestLocationPermission();
                } else {
                    Log.i("Settings", "Location enabled");
                }
                break;

            case "address_bar":
                preferences.edit().putString("needs_change", "true").apply();
                break;

            case "dark_mode":
                SettingsActivity.showSheet();
                break;


            default:
                break;
        }

    };

    Preference overflow = findPreference("about_app");
    Preference terms = findPreference("terms_set");
    Preference donate = findPreference("sim_donate");
    Preference backup_restore = findPreference("back_restore");
    Preference policy = findPreference("privacy_policy_set");
    Preference plugins = findPreference("plugins");
    overflow.setOnPreferenceClickListener(this);
    donate.setOnPreferenceClickListener(this);
    terms.setOnPreferenceClickListener(this);
    policy.setOnPreferenceClickListener(this);
    backup_restore.setOnPreferenceClickListener(this);
    plugins.setOnPreferenceClickListener(this);
    sync.setOnPreferenceClickListener(this);
    cache = findPreference("delete_cache");
    initializeCache();
    cache.setOnPreferenceClickListener(this);


}
 
Example 20
Source File: TagSettingActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * EditTextPreference の summary に値を表示するように設定します.
 *
 * @param key EditTextPreference のキー
 */
private void setEditTextPreferenceSummary(String key) {
    EditTextPreference pref = (EditTextPreference) getPreferenceScreen().findPreference(key);
    pref.setSummary(pref.getText());
    pref.setOnPreferenceChangeListener(this);
}