Search in sources :

Example 11 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project ring-client-android by savoirfairelinux.

the class AdvancedAccountFragment method initView.

@Override
public void initView(AccountConfig config, ArrayList<CharSequence> networkInterfaces) {
    for (ConfigKey confKey : config.getKeys()) {
        Preference pref = findPreference(confKey.key());
        if (pref != null) {
            pref.setOnPreferenceChangeListener(this);
            if (confKey == ConfigKey.LOCAL_INTERFACE) {
                String val = config.get(confKey);
                CharSequence[] display = networkInterfaces.toArray(new CharSequence[networkInterfaces.size()]);
                ListPreference listPref = (ListPreference) pref;
                listPref.setEntries(display);
                listPref.setEntryValues(display);
                listPref.setSummary(val);
                listPref.setValue(val);
            } else if (!confKey.isTwoState()) {
                String val = config.get(confKey);
                pref.setSummary(val);
                if (pref instanceof EditTextPreference) {
                    ((EditTextPreference) pref).setText(val);
                }
            } else {
                ((TwoStatePreference) pref).setChecked(config.getBool(confKey));
            }
        }
    }
}
Also used : ConfigKey(cx.ring.model.ConfigKey) ListPreference(android.support.v7.preference.ListPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) EditTextIntegerPreference(cx.ring.views.EditTextIntegerPreference) PasswordPreference(cx.ring.views.PasswordPreference) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference)

Example 12 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project haven by guardianproject.

the class SettingsFragment method onCreatePreferencesFix.

@Override
public void onCreatePreferencesFix(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);
    mActivity = getActivity();
    preferences = new PreferenceManager(mActivity);
    setHasOptionsMenu(true);
    app = (HavenApp) mActivity.getApplication();
    /*
         * We create an application directory to store images and audio
         */
    File directory = new File(Environment.getExternalStorageDirectory() + preferences.getDirPath());
    directory.mkdirs();
    if (preferences.getCameraActivation()) {
        String camera = preferences.getCamera();
        switch(camera) {
            case PreferenceManager.FRONT:
                ((ListPreference) findPreference(PreferenceManager.CAMERA)).setValueIndex(0);
                break;
            case PreferenceManager.BACK:
                ((ListPreference) findPreference(PreferenceManager.CAMERA)).setValueIndex(1);
                break;
            case PreferenceManager.OFF:
                ((ListPreference) findPreference(PreferenceManager.CAMERA)).setValueIndex(2);
                break;
        }
    }
    if (preferences.getSmsActivation()) {
        ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).setChecked(true);
    }
    if (checkValidString(preferences.getSmsNumber())) {
        ((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).setText(preferences.getSmsNumber().trim());
        findPreference(PreferenceManager.SMS_NUMBER).setSummary(preferences.getSmsNumber().trim());
    } else {
        findPreference(PreferenceManager.SMS_NUMBER).setSummary(R.string.sms_dialog_summary);
    }
    if (preferences.getRemoteAccessActive()) {
        ((SwitchPreferenceCompat) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).setChecked(true);
    }
    if (checkValidString(preferences.getRemoteAccessOnion())) {
        ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_ONION)).setText(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
        findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(preferences.getRemoteAccessOnion().trim() + ":" + WebServer.LOCAL_PORT);
    } else {
        findPreference(PreferenceManager.REMOTE_ACCESS_ONION).setSummary(R.string.remote_access_hint);
    }
    if (checkValidString(preferences.getRemoteAccessCredential())) {
        ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).setText(preferences.getRemoteAccessCredential().trim());
        findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.bullets);
    } else {
        findPreference(PreferenceManager.REMOTE_ACCESS_CRED).setSummary(R.string.remote_access_credential_hint);
    }
    if (checkValidString(preferences.getSignalUsername())) {
        String signalNum = "+" + preferences.getSignalUsername().trim().replaceAll("[^0-9]", "");
        findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(signalNum);
    } else {
        findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc);
    }
    if (preferences.getNotificationTimeMs() > 0) {
        findPreference(PreferenceManager.NOTIFICATION_TIME).setSummary(preferences.getNotificationTimeMs() / 60000 + " " + getString(R.string.minutes));
    }
    Preference prefCameraSensitivity = findPreference(PreferenceManager.CAMERA_SENSITIVITY);
    prefCameraSensitivity.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(mActivity, CameraConfigureActivity.class));
        return true;
    });
    Preference prefConfigMovement = findPreference(PreferenceManager.CONFIG_MOVEMENT);
    prefConfigMovement.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(mActivity, AccelConfigureActivity.class));
        return true;
    });
    Preference prefConfigSound = findPreference(PreferenceManager.CONFIG_SOUND);
    prefConfigSound.setOnPreferenceClickListener(preference -> {
        startActivity(new Intent(mActivity, MicrophoneConfigureActivity.class));
        return true;
    });
    Preference prefConfigTimeDelay = findPreference(PreferenceManager.CONFIG_TIME_DELAY);
    prefConfigTimeDelay.setOnPreferenceClickListener(preference -> {
        showTimeDelayDialog(PreferenceManager.CONFIG_TIME_DELAY);
        return true;
    });
    Preference prefConfigVideoLength = findPreference(PreferenceManager.CONFIG_VIDEO_LENGTH);
    prefConfigVideoLength.setOnPreferenceClickListener(preference -> {
        showTimeDelayDialog(PreferenceManager.CONFIG_VIDEO_LENGTH);
        return true;
    });
    Preference prefDisableBatteryOpt = findPreference(PreferenceManager.DISABLE_BATTERY_OPT);
    prefDisableBatteryOpt.setOnPreferenceClickListener(preference -> {
        requestChangeBatteryOptimizations();
        return true;
    });
    checkSignalUsername();
    ((EditTextPreference) findPreference(PreferenceManager.VERIFY_SIGNAL)).setText("");
    askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 1);
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) SwitchPreference(android.support.v14.preference.SwitchPreference) MicrophoneConfigureActivity(org.havenapp.main.ui.MicrophoneConfigureActivity) CameraConfigureActivity(org.havenapp.main.ui.CameraConfigureActivity) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) AccelConfigureActivity(org.havenapp.main.ui.AccelConfigureActivity) File(java.io.File)

Example 13 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project network-monitor by caarmen.

the class EmailPreferencesActivity method updatePreferenceSummary.

private void updatePreferenceSummary(CharSequence key, int summaryResId) {
    Preference pref = mPreferenceFragment.findPreference(key);
    CharSequence value;
    if (key.equals(EmailPreferences.PREF_EMAIL_LAST_EMAIL_SENT)) {
        long lastEmailSent = EmailPreferences.getInstance(this).getLastEmailSent();
        if (lastEmailSent > 0)
            value = DateUtils.formatDateTime(this, lastEmailSent, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR);
        else
            value = getString(R.string.pref_value_email_report_interval_never);
    } else if (pref instanceof EditTextPreference)
        value = ((EditTextPreference) pref).getText();
    else if (pref instanceof MultiSelectListPreference)
        value = getSummary((MultiSelectListPreference) pref, ((MultiSelectListPreference) pref).getValues());
    else if (pref instanceof ListPreference)
        value = ((ListPreference) pref).getEntry();
    else
        return;
    if (value == null) {
        value = "";
    }
    String summary = getString(summaryResId, value);
    pref.setSummary(summary);
}
Also used : ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) MultiSelectListPreference(android.support.v14.preference.MultiSelectListPreference) MultiSelectListPreference(android.support.v14.preference.MultiSelectListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) MultiSelectListPreference(android.support.v14.preference.MultiSelectListPreference)

Example 14 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project network-monitor by caarmen.

the class SpeedTestPreferencesActivity method updatePreferenceSummary.

private void updatePreferenceSummary(CharSequence key, int summaryResId) {
    Preference pref = mPreferenceFragment.findPreference(key);
    if (pref instanceof EditTextPreference) {
        CharSequence value = ((EditTextPreference) pref).getText();
        if (value == null) {
            value = "";
        }
        String summary = getString(summaryResId, value);
        pref.setSummary(summary);
    }
}
Also used : Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) EditTextPreference(android.support.v7.preference.EditTextPreference)

Example 15 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project i2p.i2p-bote by i2p.

the class AdvancedPreferenceFragment method setupI2PCategory.

private static void setupI2PCategory(Context context, PreferenceCategory i2pCat) {
    final ListPreference routerChoice = createRouterChoice(context);
    final EditTextPreference hostField = createHostField(context);
    final EditTextPreference portField = createPortField(context);
    i2pCat.addPreference(routerChoice);
    i2pCat.addPreference(hostField);
    i2pCat.addPreference(portField);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        routerChoice.setSummary(routerChoice.getEntry());
    if ("remote".equals(routerChoice.getValue())) {
        hostField.setEnabled(true);
        portField.setEnabled(true);
    }
    routerChoice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String val = newValue.toString();
            int index = routerChoice.findIndexOfValue(val);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                routerChoice.setSummary(routerChoice.getEntries()[index]);
            if (index == 2) {
                hostField.setEnabled(true);
                hostField.setText("127.0.0.1");
                portField.setEnabled(true);
                portField.setText("7654");
            } else {
                hostField.setEnabled(false);
                hostField.setText("internal");
                portField.setEnabled(false);
                portField.setText("internal");
            }
            return true;
        }
    });
}
Also used : Preference(android.support.v7.preference.Preference) SummaryEditTextPreference(i2p.bote.android.config.util.SummaryEditTextPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) ListPreference(android.support.v7.preference.ListPreference) SummaryEditTextPreference(i2p.bote.android.config.util.SummaryEditTextPreference) EditTextPreference(android.support.v7.preference.EditTextPreference)

Aggregations

EditTextPreference (android.support.v7.preference.EditTextPreference)11 Preference (android.support.v7.preference.Preference)10 ListPreference (android.support.v7.preference.ListPreference)8 AlertDialog (android.support.v7.app.AlertDialog)3 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)3 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)3 TwoStatePreference (android.support.v7.preference.TwoStatePreference)3 EditTextPreference (com.takisoft.fix.support.v7.preference.EditTextPreference)3 ConfigKey (cx.ring.model.ConfigKey)3 SummaryEditTextPreference (i2p.bote.android.config.util.SummaryEditTextPreference)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 EditTextPreference (android.preference.EditTextPreference)2 Toast (android.widget.Toast)2 EditTextIntegerPreference (cx.ring.views.EditTextIntegerPreference)2 PasswordPreference (cx.ring.views.PasswordPreference)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1