Search in sources :

Example 6 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat 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 7 with SwitchPreferenceCompat

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

the class GeneralAccountFragment method accountChanged.

@Override
public void accountChanged(Account account) {
    if (account == null) {
        Log.d(TAG, "accountChanged: Null account");
        return;
    }
    setPreferenceDetails(account.getConfig());
    SwitchPreferenceCompat pref = (SwitchPreferenceCompat) findPreference("Account.status");
    if (account.isSip() && pref != null) {
        String status;
        pref.setTitle(account.getAlias());
        if (account.isEnabled()) {
            if (account.isTrying()) {
                status = getString(R.string.account_status_connecting);
            } else if (account.needsMigration()) {
                status = getString(R.string.account_update_needed);
            } else if (account.isInError()) {
                status = getString(R.string.account_status_connection_error);
            } else if (account.isRegistered()) {
                status = getString(R.string.account_status_online);
            } else {
                status = getString(R.string.account_status_unknown);
            }
        } else {
            status = getString(R.string.account_status_offline);
        }
        pref.setSummary(status);
        pref.setChecked(account.isEnabled());
        // An ip2ip account is always ready
        pref.setEnabled(!account.isIP2IP());
        pref.setOnPreferenceChangeListener(changeAccountStatusListener);
    }
    setPreferenceListener(account.getConfig(), changeBasicPreferenceListener);
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat)

Example 8 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project vlc-android by GeoffreyMetais.

the class PreferencesExtensionFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    String key = preference.getKey();
    if (key == null || !key.startsWith(mExtensionKey))
        return false;
    if (key.equals(mExtensionKey)) {
        SwitchPreferenceCompat switchPreference = (SwitchPreferenceCompat) preference;
        mSettings.edit().putBoolean(key, switchPreference.isChecked()).apply();
        if (switchPreference.isChecked()) {
            for (Preference checkbox : preferences) checkbox.setEnabled(true);
        } else {
            for (Preference checkbox : preferences) {
                ((CheckBoxPreference) checkbox).setChecked(false);
                mSettings.edit().putBoolean(checkbox.getKey(), false).apply();
                checkbox.setEnabled(false);
            }
        }
    } else if (key.endsWith("_" + ExtensionsManager.ANDROID_AUTO_SUFFIX)) {
        mSettings.edit().putBoolean(preference.getKey(), ((TwoStatePreference) preference).isChecked()).apply();
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Example 9 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat 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 10 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project frostwire by frostwire.

the class ApplicationFragment method updateConnectSwitchStatus.

private void updateConnectSwitchStatus() {
    SwitchPreferenceCompat preference = findPreference("frostwire.prefs.internal.connect_disconnect");
    Engine e = Engine.instance();
    if (e.isStarted()) {
        setChecked(preference, true, false);
    } else if (e.isStopped() || e.isDisconnected()) {
        setChecked(preference, false, false);
    }
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) Engine(com.frostwire.android.gui.services.Engine)

Aggregations

SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)15 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)5 Preference (android.support.v7.preference.Preference)5 ListPreference (android.support.v7.preference.ListPreference)4 Button (android.widget.Button)4 AlertDialog (android.support.v7.app.AlertDialog)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 EditTextPreference (android.support.v7.preference.EditTextPreference)2 TwoStatePreference (android.support.v7.preference.TwoStatePreference)2 EditText (android.widget.EditText)2 ProgressBar (android.widget.ProgressBar)2 Engine (com.frostwire.android.gui.services.Engine)2 File (java.io.File)2 IOException (java.io.IOException)2 AlertDialog (android.app.AlertDialog)1 ClipboardManager (android.content.ClipboardManager)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1