Search in sources :

Example 1 with ChromeSwitchPreference

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

the class SingleCategoryPreferences method onPreferenceChange.

// OnPreferenceChangeListener:
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (READ_WRITE_TOGGLE_KEY.equals(preference.getKey())) {
        if (mCategory.isManaged())
            return false;
        if (mCategory.showAutoplaySites()) {
            PrefServiceBridge.getInstance().setAutoplayEnabled((boolean) newValue);
        } else if (mCategory.showBackgroundSyncSites()) {
            PrefServiceBridge.getInstance().setBackgroundSyncEnabled((boolean) newValue);
        } else if (mCategory.showCameraSites()) {
            PrefServiceBridge.getInstance().setCameraEnabled((boolean) newValue);
        } else if (mCategory.showCookiesSites()) {
            PrefServiceBridge.getInstance().setAllowCookiesEnabled((boolean) newValue);
            updateThirdPartyCookiesCheckBox();
        } else if (mCategory.showFullscreenSites()) {
            PrefServiceBridge.getInstance().setFullscreenAllowed((boolean) newValue);
        } else if (mCategory.showGeolocationSites()) {
            PrefServiceBridge.getInstance().setAllowLocationEnabled((boolean) newValue);
        } else if (mCategory.showJavaScriptSites()) {
            PrefServiceBridge.getInstance().setJavaScriptEnabled((boolean) newValue);
        } else if (mCategory.showMicrophoneSites()) {
            PrefServiceBridge.getInstance().setMicEnabled((boolean) newValue);
        } else if (mCategory.showNotificationsSites()) {
            PrefServiceBridge.getInstance().setNotificationsEnabled((boolean) newValue);
            updateNotificationsVibrateCheckBox();
        } else if (mCategory.showPopupSites()) {
            PrefServiceBridge.getInstance().setAllowPopupsEnabled((boolean) newValue);
        } else if (mCategory.showProtectedMediaSites()) {
            PrefServiceBridge.getInstance().setProtectedMediaIdentifierEnabled((boolean) newValue);
        }
        // Categories that support adding exceptions also manage the 'Add site' preference.
        if (mCategory.showAutoplaySites() || mCategory.showBackgroundSyncSites() || mCategory.showJavaScriptSites()) {
            if ((boolean) newValue) {
                Preference addException = getPreferenceScreen().findPreference(ADD_EXCEPTION_KEY);
                if (addException != null) {
                    // Can be null in testing.
                    getPreferenceScreen().removePreference(addException);
                }
            } else {
                getPreferenceScreen().addPreference(new AddExceptionPreference(getActivity(), ADD_EXCEPTION_KEY, getAddExceptionDialogMessage(), this));
            }
        }
        ChromeSwitchPreference globalToggle = (ChromeSwitchPreference) getPreferenceScreen().findPreference(READ_WRITE_TOGGLE_KEY);
        updateAllowedHeader(mAllowedSiteCount, !globalToggle.isChecked());
        getInfoForOrigins();
    } else if (THIRD_PARTY_COOKIES_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setBlockThirdPartyCookiesEnabled(!((boolean) newValue));
    } else if (NOTIFICATIONS_VIBRATE_TOGGLE_KEY.equals(preference.getKey())) {
        PrefServiceBridge.getInstance().setNotificationsVibrateEnabled((boolean) newValue);
    }
    return true;
}
Also used : 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)

Example 2 with ChromeSwitchPreference

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

the class DoNotTrackPreference method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.do_not_track_preferences);
    getActivity().setTitle(R.string.do_not_track_title);
    ChromeSwitchPreference doNotTrackSwitch = (ChromeSwitchPreference) findPreference(PREF_DO_NOT_TRACK_SWITCH);
    boolean isDoNotTrackEnabled = PrefServiceBridge.getInstance().isDoNotTrackEnabled();
    doNotTrackSwitch.setChecked(isDoNotTrackEnabled);
    doNotTrackSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PrefServiceBridge.getInstance().setDoNotTrackEnabled((boolean) newValue);
            return true;
        }
    });
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 3 with ChromeSwitchPreference

use of org.chromium.chrome.browser.preferences.ChromeSwitchPreference 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 4 with ChromeSwitchPreference

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

the class SyncCustomizationFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mProfileSyncService = ProfileSyncService.get();
    assert mProfileSyncService != null;
    mIsBackendInitialized = mProfileSyncService.isBackendInitialized();
    mIsPassphraseRequired = mIsBackendInitialized && mProfileSyncService.isPassphraseRequiredForDecryption();
    getActivity().setTitle(R.string.sign_in_sync);
    View view = super.onCreateView(inflater, container, savedInstanceState);
    addPreferencesFromResource(R.xml.sync_customization_preferences);
    mSyncEverything = (SwitchPreference) findPreference(PREFERENCE_SYNC_EVERYTHING);
    mSyncAutofill = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_AUTOFILL);
    mSyncBookmarks = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_BOOKMARKS);
    mSyncOmnibox = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_OMNIBOX);
    mSyncPasswords = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_PASSWORDS);
    mSyncRecentTabs = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_RECENT_TABS);
    mSyncSettings = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_SETTINGS);
    mPaymentsIntegration = (CheckBoxPreference) findPreference(PREFERENCE_PAYMENTS_INTEGRATION);
    mSyncEncryption = findPreference(PREFERENCE_ENCRYPTION);
    mSyncEncryption.setOnPreferenceClickListener(this);
    mManageSyncData = findPreference(PREFERENCE_SYNC_MANAGE_DATA);
    mManageSyncData.setOnPreferenceClickListener(this);
    mSyncErrorCard = findPreference(PREFERENCE_SYNC_ERROR_CARD);
    mSyncErrorCard.setOnPreferenceClickListener(this);
    mAllTypes = new CheckBoxPreference[] { mSyncAutofill, mSyncBookmarks, mSyncOmnibox, mSyncPasswords, mSyncRecentTabs, mSyncSettings, mPaymentsIntegration };
    mSyncEverything.setOnPreferenceChangeListener(this);
    for (CheckBoxPreference type : mAllTypes) {
        type.setOnPreferenceChangeListener(this);
    }
    mSyncSwitchPreference = (ChromeSwitchPreference) findPreference(PREF_SYNC_SWITCH);
    mSyncSwitchPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            assert canDisableSync();
            if ((boolean) newValue) {
                mProfileSyncService.requestStart();
            } else {
                stopSync();
            }
            // Must be done asynchronously because the switch state isn't updated
            // until after this function exits.
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    updateSyncStateFromSwitch();
                }
            });
            return true;
        }
    });
    mSyncedAccountPreference = (SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST);
    mSyncedAccountPreference.setOnPreferenceChangeListener(new SyncAccountSwitcher(getActivity(), mSyncedAccountPreference));
    return view;
}
Also used : SyncAccountSwitcher(org.chromium.chrome.browser.sync.SyncAccountSwitcher) CheckBoxPreference(android.preference.CheckBoxPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) SyncedAccountPreference(org.chromium.chrome.browser.preferences.SyncedAccountPreference) SwitchPreference(android.preference.SwitchPreference) Handler(android.os.Handler) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View)

Example 5 with ChromeSwitchPreference

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

the class AutofillPreferences method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.autofill_preferences);
    getActivity().setTitle(R.string.prefs_autofill);
    ChromeSwitchPreference autofillSwitch = (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });
    setPreferenceCategoryIcons();
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

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