Java Code Examples for androidx.preference.PreferenceScreen#removePreference()

The following examples show how to use androidx.preference.PreferenceScreen#removePreference() . 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: DeveloperPreferences.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void hideOrShowDangerousSettings() {
    Preference[] onScreenPrefs = getOnScreenPrefs();
    if (!GlobalPrivilegesManager.isAdvancedSettingsAccessEnabled() && !BuildConfig.DEBUG) {
        // Dangerous privileges should not be showing
        PreferenceScreen prefScreen = getPreferenceScreen();
        for (Preference p : onScreenPrefs) {
            if (p != null && !WHITELISTED_DEVELOPER_PREF_KEYS.contains(p.getKey())) {
                prefScreen.removePreference(p);
            }
        }
    } else {
        // Dangerous privileges should be showing
        if (onScreenPrefs.length == WHITELISTED_DEVELOPER_PREF_KEYS.size()) {
            // If we're currently showing only white-listed prefs, reset
            reset();
        }
    }
}
 
Example 2
Source File: PreferencesDNSFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void removePreferencesWithGPVersion() {
    PreferenceScreen dnscryptSettings = findPreference("dnscrypt_settings");

    ArrayList<PreferenceCategory> categories = new ArrayList<>();
    categories.add(findPreference("pref_dnscrypt_forwarding_rules"));
    categories.add(findPreference("pref_dnscrypt_cloaking_rules"));
    categories.add(findPreference("pref_dnscrypt_blacklist"));
    categories.add(findPreference("pref_dnscrypt_ipblacklist"));
    categories.add(findPreference("pref_dnscrypt_whitelist"));
    categories.add(findPreference("pref_dnscrypt_other"));

    for (PreferenceCategory category : categories) {
        if (dnscryptSettings != null && category != null) {
            dnscryptSettings.removePreference(category);
        }
    }

    PreferenceCategory requireServersCategory = findPreference("dnscrypt_require_servers_prop_summ");
    Preference requireNofilter = findPreference("require_nofilter");

    if (requireServersCategory != null && requireNofilter != null) {
        requireServersCategory.removePreference(requireNofilter);
    }

    PreferenceCategory queryLogCategory = findPreference("pref_dnscrypt_query_log");
    Preference ignoredQtypes = findPreference("ignored_qtypes");

    if (queryLogCategory != null && ignoredQtypes != null) {
        queryLogCategory.removePreference(ignoredQtypes);
    }
}
 
Example 3
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void changePreferencesForGPVersion() {
    PreferenceScreen preferencesFast = findPreference("fast_preferences");
    PreferenceCategory fastUpdateCategory = findPreference("fast_update");
    if (preferencesFast != null && fastUpdateCategory != null) {
        preferencesFast.removePreference(fastUpdateCategory);
    }

    PreferenceCategory fastOtherCategory = findPreference("fast_other");

    Preference blockHttp = findPreference("pref_fast_block_http");
    if (fastOtherCategory != null && blockHttp != null) {
        fastOtherCategory.removePreference(blockHttp);
    }
}
 
Example 4
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void changePreferencesForFDVersion() {
    PreferenceScreen preferencesFast = findPreference("fast_preferences");
    PreferenceCategory fastUpdateCategory = findPreference("fast_update");
    if (preferencesFast != null && fastUpdateCategory != null) {
        preferencesFast.removePreference(fastUpdateCategory);
    }
}
 
Example 5
Source File: GalleryPrefsFragment.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
private void setupPrefs() {
    saveLocation = findPreference(getString(R.string.image_file_location_pref));
    if (MimiUtil.isSamsung()) {
        PreferenceScreen galleryScreen = (PreferenceScreen) findPreference(getString(R.string.gallery_prefs_screen));
        galleryScreen.removePreference(saveLocation);
        return;
    }

    DocumentFile saveDir = MimiUtil.getSaveDir();
    if (saveDir != null) {
        saveLocation.setSummary(saveDir.getName());
    }
    saveLocation.setOnPreferenceClickListener(preference -> {

        final int res;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            res = getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        } else {
            res = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
        }
        if (res == PackageManager.PERMISSION_GRANTED) {
            showDirChooser();
        } else {
            String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                requestPermissions(perms, PERMISSIONS_CODE);
            } else {
                ActivityCompat.requestPermissions(getActivity(), perms, PERMISSIONS_CODE);
            }
        }

        return true;
    });
}
 
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: DynamicSettingsActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
@Override
public final void onRemovePreferenceHeader(final int position) {
    PreferenceScreen preferenceScreen = getNavigationFragment().getPreferenceScreen();
    Preference preference = preferenceScreen.getPreference(position);
    preferenceScreen.removePreference(preference);
    invalidateOptionsMenu();
}
 
Example 8
Source File: MainConfigurablePreferences.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void setVisibilityOfUpdateOptionsPref() {
    Preference updateOptionsPref = getPreferenceManager().findPreference(UPDATE_TARGET);
    if (!DeveloperPreferences.shouldShowUpdateOptionsSetting() && updateOptionsPref != null) {
        // If the pref is showing and it shouldn't be
        PreferenceScreen prefScreen = getPreferenceScreen();
        prefScreen.removePreference(updateOptionsPref);
    } else if (DeveloperPreferences.shouldShowUpdateOptionsSetting() &&
            updateOptionsPref == null) {
        // If the pref isn't showing and it should be
        reset();
    }
}