Search in sources :

Example 6 with EditTextPreference

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

the class GeneralAccountFragment method setPreferenceDetails.

private void setPreferenceDetails(AccountConfig details) {
    for (ConfigKey confKey : details.getKeys()) {
        Preference pref = findPreference(confKey.key());
        if (pref == null) {
            continue;
        }
        if (!confKey.isTwoState()) {
            String val = details.get(confKey);
            ((EditTextPreference) pref).setText(val);
            if (pref instanceof PasswordPreference) {
                StringBuilder tmp = new StringBuilder();
                for (int i = 0; i < val.length(); ++i) {
                    tmp.append("*");
                }
                pref.setSummary(tmp.toString());
            } else {
                pref.setSummary(val);
            }
        } else {
            ((TwoStatePreference) pref).setChecked(details.getBool(confKey));
        }
    }
}
Also used : ConfigKey(cx.ring.model.ConfigKey) TwoStatePreference(android.support.v7.preference.TwoStatePreference) 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) PasswordPreference(cx.ring.views.PasswordPreference) EditTextPreference(android.support.v7.preference.EditTextPreference)

Example 7 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project MPW by shineangelic.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences);
    // Crashlytics.getInstance().crash();
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());
    PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
    CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
    final android.support.v7.preference.SwitchPreferenceCompat globalNotifications = (SwitchPreferenceCompat) findPreference("pref_notify");
    final android.support.v7.preference.EditTextPreference walletAddr = (EditTextPreference) findPreference("wallet_addr");
    final android.support.v7.preference.SwitchPreferenceCompat service = (SwitchPreferenceCompat) findPreference("pref_sync");
    final android.support.v7.preference.ListPreference listFreqPreference = (ListPreference) findPreference("pref_sync_freq");
    final android.support.v7.preference.SwitchPreferenceCompat offlineNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_offline");
    final android.support.v7.preference.SwitchPreferenceCompat blockNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_block");
    final android.support.v7.preference.SwitchPreferenceCompat paymentNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_payment");
    // Service Enabled listener
    Preference.OnPreferenceChangeListener listenerServ = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // newValue is the value you choose
            listFreqPreference.setEnabled((Boolean) newValue);
            Boolean nv = (Boolean) newValue;
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            dispatcher.cancelAll();
            if (nv) {
                Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
                int res = dispatcher.schedule(myJob);
                if (res != dispatcher.SCHEDULE_RESULT_SUCCESS) {
                    Toast.makeText(getActivity(), "Cannot enable service. Is Play Services up to date? Notifications won't work", Toast.LENGTH_SHORT).show();
                    return false;
                }
                Log.w(Constants.TAG, "SERVICE ACTIVE, schedule res: " + res);
            }
            // firebase log event
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, nv.toString());
            mFirebaseAnalytics.logEvent("service_active", bundle);
            return true;
        }
    };
    service.setOnPreferenceChangeListener(listenerServ);
    // Service FREQ listener
    Preference.OnPreferenceChangeListener listenerServF = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Integer nv = Integer.valueOf((String) newValue);
            // newValue is the value you choose
            Log.w(Constants.TAG, "Changed FREQ setting to: " + nv);
            // pezza perche il val ancora non c'e
            prefs.edit().putString("pref_sync_freq", "" + nv).apply();
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
            dispatcher.schedule(myJob);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_freq", bundle);
            return true;
        }
    };
    listFreqPreference.setOnPreferenceChangeListener(listenerServF);
    // Notification global
    Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.w(Constants.TAG, "Changed NOTIF setting to: " + newValue);
            Boolean nv = (Boolean) newValue;
            // newValue is the value you choose
            blockNotifications.setEnabled(nv);
            offlineNotifications.setEnabled(nv);
            paymentNotifications.setEnabled(nv);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_notifications", bundle);
            return true;
        }
    };
    globalNotifications.setOnPreferenceChangeListener(listener);
    // Listener x controllo correttezza
    walletAddr.setOnPreferenceChangeListener(new WalletPrefChangeListener(getActivity(), mPool, mCur));
    walletAddr.setSummary(getString(R.string.wallet_info, mPool.toString(), mCur.toString()));
    walletAddr.setDialogTitle(mPool.toString() + " Network Login");
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) SharedPreferences(android.content.SharedPreferences) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) Bundle(android.os.Bundle) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) Job(com.firebase.jobdispatcher.Job) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum)

Example 8 with EditTextPreference

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

the class AdvancedPreferenceFragment method createPortField.

private static EditTextPreference createPortField(Context context) {
    EditTextPreference p = new SummaryEditTextPreference(context);
    p.setKey("i2pbote.i2cp.tcp.port");
    p.setTitle(R.string.pref_title_i2cp_port);
    p.setSummary("%s");
    p.setDefaultValue("internal");
    p.setEnabled(false);
    return p;
}
Also used : SummaryEditTextPreference(i2p.bote.android.config.util.SummaryEditTextPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) SummaryEditTextPreference(i2p.bote.android.config.util.SummaryEditTextPreference)

Example 9 with EditTextPreference

use of android.support.v7.preference.EditTextPreference in project Rashr by DsLNeXuS.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);
    EditTextPreference recovery_path = (EditTextPreference) findPreference(App.PREF_KEY_RECOVERY_PATH);
    recovery_path.setText(App.Preferences.getString(App.PREF_KEY_RECOVERY_PATH, null));
    EditTextPreference kernel_path = (EditTextPreference) findPreference(App.PREF_KEY_KERNEL_PATH);
    kernel_path.setText(App.Preferences.getString(App.PREF_KEY_KERNEL_PATH, null));
    EditTextPreference device_name = (EditTextPreference) findPreference(App.PREF_KEY_DEVICE_NAME);
    device_name.setText(App.Device.getName());
    device_name.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            View v = getView();
            if (v == null)
                return true;
            if (!newValue.toString().equals("")) {
                Snackbar.make(v, R.string.please_restart, Snackbar.LENGTH_INDEFINITE).show();
            }
            return true;
        }
    });
    Preference changelog = findPreference(App.PREF_KEY_CHANGELOG);
    changelog.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showChangelog(getContext());
            return false;
        }
    });
    Preference showlogs = findPreference(App.PREF_KEY_SHOW_LOGS);
    showlogs.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showLogs();
            return false;
        }
    });
    Preference report = findPreference(App.PREF_KEY_REPORT);
    report.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            new ReportDialog(getActivity(), "").show();
            return false;
        }
    });
    Preference licenses = findPreference(App.PREF_KEY_LICENSES);
    licenses.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            new LicensesDialog.Builder(getContext()).setNotices(R.raw.licenses_notice).setIncludeOwnLicense(true).build().show();
            return false;
        }
    });
    Preference reset = findPreference(App.PREF_KEY_RESET_APP);
    reset.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences, true);
            return true;
        }
    });
    Preference clearCache = findPreference(App.PREF_KEY_CLEAR_CACHE);
    clearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            final AlertDialog.Builder ConfirmationDialog = new AlertDialog.Builder(getContext());
            ConfirmationDialog.setTitle(R.string.warning);
            ConfirmationDialog.setMessage(R.string.delete_confirmation);
            ConfirmationDialog.setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (!Common.deleteFolder(App.PathToCWM, false) || !Common.deleteFolder(App.PathToTWRP, false) || !Common.deleteFolder(App.PathToPhilz, false) || !Common.deleteFolder(App.PathToCM, false) || !Common.deleteFolder(App.PathToPhilz, false) || !Common.deleteFolder(App.PathToStockRecovery, false) || !Common.deleteFolder(App.PathToStockKernel, false)) {
                        Toast.makeText(getActivity(), R.string.delete_failed, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getActivity(), R.string.files_deleted, Toast.LENGTH_SHORT).show();
                    }
                }
            });
            ConfirmationDialog.setNegativeButton(R.string.negative, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            ConfirmationDialog.show();
            return false;
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) EditTextPreference(android.support.v7.preference.EditTextPreference) LicensesDialog(de.psdev.licensesdialog.LicensesDialog) View(android.view.View) WebView(android.webkit.WebView) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) ReportDialog(de.mkrtchyan.recoverytools.ReportDialog)

Example 10 with EditTextPreference

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

the class SecurityAccountFragment method setDetails.

@Override
public void setDetails(AccountConfig config, String[] tlsMethods) {
    for (int i = 0; i < tlsCategory.getPreferenceCount(); ++i) {
        final Preference current = tlsCategory.getPreference(i);
        final ConfigKey key = ConfigKey.fromString(current.getKey());
        if (current instanceof TwoStatePreference) {
            ((TwoStatePreference) current).setChecked(config.getBool(key));
        } else {
            if (key == ConfigKey.TLS_CA_LIST_FILE) {
                File crt = new File(config.get(ConfigKey.TLS_CA_LIST_FILE));
                current.setSummary(crt.getName());
                setFeedbackIcon(current);
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_PRIVATE_KEY_FILE) {
                current.setSummary(new File(config.get(ConfigKey.TLS_PRIVATE_KEY_FILE)).getName());
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_CERTIFICATE_FILE) {
                File pem = new File(config.get(ConfigKey.TLS_CERTIFICATE_FILE));
                current.setSummary(pem.getName());
                setFeedbackIcon(current);
                checkForRSAKey();
                current.setOnPreferenceClickListener(filePickerListener);
            } else if (key == ConfigKey.TLS_METHOD) {
                ListPreference listPref = (ListPreference) current;
                String curVal = config.get(key);
                listPref.setEntries(tlsMethods);
                listPref.setEntryValues(tlsMethods);
                listPref.setValue(curVal);
                current.setSummary(curVal);
            } else if (current instanceof EditTextPreference) {
                String val = config.get(key);
                ((EditTextPreference) current).setText(val);
                current.setSummary(val);
            } else {
                current.setSummary(config.get(key));
            }
        }
        current.setOnPreferenceChangeListener(tlsListener);
    }
}
Also used : ConfigKey(cx.ring.model.ConfigKey) TwoStatePreference(android.support.v7.preference.TwoStatePreference) CredentialsPreference(cx.ring.views.CredentialsPreference) ListPreference(android.support.v7.preference.ListPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) File(java.io.File)

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