Search in sources :

Example 1 with SwitchPreferenceCompat

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

the class ApplicationFragment method setupConnectSwitch.

private void setupConnectSwitch() {
    SwitchPreferenceCompat preference = findPreference("frostwire.prefs.internal.connect_disconnect");
    preference.setOnPreferenceChangeListener((preference1, newValue) -> {
        boolean newStatus = (boolean) newValue;
        Engine e = Engine.instance();
        if (e.isStarted() && !newStatus) {
            disconnect();
            UIUtils.showShortMessage(getView(), R.string.toast_on_disconnect);
        } else if (newStatus && (e.isStopped() || e.isDisconnected())) {
            NetworkManager networkManager = NetworkManager.instance();
            if (getPreferenceManager().getSharedPreferences().getBoolean(Constants.PREF_KEY_NETWORK_BITTORRENT_ON_VPN_ONLY, false) && !networkManager.isTunnelUp()) {
                UIUtils.showShortMessage(getView(), R.string.cannot_start_engine_without_vpn);
                return false;
            } else if (getPreferenceManager().getSharedPreferences().getBoolean(Constants.PREF_KEY_NETWORK_USE_WIFI_ONLY, false) && networkManager.isDataMobileUp()) {
                UIUtils.showShortMessage(getView(), R.string.wifi_network_unavailable);
                return false;
            } else {
                connect();
            }
        }
        return true;
    });
    updateConnectSwitchStatus();
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) NetworkManager(com.frostwire.android.gui.NetworkManager) Engine(com.frostwire.android.gui.services.Engine)

Example 2 with SwitchPreferenceCompat

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

the class TorrentPreferenceFragment method setupTorrentOptions.

private void setupTorrentOptions() {
    SwitchPreferenceCompat pref = findPreference(Constants.PREF_KEY_NETWORK_ENABLE_DHT);
    pref.setOnPreferenceChangeListener((preference, newValue) -> {
        boolean newStatus = (boolean) newValue;
        if (newStatus) {
            BTEngine.getInstance().startDht();
        } else {
            BTEngine.getInstance().stopDht();
        }
        return true;
    });
    final BTEngine e = BTEngine.getInstance();
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_DOWNLOAD_SPEED, e);
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_UPLOAD_SPEED, e);
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_DOWNLOADS, e);
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_UPLOADS, e);
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_TOTAL_CONNECTIONS, e);
    setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_PEERS, e);
}
Also used : BTEngine(com.frostwire.bittorrent.BTEngine) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat)

Example 3 with SwitchPreferenceCompat

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

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 4 with SwitchPreferenceCompat

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

the class PreferencesExtensionFragment method createCheckboxes.

private void createCheckboxes() {
    preferenceScreen = this.getPreferenceScreen();
    // Main switch
    SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(preferenceScreen.getContext());
    switchPreference.setTitle(preferenceScreen.getContext().getString(R.string.extension_prefs_activation_title).toUpperCase());
    switchPreference.setKey(mExtensionKey);
    switchPreference.setChecked(mSettings.getBoolean(mExtensionKey, false));
    switchPreference.setOnPreferenceChangeListener(null);
    preferenceScreen.addPreference(switchPreference);
    // Android-auto
    if (androidAutoAvailable) {
        CheckBoxPreference checkbox = new CheckBoxPreference(preferenceScreen.getContext());
        checkbox.setTitle(R.string.android_auto);
        String key = mExtensionKey + "_" + ExtensionsManager.ANDROID_AUTO_SUFFIX;
        checkbox.setKey(key);
        checkbox.setChecked(switchPreference.isChecked() && mSettings.getBoolean(key, false));
        checkbox.setEnabled(switchPreference.isChecked());
        preferences.add(checkbox);
        preferenceScreen.addPreference(checkbox);
    }
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Example 5 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project Signal-Android by signalapp.

the class RegistrationLockDialog method showRegistrationLockPrompt.

@SuppressLint("StaticFieldLeak")
public static void showRegistrationLockPrompt(@NonNull Context context, @NonNull SwitchPreferenceCompat preference, @NonNull SignalServiceAccountManager accountManager) {
    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(R.string.RegistrationLockDialog_registration_lock).setView(R.layout.registration_lock_dialog_view).setPositiveButton(R.string.RegistrationLockDialog_enable, null).setNegativeButton(android.R.string.cancel, null).create();
    dialog.setOnShowListener(created -> {
        Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(v -> {
            EditText pin = dialog.findViewById(R.id.pin);
            EditText repeat = dialog.findViewById(R.id.repeat);
            ProgressBar progressBar = dialog.findViewById(R.id.progress);
            assert pin != null;
            assert repeat != null;
            assert progressBar != null;
            String pinValue = pin.getText().toString().replace(" ", "");
            String repeatValue = repeat.getText().toString().replace(" ", "");
            if (pinValue.length() < 4) {
                Toast.makeText(context, R.string.RegistrationLockDialog_the_registration_lock_pin_must_be_at_least_four_digits, Toast.LENGTH_LONG).show();
                return;
            }
            if (!pinValue.equals(repeatValue)) {
                Toast.makeText(context, R.string.RegistrationLockDialog_the_two_pins_you_entered_do_not_match, Toast.LENGTH_LONG).show();
                return;
            }
            new AsyncTask<Void, Void, Boolean>() {

                @Override
                protected void onPreExecute() {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setIndeterminate(true);
                    button.setEnabled(false);
                }

                @Override
                protected Boolean doInBackground(Void... voids) {
                    try {
                        accountManager.setPin(Optional.of(pinValue));
                        TextSecurePreferences.setRegistrationLockPin(context, pinValue);
                        TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
                        TextSecurePreferences.setRegistrationLockNextReminderInterval(context, RegistrationLockReminders.INITIAL_INTERVAL);
                        return true;
                    } catch (IOException e) {
                        Log.w(TAG, e);
                        return false;
                    }
                }

                @Override
                protected void onPostExecute(@NonNull Boolean result) {
                    button.setEnabled(true);
                    progressBar.setVisibility(View.GONE);
                    if (result) {
                        preference.setChecked(true);
                        created.dismiss();
                    } else {
                        Toast.makeText(context, R.string.RegistrationLockDialog_error_connecting_to_the_service, Toast.LENGTH_LONG).show();
                    }
                }
            }.execute();
        });
    });
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) Button(android.widget.Button) SpannableString(android.text.SpannableString) IOException(java.io.IOException) ProgressBar(android.widget.ProgressBar) SuppressLint(android.annotation.SuppressLint)

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