Search in sources :

Example 1 with ManagedPreferenceDelegate

use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.

the class DataReductionPreferences method createDataReductionSwitch.

private void createDataReductionSwitch(boolean isEnabled) {
    final ChromeSwitchPreference dataReductionSwitch = new ChromeSwitchPreference(getActivity(), null);
    dataReductionSwitch.setKey(PREF_DATA_REDUCTION_SWITCH);
    dataReductionSwitch.setSummaryOn(R.string.text_on);
    dataReductionSwitch.setSummaryOff(R.string.text_off);
    dataReductionSwitch.setDrawDivider(true);
    dataReductionSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(dataReductionSwitch.getContext(), (boolean) newValue);
            DataReductionPreferences.this.updatePreferences((boolean) newValue);
            return true;
        }
    });
    dataReductionSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return CommandLine.getInstance().hasSwitch(ENABLE_DATA_REDUCTION_PROXY) || DataReductionProxySettings.getInstance().isDataReductionProxyManaged();
        }
    });
    getPreferenceScreen().addPreference(dataReductionSwitch);
    // Note: setting the switch state before the preference is added to the screen results in
    // some odd behavior where the switch state doesn't always match the internal enabled state
    // (e.g. the switch will say "On" when data reduction is really turned off), so
    // .setChecked() should be called after .addPreference()
    dataReductionSwitch.setChecked(isEnabled);
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 2 with ManagedPreferenceDelegate

use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.

the class AccountManagementFragment method configureAddAccountPreference.

private void configureAddAccountPreference() {
    ChromeBasePreference addAccount = (ChromeBasePreference) findPreference(PREF_ADD_ACCOUNT);
    if (ChildAccountService.isChildAccount()) {
        getPreferenceScreen().removePreference(addAccount);
    } else {
        addAccount.setTitle(getResources().getString(R.string.account_management_add_account_title));
        addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!isVisible() || !isResumed())
                    return false;
                AccountManagementScreenHelper.logEvent(ProfileAccountManagementMetrics.ADD_ACCOUNT, mGaiaServiceType);
                AccountAdder.getInstance().addAccount(getActivity(), AccountAdder.ADD_ACCOUNT_RESULT);
                // Return to the last opened tab if triggered from the content area.
                if (mGaiaServiceType != AccountManagementScreenHelper.GAIA_SERVICE_TYPE_NONE) {
                    if (isAdded())
                        getActivity().finish();
                }
                return true;
            }
        });
        addAccount.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

            @Override
            public boolean isPreferenceControlledByPolicy(Preference preference) {
                return !canAddAccounts();
            }
        });
    }
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) SyncPreference(org.chromium.chrome.browser.preferences.SyncPreference) Preference(android.preference.Preference)

Example 3 with ManagedPreferenceDelegate

use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.

the class SavePasswordsPreferences method createAutoSignInCheckbox.

private void createAutoSignInCheckbox() {
    if (!ChromeFeatureList.isEnabled(CREDENTIAL_MANAGER_API)) {
        return;
    }
    mAutoSignInSwitch = new ChromeBaseCheckBoxPreference(getActivity(), null);
    mAutoSignInSwitch.setKey(PREF_AUTOSIGNIN_SWITCH);
    mAutoSignInSwitch.setTitle(R.string.passwords_auto_signin_title);
    mAutoSignInSwitch.setOrder(ORDER_AUTO_SIGNIN_CHECKBOX);
    mAutoSignInSwitch.setSummary(R.string.passwords_auto_signin_description);
    mAutoSignInSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setPasswordManagerAutoSigninEnabled((boolean) newValue);
            return true;
        }
    });
    mAutoSignInSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isPasswordManagerAutoSigninManaged();
        }
    });
    getPreferenceScreen().addPreference(mAutoSignInSwitch);
    mAutoSignInSwitch.setChecked(PrefServiceBridge.getInstance().isPasswordManagerAutoSigninEnabled());
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 4 with ManagedPreferenceDelegate

use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.

the class PrivacyPreferences method createManagedPreferenceDelegate.

private ManagedPreferenceDelegate createManagedPreferenceDelegate() {
    return new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            String key = preference.getKey();
            PrefServiceBridge prefs = PrefServiceBridge.getInstance();
            if (PREF_NAVIGATION_ERROR.equals(key)) {
                return prefs.isResolveNavigationErrorManaged();
            }
            if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
                return prefs.isSearchSuggestManaged();
            }
            if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key) || PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) {
                return prefs.isSafeBrowsingExtendedReportingManaged();
            }
            if (PREF_SAFE_BROWSING.equals(key)) {
                return prefs.isSafeBrowsingManaged();
            }
            if (PREF_NETWORK_PREDICTIONS.equals(key)) {
                return prefs.isNetworkPredictionManaged();
            }
            return false;
        }
    };
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) PrefServiceBridge(org.chromium.chrome.browser.preferences.PrefServiceBridge) CheckBoxPreference(android.preference.CheckBoxPreference) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) Preference(android.preference.Preference)

Example 5 with ManagedPreferenceDelegate

use of org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate in project AndroidChromium by JackyAndroid.

the class SingleCategoryPreferences method updateThirdPartyCookiesCheckBox.

private void updateThirdPartyCookiesCheckBox() {
    ChromeBaseCheckBoxPreference thirdPartyCookiesPref = (ChromeBaseCheckBoxPreference) getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);
    thirdPartyCookiesPref.setEnabled(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
    thirdPartyCookiesPref.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isBlockThirdPartyCookiesManaged();
        }
    });
}
Also used : ManagedPreferenceDelegate(org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) ChromeBaseCheckBoxPreference(org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference) Preference(android.preference.Preference)

Aggregations

Preference (android.preference.Preference)9 ManagedPreferenceDelegate (org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate)9 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)6 ChromeBaseCheckBoxPreference (org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference)4 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)4 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)2 Context (android.content.Context)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)1 PrefServiceBridge (org.chromium.chrome.browser.preferences.PrefServiceBridge)1 SyncPreference (org.chromium.chrome.browser.preferences.SyncPreference)1