Search in sources :

Example 11 with ChromeSwitchPreference

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

the class ContextualSearchPreferenceFragment method initContextualSearchSwitch.

private void initContextualSearchSwitch() {
    ChromeSwitchPreference contextualSearchSwitch = (ChromeSwitchPreference) findPreference(PREF_CONTEXTUAL_SEARCH_SWITCH);
    boolean isContextualSearchEnabled = !PrefServiceBridge.getInstance().isContextualSearchDisabled();
    contextualSearchSwitch.setChecked(isContextualSearchEnabled);
    contextualSearchSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setContextualSearchState((boolean) newValue);
            ContextualSearchUma.logPreferenceChange((boolean) newValue);
            return true;
        }
    });
    contextualSearchSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {

        @Override
        public boolean isPreferenceControlledByPolicy(Preference preference) {
            return PrefServiceBridge.getInstance().isContextualSearchDisabledByPolicy();
        }
    });
}
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 12 with ChromeSwitchPreference

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

the class SingleCategoryPreferences method configureGlobalToggles.

private void configureGlobalToggles() {
    // Only some have a global toggle at the top.
    ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
    // Configure/hide the third-party cookie toggle, as needed.
    Preference thirdPartyCookies = getPreferenceScreen().findPreference(THIRD_PARTY_COOKIES_TOGGLE_KEY);
    if (mCategory.showCookiesSites()) {
        thirdPartyCookies.setOnPreferenceChangeListener(this);
        updateThirdPartyCookiesCheckBox();
    } else {
        getPreferenceScreen().removePreference(thirdPartyCookies);
    }
    // Configure/hide the notifications vibrate toggle, as needed.
    Preference notificationsVibrate = getPreferenceScreen().findPreference(NOTIFICATIONS_VIBRATE_TOGGLE_KEY);
    if (mCategory.showNotificationsSites()) {
        notificationsVibrate.setOnPreferenceChangeListener(this);
        updateNotificationsVibrateCheckBox();
    } else {
        getPreferenceScreen().removePreference(notificationsVibrate);
    }
    // Show/hide the link that explains protected media settings, as needed.
    if (!mCategory.showProtectedMediaSites()) {
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(EXPLAIN_PROTECTED_MEDIA_KEY));
    }
    if (mCategory.showAllSites() || mCategory.showStorageSites()) {
        getPreferenceScreen().removePreference(globalToggle);
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(ALLOWED_GROUP));
        getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(BLOCKED_GROUP));
    } else {
        // When this menu opens, make sure the Blocked list is collapsed.
        if (!mGroupByAllowBlock) {
            mBlockListExpanded = false;
            mAllowListExpanded = true;
        }
        mGroupByAllowBlock = true;
        PreferenceGroup allowedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(ALLOWED_GROUP);
        PreferenceGroup blockedGroup = (PreferenceGroup) getPreferenceScreen().findPreference(BLOCKED_GROUP);
        if (mCategory.showPermissionBlockedMessage(getActivity())) {
            getPreferenceScreen().removePreference(globalToggle);
            getPreferenceScreen().removePreference(allowedGroup);
            getPreferenceScreen().removePreference(blockedGroup);
            // Show the link to system settings since permission is disabled.
            ChromeBasePreference osWarning = new ChromeBasePreference(getActivity(), null);
            ChromeBasePreference osWarningExtra = new ChromeBasePreference(getActivity(), null);
            mCategory.configurePermissionIsOffPreferences(osWarning, osWarningExtra, getActivity(), true);
            if (osWarning.getTitle() != null) {
                getPreferenceScreen().addPreference(osWarning);
            }
            if (osWarningExtra.getTitle() != null) {
                getPreferenceScreen().addPreference(osWarningExtra);
            }
        } else {
            allowedGroup.setOnPreferenceClickListener(this);
            blockedGroup.setOnPreferenceClickListener(this);
            // Determine what toggle to use and what it should display.
            int contentType = mCategory.toContentSettingsType();
            globalToggle.setOnPreferenceChangeListener(this);
            globalToggle.setTitle(ContentSettingsResources.getTitle(contentType));
            if (mCategory.showGeolocationSites() && PrefServiceBridge.getInstance().isLocationAllowedByPolicy()) {
                globalToggle.setSummaryOn(ContentSettingsResources.getGeolocationAllowedSummary());
            } else {
                globalToggle.setSummaryOn(ContentSettingsResources.getEnabledSummary(contentType));
            }
            globalToggle.setSummaryOff(ContentSettingsResources.getDisabledSummary(contentType));
            if (mCategory.isManaged() && !mCategory.isManagedByCustodian()) {
                globalToggle.setIcon(R.drawable.controlled_setting_mandatory);
            }
            if (mCategory.showAutoplaySites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isAutoplayEnabled());
            } else if (mCategory.showBackgroundSyncSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isBackgroundSyncAllowed());
            } else if (mCategory.showCameraSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isCameraEnabled());
            } else if (mCategory.showCookiesSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isAcceptCookiesEnabled());
            } else if (mCategory.showFullscreenSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isFullscreenAllowed());
                // The fullscreen global toggle cannot be disabled.
                // TODO(mgiuca): Remove this setting entirely (requires deleting all the data;
                // see https://crbug.com/591896).
                globalToggle.setEnabled(false);
            } else if (mCategory.showGeolocationSites()) {
                globalToggle.setChecked(LocationSettings.getInstance().isChromeLocationSettingEnabled());
            } else if (mCategory.showJavaScriptSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().javaScriptEnabled());
            } else if (mCategory.showMicrophoneSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isMicEnabled());
            } else if (mCategory.showNotificationsSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isNotificationsEnabled());
            } else if (mCategory.showPopupSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().popupsEnabled());
            } else if (mCategory.showProtectedMediaSites()) {
                globalToggle.setChecked(PrefServiceBridge.getInstance().isProtectedMediaIdentifierEnabled());
            }
        }
    }
}
Also used : ChromeBasePreference(org.chromium.chrome.browser.preferences.ChromeBasePreference) 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) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) ExpandablePreferenceGroup(org.chromium.chrome.browser.preferences.ExpandablePreferenceGroup) PreferenceGroup(android.preference.PreferenceGroup)

Aggregations

ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)12 Preference (android.preference.Preference)11 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)9 ManagedPreferenceDelegate (org.chromium.chrome.browser.preferences.ManagedPreferenceDelegate)5 ChromeBaseCheckBoxPreference (org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference)3 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)3 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)2 Context (android.content.Context)1 Handler (android.os.Handler)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 PreferenceGroup (android.preference.PreferenceGroup)1 SwitchPreference (android.preference.SwitchPreference)1 View (android.view.View)1 ExpandablePreferenceGroup (org.chromium.chrome.browser.preferences.ExpandablePreferenceGroup)1 SyncedAccountPreference (org.chromium.chrome.browser.preferences.SyncedAccountPreference)1 SyncAccountSwitcher (org.chromium.chrome.browser.sync.SyncAccountSwitcher)1