Search in sources :

Example 1 with EditTextPreference

use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.

the class SettingsFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    if (pref instanceof EditTextPreference) {
        EditTextPreference editTextPref = (EditTextPreference) pref;
        MinMaxInfos prefMinMax = listOfMinMaxInfos.get(editTextPref.getKey());
        if (prefMinMax != null) {
            int prefValue = 0;
            if (!editTextPref.getText().isEmpty()) {
                try {
                    prefValue = Integer.parseInt(editTextPref.getText());
                } catch (Exception e) {
                    prefValue = 999999999;
                }
            }
            if (prefValue < prefMinMax.min) {
                prefValue = prefMinMax.min;
            } else if (prefValue > prefMinMax.max) {
                prefValue = prefMinMax.max;
            }
            editTextPref.setText(String.valueOf(prefValue));
        }
    } else if (key.equals(getString(R.string.settingsThemeUsed))) {
        ThemeManager.updateThemeUsed();
        if (getActivity() != null) {
            getActivity().recreate();
        }
    } else if (key.equals(getString(R.string.settingsInvertToolbarTextColor))) {
        ThemeManager.updateToolbarTextColor();
        if (getActivity() != null) {
            getActivity().recreate();
        }
    } else if (key.equals(getString(R.string.settingsPrimaryColorOfLightTheme)) || key.equals(getString(R.string.settingsTopicNameAndAccentColorOfLightTheme))) {
        if (getActivity() != null) {
            ThemeManager.updateColorsUsed(getResources());
            getActivity().recreate();
        }
    } else if (key.startsWith("settings.customColor.")) {
        if (getActivity() != null) {
            ThemeManager.updateColorsUsed(getResources());
        }
    }
    updatePrefSummary(pref);
}
Also used : CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(com.takisoft.fix.support.v7.preference.EditTextPreference) EditTextPreference(com.takisoft.fix.support.v7.preference.EditTextPreference)

Example 2 with EditTextPreference

use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.

the class SettingsFragment method updatePrefSummary.

private void updatePrefSummary(Preference pref) {
    if (pref instanceof EditTextPreference) {
        EditTextPreference editTextPref = (EditTextPreference) pref;
        MinMaxInfos prefMinMax = listOfMinMaxInfos.get(editTextPref.getKey());
        if (prefMinMax != null) {
            editTextPref.setSummary("Entre " + String.valueOf(prefMinMax.min) + " et " + String.valueOf(prefMinMax.max) + " : " + editTextPref.getText());
        }
    }
}
Also used : EditTextPreference(com.takisoft.fix.support.v7.preference.EditTextPreference)

Example 3 with EditTextPreference

use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.

the class SettingsFragment method updatePrefDefaultValue.

/* Le but de la clef temporaire est de ne pas sauvegarder l'option par défaut si c'est celle ci
     * qui est retourné par "PrefsManager.getX()". La clef temporaire n'est pas vide pour empêcher
     * des possibles crash (des histoires de requireKey() etc). Elle est unique par type de pref pour
     * ne pas causer de crash lors de l'assignation d'un string à ce qui était précédement un bool.
     * La persistance est temporairement à false pour plus de sécurité, au cas où, dans le doute,
     * mais ça reste plutôt assez moche comme solution au final. */
private static void updatePrefDefaultValue(Preference pref) {
    String realPrefKey = pref.getKey();
    pref.setPersistent(false);
    if (pref instanceof CheckBoxPreference) {
        pref.setKey("tmpKeyBool");
        CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
        checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof SwitchPreferenceCompat) {
        pref.setKey("tmpKeyBool");
        SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
        switchPref.setChecked(PrefsManager.getBool(realPrefKey));
    } else if (pref instanceof EditTextPreference) {
        pref.setKey("tmpKeyString");
        EditTextPreference editTextPref = (EditTextPreference) pref;
        editTextPref.setText(PrefsManager.getString(realPrefKey));
    } else if (pref instanceof ListPreference) {
        pref.setKey("tmpKeyString");
        ListPreference listPref = (ListPreference) pref;
        listPref.setValue(PrefsManager.getString(realPrefKey));
    }
    pref.setPersistent(true);
    pref.setKey(realPrefKey);
}
Also used : CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) EditTextPreference(com.takisoft.fix.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference)

Example 4 with EditTextPreference

use of com.takisoft.fix.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 5 with EditTextPreference

use of com.takisoft.fix.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)

Aggregations

EditTextPreference (android.support.v7.preference.EditTextPreference)11 Preference (android.support.v7.preference.Preference)10 ListPreference (android.support.v7.preference.ListPreference)8 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 EditTextIntegerPreference (cx.ring.views.EditTextIntegerPreference)2 PasswordPreference (cx.ring.views.PasswordPreference)2 File (java.io.File)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1