Search in sources :

Example 16 with SwitchPreferenceCompat

use of android.support.v7.preference.SwitchPreferenceCompat in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method init.

private void init() {
    addPreferencesFromResource(R.xml.settings);
    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }
    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }
    /*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
    findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
    findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
    findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);
    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(findPreference(KEY_LAST_KMSG));
    }
    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
    }
    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;
        if (fragment != null && fragment.getClass() != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled");
            switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(false);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) PreferenceCategory(android.support.v7.preference.PreferenceCategory) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Fragment(android.support.v4.app.Fragment)

Example 17 with SwitchPreferenceCompat

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

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

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

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