Example usage for android.preference EditTextPreference setSummary

List of usage examples for android.preference EditTextPreference setSummary

Introduction

In this page you can find the example usage for android.preference EditTextPreference setSummary.

Prototype

public void setSummary(CharSequence summary) 

Source Link

Document

Sets the summary for this Preference with a CharSequence.

Usage

From source file:org.thoughtcrime.securesms.MmsPreferencesFragment.java

private void initializeEditTextSummary(final EditTextPreference preference) {
    if (preference.getText() == null) {
        preference.setSummary("Not set");
    } else {/*  w w  w . jav a2s  .c  om*/
        preference.setSummary(preference.getText());
    }

    preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference pref, Object newValue) {
            preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
            return true;
        }
    });
}

From source file:com.manning.androidhacks.hack004.MainActivity.java

private void updateUserText() {
    EditTextPreference pref;
    pref = (EditTextPreference) findPreference("pref_username");
    String user = pref.getText();

    if (user == null) {
        user = "?";
    }//  www .  j  a  v a2s.com

    pref.setSummary(String.format("Username: %s", user));
}

From source file:com.nttec.everychan.chans.nullchan.NullchanccModule.java

private void addDomainPreference(PreferenceGroup group) {
    Context context = group.getContext();
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setDialogTitle(R.string.pref_domain);
    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);
    group.addPreference(domainPref);/*from   ww  w. j a v  a  2s  . c  o  m*/
}

From source file:nya.miku.wishmaster.chans.endchan.EndChanModule.java

private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override//  www.  ja v a2 s. c  o  m
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                updateDomain((String) newValue);
                return true;
            }
            return false;
        }
    };
    PreferenceCategory domainCat = new PreferenceCategory(context);
    domainCat.setTitle(R.string.makaba_prefs_domain_category);
    group.addPreference(domainCat);
    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);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(domainPref);
}

From source file:fr.free.nrw.commons.settings.SettingsFragment.java

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

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    // Update spinner to show selected value as summary
    ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
    licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));

    // Keep summary updated when changing value
    licensePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
        return true;
    });/* w w  w  .  j  a v a2  s .c  o  m*/

    CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme");
    themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        getActivity().recreate();
        return true;
    });

    final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
    int uploads = prefs.getInt(Prefs.UPLOADS_SHOWING, 100);
    uploadLimit.setText(uploads + "");
    uploadLimit.setSummary(uploads + "");
    uploadLimit.setOnPreferenceChangeListener((preference, newValue) -> {
        int value = Integer.parseInt(newValue.toString());
        final SharedPreferences.Editor editor = prefs.edit();
        if (value > 500) {
            new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit)
                    .setMessage(R.string.maximum_limit_alert)
                    .setPositiveButton(android.R.string.yes, (dialog, which) -> {
                    }).setIcon(android.R.drawable.ic_dialog_alert).show();
            editor.putInt(Prefs.UPLOADS_SHOWING, 500);
            editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
            uploadLimit.setSummary(500 + "");
            uploadLimit.setText(500 + "");
        } else {
            editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString()));
            editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
            uploadLimit.setSummary(newValue.toString());
        }
        editor.apply();
        return true;
    });

    Preference sendLogsPreference = findPreference("sendLogFile");
    sendLogsPreference.setOnPreferenceClickListener(preference -> {
        //first we need to check if we have the necessary permissions
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                sendAppLogsViaEmail();
            } else {
                //first get the necessary permission
                requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
            }
        } else {
            sendAppLogsViaEmail();
        }

        return true;
    });
}

From source file:org.deviceconnect.android.client.fragment.AbstractSettingsFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    Bundle args = new Bundle();
    args.putParcelableArrayList(OpenSourceLicenseFragment.EXTRA_OSS, getOpenSourceSoftware());
    mOssFragment = new OpenSourceLicenseFragment();
    mOssFragment.setArguments(args);//from  w  w  w .  j  ava2  s .c o  m

    Bundle policyArgs = new Bundle();
    policyArgs.putInt(Intent.EXTRA_TITLE, R.string.privacy_policy);
    policyArgs.putInt(Intent.EXTRA_TEXT, R.raw.privacypolicy);
    mPrivacyPolicyFragment = new TextDialogFragment();
    mPrivacyPolicyFragment.setArguments(policyArgs);

    Bundle tosArgs = new Bundle();
    tosArgs.putInt(Intent.EXTRA_TITLE, R.string.terms_of_service);
    tosArgs.putInt(Intent.EXTRA_TEXT, R.raw.termsofservice);
    mTermsOfServiceFragment = new TextDialogFragment();
    mTermsOfServiceFragment.setArguments(tosArgs);

    PreferenceScreen versionPreferences = (PreferenceScreen) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_about_appinfo));
    try {
        versionPreferences.setSummary((getActivity().getPackageManager()
                .getPackageInfo(getActivity().getPackageName(), 0).versionName));
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    CheckBoxPreference checkBoxSslPreferences = (CheckBoxPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_ssl));
    checkBoxSslPreferences.setOnPreferenceChangeListener(this);

    EditTextPreference editHostPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_host));
    editHostPreferences.setOnPreferenceChangeListener(this);
    editHostPreferences.setSummary(editHostPreferences.getText());

    EditTextPreference editPortPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_port));
    editPortPreferences.setOnPreferenceChangeListener(this);
    editPortPreferences.setSummary(editPortPreferences.getText());

    // Local OAuth
    SettingsActivity activity = (SettingsActivity) getActivity();

    EditTextPreference editClientIdPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_client_id));
    editClientIdPreferences.setSummary(activity.getClientId());

    EditTextPreference editClientSecretPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_client_secret));
    editClientSecretPreferences.setSummary(activity.getClientSecret());

    EditTextPreference editAccessTokenPreferences = (EditTextPreference) getPreferenceScreen()
            .findPreference(getString(R.string.key_settings_dconn_access_token));
    editAccessTokenPreferences.setSummary(activity.getAccessToken());
}

From source file:org.transdroid.core.seedbox.XirvikSharedSettingsActivity.java

@SuppressWarnings("deprecation")
protected void storeScgiMountFolder(String result) {
    Editor edit = PreferenceManager.getDefaultSharedPreferences(XirvikSharedSettingsActivity.this).edit();
    EditTextPreference pref = (EditTextPreference) findPreference("seedbox_xirvikshared_rpc_" + key);
    if (result == null) {
        Crouton.showText(this, R.string.pref_seedbox_xirviknofolder, NavigationHelper.CROUTON_ERROR_STYLE);
        edit.remove("seedbox_xirvikshared_rpc_" + key);
        pref.setSummary("");
    } else {//from  w w  w  . ja  va2  s  . com
        edit.putString("seedbox_xirvikshared_rpc_" + key, result);
        pref.setSummary(result);
    }
    edit.commit();
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java

private EditTextPreference getNamePreference() {
    final EditTextPreference name = new EditTextPreference(getActivity());
    name.setTitle(R.string.special_list_name);
    name.setSummary(mItem.getName());
    name.setText(mItem.getName());//  www  . j  ava  2s  . co m
    name.setSummary(mItem.getName());
    name.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            final EditText input = new EditText(getActivity());
            input.setSingleLine(true);
            input.setText(mItem.getName());
            new AlertDialog.Builder(getActivity()).setTitle(R.string.special_list_name).setView(input)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            mItem.setName(input.getText().toString());
                            mItem.save();
                            name.setSummary(mItem.getName());
                            mAdapter.notifyDataSetChanged();
                        }
                    }).setNegativeButton(android.R.string.cancel, null).show();
            return true;
        }
    });
    return name;
}

From source file:nya.miku.wishmaster.chans.tirech.TirechModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    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);
    addPasswordPreference(preferenceGroup);
    addCloudflareRecaptchaFallbackPreference(preferenceGroup);
    addProxyPreferences(preferenceGroup);
}

From source file:be.ppareit.swiftp.gui.PreferenceFragment.java

private void updateLoginInfo() {

    String username = FsSettings.getUserName();
    String password = FsSettings.getPassWord();

    Cat.v("Updating login summary");
    PreferenceScreen loginPreference = findPref("login");
    loginPreference.setSummary(username + " : " + transformPassword(password));
    ((BaseAdapter) loginPreference.getRootAdapter()).notifyDataSetChanged();

    EditTextPreference usernamePref = findPref("username");
    usernamePref.setSummary(username);

    EditTextPreference passWordPref = findPref("password");
    passWordPref.setSummary(transformPassword(password));
}