androidx.preference.SwitchPreferenceCompat Java Examples

The following examples show how to use androidx.preference.SwitchPreferenceCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventPreferencesPeripherals.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
private void setSummary(PreferenceManager prefMng, String key, String value/*, Context context*/)
{
    SharedPreferences preferences = prefMng.getSharedPreferences();

    if (key.equals(PREF_EVENT_PERIPHERAL_ENABLED)) {
        SwitchPreferenceCompat preference = prefMng.findPreference(key);
        if (preference != null) {
            GlobalGUIRoutines.setPreferenceTitleStyleX(preference, true, preferences.getBoolean(key, false), false, false, false);
        }
    }

    if (key.equals(PREF_EVENT_PERIPHERAL_TYPE))
    {
        ListPreference listPreference = prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(value);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
        }
    }
}
 
Example #2
Source File: SettingsActivity.java    From GotoBrowser with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    findPreference(PREF_APP_VERSION).setSummary(BuildConfig.VERSION_NAME);
    Map<String, ?> allEntries = sharedPref.getAll();
    for (String key : allEntries.keySet()) {
        Log.e("GOTO", key);
        Preference preference = findPreference(key);
        if (preference == null) continue;
        if (preference instanceof ListPreference) {
            Log.e("GOTO", key + ": " + sharedPref.getString(key, ""));
        } else if (preference instanceof SwitchPreferenceCompat) {
            Log.e("GOTO", key + ": " + sharedPref.getBoolean(key, false));
            SwitchPreferenceCompat sp = (SwitchPreferenceCompat) preference;
            sp.setChecked(sharedPref.getBoolean(key, false));
        }
        preference.setOnPreferenceChangeListener(this);
    }

    String subtitleLocale = sharedPref.getString(PREF_SUBTITLE_LOCALE, "");
    if (subtitleLocale.length() > 0) {
        setSubtitlePreference(subtitleLocale);
    } else {
        findPreference(PREF_SUBTITLE_UPDATE).setEnabled(false);
        findPreference(PREF_SUBTITLE_UPDATE).setSummary(getString(R.string.subtitle_select_language));
    }
}
 
Example #3
Source File: SettingsActivity.java    From GotoBrowser with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    String key = preference.getKey();
    if (preference instanceof ListPreference) {
        String stringValue = (String) newValue;
        sharedPref.edit().putString(key, stringValue).apply();
        if (key.equals(PREF_SUBTITLE_LOCALE)) {
            setSubtitlePreference(stringValue);
        }
    }
    if (preference instanceof SwitchPreferenceCompat) {
        sharedPref.edit().putBoolean(key, (boolean) newValue).apply();
    }
    return true;
}
 
Example #4
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  context = getContext();
  toolbar = view.findViewById(R.id.toolbar);

  final AppCompatActivity parentActivity = (AppCompatActivity) getActivity();
  if (toolbar != null) {
    parentActivity.setSupportActionBar(toolbar);

    toolbar.setTitle(R.string.settings_title_settings);
    toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());

    ActionBar supportActionBar = parentActivity.getSupportActionBar();
    if (supportActionBar != null) {
      supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
  }
  setAdultContentViews();
  excludedUpdates = findPreference(EXCLUDED_UPDATES_PREFERENCE_KEY);
  sendFeedback = findPreference(SEND_FEEDBACK_PREFERENCE_KEY);
  setGDPR();
  setupAppTheme();
  deleteAccount = findPreference(DELETE_ACCOUNT);
  socialCampaignNotifications =
      (SwitchPreferenceCompat) findPreference(CAMPAIGN_SOCIAL_NOTIFICATIONS_PREFERENCE_VIEW_KEY);
  fileMaxCachePreferenceView = findPreference(MAX_FILE_CACHE);
  setupClickHandlers();
}
 
Example #5
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setAdultContentViews() {
  if (settingsManager.showAdultContent()) {
    adultContentPreferenceView =
        (SwitchPreferenceCompat) findPreference(ADULT_CONTENT_PREFERENCE_VIEW_KEY);
    adultContentWithPinPreferenceView =
        (SwitchPreferenceCompat) findPreference(ADULT_CONTENT_WITH_PIN_PREFERENCE_VIEW_KEY);
    pinPreferenceView = findPreference(ADULT_CONTENT_PIN_PREFERENCE_VIEW_KEY);
    removePinPreferenceView = findPreference(REMOVE_ADULT_CONTENT_PIN_PREFERENCE_VIEW_KEY);
  } else {
    PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("adultContent");
    if (preferenceCategory != null) {
      getPreferenceScreen().removePreference(preferenceCategory);
    }
  }
}
 
Example #6
Source File: GeneralPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupUsageStatisticsAvailability() {
    boolean available = BuildConfig.ANALYTICS_AVAILABLE;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_general_category_settings_key));
        SwitchPreferenceCompat trackingPreference = findPreference(getString(R.string.preferences_tracking_enabled_key));
        settingsCategoryPreference.removePreference(trackingPreference);

        // We have only one help preference so the whole category is to be removed
        PreferenceScreen generalScreenPreference = getPreferenceScreen();
        PreferenceCategory helpCategoryPreference = findPreference(getString(R.string.preferences_general_category_help_key));
        generalScreenPreference.removePreference(helpCategoryPreference);
    } else {
        setupUsageStatisticsDialog();
    }
}
 
Example #7
Source File: CollectorPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupHideCollectorNotificationAvailability() {
    boolean available = Build.VERSION.SDK_INT < Build.VERSION_CODES.O;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_general_category_settings_key));
        SwitchPreferenceCompat hideCollectorNotificationPreference = findPreference(getString(R.string.preferences_hide_collector_notification_key));
        settingsCategoryPreference.removePreference(hideCollectorNotificationPreference);
    }
}
 
Example #8
Source File: AdvancedPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupErrorReportingAvailability() {
    boolean available = BuildConfig.ACRA_SETTINGS_AVAILABLE;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_advanced_category_settings_key));
        SwitchPreferenceCompat errorReportingSilentPreference = findPreference(getString(R.string.preferences_error_reporting_silent_key));
        settingsCategoryPreference.removePreference(errorReportingSilentPreference);
    }
}
 
Example #9
Source File: EventPreferencesScreen.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void setWhenUnlockedTitle(PreferenceManager prefMng, int value)
{
    final SwitchPreferenceCompat whenUnlockedPreference = prefMng.findPreference(PREF_EVENT_SCREEN_WHEN_UNLOCKED);

    if (whenUnlockedPreference != null) {
        if (value == 0)
            whenUnlockedPreference.setTitle(R.string.event_preferences_screen_start_when_unlocked);
        else
            whenUnlockedPreference.setTitle(R.string.event_preferences_screen_start_when_locked);
    }
}
 
Example #10
Source File: MainSettingsActivity.java    From an2linuxclient with GNU General Public License v3.0 4 votes vote down vote up
private void updateAn2linuxEnabled(SharedPreferences sp) {
    String prefEnableAn2linuxKey = getString(R.string.preference_enable_an2linux);
    boolean currentSetting = sp.getBoolean(prefEnableAn2linuxKey, false);
    ((SwitchPreferenceCompat) findPreference(prefEnableAn2linuxKey)).setChecked(currentSetting);
}
 
Example #11
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {
        addPreferencesFromResource(R.xml.settings);

        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_PRIMARY_COLOR).setOnPreferenceClickListener(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(!AppSettings.getPassword(getActivity()).isEmpty());
        }

        NavigationActivity activity = (NavigationActivity) getActivity();
        PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
        for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
            Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
            int id = navigationFragment.mId;

            if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
                SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                        new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
                switchPreference.setSummary(getString(id));
                switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
                switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity()));
                switchPreference.setOnPreferenceChangeListener(this);
                switchPreference.setPersistent(true);
                sectionsCategory.addPreference(switchPreference);
            }
        }
    }
 
Example #12
Source File: MainSettingsActivity.java    From an2linuxclient with GNU General Public License v3.0 4 votes vote down vote up
private void updateAn2linuxEnabled(SharedPreferences sp) {
    String prefEnableAn2linuxKey = getString(R.string.preference_enable_an2linux);
    boolean currentSetting = sp.getBoolean(prefEnableAn2linuxKey, false);
    ((SwitchPreferenceCompat) findPreference(prefEnableAn2linuxKey)).setChecked(currentSetting);
}
 
Example #13
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
private void rollbackCheck(SwitchPreferenceCompat preference) {
  preference.setChecked(!preference.isChecked());
}
 
Example #14
Source File: EventPreferencesOrientation.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
void checkPreferences(PreferenceManager prefMng, Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    boolean hasAccelerometer = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null);
    boolean hasMagneticField = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null);
    boolean hasProximity = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null);
    boolean hasLight = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT) != null);
    boolean enabledAll = (hasAccelerometer) && (hasMagneticField);
    Preference preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISPLAY);
    if (preference != null) {
        if (!hasAccelerometer)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(hasAccelerometer);
    }
    preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_SIDES);
    if (preference != null) {
        if (!enabledAll)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(enabledAll);
    }
    boolean enabled = hasProximity;
    preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISTANCE);
    if (preference != null) {
        if (!enabled)
            preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+
                    ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware));
        preference.setEnabled(enabled);
    }
    SwitchPreferenceCompat switchPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_CHECK_LIGHT);
    if (switchPreference != null) {
        boolean checkLight = switchPreference.isChecked();
        if (checkLight) {
            enabled = hasLight;
            preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MIN);
            if (preference != null) {
                if (!enabled)
                    preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) +
                            ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware));
                preference.setEnabled(enabled);
            }
            preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MAX);
            if (preference != null) {
                if (!enabled)
                    preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) +
                            ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware));
                preference.setEnabled(enabled);
            }
        }
    }
    enabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0);
    ApplicationsMultiSelectDialogPreferenceX applicationsPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_IGNORED_APPLICATIONS);
    if (applicationsPreference != null) {
        applicationsPreference.setEnabled(enabled);
        applicationsPreference.setSummaryAMSDP();
    }
    SharedPreferences preferences = prefMng.getSharedPreferences();
    setSummary(prefMng, PREF_EVENT_ORIENTATION_APP_SETTINGS, preferences, context);
    setCategorySummary(prefMng, preferences, context);
}